Skip to content
Merged
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: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
MultivariatePolynomials = "0.5.9"
MutableArithmetics = "1"
MultivariatePolynomials = "0.5.12"
MutableArithmetics = "1.6.5"
Reexport = "1"
julia = "1"

Expand Down
7 changes: 4 additions & 3 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ end
# TODO need to check that this also works for non-commutative
function MA.operate!(
op::Union{typeof(+),typeof(-)},
p::Polynomial{V},
q::Polynomial{V},
) where {V<:Commutative}
p::Polynomial{V, M1, T1},
q::Polynomial{V, M2, T2},
) where {V<:Commutative, M1, M2, T1, T2}
if MP.variables(p) != MP.variables(q)
allvars, maps = ___add_variables!(p, q)
if length(allvars) == length(MP.variables(q))
Expand Down Expand Up @@ -239,6 +239,7 @@ function MA.operate!(
combine,
keep,
resize,
Tuple{MA.promote_operation(op, T1, T2), Vector{Int}},
)
return p
end
Expand Down
13 changes: 13 additions & 0 deletions test/mutable_arithmetics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Test

import MutableArithmetics
const MA = MutableArithmetics
import MultivariatePolynomials as MP

using DynamicPolynomials

Expand Down Expand Up @@ -100,3 +101,15 @@ end
@test (@allocated MA.operate!(-, poly2, x)) <= 144
end
end

@testset "Non-concrete in-place polynomial addition" begin
@polyvar p q r s
p1 = MP.polynomial(r - q, Number) + MP.polynomial(3//5 * p^2, Number)
p2 = MP.polynomial(1//2 + s, Number) + MP.polynomial(p^2, Number)
result = p1 + p2
@test isequal(result, MA.operate!(+, p1, p2))

p1 = MP.polynomial(r - q, Number) + MP.polynomial(3//5 * p^2, Number)
p2 = MP.polynomial(1//2 + s, Number) + MP.polynomial(p^2, Number)
@test isequal(result, MA.operate!(+, p2, p1))
end