#!/usr/bin/env python
# (C) 2000 Huaiyu Zhu <hzhu@users.sourceforge.net>. Licence: GPL
# $Id: test_cross.py,v 1.3 2000/10/05 01:33:21 hzhu Exp $
"""
Test cross operations for Matrix module
"""
from MatPy.Matrix import ones, norm
a = ones((1,3))*2.
b = ones((3,1))*3.
def checkequal(x, y):
print x
print y
assert norm(x-y) == 0
print "-"*40
checkequal(a.e_add(b), b.e_add(a))
checkequal(a.e_sub(b), -(b.e_sub(a)))
print "-"*40
checkequal (a.e_mul(b), b.e_mul(a))
checkequal (a.e_div(b), (b.e_div(a)).re_div(1))
print "-"*40
checkequal(a.e_add(1), a.re_add(1))
checkequal(a.e_sub(1), -(a.re_sub(1)))
print "-"*40
checkequal (a.e_mul(3), a.re_mul(3))
checkequal (a.e_div(3), (a.re_div(3)).re_div(1))
print "-"*40
try:
print a+b
print b+a
print a+b
print b+a
except ValueError:
print "These do not work, as expected"
print "-"*40
print a*b
print b*a
try:
print a/b
print b/a
except:
print "These should work with generalized inverse. Need new code."
Result obtained with
>>> from MatPy.tests import test_cross
----------------------------------------
[ 5 5 5
5 5 5
5 5 5 ]
[ 5 5 5
5 5 5
5 5 5 ]
[-1 -1 -1
-1 -1 -1
-1 -1 -1 ]
[-1 -1 -1
-1 -1 -1
-1 -1 -1 ]
----------------------------------------
[ 6 6 6
6 6 6
6 6 6 ]
[ 6 6 6
6 6 6
6 6 6 ]
[ 0.667 0.667 0.667
0.667 0.667 0.667
0.667 0.667 0.667 ]
[ 0.667 0.667 0.667
0.667 0.667 0.667
0.667 0.667 0.667 ]
----------------------------------------
[ 3 3 3 ]
[ 3 3 3 ]
[ 1 1 1 ]
[ 1 1 1 ]
----------------------------------------
[ 6 6 6 ]
[ 6 6 6 ]
[ 0.667 0.667 0.667 ]
[ 0.667 0.667 0.667 ]
----------------------------------------
These do not work, as expected
----------------------------------------
[ 18 ]
[ 6 6 6
6 6 6
6 6 6 ]
These should work with generalized inverse. Need new code.