def test_scalez_complex_vector(self): A = cn.array(self.complex_veca, dtype=cn.complex64) B = A.multiply(math.pi+1.37j) # numpy a = np.array(self.complex_veca, dtype=np.complex64) b = np.multiply(a, math.pi+1.37j) self.assert_(test.arrays_equal(B.toarray(), b))
def test_scale_real_matrix(self): A = cn.array(self.real_mata, dtype=cn.float32) B = A.multiply(math.pi) # numpy a = np.array(self.real_mata, dtype=np.float32) b = np.multiply(a, math.pi) self.assert_(test.arrays_equal(B.toarray(), b))
def test_complex_single_matrix_svd(self): A_ = cn.array(self.complex_mata, dtype=cn.complex64) A = np.array(self.complex_mata, dtype=np.complex64) # gpu U, S, VT = [x.toarray() for x in A_.svd()] R = np.dot(U, np.dot(np.diag(S), VT)) self.assert_(test.arrays_equal(R, A, 1e-03))
def test_scale_complex_matrix(self): A = cn.array(self.complex_mata, dtype=cn.complex64) B = A.multiply(math.pi) # numpy a = np.array(self.complex_mata, dtype=np.complex64) b = np.multiply(a, math.pi) self.assert_(test.arrays_equal(B.toarray(), b))
def test_real_double_matrix_svd(self): A_ = cn.array(self.real_mata, dtype=cn.float64) A = np.array(self.real_mata, dtype=np.float64) # gpu U, S, VT = [x.toarray() for x in A_.svd()] R = np.dot(U, np.dot(np.diag(S), VT)) #print S self.assert_(test.arrays_equal(R, A, 1e-03))
def test_complex_double_matrix_eigensystem(self): A_ = cn.array(self.complex_mata, dtype=cn.complex128) A = np.array(self.complex_mata, dtype=np.complex128) # gpu LV, E, RV = [x.toarray() for x in A_.eigensystem(left_vectors=True, right_vectors=True)] # cpu NE, NLV, NRV = la.eig(A, left=True, right=True) self.assert_(test.arrays_equal(E, NE, 1e-03))
def test_real_single_matrix_mul_matrix(self): A_ = cn.array(self.real_mata, dtype=cn.float32) A = np.array(self.real_mata, dtype=np.float32) # gpu R_ = A_.mul(A_) # cpu R = A * A # self.assert_(test.arrays_equal(R, R_.toarray(), 1E-03))
def test_real_double_vector_vector_dot2(self): va = cn.array(self.real_veca, dtype=cn.float64) vb = cn.array(self.real_vecb, dtype=cn.float64) vc = va.dot2(vb) # check we get the same answer as numpy na = np.array(self.real_veca, dtype=np.float64) nb = np.array(self.real_vecb, dtype=np.float64) nc = np.dot(na,nb) self.assert_(test.arrays_equal(vc.toarray(), nc, epsilon=0.0001))
def test_real_single_vector_matrix_dot2(self): va = cn.array(self.real_veca, dtype=cn.float32) vb = cn.array(self.real_matb, dtype=cn.float32) vc = va.dot2(vb) # check we get the same answer as numpy na = np.array(self.real_veca, dtype=np.float32) nb = np.array(self.real_matb, dtype=np.float32) nc = np.dot(na,nb) self.assert_(test.arrays_equal(vc.toarray(), nc, epsilon=0.05))
def test_real_single_matrix_eigensystem(self): A_ = cn.array(self.real_mata, dtype=cn.float32) A = np.array(self.real_mata, dtype=np.float32) # gpu LV, RU, IU, RV = [x.toarray() for x in A_.eigensystem(left_vectors=True, right_vectors=True)] E = RU + 1j * IU # glue egienvalues into complex array # NE, NLV, NRV = la.eig(A, left=True, right=True) self.assert_(test.arrays_equal(E, NE, 1e-03))
def test_complex_double_vector_matrix_dot2(self): va = cn.array(self.complex_veca, dtype=cn.complex128) vb = cn.array(self.complex_matb, dtype=cn.complex128) vc = va.dot2(vb) # check we get the same answer as numpy na = np.array(self.complex_veca, dtype=np.complex128) nb = np.array(self.complex_matb, dtype=np.complex128) nc = np.dot(na,nb) self.assert_(test.arrays_equal(vc.toarray(), nc, epsilon=0.0001))
def test_complex_single_vector_vector_dot2(self): va = cn.array(self.complex_veca, dtype=cn.complex64) vb = cn.array(self.complex_vecb, dtype=cn.complex64) vc = va.dot2(vb) # check we get the same answer as numpy na = np.array(self.complex_veca, dtype=np.complex64) nb = np.array(self.complex_vecb, dtype=np.complex64) nc = np.dot(na,nb) self.assert_(test.arrays_equal(vc.toarray(), nc, epsilon=0.05))
def test_real_single_mul_vector(self): V = np.array(self.real_vector, dtype=np.float32) V_ = cn.array(self.real_vector, dtype=cn.float32) # gpu R_ = V_.mul(V_) # cpu R = V * V # self.assert_(test.arrays_equal(R, R_.toarray(), 1E-03))
def test_real_single_matrix_mul_column_vector(self): A_ = cn.array(self.real_mata, dtype=cn.float32) A = np.array(self.real_mata, dtype=np.float32) V = np.array(self.real_colvec, dtype=np.float32) V_ = cn.array(self.real_colvec, dtype=cn.float32) # gpu R_ = A_.mul(V_) # cpu R = A * V # self.assert_(test.arrays_equal(R, R_.toarray(), 1E-03))
def test_real_single_matrix_cmin(self): A_ = cn.array(self.real_mata, dtype=cn.float32) A = np.array(self.real_mata, dtype=np.float32) # gpu s = A_.cmin().toarray() #print s # cpu sn = np.min(A, axis=0) #print sn # XXX this precision doesn't always return true self.assert_(test.arrays_equal(sn, s, 1E-03))
def test_real_single_matrix_mul_scalar(self): A_ = cn.array(self.real_mata, dtype=cn.float32) A = np.array(self.real_mata, dtype=np.float32) S = 27.345 # gpu s = A_.mul(S) #print s # cpu sn = A * S #print sn # XXX this precision doesn't always return true self.assert_(test.arrays_equal(sn, s.toarray(), 1E-03))
def test_fn_purity(self): A_ = cn.array(self.real_mata, dtype=cn.float32) A = np.array(self.real_mata, dtype=np.float32) # gpu RU, IU = [x.toarray() for x in A_.eigensystem()] self.assert_(test.arrays_equal(A, A_.toarray()))
def test_linalg_transpose_idempotency(self): a = cn.array(self.real_mata, dtype=cn.float32) b = cn.array(self.real_matb, dtype=cn.float32) c = a.dot(b) d = b.T.dot(a.T).T self.assert_(test.arrays_equal(c.toarray(), d.toarray(), epsilon=0.05))
def test_matrix_transpose_idempotency(self): a = cn.array(self.real_mata, dtype=cn.float32) self.assert_(test.arrays_equal(a.toarray(), a.T.T.toarray()))
def test_vector_transpose_idempotency(self): # transpose is a noop for vectors - they are always columns v = cn.array(self.real_veca, dtype=cn.float32) self.assert_(test.arrays_equal(v.T.toarray(), v.toarray()))
def test_real_single_matrix_matrix_dot(self): na = np.array(self.real_mata, dtype=np.float32) nb = np.array(self.real_matb, dtype=np.float32) nc = np.dot(na, nb) nd = cn.pdot(na, nb) self.assert_(test.arrays_equal(nd, nc, epsilon=0.05))
def test_fn_purity(self): A_ = cn.array(self.real_mata, dtype=cn.float32) A = np.array(self.real_mata, dtype=np.float32) # gpu U, S, VT = [x.toarray() for x in A_.svd()] self.assert_(test.arrays_equal(A, A_.toarray()))