subtraction allocates once only

This commit is contained in:
kalmarek 2018-08-13 19:31:58 +02:00
parent 86777050b1
commit 29f5bc1ee7
1 changed files with 6 additions and 14 deletions

View File

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