#10952: better numerical accuracy testing
-----------------------------------------------------------------------+----
Reporter: robertwb |
Owner: mvngu
Type: enhancement |
Status: needs_work
Priority: critical |
Milestone: sage-4.7.2
Component: doctest |
Keywords: sd32
Work_issues: |
Upstream: N/A
Reviewer: Jason Grout, Mariah Lenox, William Stein, John Palmieri |
Author: Robert Bradshaw, Rob Beezer
Merged: |
Dependencies:
-----------------------------------------------------------------------+----
Changes (by jhpalmieri):
* status: positive_review => needs_work
* reviewer: Jason Grout, Mariah Lenox, William Stein => Jason Grout,
Mariah Lenox, William Stein, John Palmieri
Comment:
This doesn't work. Re Leif's comment, I think the regexp should something
like `' ((\.[0-9]+|[0-9]+(\.[0-9]*)?)e[+-]?[0-9]+)'`, which adds another
group to the match, so we need to make this change:
{{{
#!diff
diff --git a/sage-doctest b/sage-doctest
--- a/sage-doctest
+++ b/sage-doctest
@@ -217,7 +217,7 @@ if __name__ == '__main__':
""" % dict
NONE=0; LONG_TIME=1; RANDOM=2; OPTIONAL=3; NOT_IMPLEMENTED=4;
NOT_TESTED=5; TOLERANCE=6
-tolerance_pattern = re.compile(r'\b((?:abs(?:olute)?)|(?:rel(?:ative)?))?
*?tol(?:erance)?\b( +[0-9.e+-]+)?')
+tolerance_pattern = re.compile(r'\b((?:abs(?:olute)?)|(?:rel(?:ative)?))?
*?tol(?:erance)?\b +((\.[0-9]+|[0-9]+(\.[0-9]*)?)e[+-]?[0-9]+)?')
def comment_modifier(s):
sind = s.find('#')
@@ -239,7 +239,7 @@ def comment_modifier(s):
m = tolerance_pattern.search(L)
if m:
v.append(TOLERANCE)
- rel_or_abs, epsilon = m.groups()
+ rel_or_abs, epsilon, _, _ = m.groups()
if rel_or_abs is not None:
rel_or_abs = rel_or_abs[:3]
if epsilon is None:
}}}
I think this should match any of "1.2e12", "1e-12", ".1e12", without
matching "ee12e+-122", like the previous regexp.
In addition to this, the whole thing just flat doesn't work. I created a
Python file with some tolerance tests in it, and they all fail, and the
failures print badly: they include tracebacks, for example. I'm not sure
why the rst file patched in the two "doc" patches isn't being doctested
correctly, but as far as I can tell, no doctests are being run in that
file -- just add an obviously wrong doctest, and tests still pass. Here
is a test file:
{{{
#!python
"""
Here are some examples::
sage: 3+3
6
sage: RDF(pi) # abs tol 1e-4
3.14159
Here is another example::
sage: [10^n for n in [0.0 .. 4]] # rel tol 2e-4
[0.9999, 10.001, 100.01, 999.9, 10001]
And another::
sage: RDF(pi) # abs tol 1e-4
3.14159
And that's the end.
"""
}}}
Save this as "new.py" and run "sage -t new.py" to see some bad behavior.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/10952#comment:30>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.