Ticket #12950: trac_12950-pickle_symbolic_function-trac.patch

File trac_12950-pickle_symbolic_function-trac.patch, 2.9 KB (added by jpflori, 8 years ago)
  • sage/libs/ginac/decl.pxi

    # HG changeset patch
    # User Burcin Erocal <burcin@erocal.org>
    # Date 1336925968 -7200
    # Node ID 6eda1f634b03c9b725a1bacd854d85b1aa22df90
    # Parent  e08fa8bc2c8966d878f7dda5b857d26b6e759b95
    Trac #12950: Fix unarchiving of symbolic functions defined at runtime without
                 any custom methods.
    
    diff --git a/sage/libs/ginac/decl.pxi b/sage/libs/ginac/decl.pxi
    a b  
    505505
    506506        object py_get_sfunction_from_serial(unsigned s) except +
    507507        unsigned py_get_serial_from_sfunction(object f) except +
     508        unsigned py_get_serial_for_new_sfunction(stdstring &s, unsigned nargs) \
     509                except +
    508510
    509511        stdstring* py_print_function(unsigned id, object args) except +
    510512        stdstring* py_latex_function(unsigned id, object args) except +
  • sage/symbolic/pynac.pyx

    diff --git a/sage/symbolic/pynac.pyx b/sage/symbolic/pynac.pyx
    a b  
    570570    return loads(s)
    571571
    572572cdef public object py_get_sfunction_from_serial(unsigned s) except +:
     573    """
     574    Return the python object
     575    """
    573576    return get_sfunction_from_serial(s)
    574577
    575578cdef public unsigned py_get_serial_from_sfunction(object f) except +:
     579    """
     580    Given a Function object return its serial.
     581
     582    Python's unpickling mechanism is used to unarchive a symbolic function with
     583    custom methods (evaluation, differentiation, etc.). Pynac extracts a string
     584    representation from the archive, calls loads() to recreate the stored
     585    function. This allows us to extract the serial from the Python object to
     586    set the corresponding member variable of the C++ object representing this
     587    function.
     588    """
    576589    return (<Function>f)._serial
    577590
     591cdef public unsigned py_get_serial_for_new_sfunction(stdstring &s,
     592        unsigned nargs) except +:
     593    """
     594    Return a symbolic function with the given name and number of arguments.
     595
     596    When unarchiving a user defined symbolic function, Pynac goes through
     597    the registry of existing functions. If there is no function already defined
     598    with the archived name and number of arguments, this method is called to
     599    create one and set up the function tables properly.
     600    """
     601    from sage.symbolic.function_factory import function_factory
     602    cdef Function fn = function_factory(s.c_str(), nargs)
     603    return fn._serial
     604
     605
    578606#################################################################
    579607# Modular helpers
    580608#################################################################
     
    20992127    py_funcs.py_get_ginac_serial = &py_get_ginac_serial
    21002128    py_funcs.py_get_sfunction_from_serial = &py_get_sfunction_from_serial
    21012129    py_funcs.py_get_serial_from_sfunction = &py_get_serial_from_sfunction
     2130    py_funcs.py_get_serial_for_new_sfunction = &py_get_serial_for_new_sfunction
    21022131
    21032132    py_funcs.py_get_constant = &py_get_constant
    21042133    py_funcs.py_print_fderivative =  &py_print_fderivative