Skip to content

Conversation

@joschmitt
Copy link
Collaborator

@joschmitt joschmitt commented Oct 24, 2025

Add an inplace option to the iterators of exponents, coefficients, terms and monomials of a multivariate polynomial.
This is still a draft. Is this the "interface" we want?
Regarding the new functions coeff!, term! and exponent_vector!: Should they be exported (I did it for now because monomial! is exported as well)? Do I need to implement an "abstract fall-back" in src/MPoly.jl?

Nemocas/Nemo.jl#2161 implements the (few) necessary functions for QQMPolyRingElem. Using those, I get the following timings in oscar-system/Oscar.jl#5483 :

# Previously
julia> @btime inv_c[n-k+1:n];
  3.628 s (28973402 allocations: 1.73 GiB)

# With inplace iterators
julia> @btime inv_c[n-k+1:n];
  1.356 s (2811 allocations: 279.24 KiB)

So that moves in the right direction.

Comment on lines +682 to +686
if !isassigned(m.coeffs, 1) || !is_one(m.coeffs[1])
m.coeffs[1] = one(base_ring(x))
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a bit ugly, but it gets the monomials iterator to constant allocations. Otherwise it would allocate a new 1 all the time. Is this too much of a corner case?

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.

1 participant