Opened 10 years ago
Last modified 7 years ago
#12289 closed enhancement
pass algorithm argument to custom numeric evalution methods — at Version 23
Reported by: | burcin | Owned by: | burcin |
---|---|---|---|
Priority: | major | Milestone: | sage-6.2 |
Component: | symbolics | Keywords: | pynac sd35.5 sd40.5 sd48 |
Cc: | benjaminfjones, dsm, kcrisman, kini, eviatarbach, vbraun | Merged in: | |
Authors: | Burcin Erocal, Benjamin Jones | Reviewers: | Karl-Dieter Crisman, Doug S. MacNeil, Benjamin Jones |
Report Upstream: | N/A | Work issues: | doctests, documentation |
Branch: | Commit: | ||
Dependencies: | #13933, #4102 | Stopgaps: |
Description (last modified by )
Custom numeric evaluation functions defined in the _evalf_()
method of symbolic functions accept only the parent of the result as an argument. We should expand this to allow passing an argument
parameter as well.
Testing instructions:
- Rebuild Pynac via
sage -f -s pynac
in Sage 5.11.betaN or higher - (By hand?) Apply this diff to the
spkg/build/pynac-0.3.0/src
directory - Do
sage -sh
andsage -b
- Apply trac_12289-evalf_dictionary_rebase.take2.patch, trac_12289-add_algorithm-rebase.patch, trac_12289-more-alg.patch, and trac_12289-last_touches.patch.
- Apply trac_12289-example.patch to test that this works, or make your own change, or something.
For merging, apply
- trac_12289-evalf_dictionary_rebase.take2.patch,
- trac_12289-add_algorithm-rebase.patch,
- trac_12289-more-alg.patch
- trac_12289-last_touches.patch.
Pynac spkg will be needed as well.
Change History (33)
Changed 10 years ago by
Changed 10 years ago by
Changed 10 years ago by
comment:1 Changed 10 years ago by
- Cc benjaminfjones added
comment:2 Changed 10 years ago by
- Keywords sd35.5 added
I'm doing some testing of these patches along with rebasing #1173. Thanks Burcin!
comment:3 Changed 10 years ago by
- Cc dsm added
- Keywords sd40.5 added
comment:4 Changed 10 years ago by
I'm trying to rebase the patch trac_12289-evalf_dictionary.patch to sage-5.0, but I'm running into a problem with the type of py_funcs.py_float
. In the patch py_float has type object (*)(object, object)
but in sage-5.0, it has type object (*)(object, PyObject *)
I guess because of a pynac change in the meantime.
To be more specific, with this type def for py_float
:
cdef public object py_float(object n, object kwds) except +:
I rebuild sage and get:
Error compiling Cython file: ------------------------------------------------------------ ... py_funcs.py_is_prime = &py_is_prime py_funcs.py_integer_from_long = &py_integer_from_long py_funcs.py_integer_from_python_obj = &py_integer_from_python_obj py_funcs.py_float = &py_float ^ ------------------------------------------------------------ sage/symbolic/pynac.pyx:2040:24: Cannot assign type 'object (*)(object, object)' to 'object (*)(object, PyObject *)'
Any suggestions (burcin?)
comment:5 Changed 10 years ago by
- Cc kcrisman added
comment:6 Changed 10 years ago by
- Cc kini added
comment:7 follow-up: ↓ 10 Changed 10 years ago by
I've been working on this ticket today at sd40.5. I've got burcin's changes working in sage-5.0 with a caveat. Here's how to get the example in comment:1 working in sage-5.0:
- install the patched pynac-0.2.4.p1 spkg at http://sage.math.washington.edu/home/bjones/pynac-0.2.4.p1.spkg. this spkg is the pynac-0.2.4 spkg from #12950 which has been patched to include the changes from burcin's
pynac-wip
branch of pynac mentioned above.
- apply all patches at #12950, here is a shell script to help that (run from
$SAGE_ROOT/devel/sage
): http://sage.math.washington.edu/home/bjones/trac_12950_apply.sh
- apply the patches to
$SAGE_ROOT/devel/sage
sage -b
comment:8 Changed 10 years ago by
- Description modified (diff)
Patchbot, though, should only apply trac_12289-evalf_dictionary_rebase.patch, trac_12289-add_algorithm_arg.patch, and trac_12289_py_float_fix.patch
comment:9 Changed 10 years ago by
So that we don't forget to fix it later:
sage: erf(1).n(algorithm='foo') 0.842700792949715 sage: erf(0) 0 sage: parent(erf(0)) Integer Ring sage: erf(0).n(algorithm='foo') --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /Users/mcneil/sagedev/sage-5.1.beta0b/sage-5.1.beta0/devel/sage-hack2/sage/<ipython console> in <module>() /Users/mcneil/sagedev/sage-5.1.beta0b/sage-5.1.beta0/local/lib/python2.7/site-packages/sage/structure/element.so in sage.structure.element.Element.numerical_approx (sage/structure/element.c:4988)() TypeError: numerical_approx() got an unexpected keyword argument 'algorithm'
comment:10 in reply to: ↑ 7 Changed 9 years ago by
- install the patched pynac-0.2.4.p1 spkg at http://sage.math.washington.edu/home/bjones/pynac-0.2.4.p1.spkg. this spkg is the pynac-0.2.4 spkg from #12950 which has been patched to include the changes from burcin's
pynac-wip
branch of pynac mentioned above.
Is this stuff in the current Pynac 0.2.6?
- apply all patches at #12950, here is a shell script to help that (run from
$SAGE_ROOT/devel/sage
): http://sage.math.washington.edu/home/bjones/trac_12950_apply.sh
Can now be skipped, presumably.
- apply the patches to
$SAGE_ROOT/devel/sage
sage -b
comment:11 Changed 9 years ago by
- Cc eviatarbach added
comment:12 Changed 9 years ago by
Some of these patches have bitrotted slightly. Updates coming up.
comment:13 Changed 9 years ago by
Regarding Doug's comment on
erf(0).n(algorithm='foo')
Is this something we want to fix here? I'm not sure whether this is behavior that is supported with this patch, though perhaps it should be. I think that so far this is only putting in infrastructure, right? I don't see any doctests here, for instance.
Changed 9 years ago by
Changed 9 years ago by
comment:14 Changed 9 years ago by
- Description modified (diff)
comment:15 Changed 9 years ago by
- Description modified (diff)
Patchbot, apply trac_12289-evalf_dictionary_rebase.patch , trac_12289-add_algorithm-rebase.patch , and trac_12289-py_float-fix-rebase.patch
comment:16 Changed 9 years ago by
I think that we definitely need at least one example of how to do this if we aren't going to have any other documentation here.
comment:17 Changed 9 years ago by
- Reviewers set to Karl-Dieter Crisman, Doug S. MacNeil, Benjamin Jones
- Status changed from new to needs_review
- Work issues set to doctests, documentation
We need to fix this.
---------------------------------------------------------------------- sage -t sage/symbolic/expression.pyx # 3 doctests failed sage -t sage/functions/other.py # Killed due to segmentation fault sage -t sage/functions/exp_integral.py # 25 doctests failed sage -t sage/functions/log.py # 4 doctests failed sage -t sage/symbolic/pynac.pyx # 2 doctests failed sage -t sage/symbolic/function.pyx # 1 doctest failed ----------------------------------------------------------------------
But it does work!
comment:18 Changed 9 years ago by
- Status changed from needs_review to needs_work
comment:19 Changed 9 years ago by
- Keywords sd48 added
comment:20 Changed 9 years ago by
Okay, Burcin figured out what he forgot here :) and most of the rest should be easily fixable.
comment:21 Changed 9 years ago by
Okay, everything fixed except a segfault on beta which is exactly the same one which this fixed. Burcin says that this needs to be handled properly and so
static ex beta_evalf(const ex & x, const ex & y, PyObject* parent) { if (is_exactly_a<numeric>(x) && is_exactly_a<numeric>(y)) { try { return exp(lgamma(ex_to<numeric>(x))+lgamma(ex_to<numeric>(y))-lgamma(ex_to<numeric>(x+y))); } catch (const dunno &e) { } } return beta(x,y).hold(); }
in ginac/inifcns_gamma.cpp needs to be worked on in addition to other stuff.
Changed 9 years ago by
comment:22 Changed 9 years ago by
- Description modified (diff)
Patchbot, apply trac_12289-evalf_dictionary_rebase.patch , trac_12289-add_algorithm-rebase.patch, trac_12289-py_float-fix-rebase.patch, and trac_12289-more-alg.patch
Changed 9 years ago by
Changed 9 years ago by
comment:23 Changed 9 years ago by
- Dependencies set to #13933, #4102
- Description modified (diff)
- Status changed from needs_work to needs_review
New patches up. All doctests pass in sage/{symbolics,calculus}/
.
The
evalf_dict
branch of Pynac available here, with the attached patches applied to the Sage library, allows this:The docstrings for
_convert()
etc. methods of symbolic expressions need to be updated to reflect these changes.