Skip to content

Commit b7c6521

Browse files
authored
Add debug helper to matrix_with_ids (#272)
1 parent fb2a034 commit b7c6521

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/include/detail/linalg/matrix_with_ids.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,48 @@ using RowMajorMatrixWithIds = MatrixWithIds<T, IdsType, stdx::layout_right, I>;
167167
template <class T, class IdsType = uint64_t, class I = size_t>
168168
using ColMajorMatrixWithIds = MatrixWithIds<T, IdsType, stdx::layout_left, I>;
169169

170+
template <class MatrixWithIds>
171+
void debug_slice_with_ids(
172+
const MatrixWithIds& A,
173+
const std::string& msg = "",
174+
size_t rows = 6,
175+
size_t cols = 18) {
176+
auto max_size = 10;
177+
auto rowsEnd = std::min(dimension(A), static_cast<size_t>(max_size));
178+
auto colsEnd = std::min(num_vectors(A), static_cast<size_t>(max_size));
179+
180+
std::cout << "# " << msg << std::endl;
181+
for (size_t i = 0; i < rowsEnd; ++i) {
182+
std::cout << "# ";
183+
for (size_t j = 0; j < colsEnd; ++j) {
184+
std::cout << (float)A(i, j) << " ";
185+
}
186+
if (A.num_cols() > max_size) {
187+
std::cout << "...";
188+
}
189+
std::cout << std::endl;
190+
}
191+
if (A.num_rows() > max_size) {
192+
std::cout << "# ..." << std::endl;
193+
}
194+
195+
std::cout << "# ids: [";
196+
auto end = std::min(A.num_ids(), static_cast<size_t>(max_size));
197+
for (size_t i = 0; i < end; ++i) {
198+
std::cout << (float)A.ids()[i];
199+
if (i != A.num_ids() - 1) {
200+
std::cout << ", ";
201+
}
202+
}
203+
if (A.num_ids() > max_size) {
204+
std::cout << "...";
205+
}
206+
std::cout << "]" << std::endl;
207+
}
208+
209+
template <class MatrixWithIds>
210+
void debug_with_ids(const MatrixWithIds& A, const std::string& msg = "") {
211+
debug_slice_with_ids(A, msg, A.num_rows(), A.num_cols());
212+
}
213+
170214
#endif // TILEDB_MATRIX_WITH_IDS_H

0 commit comments

Comments
 (0)