diff --git a/src/arithmetic.jl b/src/arithmetic.jl index ce47ad1..4cb2804 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -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 ############################################################################### # diff --git a/test/runtests.jl b/test/runtests.jl index 7caa56a..dcd6727 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,6 +3,7 @@ using Test using AbstractAlgebra using GroupRings using SparseArrays +using LinearAlgebra include("AARing_interface_conformance.jl") diff --git a/test/unittests.jl b/test/unittests.jl index 1496d73..1456278 100644 --- a/test/unittests.jl +++ b/test/unittests.jl @@ -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