本文整理汇总了Python中cysparse.sparse.ll_mat.LLSparseMatrix.put_triplet方法的典型用法代码示例。如果您正苦于以下问题:Python LLSparseMatrix.put_triplet方法的具体用法?Python LLSparseMatrix.put_triplet怎么用?Python LLSparseMatrix.put_triplet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cysparse.sparse.ll_mat.LLSparseMatrix
的用法示例。
在下文中一共展示了LLSparseMatrix.put_triplet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: factorize
# 需要导入模块: from cysparse.sparse.ll_mat import LLSparseMatrix [as 别名]
# 或者: from cysparse.sparse.ll_mat.LLSparseMatrix import put_triplet [as 别名]
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: LLMatPutTripletBenchmark
# 需要导入模块: from cysparse.sparse.ll_mat import LLSparseMatrix [as 别名]
# 或者: from cysparse.sparse.ll_mat.LLSparseMatrix import put_triplet [as 别名]
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)