yog_io/matrix_market
Matrix Market Coordinate format support.
This module provides functions to serialize and deserialize graphs in
Matrix Market coordinate format (.mtx). This is a popular sparse matrix
format used in scientific computing.
Format Overview
The format consists of a header line starting with %%MatrixMarket,
optional comments starting with %, a size line (rows, columns, entries),
and then data lines (row, column, value).
Example
%%MatrixMarket matrix coordinate real general
% Generated by Yog
3 3 2
1 2 1.0
2 3 1.0
Usage
import yog_io/matrix_market as mtx_io
pub fn main() {
let assert Ok(result) = mtx_io.read("graph.mtx")
let graph = result.graph
}
Types
Errors that can occur during Matrix Market operations
pub type MatrixMarketError {
EmptyInput
ReadError(path: String, error: String)
WriteError(path: String, error: String)
InvalidHeader(line: String)
MissingHeader(line: String)
InvalidSizeLine(line: String)
UnexpectedEndOfFile
}
Constructors
-
EmptyInputInput string is empty
-
ReadError(path: String, error: String)File not found or couldn’t be read
-
WriteError(path: String, error: String)File couldn’t be written
-
InvalidHeader(line: String)Header line is invalid
-
MissingHeader(line: String)Header line is missing
-
InvalidSizeLine(line: String)Size line (rows cols entries) is invalid
-
UnexpectedEndOfFileEnd of file reached before all data was parsed
The result of parsing a Matrix Market file
pub type MatrixMarketResult(n, e) {
MatrixMarketResult(
graph: model.Graph(n, e),
warnings: List(String),
)
}
Constructors
-
MatrixMarketResult( graph: model.Graph(n, e), warnings: List(String), )
Values
pub fn from_string(
input: String,
) -> Result(MatrixMarketResult(Nil, Float), MatrixMarketError)
Parses a Matrix Market string representation into a graph.
pub fn read(
path: String,
) -> Result(MatrixMarketResult(Nil, Float), MatrixMarketError)
Reads a graph from a Matrix Market file.
pub fn serialize(graph: model.Graph(n, Float)) -> String
Serializes a graph to Matrix Market coordinate format.
pub fn write(
path: String,
graph: model.Graph(n, Float),
) -> Result(Nil, MatrixMarketError)
Writes a graph to a Matrix Market file.