fix formatting for (non-generated) internal source files

- Change formatting standard to Cpp11. Main difference is not having
  the space between two closing >> for nested templates. We don't
  choose c++14, because older versions of clang-format (version 9
  and earlier) don't know this value yet, and it doesn't make a
  difference in the formatting.
- Apply clang-format to all (non generated) internal source files.
- Manually fix some code sections (clang-format on/off) and c-strings
- Exclude some embedded external files with very different formatting
  (gtest/gmock)
- Add script to format all source files

Change-Id: Ic6cea41575ad6e37c9e136dbce176b0d505dc44d
This commit is contained in:
Nikolaus Demmel
2020-09-20 21:45:24 +02:00
parent 921368ce31
commit 7b8f675bfd
272 changed files with 3449 additions and 3319 deletions
+114 -120
View File
@@ -50,39 +50,36 @@ namespace internal {
TEST(NumericDiffCostFunction, EasyCaseFunctorCentralDifferences) {
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<EasyFunctor,
CENTRAL,
3, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new EasyFunctor));
cost_function.reset(new NumericDiffCostFunction<EasyFunctor,
CENTRAL,
3, // number of residuals
5, // size of x1
5 // size of x2
>(new EasyFunctor));
EasyFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, CENTRAL);
}
TEST(NumericDiffCostFunction, EasyCaseFunctorForwardDifferences) {
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<EasyFunctor,
FORWARD,
3, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new EasyFunctor));
cost_function.reset(new NumericDiffCostFunction<EasyFunctor,
FORWARD,
3, // number of residuals
5, // size of x1
5 // size of x2
>(new EasyFunctor));
EasyFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, FORWARD);
}
TEST(NumericDiffCostFunction, EasyCaseFunctorRidders) {
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<EasyFunctor,
RIDDERS,
3, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new EasyFunctor));
cost_function.reset(new NumericDiffCostFunction<EasyFunctor,
RIDDERS,
3, // number of residuals
5, // size of x1
5 // size of x2
>(new EasyFunctor));
EasyFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, RIDDERS);
}
@@ -92,10 +89,10 @@ TEST(NumericDiffCostFunction, EasyCaseCostFunctionCentralDifferences) {
cost_function.reset(
new NumericDiffCostFunction<EasyCostFunction,
CENTRAL,
3, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new EasyCostFunction, TAKE_OWNERSHIP));
3, // number of residuals
5, // size of x1
5 // size of x2
>(new EasyCostFunction, TAKE_OWNERSHIP));
EasyFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, CENTRAL);
}
@@ -105,10 +102,10 @@ TEST(NumericDiffCostFunction, EasyCaseCostFunctionForwardDifferences) {
cost_function.reset(
new NumericDiffCostFunction<EasyCostFunction,
FORWARD,
3, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new EasyCostFunction, TAKE_OWNERSHIP));
3, // number of residuals
5, // size of x1
5 // size of x2
>(new EasyCostFunction, TAKE_OWNERSHIP));
EasyFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, FORWARD);
}
@@ -118,44 +115,39 @@ TEST(NumericDiffCostFunction, EasyCaseCostFunctionRidders) {
cost_function.reset(
new NumericDiffCostFunction<EasyCostFunction,
RIDDERS,
3, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new EasyCostFunction, TAKE_OWNERSHIP));
3, // number of residuals
5, // size of x1
5 // size of x2
>(new EasyCostFunction, TAKE_OWNERSHIP));
EasyFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, RIDDERS);
}
TEST(NumericDiffCostFunction,
TranscendentalCaseFunctorCentralDifferences) {
TEST(NumericDiffCostFunction, TranscendentalCaseFunctorCentralDifferences) {
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<TranscendentalFunctor,
CENTRAL,
2, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new TranscendentalFunctor));
cost_function.reset(new NumericDiffCostFunction<TranscendentalFunctor,
CENTRAL,
2, // number of residuals
5, // size of x1
5 // size of x2
>(new TranscendentalFunctor));
TranscendentalFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, CENTRAL);
}
TEST(NumericDiffCostFunction,
TranscendentalCaseFunctorForwardDifferences) {
TEST(NumericDiffCostFunction, TranscendentalCaseFunctorForwardDifferences) {
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<TranscendentalFunctor,
FORWARD,
2, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new TranscendentalFunctor));
cost_function.reset(new NumericDiffCostFunction<TranscendentalFunctor,
FORWARD,
2, // number of residuals
5, // size of x1
5 // size of x2
>(new TranscendentalFunctor));
TranscendentalFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, FORWARD);
}
TEST(NumericDiffCostFunction,
TranscendentalCaseFunctorRidders) {
TEST(NumericDiffCostFunction, TranscendentalCaseFunctorRidders) {
NumericDiffOptions options;
// Using a smaller initial step size to overcome oscillatory function
@@ -163,13 +155,13 @@ TEST(NumericDiffCostFunction,
options.ridders_relative_initial_step_size = 1e-3;
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<TranscendentalFunctor,
RIDDERS,
2, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new TranscendentalFunctor, TAKE_OWNERSHIP, 2, options));
cost_function.reset(new NumericDiffCostFunction<TranscendentalFunctor,
RIDDERS,
2, // number of residuals
5, // size of x1
5 // size of x2
>(
new TranscendentalFunctor, TAKE_OWNERSHIP, 2, options));
TranscendentalFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, RIDDERS);
}
@@ -177,13 +169,13 @@ TEST(NumericDiffCostFunction,
TEST(NumericDiffCostFunction,
TranscendentalCaseCostFunctionCentralDifferences) {
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<TranscendentalCostFunction,
CENTRAL,
2, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new TranscendentalCostFunction, TAKE_OWNERSHIP));
cost_function.reset(new NumericDiffCostFunction<TranscendentalCostFunction,
CENTRAL,
2, // number of residuals
5, // size of x1
5 // size of x2
>(
new TranscendentalCostFunction, TAKE_OWNERSHIP));
TranscendentalFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, CENTRAL);
}
@@ -191,19 +183,18 @@ TEST(NumericDiffCostFunction,
TEST(NumericDiffCostFunction,
TranscendentalCaseCostFunctionForwardDifferences) {
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<TranscendentalCostFunction,
FORWARD,
2, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new TranscendentalCostFunction, TAKE_OWNERSHIP));
cost_function.reset(new NumericDiffCostFunction<TranscendentalCostFunction,
FORWARD,
2, // number of residuals
5, // size of x1
5 // size of x2
>(
new TranscendentalCostFunction, TAKE_OWNERSHIP));
TranscendentalFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, FORWARD);
}
TEST(NumericDiffCostFunction,
TranscendentalCaseCostFunctionRidders) {
TEST(NumericDiffCostFunction, TranscendentalCaseCostFunctionRidders) {
NumericDiffOptions options;
// Using a smaller initial step size to overcome oscillatory function
@@ -211,18 +202,18 @@ TEST(NumericDiffCostFunction,
options.ridders_relative_initial_step_size = 1e-3;
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<TranscendentalCostFunction,
RIDDERS,
2, /* number of residuals */
5, /* size of x1 */
5 /* size of x2 */>(
new TranscendentalCostFunction, TAKE_OWNERSHIP, 2, options));
cost_function.reset(new NumericDiffCostFunction<TranscendentalCostFunction,
RIDDERS,
2, // number of residuals
5, // size of x1
5 // size of x2
>(
new TranscendentalCostFunction, TAKE_OWNERSHIP, 2, options));
TranscendentalFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, RIDDERS);
}
template<int num_rows, int num_cols>
template <int num_rows, int num_cols>
class SizeTestingCostFunction : public SizedCostFunction<num_rows, num_cols> {
public:
bool Evaluate(double const* const* parameters,
@@ -241,20 +232,20 @@ class SizeTestingCostFunction : public SizedCostFunction<num_rows, num_cols> {
TEST(NumericDiffCostFunction, EigenRowMajorColMajorTest) {
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<SizeTestingCostFunction<1,1>, CENTRAL, 1, 1>(
new SizeTestingCostFunction<1,1>, ceres::TAKE_OWNERSHIP));
new NumericDiffCostFunction<SizeTestingCostFunction<1, 1>, CENTRAL, 1, 1>(
new SizeTestingCostFunction<1, 1>, ceres::TAKE_OWNERSHIP));
cost_function.reset(
new NumericDiffCostFunction<SizeTestingCostFunction<2,1>, CENTRAL, 2, 1>(
new SizeTestingCostFunction<2,1>, ceres::TAKE_OWNERSHIP));
new NumericDiffCostFunction<SizeTestingCostFunction<2, 1>, CENTRAL, 2, 1>(
new SizeTestingCostFunction<2, 1>, ceres::TAKE_OWNERSHIP));
cost_function.reset(
new NumericDiffCostFunction<SizeTestingCostFunction<1,2>, CENTRAL, 1, 2>(
new SizeTestingCostFunction<1,2>, ceres::TAKE_OWNERSHIP));
new NumericDiffCostFunction<SizeTestingCostFunction<1, 2>, CENTRAL, 1, 2>(
new SizeTestingCostFunction<1, 2>, ceres::TAKE_OWNERSHIP));
cost_function.reset(
new NumericDiffCostFunction<SizeTestingCostFunction<2,2>, CENTRAL, 2, 2>(
new SizeTestingCostFunction<2,2>, ceres::TAKE_OWNERSHIP));
new NumericDiffCostFunction<SizeTestingCostFunction<2, 2>, CENTRAL, 2, 2>(
new SizeTestingCostFunction<2, 2>, ceres::TAKE_OWNERSHIP));
cost_function.reset(
new NumericDiffCostFunction<EasyFunctor, CENTRAL, ceres::DYNAMIC, 1, 1>(
@@ -288,21 +279,20 @@ TEST(NumericDiffCostFunction,
new NumericDiffCostFunction<EasyFunctor,
CENTRAL,
ceres::DYNAMIC,
5, /* size of x1 */
5 /* size of x2 */>(
new EasyFunctor, TAKE_OWNERSHIP, 3));
5, // size of x1
5 // size of x2
>(new EasyFunctor, TAKE_OWNERSHIP, 3));
EasyFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function, CENTRAL);
}
TEST(NumericDiffCostFunction, ExponentialFunctorRidders) {
std::unique_ptr<CostFunction> cost_function;
cost_function.reset(
new NumericDiffCostFunction<ExponentialFunctor,
RIDDERS,
1, /* number of residuals */
1 /* size of x1 */>(
new ExponentialFunctor));
cost_function.reset(new NumericDiffCostFunction<ExponentialFunctor,
RIDDERS,
1, // number of residuals
1 // size of x1
>(new ExponentialFunctor));
ExponentialFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function);
}
@@ -312,9 +302,9 @@ TEST(NumericDiffCostFunction, ExponentialCostFunctionRidders) {
cost_function.reset(
new NumericDiffCostFunction<ExponentialCostFunction,
RIDDERS,
1, /* number of residuals */
1 /* size of x1 */>(
new ExponentialCostFunction));
1, // number of residuals
1 // size of x1
>(new ExponentialCostFunction));
ExponentialFunctor functor;
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function);
}
@@ -326,14 +316,16 @@ TEST(NumericDiffCostFunction, RandomizedFunctorRidders) {
// presence of random noise.
options.ridders_relative_initial_step_size = 10.0;
cost_function.reset(
new NumericDiffCostFunction<RandomizedFunctor,
RIDDERS,
1, /* number of residuals */
1 /* size of x1 */>(
new RandomizedFunctor(kNoiseFactor, kRandomSeed), TAKE_OWNERSHIP,
1, options));
RandomizedFunctor functor (kNoiseFactor, kRandomSeed);
cost_function.reset(new NumericDiffCostFunction<RandomizedFunctor,
RIDDERS,
1, // number of residuals
1 // size of x1
>(
new RandomizedFunctor(kNoiseFactor, kRandomSeed),
TAKE_OWNERSHIP,
1,
options));
RandomizedFunctor functor(kNoiseFactor, kRandomSeed);
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function);
}
@@ -344,14 +336,16 @@ TEST(NumericDiffCostFunction, RandomizedCostFunctionRidders) {
// presence of random noise.
options.ridders_relative_initial_step_size = 10.0;
cost_function.reset(
new NumericDiffCostFunction<RandomizedCostFunction,
RIDDERS,
1, /* number of residuals */
1 /* size of x1 */>(
new RandomizedCostFunction(kNoiseFactor, kRandomSeed),
TAKE_OWNERSHIP, 1, options));
RandomizedFunctor functor (kNoiseFactor, kRandomSeed);
cost_function.reset(new NumericDiffCostFunction<RandomizedCostFunction,
RIDDERS,
1, // number of residuals
1 // size of x1
>(
new RandomizedCostFunction(kNoiseFactor, kRandomSeed),
TAKE_OWNERSHIP,
1,
options));
RandomizedFunctor functor(kNoiseFactor, kRandomSeed);
functor.ExpectCostFunctionEvaluationIsNearlyCorrect(*cost_function);
}