#17531: allow algorithm keyword when calling BuiltinFunction
-------------------------------------+-------------------------------------
Reporter: rws | Owner:
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-6.8
Component: symbolics | Resolution:
Keywords: symbolic | Merged in:
functions | Reviewers:
Authors: Ralf Stephan | Work issues:
Report Upstream: N/A | Commit:
Branch: | b838310bd8b22284f60fdeff03a1de7b5cd9e49c
u/rws/allow_algorithm_keyword_when_calling_builtinfunction| Stopgaps:
Dependencies: |
-------------------------------------+-------------------------------------
Description changed by rws:
Old description:
> As per http://trac.sagemath.org/ticket/17489#comment:17 and
> http://trac.sagemath.org/ticket/17489#comment:23, the ticket should
> improve the `BuiltinFunction` class, such that subclassed function
> classes that have an `algorithm=...` keyword given via function call will
> automatically have this keyword inserted into any `__evalf__` member
> function call.
>
> This means the following should be possible without changes to
> `subclassedfunction.__call__`:
> {{{
> sage: from sage.symbolic.function import BuiltinFunction
> sage: class MyFunction(BuiltinFunction):
> ....: def __init__(self):
> ....: BuiltinFunction.__init__(self, 'test', nargs=1)
> ....: def _evalf_(self, x, **kwds):
> ....: algorithm = kwds.get('algorithm', None)
> ....: if algorithm == 'algoA':
> ....: return 1.0
> ....: else:
> ....: return 0.0
> ....: def _eval_(self, x):
> ....: return self._evalf_try_(x)
> sage: f = MyFunction()
> sage: f(0.0, algorithm='algoA')
> 1.00000000000000
> sage: f(0.0)
> 0.000000000000000
> }}}
> At the moment, as with all(?) symbolic functions we get
> {{{
> sage: f(x, algorithm='algoB')
> TypeError: __call__() got an unexpected keyword argument 'algorithm'
> sage: sin(x, algorithm='algoB')
> TypeError: __call__() got an unexpected keyword argument 'algorithm'
> }}}
> So the ticket should also give a better error message for existing
> functions.
New description:
As per http://trac.sagemath.org/ticket/17489#comment:17 and
http://trac.sagemath.org/ticket/17489#comment:23, the ticket should
improve the `BuiltinFunction` class, such that subclassed function classes
that have an `algorithm=...` keyword given via function call will
automatically have this keyword inserted into any `__evalf__` member
function call.
This means the following should be possible without changes to
`subclassedfunction.__call__`:
{{{
sage: from sage.symbolic.function import BuiltinFunction
sage: class MyFunction(BuiltinFunction):
....: def __init__(self):
....: BuiltinFunction.__init__(self, 'test', nargs=1)
....: def _evalf_(self, x, **kwds):
....: algorithm = kwds.get('algorithm', None)
....: if algorithm == 'algoA':
....: return 1.0
....: else:
....: return 0.0
....: def _eval_(self, x):
....: return self._evalf_try_(x)
sage: f = MyFunction()
sage: f(0.0, algorithm='algoA')
1.00000000000000
sage: f(0.0)
0.000000000000000
}}}
At the moment, as with all(?) symbolic functions we get
{{{
sage: f(x, algorithm='algoB')
TypeError: __call__() got an unexpected keyword argument 'algorithm'
sage: sin(x, algorithm='algoB')
TypeError: __call__() got an unexpected keyword argument 'algorithm'
}}}
So the ticket should also give a better error message for existing
functions.
#16812 and #17489 depend on this.
--
--
Ticket URL: <http://trac.sagemath.org/ticket/17531#comment:33>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.