These are chat archives for symengine/symengine

13th
Aug 2014
Nikolaus Sonnenschein
@phantomas1234
Aug 13 2014 08:13

I am using sympy for a project where I am extending Symbol with a few extras. I was trying to see if I could switch over to csympy but I am having troubles with inheritance. For example (works fine with sympy)

from csympy import Symbol
class ChildSymbol(Symbol):
    def __init__(self, name, lb=None, ub=None):
        Symbol.__init__(name)
        self.lb = lb
        self.ub = None
child = ChildSymbol('a', lb=-10, ub=10)

will raise

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-26-bcfa3d993935> in <module>()
      5         self.lb = lb
      6         self.ub = None
----> 7 child = ChildSymbol('a', lb=-10, ub=10)

/Users/niko/Arbejder/Dev/csympy/build/csympy/lib/csympy_wrapper.so in csympy.lib.csympy_wrapper.Symbol.__cinit__ (/Users/niko/Arbejder/Dev/csympy/build/csympy/lib/csympy_wrapper.cpp:4975)()

TypeError: __cinit__() got an unexpected keyword argument 'lb'

I am aware that inheritance is tricky in Cython (see for example http://stackoverflow.com/questions/18260095/cant-override-init-of-class-from-cython-extension and others). Does anyone maybe have a suggestion for how to circumvent that arguments are passed on to cinit? I am sorry if this is not an appropriate place to ask.

Ondřej Čertík
@certik
Aug 13 2014 19:54
Hi @phantomas1234 yes, it's an appropriate place to ask. I think @asmeurer mentioned on the list that you might want to do things differently. As to this particular issue, there might be some workaround in Cython, though I don't know myself. You could of course extend csympy in C++, and then wrap that.
What exactly is your application?
Aaron Meurer
@asmeurer
Aug 13 2014 19:56
so do you just need to override __cinit__?