Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/generic/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/generic/imports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/Solve-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions test/generic/MPoly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading