@@ -3035,7 +3035,6 @@ def has_symbol(obj, symbol=None):
3035
3035
IF HAVE_NUMPY:
3036
3036
# Lambdify requires NumPy (since b713a61, see gh-112)
3037
3037
import os
3038
- cimport numpy as cnp
3039
3038
import numpy as np
3040
3039
have_numpy = True
3041
3040
@@ -3181,29 +3180,26 @@ IF HAVE_NUMPY:
3181
3180
raise ValueError (" Not supported" )
3182
3181
3183
3182
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,
3186
3184
int inp_offset = 0 , int out_offset = 0 ):
3187
3185
raise ValueError (" Not supported" )
3188
3186
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,
3192
3188
int inp_offset = 0 , int out_offset = 0 ):
3193
3189
raise ValueError (" Not supported" )
3194
3190
3195
3191
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):
3198
3194
if inp.size != self .args_size:
3199
3195
raise ValueError (" Size of inp incompatible with number of args." )
3200
3196
if out.size != self .tot_out_size:
3201
3197
raise ValueError (" Size of out incompatible with number of exprs." )
3202
3198
self .unsafe_real(inp, out)
3203
3199
3204
3200
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):
3207
3203
if inp.size != self .args_size:
3208
3204
raise ValueError (" Size of inp incompatible with number of args." )
3209
3205
if out.size != self .tot_out_size:
@@ -3228,19 +3224,18 @@ IF HAVE_NUMPY:
3228
3224
3229
3225
"""
3230
3226
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
3235
3227
bint reshape_outs
3236
3228
size_t idx, new_tot_out_size, nbroadcast = 1
3237
3229
long inp_size
3238
3230
tuple inp_shape
3231
+ double [::1 ] real_out, real_inp
3232
+ double complex [::1 ] cmplx_out, cmplx_inp
3239
3233
try :
3240
3234
inp = np.ascontiguousarray(inp, dtype = self .numpy_dtype)
3241
3235
except TypeError :
3242
3236
inp = np.fromiter(inp, dtype = self .numpy_dtype)
3243
3237
inp_shape = inp.shape
3238
+
3244
3239
if self .real:
3245
3240
real_inp = inp.ravel()
3246
3241
else :
@@ -3258,10 +3253,6 @@ IF HAVE_NUMPY:
3258
3253
new_out_shapes = [inp_shape[:- 1 ] + out_shape for out_shape in self .out_shapes]
3259
3254
reshape_outs = len (new_out_shapes[0 ]) > 1
3260
3255
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
3265
3256
else :
3266
3257
reshape_outs = False
3267
3258
if out.size < new_tot_out_size:
@@ -3270,15 +3261,12 @@ IF HAVE_NUMPY:
3270
3261
raise ValueError (" Output argument needs to be C-contiguous" )
3271
3262
if not out.flags[' WRITEABLE' ]:
3272
3263
raise ValueError (" Output argument needs to be writeable" )
3264
+ out = out.ravel()
3273
3265
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
3282
3270
3283
3271
if self .real:
3284
3272
for idx in range (nbroadcast):
@@ -3315,16 +3303,10 @@ IF HAVE_NUMPY:
3315
3303
self .lambda_double_complex.resize(1 )
3316
3304
self .lambda_double_complex[0 ].init(args_, outs_)
3317
3305
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 ):
3322
3307
self .lambda_double[0 ].call(& out[out_offset], & inp[inp_offset])
3323
3308
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 ):
3328
3310
self .lambda_double_complex[0 ].call(& out[out_offset], & inp[inp_offset])
3329
3311
3330
3312
@@ -3337,10 +3319,7 @@ IF HAVE_NUMPY:
3337
3319
self .lambda_double.resize(1 )
3338
3320
self .lambda_double[0 ].init(args_, outs_)
3339
3321
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 ):
3344
3323
self .lambda_double[0 ].call(& out[out_offset], & inp[inp_offset])
3345
3324
3346
3325
0 commit comments