Skip to content

Commit 90985ba

Browse files
committed
[skip ci] Try memview
1 parent 756bc26 commit 90985ba

File tree

1 file changed

+17
-38
lines changed

1 file changed

+17
-38
lines changed

symengine/lib/symengine_wrapper.pyx

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,7 +3035,6 @@ def has_symbol(obj, symbol=None):
30353035
IF HAVE_NUMPY:
30363036
# Lambdify requires NumPy (since b713a61, see gh-112)
30373037
import os
3038-
cimport numpy as cnp
30393038
import numpy as np
30403039
have_numpy = True
30413040

@@ -3181,29 +3180,26 @@ IF HAVE_NUMPY:
31813180
raise ValueError("Not supported")
31823181

31833182
cpdef unsafe_real(self,
3184-
cnp.ndarray[cnp.float64_t, ndim=1, mode='c'] inp,
3185-
cnp.ndarray[cnp.float64_t, ndim=1, mode='c'] out,
3183+
double[::1] inp, double[::1] out,
31863184
int inp_offset=0, int out_offset=0):
31873185
raise ValueError("Not supported")
31883186

3189-
cpdef unsafe_complex(self,
3190-
cnp.ndarray[cnp.complex128_t, ndim=1, mode='c'] inp,
3191-
cnp.ndarray[cnp.complex128_t, ndim=1, mode='c'] out,
3187+
cpdef unsafe_complex(self, double complex[::1] inp, double complex[::1] out,
31923188
int inp_offset=0, int out_offset=0):
31933189
raise ValueError("Not supported")
31943190

31953191
cpdef eval_real(self,
3196-
cnp.ndarray[cnp.float64_t, ndim=1, mode='c'] inp,
3197-
cnp.ndarray[cnp.float64_t, ndim=1, mode='c'] out):
3192+
inp,
3193+
out):
31983194
if inp.size != self.args_size:
31993195
raise ValueError("Size of inp incompatible with number of args.")
32003196
if out.size != self.tot_out_size:
32013197
raise ValueError("Size of out incompatible with number of exprs.")
32023198
self.unsafe_real(inp, out)
32033199

32043200
cpdef eval_complex(self,
3205-
cnp.ndarray[cnp.complex128_t, ndim=1, mode='c'] inp,
3206-
cnp.ndarray[cnp.complex128_t, ndim=1, mode='c'] out):
3201+
inp,
3202+
out):
32073203
if inp.size != self.args_size:
32083204
raise ValueError("Size of inp incompatible with number of args.")
32093205
if out.size != self.tot_out_size:
@@ -3228,19 +3224,18 @@ IF HAVE_NUMPY:
32283224
32293225
"""
32303226
cdef:
3231-
cnp.ndarray[cnp.float64_t, ndim=1, mode='c'] real_inp
3232-
cnp.ndarray[cnp.float64_t, ndim=1, mode='c'] real_out
3233-
cnp.ndarray[cnp.complex128_t, ndim=1, mode='c'] cmplx_inp
3234-
cnp.ndarray[cnp.complex128_t, ndim=1, mode='c'] cmplx_out
32353227
bint reshape_outs
32363228
size_t idx, new_tot_out_size, nbroadcast = 1
32373229
long inp_size
32383230
tuple inp_shape
3231+
double[::1] real_out, real_inp
3232+
double complex[::1] cmplx_out, cmplx_inp
32393233
try:
32403234
inp = np.ascontiguousarray(inp, dtype=self.numpy_dtype)
32413235
except TypeError:
32423236
inp = np.fromiter(inp, dtype=self.numpy_dtype)
32433237
inp_shape = inp.shape
3238+
32443239
if self.real:
32453240
real_inp = inp.ravel()
32463241
else:
@@ -3258,10 +3253,6 @@ IF HAVE_NUMPY:
32583253
new_out_shapes = [inp_shape[:-1] + out_shape for out_shape in self.out_shapes]
32593254
reshape_outs = len(new_out_shapes[0]) > 1
32603255
out = np.empty(new_tot_out_size, dtype=self.numpy_dtype)
3261-
if self.real:
3262-
real_out = out
3263-
else:
3264-
cmplx_out = out
32653256
else:
32663257
reshape_outs = False
32673258
if out.size < new_tot_out_size:
@@ -3270,15 +3261,12 @@ IF HAVE_NUMPY:
32703261
raise ValueError("Output argument needs to be C-contiguous")
32713262
if not out.flags['WRITEABLE']:
32723263
raise ValueError("Output argument needs to be writeable")
3264+
out = out.ravel()
32733265

3274-
if self.real:
3275-
real_out = out.ravel()
3276-
if <size_t>real_out.data != out.__array_interface__['data'][0]:
3277-
raise ValueError("out parameter not compatible")
3278-
else:
3279-
cmplx_out = out.ravel()
3280-
if <size_t>cmplx_out.data != out.__array_interface__['data'][0]:
3281-
raise ValueError("out parameter not compatible")
3266+
if self.real:
3267+
real_out = out
3268+
else:
3269+
cmplx_out = out
32823270

32833271
if self.real:
32843272
for idx in range(nbroadcast):
@@ -3315,16 +3303,10 @@ IF HAVE_NUMPY:
33153303
self.lambda_double_complex.resize(1)
33163304
self.lambda_double_complex[0].init(args_, outs_)
33173305

3318-
cpdef unsafe_real(self,
3319-
cnp.ndarray[cnp.float64_t, ndim=1, mode='c'] inp,
3320-
cnp.ndarray[cnp.float64_t, ndim=1, mode='c'] out,
3321-
int inp_offset=0, int out_offset=0):
3306+
cpdef unsafe_real(self, double[::1] inp, double[::1] out, int inp_offset=0, int out_offset=0):
33223307
self.lambda_double[0].call(&out[out_offset], &inp[inp_offset])
33233308

3324-
cpdef unsafe_complex(self,
3325-
cnp.ndarray[cnp.complex128_t, ndim=1, mode='c'] inp,
3326-
cnp.ndarray[cnp.complex128_t, ndim=1, mode='c'] out,
3327-
int inp_offset=0, int out_offset=0):
3309+
cpdef unsafe_complex(self, double complex[::1] inp, double complex[::1] out, int inp_offset=0, int out_offset=0):
33283310
self.lambda_double_complex[0].call(&out[out_offset], &inp[inp_offset])
33293311

33303312

@@ -3337,10 +3319,7 @@ IF HAVE_NUMPY:
33373319
self.lambda_double.resize(1)
33383320
self.lambda_double[0].init(args_, outs_)
33393321

3340-
cpdef unsafe_real(self,
3341-
cnp.ndarray[cnp.float64_t, ndim=1, mode='c'] inp,
3342-
cnp.ndarray[cnp.float64_t, ndim=1, mode='c'] out,
3343-
int inp_offset=0, int out_offset=0):
3322+
cpdef unsafe_real(self, double[::1] inp, double[::1] out, int inp_offset=0, int out_offset=0):
33443323
self.lambda_double[0].call(&out[out_offset], &inp[inp_offset])
33453324

33463325

0 commit comments

Comments
 (0)