@@ -5,13 +5,34 @@ from cython cimport Py_ssize_t
55cimport numpy as cnp
66from numpy cimport ndarray
77
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
831
9- cdef extern from " src/numpy_helper.h" :
10- void set_array_not_contiguous(ndarray ao)
1132
33+ cdef extern from " src/numpy_helper.h" :
1234 int assign_value_1d(ndarray, Py_ssize_t, object ) except - 1
1335 object get_value_1d(ndarray, Py_ssize_t)
14- const char * get_c_string(object ) except NULL
1536
1637
1738cdef extern from " src/headers/stdint.h" :
@@ -44,6 +65,13 @@ ctypedef fused numeric:
4465 cnp.float64_t
4566
4667
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+
4775cdef inline object get_value_at(ndarray arr, object loc):
4876 cdef:
4977 Py_ssize_t i, sz
0 commit comments