New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
slow coercion from integer mod ring to integer ring #9885
Comments
comment:2
Thinking about it a bit more, we could move the |
Branch: u/nbruin/9885 |
Author: Nils Bruin |
Commit: |
comment:4
This at least helps a bit (dropping from 900ns to 580ns in my tests) by avoiding a double attribute lookup that was already highlighted as undesirable in the code. New commits:
|
comment:5
Looks like we have been working on the issue at the same time! My go at it is at
So apparently my version is slightly faster... at least on this particular example. |
comment:6
It looks like you changed more branches (for the better, I hope). You use a try/except where I use a getattr. I suspect it's better to go with the getattr for the following reasons:
I'd recommend adopting the I've checked and cython produces an inline function for EDIT: I've tested the several Anyway, the possibility for catching extraneous errors with guarding too much with try/except is I think the strongest argument. |
comment:7
Replying to @nbruin:
True. But that pattern is so common in sage that I don't worry too much.
Well, that's the case of the branch used in my timings!
I already tried after seeing your version, and the hybrid solution was the slowest of the three (by a significant amount). I didn't try to understand why. |
comment:8
Replying to @mezzarobba:
Hm, something must have gone wrong in the hybridization then. With this test code:
I get
you see that |
comment:9
OK, with this change made to your patch: --- 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
I get 20.3 ms for |
Changed branch from u/nbruin/9885 to u/mmezzarobba/9885-intmod_to_int |
Reviewer: Marc Mezzarobba, Nils Bruin |
Changed author from Nils Bruin to Nils Bruin, Marc Mezzarobba |
comment:11
Nils, any chance you can have a quick look at my second commit and set the ticket to positive review? Thanks! |
comment:12
The docstring of |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:14
Replying to @pjbruin:
Thanks, I didn't know this was necessary for docstrings that only contain tests. |
Changed reviewer from Marc Mezzarobba, Nils Bruin to Marc Mezzarobba, Nils Bruin, Peter Bruin |
comment:15
I can confirm the speedup, if doctests pass I'll give this a positive review. |
Changed branch from u/mmezzarobba/9885-intmod_to_int to |
Sage 4.5.3, 2.6GHz Opteron, Linux
This is ok:
This is not:
Why is this so much slower? Or how is the user supposed to know which one to use?
Component: performance
Author: Nils Bruin, Marc Mezzarobba
Branch/Commit:
7c9c847
Reviewer: Marc Mezzarobba, Nils Bruin, Peter Bruin
Issue created by migration from https://trac.sagemath.org/ticket/9885
The text was updated successfully, but these errors were encountered: