Mundy: Multibody Nonlocal Dynamics Version of the Day
Loading...
Searching...
No Matches
matrix_market.hpp File Reference

Write and read vectors and matrices as Matrix Market array files, and sparse matrices as Matrix Market coordinate files, exactly. More...

Namespaces

namespace  mundy

Functions

Kokkos views
template<class View>
void mundy::write_matrix_market (const std::string &filename, const View &view)
 Write a rank-1 or rank-2 view to filename as a Matrix Market array file.
template<class View>
void mundy::read_matrix_market (const std::string &filename, View &view)
 Read a Matrix Market array file into a rank-1 or rank-2 view, resized to the file's extents.
AVector and AMatrix
template<typename T, size_t N, ValidAccessor< T > Accessor>
void mundy::write_matrix_market (const std::string &filename, const AVector< T, N, Accessor > &vec)
 Write an N-vector to filename as an N x 1 Matrix Market array file.
template<typename T, size_t N, size_t M, ValidAccessor< T > Accessor>
void mundy::write_matrix_market (const std::string &filename, const AMatrix< T, N, M, Accessor > &mat)
 Write an N x M matrix to filename as a Matrix Market array file.
template<typename T, size_t N, ValidAccessor< T > Accessor>
void mundy::read_matrix_market (const std::string &filename, AVector< T, N, Accessor > &vec)
 Read an N x 1 Matrix Market array file into an N-vector.
template<typename T, size_t N, size_t M, ValidAccessor< T > Accessor>
void mundy::read_matrix_market (const std::string &filename, AMatrix< T, N, M, Accessor > &mat)
 Read an N x M Matrix Market array file into an N x M matrix.
Linear operators
template<class Backend, class LinearOp>
void mundy::write_matrix_market (const std::string &filename, const LinearOp &op)
 Write op's matrix to filename as a Matrix Market array file: column j is op applied, through Backend, to the j-th column of the identity.

Detailed Description

The Matrix Market array format is the dense text format of numpy and scipy (mmread, mmwrite), MATLAB, Tpetra, and Eigen: the banner "%%MatrixMarket matrix array real general", the extents "rows cols", then the entries in column-major order, one per line. A vector is a rows x 1 column. The coordinate format is their sparse peer: the banner "%%MatrixMarket matrix coordinate real general", the extents "rows cols nnz", then one stored entry per line as "row col value" with one-based indices. Each entry is written as the shortest decimal that reads back to the same bits, so writing then reading reproduces every value exactly, including -0, infinities, and NaN.

Both solver backends are supported. Kokkos views (rank 1 or 2, any memory space and layout) are resized to the file's extents, and a sparse matrix takes the file's extents and entries. AVector and AMatrix have compile-time sizes, so the file's extents must equal them.

A linear operator, with or without a stored matrix, is written as its matrix: column j is the operator applied to the j-th column of the identity.

These functions are serial: every process that calls them opens the file itself, so under MPI only one process should write a given file.