-
Notifications
You must be signed in to change notification settings - Fork 128
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
Speed up polynomial mappings #4124
Speed up polynomial mappings #4124
Conversation
src/Rings/MPolyMap/MPolyRing.jl
Outdated
r = ngens(S) | ||
ctx = MPolyBuildCtx(S) | ||
for (c, e) in zip(AbstractAlgebra.coefficients(u), AbstractAlgebra.exponent_vectors(u)) | ||
ee = [0 for _ in 1:r] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ee = [0 for _ in 1:r] | |
ee = Vector{Int}(undef, r) |
should be an epsilon faster
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One should be able to use the "same" vector ee
for the whole loop as it gets copied anyway. I try to optimize this further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An undefined vector will not work. We need the zeroes.
Unfortunately this still does not seem to make a difference. I was running the tests for elliptic surfaces with and without the changes made here (since @fingolfin pointed to that as a potential example). The result is Without this PR:
With this PR:
The different timings might also be due to randomization of parts of the tests on the lattice theoretic side (@simonbrandhorst : Is this correct?), but the allocations do not go down significantly. One thing I noticed is that In my opinion it would therefore be desirable to have a Orthogonal to that, the question remains: Why does this PR not help speeding things up for mappings? |
So: In the end this is useful. Just not for all the flattenings used in the elliptic surfaces (yet). I created the following test polynomial. Run the following code: g = load("poly.txt")
S = parent(g)
flat = Oscar.flatten(S)
f = copy(g);
@time flat(f); With this PR:
without this PR:
|
Looks good so far. I think this is going in the right direction. (It reminds of the The logic for the evaluation was already hard to follow before (blame on me), and it seems it won't be getting better. But it is easer to talk in persons about this. |
I added a keyword argument to the internal constructor for the maps to be able to avoid the internal checks whether you have a mapping of variables to variables. These are not yet forwarded to the user-facing constructors, but should this ever become a performance issue, this possibility exists. |
Looks like we're slowly getting somewhere here. I ran the
after:
ping: @fingolfin |
e11b048
to
8944bb2
Compare
@HereAround : Might it be the case that your test in the Anyways: If the tests pass, then from my side, this is good to go. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4124 +/- ##
==========================================
+ Coverage 84.68% 84.69% +0.01%
==========================================
Files 628 628
Lines 84471 84578 +107
==========================================
+ Hits 71533 71636 +103
- Misses 12938 12942 +4
|
Unfortunately these kind of doctests (printing a large vector) are dependent on the windows size of the terminal you run the doctest_fix from |
Why does this exist if it is not used here? |
I thought, it would be nice to give future developers a hint that they can safely disable this feature by using the keyword argument. If you think, it's causing more confusion than insight, then I can remove it. Also, it seems that we can reunite both internal constructors into one constructor again, now that I have allowed more rings in the codomain. |
I had hoped that a no one would ever create a map by calling |
The computation of generic_section of line bundles picks random coefficients. This is the element of randomness in the FTheoryTools test. Everything else is (or so I hope at least) deterministic. |
src/Rings/mpolyquo-localizations.jl
Outdated
# The following methods are only safe, because they are called | ||
# exclusively in a setup where variables map to variables | ||
# and no denominators are introduced. | ||
_coefficients(x::MPolyRingElem) = coefficients(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but maybe you want the following here?
_coefficients(x::MPolyRingElem) = coefficients(x) | |
_coefficients(x::MPolyRingElem) = AbstractAlgebra.coefficients(x) |
And also below with exponent_vectors
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw the AA
-qualifier elsewhere, too. But I thought, it was redundant. Isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. It is the difference between painfully slow and fast when iterating over coefficients/exponents. There used to be an explanation in the documentation, but it was removed for reasons I don't know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #4168
Again: Ready for merge from my side. |
Thanks, it looks good. |
@fingolfin mentioned in his course this week that in the
RingFlattening
s there was lots of potential improvements available via the use ofMPolyBuildCtx
. I tried a little bit, but could not achieve any better performance. I'm wondering why, though, so I put it up here for discussion.