Ticket #12289: trac_12289-evalf_dictionary_rebase.take2.patch

File trac_12289-evalf_dictionary_rebase.take2.patch, 4.2 KB (added by burcin, 6 years ago)
  • sage/symbolic/expression.pyx

    # HG changeset patch
    # User Jean-Pierre Flori <jean-pierre.flor@ssi.gouv.fr>
    # Date 1337847098 -7200
    #      Thu May 24 10:11:38 2012 +0200
    # Node ID b867edd171d975c718e1efc146d4f0de3a9013da
    # Parent  159247f5892d8a1e321a786e0bee58389e240683
    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  
    943943        """
    944944        cdef GEx res
    945945        try:
    946             res = self._gobj.evalf(0, R)
     946            res = self._gobj.evalf(0, {'parent':R})
    947947        except TypeError as err:
    948948            # try the evaluation again with the complex field
    949949            # corresponding to the parent R
     
    954954                    R_complex = R.complex_field()
    955955                except (TypeError, AttributeError):
    956956                    raise err
    957             res = self._gobj.evalf(0, R_complex)
     957            res = self._gobj.evalf(0, {'parent':R})
    958958        if is_a_numeric(res):
    959959            return R(py_object_from_numeric(res))
    960960        else:
     
    10031003            sage: f._convert(int)
    10041004            -0.989992496600445*sqrt(2)
    10051005        """
    1006         cdef GEx res = self._gobj.evalf(0, R)
     1006        cdef GEx res = self._gobj.evalf(0, {'parent':R})
    10071007        return new_Expression_from_GEx(self._parent, res)
    10081008
    10091009    def _mpfr_(self, R):
  • sage/symbolic/pynac.pyx

    diff --git a/sage/symbolic/pynac.pyx b/sage/symbolic/pynac.pyx
    a b  
    10811081    """
    10821082    return py_is_cinteger(x)
    10831083
    1084 cdef public object py_float(object n, PyObject* parent) except +:
     1084cdef public object py_float(object n, PyObject* kwds) except +:
    10851085    """
    10861086    Evaluate pynac numeric objects numerically.
    10871087
    10881088    TESTS::
    10891089
    10901090        sage: from sage.symbolic.pynac import py_float_for_doctests as py_float
    1091         sage: py_float(I, ComplexField(10))
     1091        sage: py_float(I, {'parent':ComplexField(10)})
    10921092        1.0*I
    1093         sage: py_float(pi, RealField(100))
     1093        sage: py_float(pi, {'parent':RealField(100)})
    10941094        3.1415926535897932384626433833
    10951095        sage: py_float(10, CDF)
    10961096        10.0
    1097         sage: type(py_float(10, CDF))
     1097        sage: type(py_float(10, {'parent':CDF}))
    10981098        <type 'sage.rings.complex_double.ComplexDoubleElement'>
    1099         sage: py_float(1/2, CC)
     1099        sage: py_float(1/2, {'parent':CC}))
    11001100        0.500000000000000
    1101         sage: type(py_float(1/2, CC))
     1101        sage: type(py_float(1/2, {'parent':CC}))
    11021102        <type 'sage.rings.complex_number.ComplexNumber'>
    11031103    """
    1104     if parent is not NULL:
    1105         return (<object>parent)(n)
     1104    if kwds is not NULL:
     1105        return (<object>kwds)['parent'](n)
    11061106    else:
    11071107        try:
    11081108            return RR(n)
    11091109        except TypeError:
    11101110            return CC(n)
    11111111
    1112 def py_float_for_doctests(n, prec):
     1112def py_float_for_doctests(n, kwds):
    11131113    """
    11141114    This function is for testing py_float.
    11151115
    11161116    EXAMPLES::
    1117        
     1117
    11181118        sage: from sage.symbolic.pynac import py_float_for_doctests
    1119         sage: py_float_for_doctests(pi, RealField(80))
     1119        sage: py_float_for_doctests(pi, {'parent':RealField(80)})
    11201120        3.1415926535897932384626
    11211121    """
    1122     return py_float(n, <PyObject*>prec)
     1122    return py_float(n, <PyObject*>kwds)
    11231123
    11241124# TODO: Optimize this
    11251125from sage.rings.real_double import RDF
     
    18941894        pc = c._pynac
    18951895        return pc.object
    18961896
    1897 cdef public object py_eval_constant(unsigned serial, object parent) except +:
     1897cdef public object py_eval_constant(unsigned serial, object kwds) except +:
    18981898    from sage.symbolic.constants import constants_table
    18991899    constant = constants_table[serial]
    1900     return parent(constant)
     1900    return kwds['parent'](constant)
    19011901
    19021902cdef public object py_eval_unsigned_infinity() except +:
    19031903    """