Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
17531: move exception raising out of GinacFunction.__call__
Browse files Browse the repository at this point in the history
  • Loading branch information
rwst committed Jun 18, 2015
1 parent 3080e76 commit b838310
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/sage/functions/hypergeometric.py
Expand Up @@ -273,7 +273,7 @@ def _eval_(self, a, b, z, **kwargs):
if not isinstance(z, Expression) and z == 0: # Expression is excluded
return Integer(1) # to avoid call to Maxima

def _evalf_try_(self, a, b, z):
def _evalf_try_(self, a, b, z, **kwds):
"""
Call :meth:`_evalf_` if one of the arguments is numerical and none
of the arguments are symbolic.
Expand Down Expand Up @@ -304,7 +304,7 @@ def _evalf_try_(self, a, b, z):
if any(self._is_numerical(x) for x in args):
if not any(isinstance(x, Expression) for x in args):
p = get_coercion_model().common_parent(*args)
return self._evalf_(a, b, z, parent=p)
return self._evalf_(a, b, z, parent=p, **kwds)

def _evalf_(self, a, b, z, parent, algorithm=None):
"""
Expand Down
26 changes: 13 additions & 13 deletions src/sage/symbolic/function.pyx
Expand Up @@ -318,7 +318,7 @@ cdef class Function(SageObject):
return cmp(self._serial, (<Function>other)._serial)
return False

def __call__(self, *args, bint coerce=True, bint hold=False):
def __call__(self, *args, bint coerce=True, bint hold=False, algorithm=None):
"""
Evaluates this function at the given arguments.
Expand Down Expand Up @@ -495,6 +495,10 @@ cdef class Function(SageObject):
if not isinstance(a, Expression):
raise TypeError("arguments must be symbolic expressions")

# we have a GinacFunction, check algorithm
if algorithm is not None and algorithm != "ginac":
raise ValueError("unknown algorithm %r for %s"%(algorithm,self))

cdef GEx res
cdef GExVector vec
if self._nargs == 0 or self._nargs > 3:
Expand Down Expand Up @@ -847,19 +851,15 @@ cdef class GinacFunction(BuiltinFunction):
TESTS::
sage: sin(x, algorithm='foo')
sage: sin(0, algorithm='foo')
Traceback (most recent call last):
...
ValueError: unknown algorithm 'foo' for sin
sage: sin(x, algorithm='ginac')
sin(x)
sage: sin(1, algorithm='ginac')
sin(1)
"""
res = super(GinacFunction, self).__call__(*args, **kwds)

algorithm = kwds.get('algorithm')
if algorithm is not None and algorithm != "ginac":
raise ValueError("unknown algorithm %r for %s"%(algorithm,self))

# Convert to Integer if the output was of type "int" and any of
# the inputs was a Sage Element
if isinstance(res, int) and any(isinstance(x, Element) for x in args):
Expand Down Expand Up @@ -959,8 +959,8 @@ cdef class BuiltinFunction(Function):
Function.__init__(self, name, nargs, latex_name, conversions,
evalf_params_first, alt_name = alt_name)

def __call__(self, *args, bint coerce=True, bint hold=False,
bint dont_call_method_on_arg=False, algorithm=None):
def __call__(self, *args, algorithm=None, bint coerce=True, bint hold=False,
bint dont_call_method_on_arg=False):
r"""
Evaluate this function on the given arguments and return the result.
Expand All @@ -983,9 +983,9 @@ cdef class BuiltinFunction(Function):
sage: bar = BuiltinFunction(name='bar', alt_name='foo')
sage: bar(A())
'foo'
Algorithm arguments are passed to `_evalf_`::
sage: from sage.symbolic.function import BuiltinFunction
sage: class MyFunction(BuiltinFunction):
....: def __init__(self):
Expand Down Expand Up @@ -1026,7 +1026,7 @@ cdef class BuiltinFunction(Function):
res = self._evalf_try_(*args, algorithm=algorithm)
if res is None:
res = super(BuiltinFunction, self).__call__(
*args, coerce=coerce, hold=hold)
*args, coerce=coerce, hold=hold, algorithm=algorithm)

# If none of the input arguments was a Sage Element but the
# output is, then convert the output back to the corresponding
Expand Down

0 comments on commit b838310

Please sign in to comment.