mirror of
https://github.com/kalmarek/GroupRings.jl.git
synced 2025-01-01 11:45:28 +01:00
make add! use addeq! when out is aliased with either of args
This commit is contained in:
parent
cc7eb9b699
commit
810245b7c2
@ -56,6 +56,9 @@ Perform te the addition `X + Y` and store the result in `result`.
|
|||||||
* no checks on arguments parents (i.e. mathematical correctns) are performed
|
* no checks on arguments parents (i.e. mathematical correctns) are performed
|
||||||
"""
|
"""
|
||||||
function add!(result::GroupRingElem, X::GroupRingElem, Y::GroupRingElem)
|
function add!(result::GroupRingElem, X::GroupRingElem, Y::GroupRingElem)
|
||||||
|
result === X && return addeq!(result, Y)
|
||||||
|
result === Y && return addeq!(result, X)
|
||||||
|
|
||||||
result = _dealias(result, X, Y)
|
result = _dealias(result, X, Y)
|
||||||
@inbounds for i in eachindex(result.coeffs)
|
@inbounds for i in eachindex(result.coeffs)
|
||||||
result.coeffs[i] = X.coeffs[i] + Y.coeffs[i]
|
result.coeffs[i] = X.coeffs[i] + Y.coeffs[i]
|
||||||
@ -184,7 +187,8 @@ function scalarmul(a::S, X::GroupRingElem{T}) where {S,T}
|
|||||||
return scalarmul!(base_ring(parent(X))(a), deepcopy(X))
|
return scalarmul!(base_ring(parent(X))(a), deepcopy(X))
|
||||||
else
|
else
|
||||||
RG = change_base_ring(parent(X), parent(a))
|
RG = change_base_ring(parent(X), parent(a))
|
||||||
@warn "Coefficient ring does not contain scalar $a;\nThe resulting GroupRingElem has coefficients in $(parent(a)) of type $(elem_type(parent(a)))."
|
@warn "Coefficient ring does not contain scalar $a;
|
||||||
|
The resulting GroupRingElem has coefficients in $(parent(a)) of type $(elem_type(parent(a)))."
|
||||||
return scalarmul!(a, GroupRingElem(base_ring(RG).(X.coeffs), RG))
|
return scalarmul!(a, GroupRingElem(base_ring(RG).(X.coeffs), RG))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -196,12 +200,12 @@ end
|
|||||||
*(X::GroupRingElem{S}, a::T) where {T, S} = scalarmul(a, X)
|
*(X::GroupRingElem{S}, a::T) where {T, S} = scalarmul(a, X)
|
||||||
|
|
||||||
# deambiguations:
|
# deambiguations:
|
||||||
*(a::Union{AbstractFloat, Integer, RingElem, Rational}, X::GroupRingElem) = scalarmul(a, X)
|
*(a::RingElement, X::GroupRingElem) = scalarmul(a, X)
|
||||||
*(X::GroupRingElem, a::Union{AbstractFloat, Integer, RingElem, Rational}) = scalarmul(a, X)
|
*(X::GroupRingElem, a::RingElement) = scalarmul(a, X)
|
||||||
|
|
||||||
# divisions
|
# divisions
|
||||||
(/)(X::GroupRingElem, a) = inv(a)*X
|
(/)(X::GroupRingElem, a) = inv(a)*X
|
||||||
(//)(X::GroupRingElem, a::Union{Integer, Rational}) = 1//a*X
|
(//)(X::GroupRingElem, a::Union{Integer, Rational}) = inv(a)*X
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user