Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Dia/Morpheus_Print_Impl.hpp
1
24#ifndef MORPHEUS_DIA_PRINT_IMPL_HPP
25#define MORPHEUS_DIA_PRINT_IMPL_HPP
26
27#include <Morpheus_FormatTags.hpp>
28#include <impl/Morpheus_Utils.hpp>
29
30#include <iostream>
31#include <iomanip> // setw, setprecision
32#include <algorithm> // max, min
33
34namespace Morpheus {
35namespace Impl {
36
37template <typename Printable, typename Stream>
38void print(const Printable& p, Stream& s,
39 typename std::enable_if<
40 Morpheus::is_dia_matrix_format_container_v<Printable>>::type* =
41 nullptr) {
42 using size_type = typename Printable::size_type;
43 using index_type = typename Printable::index_type;
44 using value_type = typename Printable::value_type;
45 const size_type ndiag = p.cvalues().ncols();
46
47 print_matrix_header(p, s);
48
49 for (size_type i = 0; i < ndiag; i++) {
50 const index_type k = p.cdiagonal_offsets(i);
51
52 const size_type i_start = std::max<size_type>(0, -k);
53 const size_type j_start = std::max<size_type>(0, k);
54
55 // number of elements to process in this diagonal
56 const size_type N = std::min(p.nrows() - i_start, p.ncols() - j_start);
57
58 for (size_type n = 0; n < N; n++) {
59 value_type temp = p.cvalues(i_start + n, i);
60 if (temp != value_type(0)) {
61 s << " " << std::setw(14) << i;
62 s << " " << std::setw(14) << i_start + n;
63 s << " " << std::setw(14) << j_start + n;
64 s << " " << std::setprecision(4) << std::setw(8) << "(" << temp
65 << ")\n";
66 }
67 }
68 }
69}
70
71} // namespace Impl
72} // namespace Morpheus
73
74#endif // MORPHEUS_DIA_PRINT_IMPL_HPP
Generic Morpheus interfaces.
Definition: dummy.cpp:24