def find(self): """ Return the sparse matrix in triple format (val,irow,jcol). If the matrix data type is `None`, i.e., only the matrix sparsity pattern is available, this method returns (irow,jcol). """ if self.dtype is not None: return (self.values, self.irow, self.jcol) return (self.irow, self.jcol) if __name__ == '__main__': import sys fname = sys.argv[1] A = MatrixMarketMatrix(fname) print 'type: ', A.dtype print 'symmetric, Hermitian, skew: ', A.symmetric, A.Hermitian, A.skewsym print 'comments:' print A.comments from hsl.tools.spy import fast_spy import matplotlib.pyplot as plt fig = plt.figure() fast_spy(A.nrow, A.ncol, A.irow, A.jcol, sym=(A.symmetric or A.Hermitian or A.skewsym), # val=A.values, ax=fig.gca(), ) plt.show()
if len(sys.argv) < 2: sys.stderr.write('Supply input matrix as argument\n') sys.exit(1) fname = sys.argv[1] # M = HarwellBoeingMatrix(fname, patternOnly=True, readRhs=False) M = RutherfordBoeingData(fname, patternOnly=True, readRhs=False) if M.nrow != M.ncol: sys.stderr.write('Input matrix must be square\n') sys.exit(1) perm, nzdiag = nonzerodiag(M.nrow, M.ind, M.ip) print 'Number of nonzeros on diagonal after reordering: ', nzdiag try: from hsl.tools.spy import fast_spy import pylab (_, irow, jcol) = M.find() left = pylab.subplot(121) fast_spy(M.nrow, M.ncol, irow, jcol, sym=M.issym, ax=left.get_axes()) right = pylab.subplot(122) fast_spy(M.nrow, M.ncol, perm[irow], jcol, sym=M.issym, ax=right.get_axes()) pylab.show() # pylab.savefig('mc21.pdf', bbox_inches='tight') except: pass
if len(sys.argv) < 2: sys.stderr.write('Data file name must be supplied\n') sys.exit(1) fname = sys.argv[1] #M = HarwellBoeingMatrix(fname, patternOnly=True, readRhs=False) M = RutherfordBoeingData(fname, patternOnly=True, readRhs=False) if M.nrow != M.ncol or not M.issym: sys.stderr.write('Input matrix must be square and symmetric\n') sys.exit(1) # Compute reverse Cuthill-McKee ordering perm, rinfo = rcmk(M.nrow, M.ind, M.ip) # Or: Compute Sloan's ordering #perm, rinfo = sloan(M.nrow, M.ind, M.ip) # Plot original matrix (_, irow, jcol) = M.find() left = pylab.subplot(121) fast_spy(M.nrow, M.ncol, irow, jcol, sym=M.issym, ax=left.get_axes(), title='Original') # Apply permutation and plot reordered matrix right = pylab.subplot(122) fast_spy(M.nrow, M.ncol, perm[irow], perm[jcol], sym=M.issym, ax=right.get_axes(), title='Reordered') pylab.show()
import matplotlib.pyplot as plt A = LLSparseMatrix(mm_filename='bcsstk01.mtx', itype=types.INT32_T, dtype=types.FLOAT64_T) m, n = A.shape irow, jcol, val = A.find() A_csc = A.to_csc() colptr, rowind, values = A_csc.get_numpy_arrays() perm1, rinfo1 = rcmk(n, rowind, colptr) # Reverse Cuthill-McKee perm2, rinfo2 = sloan(n, rowind, colptr) # Sloan's method left = plt.subplot(131) fast_spy(n, n, irow, jcol, sym=True, ax=left.get_axes(), title='Original') # Apply permutation 1 and plot reordered matrix middle = plt.subplot(132) fast_spy(n, n, perm1[irow], perm1[jcol], sym=True, ax=middle.get_axes(), title='Rev. Cuthill-McKee (semibandwidth=%d)' % rinfo1[2]) # Apply permutation 2 and plot reordered matrix right = plt.subplot(133) fast_spy(n, n, perm2[irow], perm2[jcol], sym=True, ax=right.get_axes(), title='Sloan (semibandwidth=%d)' % rinfo2[2]) plt.savefig('mc60_rcmk_sloan.png', bbox_inches='tight') # plt.show()