-
Notifications
You must be signed in to change notification settings - Fork 120
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
base: master
Are you sure you want to change the base?
Speed up polynomial mappings #4124
Conversation
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.
is_gen(x::MPolyQuoRingElem) = is_gen(lift(x)) | ||
is_gen(x::MPolyDecRingElem) = is_gen(forget_grading(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.
Memo to self: This is not legitimate. We need to switch to some internal method like _is_gen
for that.
@@ -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 |
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.
# 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) |
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.
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] |
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.
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] |
@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.