當前位置: 首頁>>代碼示例>>Python>>正文


Python ll_mat.LLSparseMatrix類代碼示例

本文整理匯總了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)
開發者ID:PythonOptimizers,項目名稱:LLDL.py,代碼行數:27,代碼來源:solver.py

示例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
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:34,代碼來源:row_scale_strided.py

示例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
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:32,代碼來源:col_scale.py

示例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
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:33,代碼來源:generalize.py

示例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)
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:31,代碼來源:transposed_mat_mul_vector.py

示例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
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:35,代碼來源:shift.py

示例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
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:52,代碼來源:transposed_mat_mul_vector.py

示例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)
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:52,代碼來源:matvec.py

示例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
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:31,代碼來源:norm_frob_sym.py

示例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)
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:26,代碼來源:matvec_csc_non_contiguous.py

示例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
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:31,代碼來源:to_csr.py

示例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)
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:28,代碼來源:matvec_csr.py

示例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
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:27,代碼來源:norm_inf.py

示例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)
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:47,代碼來源:put.py

示例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)
開發者ID:PythonOptimizers,項目名稱:cysparse,代碼行數:10,代碼來源:norm_inf.py


注:本文中的cysparse.sparse.ll_mat.LLSparseMatrix類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。