@@ -4369,7 +4369,7 @@ cdef class _Lambdify(object):
4369
4369
cdef vector[int ] accum_out_sizes
4370
4370
cdef object numpy_dtype
4371
4371
4372
- def __init__ (self , args , *exprs , cppbool real = True , order = ' C' , cppbool cse = False ):
4372
+ def __init__ (self , args , *exprs , cppbool real = True , order = ' C' , cppbool cse = False , cppbool load = False ):
4373
4373
cdef:
4374
4374
Basic e_
4375
4375
size_t ri, ci, nr, nc
@@ -4378,6 +4378,13 @@ cdef class _Lambdify(object):
4378
4378
symengine.vec_basic args_, outs_
4379
4379
vector[int ] out_sizes
4380
4380
4381
+ if load:
4382
+ self .args_size, self .tot_out_size, self .out_shapes, self .real, \
4383
+ self .n_exprs, self .order, self .accum_out_sizes, self .numpy_dtype, \
4384
+ llvm_function = args
4385
+ self ._load(llvm_function)
4386
+ return
4387
+
4381
4388
args = np.asanyarray(args)
4382
4389
self .args_size = args.size
4383
4390
exprs = tuple (np.asanyarray(expr) for expr in exprs)
@@ -4414,6 +4421,9 @@ cdef class _Lambdify(object):
4414
4421
cdef _init(self , symengine.vec_basic& args_, symengine.vec_basic& outs_, cppbool cse):
4415
4422
raise ValueError (" Not supported" )
4416
4423
4424
+ cdef _load(self , const string & s):
4425
+ raise ValueError (" Not supported" )
4426
+
4417
4427
cpdef unsafe_real(self ,
4418
4428
double [::1 ] inp, double [::1 ] out,
4419
4429
int inp_offset = 0 , int out_offset = 0 ):
@@ -4625,6 +4635,18 @@ IF HAVE_SYMENGINE_LLVM:
4625
4635
self .lambda_double.resize(1 )
4626
4636
self .lambda_double[0 ].init(args_, outs_, cse)
4627
4637
4638
+ cdef _load(self , const string & s):
4639
+ self .lambda_double.resize(1 )
4640
+ self .lambda_double[0 ].loads(s)
4641
+
4642
+ def __reduce__ (self ):
4643
+ """
4644
+ Interface for pickle. Note that the resulting object is platform dependent.
4645
+ """
4646
+ cdef bytes s = self .lambda_double[0 ].dumps()
4647
+ return llvm_loading_func, (self .args_size, self .tot_out_size, self .out_shapes, self .real, \
4648
+ self .n_exprs, self .order, self .accum_out_sizes, self .numpy_dtype, s)
4649
+
4628
4650
cpdef unsafe_real(self , double [::1 ] inp, double [::1 ] out, int inp_offset = 0 , int out_offset = 0 ):
4629
4651
self .lambda_double[0 ].call(& out[out_offset], & inp[inp_offset])
4630
4652
@@ -4639,6 +4661,8 @@ IF HAVE_SYMENGINE_LLVM:
4639
4661
addr2 = cast(< size_t> & self .lambda_double[0 ], c_void_p)
4640
4662
return create_low_level_callable(self , addr1, addr2)
4641
4663
4664
+ def llvm_loading_func (*args ):
4665
+ return LLVMDouble(args, load = True )
4642
4666
4643
4667
def Lambdify (args , *exprs , cppbool real = True , backend = None , order = ' C' , as_scipy = False , cse = False ):
4644
4668
"""
0 commit comments