Skip to content

Commit

Permalink
add! -> operate_to!(+
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Feb 26, 2024
1 parent c40ae73 commit 3c226f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function _preallocate_output(X::AlgebraElement, Y::AlgebraElement, op)
return similar(X, T)
end

Base.:+(X::AlgebraElement, Y::AlgebraElement) = add!(_preallocate_output(X, Y, +), X, Y)
Base.:+(X::AlgebraElement, Y::AlgebraElement) = MA.operate_to!(_preallocate_output(X, Y, +), +, X, Y)
Base.:-(X::AlgebraElement, Y::AlgebraElement) = sub!(_preallocate_output(X, Y, -), X, Y)
Base.:*(X::AlgebraElement, Y::AlgebraElement) = mul!(_preallocate_output(X, Y, *), X, Y)

Expand All @@ -44,7 +44,7 @@ function MA.operate_to!(res::AlgebraElement, ::typeof(-), X::AlgebraElement)
return res
end

function add!(res::AlgebraElement, X::AlgebraElement, Y::AlgebraElement)
function MA.operate_to!(res::AlgebraElement, ::typeof(+), X::AlgebraElement, Y::AlgebraElement)
@assert parent(res) === parent(X)
@assert parent(X) === parent(Y)
if res === X
Expand All @@ -70,7 +70,7 @@ end
function sub!(res::AlgebraElement, X::AlgebraElement, Y::AlgebraElement)
@assert parent(res) === parent(X) === parent(Y)
MA.operate_to!(res, -, Y)
add!(res, res, X)
MA.operate_to!(res, +, res, X)
return res
end

Expand Down
12 changes: 6 additions & 6 deletions test/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,19 @@
end

let d = deepcopy(a)
StarAlgebras.add!(d, d, b)
StarAlgebras.add!(d, b, d)
StarAlgebras.add!(d, a, b)
MA.operate_to!(d, +, d, b)
MA.operate_to!(d, +, b, d)
MA.operate_to!(d, +, a, b)

d = deepcopy(a)
@test @allocated(StarAlgebras.add!(d, d, b)) == 0
@test @allocated(MA.operate_to!(d, +, d, b)) == 0
@test d == a + b

d = deepcopy(a)
@test @allocated(StarAlgebras.add!(d, b, d)) == 0
@test @allocated(MA.operate_to!(d, +, b, d)) == 0
@test d == a + b

@test @allocated(StarAlgebras.add!(d, a, b)) == 0
@test @allocated(MA.operate_to!(d, +, a, b)) == 0
@test d == a + b
end

Expand Down

0 comments on commit 3c226f7

Please sign in to comment.