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 Type
- data Field
- data Format
- = Coordinate
- | Array
- data MatrixType
- 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 -> MatrixType -> (Int, Int) -> [a] -> IO ()
- hPutMatrixWithDesc :: Show a => Handle -> String -> Field -> MatrixType -> (Int, Int) -> [a] -> IO ()
- hGetMatrix :: Read a => Handle -> Field -> MatrixType -> IO ((Int, Int), Maybe [a])
- hPutCoordMatrix :: Show a => Handle -> Field -> MatrixType -> (Int, Int) -> Int -> [((Int, Int), a)] -> IO ()
- hPutCoordMatrixWithDesc :: Show a => Handle -> String -> Field -> MatrixType -> (Int, Int) -> Int -> [((Int, Int), a)] -> IO ()
- hGetCoordMatrix :: Read a => Handle -> Field -> MatrixType -> IO ((Int, Int), Int, Either [(Int, Int)] [((Int, Int), a)])
- showVectorHeader :: Format -> Field -> String
- showMatrixHeader :: Format -> Field -> MatrixType -> String
- readHeader :: String -> (Type, Format, Field, Maybe MatrixType)
- hPutVectorBanner :: Handle -> Format -> Field -> String -> IO ()
- hPutMatrixBanner :: Handle -> Format -> Field -> MatrixType -> String -> IO ()
- hGetBanner :: Handle -> IO (Type, Format, Field, Maybe MatrixType)
- hPutVectorHeader :: Handle -> Format -> Field -> IO ()
- hPutMatrixHeader :: Handle -> Format -> Field -> MatrixType -> IO ()
- hGetHeader :: Handle -> IO (Type, Format, Field, Maybe MatrixType)
- commentChar :: Char
- hPutComments :: Handle -> String -> IO ()
- hGetComments :: Handle -> IO String
Matrix and vector type descriptors
Specifies what kind of object is stored in the file. Note that "vector" is a non-standard format.
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.
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.
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.
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.