1
0
mirror of https://github.com/kalmarek/GroupRings.jl.git synced 2024-08-08 16:13:51 +02:00

subtraction allocates once only

This commit is contained in:
kalmarek 2018-08-13 19:31:58 +02:00
parent 86777050b1
commit 29f5bc1ee7

View File

@ -308,28 +308,20 @@ end
############################################################################### ###############################################################################
function addeq!{T}(X::GroupRingElem{T}, Y::GroupRingElem{T}) function addeq!{T}(X::GroupRingElem{T}, Y::GroupRingElem{T})
X.coeffs .+= Y.coeffs X.coeffs += Y.coeffs
return X return X
end end
function add{T<:Number}(X::GroupRingElem{T}, Y::GroupRingElem{T}, check::Bool=true) function +(X::GroupRingElem{T}, Y::GroupRingElem{T}) where T
if check
parent(X) == parent(Y) || throw("Elements don't seem to belong to the same Group Ring!")
end
return GroupRingElem(X.coeffs+Y.coeffs, parent(X)) return GroupRingElem(X.coeffs+Y.coeffs, parent(X))
end end
function add{T<:Number, S<:Number}(X::GroupRingElem{T}, function +(X::GroupRingElem{T}, Y::GroupRingElem{S}) where {T,S}
Y::GroupRingElem{S}, check::Bool=true) warn("Adding elements with different coefficient rings, Promoting result to $(promote_type(T,S))")
if check return GroupRingElem(X.coeffs+Y.coeffs, parent(X))
parent(X) == parent(Y) || throw("Elements don't seem to belong to the same Group Ring!")
end
warn("Adding elements with different base rings!")
return GroupRingElem(+(promote(X.coeffs, Y.coeffs)...), parent(X))
end end
(+)(X::GroupRingElem, Y::GroupRingElem) = add(X,Y) (-)(X::GroupRingElem, Y::GroupRingElem) = addeq!((-Y), X)
(-)(X::GroupRingElem, Y::GroupRingElem) = add(X,-Y)
doc""" doc"""
mul!{T}(result::AbstractArray{T}, mul!{T}(result::AbstractArray{T},