cdef npy_intp PyArray_DIMS(ndarray arr)
cdef Py_ssize_t PyArray_ITEMSIZE(ndarray arr)
+ ctypedef signed int npy_byte
+ ctypedef signed int npy_short
+ ctypedef signed int npy_int
+ ctypedef signed int npy_long
+ ctypedef signed int npy_longlong
+
+ ctypedef unsigned int npy_ubyte
+ ctypedef unsigned int npy_ushort
+ ctypedef unsigned int npy_uint
+ ctypedef unsigned int npy_ulong
+ ctypedef unsigned int npy_ulonglong
+
+ ctypedef float npy_float
+ ctypedef float npy_double
+ ctypedef float npy_longdouble
+
ctypedef signed int npy_int8
ctypedef signed int npy_int16
ctypedef signed int npy_int32
ctypedef float npy_float96
ctypedef float npy_float128
+# Typedefs that matches the runtime dtype objects in
+# the numpy module.
+
+# The ones that are commented out needs an IFDEF function
+# in Cython to enable them only on the right systems.
+
+ctypedef npy_int8 int8_t
+ctypedef npy_int16 int16_t
+ctypedef npy_int32 int32_t
+ctypedef npy_int64 int64_t
+#ctypedef npy_int96 int96_t
+#ctypedef npy_int128 int128_t
+
+ctypedef npy_uint8 uint8_t
+ctypedef npy_uint16 uint16_t
+ctypedef npy_uint32 uint32_t
+ctypedef npy_uint64 uint64_t
+#ctypedef npy_uint96 uint96_t
+#ctypedef npy_uint128 uint128_t
+
+ctypedef npy_float32 float32_t
+ctypedef npy_float64 float64_t
+#ctypedef npy_float80 float80_t
+#ctypedef npy_float128 float128_t
+
+# The int types are mapped a bit surprising --
+# numpy.int corresponds to 'l' and numpy.long to 'q'
+ctypedef npy_long int_t
+ctypedef npy_longlong long_t
+
+ctypedef npy_ulong uint_t
+ctypedef npy_ulonglong ulong_t
+
+ctypedef npy_double float_t
+ctypedef npy_double double_t
+ctypedef npy_longdouble longdouble_t
-ctypedef npy_int8 int8_t
-ctypedef npy_int16 int16_t
-ctypedef npy_int32 int32_t
-ctypedef npy_int64 int64_t
-ctypedef npy_int96 int96_t
-ctypedef npy_int128 int128_t
-
-ctypedef npy_uint8 uint8_t
-ctypedef npy_uint16 uint16_t
-ctypedef npy_uint32 uint32_t
-ctypedef npy_uint64 uint64_t
-ctypedef npy_uint96 uint96_t
-ctypedef npy_uint128 uint128_t
-
-ctypedef npy_float32 float32_t
-ctypedef npy_float64 float64_t
-ctypedef npy_float80 float80_t
-ctypedef npy_float128 float128_t
>>> test_dtype('g', inc1_longdouble)
>>> test_dtype('O', inc1_object)
+ >>> test_dtype(np.int, inc1_int_t)
+ >>> test_dtype(np.long, inc1_long_t)
+ >>> test_dtype(np.float, inc1_float_t)
+ >>> test_dtype(np.double, inc1_double_t)
+ >>> test_dtype(np.longdouble, inc1_longdouble_t)
+
+ >>> test_dtype(np.int32, inc1_int32_t)
+ >>> test_dtype(np.float64, inc1_float64_t)
+
Unsupported types:
>>> test_dtype(np.complex, inc1_byte)
Traceback (most recent call last):
Traceback (most recent call last):
...
ValueError: only objects, int and float dtypes supported for ndarray buffer access so far (dtype is 20)
-
"""
except:
def inc1_double(np.ndarray[double] arr): arr[1] += 1
def inc1_longdouble(np.ndarray[long double] arr): arr[1] += 1
+
def inc1_object(np.ndarray[object] arr):
o = arr[1]
o += 1
arr[1] = o # unfortunately, += segfaults for objects
+
+
+def inc1_int_t(np.ndarray[np.int_t] arr): arr[1] += 1
+def inc1_long_t(np.ndarray[np.long_t] arr): arr[1] += 1
+def inc1_float_t(np.ndarray[np.float_t] arr): arr[1] += 1
+def inc1_double_t(np.ndarray[np.double_t] arr): arr[1] += 1
+def inc1_longdouble_t(np.ndarray[np.longdouble_t] arr): arr[1] += 1
+
+# The tests below only work on platforms that has the given types
+def inc1_int32_t(np.ndarray[np.int32_t] arr): arr[1] += 1
+def inc1_float64_t(np.ndarray[np.float64_t] arr): arr[1] += 1
+
+
def test_dtype(dtype, inc1):
a = np.array([0, 10], dtype=dtype)
inc1(a)