Skip to content

Commit

Permalink
Merge pull request #31 from jschueller/np17
Browse files Browse the repository at this point in the history
Fix missing PyArray_DATA accessors
  • Loading branch information
PeterMeisrimelModelon authored Dec 8, 2021
2 parents 1ecaff1 + 6207887 commit dcd1be3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/lib/sundials_callbacks.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ cdef inline N.ndarray nv2arr(N_Vector v):
cdef long int n = (<N_VectorContent_Serial>v.content).length
cdef realtype* v_data = (<N_VectorContent_Serial>v.content).data
cdef N.ndarray[realtype, ndim=1, mode='c'] x=N.empty(n)
memcpy(x.data, v_data, n*sizeof(realtype))
memcpy(PyArray_DATA(x), v_data, n*sizeof(realtype))
return x

cdef inline void nv2arr_inplace(N_Vector v, N.ndarray o):
cdef long int n = (<N_VectorContent_Serial>v.content).length
cdef realtype* v_data = (<N_VectorContent_Serial>v.content).data
memcpy(o.data, v_data, n*sizeof(realtype))
memcpy(PyArray_DATA(o), v_data, n*sizeof(realtype))

cdef inline void nv2mat_inplace(int Ns, N_Vector *v, N.ndarray o):
cdef long int i,j, Nf
Expand All @@ -73,5 +73,5 @@ cdef inline void nv2mat_inplace(int Ns, N_Vector *v, N.ndarray o):
cdef inline realtype2arr(realtype *data, int n):
"""Create new numpy array from realtype*"""
cdef N.ndarray[realtype, ndim=1, mode='c'] x=N.empty(n)
memcpy(x.data, data, n*sizeof(realtype))
memcpy(PyArray_DATA(x), data, n*sizeof(realtype))
return x
4 changes: 2 additions & 2 deletions thirdparty/hairer/radau5_c_py.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ cdef void c2py(np.ndarray[double, ndim=1, mode='c'] dest, double* source, int di
"""
Copy (double *) C vector to 1D numpy array
"""
memcpy(dest.data, source, dim*sizeof(double))
memcpy(PyArray_DATA(dest), source, dim*sizeof(double))

@cython.boundscheck(False)
@cython.wraparound(False)
cdef void c2py_mat_F(np.ndarray[double, ndim=2, mode='fortran'] dest, double* source, int dim):
"""
Copy (double *) C matrix (Fotran-style column major ordering) to 2D numpy array
"""
memcpy(dest.data, source, dim*sizeof(double))
memcpy(PyArray_DATA(dest), source, dim*sizeof(double))

cdef int callback_fcn(integer* n, doublereal* x, doublereal* y_in, doublereal* y_out,
doublereal* rpar, integer* ipar, void* fcn_PY):
Expand Down

0 comments on commit dcd1be3

Please sign in to comment.