From 9c771ecf5712b700f294f1ff2f18f785008f0f63 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 22 Feb 2021 12:02:04 -0500 Subject: [PATCH] eja: cache one() for Cartesian product algebras. --- mjo/eja/TODO | 12 ++++++------ mjo/eja/eja_algebra.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/mjo/eja/TODO b/mjo/eja/TODO index fe18d56..03bf404 100644 --- a/mjo/eja/TODO +++ b/mjo/eja/TODO @@ -1,9 +1,9 @@ -1. Finish CartesianProductEJA: add to_matrix(), random_instance(), - one()... methods. This will require rethinking what a "matrix - representation" and "matrix space" means for a cartesian product - algebra. Do we want our matrix basis to consist of ordered pairs - (or triples, or...)? Should the matrix_space() of the algebra be - the cartesian product of the factors' matrix spaces? Can we just +1. Finish CartesianProductEJA: add to_matrix(), + random_instance(),... methods. This will require rethinking what a + "matrix representation" and "matrix space" means for a cartesian + product algebra. Do we want our matrix basis to consist of ordered + pairs (or triples, or...)? Should the matrix_space() of the algebra + be the cartesian product of the factors' matrix spaces? Can we just fix the matrix basis/space after we call the FDEJA initializer? 2. Add references and start citing them. diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 3390df7..850447b 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -2780,6 +2780,19 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct, True sage: x.inner_product(y) == J.cartesian_inner_product(x,y) True + + The cached unit element is the same one that would be computed:: + + sage: set_random_seed() # long time + sage: J1 = random_eja() # long time + sage: J2 = random_eja() # long time + sage: J = cartesian_product([J1,J2]) # long time + sage: actual = J.one() # long time + sage: J.one.clear_cache() # long time + sage: expected = J.one() # long time + sage: actual == expected # long time + True + """ def __init__(self, modules, **kwargs): CombinatorialFreeModule_CartesianProduct.__init__(self, @@ -2819,6 +2832,8 @@ class CartesianProductEJA(CombinatorialFreeModule_CartesianProduct, check_axioms=False, category=self.category()) + ones = tuple(J.one() for J in modules) + self.one.set_cache(self._cartesian_product_of_elements(ones)) self.rank.set_cache(sum(J.rank() for J in modules)) @cached_method -- 2.43.2