Input / Output

The hrb Module

Provides access to sparse linear systems described in Harwell-Boeing or Rutherford-Boeing format. This module exposes the two classes HarwellBoeingMatrix and RutherfordBoeingData. For more information, see the references below.

References

[DGL]I.S. Duff, R.G. Grimes and J.G. Lewis, Sparse Matrix Test Problems, ACM Transactions on Mathematical Software, 15(1), p.1-14, 1989
[HBUG]ftp://ftp.cerfacs.fr/pub/algo/matrices/harwell_boeing/userguide.ps.Z
[HB]http://math.nist.gov/MatrixMarket/data/Harwell-Boeing
[RBC]The Rutherford-Boeing Sparse Matrix Collection, I.S. Duff, R.G. Grimes and J.G. Lewis, Technical Report RAL-TR-97-031, Rutherford Appleton Laboratory, Chilton, OX, UK, 1997. (ftp://ftp.numerical.rl.ac.uk/pub/reports/duglRAL97031.pdf)
[RB]http://www.cerfacs.fr/algor/Softs/RB

Classes Available

class pyorder.tools.hrb.HarwellBoeingMatrix(fname, **kwargs)

Imports a sparse matrix from a file in Harwell-Boeing format. The matrix is stored in compressed sparse row format in (self.ind, self.ip, self.val). Right-hand sides, if any, are stored in self.rhs. Right-hand sides can be stored as dense vectors, in which case self.rhs has shape (nrow, nrhs), as sparse vectors, in which case they are stored in compressed sparse column format in (self.rhsptr, self.rhsind, self.rhs), or in elemental format (typically when the matrix itself is stored in finite-element format), in which case self.rhs has shape (nnzero, nrhs).

Note that the matrix indices are zero-based, i.e., row indices range from 0 through nrow-1 and column indices range from 0 through ncol-1.

The matrix can be subsequently converted to triple format with
(val, row, col) = self.find()
Keywords:
patternOnly:do not read matrix element values (False)
readRhs:read right-hand sides, if any (False)
readGuess:read starting guess, if any (False)
realSol:read solution vector, if any (False)
data()

Return matrix data in compressed sparse row format.

Returns:
val:array of values of nonzero elements
ip:array of pointer to rows
ind:array of indices of nonzero elements in each row
find()

Return matrix data in coordinate format.

Returns:
val:array of values of nonzero elements
irow:array of indices of nonzero elements in each row
jcol:array of indices of nonzero elements in each column
class pyorder.tools.hrb.RutherfordBoeingData(fname, **kwargs)

Bases: pyorder.tools.hrb.HarwellBoeingMatrix

Imports data from a file in Rutherford-Boeing format. The data is held in (self.ind, self.ip, self.val). If the data represents a sparse matrix, the three arrays represent the matrix stored in compressed sparse row format. Otherwise, the three arrays represent the supplementary data. Refer to the Rutherford-Boeing documentation for more information (reference [4] in the docstring for the present module.)

Note that the matrix indices are zero-based, i.e., row indices range from 0 through nrow-1 and column indices range from 0 through ncol-1.

The data can be subsequently converted to triple format with
(val, row, col) = self.find()
Keywords:
patternOnly:do not read data values (False)
data()

Return matrix data in compressed sparse row format.

Returns:
val:array of values of nonzero elements
ip:array of pointer to rows
ind:array of indices of nonzero elements in each row
find()

Return matrix data in coordinate format.

Returns:
val:array of values of nonzero elements
irow:array of indices of nonzero elements in each row
jcol:array of indices of nonzero elements in each column

Convenience Functions

See [RBC] for more information on the meaning of some of the arguments below.

pyorder.tools.hrb.write_rb(fname, nrow, ncol, ip, ind, val=None, precision=17, symmetric=False, skew=False, title='Generic', key='Generic')

Write a sparse matrix to file in Rutherford-Boeing format. The input matrix must be described in compressed column format by the arrays ip and ind. Rows must be ordered in each column. If numerical values are to be written to file, they should be specified in the array val.

Currently only supports assembled matrices in compressed column format.

pyorder.tools.hrb.write_rb_from_rb(fname, matrix)

Convenience function to write a matrix in RB format to file.

pyorder.tools.hrb.write_rb_from_coord(fname, nrow, ncol, irow, jcol, val=None, **kwargs)

Convenience function to write a matrix in coordinate format to file in RB format.

pyorder.tools.hrb.write_aux(fname, nrow, nvec, precision=17, title='Generic', key='Generic', caseid='Generic', dattyp='rhs', positn='r', orgniz='d', nauxd=None, ip=None, ind=None, val=None)

Write supplementary data to file in Rutherford-Boeing format.

Only real data is supported for now.

The mtx Module

Read a sparse matrix in Matrix Market format. See http://math.nist.gov/MatrixMarket for a description of this format.

Classes Available

class pyorder.tools.mtx.MatrixMarketMatrix(fname, **kwargs)

A MatrixMarketMatrix object represents a sparse matrix read from a file. This file must describe a sparse matrix in the MatrixMarket file format.

See http://math.nist.gov/MatrixMarket for more information.

Example: mat = MatrixMarketMatrix(‘1138bus.mtx’)

find()

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).