MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
spy.hpp File Reference
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <stdexcept>
#include <vector>
#include <mtl/concepts/magnitude.hpp>
#include <mtl/math/identity.hpp>
#include <mtl/io/png.hpp>
#include <mtl/mat/compressed2D.hpp>
#include <mtl/mat/coordinate2D.hpp>
#include <mtl/mat/ell_matrix.hpp>

Classes

struct  mtl::io::spy_options
 Rendering options shared by the spy variants. More...
struct  mtl::io::detail::spy_grid< Mag >
 Binned grid: for each of W*H pixel cells, the non-zero count and the largest |value| that fell in it. More...

Namespaces

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

Functions

template<typename M, typename F>
void mtl::io::for_each_nonzero (const M &A, F &&f)
 Generic fallback: scan (i,j) and report entries that differ from zero.
template<typename Value, typename Parameters, typename F>
void mtl::io::for_each_nonzero (const mat::compressed2D< Value, Parameters > &A, F &&f)
 CSR: iterate the three arrays directly (O(nnz)), skipping stored zeros.
template<typename Value, typename Parameters, typename F>
void mtl::io::for_each_nonzero (const mat::coordinate2D< Value, Parameters > &A, F &&f)
 COO: iterate the stored triplets (O(nnz)), skipping stored zeros.
template<typename Value, typename Parameters, typename F>
void mtl::io::for_each_nonzero (const mat::ell_matrix< Value, Parameters > &A, F &&f)
 ELLPACK: iterate the packed rows up to the invalid sentinel (O(nnz)), skipping stored zeros.
std::size_t mtl::io::detail::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 > > mtl::io::detail::build_spy_grid (const M &A, std::size_t max_pixels)
void mtl::io::detail::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.
template<typename M>
void mtl::io::spy (const M &A, const std::filesystem::path &path, const spy_options &opt={})
 Binary non-zero pattern: black mark on white where the matrix has a non-zero (MATLAB spy).
template<typename M>
void mtl::io::spy_magnitude (const M &A, const std::filesystem::path &path, const spy_options &opt={})
 Non-zero pattern colored by per-cell max |a_ij| (analog of imagesc(abs(A))).
template<typename M>
void mtl::io::spy_density (const M &A, const std::filesystem::path &path, const spy_options &opt={})
 Non-zero pattern colored by per-cell non-zero count – reveals clustering once a large matrix is down-sampled.