@@ -5,13 +5,34 @@ from cython cimport Py_ssize_t
5
5
cimport numpy as cnp
6
6
from numpy cimport ndarray
7
7
8
+ cdef extern from " numpy/ndarraytypes.h" :
9
+ void PyArray_CLEARFLAGS(ndarray arr, int flags) nogil
10
+
11
+
12
+ cdef extern from " numpy/arrayobject.h" :
13
+ enum :
14
+ NPY_ARRAY_C_CONTIGUOUS
15
+ NPY_ARRAY_F_CONTIGUOUS
16
+
17
+
18
+ cdef extern from * :
19
+ """
20
+ // returns ASCII or UTF8 (py3) view on python str
21
+ // python object owns memory, should not be freed
22
+ static const char* get_c_string(PyObject* obj) {
23
+ #if PY_VERSION_HEX >= 0x03000000
24
+ return PyUnicode_AsUTF8(obj);
25
+ #else
26
+ return PyString_AsString(obj);
27
+ #endif
28
+ }
29
+ """
30
+ const char * get_c_string(object ) except NULL
8
31
9
- cdef extern from " src/numpy_helper.h" :
10
- void set_array_not_contiguous(ndarray ao)
11
32
33
+ cdef extern from " src/numpy_helper.h" :
12
34
int assign_value_1d(ndarray, Py_ssize_t, object ) except - 1
13
35
object get_value_1d(ndarray, Py_ssize_t)
14
- const char * get_c_string(object ) except NULL
15
36
16
37
17
38
cdef extern from " src/headers/stdint.h" :
@@ -44,6 +65,13 @@ ctypedef fused numeric:
44
65
cnp.float64_t
45
66
46
67
68
+ cdef inline void set_array_not_contiguous(ndarray ao) nogil:
69
+ # Numpy>=1.8-compliant equivalent to:
70
+ # ao->flags &= ~(NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS);
71
+ PyArray_CLEARFLAGS(ao,
72
+ (NPY_ARRAY_C_CONTIGUOUS | NPY_ARRAY_F_CONTIGUOUS))
73
+
74
+
47
75
cdef inline object get_value_at(ndarray arr, object loc):
48
76
cdef:
49
77
Py_ssize_t i, sz
0 commit comments