From 51d67fea865f7f35a2f0fad96f87fdcccbf02b46 Mon Sep 17 00:00:00 2001 From: Marek Kaluba Date: Tue, 10 Dec 2024 20:39:48 +0100 Subject: [PATCH] fix: rename MA.operate_to! to MA.operate! when appropriate --- src/arithmetic.jl | 6 +++--- src/mstructures.jl | 14 +++++++------- src/quadratic_form.jl | 2 +- test/monoid_algebra.jl | 5 +++++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/arithmetic.jl b/src/arithmetic.jl index e7a5088..a1eb2c1 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -143,12 +143,12 @@ function MA.operate_to!( return res end -function MA.operate_to!( - res::AlgebraElement, +function MA.operate!( mul::UnsafeAddMul, + res::AlgebraElement, ABC::Vararg{AlgebraElement,N}, ) where {N} - MA.operate_to!(coeffs(res), mul, map(coeffs, ABC)..., true) + MA.operate!(mul, coeffs(res), map(coeffs, ABC)..., true) return res end diff --git a/src/mstructures.jl b/src/mstructures.jl index f5923a7..7bb9817 100644 --- a/src/mstructures.jl +++ b/src/mstructures.jl @@ -59,28 +59,28 @@ function MA.operate_to!( ) end MA.operate!(zero, res) - res = MA.operate_to!(res, UnsafeAddMul(ms), args...) + res = MA.operate!(UnsafeAddMul(ms), res, args...) MA.operate!(canonical, res) return res end struct UnsafeAdd end -function MA.operate_to!(res, ::UnsafeAdd, b) +function MA.operate!(::UnsafeAdd, res, b) for (k, v) in nonzero_pairs(b) unsafe_push!(res, k, v) end return res end -function MA.operate_to!(res, op::UnsafeAddMul, A, B, α = true) +function MA.operate!(op::UnsafeAddMul, res, A, B, α) for (kA, vA) in nonzero_pairs(A) for (kB, vB) in nonzero_pairs(B) for (k, v) in nonzero_pairs(op.structure(kA, kB)) cfs = MA.@rewrite α * vA * vB * v - MA.operate_to!( - res, + MA.operate!( UnsafeAdd(), + res, SparseCoefficients((_key(op.structure, k),), (cfs,)), ) end @@ -89,11 +89,11 @@ function MA.operate_to!(res, op::UnsafeAddMul, A, B, α = true) return res end -function MA.operate_to!(res, op::UnsafeAddMul, A, B, C, α) +function MA.operate!(op::UnsafeAddMul, res, A, B, C, α) for (kA, vA) in nonzero_pairs(A) for (kB, vB) in nonzero_pairs(B) cfs = MA.@rewrite α * vA * vB - MA.operate_to!(res, op, op.structure(kA, kB), C, cfs) + MA.operate!(op, res, op.structure(kA, kB), C, cfs) end end return res diff --git a/src/quadratic_form.jl b/src/quadratic_form.jl index d2d68ea..866a649 100644 --- a/src/quadratic_form.jl +++ b/src/quadratic_form.jl @@ -37,7 +37,7 @@ function MA.operate_to!( for (i, b1) in pairs(basis(Q)) b1★ = ε(b1) for (j, b2) in pairs(basis(Q)) - MA.operate_to!(res, op, coeffs(b1★), coeffs(b2), Q[i, j]) + MA.operate!(op, res, coeffs(b1★), coeffs(b2), Q[i, j]) end end MA.operate!(canonical, res) diff --git a/test/monoid_algebra.jl b/test/monoid_algebra.jl index c930132..2e70b56 100644 --- a/test/monoid_algebra.jl +++ b/test/monoid_algebra.jl @@ -136,8 +136,13 @@ MA.operate_to!(d, *, a, b) @test d == a * b + MA.operate!(SA.UnsafeAddMul(SA.mstructure(RG)), d, a, b) + @test d == 2 * a * b + MA.operate_to!(d, *, a, b, b) @test d == a * b * b + MA.operate!(SA.UnsafeAddMul(SA.mstructure(RG)), d, a, b, b) + @test d == 2 * a * b * b end end end