Skip to content

Commit

Permalink
replace Val dispatch by __lmul and __rmul functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmarek committed Jul 4, 2024
1 parent 0e1f0de commit 7a0232e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ function Base.:*(
a::T,
X::AlgebraElement{A},
) where {T,O,A<:AbstractStarAlgebra{O,T}}
return MA.operate_to!(similar(X), Val(:lmul), a, X)
return MA.operate_to!(similar(X), __lmul, a, X)
end
function Base.:*(
X::AlgebraElement{A},
a::T,
) where {T,O,A<:AbstractStarAlgebra{O,T}}
return MA.operate_to!(similar(X), Val(:rmul), a, X)
return MA.operate_to!(similar(X), __rmul, a, X)
end

for op in [:+, :-, :*]
Expand Down Expand Up @@ -95,7 +95,12 @@ function MA.operate_to!(
return res
end

function MA.operate_to!(res::AlgebraElement, mul::Val, a, X::AlgebraElement)
function MA.operate_to!(
res::AlgebraElement,
mul::Union{typeof(__lmul),typeof(__rmul)},
a,
X::AlgebraElement,
)
@assert parent(res) == parent(X)
MA.operate_to!(coeffs(res), mul, a, coeffs(X))
return res
Expand Down
10 changes: 6 additions & 4 deletions src/coefficients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,12 @@ function MA.operate_to!(
return res
end

__lmul(a, k) = a * k
__rmul(a, k) = k * a

function MA.operate_to!(
res::AbstractCoefficients,
mul::Val,
mul::Union{typeof(__lmul),typeof(__rmul)},
a,
X::AbstractCoefficients,
)
Expand All @@ -252,11 +255,10 @@ function MA.operate_to!(
else
MA.operate!(zero, res)
for (k, v) in nonzero_pairs(X)
res[__op(a, k, mul)] += v
res[mul(a, k)] += v
end
end
return res
end

__op(a, k, ::Val{:lmul}) = a * k
__op(a, k, ::Val{:rmul}) = k * a

0 comments on commit 7a0232e

Please sign in to comment.