Skip to content

Commit 5d04216

Browse files
refactor: use new polynomial_merge! (#181)
* refactor: use new `polynomial_merge!` * test: test in-place non-concrete polynomial addition * build: bump MutableArithmetics compat * build: bump MultivariatePolynomials compat
1 parent b5f4780 commit 5d04216

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1212
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1313

1414
[compat]
15-
MultivariatePolynomials = "0.5.9"
16-
MutableArithmetics = "1"
15+
MultivariatePolynomials = "0.5.12"
16+
MutableArithmetics = "1.6.5"
1717
Reexport = "1"
1818
julia = "1"
1919

src/operators.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ end
183183
# TODO need to check that this also works for non-commutative
184184
function MA.operate!(
185185
op::Union{typeof(+),typeof(-)},
186-
p::Polynomial{V},
187-
q::Polynomial{V},
188-
) where {V<:Commutative}
186+
p::Polynomial{V, M1, T1},
187+
q::Polynomial{V, M2, T2},
188+
) where {V<:Commutative, M1, M2, T1, T2}
189189
if MP.variables(p) != MP.variables(q)
190190
allvars, maps = ___add_variables!(p, q)
191191
if length(allvars) == length(MP.variables(q))
@@ -239,6 +239,7 @@ function MA.operate!(
239239
combine,
240240
keep,
241241
resize,
242+
Tuple{MA.promote_operation(op, T1, T2), Vector{Int}},
242243
)
243244
return p
244245
end

test/mutable_arithmetics.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using Test
22

33
import MutableArithmetics
44
const MA = MutableArithmetics
5+
import MultivariatePolynomials as MP
56

67
using DynamicPolynomials
78

@@ -100,3 +101,15 @@ end
100101
@test (@allocated MA.operate!(-, poly2, x)) <= 144
101102
end
102103
end
104+
105+
@testset "Non-concrete in-place polynomial addition" begin
106+
@polyvar p q r s
107+
p1 = MP.polynomial(r - q, Number) + MP.polynomial(3//5 * p^2, Number)
108+
p2 = MP.polynomial(1//2 + s, Number) + MP.polynomial(p^2, Number)
109+
result = p1 + p2
110+
@test isequal(result, MA.operate!(+, p1, p2))
111+
112+
p1 = MP.polynomial(r - q, Number) + MP.polynomial(3//5 * p^2, Number)
113+
p2 = MP.polynomial(1//2 + s, Number) + MP.polynomial(p^2, Number)
114+
@test isequal(result, MA.operate!(+, p2, p1))
115+
end

0 commit comments

Comments
 (0)