Skip to content

Commit 5c862c4

Browse files
authored
Update to MutableArithmetics v0.3 (#74)
* Update to MutableArithmetics v0.3 * Updates
1 parent 21c561f commit 5c862c4

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1313

1414
[compat]
1515
MacroTools = "0.5"
16-
MultivariatePolynomials = "~0.3.5"
17-
MutableArithmetics = "0.2"
16+
MultivariatePolynomials = "0.4"
17+
MutableArithmetics = "0.3"
1818
NBInclude = "2"
1919
julia = "1"
2020

src/operators.jl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,32 @@ end
5151
(+)(p1::Polynomial, p2::Polynomial{<:UniformScaling}) = p1 + MP.mapcoefficientsnz(J -> J.λ, p2)
5252
(+)(p1::Polynomial{<:UniformScaling}, p2::Polynomial) = MP.mapcoefficientsnz(J -> J.λ, p1) + p2
5353
(+)(p1::Polynomial{<:UniformScaling}, p2::Polynomial{<:UniformScaling}) = MP.mapcoefficientsnz(J -> J.λ, p1) + p2
54-
function MA.mutable_operate_to!(result::Polynomial, ::typeof(+), p1::Polynomial, p2::Polynomial)
54+
function MA.operate_to!(result::Polynomial, ::typeof(+), p1::Polynomial, p2::Polynomial)
5555
if result === p1 || result === p2
56-
error("Cannot call `mutable_operate_to!(output, +, p, q)` with `output` equal to `p` or `q`, call `mutable_operate!` instead.")
56+
error("Cannot call `operate_to!(output, +, p, q)` with `output` equal to `p` or `q`, call `operate!` instead.")
5757
end
5858
jointerms!(result.terms, terms(p1), terms(p2))
5959
result
6060
end
61-
function MA.mutable_operate_to!(result::Polynomial, ::typeof(*), p::Polynomial, t::AbstractTermLike)
61+
function MA.operate_to!(result::Polynomial, ::typeof(*), p::Polynomial, t::AbstractTermLike)
6262
if iszero(t)
63-
MA.mutable_operate!(zero, result)
63+
MA.operate!(zero, result)
6464
else
6565
resize!(result.terms, nterms(p))
6666
for i in eachindex(p.terms)
67-
# TODO could use MA.mul_to! for indices that were presents in `result` before the `resize!`.
67+
# TODO could use MA.mul_to!! for indices that were presents in `result` before the `resize!`.
6868
result.terms[i] = p.terms[i] * t
6969
end
7070
return result
7171
end
7272
end
73-
function MA.mutable_operate_to!(result::Polynomial, ::typeof(*), t::AbstractTermLike, p::Polynomial)
73+
function MA.operate_to!(result::Polynomial, ::typeof(*), t::AbstractTermLike, p::Polynomial)
7474
if iszero(t)
75-
MA.mutable_operate!(zero, result)
75+
MA.operate!(zero, result)
7676
else
7777
resize!(result.terms, nterms(p))
7878
for i in eachindex(p.terms)
79-
# TODO could use MA.mul_to! for indices that were presents in `result` before the `resize!`.
79+
# TODO could use MA.mul_to!! for indices that were presents in `result` before the `resize!`.
8080
result.terms[i] = t * p.terms[i]
8181
end
8282
return result
@@ -87,7 +87,7 @@ end
8787
(-)(p1::Polynomial{<:UniformScaling}, p2::Polynomial) = MP.mapcoefficientsnz(J -> J.λ, p1) - p2
8888
(-)(p1::Polynomial{<:UniformScaling}, p2::Polynomial{<:UniformScaling}) = MP.mapcoefficientsnz(J -> J.λ, p1) - p2
8989

90-
function MA.mutable_operate!(op::Union{typeof(+), typeof(-)}, p::Polynomial{T}, q::Polynomial) where T
90+
function MA.operate!(op::Union{typeof(+), typeof(-)}, p::Polynomial{T}, q::Polynomial) where T
9191
get1(i) = p.terms[i]
9292
function get2(i)
9393
t = q.terms[i]
@@ -97,12 +97,12 @@ function MA.mutable_operate!(op::Union{typeof(+), typeof(-)}, p::Polynomial{T},
9797
push(t::Term) = push!(p.terms, t)
9898
compare_monomials(t::Term, j::Int) = grlex(q.terms[j].monomial, t.monomial)
9999
compare_monomials(i::Int, j::Int) = compare_monomials(get1(i), j)
100-
combine(i::Int, j::Int) = p.terms[i] = Term(MA.operate!(op, p.terms[i].coefficient, q.terms[j].coefficient), p.terms[i].monomial)
101-
combine(t::Term, j::Int) = Term(MA.operate!(op, t.coefficient, q.terms[j].coefficient), t.monomial)
100+
combine(i::Int, j::Int) = p.terms[i] = Term(MA.operate!!(op, p.terms[i].coefficient, q.terms[j].coefficient), p.terms[i].monomial)
101+
combine(t::Term, j::Int) = Term(MA.operate!!(op, t.coefficient, q.terms[j].coefficient), t.monomial)
102102
resize(n) = resize!(p.terms, n)
103103
# We can modify the coefficient since it's the result of `combine`.
104-
keep(t::Term) = !MA.iszero!(t.coefficient)
105-
keep(i::Int) = !MA.iszero!(p.terms[i].coefficient)
104+
keep(t::Term) = !MA.iszero!!(t.coefficient)
105+
keep(i::Int) = !MA.iszero!!(p.terms[i].coefficient)
106106
MP.polynomial_merge!(
107107
nterms(p), nterms(q), get1, get2, set, push,
108108
compare_monomials, combine, keep, resize
@@ -138,36 +138,36 @@ function MP.mapexponents!(op::F, m1::Monomial, m2::Monomial) where {F<:Function}
138138
return MP.mapexponents(op, m1, m2)
139139
end
140140

141-
function MA.mutable_operate_to!(output::Polynomial, ::typeof(*), p::Polynomial, q::Polynomial)
141+
function MA.operate_to!(output::Polynomial, ::typeof(*), p::Polynomial, q::Polynomial)
142142
empty!(output.terms)
143143
MP.mul_to_terms!(output.terms, p, q)
144144
sort!(output.terms, lt=(>))
145145
MP.uniqterms!(output.terms)
146146
return output
147147
end
148-
function MA.mutable_operate!(::typeof(*), p::Polynomial, q::Polynomial)
149-
return MA.mutable_operate_to!(p, *, MA.mutable_copy(p), q)
148+
function MA.operate!(::typeof(*), p::Polynomial, q::Polynomial)
149+
return MA.operate_to!(p, *, MA.mutable_copy(p), q)
150150
end
151151

152-
function MA.mutable_operate!(::typeof(zero), p::Polynomial)
152+
function MA.operate!(::typeof(zero), p::Polynomial)
153153
empty!(p.terms)
154154
return p
155155
end
156-
function MA.mutable_operate!(::typeof(one), p::Polynomial{T}) where T
156+
function MA.operate!(::typeof(one), p::Polynomial{T}) where T
157157
if isempty(p.terms)
158158
push!(p.terms, constantterm(one(T), p))
159159
else
160160
t = p.terms[1]
161-
p.terms[1] = Term(MA.one!(coefficient(t)), constantmonomial(t))
161+
p.terms[1] = Term(MA.one!!(coefficient(t)), constantmonomial(t))
162162
resize!(p.terms, 1)
163163
end
164164
return p
165165
end
166166

167167
# The exponents are stored in a tuple, this is not mutable.
168168
# We could remove these methods since it is the default.
169-
MA.mutability(::Type{<:Monomial}) = MA.NotMutable()
170-
MA.mutability(::Type{<:Term}) = MA.NotMutable()
169+
MA.mutability(::Type{<:Monomial}) = MA.IsNotMutable()
170+
MA.mutability(::Type{<:Term}) = MA.IsNotMutable()
171171
# The polynomials can be mutated.
172172
MA.mutability(::Type{<:Polynomial}) = MA.IsMutable()
173173

@@ -202,7 +202,7 @@ function MP.mapcoefficientsnz_to!(output::Polynomial, f::Function, p::AbstractPo
202202
return MP.mapcoefficientsnz_to!(output, f, polynomial(p))
203203
end
204204

205-
function MA.mutable_operate!(::typeof(MP.removeleadingterm), p::Polynomial)
205+
function MA.operate!(::typeof(MP.removeleadingterm), p::Polynomial)
206206
deleteat!(p.terms, 1)
207207
return p
208208
end

0 commit comments

Comments
 (0)