Add debugging method for printing matrices to stderr to fixture.h

PiperOrigin-RevId: 702301299
Change-Id: I01738b6634a91cde6b146475d06731471dcf3764
This commit is contained in:
Yuval Tassa
2024-12-03 05:19:02 -08:00
committed by Copybara-Service
parent a793a3417a
commit 13d3bdedad
2 changed files with 14 additions and 15 deletions
-15
View File
@@ -14,8 +14,6 @@
// Tests for engine/engine_derivative.c.
#include <iomanip>
#include <iostream>
#include <random>
#include <string>
#include <vector>
@@ -74,19 +72,6 @@ static mjtNum CompareMatrices(mjtNum* Actual, mjtNum* Expected,
return max_error;
}
// utility function for matrix printing (debug)
// NOLINTNEXTLINE(clang-diagnostic-unused-function)
static void PrintMatrix(mjtNum* mat, int nrow, int ncol) {
std::cerr.precision(5);
std::cerr << "\n";
for (int r=0; r < nrow; r++) {
for (int c=0; c < ncol; c++) {
std::cerr << std::fixed << std::setw(9) << mat[c + r*ncol] << " ";
}
std::cerr << "\n";
}
}
static const char* const kEnergyConservingPendulumPath =
"engine/testdata/derivative/energy_conserving_pendulum.xml";
static const char* const kTumblingThinObjectPath =
+14
View File
@@ -17,6 +17,8 @@
#include <csetjmp>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <string_view>
#include <vector>
@@ -110,6 +112,18 @@ inline std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
return std::vector<mjtNum>(array, array + n);
}
// Prints a matrix to stderr, useful for debugging.
inline void PrintMatrix(const mjtNum* mat, int nrow, int ncol, int p = 5) {
std::cerr.precision(p);
std::cerr << "\n";
for (int r = 0; r < nrow; r++) {
for (int c = 0; c < ncol; c++) {
std::cerr << std::fixed << std::setw(4 + p) << mat[c + r*ncol] << " ";
}
std::cerr << "\n";
}
}
// Installs a mock filesystem via a resource provider. To obtain thread safety,
// each filesystem is scoped for individual unit tests with destructive
// operations not permitted.