Fix cython syntax and port to more recent numpy.pxd

This commit is contained in:
Guilhem Lavaux 2023-12-06 09:28:36 +01:00
parent 4afc982dfc
commit 0093a6aa0f
3 changed files with 12 additions and 4 deletions

View File

@ -12,7 +12,7 @@ cdef extern from "numpy/npy_common.h":
ctypedef npy_intp ctypedef npy_intp
cdef extern from "special_math.hpp" namespace "CosmoTool": cdef extern from "special_math.hpp" namespace "CosmoTool":
T log_modified_bessel_first_kind[T](T v, T z) nogil except + T log_modified_bessel_first_kind[T](T v, T z) except + nogil
cdef extern from "numpy_adaptors.hpp" namespace "CosmoTool": cdef extern from "numpy_adaptors.hpp" namespace "CosmoTool":
void parallel_ufunc_dd_d[T,IT](char **args, IT* dimensions, IT* steps, void *func) void parallel_ufunc_dd_d[T,IT](char **args, IT* dimensions, IT* steps, void *func)

View File

@ -39,7 +39,7 @@ cdef extern from "loadSimu.hpp" namespace "CosmoTool":
cdef extern from "loadGadget.hpp" namespace "CosmoTool": cdef extern from "loadGadget.hpp" namespace "CosmoTool":
SimuData *loadGadgetMulti(const char *fname, int id, int flags, int gformat) nogil except + SimuData *loadGadgetMulti(const char *fname, int id, int flags, int gformat) except + nogil
void cxx_writeGadget "CosmoTool::writeGadget" (const char * s, SimuData *data) except + void cxx_writeGadget "CosmoTool::writeGadget" (const char * s, SimuData *data) except +
cdef extern from "safe_gadget.hpp": cdef extern from "safe_gadget.hpp":
@ -313,6 +313,13 @@ tries to get an array from the object."""
references to the object are gone. """ references to the object are gone. """
pass pass
cdef extern from "numpy/arrayobject.h":
# a little bit awkward: the reference to obj will be stolen
# using PyObject* to signal that Cython cannot handle it automatically
int PyArray_SetBaseObject(np.ndarray arr, PyObject *obj) except -1 # -1 means there was an error
cdef object wrap_array(void *p, np.uint64_t s, int typ): cdef object wrap_array(void *p, np.uint64_t s, int typ):
cdef np.ndarray ndarray cdef np.ndarray ndarray
cdef ArrayWrapper wrapper cdef ArrayWrapper wrapper
@ -320,7 +327,8 @@ cdef object wrap_array(void *p, np.uint64_t s, int typ):
wrapper = ArrayWrapper() wrapper = ArrayWrapper()
wrapper.set_data(s, typ, p) wrapper.set_data(s, typ, p)
ndarray = np.array(wrapper, copy=False) ndarray = np.array(wrapper, copy=False)
ndarray.base = <PyObject*> wrapper #ndarray.base = <PyObject*> wrapper
PyArray_SetBaseObject(ndarray, <PyObject*> wrapper)
Py_INCREF(wrapper) Py_INCREF(wrapper)
return ndarray return ndarray

View File

@ -727,7 +727,7 @@ cdef DTYPE_t C_line_of_sight_projection(DTYPE_t[:,:,:] density,
cdef int iu0[3] cdef int iu0[3]
cdef int i cdef int i
cdef int N = density.shape[0] cdef int N = density.shape[0]
cdef int half_N = density.shape[0]/2 cdef int half_N = density.shape[0]//2
cdef int completed cdef int completed
cdef DTYPE_t I0, d, dist2, delta, s, max_distance2 cdef DTYPE_t I0, d, dist2, delta, s, max_distance2
cdef int jumper[1] cdef int jumper[1]