@@ -868,14 +868,16 @@ cdef class Basic(object):
868
868
def expand (Basic self not None , cppbool deep = True ):
869
869
return c2py(symengine.expand(self .thisptr, deep))
870
870
871
- def diff (Basic self not None , x = None ):
872
- if x is None :
871
+ def _diff (Basic self not None , Basic x ):
872
+ return c2py(symengine.diff(self .thisptr, x.thisptr))
873
+
874
+ def diff (self , *args ):
875
+ if len (args) == 0 :
873
876
f = self .free_symbols
874
877
if (len (f) != 1 ):
875
878
raise RuntimeError (" Variable w.r.t should be given" )
876
- return self .diff(f.pop())
877
- cdef Basic s = sympify(x)
878
- return c2py(symengine.diff(self .thisptr, s.thisptr))
879
+ return self ._diff(f.pop())
880
+ return diff(self , * args)
879
881
880
882
def subs_dict (Basic self not None , *args ):
881
883
warnings.warn(" subs_dict() is deprecated. Use subs() instead" , DeprecationWarning )
@@ -3430,13 +3432,15 @@ cdef class DenseMatrixBase(MatrixBase):
3430
3432
cdef _DictBasic D = get_dict(* args)
3431
3433
return self .applyfunc(lambda x : x.msubs(D))
3432
3434
3433
- def diff (self , x ):
3434
- cdef Basic x_ = sympify(x)
3435
+ def _diff (self , Basic x ):
3435
3436
cdef DenseMatrixBase R = self .__class__ (self .rows, self .cols)
3436
3437
symengine.diff(< const symengine.DenseMatrix & > deref(self .thisptr),
3437
- x_ .thisptr, < symengine.DenseMatrix & > deref(R.thisptr))
3438
+ x .thisptr, < symengine.DenseMatrix & > deref(R.thisptr))
3438
3439
return R
3439
3440
3441
+ def diff (self , *args ):
3442
+ return diff(self , * args)
3443
+
3440
3444
# TODO: implement this in C++
3441
3445
def subs (self , *args ):
3442
3446
cdef _DictBasic D = get_dict(* args)
@@ -3762,17 +3766,31 @@ cdef class Sieve_iterator:
3762
3766
3763
3767
3764
3768
def module_cleanup ():
3765
- global I, E, pi, oo, minus_oo, zoo, nan, true, false, golden_ratio, catalan, eulergamma, sympy_module, sage_module
3769
+ global I, E, pi, oo, minus_oo, zoo, nan, true, false, golden_ratio, \
3770
+ catalan, eulergamma, sympy_module, sage_module, half, one, \
3771
+ minus_one, zero
3766
3772
funcs.clear()
3767
- del I, E, pi, oo, minus_oo, zoo, nan, true, false, golden_ratio, catalan, eulergamma, sympy_module, sage_module
3773
+ del I, E, pi, oo, minus_oo, zoo, nan, true, false, golden_ratio, \
3774
+ catalan, eulergamma, sympy_module, sage_module, half, one, \
3775
+ minus_one, zero
3768
3776
3769
3777
import atexit
3770
3778
atexit.register(module_cleanup)
3771
3779
3772
- def diff (ex , *x ):
3780
+ def diff (ex , *args ):
3773
3781
ex = sympify(ex)
3774
- for i in x:
3775
- ex = ex.diff(i)
3782
+ prev = 0
3783
+ cdef Basic b
3784
+ cdef size_t i
3785
+ for x in args:
3786
+ b = sympify(x)
3787
+ if isinstance (b, Integer):
3788
+ i = int (b) - 1
3789
+ for j in range (i):
3790
+ ex = ex._diff(prev)
3791
+ else :
3792
+ ex = ex._diff(b)
3793
+ prev = b
3776
3794
return ex
3777
3795
3778
3796
def expand (x , deep = True ):
@@ -4369,7 +4387,7 @@ cdef class _Lambdify(object):
4369
4387
cdef size_t args_size, tot_out_size
4370
4388
cdef list out_shapes
4371
4389
cdef readonly bint real
4372
- cdef readonly int n_exprs
4390
+ cdef readonly size_t n_exprs
4373
4391
cdef public str order
4374
4392
cdef vector[int ] accum_out_sizes
4375
4393
cdef object numpy_dtype
0 commit comments