Python numpy.ctypeslib.ndpointer() Examples

The following are code examples for showing how to use numpy.ctypeslib.ndpointer(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_ctypeslib.py    MIT License 6 votes vote down vote up
def test_return(self, dt):
        """ Test that return values are coerced to arrays """
        arr = np.zeros((2, 3), dt)
        ptr_type = ndpointer(shape=arr.shape, dtype=arr.dtype)

        c_forward_pointer.restype = ptr_type
        c_forward_pointer.argtypes = (ptr_type,)

        # check that the arrays are equivalent views on the same data
        arr2 = c_forward_pointer(arr)
        assert_equal(arr2.dtype, arr.dtype)
        assert_equal(arr2.shape, arr.shape)
        assert_equal(
            arr2.__array_interface__['data'],
            arr.__array_interface__['data']
        ) 
Example 2
Project: recruit   Author: Frank-qlu   File: test_ctypeslib.py    Apache License 2.0 6 votes vote down vote up
def test_return(self, dt):
        """ Test that return values are coerced to arrays """
        arr = np.zeros((2, 3), dt)
        ptr_type = ndpointer(shape=arr.shape, dtype=arr.dtype)

        c_forward_pointer.restype = ptr_type
        c_forward_pointer.argtypes = (ptr_type,)

        # check that the arrays are equivalent views on the same data
        arr2 = c_forward_pointer(arr)
        assert_equal(arr2.dtype, arr.dtype)
        assert_equal(arr2.shape, arr.shape)
        assert_equal(
            arr2.__array_interface__['data'],
            arr.__array_interface__['data']
        ) 
Example 3
Project: indigo   Author: mbdriscoll   File: cuda.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def cublasCgemm_v2(
        handle : cublasHandle_t,
        transa : cublasOperator_t,
        transb : cublasOperator_t,
        m      : c_int,
        n      : c_int,
        k      : c_int,
        alpha  : ndpointer(dtype=np.complex64, ndim=0),
        M      : dndarray,
        lda    : c_int,
        x      : dndarray,
        ldb    : c_int,
        beta   : ndpointer(dtype=np.complex64, ndim=0),
        y      : dndarray,
        ldc    : c_int,
    ) -> cublasStatus_t:
        pass 
Example 4
Project: indigo   Author: mbdriscoll   File: mkl.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def cblas_cgemm(
        layout : CBlasLayout,
        transa : CBlasTranspose,
        transb : CBlasTranspose,
        m     : c_int,
        n     : c_int,
        k     : c_int,
        alpha : ndpointer(dtype=np.complex64, ndim=0),
        a     : dndarray,
        lda   : c_int,
        b     : dndarray,
        ldb   : c_int,
        beta  : ndpointer(dtype=np.complex64, ndim=0),
        c     : dndarray,
        ldc   : c_int,
    ) -> c_void_p:
        pass 
Example 5
Project: indigo   Author: mbdriscoll   File: mkl.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def cblas_csymm(
        layout: CBlasLayout,
        side  : CBlasSide,
        uplo  : CBlasUplo,
        m     : c_int,
        n     : c_int,
        alpha : ndpointer(dtype=np.complex64, ndim=0),
        a     : dndarray,
        lda   : c_int,
        b     : dndarray,
        ldb   : c_int,
        beta  : ndpointer(dtype=np.complex64, ndim=0),
        c     : dndarray,
        ldc   : c_int,
    ) -> c_void_p:
        pass 
Example 6
Project: indigo   Author: mbdriscoll   File: mkl.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def mkl_ccsrmm(
        transA   : c_char*1,
        m        : ndpointer(dtype=np.int32,     ndim=0),
        n        : ndpointer(dtype=np.int32,     ndim=0),
        k        : ndpointer(dtype=np.int32,     ndim=0),
        alpha    : ndpointer(dtype=np.dtype('complex64'), ndim=1),
        matdescA : c_char * 6,
        val      : dndarray,
        indx     : dndarray,
        pntrb    : dndarray,
        pntre    : dndarray,
        b        : dndarray,
        ldb      : ndpointer(dtype=np.int32,     ndim=0),
        beta     : ndpointer(dtype=np.dtype('complex64'), ndim=1),
        c        : dndarray,
        ldc      : ndpointer(dtype=np.int32,     ndim=0),
    ) -> c_void_p :
        pass 
Example 7
Project: indigo   Author: mbdriscoll   File: mkl.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def mkl_cdiamm(
        transA   : c_char*1,
        m        : ndpointer(dtype=np.int32,     ndim=0),
        n        : ndpointer(dtype=np.int32,     ndim=0),
        k        : ndpointer(dtype=np.int32,     ndim=0),
        alpha    : ndpointer(dtype=np.dtype('complex64'), ndim=1),
        matdescA : c_char * 6,
        val      : dndarray,
        lval     : ndpointer(dtype=np.int32,     ndim=0),
        idiag    : dndarray,
        ndiag    : ndpointer(dtype=np.int32,     ndim=0),
        b        : dndarray,
        ldb      : ndpointer(dtype=np.int32,     ndim=0),
        beta     : ndpointer(dtype=np.dtype('complex64'), ndim=1),
        c        : dndarray,
        ldc      : ndpointer(dtype=np.int32,     ndim=0),
    ) -> c_void_p :
        pass 
Example 8
Project: MARRtino-2.0   Author: DaniAffCH   File: test_ctypeslib.py    GNU General Public License v3.0 6 votes vote down vote up
def test_return(self, dt):
        """ Test that return values are coerced to arrays """
        arr = np.zeros((2, 3), dt)
        ptr_type = ndpointer(shape=arr.shape, dtype=arr.dtype)

        c_forward_pointer.restype = ptr_type
        c_forward_pointer.argtypes = (ptr_type,)

        # check that the arrays are equivalent views on the same data
        arr2 = c_forward_pointer(arr)
        assert_equal(arr2.dtype, arr.dtype)
        assert_equal(arr2.shape, arr.shape)
        assert_equal(
            arr2.__array_interface__['data'],
            arr.__array_interface__['data']
        ) 
Example 9
Project: ble5-nrf52-mac   Author: tomasero   File: test_ctypeslib.py    MIT License 6 votes vote down vote up
def test_return(self, dt):
        """ Test that return values are coerced to arrays """
        arr = np.zeros((2, 3), dt)
        ptr_type = ndpointer(shape=arr.shape, dtype=arr.dtype)

        c_forward_pointer.restype = ptr_type
        c_forward_pointer.argtypes = (ptr_type,)

        # check that the arrays are equivalent views on the same data
        arr2 = c_forward_pointer(arr)
        assert_equal(arr2.dtype, arr.dtype)
        assert_equal(arr2.shape, arr.shape)
        assert_equal(
            arr2.__array_interface__['data'],
            arr.__array_interface__['data']
        ) 
Example 10
Project: LaserTOF   Author: kyleuckert   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        self.assertRaises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names': dtnames, 'formats': dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        self.assertTrue(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            self.assertRaises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            self.assertTrue(p.from_param(np.zeros((10,), dt2))) 
Example 11
Project: LaserTOF   Author: kyleuckert   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        self.assertTrue(p.from_param(np.array(1)))
        self.assertRaises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        self.assertRaises(TypeError, p.from_param, np.array(1))
        self.assertTrue(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        self.assertTrue(p.from_param(np.array([[1]]))) 
Example 12
Project: LaserTOF   Author: kyleuckert   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        self.assertTrue(p.from_param(np.array([[1, 2]])))
        self.assertRaises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        self.assertTrue(p.from_param(np.array(1))) 
Example 13
Project: LaserTOF   Author: kyleuckert   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        self.assertTrue(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        self.assertRaises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        self.assertTrue(p.from_param(x))
        self.assertRaises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 14
Project: LaserTOF   Author: kyleuckert   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_cache(self):
        a1 = ndpointer(dtype=np.float64)
        a2 = ndpointer(dtype=np.float64)
        self.assertEqual(a1, a2) 
Example 15
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        assert_raises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names': dtnames, 'formats': dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        assert_(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            assert_raises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            assert_(p.from_param(np.zeros((10,), dt2))) 
Example 16
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        assert_(p.from_param(np.array(1)))
        assert_raises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        assert_raises(TypeError, p.from_param, np.array(1))
        assert_(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        assert_(p.from_param(np.array([[1]]))) 
Example 17
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        assert_(p.from_param(np.array([[1, 2]])))
        assert_raises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        assert_(p.from_param(np.array(1))) 
Example 18
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        assert_(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        assert_raises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        assert_(p.from_param(x))
        assert_raises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 19
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_cache(self):
        assert_(ndpointer(dtype=np.float64) is ndpointer(dtype=np.float64))

        # shapes are normalized
        assert_(ndpointer(shape=2) is ndpointer(shape=(2,)))

        # 1.12 <= v < 1.16 had a bug that made these fail
        assert_(ndpointer(shape=2) is not ndpointer(ndim=2))
        assert_(ndpointer(ndim=2) is not ndpointer(shape=2)) 
Example 20
Project: FX-RER-Value-Extraction   Author: tsKenneth   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_vague_return_value(self):
        """ Test that vague ndpointer return values do not promote to arrays """
        arr = np.zeros((2, 3))
        ptr_type = ndpointer(dtype=arr.dtype)

        c_forward_pointer.restype = ptr_type
        c_forward_pointer.argtypes = (ptr_type,)

        ret = c_forward_pointer(arr)
        assert_(isinstance(ret, ptr_type)) 
Example 21
Project: recruit   Author: Frank-qlu   File: test_ctypeslib.py    Apache License 2.0 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        assert_raises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names': dtnames, 'formats': dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        assert_(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            assert_raises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            assert_(p.from_param(np.zeros((10,), dt2))) 
Example 22
Project: recruit   Author: Frank-qlu   File: test_ctypeslib.py    Apache License 2.0 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        assert_(p.from_param(np.array(1)))
        assert_raises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        assert_raises(TypeError, p.from_param, np.array(1))
        assert_(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        assert_(p.from_param(np.array([[1]]))) 
Example 23
Project: recruit   Author: Frank-qlu   File: test_ctypeslib.py    Apache License 2.0 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        assert_(p.from_param(np.array([[1, 2]])))
        assert_raises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        assert_(p.from_param(np.array(1))) 
Example 24
Project: recruit   Author: Frank-qlu   File: test_ctypeslib.py    Apache License 2.0 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        assert_(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        assert_raises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        assert_(p.from_param(x))
        assert_raises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 25
Project: recruit   Author: Frank-qlu   File: test_ctypeslib.py    Apache License 2.0 5 votes vote down vote up
def test_cache(self):
        assert_(ndpointer(dtype=np.float64) is ndpointer(dtype=np.float64))

        # shapes are normalized
        assert_(ndpointer(shape=2) is ndpointer(shape=(2,)))

        # 1.12 <= v < 1.16 had a bug that made these fail
        assert_(ndpointer(shape=2) is not ndpointer(ndim=2))
        assert_(ndpointer(ndim=2) is not ndpointer(shape=2)) 
Example 26
Project: recruit   Author: Frank-qlu   File: test_ctypeslib.py    Apache License 2.0 5 votes vote down vote up
def test_vague_return_value(self):
        """ Test that vague ndpointer return values do not promote to arrays """
        arr = np.zeros((2, 3))
        ptr_type = ndpointer(dtype=arr.dtype)

        c_forward_pointer.restype = ptr_type
        c_forward_pointer.argtypes = (ptr_type,)

        ret = c_forward_pointer(arr)
        assert_(isinstance(ret, ptr_type)) 
Example 27
Project: indigo   Author: mbdriscoll   File: cuda.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def cublasCaxpy_v2(
        handle : cublasHandle_t,
        n      : c_int,
        alpha  : ndpointer(dtype=np.complex64, ndim=0),
        x      : c_ulong, incx : c_int,
        y      : c_ulong, incy : c_int,
    ) -> cublasStatus_t:
        pass 
Example 28
Project: indigo   Author: mbdriscoll   File: cuda.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def cublasCdotc_v2(
        handle : cublasHandle_t,
        n      : c_int,
        x      : c_ulong,
        incx   : c_int,
        y      : c_ulong,
        incy   : c_int,
        result : ndpointer(dtype=np.complex64, ndim=0),
    ) -> cublasStatus_t:
        pass 
Example 29
Project: indigo   Author: mbdriscoll   File: cuda.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def cublasScnrm2_v2(
        handle : cublasHandle_t,
        n      : c_int,
        x      : c_ulong,
        incx   : c_int,
        result : ndpointer(dtype=np.complex64, ndim=0),
    ) -> cublasStatus_t:
        pass 
Example 30
Project: indigo   Author: mbdriscoll   File: cuda.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def cublasCscal_v2(
        handle : cublasHandle_t,
        n      : c_int,
        alpha  : ndpointer(dtype=np.complex64, ndim=0),
        x      : c_ulong,
        incx   : c_int,
    ) -> cublasStatus_t:
        pass 
Example 31
Project: indigo   Author: mbdriscoll   File: mkl.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def cblas_caxpby(
        n : c_int,
        a : ndpointer(dtype=np.complex64, ndim=0),
        x : ndpointer(dtype=np.complex64),
        incx : c_int,
        b : ndpointer(dtype=np.complex64, ndim=0),
        y : ndpointer(dtype=np.complex64),
        incy : c_int,
    ) -> c_void_p:
        pass 
Example 32
Project: indigo   Author: mbdriscoll   File: mkl.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def cblas_cdotc_sub(
        n    : c_int,
        x    : ndpointer(dtype=np.complex64),
        incx : c_int,
        y    : ndpointer(dtype=np.complex64),
        incy : c_int,
        dotc : ndpointer(dtype=np.complex64, ndim=0),
    ) -> c_void_p:
        pass 
Example 33
Project: indigo   Author: mbdriscoll   File: mkl.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def cblas_scnrm2(
        n : c_int,
        x    : ndpointer(dtype=np.complex64),
        incx : c_int,
    ) -> c_float:
        pass 
Example 34
Project: indigo   Author: mbdriscoll   File: mkl.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def mkl_ccsrmv(
        transA   : c_char*1,
        m        : ndpointer(dtype=np.int32,     ndim=0),
        k        : ndpointer(dtype=np.int32,     ndim=0),
        alpha    : ndpointer(dtype=np.dtype('complex64'), ndim=1),
        matdescA : c_char * 6,
        val      : dndarray,
        indx     : dndarray,
        pntrb    : dndarray,
        pntre    : dndarray,
        b        : dndarray,
        beta     : ndpointer(dtype=np.dtype('complex64'), ndim=1),
        c        : dndarray,
    ) -> c_void_p :
        pass 
Example 35
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_ctypeslib.py    GNU General Public License v3.0 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        self.assertRaises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names' : dtnames, 'formats' : dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        self.assertTrue(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            self.assertRaises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            self.assertTrue(p.from_param(np.zeros((10,), dt2))) 
Example 36
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_ctypeslib.py    GNU General Public License v3.0 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        self.assertTrue(p.from_param(np.array(1)))
        self.assertRaises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        self.assertRaises(TypeError, p.from_param, np.array(1))
        self.assertTrue(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        self.assertTrue(p.from_param(np.array([[1]]))) 
Example 37
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_ctypeslib.py    GNU General Public License v3.0 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        self.assertTrue(p.from_param(np.array([[1, 2]])))
        self.assertRaises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        self.assertTrue(p.from_param(np.array(1))) 
Example 38
Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_ctypeslib.py    GNU General Public License v3.0 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        self.assertTrue(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        self.assertRaises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        self.assertTrue(p.from_param(x))
        self.assertRaises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 39
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        assert_raises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names': dtnames, 'formats': dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        assert_(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            assert_raises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            assert_(p.from_param(np.zeros((10,), dt2))) 
Example 40
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        assert_(p.from_param(np.array(1)))
        assert_raises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        assert_raises(TypeError, p.from_param, np.array(1))
        assert_(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        assert_(p.from_param(np.array([[1]]))) 
Example 41
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        assert_(p.from_param(np.array([[1, 2]])))
        assert_raises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        assert_(p.from_param(np.array(1))) 
Example 42
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        assert_(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        assert_raises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        assert_(p.from_param(x))
        assert_raises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 43
Project: FUTU_Stop_Loss   Author: BigtoC   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_cache(self):
        a1 = ndpointer(dtype=np.float64)
        a2 = ndpointer(dtype=np.float64)
        assert_(a1 == a2) 
Example 44
Project: MARRtino-2.0   Author: DaniAffCH   File: test_ctypeslib.py    GNU General Public License v3.0 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        assert_raises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names': dtnames, 'formats': dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        assert_(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            assert_raises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            assert_(p.from_param(np.zeros((10,), dt2))) 
Example 45
Project: MARRtino-2.0   Author: DaniAffCH   File: test_ctypeslib.py    GNU General Public License v3.0 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        assert_(p.from_param(np.array(1)))
        assert_raises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        assert_raises(TypeError, p.from_param, np.array(1))
        assert_(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        assert_(p.from_param(np.array([[1]]))) 
Example 46
Project: MARRtino-2.0   Author: DaniAffCH   File: test_ctypeslib.py    GNU General Public License v3.0 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        assert_(p.from_param(np.array([[1, 2]])))
        assert_raises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        assert_(p.from_param(np.array(1))) 
Example 47
Project: MARRtino-2.0   Author: DaniAffCH   File: test_ctypeslib.py    GNU General Public License v3.0 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        assert_(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        assert_raises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        assert_(p.from_param(x))
        assert_raises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 48
Project: MARRtino-2.0   Author: DaniAffCH   File: test_ctypeslib.py    GNU General Public License v3.0 5 votes vote down vote up
def test_cache(self):
        assert_(ndpointer(dtype=np.float64) is ndpointer(dtype=np.float64))

        # shapes are normalized
        assert_(ndpointer(shape=2) is ndpointer(shape=(2,)))

        # 1.12 <= v < 1.16 had a bug that made these fail
        assert_(ndpointer(shape=2) is not ndpointer(ndim=2))
        assert_(ndpointer(ndim=2) is not ndpointer(shape=2)) 
Example 49
Project: MARRtino-2.0   Author: DaniAffCH   File: test_ctypeslib.py    GNU General Public License v3.0 5 votes vote down vote up
def test_vague_return_value(self):
        """ Test that vague ndpointer return values do not promote to arrays """
        arr = np.zeros((2, 3))
        ptr_type = ndpointer(dtype=arr.dtype)

        c_forward_pointer.restype = ptr_type
        c_forward_pointer.argtypes = (ptr_type,)

        ret = c_forward_pointer(arr)
        assert_(isinstance(ret, ptr_type)) 
Example 50
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        self.assertRaises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names': dtnames, 'formats': dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        self.assertTrue(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            self.assertRaises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            self.assertTrue(p.from_param(np.zeros((10,), dt2))) 
Example 51
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        self.assertTrue(p.from_param(np.array(1)))
        self.assertRaises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        self.assertRaises(TypeError, p.from_param, np.array(1))
        self.assertTrue(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        self.assertTrue(p.from_param(np.array([[1]]))) 
Example 52
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        self.assertTrue(p.from_param(np.array([[1, 2]])))
        self.assertRaises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        self.assertTrue(p.from_param(np.array(1))) 
Example 53
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        self.assertTrue(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        self.assertRaises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        self.assertTrue(p.from_param(x))
        self.assertRaises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 54
Project: vnpy_crypto   Author: birforce   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        assert_raises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names': dtnames, 'formats': dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        assert_(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            assert_raises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            assert_(p.from_param(np.zeros((10,), dt2))) 
Example 55
Project: vnpy_crypto   Author: birforce   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        assert_(p.from_param(np.array(1)))
        assert_raises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        assert_raises(TypeError, p.from_param, np.array(1))
        assert_(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        assert_(p.from_param(np.array([[1]]))) 
Example 56
Project: vnpy_crypto   Author: birforce   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        assert_(p.from_param(np.array([[1, 2]])))
        assert_raises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        assert_(p.from_param(np.array(1))) 
Example 57
Project: vnpy_crypto   Author: birforce   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        assert_(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        assert_raises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        assert_(p.from_param(x))
        assert_raises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 58
Project: vnpy_crypto   Author: birforce   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_cache(self):
        a1 = ndpointer(dtype=np.float64)
        a2 = ndpointer(dtype=np.float64)
        assert_(a1 == a2) 
Example 59
Project: ble5-nrf52-mac   Author: tomasero   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        assert_raises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names': dtnames, 'formats': dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        assert_(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            assert_raises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            assert_(p.from_param(np.zeros((10,), dt2))) 
Example 60
Project: ble5-nrf52-mac   Author: tomasero   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        assert_(p.from_param(np.array(1)))
        assert_raises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        assert_raises(TypeError, p.from_param, np.array(1))
        assert_(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        assert_(p.from_param(np.array([[1]]))) 
Example 61
Project: ble5-nrf52-mac   Author: tomasero   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        assert_(p.from_param(np.array([[1, 2]])))
        assert_raises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        assert_(p.from_param(np.array(1))) 
Example 62
Project: ble5-nrf52-mac   Author: tomasero   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        assert_(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        assert_raises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        assert_(p.from_param(x))
        assert_raises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 63
Project: ble5-nrf52-mac   Author: tomasero   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_cache(self):
        assert_(ndpointer(dtype=np.float64) is ndpointer(dtype=np.float64))

        # shapes are normalized
        assert_(ndpointer(shape=2) is ndpointer(shape=(2,)))

        # 1.12 <= v < 1.16 had a bug that made these fail
        assert_(ndpointer(shape=2) is not ndpointer(ndim=2))
        assert_(ndpointer(ndim=2) is not ndpointer(shape=2)) 
Example 64
Project: ble5-nrf52-mac   Author: tomasero   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_vague_return_value(self):
        """ Test that vague ndpointer return values do not promote to arrays """
        arr = np.zeros((2, 3))
        ptr_type = ndpointer(dtype=arr.dtype)

        c_forward_pointer.restype = ptr_type
        c_forward_pointer.argtypes = (ptr_type,)

        ret = c_forward_pointer(arr)
        assert_(isinstance(ret, ptr_type)) 
Example 65
Project: Computable   Author: ktraunmueller   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        self.assertRaises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names' : dtnames, 'formats' : dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        self.assertTrue(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            self.assertRaises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            self.assertTrue(p.from_param(np.zeros((10,), dt2))) 
Example 66
Project: Computable   Author: ktraunmueller   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        self.assertTrue(p.from_param(np.array(1)))
        self.assertRaises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        self.assertRaises(TypeError, p.from_param, np.array(1))
        self.assertTrue(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        self.assertTrue(p.from_param(np.array([[1]]))) 
Example 67
Project: Computable   Author: ktraunmueller   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        self.assertTrue(p.from_param(np.array([[1, 2]])))
        self.assertRaises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        self.assertTrue(p.from_param(np.array(1))) 
Example 68
Project: Computable   Author: ktraunmueller   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        self.assertTrue(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        self.assertRaises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        self.assertTrue(p.from_param(x))
        self.assertRaises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 69
Project: poker   Author: surgebiswas   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        self.assertRaises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names': dtnames, 'formats': dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        self.assertTrue(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        self.assertTrue(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            self.assertRaises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            self.assertTrue(p.from_param(np.zeros((10,), dt2))) 
Example 70
Project: poker   Author: surgebiswas   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        self.assertTrue(p.from_param(np.array(1)))
        self.assertRaises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        self.assertRaises(TypeError, p.from_param, np.array(1))
        self.assertTrue(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        self.assertTrue(p.from_param(np.array([[1]]))) 
Example 71
Project: poker   Author: surgebiswas   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        self.assertTrue(p.from_param(np.array([[1, 2]])))
        self.assertRaises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        self.assertTrue(p.from_param(np.array(1))) 
Example 72
Project: poker   Author: surgebiswas   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        self.assertTrue(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        self.assertRaises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        self.assertTrue(p.from_param(x))
        self.assertRaises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 73
Project: poker   Author: surgebiswas   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_cache(self):
        a1 = ndpointer(dtype=np.float64)
        a2 = ndpointer(dtype=np.float64)
        self.assertEqual(a1, a2) 
Example 74
Project: HiguchiFractalDimension   Author: inuritdino   File: hfd.py    MIT License 5 votes vote down vote up
def init_lib():
    libdir = os.path.dirname(__file__)
    libfile = os.path.join(libdir, "libhfd.so")
    lib = ctypes.CDLL(libfile)

    rwptr = ndpointer(float, flags=('C','A','W'))
    rwptr_sizet = ndpointer(ctypes.c_size_t, flags=('C','A','W'))

    lib.curve_length.restype = ctypes.c_int
    lib.curve_length.argtypes = [rwptr_sizet, ctypes.c_size_t, rwptr, ctypes.c_size_t, rwptr]

    return lib; 
Example 75
Project: P3_image_processing   Author: latedude2   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_dtype(self):
        dt = np.intc
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = '<i4'
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.array([1], dt)))
        dt = np.dtype('>i4')
        p = ndpointer(dtype=dt)
        p.from_param(np.array([1], dt))
        assert_raises(TypeError, p.from_param,
                          np.array([1], dt.newbyteorder('swap')))
        dtnames = ['x', 'y']
        dtformats = [np.intc, np.float64]
        dtdescr = {'names': dtnames, 'formats': dtformats}
        dt = np.dtype(dtdescr)
        p = ndpointer(dtype=dt)
        assert_(p.from_param(np.zeros((10,), dt)))
        samedt = np.dtype(dtdescr)
        p = ndpointer(dtype=samedt)
        assert_(p.from_param(np.zeros((10,), dt)))
        dt2 = np.dtype(dtdescr, align=True)
        if dt.itemsize != dt2.itemsize:
            assert_raises(TypeError, p.from_param, np.zeros((10,), dt2))
        else:
            assert_(p.from_param(np.zeros((10,), dt2))) 
Example 76
Project: P3_image_processing   Author: latedude2   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_ndim(self):
        p = ndpointer(ndim=0)
        assert_(p.from_param(np.array(1)))
        assert_raises(TypeError, p.from_param, np.array([1]))
        p = ndpointer(ndim=1)
        assert_raises(TypeError, p.from_param, np.array(1))
        assert_(p.from_param(np.array([1])))
        p = ndpointer(ndim=2)
        assert_(p.from_param(np.array([[1]]))) 
Example 77
Project: P3_image_processing   Author: latedude2   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_shape(self):
        p = ndpointer(shape=(1, 2))
        assert_(p.from_param(np.array([[1, 2]])))
        assert_raises(TypeError, p.from_param, np.array([[1], [2]]))
        p = ndpointer(shape=())
        assert_(p.from_param(np.array(1))) 
Example 78
Project: P3_image_processing   Author: latedude2   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_flags(self):
        x = np.array([[1, 2], [3, 4]], order='F')
        p = ndpointer(flags='FORTRAN')
        assert_(p.from_param(x))
        p = ndpointer(flags='CONTIGUOUS')
        assert_raises(TypeError, p.from_param, x)
        p = ndpointer(flags=x.flags.num)
        assert_(p.from_param(x))
        assert_raises(TypeError, p.from_param, np.array([[1, 2], [3, 4]])) 
Example 79
Project: P3_image_processing   Author: latedude2   File: test_ctypeslib.py    MIT License 5 votes vote down vote up
def test_cache(self):
        assert_(ndpointer(dtype=np.float64) is ndpointer(dtype=np.float64))

        # shapes are normalized
        assert_(ndpointer(shape=2) is ndpointer(shape=(2,)))

        # 1.12 <= v < 1.16 had a bug that made these fail
        assert_(ndpointer(shape=2) is not ndpointer(ndim=2))
        assert_(ndpointer(ndim=2) is not ndpointer(shape=2)) 
Example 80
Project: RecurrentGaze   Author: crisie   File: info3D_estimation.py    MIT License 4 votes vote down vote up
def get_3Dinformation(self, image, calib_matrix, certainty_threshold = 0.5):
        """
        Calls trackFace method from shared library, which extracts FACE_INFO information
        :param image:
        :param calib_matrix:
        :param certainty_threshold:
        :return:
        """

        calib_matrix_np = np.array(calib_matrix).reshape((9, 1))
        self.info3D_model.trackFace.argtypes = [c_char_p, ndpointer(c_double, flags="C_CONTIGUOUS"), POINTER(FACE_INFO)]
        face_info = FACE_INFO(0.0, 0)
        success = self.info3D_model.trackFace(image.encode('utf-8'), calib_matrix_np, pointer(face_info))

        if success and face_info.certainty >= certainty_threshold:
            info3D = dict()

            # Landmark 2D
            info3D['landmarks2D'] = np.ndarray(buffer=landmarks2D_array.from_address(addressof(face_info.landmarks2D)),
                                     shape=(landmarks2D_size,)).reshape((2, landmarks_model_num)).transpose().copy()

            # Landmarks 3D
            info3D['landmarks3D'] = np.ndarray(buffer=landmarks3D_array.from_address(addressof(face_info.landmarks3D)),
                                     shape=(landmarks3D_size,)).reshape((3, landmarks_model_num)).transpose().copy()

            # Head pose
            info3D['R'] = np.ndarray(buffer=head_pose_array.from_address(addressof(face_info.head_rotation)),
                           shape=(pose_size,)).copy()

            # Head position
            info3D['T'] = np.ndarray(buffer=head_pose_array.from_address(addressof(face_info.head_position)),
                           shape=(pose_size,)).copy()

            # AUS intensity
            info3D['AUSint'] = np.ndarray(buffer=aus_intensity_array.from_address(addressof(face_info.aus_intensity)),
                                shape=(aus_intensity_size,)).copy()

            # AUS presence
            info3D['AUSpres'] = np.ndarray(buffer=aus_presence_array.from_address(addressof(face_info.aus_presence)),
                                 shape=(aus_presence_size,)).copy()

            return info3D

        print("WARNING from OpenFaceWrapper reading the input image or applying face model, or certainty obtained "
              "below threshold.")
        print("Please check image directory is correct.")
        return None