Skip to content

Commit

Permalink
fmac -> MA
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Feb 26, 2024
1 parent de56536 commit 59807e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
20 changes: 14 additions & 6 deletions src/mstructures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,31 @@ When the product is not representable faithfully,
"""
abstract type MultiplicativeStructure end

struct UnsafeAddMul{M<:MultiplicativeStructure}
structure::M
end

function MA.operate_to!(
res::SparseCoefficients,
ms::MultiplicativeStructure,
v::AbstractCoefficients,
w::AbstractCoefficients,
)
MA.operate!(zero, res)
res = fmac!(ms, res, v, w)
res = MA.operate_to!(res, UnsafeAddMul(ms), v, w)
__canonicalize!(res)
return res
end

function fmac!(
ms::MultiplicativeStructure,
function MA.operate_to!(
res::SparseCoefficients,
ms::UnsafeAddMul,
v::AbstractCoefficients,
w::AbstractCoefficients,
)
for (kv, a) in pairs(v)
for (kw, b) in pairs(w)
c = ms(kv, kw) # ::AbstractCoefficients
c = ms.structure(kv, kw) # ::AbstractCoefficients
unsafe_append!(res, c => a * b)
end
end
Expand All @@ -61,8 +65,12 @@ function MA.operate_to!(
X::AbstractVector,
Y::AbstractVector,
)
res = (res === X || res === Y) ? zero(res) : (res .= zero(eltype(res)))
fmac!(ms, res, X, Y)
if res === X || res === Y
res = zero(res)
else
MA.operate!(zero, res)
end
MA.operate_to!(res, UnsafeAddMul(ms), X, Y)
res = __canonicalize!(res)
return res
end
Expand Down
8 changes: 4 additions & 4 deletions src/mtables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ function complete!(mt::MTable)
return mt
end

function fmac!(
ms::MTable,
function MA.operate_to!(
res::AbstractSparseVector,
ms::UnsafeAddMul{<:MTable},
v::AbstractVector,
w::AbstractVector,
)
Expand All @@ -93,9 +93,9 @@ function fmac!(

for (kv, a) in _nzpairs(v)
for (kw, b) in _nzpairs(w)
c = ms(kv, kw)
c = ms.structure(kv, kw)
for (k, v) in pairs(c)
push!(idcs, ms[k])
push!(idcs, ms.structure[k])
push!(vals, v * a * b)
end
end
Expand Down

0 comments on commit 59807e5

Please sign in to comment.