Ticket #13933: trac_13933-slow_call.patch

File trac_13933-slow_call.patch, 3.6 KB (added by Burcin Erocal, 10 years ago)

robert's patch rebased on top of move_call.patch

  • sage/functions/generalized.py

    # HG changeset patch
    # User Robert Bradshaw <robertwb@math.washington.edu>
    # Date 1357804216 -3600
    # Node ID ef8bfd2085a89dd11fbe6da2f38563c00f212436
    # Parent  590885bf61de248ba009dd33b9c34cfee92d1e01
    Speed improvements for BuiltinFunction.__call__
    
    diff --git a/sage/functions/generalized.py b/sage/functions/generalized.py
    a b  
    441441            sgn(x)
    442442        """
    443443        BuiltinFunction.__init__(self, "sgn", latex_name=r"\mathrm{sgn}",
    444                 conversions=dict(maxima='signum',mathematica='Sign',sympy='sign'))
     444                alt_name="sign", conversions=dict(maxima='signum',
     445                    mathematica='Sign', sympy='sign'))
    445446
    446447    def _eval_(self, x):
    447448        """
  • sage/symbolic/function.pxd

    diff --git a/sage/symbolic/function.pxd b/sage/symbolic/function.pxd
    a b  
    2828
    2929cdef class BuiltinFunction(Function):
    3030    cdef _is_registered(self)
     31    cdef object _alt_name
    3132
    3233cdef class GinacFunction(BuiltinFunction):
    3334    cdef object _ginac_name
  • sage/symbolic/function.pyx

    diff --git a/sage/symbolic/function.pyx b/sage/symbolic/function.pyx
    a b  
    272272            return cmp(self._serial, (<Function>other)._serial)
    273273        return False
    274274
    275     def __call__(self, *args, coerce=True, hold=False):
     275    def __call__(self, *args, bint coerce=True, bint hold=False):
    276276        """
    277277        Evaluates this function at the given arguments.
    278278       
     
    736736    of this class.
    737737    """
    738738    def __init__(self, name, nargs=1, latex_name=None, conversions=None,
    739             evalf_params_first=True):
     739            evalf_params_first=True, alt_name=None):
    740740        """
    741741        TESTS::
    742742
     
    747747        """
    748748        Function.__init__(self, name, nargs, latex_name, conversions,
    749749                evalf_params_first)
     750        self._alt_name = alt_name
    750751
    751752    cdef _is_registered(self):
    752753        """
     
    827828            # we should never end up here
    828829            raise ValueError, "cannot read pickle"
    829830
    830     def __call__(self, *args, coerce=True, hold=False,
    831             dont_call_method_on_arg=False):
     831    def __call__(self, *args, bint coerce=True, bint hold=False,
     832            bint dont_call_method_on_arg=False):
    832833        """
    833834        Evaluate this function on the given arguments and return the result.
    834835
     
    839840            sage: gamma(15)
    840841            87178291200
    841842        """
    842         # we want to convert the result to the original parent if the input
    843         # is not exact, so we store the parent here
    844         org_parent = parent_c(args[0])
    845 
    846843        # if there is only one argument, and the argument has an attribute
    847844        # with the same name as this function, try to call it to get the result
    848845        # The argument dont_call_method_on_arg is used to prevent infinite loops
     
    853850                return getattr(args[0], self._name)()
    854851            except AttributeError:
    855852                pass
     853            if self._alt_name:
     854                try:
     855                    return getattr(args[0], self._alt_name)()
     856                except AttributeError:
     857                    pass
    856858
    857859        res = super(BuiltinFunction, self).__call__(*args, coerce=coerce,
    858860                hold=hold)
     
    862864        #     sage: arctan(RR(1))
    863865        #     1/4*pi
    864866        # which is surprising, to say the least...
     867        org_parent = parent_c(args[0])
    865868        if org_parent is not SR and \
    866869                (org_parent is float or org_parent is complex or \
    867870                (PY_TYPE_CHECK(org_parent, Parent) and \