Skip to content

Commit a75cd50

Browse files
authored
More @inferred fixes (Nemocas#2221)
1 parent 5294c69 commit a75cd50

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

src/MPoly.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,10 @@ function exponent_vector!(e::Vector{S}, a::MPolyRingElem{T}, i::Int) where {T <:
500500
return S.(exponent_vector(a, i))
501501
end
502502

503+
function exponent_vector(::Type{Vector{S}}, a::MPolyRingElem{T}, i::Int) where {T <: RingElement, S}
504+
return S.(exponent_vector(a, i))
505+
end
506+
503507
function coeff!(c::T, a::MPolyRingElem{T}, i::Int) where {T <: RingElement}
504508
return coeff(a, i)
505509
end

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

src/generic/imports.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ import ..AbstractAlgebra: domain
131131
import ..AbstractAlgebra: elem_type
132132
import ..AbstractAlgebra: evaluate
133133
import ..AbstractAlgebra: exp
134+
import ..AbstractAlgebra: exponent_vector
134135
import ..AbstractAlgebra: exponent_vectors
135136
import ..AbstractAlgebra: exponent_vector!
136137
import ..AbstractAlgebra: expressify

test/Solve-test.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ end
244244

245245
@test base_ring(MT) == QQ
246246

247-
@test @inferred zero(MT) == AbstractAlgebra.Solve.lazy_transpose(zero_matrix(QQ, 3, 5))
248-
@test @inferred zero(MT, 2, 3) == AbstractAlgebra.Solve.lazy_transpose(zero_matrix(QQ, 3, 2))
247+
@test (@inferred zero(MT)) == AbstractAlgebra.Solve.lazy_transpose(zero_matrix(QQ, 3, 5))
248+
@test (@inferred zero(MT, 2, 3)) == AbstractAlgebra.Solve.lazy_transpose(zero_matrix(QQ, 3, 2))
249249

250250
S = @inferred similar(MT)
251251
@test S isa AbstractAlgebra.Solve.LazyTransposeMatElem

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)