Ticket #12289: trac_12289-evalf_dictionary_rebase.patch

File trac_12289-evalf_dictionary_rebase.patch, 4.2 KB (added by benjaminfjones, 7 years ago)

rebase to sage-5.0 + pynac-0.2.4 spkg

  • sage/symbolic/expression.pyx

    # HG changeset patch
    # User Jean-Pierre Flori <jean-pierre.flor@ssi.gouv.fr>
    # Date 1337847098 -7200
    # Node ID f32794ad03dd6ed0746db26b586f83bb9cc5933a
    # Parent  319b0d196dded363524beddbccbda00c933c0146
    trac 12289: convert parent keyword argument of _evalf_() to an arbitrary dict
    
    Custom evaluation methods defined in symbolic functions only accept parent as
    a keyword argument. This framework does not allow the user to select different
    systems for the numeric evaluation of a function.
    
    Pynac passes around a Python object around during numeric evaluation. This
    patch, along with the corresponding changes in Pynac, makes this object an
    arbitrary dict. This dictionary can later be used to pass around different
    options relevant for numeric evaluation.
    
    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    828828        """
    829829        cdef GEx res
    830830        try:
    831             res = self._gobj.evalf(0, R)
     831            res = self._gobj.evalf(0, {'parent':R})
    832832        except TypeError as err:
    833833            # try the evaluation again with the complex field
    834834            # corresponding to the parent R
     
    839839                    R_complex = R.complex_field()
    840840                except (TypeError, AttributeError):
    841841                    raise err
    842             res = self._gobj.evalf(0, R_complex)
     842            res = self._gobj.evalf(0, {'parent':R})
    843843        if is_a_numeric(res):
    844844            return R(py_object_from_numeric(res))
    845845        else:
     
    888888            sage: f._convert(int)
    889889            -0.989992496600445*sqrt(2)
    890890        """
    891         cdef GEx res = self._gobj.evalf(0, R)
     891        cdef GEx res = self._gobj.evalf(0, {'parent':R})
    892892        return new_Expression_from_GEx(self._parent, res)
    893893
    894894    def _mpfr_(self, R):
  • sage/symbolic/pynac.pyx

    diff --git a/sage/symbolic/pynac.pyx b/sage/symbolic/pynac.pyx
    a b  
    10821082    """
    10831083    return py_is_cinteger(x)
    10841084
    1085 cdef public object py_float(object n, PyObject* parent) except +:
     1085cdef public object py_float(object n, object kwds) except +:
    10861086    """
    10871087    Evaluate pynac numeric objects numerically.
    10881088
    10891089    TESTS::
    10901090
    10911091        sage: from sage.symbolic.pynac import py_float_for_doctests as py_float
    1092         sage: py_float(I, ComplexField(10))
     1092        sage: py_float(I, {'parent':ComplexField(10)})
    10931093        1.0*I
    1094         sage: py_float(pi, RealField(100))
     1094        sage: py_float(pi, {'parent':RealField(100)})
    10951095        3.1415926535897932384626433833
    10961096        sage: py_float(10, CDF)
    10971097        10.0
    1098         sage: type(py_float(10, CDF))
     1098        sage: type(py_float(10, {'parent':CDF}))
    10991099        <type 'sage.rings.complex_double.ComplexDoubleElement'>
    1100         sage: py_float(1/2, CC)
     1100        sage: py_float(1/2, {'parent':CC}))
    11011101        0.500000000000000
    1102         sage: type(py_float(1/2, CC))
     1102        sage: type(py_float(1/2, {'parent':CC}))
    11031103        <type 'sage.rings.complex_number.ComplexNumber'>
    11041104    """
    1105     if parent is not NULL:
    1106         return (<object>parent)(n)
     1105    if 'parent' in kwds:
     1106        return kwds['parent'](n)
    11071107    else:
    11081108        try:
    11091109            return RR(n)
    11101110        except TypeError:
    11111111            return CC(n)
    11121112
    1113 def py_float_for_doctests(n, prec):
     1113def py_float_for_doctests(n, kwds):
    11141114    """
    11151115    This function is for testing py_float.
    11161116
    11171117    EXAMPLES::
    1118        
     1118
    11191119        sage: from sage.symbolic.pynac import py_float_for_doctests
    1120         sage: py_float_for_doctests(pi, RealField(80))
     1120        sage: py_float_for_doctests(pi, {'parent':RealField(80)})
    11211121        3.1415926535897932384626
    11221122    """
    1123     return py_float(n, <PyObject*>prec)
     1123    return py_float(n, kwds)
    11241124
    11251125# TODO: Optimize this
    11261126from sage.rings.real_double import RDF
     
    18951895        pc = c._pynac
    18961896        return pc.object
    18971897
    1898 cdef public object py_eval_constant(unsigned serial, object parent) except +:
     1898cdef public object py_eval_constant(unsigned serial, object kwds) except +:
    18991899    from sage.symbolic.constants import constants_table
    19001900    constant = constants_table[serial]
    1901     return parent(constant)
     1901    return kwds['parent'](constant)
    19021902
    19031903cdef public object py_eval_unsigned_infinity() except +:
    19041904    """