symengine / symengine.py

Python wrappers for SymEngine
MIT License
167 stars 64 forks source link

Subclassed Symbols that define `__getitem__` break `DenseMatrix` #485

Open bocklund opened 3 months ago

bocklund commented 3 months ago

Here's a self-contained test

from symengine import Symbol, DenseMatrix
class MySymbol(Symbol):
    def __getitem__(self, x):
        pass
x = Symbol("x")
y = MySymbol("y")
DenseMatrix([x])  # works fine
DenseMatrix([y])  # SIGSEGV

In PyCalphad (https://github.com/pycalphad/pycalphad/issues/547), we have something where __getitem__ returns, effectively, a new MySymbol, and think ends up in some loop where MySymbol keeps getting created and eats all the system memory.

isuruf commented 3 months ago

You'll have to do DenseMatrix([[y]]) as a workaround.

bocklund commented 3 months ago

Thank you, I think this is working for my immediate need