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 === X && return addeq!(result, Y)
result === Y && return addeq!(result, X) result === Y && return addeq!(result, X)
result = _dealias(result, X, Y) result = zero!(result)
@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 .= X.coeffs .+ Y.coeffs
end
return result return result
end end
@ -108,7 +107,7 @@ end
function +(X::GroupRingElem{T, GR}, Y::GroupRingElem{T, GR}) where {T, GR<:GroupRing} function +(X::GroupRingElem{T, GR}, Y::GroupRingElem{T, GR}) where {T, GR<:GroupRing}
# @assert parent(X) == parent(Y) # @assert parent(X) == parent(Y)
return add!(X, X, Y) return add!(zero(parent(X)), X, Y)
end end
function +(X::GroupRingElem{S}, Y::GroupRingElem{T}) where {S,T} function +(X::GroupRingElem{S}, Y::GroupRingElem{T}) where {S,T}
@ -205,7 +204,7 @@ end
# divisions # divisions
(/)(X::GroupRingElem, a) = inv(a)*X (/)(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 AbstractAlgebra
using GroupRings using GroupRings
using SparseArrays using SparseArrays
using LinearAlgebra
include("AARing_interface_conformance.jl") include("AARing_interface_conformance.jl")

View File

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