From e1c7e0c4deb6208d09a8c2e08db25e0f40aa4be5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Tue, 22 Oct 2024 15:38:13 +0200 Subject: [PATCH] Improve performance of `bracket` for `AbstractLieAlgebraElem` --- .../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 ###############################################################################