matrix-market-1.2: 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 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 Type 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 

Instances

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 -> IO (Field, Int, Maybe [a])Source

Lazily read a dense vector from a file. The vector field, dimension and elements are returned. The file is put in a semi-closed state and the elements are read lazily. 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 -> IO (Field, Int, Int, Either [Int] [(Int, a)])Source

Lazily read a coordinate vector from a file. The vector field, dimension, size, and elements are returned. The file is put in a semi-clased state and the elements are read lazily. If the field is Pattern, only a list of indices is returned.

Dense Matrix I/O

hPutMatrix :: Show a => Handle -> Field -> Type -> (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 -> Type -> (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 -> IO (Field, Type, (Int, Int), Maybe [a])Source

Lazily read a dense matrix from a file, returning the matrix field, type, shape and elements in column-major order. The elements are read laxily, and the file is put in a semi-closed state. If the field is Pattern, Nothing is returned instead of an element list.

Sparse Matrix I/O

hPutCoordMatrix :: Show a => Handle -> Field -> Type -> (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 -> Type -> (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 -> IO (Field, Type, (Int, Int), Int, Either [(Int, Int)] [((Int, Int), a)])Source

Lazily read a coordinate matrix from a file. The matrix field, type, shape size,and elements are returned. The files contents lazily, and the file is put in a semi-closed state. If the field is Pattern, only the indices are returned.

Banner Functions

showHeader :: Format -> Field -> Type -> StringSource

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

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

Read a Matrix Market header from a string.

hPutBanner :: Handle -> Format -> Field -> Type -> String -> IO ()Source

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

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

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

hPutHeader :: Handle -> Format -> Field -> Type -> IO ()Source

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

hGetHeader :: Handle -> IO (Format, Field, Type)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.