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
Integer and Rational comparisons #18304
Comments
Author: Vincent Delecroix |
This comment has been minimized.
This comment has been minimized.
Branch: u/vdelecroix/18304 |
Commit: |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
This comment has been minimized.
This comment has been minimized.
comment:6
It's not really a big deal, but I'm not much of a fan of these global Also, couldn't By the way, if you make further changes, perhaps you could take the occasion to make |
comment:7
Hello, Replying to @mezzarobba:
Me neither (and there is actually one in
It is minor but timings are in the ticket description. In a more concrete situation
compared to
I do not know why it was done this way for integers. I just naively used the implementation of
Yes. |
comment:8
Replying to @videlec:
Actually, no. Because it is not a rich comparison but just comparison. |
comment:9
Replying to @videlec:
Yes, I saw that.
I have no idea.
No, I mean specifically for using a global temporary variable instead of creating a new one each time. |
comment:11
With
declaring global
and with local ones
Note that this bad scenario only occurs for comparisons of:
There is a slightly another annoying thing with the global I will try harder to see if there is a way to tweak Vincent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:15
Hi Vincent, Do you still want to patch mpir after the answers you got on mpir-devel and gmp-devel? If you do: would the code from this ticket still work if sage is built with gmp? |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
Changed dependencies from #22493 to none |
This comment has been minimized.
This comment has been minimized.
comment:28
Overall, I think this is ready to go into Sage. However, close to the realm of bikeshedding, I would change: -if not isinstance(left, Rational):
- raise RuntimeError('this should not happen')
+assert isinstance(left, Rational) |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:31
rebased on 8.0.beta10 (and incorported your comment:28) |
comment:32
Thanks. However, I just had a strong sense of dread come over me when I thought about why the old code was checking left/right. In code like https://eev.ee/blog/2012/03/24/python-faq-equality/ I do not know if this is done for |
comment:33
does not build, due to a changed import (richcmp stuff is now in sage.structure.richcmp) |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:35
Indeed. I rebased on 8.0.beta11. |
Reviewer: Marc Mezzarobba, Travis Scrimshaw |
comment:36
Hmm...I could've sworn Python sometimes flips inputs for something like |
Changed branch from u/vdelecroix/18304 to |
MPIR 3.0.0 is shipped with the function
mpq_cmp_z(mpq_t, mpz_t)
. We can use it to make integer/rational comparisons much faster.Comparing integers is very fast, comparing rationals is very fast but comparing integer with rational is about 5x slower:
With the branch applied, it gets better
CC: @jdemeyer
Component: performance
Author: Vincent Delecroix
Branch/Commit:
e72c82d
Reviewer: Marc Mezzarobba, Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/18304
The text was updated successfully, but these errors were encountered: