diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7939bb0..7cb989a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,16 @@ jobs: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - uses: julia-actions/cache@v2 + - uses: actions/checkout@v4 + with: + repository: AayushSabharwal/MultivariatePolynomials.jl + ref: as/poly-merge-nonconcrete + path: upstream + - name: Use branch + shell: julia --color=yes --project=@. {0} + run: | + using Pkg + Pkg.develop(PackageSpec(; path = "upstream")) - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 with: diff --git a/src/operators.jl b/src/operators.jl index dd27226..cbe67b7 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -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)) @@ -239,6 +239,7 @@ function MA.operate!( combine, keep, resize, + Tuple{MA.promote_operation(op, T1, T2), Vector{Int}}, ) return p end diff --git a/test/mutable_arithmetics.jl b/test/mutable_arithmetics.jl index 5529013..f5959d7 100644 --- a/test/mutable_arithmetics.jl +++ b/test/mutable_arithmetics.jl @@ -2,6 +2,7 @@ using Test import MutableArithmetics const MA = MutableArithmetics +import MultivariatePolynomials as MP using DynamicPolynomials @@ -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