|
MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
|
Classes | |
| class | 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 | mm_header |
| The banner %MatrixMarket matrix <format> <field> <symmetry>. More... | |
| struct | mm_sizes |
| Everything after the banner up to the data: comment lines, then the size line, checked in full. More... | |
| struct | spy_grid |
| Binned grid: for each of W*H pixel cells, the non-zero count and the largest |value| that fell in it. More... | |
| class | token_cursor |
| Splits a line into whitespace-separated tokens, one at a time. More... | |
Functions | |
| mm_header | parse_mm_banner (const std::string &banner_line) |
| Parse the banner. | |
| bool | 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 | 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 | check_mm_field (const mm_header &h, const char *who) |
| Checks that Value can hold the file's field. | |
| bool | next_data_line (mm_reader &in, std::string &line) |
| The next non-blank line, or false at EOF. | |
| template<typename Value> | |
| bool | 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 | mm_mirror (const mm_header &h, const Value &v) |
| The mirrored value at (j, i) for a stored (i, j), i != j. | |
| mm_sizes | read_mm_sizes (mm_reader &in, const mm_header &h, std::size_t max_index, const std::string &filename, const char *who) |
| void | 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 | 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 | 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> | |
| constexpr const char * | mm_field_name () |
| The banner field for a value type: complex for std::complex, integer for integral types, real otherwise. | |
| template<typename Value> | |
| void | set_mm_precision (std::ostream &out) |
| Enough digits for the value to read back exactly. | |
| template<typename T> | |
| void | 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 | write_mm_value (std::ostream &out, const Value &v) |
| One value: a complex one as "re im". | |
| const std::array< std::uint32_t, 256 > & | crc32_table () |
| CRC-32 lookup table (reflected polynomial 0xEDB88320), built once. | |
| std::uint32_t | crc32_add (std::uint32_t crc, const std::uint8_t *buf, std::size_t len) |
| Fold bytes into a running CRC-32 register (internal, pre-inverted form: start from 0xFFFFFFFF and XOR 0xFFFFFFFF once at the end). | |
| std::uint32_t | adler32 (const std::uint8_t *data, std::size_t len) |
| Adler-32 (zlib checksum) of a byte buffer. | |
| void | put_u32_be (std::vector< std::uint8_t > &v, std::uint32_t x) |
| std::vector< std::uint8_t > | zlib_store (const std::vector< std::uint8_t > &raw) |
| Wrap raw bytes into a zlib stream of DEFLATE stored blocks (no compression). | |
| void | write_chunk (std::ofstream &os, const char type[4], const std::vector< std::uint8_t > &data) |
| Write one PNG chunk: length (BE) + type + data + CRC-32(type+data). | |
| void | write_png (const std::filesystem::path &path, const std::uint8_t *pixels, std::size_t w, std::size_t h, int channels) |
| Core writer: channels is 1 (grayscale) or 3 (RGB); pixels is row-major, w*h*channels bytes, top row first. | |
| bool | split_fields (std::string_view line, char delimiter, std::vector< std::string_view > &fields) |
| The fields of one line. | |
| std::size_t | scale_index (std::size_t idx, std::size_t span, std::size_t dim) |
| floor(idx * span / dim) for idx < dim and span <= dim, without overflowing the intermediate product for huge logical dimensions. | |
| template<typename M> | |
| spy_grid< magnitude_t< typename M::value_type > > | build_spy_grid (const M &A, std::size_t max_pixels) |
| void | colormap (double t, std::uint8_t &r, std::uint8_t &gc, std::uint8_t &b) |
| Compact viridis-like colormap: t in [0,1] -> (r,g,b), 8-bit. | |
| bool | is_space (char ch) noexcept |
| bool | is_blank (std::string_view line) noexcept |
| True if the line holds nothing but whitespace. | |
| bool | parse_index (std::string_view tok, std::size_t &out, std::size_t max=std::numeric_limits< std::size_t >::max()) noexcept |
| A non-negative decimal integer, the whole token. | |
| template<typename T> | |
| bool | parse_float_strto (const char *first, const char *last, T &out) |
| The strtof/strtod/strtold reading of [first, last), a token without a leading '+': parse_value's path where std::from_chars is missing, or where it reports a value out of range. | |
| template<typename T> | |
| bool | parse_value (std::string_view tok, T &out) |
| One value, the whole token. | |
|
inline |
Adler-32 (zlib checksum) of a byte buffer.
| spy_grid< magnitude_t< typename M::value_type > > mtl::io::detail::build_spy_grid | ( | const M & | A, |
| std::size_t | max_pixels ) |
| void mtl::io::detail::check_mm_field | ( | const mm_header & | h, |
| const char * | who ) |
Checks that Value can hold the file's field.
|
inline |
After the data: only blank and comment lines may follow.
|
inlinenoexcept |
a * b, or false if it overflows max.
|
inline |
Compact viridis-like colormap: t in [0,1] -> (r,g,b), 8-bit.
|
inline |
Fold bytes into a running CRC-32 register (internal, pre-inverted form: start from 0xFFFFFFFF and XOR 0xFFFFFFFF once at the end).
|
inline |
CRC-32 lookup table (reflected polynomial 0xEDB88320), built once.
|
inlinenoexcept |
True if the line holds nothing but whitespace.
|
inlinenoexcept |
|
constexpr |
The banner field for a value type: complex for std::complex, integer for integral types, real otherwise.
| 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.
|
inline |
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).
Throws if it overflows max.
|
inline |
The next non-blank line, or false at EOF.
| bool mtl::io::detail::parse_float_strto | ( | const char * | first, |
| const char * | last, | ||
| T & | out ) |
The strtof/strtod/strtold reading of [first, last), a token without a leading '+': parse_value's path where std::from_chars is missing, or where it reports a value out of range.
strto* also reads hexadecimal floats ("0x1p3"), which from_chars in its general format does not, so they are refused here: the grammar is the same either way (#855). strto* would also skip leading whitespace, but a token has none.
|
inlinenoexcept |
A non-negative decimal integer, the whole token.
Rejects a sign, other characters, and values above max.
|
inline |
Parse the banner.
All five tokens are required and matched exactly (case insensitive): symmetric is a substring of skew-symmetric, so substring matching is unsafe, and a missing token used to default silently (#843). pattern is not supported, and hermitian needs a complex field.
| bool mtl::io::detail::parse_value | ( | std::string_view | tok, |
| T & | out ) |
One value, the whole token.
|
inline |
| 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).
| 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.
Mirroring is left to the caller.
|
inline |
| 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.
|
inline |
floor(idx * span / dim) for idx < dim and span <= dim, without overflowing the intermediate product for huge logical dimensions.
| void mtl::io::detail::set_mm_precision | ( | std::ostream & | out | ) |
Enough digits for the value to read back exactly.
|
inline |
The fields of one line.
With a space delimiter, any run of whitespace separates fields. With another delimiter, the line is split on exactly that character and each field is trimmed, so an empty field ("1,,2") is an error rather than a dropped column.
|
inline |
Write one PNG chunk: length (BE) + type + data + CRC-32(type+data).
| 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.
| void mtl::io::detail::write_mm_value | ( | std::ostream & | out, |
| const Value & | v ) |
One value: a complex one as "re im".
|
inline |
Core writer: channels is 1 (grayscale) or 3 (RGB); pixels is row-major, w*h*channels bytes, top row first.
|
inline |
Wrap raw bytes into a zlib stream of DEFLATE stored blocks (no compression).