<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
debugutils.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
5//
6// This file is part of <T>LAPACK.
7// <T>LAPACK is free software: you can redistribute it and/or modify it under
8// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
9
10#ifndef TLAPACK_DEBUG_UTILS_HH
11#define TLAPACK_DEBUG_UTILS_HH
12
13#include <complex>
14#include <fstream>
15#include <iomanip>
16#include <iostream>
17#include <sstream>
18
20
21namespace tlapack {
22
28template <TLAPACK_MATRIX matrix_t>
30{
31 using idx_t = size_type<matrix_t>;
32 const idx_t m = std::min<idx_t>(100, nrows(A));
33 const idx_t n = std::min<idx_t>(100, ncols(A));
34
35 for (idx_t i = 0; i < m; ++i) {
36 std::cout << std::endl;
37 for (idx_t j = 0; j < n; ++j)
38 std::cout << std::setw(16) << A(i, j) << " ";
39 }
40}
41
50template <TLAPACK_MATRIX matrix_t>
51std::string visualize_matrix_text(const matrix_t& A)
52{
53 using idx_t = size_type<matrix_t>;
54 const idx_t m = std::min<idx_t>(100, nrows(A));
55 const idx_t n = std::min<idx_t>(100, ncols(A));
56
57 const int width = is_complex<type_t<matrix_t>> ? 25 : 10;
58
59 std::stringstream stream;
60 stream << "{ \"kind\":{ \"text\": true },\"text\": \"";
61
62 // Col indices
63 for (idx_t j = 0; j < n; ++j)
64 stream << std::setw(width) << j << " ";
65 stream << "\\n";
66
67 // Add the matrix values
68 for (idx_t i = 0; i < m; ++i) {
69 for (idx_t j = 0; j < n; ++j)
70 stream << std::setw(width) << std::setprecision(3) << A(i, j)
71 << " ";
72 stream << "\\n";
73 }
74
75 stream << "\"}";
76
77 return stream.str();
78}
79
88template <TLAPACK_MATRIX matrix_t>
90{
91 using idx_t = size_type<matrix_t>;
92 const idx_t m = std::min<idx_t>(100, nrows(A));
93 const idx_t n = std::min<idx_t>(100, ncols(A));
94
95 std::stringstream stream;
96 stream << "{ \"kind\":{ \"plotly\": true },\"data\":[{";
97
98 // Add the header (matrix index)
99 stream << "\"header\":{\"values\":[";
100 for (idx_t j = 0; j < n; ++j) {
101 stream << j;
102 if (j + 1 < n) stream << ", ";
103 }
104 stream << "]},";
105
106 // Add the matrix values
107 stream << "\"cells\":{\"values\":[";
108 for (idx_t j = 0; j < n; ++j) {
109 stream << "[";
110 for (idx_t i = 0; i < m; ++i) {
111 stream << "\"" << std::setprecision(3) << A(i, j) << "\"";
112 if (i + 1 < m) stream << ", ";
113 }
114 stream << "]";
115 if (j + 1 < n) stream << ", ";
116 }
117
118 stream << "]},";
119 stream << "\"type\": \"table\"}],\"layout\": {}}";
120
121 return stream.str();
122}
123
132template <TLAPACK_MATRIX matrix_t>
133std::string visualize_matrix(const matrix_t& A)
134{
135 using idx_t = size_type<matrix_t>;
136 const idx_t n = std::max(ncols(A), nrows(A));
137
138 if (n > 7)
139 return visualize_matrix_text(A);
140 else
142}
143
144} // namespace tlapack
145
146#endif // TLAPACK_DEBUG_UTILS_HH
std::string visualize_matrix_text(const matrix_t &A)
Constructs a json string representing the matrix for use with vscode-debug-visualizer.
Definition debugutils.hpp:51
std::string visualize_matrix_table(const matrix_t &A)
Constructs a json string representing the matrix for use with vscode-debug-visualizer.
Definition debugutils.hpp:89
void print_matrix(const matrix_t &A)
Prints a matrix a to std::out.
Definition debugutils.hpp:29
std::string visualize_matrix(const matrix_t &A)
Constructs a json string representing the matrix for use with vscode-debug-visualizer.
Definition debugutils.hpp:133
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113