From: Michael Orlitzky Date: Fri, 12 Mar 2021 02:57:16 +0000 (-0500) Subject: eja: cache the span of the matrix basis when written out as long vectors. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=sage.d.git;a=commitdiff_plain;h=fd6a4ce03de36bb2551160e08440b0c0049746e1 eja: cache the span of the matrix basis when written out as long vectors. This GREATLY improves the speed of the _element_constructor_(), and therefore of Cartesian products. --- diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index ee2b526..5e2c315 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -347,14 +347,19 @@ class FiniteDimensionalEJA(CombinatorialFreeModule): # its own set of non-ambient coordinates (in terms of the # supplied basis). vector_basis = tuple( V(_all2list(b)) for b in basis ) - W = V.span_of_basis( vector_basis, check=check_axioms) + + # Save the span of our matrix basis (when written out as long + # vectors) because otherwise we'll have to reconstruct it + # every time we want to coerce a matrix into the algebra. + self._matrix_span = V.span_of_basis( vector_basis, check=check_axioms) if orthonormalize: - # Now "W" is the vector space of our algebra coordinates. The - # variables "X1", "X2",... refer to the entries of vectors in - # W. Thus to convert back and forth between the orthonormal - # coordinates and the given ones, we need to stick the original - # basis in W. + # Now "self._matrix_span" is the vector space of our + # algebra coordinates. The variables "X1", "X2",... refer + # to the entries of vectors in self._matrix_span. Thus to + # convert back and forth between the orthonormal + # coordinates and the given ones, we need to stick the + # original basis in self._matrix_span. U = V.span_of_basis( deortho_vector_basis, check=check_axioms) self._deortho_matrix = matrix.column( U.coordinate_vector(q) for q in vector_basis ) @@ -378,7 +383,7 @@ class FiniteDimensionalEJA(CombinatorialFreeModule): # The jordan product returns a matrixy answer, so we # have to convert it to the algebra coordinates. elt = jordan_product(q_i, q_j) - elt = W.coordinate_vector(V(_all2list(elt))) + elt = self._matrix_span.coordinate_vector(V(_all2list(elt))) self._multiplication_table[i][j] = self.from_vector(elt) if not orthonormalize: @@ -781,15 +786,10 @@ class FiniteDimensionalEJA(CombinatorialFreeModule): # is that we're already converting everything to long vectors, # and that strategy works for tuples as well. # - # We pass check=False because the matrix basis is "guaranteed" - # to be linearly independent... right? Ha ha. - elt = _all2list(elt) - V = VectorSpace(self.base_ring(), len(elt)) - W = V.span_of_basis( (V(_all2list(s)) for s in self.matrix_basis()), - check=False) + elt = self._matrix_span.ambient_vector_space()(_all2list(elt)) try: - coords = W.coordinate_vector(V(elt)) + coords = self._matrix_span.coordinate_vector(elt) except ArithmeticError: # vector is not in free module raise ValueError(msg)