コード例 #1
0
ファイル: csparse_test.py プロジェクト: craig8/CSparse.py
    def get_problem(self, inp, tol, base=0):
        """Reads a problem from a file.

        @param fileName: file name
        @param tol: drop tolerance
        @param base: file index base
        @return: problem
        """
        prob = Problem()
        T = cs.cs_load (inp, base) # load triplet matrix T from a file
        prob.A = A = cs.cs_compress (T) # A = compressed-column form of T

        if not cs.cs_dupl (A): return None # sum up duplicates
        prob.sym = sym = self.is_sym (A) # determine if A is symmetric
        m = A.m ; n = A.n
        mn = max (m, n)
        nz1 = A.p [n]
        if tol > 0: cs.cs_dropzeros (A) # drop zero entries
        nz2 = A.p [n]
        if tol > 0: cs.cs_droptol (A, tol) # drop tiny entries (just to test)
        prob.C = C = self.make_sym(A) if sym != 0 else A # C = A + triu(A,1)', or C=A
        if C == None: return None
        print ("\n--- Matrix: %d-by-%d, nnz: %d (sym: %d: nnz %d), norm: %8.2e\n" %
            (m, n, A.p [n], sym, C.p [n] if sym != 0 else 0, cs.cs_norm (C)))
        prob.dropped_zeros = nz1 - nz2
        if nz1 != nz2: print "zero entries dropped: %d\n" % nz1 - nz2
        prob.dropped_tiny = nz2 - A.p [n]
        if nz2 != A.p [n]: print "tiny entries dropped: %d\n" % nz2 - A.p [n]
        prob.b = [0.0]*mn
        prob.x = [0.0]*mn
        prob.resid = [0.0]*mn
        return prob
コード例 #2
0
    def get_problem(self, inp, tol, base=0):
        """Reads a problem from a file.

        @param fileName: file name
        @param tol: drop tolerance
        @param base: file index base
        @return: problem
        """
        prob = Problem()
        T = cs.cs_load(inp, base)  # load triplet matrix T from a file
        prob.A = A = cs.cs_compress(T)  # A = compressed-column form of T

        if not cs.cs_dupl(A): return None  # sum up duplicates
        prob.sym = sym = self.is_sym(A)  # determine if A is symmetric
        m = A.m
        n = A.n
        mn = max(m, n)
        nz1 = A.p[n]
        if tol > 0: cs.cs_dropzeros(A)  # drop zero entries
        nz2 = A.p[n]
        if tol > 0: cs.cs_droptol(A, tol)  # drop tiny entries (just to test)
        prob.C = C = self.make_sym(
            A) if sym != 0 else A  # C = A + triu(A,1)', or C=A
        if C == None: return None
        print(
            "\n--- Matrix: %d-by-%d, nnz: %d (sym: %d: nnz %d), norm: %8.2e\n"
            % (m, n, A.p[n], sym, C.p[n] if sym != 0 else 0, cs.cs_norm(C)))
        prob.dropped_zeros = nz1 - nz2
        if nz1 != nz2: print "zero entries dropped: %d\n" % nz1 - nz2
        prob.dropped_tiny = nz2 - A.p[n]
        if nz2 != A.p[n]: print "tiny entries dropped: %d\n" % nz2 - A.p[n]
        prob.b = [0.0] * mn
        prob.x = [0.0] * mn
        prob.resid = [0.0] * mn
        return prob
コード例 #3
0
ファイル: csparse_test.py プロジェクト: craig8/CSparse.py
    def multiply_add(self, A, AT):
        m = A.m if A != None else 0 # m = # of rows of A
        T = cs.cs_spalloc (m, m, m, True, True) # create triplet identity matrix
        for i in range(m): cs.cs_entry (T, i, i, 1)
        Eye = cs.cs_compress (T) # Eye = speye (m)
        C = cs.cs_multiply (A, AT) # C = A*A'
        D = cs.cs_add(C, Eye, 1, cs.cs_norm (C)) # D = C + Eye*norm (C,1)
#        print "D:"
#        cs.cs_print(D, False) # print D
        return D
コード例 #4
0
 def multiply_add(self, A, AT):
     m = A.m if A != None else 0  # m = # of rows of A
     T = cs.cs_spalloc(m, m, m, True,
                       True)  # create triplet identity matrix
     for i in range(m):
         cs.cs_entry(T, i, i, 1)
     Eye = cs.cs_compress(T)  # Eye = speye (m)
     C = cs.cs_multiply(A, AT)  # C = A*A'
     D = cs.cs_add(C, Eye, 1, cs.cs_norm(C))  # D = C + Eye*norm (C,1)
     #        print "D:"
     #        cs.cs_print(D, False) # print D
     return D
コード例 #5
0
ファイル: csparse_test.py プロジェクト: craig8/CSparse.py
    def compress(self, T):
        A = cs.cs_compress (T) # A = compressed-column form of T
#        print("A:")
#        cs.cs_print (A, False) # print A
        return A
コード例 #6
0
 def compress(self, T):
     A = cs.cs_compress(T)  # A = compressed-column form of T
     #        print("A:")
     #        cs.cs_print (A, False) # print A
     return A