#!/usr/bin/env python
# (C) 2000 Huaiyu Zhu <hzhu@users.sourceforge.net>. Licence: GPL
# $Id: test_block.py,v 1.6 2000/09/13 01:22:57 hzhu Exp $
"""
Test constructing block matrices for Matrix module
"""
from MatPy.Matrix import *
#------------------------------------------------------------------
print "-"*40, "Assemble block matrices"
print "For proper matrices"
a = ones((2,3))
b = [a*1, a*2, a*3]
print Matrix_c(b)
print Matrix_r(b)
print "For row vectors"
a = ones(3)
b = [a*1, a*2, a*3]
print Matrix_c(b)
print Matrix_r(b)
print "For col vectors"
a = ones(2).T
b = [a*1, a*2, a*3]
print Matrix_c(b)
print Matrix_r(b)
#------------------------------------------------------------------
print "For different shapes"
a = zeros((0,0))
b = ones(3)
c = ones((2,3))*2
print a, b, c
print Matrix_c((a, b, c))
print Matrix_r((a.T, b.T, c.T))
#------------------------------------------------------------------
print "-"*40, "Split into block matrices"
print "For proper matrices"
a = rand((2,3))
print len(rows(a)), rows(a)
print len(cols(a)), cols(a)
print "For row vectors"
a = rand(3)
print len(rows(a)), rows(a)
print len(cols(a)), cols(a)
print "For col vectors"
a = rand(2).T
print len(rows(a)), rows(a)
print len(cols(a)), cols(a)
#------------------------------------------------------------------
print "-"*40, "Split and assemble"
a = rand((2,3))
print a
b = rows(a)
print b
c = Matrix_c(b)
print c
assert norm(a - c) == 0
d = cols(a)
print d
e = Matrix_r(d)
print e
assert norm(a - e) == 0
|