@@ -2604,6 +2604,7 @@ cdef class Lambdify(object):
2604
2604
def __cinit__ (self , args , exprs , bool real = True ):
2605
2605
cdef:
2606
2606
symengine.vec_basic args_
2607
+ symengine.vec_basic outs_
2607
2608
Basic e_
2608
2609
size_t ri, ci, nr, nc
2609
2610
symengine.MatrixBase * mtx
@@ -2626,63 +2627,40 @@ cdef class Lambdify(object):
2626
2627
e_ = sympify(e)
2627
2628
args_.push_back(e_.thisptr)
2628
2629
2629
- if self .real:
2630
- self .lambda_double.resize(self .out_size)
2631
- else :
2632
- self .lambda_double_complex.resize(self .out_size)
2633
-
2634
2630
if isinstance (exprs, DenseMatrix):
2635
2631
nr = exprs.nrows()
2636
2632
nc = exprs.ncols()
2637
2633
mtx = (< DenseMatrix> exprs).thisptr
2638
2634
for ri in range (nr):
2639
2635
for ci in range (nc):
2640
2636
b_ = deref(mtx).get(ri, ci)
2641
- if real:
2642
- self .lambda_double[ri* nc+ ci].init(args_, deref(b_))
2643
- else :
2644
- self .lambda_double_complex[ri* nc+ ci].init(args_, deref(b_))
2637
+ outs_.push_back(b_)
2645
2638
else :
2646
2639
for e in ravel(exprs):
2647
2640
e_ = sympify(e)
2648
- if real:
2649
- self .lambda_double[idx].init(args_, deref(e_.thisptr))
2650
- else :
2651
- self .lambda_double_complex[idx].init(args_, deref(e_.thisptr))
2652
- idx += 1
2641
+ outs_.push_back(e_.thisptr)
2642
+
2643
+ if real:
2644
+ self .lambda_double.resize(1 )
2645
+ self .lambda_double[0 ].init(args_, outs_)
2646
+ else :
2647
+ self .lambda_double_complex.resize(1 )
2648
+ self .lambda_double_complex[0 ].init(args_, outs_)
2649
+
2653
2650
2654
2651
cdef void _eval(self , ValueType[::1 ] inp, ValueType[::1 ] out):
2655
- cdef vector[ValueType] inp_
2656
2652
cdef size_t idx, ninp = inp.size, nout = out.size
2657
2653
2658
2654
if inp.size != self .args_size:
2659
2655
raise ValueError (" Size of inp incompatible with number of args." )
2660
2656
if out.size != self .out_size:
2661
2657
raise ValueError (" Size of out incompatible with number of exprs." )
2662
2658
2663
- # Create the substitution "dict"
2664
- for idx in range (ninp):
2665
- inp_.push_back(inp[idx])
2666
-
2667
2659
# Convert expr_subs to doubles write to out
2668
2660
if ValueType == cython.double:
2669
- self .as_real(inp_, out )
2661
+ self .lambda_double[ 0 ].call( & out[ 0 ], & inp[ 0 ] )
2670
2662
else :
2671
- self .as_complex(inp_, out)
2672
-
2673
- @ cython.wraparound (False )
2674
- @ cython.boundscheck (False )
2675
- cdef void as_real(self , vector[double ] & vec, double [::1 ] out) nogil:
2676
- cdef size_t i
2677
- for i in range (self .out_size):
2678
- out[i] = self .lambda_double[i].call(vec)
2679
-
2680
- @ cython.wraparound (False )
2681
- @ cython.boundscheck (False )
2682
- cdef void as_complex(self , vector[double complex ] & vec, double complex [::1 ] out) nogil:
2683
- cdef size_t i
2684
- for i in range (self .out_size):
2685
- out[i] = self .lambda_double_complex[i].call(vec)
2663
+ self .lambda_double_complex[0 ].call(& out[0 ], & inp[0 ])
2686
2664
2687
2665
# the two cpdef:ed methods below may use void return type
2688
2666
# once Cython 0.23 (from 2015) is acceptable as requirement.
0 commit comments