Skip to content

Commit

Permalink
fix: rename MA.operate_to! to MA.operate! when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed Dec 10, 2024
1 parent f35b2a9 commit 51d67fe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 7 additions & 7 deletions src/mstructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/quadratic_form.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/monoid_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 51d67fe

Please sign in to comment.