当前位置: 首页>>代码示例>>Python>>正文


Python LLSparseMatrix.put_triplet方法代码示例

本文整理汇总了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)
开发者ID:PythonOptimizers,项目名称:LLDL.py,代码行数:29,代码来源:solver.py

示例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)
开发者ID:PythonOptimizers,项目名称:cysparse,代码行数:49,代码来源:put.py


注:本文中的cysparse.sparse.ll_mat.LLSparseMatrix.put_triplet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。