1
0
mirror of https://github.com/kalmarek/GroupRings.jl.git synced 2024-12-28 02:40:28 +01:00

fix aliasing bugs with add!

This commit is contained in:
kalmarek 2019-07-23 17:19:24 +02:00
parent d0fbd0301b
commit 80c609ad6e
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
3 changed files with 14 additions and 15 deletions

View File

@ -59,10 +59,9 @@ 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)
@inbounds for i in eachindex(result.coeffs)
result.coeffs[i] = X.coeffs[i] + Y.coeffs[i]
end
result = zero!(result)
# @inbounds for i in eachindex(result.coeffs)
result.coeffs .= X.coeffs .+ Y.coeffs
return result
end
@ -108,7 +107,7 @@ end
function +(X::GroupRingElem{T, GR}, Y::GroupRingElem{T, GR}) where {T, GR<:GroupRing}
# @assert parent(X) == parent(Y)
return add!(X, X, Y)
return add!(zero(parent(X)), X, Y)
end
function +(X::GroupRingElem{S}, Y::GroupRingElem{T}) where {S,T}
@ -205,7 +204,7 @@ end
# divisions
(/)(X::GroupRingElem, a) = inv(a)*X
(//)(X::GroupRingElem, a::Union{Integer, Rational}) = inv(a)*X
(//)(X::GroupRingElem, a::Union{Integer, Rational}) = 1//a*X
###############################################################################
#

View File

@ -3,6 +3,7 @@ using Test
using AbstractAlgebra
using GroupRings
using SparseArrays
using LinearAlgebra
include("AARing_interface_conformance.jl")

View File

@ -1,5 +1,3 @@
using LinearAlgebra
@testset "Unit tests" begin
R = AbstractAlgebra.zz
G = PermGroup(4)
@ -38,7 +36,7 @@ using LinearAlgebra
@test length(X.coeffs.nzind) < k
@test norm(X, 4) isa Float64
@test aug(X) isa Int
@test aug(X) isa elem_type(base_ring(RG))
@test supp(X) isa Vector{elem_type(G)}
@test [RG[g] for g in supp(X)] == X.coeffs.nzind
@ -90,14 +88,15 @@ using LinearAlgebra
for (inplace_op, op) in [(AbstractAlgebra.mul!, *),
(AbstractAlgebra.add!, +)]
let X = X, Y = Y
@test inplace_op(X, X, Y) == op(X, Y)
@test inplace_op(X, Y, X) == op(Y, X)
@test op(X, Y) == inplace_op(X, X, Y)
@test op(Y, X) == inplace_op(X, Y, X)
Z = inplace_op(X, X, Y)
@test Z == op(X, Y)
Z = inplace_op(Z, Y, X)
@test Z == op(Y, X)
Z = op(X, Y)
@test Z == inplace_op(Z, X, Y)
Z = op(Y, X)
@test Z == inplace_op(Z, Y, X)
end
end