@@ -4365,7 +4365,7 @@ cdef class _Lambdify(object):
4365
4365
cdef list out_shapes
4366
4366
cdef readonly bint real
4367
4367
cdef readonly int n_exprs
4368
- cdef readonly str order
4368
+ cdef public str order
4369
4369
cdef vector[int ] accum_out_sizes
4370
4370
cdef object numpy_dtype
4371
4371
@@ -4440,7 +4440,7 @@ cdef class _Lambdify(object):
4440
4440
raise ValueError (" Size of out incompatible with number of exprs." )
4441
4441
self .unsafe_complex(inp, out)
4442
4442
4443
- def __call__ (self , inp , *, out = None , order = None ):
4443
+ def __call__ (self , inp , *, out = None ):
4444
4444
"""
4445
4445
Parameters
4446
4446
----------
@@ -4469,9 +4469,7 @@ cdef class _Lambdify(object):
4469
4469
tuple inp_shape
4470
4470
double [::1 ] real_out, real_inp
4471
4471
double complex [::1 ] cmplx_out, cmplx_inp
4472
- if order is None :
4473
- order = self .order
4474
- if order not in (' C' , ' F' ):
4472
+ if self .order not in (' C' , ' F' ):
4475
4473
raise NotImplementedError (" Only C & F order supported for now." )
4476
4474
4477
4475
try :
@@ -4480,22 +4478,22 @@ cdef class _Lambdify(object):
4480
4478
inp = np.fromiter(inp, dtype = self .numpy_dtype)
4481
4479
4482
4480
if self .real:
4483
- real_inp = np.ascontiguousarray(inp.ravel(order = order))
4481
+ real_inp = np.ascontiguousarray(inp.ravel(order = self . order))
4484
4482
else :
4485
- cmplx_inp = np.ascontiguousarray(inp.ravel(order = order))
4483
+ cmplx_inp = np.ascontiguousarray(inp.ravel(order = self . order))
4486
4484
4487
4485
if inp.size < self .args_size or inp.size % self .args_size != 0 :
4488
4486
raise ValueError (" Broadcasting failed (input/arg size mismatch)" )
4489
4487
nbroadcast = inp.size // self .args_size
4490
4488
4491
4489
if inp.ndim > 1 :
4492
4490
if self .args_size > 1 :
4493
- if order == ' C' :
4491
+ if self . order == ' C' :
4494
4492
if inp.shape[inp.ndim- 1 ] != self .args_size:
4495
4493
raise ValueError ((" C order implies last dim (%d ) == len(args)"
4496
4494
" (%d )" ) % (inp.shape[inp.ndim- 1 ], self .args_size))
4497
4495
extra_dim = inp.shape[:inp.ndim- 1 ]
4498
- elif order == ' F' :
4496
+ elif self . order == ' F' :
4499
4497
if inp.shape[0 ] != self .args_size:
4500
4498
raise ValueError (" F order implies first dim (%d ) == len(args) (%d )"
4501
4499
% (inp.shape[0 ], self .args_size))
@@ -4507,35 +4505,37 @@ cdef class _Lambdify(object):
4507
4505
extra_dim = (nbroadcast,) # special case
4508
4506
else :
4509
4507
extra_dim = ()
4510
- extra_left = extra_dim if order == ' C' else ()
4511
- extra_right = () if order == ' C' else extra_dim
4508
+ extra_left = extra_dim if self . order == ' C' else ()
4509
+ extra_right = () if self . order == ' C' else extra_dim
4512
4510
new_out_shapes = [extra_left + out_shape + extra_right
4513
4511
for out_shape in self .out_shapes]
4514
4512
4515
4513
new_tot_out_size = nbroadcast * self .tot_out_size
4516
4514
if out is None :
4517
- out = np.empty(new_tot_out_size, dtype = self .numpy_dtype, order = order)
4515
+ out = np.empty(new_tot_out_size, dtype = self .numpy_dtype, order = self . order)
4518
4516
else :
4519
4517
if out.size < new_tot_out_size:
4520
4518
raise ValueError (" Incompatible size of output argument" )
4521
4519
if out.ndim > 1 :
4522
- if order == ' C' and not out.flags[' C_CONTIGUOUS' ]:
4523
- raise ValueError (" Output argument needs to be C-contiguous" )
4524
- elif order == ' F' and not out.flags[' F_CONTIGUOUS' ]:
4525
- raise ValueError (" Output argument needs to be F-contiguous" )
4526
4520
if len (self .out_shapes) > 1 :
4527
4521
raise ValueError (" output array with ndim > 1 assumes one output" )
4528
4522
out_shape, = self .out_shapes
4529
- if order == ' C' and out.shape[- len (out_shape):] != tuple (out_shape):
4530
- raise ValueError (" shape mismatch for output array" )
4531
- elif order == ' F' and out.shape[:len (out_shape)] != tuple (out_shape):
4532
- raise ValueError (" shape mismatch for output array" )
4523
+ if self .order == ' C' :
4524
+ if not out.flags[' C_CONTIGUOUS' ]:
4525
+ raise ValueError (" Output argument needs to be C-contiguous" )
4526
+ if out.shape[- len (out_shape):] != tuple (out_shape):
4527
+ raise ValueError (" shape mismatch for output array" )
4528
+ elif self .order == ' F' :
4529
+ if not out.flags[' F_CONTIGUOUS' ]:
4530
+ raise ValueError (" Output argument needs to be F-contiguous" )
4531
+ if out.shape[:len (out_shape)] != tuple (out_shape):
4532
+ raise ValueError (" shape mismatch for output array" )
4533
4533
else :
4534
4534
if not out.flags[' F_CONTIGUOUS' ]: # or C_CONTIGUOUS (ndim <= 1)
4535
4535
raise ValueError (" Output array need to be contiguous" )
4536
4536
if not out.flags[' WRITEABLE' ]:
4537
4537
raise ValueError (" Output argument needs to be writeable" )
4538
- out = out.ravel(order = order)
4538
+ out = out.ravel(order = self . order)
4539
4539
4540
4540
if self .real:
4541
4541
real_out = out
@@ -4551,13 +4551,13 @@ cdef class _Lambdify(object):
4551
4551
self .unsafe_complex(cmplx_inp, cmplx_out,
4552
4552
idx* self .args_size, idx* self .tot_out_size)
4553
4553
4554
- if order == ' C' :
4554
+ if self . order == ' C' :
4555
4555
out = out.reshape((nbroadcast, self .tot_out_size), order = ' C' )
4556
4556
result = [
4557
4557
out[:, self .accum_out_sizes[idx]:self .accum_out_sizes[idx+ 1 ]].reshape(
4558
4558
new_out_shapes[idx], order = ' C' ) for idx in range (self .n_exprs)
4559
4559
]
4560
- elif order == ' F' :
4560
+ elif self . order == ' F' :
4561
4561
out = out.reshape((self .tot_out_size, nbroadcast), order = ' F' )
4562
4562
result = [
4563
4563
out[self .accum_out_sizes[idx]:self .accum_out_sizes[idx+ 1 ], :].reshape(
@@ -4657,16 +4657,15 @@ def LambdifyCSE(args, *exprs, cse=None, order='C', **kwargs):
4657
4657
new_lmb = Lambdify(tuple (_args) + cse_symbs, * new_exprs, order = order, ** kwargs)
4658
4658
cse_lambda = Lambdify(_args, [ce.xreplace(explicit_subs) for ce in cse_exprs], ** kwargs)
4659
4659
def cb (inp , *, out = None , **kw ):
4660
- _order = kw.pop(' order' , order)
4661
4660
_inp = np.asanyarray(inp)
4662
- cse_vals = cse_lambda(_inp, order = _order, ** kw)
4661
+ cse_vals = cse_lambda(_inp, ** kw)
4663
4662
if order == ' C' :
4664
4663
new_inp = np.concatenate((_inp[(Ellipsis ,) + (np.newaxis,)* (cse_vals.ndim - _inp.ndim)],
4665
4664
cse_vals), axis = - 1 )
4666
4665
else :
4667
4666
new_inp = np.concatenate((_inp[(np.newaxis,)* (cse_vals.ndim - _inp.ndim) + (Ellipsis ,)],
4668
4667
cse_vals), axis = 0 )
4669
- return new_lmb(new_inp, out = out, order = _order, ** kw)
4668
+ return new_lmb(new_inp, out = out, ** kw)
4670
4669
return cb
4671
4670
else :
4672
4671
return Lambdify(args, * exprs, ** kwargs)
0 commit comments