Skip to content

Commit a2faa05

Browse files
committed
Pass int tests with DynamicPolynomials
1 parent 71172d3 commit a2faa05

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

src/monomial.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ The multiplication `m1 * m2` is equivalent to `mapexponents(+, m1, m2)`, the uns
122122
"""
123123
mapexponents(f, m1::AbstractMonomialLike, m2::AbstractMonomialLike) = mapexponents(f, monomial(m1), monomial(m2))
124124

125+
function mapexponents_to! end
126+
function mapexponents! end
127+
125128
Base.one(::Type{TT}) where {TT<:AbstractMonomialLike} = constantmonomial(TT)
126129
Base.one(t::AbstractMonomialLike) = constantmonomial(t)
127130
MA.promote_operation(::typeof(one), MT::Type{<:AbstractMonomialLike}) = monomialtype(MT)

src/operators.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ _multconstant(α, f, p::AbstractPolynomialLike) = _multconstant(α, f, polynomia
7474
multconstant(α, p::AbstractPolynomialLike) = _multconstant(α, β -> α*β, p)
7575
multconstant(p::AbstractPolynomialLike, α) = _multconstant(α, β -> β*α, p)
7676

77+
MA.mutable_operate_to!(output::AbstractMonomial, ::typeof(*), m1::AbstractMonomialLike, m2::AbstractMonomialLike) = mapexponents_to!(output, +, m1, m2)
78+
MA.mutable_operate!(::typeof(*), m1::AbstractMonomial, m2::AbstractMonomialLike) = mapexponents!(+, m1, m2)
7779
Base.:*(m1::AbstractMonomialLike, m2::AbstractMonomialLike) = mapexponents(+, m1, m2)
7880
#Base.:*(m1::AbstractMonomialLike, m2::AbstractMonomialLike) = *(monomial(m1), monomial(m2))
7981

@@ -140,3 +142,19 @@ Base.vec(vars::Tuple{Vararg{AbstractVariable}}) = [vars...]
140142

141143
# https://github.com/JuliaLang/julia/pull/23332
142144
Base.:^(x::AbstractPolynomialLike, p::Integer) = Base.power_by_squaring(x, p)
145+
146+
function MA.mutable_operate_to!(output::AbstractPolynomial, ::typeof(MA.add_mul), x, args::Vararg{Any, N}) where N
147+
return MA.mutable_operate_to!(output, +, x, *(args...))
148+
end
149+
function MA.mutable_operate!(::typeof(MA.add_mul), x, args::Vararg{Any, N}) where N
150+
return MA.mutable_operate!(+, x, *(args...))
151+
end
152+
MA.buffer_for(::typeof(MA.add_mul), ::Type{<:AbstractPolynomial}, args::Vararg{Any, N}) where {N} = MA.promote_operation(*, args...)
153+
function MA.mutable_buffered_operate_to!(buffer::AbstractPolynomial, output::AbstractPolynomial, ::typeof(MA.add_mul), x, args::Vararg{Any, N}) where N
154+
product = MA.operate_to!(buffer, *, args...)
155+
return MA.mutable_operate_to!(output, +, x, product)
156+
end
157+
function MA.mutable_buffered_operate!(buffer::AbstractPolynomial, ::typeof(MA.add_mul), x, args::Vararg{Any, N}) where N
158+
product = MA.operate_to!(buffer, *, args...)
159+
return MA.mutable_operate!(+, x, product)
160+
end

test/commutativetests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include("mutable_arithmetics.jl")
2+
13
include("zip.jl")
24
include("variable.jl")
35
include("monomial.jl")

test/mutable_arithmetics.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import MutableArithmetics
2+
const MA = MutableArithmetics
3+
4+
@testset "MutableArithmetics with $T" for T in [BigInt]
5+
Mod.@polyvar x y
6+
# @testset "Int" begin
7+
MA.Test.int_test(termtype(x, T), exclude = ["int_add", "int_add_mul", "int_zero"])
8+
MA.Test.int_test(polynomialtype(x, T))
9+
# end
10+
# a = T(2) * x^2 + T(3) * x * y + T(4) * y
11+
# b = T(4) * y^2 - T(1) * x * y + T(4) * x
12+
# c = T(1) * x^2 + T(3) * x - T(4)
13+
# d = T(5) * x^2 * y - T(3) * x + T(4) * y
14+
# @testset "Scalar" begin
15+
# MA.Test.scalar_test(a)
16+
# end
17+
# @testset "Quadratic" begin
18+
# MA.Test.quadratic_test(a, b, c, d)
19+
# end
20+
# @testset "Sparse" begin
21+
# MA.Test.sparse_test(a, b, T[a b c; b c a; a b a])
22+
# end
23+
# @testset "Vector" begin
24+
# MA.Test.array_test(T[a, b, c])
25+
# end
26+
# @testset "Matrix" begin
27+
# MA.Test.array_test(T[a b; c d])
28+
# MA.Test.array_test(T[a b c; b c a; a b a])
29+
# end
30+
end

0 commit comments

Comments
 (0)