Skip to content
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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HechtiDerLachs
Copy link
Collaborator

@fingolfin mentioned in his course this week that in the RingFlattenings there was lots of potential improvements available via the use of MPolyBuildCtx. 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.

@joschmitt joschmitt marked this pull request as draft September 19, 2024 15:55
r = ngens(S)
ctx = MPolyBuildCtx(S)
for (c, e) in zip(AbstractAlgebra.coefficients(u), AbstractAlgebra.exponent_vectors(u))
ee = [0 for _ in 1:r]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ee = [0 for _ in 1:r]
ee = Vector{Int}(undef, r)

should be an epsilon faster

Copy link
Member

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.

Copy link
Collaborator Author

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.

Comment on lines +136 to +137
is_gen(x::MPolyQuoRingElem) = is_gen(lift(x))
is_gen(x::MPolyDecRingElem) = is_gen(forget_grading(x))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memo to self: This is not legitimate. We need to switch to some internal method like _is_gen for that.

@fingolfin fingolfin changed the title Speedup polynomial mappings Speed up polynomial mappings Sep 20, 2024
@@ -42,17 +42,37 @@ const _DomainTypes = Union{MPolyRing, MPolyQuoRing}
coeff_map::U
img_gens::Vector{V}
temp_ring # temporary ring used when evaluating maps
variable_indices::Vector{Int} # a table where the i-th entry contains the
# index of the variable where it's mapped to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# index of the variable where it's mapped to
# index of the variable where it is mapped to

@assert parent(g) === codomain "elements does not have the correct parent"
end
result = new{D, C, U, V}(domain, codomain, coeff_map, img_gens)
if all(is_gen(x) for x in img_gens) && allunique(img_gens)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if all(is_gen(x) for x in img_gens) && allunique(img_gens)
if all(is_gen, img_gens) && allunique(img_gens)

end
result = new{D, C, U, V}(domain, codomain, coeff_map, img_gens)
if all(is_gen(x) for x in img_gens) && allunique(img_gens)
result.variable_indices = [findfirst(x==y for y in gens(codomain)) for x in img_gens]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result.variable_indices = [findfirst(x==y for y in gens(codomain)) for x in img_gens]
result.variable_indices = [findfirst(==(x), gens(codomain)) for x in img_gens]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants