From: Michael Orlitzky Date: Wed, 25 Nov 2020 19:03:41 +0000 (-0500) Subject: eja: make element constructor errors more consistent. X-Git-Url: http://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=efe6cd067e02b788bfcdc5e8b61e994cd524120c;p=sage.d.git eja: make element constructor errors more consistent. --- diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 933603a..a0af3f0 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -54,7 +54,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule): sage: J(1) Traceback (most recent call last): ... - ValueError: not a naturally-represented algebra element + ValueError: not an element of this algebra """ return None @@ -177,7 +177,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule): sage: J(A) Traceback (most recent call last): ... - ArithmeticError: vector is not in free module + ValueError: not an element of this algebra TESTS: @@ -196,7 +196,7 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule): True """ - msg = "not a naturally-represented algebra element" + msg = "not an element of this algebra" if elt == 0: # The superclass implementation of random_element() # needs to be able to coerce "0" into the algebra. @@ -221,7 +221,12 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule): # could be QQ instead of QQbar. V = VectorSpace(basis_space.base_ring(), elt.nrows()*elt.ncols()) W = V.span_of_basis( _mat2vec(s) for s in natural_basis ) - coords = W.coordinate_vector(_mat2vec(elt)) + + try: + coords = W.coordinate_vector(_mat2vec(elt)) + except ArithmeticError: # vector is not in free module + raise ValueError(msg) + return self.from_vector(coords) def _repr_(self):