From 5c30f3abbd2d61759c500dde62f4c0fe50c54ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 24 Oct 2024 11:29:53 +0200 Subject: [PATCH] Improve performance of `bracket` for `AbstractLieAlgebraElem` (#4228) --- .../LieAlgebras/src/AbstractLieAlgebra.jl | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/experimental/LieAlgebras/src/AbstractLieAlgebra.jl b/experimental/LieAlgebras/src/AbstractLieAlgebra.jl index 9fa34cbfe69a..1052aa7c43ff 100644 --- a/experimental/LieAlgebras/src/AbstractLieAlgebra.jl +++ b/experimental/LieAlgebras/src/AbstractLieAlgebra.jl @@ -68,12 +68,15 @@ function bracket( ) where {C<:FieldElem} check_parent(x, y) L = parent(x) - mat = sum( - cxi * cyj * _struct_consts(L)[i, j] for (i, cxi) in enumerate(coefficients(x)), - (j, cyj) in enumerate(coefficients(y)); - init=sparse_row(coefficient_ring(L)), - ) - return L(mat) + vec = sparse_row(coefficient_ring(L)) + for (i, cxi) in enumerate(coefficients(x)) + iszero(cxi) && continue + for (j, cyj) in enumerate(coefficients(y)) + iszero(cyj) && continue + Hecke.add_scaled_row!(_struct_consts(L)[i, j], vec, cxi * cyj) + end + end + return L(vec) end ###############################################################################