# 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
|
|
505 | 505 | |
506 | 506 | object py_get_sfunction_from_serial(unsigned s) except + |
507 | 507 | unsigned py_get_serial_from_sfunction(object f) except + |
| 508 | unsigned py_get_serial_for_new_sfunction(stdstring &s, unsigned nargs) \ |
| 509 | except + |
508 | 510 | |
509 | 511 | stdstring* py_print_function(unsigned id, object args) except + |
510 | 512 | stdstring* py_latex_function(unsigned id, object args) except + |
diff --git a/sage/symbolic/pynac.pyx b/sage/symbolic/pynac.pyx
a
|
b
|
|
570 | 570 | return loads(s) |
571 | 571 | |
572 | 572 | cdef public object py_get_sfunction_from_serial(unsigned s) except +: |
| 573 | """ |
| 574 | Return the python object |
| 575 | """ |
573 | 576 | return get_sfunction_from_serial(s) |
574 | 577 | |
575 | 578 | cdef 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 | """ |
576 | 589 | return (<Function>f)._serial |
577 | 590 | |
| 591 | cdef 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 | |
578 | 606 | ################################################################# |
579 | 607 | # Modular helpers |
580 | 608 | ################################################################# |
… |
… |
|
2099 | 2127 | py_funcs.py_get_ginac_serial = &py_get_ginac_serial |
2100 | 2128 | py_funcs.py_get_sfunction_from_serial = &py_get_sfunction_from_serial |
2101 | 2129 | 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 |
2102 | 2131 | |
2103 | 2132 | py_funcs.py_get_constant = &py_get_constant |
2104 | 2133 | py_funcs.py_print_fderivative = &py_print_fderivative |