def test_complex_single_matrix_matrix_dot(self): va = cn.array(self.complex_mata, dtype=cn.complex64) vb = cn.array(self.complex_matb, dtype=cn.complex64) vc = va.dot(vb) # check we get the same answer as numpy na = np.array(self.complex_mata, dtype=np.complex64) nb = np.array(self.complex_matb, dtype=np.complex64) nc = np.dot(na,nb) self.assert_(test.arrays_equal(vc.toarray(), nc, epsilon=0.05))
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_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_complex_single_vector_vector_dot(self): va = cn.array(self.complex_veca, dtype=cn.complex64) vb = cn.array(self.complex_vecb, dtype=cn.complex64) vc = va.dot(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.scalars_equal(vc, nc, epsilon=0.05))
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_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_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_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_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_real_single_vector_array(self): # check shape, type and values A = cn.array(self.real_vec, dtype=cn.float32) self.assertEqual(A.shape, (len(self.real_vec),)) self.assertEqual(A.dtype, cn.float32) self.assertEqual(A.itemsize, 4) self.assert_(arrays_equal(A.toarray(), np.array(self.real_vec, dtype=np.float32)))
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_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_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_real_single_matrix_product(self): A_ = cn.array(self.real_mata, dtype=cn.float32) A = np.array(self.real_mata, dtype=np.float32) # gpu s = A_.product() # cpu sn = np.product(A) # XXX this precision doesn't always return true self.assert_(test.scalars_equal(sn, s, 1E-04))
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_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_memory_churn(self): for x in xrange(self.n): b = cn.array(self.a, dtype=cn.float32) #b = a.sqrt() c = b.dot(b) del b, c if x % 1000 == 0: sys.stdout.write('.') sys.stdout.flush() self._assert(True)
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_maxmem(self): k = 0 try: while k < 500: k += 1 n = k * 1024 * 1024 a = cn.array(np.random.rand(n), dtype=cn.float32) print k * 4, ' ', sys.stdout.flush() except CUDAERROR, e: print e, '@', k * 4, 'MB ', sys.stdout.flush()
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_untyped_real_vector(self): A = cn.array(self.real_vec) self.assertEqual(A.shape, (len(self.real_vec),)) self.assertEqual(A.dtype, cn.float64) self.assertEqual(A.itemsize, 8) self.assert_(arrays_equal(A.toarray(), np.array(self.real_vec, dtype=np.float64)))
def test_bug_00000002(self): A = cn.array([1,2,3,4]) self.assertEqual(A.dtype, np.int32)
def test_matrix_from_numpy_array(self): a = np.array([[1, 2, 4, 5], [4, 5, 6, 7], [8, 9, 10, 11]], dtype=cn.float32) # default cuda is float32 A = cn.array(a) self.assert_(arrays_equal(a, A.toarray()))
def test_vector_from_numpy_array(self): a = np.array([1, 2, 4, 5], dtype=cn.float32) # default cuda is float32 A = cn.array(a) self.assert_(arrays_equal(a, A.toarray()))
def test_complex_double_matrix_array(self): A = cn.array(self.complex_mat, dtype=cn.complex128) self.assertEqual(A.shape, (len(self.complex_mat), len(self.complex_vec))) self.assertEqual(A.dtype, cn.complex128) self.assertEqual(A.itemsize, 16) self.assert_(arrays_equal(A.toarray(), np.array(self.complex_mat, dtype=np.complex128)))