diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 908a770..d651782 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -13,7 +13,7 @@ Base.:(//)(X::AlgebraElement, a::Number) = AlgebraElement(coeffs(X) .// a, paren Base.:div(X::AlgebraElement, a::Number) = AlgebraElement(div.(coeffs(X), a), parent(X)) # ring structure: -Base.:-(X::AlgebraElement) = neg!(similar(X), X) +Base.:-(X::AlgebraElement) = MA.operate_to!(similar(X), -, X) function _preallocate_output(X::AlgebraElement, Y::AlgebraElement, op) T = Base._return_type(op, Tuple{eltype(X),eltype(Y)}) @@ -38,7 +38,7 @@ end MA.operate!(::typeof(zero), v::SparseVector) = (v .*= 0; v) -function neg!(res::AlgebraElement, X::AlgebraElement) +function MA.operate_to!(res::AlgebraElement, ::typeof(-), X::AlgebraElement) @assert parent(res) === parent(X) res.coeffs .= .-coeffs(X) return res @@ -69,7 +69,7 @@ end function sub!(res::AlgebraElement, X::AlgebraElement, Y::AlgebraElement) @assert parent(res) === parent(X) === parent(Y) - neg!(res, Y) + MA.operate_to!(res, -, Y) add!(res, res, X) return res end diff --git a/test/arithmetic.jl b/test/arithmetic.jl index 902a19c..e7472cb 100644 --- a/test/arithmetic.jl +++ b/test/arithmetic.jl @@ -210,14 +210,14 @@ let d = deepcopy(a) StarAlgebras.zero!(d) - StarAlgebras.neg!(d, a) + MA.operate_to!(d, -, a) d = deepcopy(a) @test !iszero(d) @test @allocated(StarAlgebras.zero!(d)) == 0 @test iszero(d) - @test @allocated(StarAlgebras.neg!(d, a)) == 0 + @test @allocated(MA.operate_to!(d, -, a)) == 0 @test d == -a end