MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
matrix_market.hpp File Reference
#include <algorithm>
#include <cctype>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <limits>
#include <ostream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <vector>
#include <mtl/concepts/magnitude.hpp>
#include <mtl/concepts/scalar.hpp>
#include <mtl/io/text_parse.hpp>
#include <mtl/mat/dense2D.hpp>
#include <mtl/mat/compressed2D.hpp>
#include <mtl/mat/coordinate2D.hpp>
#include <mtl/math/identity.hpp>

Classes

class  mtl::io::detail::mm_reader
 Line source for Matrix Market input: reads from a plain file, or transparently from a gzip-compressed ".gz" file when built with zlib. More...
struct  mtl::io::detail::mm_header
 The banner %MatrixMarket matrix <format> <field> <symmetry>. More...
struct  mtl::io::detail::mm_sizes
 Everything after the banner up to the data: comment lines, then the size line, checked in full. More...

Namespaces

namespace  mtl
namespace  mtl::io
namespace  mtl::io::detail

Functions

mm_header mtl::io::detail::parse_mm_banner (const std::string &banner_line)
 Parse the banner.
bool mtl::io::detail::checked_mul (std::size_t a, std::size_t b, std::size_t &out, std::size_t max=std::numeric_limits< std::size_t >::max()) noexcept
 a * b, or false if it overflows max.
std::size_t mtl::io::detail::mm_value_count (const mm_header &h, std::size_t nrows, std::size_t ncols, std::size_t max, const char *who)
 The number of values an array-format file holds, which is also the most entries a coordinate file can have without duplicates: m*n for general, n(n+1)/2 for symmetric and hermitian, n(n-1)/2 for skew-symmetric (whose diagonal is zero and not stored).
template<typename Value>
void mtl::io::detail::check_mm_field (const mm_header &h, const char *who)
 Checks that Value can hold the file's field.
bool mtl::io::detail::next_data_line (mm_reader &in, std::string &line)
 The next non-blank line, or false at EOF.
template<typename Value>
bool mtl::io::detail::read_mm_value (token_cursor &cur, const mm_header &h, Value &v)
 Reads one value (two numbers for a complex field) from the cursor.
template<typename Value>
Value mtl::io::detail::mm_mirror (const mm_header &h, const Value &v)
 The mirrored value at (j, i) for a stored (i, j), i != j.
mm_sizes mtl::io::detail::read_mm_sizes (mm_reader &in, const mm_header &h, std::size_t max_index, const std::string &filename, const char *who)
void mtl::io::detail::check_mm_trailer (mm_reader &in, std::size_t expected, const char *who)
 After the data: only blank and comment lines may follow.
template<typename Value, typename F>
void mtl::io::detail::read_mm_array (mm_reader &in, const mm_header &h, const mm_sizes &z, const char *who, F &&f)
 Visits the array-format values in file order (column-major; for a symmetric, skew-symmetric or hermitian file, the lower triangle by columns, without the diagonal when skew), as f(i, j, v).
template<typename Value, typename F>
void mtl::io::detail::read_mm_coordinate (mm_reader &in, const mm_header &h, const mm_sizes &z, const char *who, F &&f)
 Visits the coordinate entries as f(i, j, v), 0-based, after checking each line and index.
template<typename Value = double, typename Parameters = mat::parameters<>>
mat::compressed2D< Value, Parameters > mtl::io::mm_read (const std::string &filename)
 Read a Matrix Market file into a compressed2D, from either format.
template<typename Value = double>
mat::dense2D< Value > mtl::io::mm_read_dense (const std::string &filename)
 Read a Matrix Market file into a dense2D, from either format, with the same support and checks as mm_read.
template<typename Value>
constexpr const char * mtl::io::detail::mm_field_name ()
 The banner field for a value type: complex for std::complex, integer for integral types, real otherwise.
template<typename Value>
void mtl::io::detail::set_mm_precision (std::ostream &out)
 Enough digits for the value to read back exactly.
template<typename T>
void mtl::io::detail::write_mm_number (std::ostream &out, const T &v)
 One number; an integral one is promoted, so a char-sized type prints as a number rather than a character.
template<typename Value>
void mtl::io::detail::write_mm_value (std::ostream &out, const Value &v)
 One value: a complex one as "re im".
template<typename Matrix>
void mtl::io::mm_write (const std::string &filename, const Matrix &A, const std::string &comment="")
 Write a matrix in Matrix Market array format (column-major), with the field taken from the value type: real, integer or complex.
template<typename Value, typename Parameters>
void mtl::io::mm_write_sparse (const std::string &filename, const mat::compressed2D< Value, Parameters > &A, const std::string &comment="")
 Write a sparse matrix in Matrix Market coordinate format, with the field taken from the value type: real, integer or complex.