Skip to content

Commit 102ec7b

Browse files
committed
Use `@inferred` correctly and fix return type
1 parent 7743f23 commit 102ec7b

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/generic/MPoly.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ are given in the order of the variables for the ring, as supplied when the
129129
ring was created.
130130
"""
131131
function exponent_vector(a::MPoly{T}, i::Int) where T <: RingElement
132-
e = Vector{Int}(undef, nvars(parent(a)))
133-
return exponent_vector!(e, a, i)
132+
return exponent_vector(Vector{Int}, a, i)
133+
end
134+
135+
function exponent_vector(::Type{Vector{S}}, a::MPoly{T}, i::Int) where {T <: RingElement, S}
136+
e = Vector{S}(undef, nvars(parent(a)))
137+
return exponent_vector!(e, a, i)
134138
end
135139

136140
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)
843847
end
844848
end
845849

846-
function Base.iterate(x::MPolyExponentVectors, state::Union{Nothing, Int} = nothing)
850+
function Base.iterate(x::MPolyExponentVectors{T, S}, state::Union{Nothing, Int} = nothing) where {T, S}
847851
s = isnothing(state) ? 1 : state + 1
848852
if length(x.poly) >= s
849-
v = x.inplace ? exponent_vector!(x.temp, x.poly, s) : exponent_vector(x.poly, s)
853+
v = x.inplace ? exponent_vector!(x.temp, x.poly, s) : exponent_vector(S, x.poly, s)
850854
return v, s
851855
else
852856
return nothing

test/generic/MPoly-test.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,15 +1882,15 @@ end
18821882
R, (x, y, z) = polynomial_ring(QQ, [:x, :y, :z])
18831883
f = x * y + 2 * x - 3 * z
18841884

1885-
@test @inferred collect(exponent_vectors(f)) == [[1, 1, 0], [1, 0, 0], [0, 0, 1]]
1886-
@test @inferred collect(exponent_vectors(Vector{UInt}, f)) == [UInt[1, 1, 0], UInt[1, 0, 0], UInt[0, 0, 1]]
1887-
@test @inferred collect(coefficients(f)) == [QQ(1), QQ(2), QQ(-3)]
1888-
@test @inferred collect(terms(f)) == [x * y, 2 * x, -3 * z]
1889-
@test @inferred collect(monomials(f)) == [x * y, x, z]
1890-
1891-
@test @inferred first(exponent_vectors(f, inplace = true)) == [1, 1, 0]
1892-
@test @inferred first(exponent_vectors(Vector{UInt}, f, inplace = true)) == UInt[1, 1, 0]
1893-
@test @inferred first(coefficients(f, inplace = true)) == QQ(1)
1894-
@test @inferred first(monomials(f, inplace = true)) == x * y
1895-
@test @inferred first(terms(f, inplace = true)) == x * y
1885+
@test (@inferred collect(exponent_vectors(f))) == [[1, 1, 0], [1, 0, 0], [0, 0, 1]]
1886+
@test (@inferred collect(exponent_vectors(Vector{UInt}, f))) == [UInt[1, 1, 0], UInt[1, 0, 0], UInt[0, 0, 1]]
1887+
@test (@inferred collect(coefficients(f))) == [QQ(1), QQ(2), QQ(-3)]
1888+
@test (@inferred collect(terms(f))) == [x * y, 2 * x, -3 * z]
1889+
@test (@inferred collect(monomials(f))) == [x * y, x, z]
1890+
1891+
@test (@inferred first(exponent_vectors(f, inplace = true))) == [1, 1, 0]
1892+
@test (@inferred first(exponent_vectors(Vector{UInt}, f, inplace = true))) == UInt[1, 1, 0]
1893+
@test (@inferred first(coefficients(f, inplace = true))) == QQ(1)
1894+
@test (@inferred first(monomials(f, inplace = true))) == x * y
1895+
@test (@inferred first(terms(f, inplace = true))) == x * y
18961896
end

0 commit comments

Comments
 (0)