]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: cache one() for Cartesian product algebras.
[sage.d.git] / mjo / eja / eja_algebra.py
index 3390df7545bb41257ee58c68f04154ce7a18d462..850447b38f55b09b707f745959e85dfdfa7d62c1 100644 (file)
@@ -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