class TestCuSparsePreconditioners(CUDATestCase): def setUp(self): from pyculib.sparse import Sparse self.cus = Sparse() def test_Scsric0(self): """ Just exercise the codepath """ dtype = np.float32 m = n = 3 trans = 'N' sary = scipy.sparse.rand(m, n, 0.75, format='csr', dtype=dtype) nnz = sary.nnz csrValM = sary.data csrRowPtrA = sary.indptr csrColIndA = sary.indices descr = self.cus.matdescr(matrixtype='S') info = self.cus.csrsv_analysis(trans, m, nnz, descr, csrValM, csrRowPtrA, csrColIndA) self.cus.csric0(trans, m, descr, csrValM, csrRowPtrA, csrColIndA, info) def test_Scsrilu0(self): """ Just exercise the codepath """ dtype = np.float32 m = n = 3 trans = 'N' sary = scipy.sparse.rand(m, n, 0.75, format='csr', dtype=dtype) csrValM = sary.data csrRowPtrA = sary.indptr csrColIndA = sary.indices descr = self.cus.matdescr() info = self.cus.api.solve_analysis_info() self.cus.csrilu0(trans, m, descr, csrValM, csrRowPtrA, csrColIndA, info) def test_Sgtsv(self): """ Just exercise the codepath """ dtype = np.float32 m = 4 n = 3 ldb = m dl = np.asarray([3] * 8, dtype=dtype) d = np.asarray([1] * 9, dtype=dtype) du = np.asarray([4] * 8, dtype=dtype) B = np.ones((m, n), dtype=dtype, order='F') Bcopy = B.copy() self.cus.gtsv(m, n, dl, d, du, B, ldb) self.assertTrue(not np.all(B == Bcopy)) def test_Sgtsv_nopivot(self): """ Just exercise the codepath """ dtype = np.float32 m = 4 n = 3 ldb = m dl = np.asarray([3] * 8, dtype=dtype) d = np.asarray([1] * 9, dtype=dtype) du = np.asarray([4] * 8, dtype=dtype) B = np.ones((m, n), dtype=dtype, order='F') Bcopy = B.copy() self.cus.gtsv_nopivot(m, n, dl, d, du, B, ldb) self.assertTrue(not np.all(B == Bcopy)) def test_SgtsvStridedBatch(self): """ Just exercise the codepath """ dtype = np.float32 batchCount = 1 batchStride = 4 m = 4 n = 3 dl = np.asarray([3] * 8, dtype=dtype) d = np.asarray([1] * 9, dtype=dtype) du = np.asarray([4] * 8, dtype=dtype) x = np.ones((m, n), dtype=dtype, order='F') xcopy = x.copy() self.cus.gtsvStridedBatch(m, dl, d, du, x, batchCount, batchStride) self.assertTrue(not np.all(x == xcopy))
class TestCuSparseLevel2(CUDATestCase): def setUp(self): from pyculib.sparse import Sparse self.cus = Sparse() def generic_test_bsrmv(self, dtype): from pyculib.sparse import bsr_matrix row = np.array([0, 0, 1, 2, 2, 2]) col = np.array([0, 2, 2, 0, 1, 2]) data = np.array([1, 2, 3, 4, 5, 6], dtype=dtype) bsrmat = bsr_matrix((data, (row, col)), shape=(3, 3)) x = np.ones(3, dtype=dtype) y = np.ones(3, dtype=dtype) oldy = y.copy() alpha = 1 beta = 1 descr = self.cus.matdescr() self.cus.bsrmv_matrix('C', 'N', alpha, descr, bsrmat, x, beta, y) self.assertFalse(np.all(y == oldy)) def test_Sbsrmv(self): dtype = np.float32 self.generic_test_bsrmv(dtype=dtype) def test_Cbsrmv(self): dtype = np.complex64 self.generic_test_bsrmv(dtype=dtype) def test_Sbsrxmv(self): """ Just exercise the codepath """ dtype = np.float32 alpha = 0 beta = 0 descr = self.cus.matdescr() bsrVal = np.zeros(10, dtype=dtype) bsrMaskPtr = np.zeros(10, dtype=np.int32) bsrRowPtr = np.zeros(10, dtype=np.int32) bsrEndPtr = np.zeros(10, dtype=np.int32) bsrColInd = np.zeros(10, dtype=np.int32) blockDim = 1 x = np.zeros(10, dtype=dtype) y = np.zeros(10, dtype=dtype) self.cus.bsrxmv('C', 'N', 1, 1, 1, 1, alpha, descr, bsrVal, bsrMaskPtr, bsrRowPtr, bsrEndPtr, bsrColInd, blockDim, x, beta, y) def test_Scsrmv(self): """ Just exercise the codepath """ dtype = np.float32 alpha = 0 beta = 0 descr = self.cus.matdescr() csrVal = np.zeros(10, dtype=dtype) csrColInd = np.zeros(10, dtype=np.int32) csrRowPtr = np.zeros(10, dtype=np.int32) x = np.zeros(10, dtype=dtype) y = np.zeros(10, dtype=dtype) trans = 'N' m = 1 n = 1 nnz = 1 self.cus.csrmv(trans, m, n, nnz, alpha, descr, csrVal, csrRowPtr, csrColInd, x, beta, y) def test_Scsrmv(self): """ Just exercise the codepath """ dtype = np.float32 descr = self.cus.matdescr() csrVal = np.zeros(10, dtype=dtype) csrColInd = np.zeros(10, dtype=np.int32) csrRowPtr = np.zeros(10, dtype=np.int32) trans = 'N' m = 1 nnz = 1 info = self.cus.csrsv_analysis(trans, m, nnz, descr, csrVal, csrRowPtr, csrColInd) alpha = 1.0 x = np.zeros(10, dtype=dtype) y = np.zeros(10, dtype=dtype) self.cus.csrsv_solve(trans, m, alpha, descr, csrVal, csrRowPtr, csrColInd, info, x, y)