Move AsVector utility to fixture.h
PiperOrigin-RevId: 690577546 Change-Id: I2cebcffa1f2e3b0789f43e772e364c4762719ab3
This commit is contained in:
committed by
Copybara-Service
parent
d95befaddd
commit
a4a6248a06
@@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
// A benchmark for comparing different implementations of mj_solveLD.
|
// A benchmark for comparing different implementations of mj_solveLD.
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <benchmark/benchmark.h>
|
#include <benchmark/benchmark.h>
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include <absl/base/attributes.h>
|
#include <absl/base/attributes.h>
|
||||||
#include <mujoco/mjdata.h>
|
#include <mujoco/mjdata.h>
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
@@ -30,11 +30,6 @@ static const int kNumWarmupSteps = 200;
|
|||||||
// number of steps to benchmark
|
// number of steps to benchmark
|
||||||
static const int kNumBenchmarkSteps = 50;
|
static const int kNumBenchmarkSteps = 50;
|
||||||
|
|
||||||
// copy array into vector
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------- old functions --------------------------------
|
// ----------------------------- old functions --------------------------------
|
||||||
|
|
||||||
void ABSL_ATTRIBUTE_NOINLINE solveLD_baseline(const mjModel* m, mjtNum* x,
|
void ABSL_ATTRIBUTE_NOINLINE solveLD_baseline(const mjModel* m, mjtNum* x,
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <benchmark/benchmark.h>
|
#include <benchmark/benchmark.h>
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include <absl/base/attributes.h>
|
#include <absl/base/attributes.h>
|
||||||
#include <mujoco/mjdata.h>
|
#include <mujoco/mjdata.h>
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
@@ -37,11 +36,6 @@ using SqrMatTDFuncPtr = decltype(&mju_sqrMatTDSparse);
|
|||||||
// number of steps to roll out before benchmarking
|
// number of steps to roll out before benchmarking
|
||||||
static const int kNumWarmupSteps = 500;
|
static const int kNumWarmupSteps = 500;
|
||||||
|
|
||||||
// copy array into vector
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------- old functions --------------------------------
|
// ----------------------------- old functions --------------------------------
|
||||||
|
|
||||||
void ABSL_ATTRIBUTE_NOINLINE mju_sqrMatTDSparse_baseline(
|
void ABSL_ATTRIBUTE_NOINLINE mju_sqrMatTDSparse_baseline(
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
@@ -34,10 +33,6 @@ using ::testing::DoubleNear;
|
|||||||
using ::testing::Pointwise;
|
using ::testing::Pointwise;
|
||||||
using CoreConstraintTest = MujocoTest;
|
using CoreConstraintTest = MujocoTest;
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// compute rotation residual following formula in mj_instantiateEquality
|
// compute rotation residual following formula in mj_instantiateEquality
|
||||||
void RotationResidual(const mjModel *model, mjData *data,
|
void RotationResidual(const mjModel *model, mjData *data,
|
||||||
const mjtNum qpos[7], const mjtNum dqpos[6],
|
const mjtNum qpos[7], const mjtNum dqpos[6],
|
||||||
|
|||||||
@@ -86,11 +86,6 @@ static void PrintMatrix(mjtNum* mat, int nrow, int ncol) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + 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 =
|
||||||
|
|||||||
@@ -40,10 +40,6 @@
|
|||||||
namespace mujoco {
|
namespace mujoco {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + 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 kDampedActuatorsPath =
|
static const char* const kDampedActuatorsPath =
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
// Tests for engine/engine_solver.c
|
// Tests for engine/engine_solver.c
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
@@ -25,10 +24,6 @@
|
|||||||
namespace mujoco {
|
namespace mujoco {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
using ::testing::DoubleNear;
|
using ::testing::DoubleNear;
|
||||||
using ::testing::NotNull;
|
using ::testing::NotNull;
|
||||||
using ::testing::Pointwise;
|
using ::testing::Pointwise;
|
||||||
|
|||||||
@@ -37,10 +37,6 @@ using ::testing::Pointwise;
|
|||||||
using ::testing::ElementsAreArray;
|
using ::testing::ElementsAreArray;
|
||||||
using ::testing::Pointwise;
|
using ::testing::Pointwise;
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
using AngMomMatTest = MujocoTest;
|
using AngMomMatTest = MujocoTest;
|
||||||
|
|
||||||
static constexpr char AngMomTestingModel[] = R"(
|
static constexpr char AngMomTestingModel[] = R"(
|
||||||
|
|||||||
@@ -36,10 +36,6 @@ using ::std::string;
|
|||||||
using ::std::setw;
|
using ::std::setw;
|
||||||
using QCQP2Test = MujocoTest;
|
using QCQP2Test = MujocoTest;
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(QCQP2Test, DegenerateAMatrix) {
|
TEST_F(QCQP2Test, DegenerateAMatrix) {
|
||||||
// A 2x2 matrix with determinant zero.
|
// A 2x2 matrix with determinant zero.
|
||||||
const mjtNum Ain[9] { 6, -15, 2, -5 };
|
const mjtNum Ain[9] { 6, -15, 2, -5 };
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
// Tests for engine/engine_util_spatial.c
|
// Tests for engine/engine_util_spatial.c
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
@@ -36,10 +35,6 @@ using ::testing::Pointwise;
|
|||||||
|
|
||||||
using Quat2MatTest = MujocoTest;
|
using Quat2MatTest = MujocoTest;
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(Quat2MatTest, NoRotation) {
|
TEST_F(Quat2MatTest, NoRotation) {
|
||||||
mjtNum result[9] = {0};
|
mjtNum result[9] = {0};
|
||||||
mjtNum quat[] = {1, 0, 0, 0};
|
mjtNum quat[] = {1, 0, 0, 0};
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ std::vector<mjtNum> GetCtrlNoise(const mjModel* m, int nsteps,
|
|||||||
// Returns the name of the different field and the max difference.
|
// Returns the name of the different field and the max difference.
|
||||||
mjtNum CompareModel(const mjModel* m1, const mjModel* m2, std::string& field);
|
mjtNum CompareModel(const mjModel* m1, const mjModel* m2, std::string& field);
|
||||||
|
|
||||||
|
// Returns a vector containing the elements of the array.
|
||||||
|
inline std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
||||||
|
return std::vector<mjtNum>(array, array + 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.
|
||||||
|
|||||||
@@ -27,10 +27,6 @@
|
|||||||
namespace mujoco {
|
namespace mujoco {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* const kDefaultModel = "testdata/model.xml";
|
static const char* const kDefaultModel = "testdata/model.xml";
|
||||||
|
|
||||||
using ::testing::Pointwise;
|
using ::testing::Pointwise;
|
||||||
|
|||||||
@@ -67,10 +67,6 @@ static const char* const kDuplicateOBJPath =
|
|||||||
static const char* const kMalformedFaceOBJPath =
|
static const char* const kMalformedFaceOBJPath =
|
||||||
"user/testdata/malformed_face.xml";
|
"user/testdata/malformed_face.xml";
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
using ::testing::ElementsAre;
|
using ::testing::ElementsAre;
|
||||||
using ::testing::HasSubstr;
|
using ::testing::HasSubstr;
|
||||||
using ::testing::IsNull;
|
using ::testing::IsNull;
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
#include <absl/strings/str_format.h>
|
#include <absl/strings/str_format.h>
|
||||||
#include <mujoco/mjmodel.h>
|
#include <mujoco/mjmodel.h>
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
#include "src/cc/array_safety.h"
|
|
||||||
#include "test/fixture.h"
|
#include "test/fixture.h"
|
||||||
|
|
||||||
namespace mujoco {
|
namespace mujoco {
|
||||||
@@ -44,10 +43,6 @@ static std::vector<mjtNum> GetRow(const mjtNum* array, int ncolumn, int row) {
|
|||||||
array + ncolumn * (row + 1));
|
array + ncolumn * (row + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------- test mjCModel --------------------------------
|
// ----------------------------- test mjCModel --------------------------------
|
||||||
|
|
||||||
using UserCModelTest = MujocoTest;
|
using UserCModelTest = MujocoTest;
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
@@ -34,10 +33,6 @@ namespace {
|
|||||||
|
|
||||||
constexpr double kInertiaTol = 1e-6;
|
constexpr double kInertiaTol = 1e-6;
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using ::testing::DoubleNear;
|
using ::testing::DoubleNear;
|
||||||
using ::testing::ElementsAre;
|
using ::testing::ElementsAre;
|
||||||
@@ -2402,7 +2397,8 @@ TEST_F(UserObjectsTest, BadWeld) {
|
|||||||
int len = 4;
|
int len = 4;
|
||||||
|
|
||||||
// good model using body semantic
|
// good model using body semantic
|
||||||
string xml = base.replace(pos, len, "<weld body1='1' anchor='0 0 1' torquescale='2'/>");
|
string xml = base.replace(pos, len,
|
||||||
|
"<weld body1='1' anchor='0 0 1' torquescale='2'/>");
|
||||||
char error[1024];
|
char error[1024];
|
||||||
mjModel* m = LoadModelFromString(xml.c_str(), error, sizeof(error));
|
mjModel* m = LoadModelFromString(xml.c_str(), error, sizeof(error));
|
||||||
ASSERT_THAT(m, NotNull()) << error;
|
ASSERT_THAT(m, NotNull()) << error;
|
||||||
|
|||||||
@@ -33,10 +33,6 @@
|
|||||||
namespace mujoco {
|
namespace mujoco {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
|
|
||||||
return std::vector<mjtNum>(array, array + n);
|
|
||||||
}
|
|
||||||
|
|
||||||
using ::std::string;
|
using ::std::string;
|
||||||
using ::testing::AllOf;
|
using ::testing::AllOf;
|
||||||
using ::testing::ElementsAre;
|
using ::testing::ElementsAre;
|
||||||
|
|||||||
Reference in New Issue
Block a user