5#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
14#include <Eigen/SparseCore>
63 Spy(std::string_view filename, std::string_view title,
64 std::string_view row_label, std::string_view col_label,
int rows,
68 write32le(title.size());
69 m_file.write(title.data(), title.size());
72 write32le(row_label.size());
73 m_file.write(row_label.data(), row_label.size());
76 write32le(col_label.size());
77 m_file.write(col_label.data(), col_label.size());
89 void add(
const Eigen::SparseMatrix<double>& mat) {
91 write32le(mat.nonZeros());
94 for (
int k = 0; k < mat.outerSize(); ++k) {
95 for (Eigen::SparseMatrix<double>::InnerIterator it{mat, k}; it; ++it) {
98 if (it.value() > 0.0) {
100 }
else if (it.value() < 0.0) {
110 std::ofstream m_file;
117 void write32le(int32_t num) {
118 if constexpr (std::endian::native != std::endian::little) {
121 m_file.write(
reinterpret_cast<char*
>(&num),
sizeof(num));
This file implements the C++20 <bit> header.
Writes the sparsity pattern of a sparse matrix to a file.
Definition spy.hpp:51
void add(const Eigen::SparseMatrix< double > &mat)
Adds a matrix to the file.
Definition spy.hpp:89
Spy(std::string_view filename, std::string_view title, std::string_view row_label, std::string_view col_label, int rows, int cols)
Constructs a Spy instance.
Definition spy.hpp:63
Definition expression_graph.hpp:11
Definition PointerIntPair.h:280
constexpr T byteswap(T V) noexcept
Reverses the bytes in the given integer value V.
Definition bit.h:63
#define SLEIPNIR_DLLEXPORT
Definition symbol_exports.hpp:34