当前位置: 首页>>代码示例>>Python>>正文


Python ctypeslib.ndpointer方法代码示例

本文整理汇总了Python中numpy.ctypeslib.ndpointer方法的典型用法代码示例。如果您正苦于以下问题:Python ctypeslib.ndpointer方法的具体用法?Python ctypeslib.ndpointer怎么用?Python ctypeslib.ndpointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy.ctypeslib的用法示例。


在下文中一共展示了ctypeslib.ndpointer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_return

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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']
        ) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:test_ctypeslib.py

示例2: kmeans

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
def kmeans(X, nclst, maxiter=0, numruns=1):
    """Wrapper for Peter Gehlers accelerated MPI-Kmeans routine."""
    
    mpikmeanslib = N.ctypeslib.load_library("libmpikmeans.so", ".")
    mpikmeanslib.kmeans.restype = c_double
    mpikmeanslib.kmeans.argtypes = [ndpointer(dtype=c_double, ndim=1, flags='C_CONTIGUOUS'), \
                                    ndpointer(dtype=c_double, ndim=1, flags='C_CONTIGUOUS'), \
                                    ndpointer(dtype=c_uint, ndim=1, flags='C_CONTIGUOUS'), \
                                    c_uint, c_uint, c_uint, c_uint, c_uint ]
    
    npts,dim = X.shape
    assignments=empty( (npts), c_uint )
    
    bestSSE=N.Inf
    bestassignments=empty( (npts), c_uint)
    Xvec = array( reshape( X, (-1,) ), c_double )
    permutation = N.random.permutation( range(npts) ) # randomize order of points
    CX = array(X[permutation[:nclst],:], c_double).flatten()
    SSE = mpikmeanslib.kmeans( CX, Xvec, assignments, dim, npts, min(nclst, npts), maxiter, numruns)
    return reshape(CX, (nclst,dim)), SSE, (assignments+1) 
开发者ID:seanbell,项目名称:opensurfaces,代码行数:22,代码来源:mpi_kmeans.py

示例3: remove_isolated_3d_points

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
def remove_isolated_3d_points(xyz, r, p, n, q=1):
    """
    Discard (in place) isolated (groups of) points in a gridded set of 3D points

    Discarded points satisfy the following conditions:
    - they have less than n 3D neighbors in a ball of radius r units (ex: meters);
    - all their neighboring points of the grid in a square window of size 2q+1
      that are closer than r units are also discarded.

    Args:
        xyz (array): 3D array of shape (h, w, 3) where each pixel contains the
            UTM easting, northing, and altitude of a 3D point.
        r (float): filtering radius, in the unit of the CRS (ex: meters)
        p (int): filering window radius, in pixels (square window of size 2p+1)
        n (int): filtering threshold, in number of points
        q (int): 2nd filtering window radius, in pixels (square of size 2q+1)
    """
    h, w, d = xyz.shape
    assert d == 3, 'expecting a 3-channels image with shape (h, w, 3)'

    lib.remove_isolated_3d_points.argtypes = (
        ndpointer(dtype=c_float, shape=(h, w, 3)),
        c_int, c_int, c_float, c_int, c_int, c_int)

    lib.remove_isolated_3d_points(np.ascontiguousarray(xyz), w, h, r, p, n, q) 
开发者ID:cmla,项目名称:s2p,代码行数:27,代码来源:triangulation.py

示例4: test_dtype

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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))) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:28,代码来源:test_ctypeslib.py

示例5: test_ndim

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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]]))) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_ctypeslib.py

示例6: test_shape

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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))) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:8,代码来源:test_ctypeslib.py

示例7: test_flags

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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]])) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_ctypeslib.py

示例8: test_cache

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:test_ctypeslib.py

示例9: test_vague_return_value

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:12,代码来源:test_ctypeslib.py

示例10: test_dtype

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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))) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:28,代码来源:test_ctypeslib.py

示例11: test_ndim

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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]]))) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:11,代码来源:test_ctypeslib.py

示例12: test_shape

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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))) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:8,代码来源:test_ctypeslib.py

示例13: test_flags

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
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]])) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:11,代码来源:test_ctypeslib.py

示例14: test_cache

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
def test_cache(self):
        a1 = ndpointer(dtype=np.float64)
        a2 = ndpointer(dtype=np.float64)
        self.assertEqual(a1, a2) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:6,代码来源:test_ctypeslib.py

示例15: test_cache

# 需要导入模块: from numpy import ctypeslib [as 别名]
# 或者: from numpy.ctypeslib import ndpointer [as 别名]
def test_cache(self):
        a1 = ndpointer(dtype=np.float64)
        a2 = ndpointer(dtype=np.float64)
        assert_(a1 == a2) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:6,代码来源:test_ctypeslib.py


注:本文中的numpy.ctypeslib.ndpointer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。