diff --git a/src/MPoly.jl b/src/MPoly.jl index 5579082933..27c90aa8fc 100644 --- a/src/MPoly.jl +++ b/src/MPoly.jl @@ -500,6 +500,10 @@ function exponent_vector!(e::Vector{S}, a::MPolyRingElem{T}, i::Int) where {T <: return S.(exponent_vector(a, i)) end +function exponent_vector(::Type{Vector{S}}, a::MPolyRingElem{T}, i::Int) where {T <: RingElement, S} + return S.(exponent_vector(a, i)) +end + function coeff!(c::T, a::MPolyRingElem{T}, i::Int) where {T <: RingElement} return coeff(a, i) end diff --git a/src/generic/MPoly.jl b/src/generic/MPoly.jl index 713f90426a..b3f5df9f57 100644 --- a/src/generic/MPoly.jl +++ b/src/generic/MPoly.jl @@ -129,8 +129,12 @@ are given in the order of the variables for the ring, as supplied when the ring was created. """ function exponent_vector(a::MPoly{T}, i::Int) where T <: RingElement - e = Vector{Int}(undef, nvars(parent(a))) - return exponent_vector!(e, a, i) + return exponent_vector(Vector{Int}, a, i) +end + +function exponent_vector(::Type{Vector{S}}, a::MPoly{T}, i::Int) where {T <: RingElement, S} + e = Vector{S}(undef, nvars(parent(a))) + return exponent_vector!(e, a, i) end function exponent_vector!(e::Vector{S}, a::MPoly{T}, i::Int) where {T <: RingElement, S} @@ -843,10 +847,10 @@ function Base.iterate(x::MPolyCoeffs, state::Union{Nothing, Int} = nothing) end end -function Base.iterate(x::MPolyExponentVectors, state::Union{Nothing, Int} = nothing) +function Base.iterate(x::MPolyExponentVectors{T, S}, state::Union{Nothing, Int} = nothing) where {T, S} s = isnothing(state) ? 1 : state + 1 if length(x.poly) >= s - v = x.inplace ? exponent_vector!(x.temp, x.poly, s) : exponent_vector(x.poly, s) + v = x.inplace ? exponent_vector!(x.temp, x.poly, s) : exponent_vector(S, x.poly, s) return v, s else return nothing diff --git a/src/generic/imports.jl b/src/generic/imports.jl index 28957330bb..a2ef7dacff 100644 --- a/src/generic/imports.jl +++ b/src/generic/imports.jl @@ -131,6 +131,7 @@ import ..AbstractAlgebra: domain import ..AbstractAlgebra: elem_type import ..AbstractAlgebra: evaluate import ..AbstractAlgebra: exp +import ..AbstractAlgebra: exponent_vector import ..AbstractAlgebra: exponent_vectors import ..AbstractAlgebra: exponent_vector! import ..AbstractAlgebra: expressify diff --git a/test/Solve-test.jl b/test/Solve-test.jl index d8056e71eb..dc852cb16d 100644 --- a/test/Solve-test.jl +++ b/test/Solve-test.jl @@ -244,8 +244,8 @@ end @test base_ring(MT) == QQ - @test @inferred zero(MT) == AbstractAlgebra.Solve.lazy_transpose(zero_matrix(QQ, 3, 5)) - @test @inferred zero(MT, 2, 3) == AbstractAlgebra.Solve.lazy_transpose(zero_matrix(QQ, 3, 2)) + @test (@inferred zero(MT)) == AbstractAlgebra.Solve.lazy_transpose(zero_matrix(QQ, 3, 5)) + @test (@inferred zero(MT, 2, 3)) == AbstractAlgebra.Solve.lazy_transpose(zero_matrix(QQ, 3, 2)) S = @inferred similar(MT) @test S isa AbstractAlgebra.Solve.LazyTransposeMatElem diff --git a/test/generic/MPoly-test.jl b/test/generic/MPoly-test.jl index 4a3a10bd0e..f56dfa1ae4 100644 --- a/test/generic/MPoly-test.jl +++ b/test/generic/MPoly-test.jl @@ -1882,15 +1882,15 @@ end R, (x, y, z) = polynomial_ring(QQ, [:x, :y, :z]) f = x * y + 2 * x - 3 * z - @test @inferred collect(exponent_vectors(f)) == [[1, 1, 0], [1, 0, 0], [0, 0, 1]] - @test @inferred collect(exponent_vectors(Vector{UInt}, f)) == [UInt[1, 1, 0], UInt[1, 0, 0], UInt[0, 0, 1]] - @test @inferred collect(coefficients(f)) == [QQ(1), QQ(2), QQ(-3)] - @test @inferred collect(terms(f)) == [x * y, 2 * x, -3 * z] - @test @inferred collect(monomials(f)) == [x * y, x, z] - - @test @inferred first(exponent_vectors(f, inplace = true)) == [1, 1, 0] - @test @inferred first(exponent_vectors(Vector{UInt}, f, inplace = true)) == UInt[1, 1, 0] - @test @inferred first(coefficients(f, inplace = true)) == QQ(1) - @test @inferred first(monomials(f, inplace = true)) == x * y - @test @inferred first(terms(f, inplace = true)) == x * y + @test (@inferred collect(exponent_vectors(f))) == [[1, 1, 0], [1, 0, 0], [0, 0, 1]] + @test (@inferred collect(exponent_vectors(Vector{UInt}, f))) == [UInt[1, 1, 0], UInt[1, 0, 0], UInt[0, 0, 1]] + @test (@inferred collect(coefficients(f))) == [QQ(1), QQ(2), QQ(-3)] + @test (@inferred collect(terms(f))) == [x * y, 2 * x, -3 * z] + @test (@inferred collect(monomials(f))) == [x * y, x, z] + + @test (@inferred first(exponent_vectors(f, inplace = true))) == [1, 1, 0] + @test (@inferred first(exponent_vectors(Vector{UInt}, f, inplace = true))) == UInt[1, 1, 0] + @test (@inferred first(coefficients(f, inplace = true))) == QQ(1) + @test (@inferred first(monomials(f, inplace = true))) == x * y + @test (@inferred first(terms(f, inplace = true))) == x * y end