Sympy `Function` objects cause errors

Issue #79 resolved
Colin Macdonald created an issue

@nvs232 brought this up on the maillist.

Consider the following Python object (example needs Sympy).

>> myexpr = py.sympy.S ('f(x)')
myexpr = [pyobject 0x7f6105f55908]

  f(x)

Various operations on myexpr give a pyexec conversion error:

>> py.str (myexpr)
error: pyexec: error in return value type conversion
error: called from
    subsref at line 59 column 9
    subsref at line 56 column 7

(expected value is a python string 'f(x)').

Some python output that might be relevant:

>>> sympy.srepr(myexpr)

"Function('f')(Symbol('x'))"

>>> type(myexpr)

f

Perhaps the strange return from type is confusing things? These sympy.Function objects are a bit strange IIRC. Perhaps subsref is trying to deal with the (x) part? Anyway, there is something we're not doing quiet right.

Comments (6)

  1. NVS Abhilash

    @mtmiller Can you check by reproducing these errors. Can you reproduce the same results? This is what I am getting:

    octave:1> myexpr = py.sympy.S ('f(x)')
    terminate called after throwing an instance of 'pytave::object_convert_exception'
    panic: Aborted -- stopping myself...
    attempting to save variables to 'octave-workspace'...
    error: octave_base_value::save_binary(): wrong type argument 'object'
    terminate called recursively
    panic: attempted clean up failed -- aborting...
    Aborted (core dumped)
    

    This is with the latest pull. I think I was able to reproduce the same results sometime before when this issue was reported. Is it due to some recent changes?

  2. Mike Miller repo owner

    I think it might be due to recent changes in the display method. If you avoid that (by always ending with a semicolon), it works as the original submission:

    >> x = py.sympy.S ("f(x)");
    >> char (x)
    ans = f(x)
    >> py.str (x)
    error: pyexec: error in return value type conversion
    error: called from
        subsref at line 58 column 9
        subsref at line 56 column 7
    
  3. Mike Miller repo owner

    Fix extraction of class name for Python types without a module (fixes issue #79)

    • oct-py-util.cc (pytave::py_object_class_name): Handle object types with module set to None, just return the value of name.
    • py_struct_from_dict.cc (Fpy_class_name): Add test case.

    → <<cset 668fcb0f68ef>>

  4. Mike Miller repo owner

    This problem turned out to be extremely easy to debug and add a fix for.

    @macdonald I now get only one test failure with sympref ipc native; octsympy_tests, if we can address that we have a good base of equivalent functionality now.

  5. Colin Macdonald reporter

    extremely easy to debug and add a fix for.

    maybe for you ;-) By which I mean, thank you!

  6. Mike Miller repo owner

    Fix extraction of class name for Python types without a module (fixes issue #79)

    • oct-py-util.cc (pytave::py_object_class_name): Handle object types with module set to None, just return the value of name.
    • py_struct_from_dict.cc (Fpy_class_name): Add test case.

    → <<cset 668fcb0f68ef>>

  7. Log in to comment