Stability | stable |
---|---|

Maintainer | Patrick Perry <patperry@stanford.edu> |

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

- data Field
- data Format
- = Coordinate
- | Array

- data Type
- hPutVector :: Show a => Handle -> Field -> Int -> [a] -> IO ()
- hPutVectorWithDesc :: Show a => Handle -> String -> Field -> Int -> [a] -> IO ()
- hGetVector :: Read a => Handle -> Field -> IO (Int, Maybe [a])
- hPutCoordVector :: Show a => Handle -> Field -> Int -> Int -> [(Int, a)] -> IO ()
- hPutCoordVectorWithDesc :: Show a => Handle -> String -> Field -> Int -> Int -> [(Int, a)] -> IO ()
- hGetCoordVector :: Read a => Handle -> Field -> IO (Int, Int, Either [Int] [(Int, a)])
- hPutMatrix :: Show a => Handle -> Field -> Type -> (Int, Int) -> [a] -> IO ()
- hPutMatrixWithDesc :: Show a => Handle -> String -> Field -> Type -> (Int, Int) -> [a] -> IO ()
- hGetMatrix :: Read a => Handle -> Field -> Type -> IO ((Int, Int), Maybe [a])
- hPutCoordMatrix :: Show a => Handle -> Field -> Type -> (Int, Int) -> Int -> [((Int, Int), a)] -> IO ()
- hPutCoordMatrixWithDesc :: Show a => Handle -> String -> Field -> Type -> (Int, Int) -> Int -> [((Int, Int), a)] -> IO ()
- hGetCoordMatrix :: Read a => Handle -> Field -> Type -> IO ((Int, Int), Int, Either [(Int, Int)] [((Int, Int), a)])
- showHeader :: Format -> Field -> Type -> String
- readHeader :: String -> (Format, Field, Type)
- hPutBanner :: Handle -> Format -> Field -> Type -> String -> IO ()
- hGetBanner :: Handle -> IO (Format, Field, Type)
- hPutHeader :: Handle -> Format -> Field -> Type -> IO ()
- hGetHeader :: Handle -> IO (Format, Field, Type)
- commentChar :: Char
- hPutComments :: Handle -> String -> IO ()
- hGetComments :: Handle -> IO String

# Matrix and vector type descriptors

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

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.

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.

# 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 -> 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 -> Field -> Type -> 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 -> 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 -> Field -> Type -> 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

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

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

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

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

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

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

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.