npctypes.types module¶
-
npctypes.types.
ctype
(a_type)[source]¶ Takes a numpy.dtype or any type that can be converted to a numpy.dtype and returns its equivalent ctype.
Parameters: a_type (type) – the type to find an equivalent ctype to. Returns: the ctype equivalent to the dtype provided. Return type: (ctype) Examples
>>> ctype(float) <class 'ctypes.c_double'>
>>> ctype(numpy.float64) <class 'ctypes.c_double'>
>>> ctype(numpy.float32) <class 'ctypes.c_float'>
>>> ctype(numpy.dtype(numpy.float32)) <class 'ctypes.c_float'>
>>> ctype(int) <class 'ctypes.c_long'>
-
npctypes.types.
get_ndpointer_type
(a)[source]¶ Takes a numpy.ndarray and gets a pointer type for that array.
Parameters: a (ndarray) – the ndarray to get the pointer type for. Returns: the pointer type associated with this array. Return type: (PyCSimpleType) Examples
>>> a = numpy.zeros((3, 4), dtype=float) >>> a_ptr = get_ndpointer_type(a)
>>> a_ptr <class 'numpy.ctypeslib.ndpointer_<f8_2d_3x4_C_CONTIGUOUS_ALIGNED_WRITEABLE_OWNDATA'>
>>> a_ptr._dtype_ dtype('float64') >>> a_ptr._ndim_ 2 >>> tuple(int(s) for s in a_ptr._shape_) (3, 4) >>> a_ptr._flags_ 1285 >>> numpy.ctypeslib.flagsobj(a_ptr._flags_) C_CONTIGUOUS : True F_CONTIGUOUS : True OWNDATA : True WRITEABLE : False ALIGNED : True WRITEBACKIFCOPY : False UPDATEIFCOPY : False
-
npctypes.types.
tinfo
(a_type)[source]¶ Takes a
numpy.dtype
or any type that can be converted to anumpy.dtype
and returns its info.Parameters: a_type (type) – the type to find info for. Returns: info about the type. Return type: (np.core.getlimits.info) Examples
>>> tinfo(float) finfo(resolution=1e-15, min=-1.7976931348623157e+308, max=1.7976931348623157e+308, dtype=float64)
>>> tinfo(numpy.float64) finfo(resolution=1e-15, min=-1.7976931348623157e+308, max=1.7976931348623157e+308, dtype=float64)
>>> tinfo(numpy.float32) finfo(resolution=1e-06, min=-3.4028235e+38, max=3.4028235e+38, dtype=float32)
>>> tinfo(complex) finfo(resolution=1e-15, min=-1.7976931348623157e+308, max=1.7976931348623157e+308, dtype=float64)
>>> tinfo(numpy.int32) iinfo(min=-2147483648, max=2147483647, dtype=int32)