class LLMatMatVecBenchmark_4(LLMatMatVecBenchmark): label = "matvec with 5000 elements and size = 1,000,000" each = 100 def setUp(self): self.nbr_elements = 5000 self.size = 1000000 self.A_c = LLSparseMatrix(size=self.size, size_hint=self.nbr_elements, itype=INT32_T, dtype=FLOAT64_T) self.A_p = spmatrix.ll_mat(self.size, self.size, self.nbr_elements) self.A_s = lil_matrix((self.size, self.size), dtype=np.float64) self.list_of_matrices = [] self.list_of_matrices.append(self.A_c) self.list_of_matrices.append(self.A_p) self.list_of_matrices.append(self.A_s) construct_random_matrices(self.list_of_matrices, self.size, self.nbr_elements) self.CSR_c = self.A_c.to_csr() self.CSR_p = self.A_p.to_csr() self.CSR_s = self.A_s.tocsr() self.v = np.arange(0, self.size, dtype=np.float64)
class LLMatToCSRBenchmark(benchmark.Benchmark): label = "to_csr() with 100 elements and size = 1,000" each = 100 def setUp(self): self.nbr_elements = 100 self.size = 1000 self.A_c = LLSparseMatrix(size=self.size, size_hint=self.nbr_elements, dtype=FLOAT64_T) construct_sparse_matrix(self.A_c, self.size, self.nbr_elements) self.A_p = spmatrix.ll_mat(self.size, self.size, self.nbr_elements) construct_sparse_matrix(self.A_p, self.size, self.nbr_elements) #def tearDown(self): # for i in xrange(self.size): # for j in xrange(self.size): # assert self.csr_c[i, j] == self.A_c[i, j] def test_pysparse(self): self.csr_p = self.A_p.to_csr() return def test_cysparse(self): self.csr_c = self.A_c.to_csr() return
class LLMatMatVecBenchmark(benchmark.Benchmark): label = "CSR * CSC * v with 1000 elements and size = 10,000" each = 100 def setUp(self): self.nbr_elements = 1000 self.size = 10000 self.A_c = LLSparseMatrix(size=self.size, size_hint=self.nbr_elements, itype=INT32_T, dtype=FLOAT64_T) self.A_s = lil_matrix((self.size, self.size), dtype=np.float64) self.list_of_matrices = [] self.list_of_matrices.append(self.A_c) self.list_of_matrices.append(self.A_s) construct_random_matrices(self.list_of_matrices, self.size, self.nbr_elements) self.CSR_c = self.A_c.to_csr() self.CSR_s = self.A_s.tocsr() self.B_c = LLSparseMatrix(size=self.size, size_hint=self.nbr_elements, itype=INT32_T, dtype=FLOAT64_T) self.B_s = lil_matrix((self.size, self.size), dtype=np.float64) self.list_of_matrices = [] self.list_of_matrices.append(self.B_c) self.list_of_matrices.append(self.B_s) construct_random_matrices(self.list_of_matrices, self.size, self.nbr_elements) self.CSC_c = self.B_c.to_csc() self.CSC_s = self.B_s.tocsc() self.v = np.arange(0, self.size, dtype=np.float64) #def tearDown(self): # for i in xrange(self.size): # assert self.w_c[i] == self.w_p[i] # assert self.w_c[i] == self.w_s[i] def test_cysparse(self): self.w_c = self.CSR_c * self.CSC_c * self.v return def test_scipy_sparse(self): self.w_s = self.CSR_s * self.CSC_s * self.v return
class LLMatMatVecBenchmark(benchmark.Benchmark): label = "matvec with 1000 elements and size = 10,000" each = 100 def setUp(self): self.nbr_elements = 1000 self.size = 10000 self.A_c = LLSparseMatrix(size=self.size, size_hint=self.nbr_elements, itype=INT32_T, dtype=FLOAT64_T) self.A_p = spmatrix.ll_mat(self.size, self.size, self.nbr_elements) self.A_s = lil_matrix((self.size, self.size), dtype=np.float64) self.list_of_matrices = [] self.list_of_matrices.append(self.A_c) self.list_of_matrices.append(self.A_p) self.list_of_matrices.append(self.A_s) construct_random_matrices(self.list_of_matrices, self.size, self.nbr_elements) self.CSR_c = self.A_c.to_csr() self.CSR_p = self.A_p.to_csr() self.CSR_s = self.A_s.tocsr() self.v = np.arange(0, self.size, dtype=np.float64) #def tearDown(self): # for i in xrange(self.size): # assert self.w_c[i] == self.w_p[i] # assert self.w_c[i] == self.w_s[i] def test_pysparse(self): self.w_p = np.empty(self.size, dtype=np.float64) self.CSR_p.matvec(self.v, self.w_p) return def test_cysparse(self): self.w_c = self.CSR_c * self.v return def test_cysparse2(self): self.w_c2 = self.CSR_c.matvec(self.v) return def test_scipy_sparse(self): self.w_s = self.CSR_s * self.v return def test_scipy_sparse2(self): self.w_s2 = self.CSR_s._mul_vector(self.v)