Add debugging method for printing matrices to stderr to fixture.h
PiperOrigin-RevId: 702301299 Change-Id: I01738b6634a91cde6b146475d06731471dcf3764
This commit is contained in:
committed by
Copybara-Service
parent
a793a3417a
commit
13d3bdedad
@@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
// Tests for engine/engine_derivative.c.
|
// Tests for engine/engine_derivative.c.
|
||||||
|
|
||||||
#include <iomanip>
|
|
||||||
#include <iostream>
|
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -74,19 +72,6 @@ static mjtNum CompareMatrices(mjtNum* Actual, mjtNum* Expected,
|
|||||||
return max_error;
|
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 =
|
static const char* const kEnergyConservingPendulumPath =
|
||||||
"engine/testdata/derivative/energy_conserving_pendulum.xml";
|
"engine/testdata/derivative/energy_conserving_pendulum.xml";
|
||||||
static const char* const kTumblingThinObjectPath =
|
static const char* const kTumblingThinObjectPath =
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include <csetjmp>
|
#include <csetjmp>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -110,6 +112,18 @@ inline std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|||||||
return std::vector<mjtNum>(array, array + 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,
|
// Installs a mock filesystem via a resource provider. To obtain thread safety,
|
||||||
// each filesystem is scoped for individual unit tests with destructive
|
// each filesystem is scoped for individual unit tests with destructive
|
||||||
// operations not permitted.
|
// operations not permitted.
|
||||||
|
|||||||
Reference in New Issue
Block a user