Skip to content

Commit 01869ba

Browse files
authored
[BREAKING] Remove term iterator behavior of polynomial (#161)
* Remove term iterator behavior of polynomial * Fix * Fixes * Add bounds to MP
1 parent 469c47c commit 01869ba

File tree

5 files changed

+8
-19
lines changed

5 files changed

+8
-19
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1313
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1414

1515
[compat]
16-
MultivariatePolynomials = "0.5.3"
16+
MultivariatePolynomials = "0.5.6"
1717
MutableArithmetics = "1"
1818
Reexport = "1"
1919
julia = "1"

src/comp.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import Base.==
22

3-
#Base.iszero(t::Term) = iszero(MP.coefficient(t))
4-
Base.iszero(p::Polynomial) = isempty(p)
5-
63
# TODO This should be in Base with T instead of Variable{V,M}.
74
# See https://github.com/blegat/MultivariatePolynomials.jl/issues/3
85
function (==)(x::Vector{Variable{V,M}}, y::Vector{Variable{V,M}}) where {V,M}
@@ -162,10 +159,10 @@ end
162159
# Comparison of Term
163160
function (==)(p::Polynomial{V,M}, q::Polynomial{V,M}) where {V,M}
164161
# terms should be sorted and without zeros
165-
if length(p) != length(q)
162+
if MP.nterms(p) != MP.nterms(q)
166163
return false
167164
end
168-
for i in 1:length(p)
165+
for i in eachindex(p.a)
169166
if p.x[i] != q.x[i]
170167
# There should not be zero terms
171168
@assert p.a[i] != 0

src/mult.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ function _mul(
101101
else
102102
allvars, maps = mergevars([MP.variables(p), MP.variables(q)])
103103
end
104-
N = length(p) * length(q)
104+
N = MP.nterms(p) * MP.nterms(q)
105105
Z = Vector{Vector{Int}}(undef, N)
106106
a = Vector{T}(undef, N)
107107
i = 0
108-
for u in p
109-
for v in q
108+
for u in MP.terms(p)
109+
for v in MP.terms(q)
110110
if samevars
111111
z = MP.monomial(u).z + MP.monomial(v).z
112112
else

src/operators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ end
1515
Base.:(+)(x::DMonomialLike, y::DMonomialLike) = MP.term(x) + MP.term(y)
1616
Base.:(-)(x::DMonomialLike, y::DMonomialLike) = MP.term(x) - MP.term(y)
1717

18-
_getindex(p::Polynomial, i::Int) = p[i]
18+
_getindex(p::Polynomial, i::Int) = MP.terms(p)[i]
1919
_getindex(t::_Term, ::Int) = t
2020
function _plusorminus_to!(
2121
a::Vector{U},

src/poly.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,6 @@ end
137137
#Base.convert(::Type{term_type{V,M}}, p::TermContainer{V,M}) where {V,M} = p
138138
#Base.convert(::Type{term_type{V,M,T}}, p::TermContainer{V,M,T}) where {V,M,T} = p
139139

140-
Base.length(p::Polynomial) = length(p.a)
141-
Base.isempty(p::Polynomial) = isempty(p.a)
142-
Base.iterate(p::Polynomial) = isempty(p) ? nothing : (p[1], 1)
143-
function Base.iterate(p::Polynomial, state::Int)
144-
return state < length(p) ? (p[state+1], state + 1) : nothing
145-
end
146-
#eltype(::Type{Polynomial{V,M,T}}) where {V,M,T} = T
147-
Base.getindex(p::Polynomial, I::Int) = MP.term(p.a[I[1]], p.x[I[1]])
148140

149141
#Base.transpose(p::Polynomial) = Polynomial(map(transpose, p.a), p.x) # FIXME invalid age range update
150142

@@ -192,7 +184,7 @@ function MP.remove_monomials(p::Polynomial, x::MonomialVector)
192184
# use the fact that monomials are sorted to do this O(n) instead of O(n^2)
193185
j = 1
194186
I = Int[]
195-
for (i, t) in enumerate(p)
187+
for (i, t) in enumerate(MP.terms(p))
196188
while j <= length(x) && x[j] < MP.monomial(t)
197189
j += 1
198190
end

0 commit comments

Comments
 (0)