Skip to content

Commit

Permalink
mul! -> MA.operate_to!
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Feb 26, 2024
1 parent 3c226f7 commit b8faeb2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function Base.:*(a::Number, X::AlgebraElement)
T = Base._return_type(*, Tuple{eltype(X),typeof(a)})
return mul!(similar(X, T), X, a)
return MA.operate_to!(similar(X, T), *, X, a)
end

Base.:*(X::AlgebraElement, a::Number) = a * X
Expand All @@ -25,7 +25,7 @@ end

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)
Base.:*(X::AlgebraElement, Y::AlgebraElement) = MA.operate_to!(_preallocate_output(X, Y, *), *, X, Y)

Base.:^(a::AlgebraElement, p::Integer) = Base.power_by_squaring(a, p)

Expand Down Expand Up @@ -74,7 +74,7 @@ function sub!(res::AlgebraElement, X::AlgebraElement, Y::AlgebraElement)
return res
end

function mul!(res::AlgebraElement, X::AlgebraElement, a::Number)
function MA.operate_to!(res::AlgebraElement, ::typeof(*), X::AlgebraElement, a::Number)
@assert parent(res) === parent(X)
if res !== X
MA.operate!(zero, res)
Expand All @@ -85,7 +85,7 @@ function mul!(res::AlgebraElement, X::AlgebraElement, a::Number)
return res
end

function mul!(res::AlgebraElement, X::AlgebraElement, Y::AlgebraElement)
function MA.operate_to!(res::AlgebraElement, ::typeof(*), X::AlgebraElement, Y::AlgebraElement)
@assert parent(res) === parent(X) === parent(Y)
mstr = mstructure(basis(parent(res)))
mul!(mstr, coeffs(res), coeffs(X), coeffs(Y))
Expand Down
24 changes: 12 additions & 12 deletions test/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
norm(a)^2
LinearAlgebra.dot(coeffs(a), a)

@test a * b == StarAlgebras.mul!(a, a, b)
@test a * b == MA.operate_to!(a, *, a, b)

@test aug(a) == 3
@test aug(b) == -1
Expand Down Expand Up @@ -164,7 +164,7 @@

@test coeffs(X * Y) ==
coeffs(Xc * Yc) ==
coeffs(StarAlgebras.mul!(Z, X, Y))
coeffs(MA.operate_to!(Z, *, X, Y))

@test coeffs(X^2) == coeffs(Xc^2) == coeffs(X * X)
@test coeffs(Y^2) == coeffs(Yc^2) == coeffs(Y * Y)
Expand All @@ -187,7 +187,7 @@
MA.operate!(zero, W)
StarAlgebras.fmac!(coeffs(W), coeffs(X), coeffs(Y), RG.mstructure)

@test coeffs(2 * X * Y) == coeffs(StarAlgebras.mul!(W, W, 2))
@test coeffs(2 * X * Y) == coeffs(MA.operate_to!(W, *, W, 2))
end
end

Expand Down Expand Up @@ -239,25 +239,25 @@
end

let d = deepcopy(a)
StarAlgebras.mul!(d, d, 2)
StarAlgebras.mul!(d, a, 2)
StarAlgebras.mul!(d, a, b)
MA.operate_to!(d, *, d, 2)
MA.operate_to!(d, *, a, 2)
MA.operate_to!(d, *, a, b)
d = deepcopy(a)
StarAlgebras.mul!(d, d, b)
MA.operate_to!(d, *, d, b)

d = deepcopy(a)
@test @allocated(StarAlgebras.mul!(d, d, 2)) == 0
@test @allocated(MA.operate_to!(d, *, d, 2)) == 0
@test d == 2a

@test @allocated(StarAlgebras.mul!(d, a, 2)) == 0
@test @allocated(MA.operate_to!(d, *, a, 2)) == 0
@test d == 2a

@test @allocated(StarAlgebras.mul!(d, a, b)) == 32
@test @allocated(MA.operate_to!(d, *, a, b)) == 32
@test d == a * b

d = deepcopy(a)
@test @allocated(StarAlgebras.mul!(d, d, b)) != 0
z = StarAlgebras.mul!(d, d, b)
@test @allocated(MA.operate_to!(d, *, d, b)) != 0
z = MA.operate_to!(d, *, d, b)
@test z == a * b
@test z !== d
end
Expand Down
2 changes: 1 addition & 1 deletion test/sum_of_squares.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

G = (one(RG) - RG(g))
@test G' == one(RG) - RG(inv(g))
@test G' * G == StarAlgebras.mul!(zero(G), G', G) == 2one(RG) - RG(g) - RG(g)'
@test G' * G == MA.operate_to!(zero(G), *, G', G) == 2one(RG) - RG(g) - RG(g)'
@test star(G * G) == G' * G'

@testset "Sums of hermitian squares" begin
Expand Down

0 comments on commit b8faeb2

Please sign in to comment.