def test_tLU(self): n,p=500,2 tm=get_trid(n,p,herm=True) tmr=tm.tocoo().tocsc() tma=tmr.toarray() print 'checking for twist LU decomposition' t0=time.time() invegn=lin.get_inv_system(tm) L,U=invegn.get_twist_LU(j=2) t1=time.time() diff=abs(L.dot(U)-tmr).sum() print 'err -> %s, Elapse -> %s'%(diff,t1-t0) assert_almost_equal(diff,0)
def test_tLU(self): n, p = 500, 2 tm = get_trid(n, p, herm=True) tmr = tm.tocoo().tocsc() tma = tmr.toarray() print 'checking for twist LU decomposition' t0 = time.time() invegn = lin.get_inv_system(tm) L, U = invegn.get_twist_LU(j=2) t1 = time.time() diff = abs(L.dot(U) - tmr).sum() print 'err -> %s, Elapse -> %s' % (diff, t1 - t0) assert_almost_equal(diff, 0)
def test_inv(self): n,p=200,2 tm=get_trid(n,p,herm=True) tmr=tm.tocoo().tocsc() tma=tmr.toarray() print 'checking for inv' t0=time.time() res=lin.tinv(tm) t1=time.time() res2=sinv(tmr) t2=time.time() res3=inv(tma) t3=time.time() diff1=abs(res.dot(tma)-identity(tm.N)).sum() diff2=abs(res2.dot(tmr)-identity(tm.N)).sum() diff3=abs(res3.dot(tma)-identity(tm.N)).sum() print '(Trid, sps, dens) err -> %s(%s,%s), Elapse -> %s(%s,%s)'%(diff1,diff2,diff3,t1-t0,t2-t1,t3-t2) assert_almost_equal(diff1,0) assert_almost_equal(diff2,0) assert_almost_equal(diff3,0)
def test_inv(self): n, p = 200, 2 tm = get_trid(n, p, herm=True) tmr = tm.tocoo().tocsc() tma = tmr.toarray() print 'checking for inv' t0 = time.time() res = lin.tinv(tm) t1 = time.time() res2 = sinv(tmr) t2 = time.time() res3 = inv(tma) t3 = time.time() diff1 = abs(res.dot(tma) - identity(tm.N)).sum() diff2 = abs(res2.dot(tmr) - identity(tm.N)).sum() diff3 = abs(res3.dot(tma) - identity(tm.N)).sum() print '(Trid, sps, dens) err -> %s(%s,%s), Elapse -> %s(%s,%s)' % ( diff1, diff2, diff3, t1 - t0, t2 - t1, t3 - t2) assert_almost_equal(diff1, 0) assert_almost_equal(diff2, 0) assert_almost_equal(diff3, 0)
import trid,linalg #import this library from numpy.linalg import inv #numpy inversion method import time n,p=100,10 tm=trid.get_trid(n,p,herm=True) #construct a random block (np x np) hermitian tridiagonal matrix with block size p. tma=tm.toarray() #parse this tridiagonal matrix to a numpy array. t0=time.time() isys=linalg.get_inv_system(tm) #get the inversion generator. inv00=isys[0,0] #the the first element of the inverse matrix. t1=time.time() invtm=inv(tma) #the traditional method without optimization. t2=time.time() print 'Difference -> %s, Elapse %s(this), %s(numpy).'%(invtm[:p,:p]-inv00,t1-t0,t2-t1)
def __init__(self): n,p=500,2 self.tm=get_trid(n,p) self.tmr=self.tm.tocoo().tocsr() self.tma=self.tmr.toarray()
def __init__(self): n, p = 500, 2 self.tm = get_trid(n, p) self.tmr = self.tm.tocoo().tocsr() self.tma = self.tmr.toarray()