[PATCH] tests for Matrix.eigenvects() robustified

2 views
Skip to first unread message

Ondrej Certik

unread,
Dec 27, 2008, 2:57:47 PM12/27/08
to sympy-...@googlegroups.com, Ondrej Certik
The ordering of the result of eigenvects() was platform dependent due to
hashes. That is ok, but when we test it, we need to make the comparison
platform independent (otherwise it fails in jython), so I introduced a
canonicalize() method in the matrix tests. See it's docstring for more info.

Signed-off-by: Ondrej Certik <ond...@certik.cz>
---
sympy/matrices/tests/test_matrices.py | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/sympy/matrices/tests/test_matrices.py b/sympy/matrices/tests/test_matrices.py
index 15682ba..98e93cf 100644
--- a/sympy/matrices/tests/test_matrices.py
+++ b/sympy/matrices/tests/test_matrices.py
@@ -401,6 +401,19 @@ def test_wronskian():
-6*exp(x)*sin(x)*x + 6*cos(x)*exp(x)*x**2 - 6*exp(x)*cos(x)*x - \
exp(x)*cos(x)*x**3 + exp(x)*sin(x)*x**3

+def canonicalize(v):
+ """
+ Takes the output of eigenvects() and makes it canonical, so that we can
+ compare it across platforms.
+
+ It converts Matrices to lists, and uses set() to list the outer list in a
+ platform independent way.
+ """
+ def c(x):
+ a, b, c = x
+ return (S(a), S(b), tuple(c[0]))
+ return tuple(set([c(x) for x in v]))
+
def test_eigen():
x,y = symbols('xy')

@@ -415,10 +428,10 @@ def test_eigen():

assert M.eigenvals() == {S.One: 3}

- assert M.eigenvects() == \
+ assert canonicalize(M.eigenvects()) == canonicalize(
[(1, 3, [Matrix([1,0,0]),
Matrix([0,1,0]),
- Matrix([0,0,1])])]
+ Matrix([0,0,1])])])

M = Matrix([[0,1,1],
[1,0,0],
@@ -426,19 +439,19 @@ def test_eigen():

assert M.eigenvals() == {2*S.One: 1, -S.One: 1, S.Zero: 1}

- assert M.eigenvects() == \
+ assert canonicalize(M.eigenvects()) == canonicalize(
[( 2, 1, [Matrix([R(2,3), R(1,3), 1])]),
(-1, 1, [Matrix([-1, 1, 0])]),
- ( 0, 1, [Matrix([ 0,-1, 1])])]
+ ( 0, 1, [Matrix([ 0,-1, 1])])])

eps = Symbol('eps',real=True)

M = Matrix([[abs(eps), I*eps ],
[-I*eps, abs(eps) ]])

- assert M.eigenvects() == \
+ assert canonicalize(M.eigenvects()) == canonicalize(
[( 2*abs(eps), 1, [ Matrix([[I*eps/abs(eps)],[1]]) ] ),
- ( 0, 1, [Matrix([[-I*eps/abs(eps)],[1]])]) ]
+ ( 0, 1, [Matrix([[-I*eps/abs(eps)],[1]])]) ])

def test_sparse_matrix():
return
--
1.6.0.4.1060.g9433b

Fabian Seoane

unread,
Dec 28, 2008, 6:52:50 AM12/28/08
to sympy-...@googlegroups.com
seems ok to me
--
Fabian, http://fseoane.net/blog/

Ondrej Certik

unread,
Dec 28, 2008, 7:01:24 AM12/28/08
to sympy-...@googlegroups.com
On Sun, Dec 28, 2008 at 12:52 PM, Fabian Seoane <fabian...@gmail.com> wrote:
> seems ok to me

Thanks, it's in.

Ondrej

Reply all
Reply to author
Forward
0 new messages