#20209: Failing conversion QQbar -> RIF
-------------------------------------+-------------------------------------
Reporter: vdelecroix | Owner:
Type: defect | Status: needs_review
Priority: blocker | Milestone: sage-7.1
Component: number fields | Resolution:
Keywords: | Merged in:
Authors: Vincent Delecroix | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/vdelecroix/20209 | 53d955c1c7c9fb0cdc8e4b0d8338544e7af629f8
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by tscrim):
I think a better solution would be to do
{{{#!python
def interval(self, field):
target = RR(1.0) >> field.prec()
val = self.interval_diameter(target)
from sage.rings.real_mpfi import RealIntervalField_class
if isinstance(field, RealIntervalField_class) and
self.imag().is_zero():
val = self.real().interval_diameter(target)
return field(val)
}}}
(I would probably even put the import at the namespace level too.) That
way we do not generate the error and catch it, which is a slow operation
compared to an `isinstance` check:
{{{
sage: def foo():
....: try:
....: raise ValueError
....: except ValueError:
....: pass
sage: %timeit foo()
The slowest run took 22.94 times longer than the fastest. This could mean
that an intermediate result is being cached.
1000000 loops, best of 3: 832 ns per loop
sage: def bar():
....: return isinstance(RIF, type(RIF))
sage: %timeit bar()
The slowest run took 27.02 times longer than the fastest. This could mean
that an intermediate result is being cached.
10000000 loops, best of 3: 185 ns per loop
}}}
(This test is also somewhat unfair to the `isinstance` check.) I could see
this conversion being used in a tight loop in many computations. (We also
loose about 20ns just for having that try-except block.)
--
Ticket URL: <http://trac.sagemath.org/ticket/20209#comment:3>
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 https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.