def test_svd_rand(self): m = 19 n = 15 k = 13 for dt in [numpy.float32, numpy.float64, numpy.complex64, numpy.complex128]: A = ctf.random.random((m,n)) A = ctf.astensor(A,dtype=dt) [U,S,VT]=ctf.svd_rand(A,k,5,1) self.assertTrue(allclose(ctf.eye(k),ctf.dot(U.T(),U))) self.assertTrue(allclose(ctf.eye(k),ctf.dot(VT,VT.T()))) [U2,S2,VT2]=ctf.svd(A,k) rs1 = ctf.vecnorm(A - ctf.dot(U*S,VT)) rs2 = ctf.vecnorm(A - ctf.dot(U2*S2,VT2)) rA = ctf.vecnorm(A) self.assertTrue(rs1 < rA) self.assertTrue(rs2 < rs1) self.assertTrue(numpy.abs(rs1 - rs2)<3.e-1)
def svd_rand(A, r): return ctf.svd_rand(A, r)