symengine.py icon indicating copy to clipboard operation
symengine.py copied to clipboard

Better compatibility with sympy ImmutableMatrix (fixes #363)

Open rikardn opened this issue 3 years ago • 2 comments

  • simplify Immutable to new Immutable
  • sympy.sympify matrices to Immutable

rikardn avatar Feb 26 '22 17:02 rikardn

Can you paste the output of the following with this PR?

import symengine
import sympy
print(type(symengine.zeros(5) + symengine.zeros(5)))
print(type(sympy.zeros(5) + sympy.zeros(5)))
print(type(symengine.zeros(5) + sympy.zeros(5)))
print(type(sympy.zeros(5) + symengine.zeros(5)))

isuruf avatar Feb 28 '22 00:02 isuruf

Sure:

n [1]: import symengine
   ...: import sympy
   ...: print(type(symengine.zeros(5) + symengine.zeros(5)))
   ...: print(type(sympy.zeros(5) + sympy.zeros(5)))
   ...: print(type(symengine.zeros(5) + sympy.zeros(5)))
   ...: print(type(sympy.zeros(5) + symengine.zeros(5)))
<class 'symengine.lib.symengine_wrapper.MutableDenseMatrix'>
<class 'sympy.matrices.dense.MutableDenseMatrix'>
<class 'symengine.lib.symengine_wrapper.MutableDenseMatrix'>
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-61b037069457> in <module>
      4 print(type(sympy.zeros(5) + sympy.zeros(5)))
      5 print(type(symengine.zeros(5) + sympy.zeros(5)))
----> 6 print(type(sympy.zeros(5) + symengine.zeros(5)))

~/testing/myvenv/lib/python3.8/site-packages/sympy/core/decorators.py in binary_op_wrapper(self, other)
    134                     if f is not None:
    135                         return f(self)
--> 136             return func(self, other)
    137         return binary_op_wrapper
    138     return priority_decorator

~/testing/myvenv/lib/python3.8/site-packages/sympy/matrices/common.py in __add__(self, other)
   2708             # call the highest-priority class's _eval_add
   2709             a, b = self, other
-> 2710             if a.__class__ != classof(a, b):
   2711                 b, a = a, b
   2712             return a._eval_add(b)

~/testing/myvenv/lib/python3.8/site-packages/sympy/matrices/common.py in classof(A, B)
   3283             return A.__class__
   3284 
-> 3285     raise TypeError("Incompatible classes %s, %s" % (A.__class__, B.__class__))

TypeError: Incompatible classes <class 'sympy.matrices.dense.MutableDenseMatrix'>, <class 'symengine.lib.symengine_wrapper.MutableDenseMatrix'>

rikardn avatar Feb 28 '22 20:02 rikardn

Merging without appveyor for now as the queue is long. Will revert if appveyor fails.

Thanks for the PR @rikardn

isuruf avatar Mar 20 '23 22:03 isuruf