matrix-market-1.0: Read and write NIST Matrix Market files

Stabilitystable
MaintainerPatrick Perry <patperry@stanford.edu>

System.IO.MatrixMarket

Contents

Description

Read and write matrices and vectors in the Matrix Market format (see http://math.nist.gov/MatrixMarket/).

Synopsis

Matrix and vector type descriptors

data Type Source

Specifies what kind of object is stored in the file. Note that "vector" is a non-standard format.

Constructors

Matrix 
Vector 

Instances

data Field Source

Specifies the element type. Pattern matrices do not have any elements, only indices, and only make sense for coordinate matrices and vectors.

Constructors

Real 
Complex 
Integer 
Pattern 

Instances

data Format Source

Specifies either sparse or dense storage. In sparse ("coordinate") storage, elements are given in (i,j,x) triplets for matrices (or (i,x) for vectors). Indices are 1-based, so that A(1,1) is the first element of a matrix, and x(1) is the first element of a vector.

In dense ("array") storage, elements are given in column-major order.

In both cases, each element is given on a separate line.

Constructors

Coordinate 
Array 

data MatrixType Source

Specifies any special structure in the matrix. For symmetric and hermition matrices, only the lower-triangular part of the matrix is given. For skew matrices, only the entries below the diagonal are stored.

Constructors

General 
Symmetric 
Hermitian 
Skew 

Dense Vector I/O

hPutVector :: Show a => Handle -> Field -> Int -> [a] -> IO ()Source

Write a dense vector with the given dimension and elements to a file. If the field is given as Pattern, no elements are written, only the header and size.

hPutVectorWithDesc :: Show a => Handle -> String -> Field -> Int -> [a] -> IO ()Source

Write a dense vector along with a description, which is put in the comment section of the file.

hGetVector :: Read a => Handle -> Field -> IO (Int, Maybe [a])Source

Lazily read a dense vector from a file. The vector dimension and elements are returned. The file is closed when the operation finishes. If the field is Pattern, the elements list will be Nothing.

Sparse Vector I/O

hPutCoordVector :: Show a => Handle -> Field -> Int -> Int -> [(Int, a)] -> IO ()Source

Write a coordinate vector with the given dimension and size to a file. The indices are 1-based, so that x(1) is the first element of the vector. If the field is Pattern, only the indices are used.

hPutCoordVectorWithDesc :: Show a => Handle -> String -> Field -> Int -> Int -> [(Int, a)] -> IO ()Source

Write a coordinate vector along with a description, which is put in the comment section of the file.

hGetCoordVector :: Read a => Handle -> Field -> IO (Int, Int, Either [Int] [(Int, a)])Source

Lazily read a coordinate vector from a file. The vector dimension, size, and elements are returned. The file is closed when the operation finishes. If the field is given as Pattern, only a list of indices is returned.

Dense Matrix I/O

hPutMatrix :: Show a => Handle -> Field -> MatrixType -> (Int, Int) -> [a] -> IO ()Source

Write a dense matrix with the given shape and elements in column-major order to a file. If the field is given as Pattern, no elements are written, only the header and size.

hPutMatrixWithDesc :: Show a => Handle -> String -> Field -> MatrixType -> (Int, Int) -> [a] -> IO ()Source

Write a dense matrix along with a description, which is put in the comment section of the file.

hGetMatrix :: Read a => Handle -> Field -> MatrixType -> IO ((Int, Int), Maybe [a])Source

Lazily read a dense matrix from a file, returning the matrix shape and its elements in column-major order. The file is closed when the operation finishes. If the field is given as Pattern, Nothing is returned instead of an element list.

Sparse Matrix I/O

hPutCoordMatrix :: Show a => Handle -> Field -> MatrixType -> (Int, Int) -> Int -> [((Int, Int), a)] -> IO ()Source

Write a coordinate matrix with the given shape and size to a file. The indices are 1-based, so that A(1,1) is the first element of the matrix. If the field is Pattern, only the indices are used.

hPutCoordMatrixWithDesc :: Show a => Handle -> String -> Field -> MatrixType -> (Int, Int) -> Int -> [((Int, Int), a)] -> IO ()Source

Write a coordinate matrix along with a description, which is put in the comment section of the file.

hGetCoordMatrix :: Read a => Handle -> Field -> MatrixType -> IO ((Int, Int), Int, Either [(Int, Int)] [((Int, Int), a)])Source

Lazily read a coordinate vector from a file. The vector dimension, size, and elements are returned. The file is closed when the operation finishes. If the field is Pattern, only the indices are returned.

Banner Functions

showVectorHeader :: Format -> Field -> StringSource

Give the Matrix Market header string for the given vector type.

showMatrixHeader :: Format -> Field -> MatrixType -> StringSource

Give the Matrix Market header string for the given matrix type.

readHeader :: String -> (Type, Format, Field, Maybe MatrixType)Source

Read a Matrix Market header from a string.

hPutVectorBanner :: Handle -> Format -> Field -> String -> IO ()Source

Write out a header and comments for a Matrix Market vector.

hPutMatrixBanner :: Handle -> Format -> Field -> MatrixType -> String -> IO ()Source

Write out a header and comments for a Matrix Market matrix.

hGetBanner :: Handle -> IO (Type, Format, Field, Maybe MatrixType)Source

Read the Matrix Market banner (including comments) from a file. The comments are discarded and the banner information is returned.

hPutVectorHeader :: Handle -> Format -> Field -> IO ()Source

Write a Matrix Market header for a vector to a file.

hPutMatrixHeader :: Handle -> Format -> Field -> MatrixType -> IO ()Source

Write a Matrix Market header for a matrix to a file.

hGetHeader :: Handle -> IO (Type, Format, Field, Maybe MatrixType)Source

Read the Matrix Market header from a file.

commentChar :: CharSource

The line-comment character (%).

hPutComments :: Handle -> String -> IO ()Source

Write a string as a Matrix Market file comment. This prepends each line with '%' and then writes it out to the file.

hGetComments :: Handle -> IO StringSource

Read the comments from a file, stripping the leading '%' from each line, until reaching a line that does not start with the comment character.