Skip to content

Commit

Permalink
fix: unary minus for sparse group algebra elems
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Nov 19, 2024
1 parent 6eb76a2 commit 4b6c2e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/AlgAss/Elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

################################################################################
Expand Down
2 changes: 2 additions & 0 deletions test/AlgAss/AlgGrp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 4b6c2e6

Please sign in to comment.