本文整理汇总了Python中cysparse.sparse.ll_mat.LLSparseMatrix类的典型用法代码示例。如果您正苦于以下问题:Python LLSparseMatrix类的具体用法?Python LLSparseMatrix怎么用?Python LLSparseMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LLSparseMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: factorize
def factorize(self):
u"""Factorize matrix A as limited-memory LDLᵀ.
:returns:
:L: L as a llmat matrix
:d: as a Numpy array
"""
super(CySparseLLDLSolver, self).factorize()
nnz = len(self.lvals)
row = np.empty(nnz, dtype=np.int64)
col = np.empty(nnz, dtype=np.int64)
val = np.empty(nnz, dtype=np.float64)
elem = 0
for j in xrange(len(self.colptr) - 1):
for k in xrange(self.colptr[j], self.colptr[j + 1]):
row[elem] = self.rowind[k]
col[elem] = j
val[elem] = self.lvals[k]
elem += 1
L = LLSparseMatrix(size=self.n,
itype=INT64_T,
dtype=FLOAT64_T)
L.put_triplet(row, col, val)
return (L, self.d)
示例2: LLMatRowScaleStridedBenchmark
class LLMatRowScaleStridedBenchmark(benchmark.Benchmark):
label = "Simple row_scale with 100 elements and size = 1,000 and a strided NumPy vector (stride = 10)"
each = 10
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)
self.stride = 10
self.v = np.arange(0, self.size * self.stride, dtype=np.float64)
#def tearDown(self):
# for i in xrange(self.size):
# for j in xrange(self.size):
# assert self.A_c[i,j] == self.A_p[i,j]
def test_pysparse(self):
self.A_p.row_scale(self.v[::self.stride])
return
def test_cysparse(self):
self.A_c.row_scale(self.v[::self.stride])
return
示例3: LLMatColScaleBenchmark
class LLMatColScaleBenchmark(benchmark.Benchmark):
label = "Simple col_scale with 100 elements and size = 1,000"
each = 10
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)
self.v = np.arange(0, self.size, dtype=np.float64)
#def tearDown(self):
# for i in xrange(self.size):
# for j in xrange(self.size):
# assert self.A_c[i,j] == self.A_p[i,j]
def test_pysparse(self):
self.A_p.col_scale(self.v)
return
def test_cysparse(self):
self.A_c.col_scale(self.v)
return
示例4: LLMatFrobeniusNormBenchmark
class LLMatFrobeniusNormBenchmark(benchmark.Benchmark):
label = "Generalize norm with 100 elements and size = 1,000 for a symmetrical matrix"
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, is_symmetric=True)
construct_sym_sparse_matrix(self.A_c, self.size, self.nbr_elements)
self.A_p = spmatrix.ll_mat_sym(self.size, self.size, self.nbr_elements)
construct_sym_sparse_matrix(self.A_p, self.size, self.nbr_elements)
#def tearDown(self):
# assert self.A_c.nnz == self.A_p.nnz
# for i in xrange(self.size):
# for j in xrange(self.size):
# assert self.A_c[i,j] == self.A_p[i,j]
def test_pysparse(self):
self.A_p.generalize()
return
def test_cysparse(self):
self.A_c.generalize()
return
示例5: setUp
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)
示例6: LLMatShiftBenchmark
class LLMatShiftBenchmark(benchmark.Benchmark):
label = "Simple shift with 100 elements and size = 1,000 (sigma = 10.47)"
each = 100
def setUp(self):
self.nbr_elements = 100
self.size = 1000
self.sigma = 10.47
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_c2 = self.A_c.copy()
self.A_p = spmatrix.ll_mat(self.size, self.size, self.nbr_elements)
construct_sparse_matrix(self.A_p, self.size, self.nbr_elements)
self.A_p2 = self.A_p.copy()
#def tearDown(self):
# for i in xrange(self.size):
# for j in xrange(self.size):
# assert self.A_c[i,j] == self.A_p[i,j]
def test_pysparse(self):
self.A_p.shift(self.sigma, self.A_p2)
return
def test_cysparse(self):
self.A_c.shift(self.sigma, self.A_c2)
return
示例7: LLMatMatVecBenchmark
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
示例8: LLMatMatVecBenchmark
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.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.A_p.matvec(self.v, self.w_p)
return
def test_cysparse(self):
self.w_c = self.A_c * self.v
return
def test_cysparse2(self):
self.A_c.matvec(self.v)
return
def test_scipy_sparse(self):
self.w_s = self.A_s * self.v
return
def test_scipy_sparse2(self):
self.A_s._mul_vector(self.v)
示例9: LLMatFrobeniusNormBenchmark
class LLMatFrobeniusNormBenchmark(benchmark.Benchmark):
label = "Frobenius norm with 100 elements and size = 1,000 for a symmetrical matrix"
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, store_symmetric=True)
construct_sym_sparse_matrix(self.A_c, self.size, self.nbr_elements)
self.A_p = spmatrix.ll_mat_sym(self.size, self.size, self.nbr_elements)
construct_sym_sparse_matrix(self.A_p, self.size, self.nbr_elements)
def tearDown(self):
assert self.p_norm == self.c_norm
#assert self.w_c[i] == self.w_s[i]
def test_pysparse(self):
self.p_norm = self.A_p.norm('fro')
return
def test_cysparse(self):
self.c_norm = self.A_c.norm('frob')
return
示例10: LLMatMatVecBenchmark_2
class LLMatMatVecBenchmark_2(LLMatMatVecBenchmark):
label = "matvec with 10,000 elements and size = 100,000"
each = 100
def setUp(self):
self.nbr_elements = 10000
self.size = 100000
self.non_contiguity = 10
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.CSC_c = self.A_c.to_csc()
self.CSC_s = self.A_s.tocsc()
self.v = np.arange(0, self.size * self.non_contiguity, dtype=np.float64)
示例11: LLMatToCSRBenchmark
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
示例12: LLMatMatVecBenchmark_4
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)
示例13: LLMatInfiniteNormBenchmark
class LLMatInfiniteNormBenchmark(benchmark.Benchmark):
label = "Infinite norm 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):
assert self.p_norm_inf == self.c_norm_inf
#assert self.w_c[i] == self.w_s[i]
def test_pysparse(self):
self.p_norm_inf = self.A_p.norm('inf')
return
def test_cysparse(self):
self.c_norm_inf = self.A_c.norm('inf')
return
示例14: LLMatPutTripletBenchmark
class LLMatPutTripletBenchmark(benchmark.Benchmark):
label = "Simple put_triplet with 100 elements, size = 1,000 and put_size = 1,000"
each = 100
def setUp(self):
self.nbr_elements = 100
self.size = 1000
self.put_size = 1000
assert self.put_size <= self.size
self.A_c = LLSparseMatrix(size=self.size, size_hint=self.nbr_elements, itype=INT32_T, 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)
self.A_sppy = None
self.id1 = np.arange(0, self.put_size, dtype=np.int32)
self.id2 = np.full(self.put_size, 37, dtype=np.int32)
self.b = np.arange(0, self.put_size,dtype=np.float64)
def eachSetUp(self):
self.A_sppy = csarray((self.size, self.size), dtype=np.float64, storagetype='row')
#def tearDown(self):
# for i in xrange(self.size):
# for j in xrange(self.size):
# assert self.A_c[i, j] == self.A_p[i, j]
def test_pysparse(self):
self.A_p.put(self.b, self.id1, self.id2)
return
def test_cysparse(self):
self.A_c.put_triplet(self.id1, self.id2, self.b)
return
def test_sppy(self):
self.A_sppy.put(self.b, self.id1, self.id2, init=True)
示例15: setUp
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)