From 4b6c2e681f71d2220277555a0a2fd59222c9e002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 19 Nov 2024 12:07:41 +0100 Subject: [PATCH] fix: unary minus for sparse group algebra elems --- src/AlgAss/Elem.jl | 8 ++++++-- test/AlgAss/AlgGrp.jl | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/AlgAss/Elem.jl b/src/AlgAss/Elem.jl index 46e8d75b69..6f7970a8a5 100644 --- a/src/AlgAss/Elem.jl +++ b/src/AlgAss/Elem.jl @@ -147,8 +147,12 @@ end ################################################################################ function -(a::AbstractAssociativeAlgebraElem{T}) where {T} - v = T[ -coefficients(a, copy = false)[i] for i = 1:dim(parent(a)) ] - return parent(a)(v) + if _is_sparse(a) + return parent(a)(-a.coeffs_sparse) + else + v = T[ -coefficients(a, copy = false)[i] for i = 1:dim(parent(a)) ] + return parent(a)(v) + end end ################################################################################ diff --git a/test/AlgAss/AlgGrp.jl b/test/AlgAss/AlgGrp.jl index 3413ff06e0..7ee39d22ca 100644 --- a/test/AlgAss/AlgGrp.jl +++ b/test/AlgAss/AlgGrp.jl @@ -107,6 +107,7 @@ @test aa * bb == cc @test bb * aa == dd @test (aa + bb)^2 == QG(a)^2 + cc + dd + QG(b)^2 + @test aa - bb == aa + (-bb) end end @@ -129,6 +130,7 @@ @test aa * bb == cc @test bb * aa == dd @test (aa + bb)^2 == QG(a)^2 + cc + dd + QG(b)^2 + @test aa - bb == aa + (-bb) end end