#9885: slow coercion from integer mod ring to integer ring
-------------------------+-------------------------------------------------
Reporter: | Owner: tbd
dmharvey | Status: needs_review
Type: | Milestone:
defect | Resolution:
Priority: major | Merged in:
Component: | Reviewers:
performance | Work issues:
Keywords: | Commit:
Authors: Nils | c04c8b5cd99d9614d52dc65df8bb1b07a497ff5a
Bruin | Stopgaps:
Report Upstream: N/A |
Branch: |
u/nbruin/9885 |
Dependencies: |
-------------------------+-------------------------------------------------
Comment (by nbruin):
OK, with this change made to your patch:
{{{
#!diff
--- a/src/sage/rings/integer.pyx
+++ b/src/sage/rings/integer.pyx
@@ -693,11 +693,10 @@ cdef class
Integer(sage.structure.element.EuclideanDomainE
else:
- try:
- set_from_Integer(self, x._integer_(the_integer_ring))
+ otmp=getattr(x,"_integer_",None)
+ if otmp is not None:
+ set_from_Integer(self, otmp(the_integer_ring))
return
- except AttributeError:
- pass
}}}
I get hardly a difference in timing. Using
{{{
%cpaste
cython("""
from sage.rings.integer import Integer
def test(a,n):
cdef long N=n
for i in range(N):
v=Integer(a)
""")
--
R = Integers(3^20)
u=R(2)
timeit("test(u,100000)")
}}}
I get 20.3 ms for `getattr` and 20.7ms for the `try/except` variant. So,
really a minute difference, but still measurable.I'd go for the getattr
option, mainly because of the error checking.
--
Ticket URL: <http://trac.sagemath.org/ticket/9885#comment:9>
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.