def testRandom(self): m = Matrix(5) m.random(3) q, r = m.QRSimple() one = Matrix(5) one.one() self.assertTrue(m.isAlmostEqual(q*r)) self.assertTrue(one.isAlmostEqual(q*q.transpose()))
def testRandom(self): m = Matrix(self.size) m.random(3) q, r = m.QRHouseholder() one = Matrix(self.size) one.one() self.assertTrue(m.isAlmostEqual(q*r)) self.assertTrue(one.isAlmostEqual(q*q.transpose()))
def genMatrix(size, kind): m = Matrix(size) if kind == "random": m.random(seed()) elif kind == "triangular": m.randomUpperTriangular(seed()) elif kind == "hilbert": m.hilbert() elif kind == "diagonal_dominant": m.randomDiagonalDominant(seed()) elif kind == "almost_singular": m.randomAlmostSingular(seed()) elif kind == "zero_minor": m.randomZeroMinor(seed()) elif kind == "tridiagonal": m.randomTridiagonal(seed()) else: return None return m
from pymatrix import Matrix from time import time minsize = 10 maxsize = 200 step = 5 print "# time test" print "# size LU QR-Gram QR-Householder" for size in range(minsize, maxsize + 1, step): m = Matrix(size) m.random(int(time())) m, lu_time = m.invertLUTimed() m, qr_gram_time = m.invertQRSimpleTimed() m, qr_house_time = m.invertQRHouseholderTimed() print size, lu_time, qr_gram_time, qr_house_time
def testRandom(self): m = Matrix(self.size) m.random(3); one = Matrix(self.size) one.one() self.assertTrue(one.isAlmostEqual(m * m.invertQRHouseholder()))