|
Packit |
ea1746 |
// Ceres Solver - A fast non-linear least squares minimizer
|
|
Packit |
ea1746 |
// Copyright 2015 Google Inc. All rights reserved.
|
|
Packit |
ea1746 |
// http://ceres-solver.org/
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// Redistribution and use in source and binary forms, with or without
|
|
Packit |
ea1746 |
// modification, are permitted provided that the following conditions are met:
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// * Redistributions of source code must retain the above copyright notice,
|
|
Packit |
ea1746 |
// this list of conditions and the following disclaimer.
|
|
Packit |
ea1746 |
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
ea1746 |
// this list of conditions and the following disclaimer in the documentation
|
|
Packit |
ea1746 |
// and/or other materials provided with the distribution.
|
|
Packit |
ea1746 |
// * Neither the name of Google Inc. nor the names of its contributors may be
|
|
Packit |
ea1746 |
// used to endorse or promote products derived from this software without
|
|
Packit |
ea1746 |
// specific prior written permission.
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
ea1746 |
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
ea1746 |
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
ea1746 |
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
ea1746 |
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
ea1746 |
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
ea1746 |
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
ea1746 |
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
ea1746 |
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
ea1746 |
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
ea1746 |
// POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
ea1746 |
//
|
|
Packit |
ea1746 |
// Author: sameeragarwal@google.com (Sameer Agarwal)
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#include "ceres/cost_function_to_functor.h"
|
|
Packit |
ea1746 |
#include "ceres/dynamic_autodiff_cost_function.h"
|
|
Packit |
ea1746 |
#include "ceres/dynamic_cost_function_to_functor.h"
|
|
Packit |
ea1746 |
#include "ceres/autodiff_cost_function.h"
|
|
Packit |
ea1746 |
#include "gtest/gtest.h"
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
namespace ceres {
|
|
Packit |
ea1746 |
namespace internal {
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
using std::vector;
|
|
Packit |
ea1746 |
const double kTolerance = 1e-18;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
void ExpectCostFunctionsAreEqual(const CostFunction& cost_function,
|
|
Packit |
ea1746 |
const CostFunction& actual_cost_function) {
|
|
Packit |
ea1746 |
EXPECT_EQ(cost_function.num_residuals(),
|
|
Packit |
ea1746 |
actual_cost_function.num_residuals());
|
|
Packit |
ea1746 |
const int num_residuals = cost_function.num_residuals();
|
|
Packit |
ea1746 |
const vector<int32>& parameter_block_sizes =
|
|
Packit |
ea1746 |
cost_function.parameter_block_sizes();
|
|
Packit |
ea1746 |
const vector<int32>& actual_parameter_block_sizes =
|
|
Packit |
ea1746 |
actual_cost_function.parameter_block_sizes();
|
|
Packit |
ea1746 |
EXPECT_EQ(parameter_block_sizes.size(),
|
|
Packit |
ea1746 |
actual_parameter_block_sizes.size());
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
int num_parameters = 0;
|
|
Packit |
ea1746 |
for (int i = 0; i < parameter_block_sizes.size(); ++i) {
|
|
Packit |
ea1746 |
EXPECT_EQ(parameter_block_sizes[i], actual_parameter_block_sizes[i]);
|
|
Packit |
ea1746 |
num_parameters += parameter_block_sizes[i];
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
scoped_array<double> parameters(new double[num_parameters]);
|
|
Packit |
ea1746 |
for (int i = 0; i < num_parameters; ++i) {
|
|
Packit |
ea1746 |
parameters[i] = static_cast<double>(i) + 1.0;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
scoped_array<double> residuals(new double[num_residuals]);
|
|
Packit |
ea1746 |
scoped_array<double> jacobians(new double[num_parameters * num_residuals]);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
scoped_array<double> actual_residuals(new double[num_residuals]);
|
|
Packit |
ea1746 |
scoped_array<double> actual_jacobians
|
|
Packit |
ea1746 |
(new double[num_parameters * num_residuals]);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
scoped_array<double*> parameter_blocks(
|
|
Packit |
ea1746 |
new double*[parameter_block_sizes.size()]);
|
|
Packit |
ea1746 |
scoped_array<double*> jacobian_blocks(
|
|
Packit |
ea1746 |
new double*[parameter_block_sizes.size()]);
|
|
Packit |
ea1746 |
scoped_array<double*> actual_jacobian_blocks(
|
|
Packit |
ea1746 |
new double*[parameter_block_sizes.size()]);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
num_parameters = 0;
|
|
Packit |
ea1746 |
for (int i = 0; i < parameter_block_sizes.size(); ++i) {
|
|
Packit |
ea1746 |
parameter_blocks[i] = parameters.get() + num_parameters;
|
|
Packit |
ea1746 |
jacobian_blocks[i] = jacobians.get() + num_parameters * num_residuals;
|
|
Packit |
ea1746 |
actual_jacobian_blocks[i] =
|
|
Packit |
ea1746 |
actual_jacobians.get() + num_parameters * num_residuals;
|
|
Packit |
ea1746 |
num_parameters += parameter_block_sizes[i];
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
EXPECT_TRUE(cost_function.Evaluate(parameter_blocks.get(),
|
|
Packit |
ea1746 |
residuals.get(), NULL));
|
|
Packit |
ea1746 |
EXPECT_TRUE(actual_cost_function.Evaluate(parameter_blocks.get(),
|
|
Packit |
ea1746 |
actual_residuals.get(), NULL));
|
|
Packit |
ea1746 |
for (int i = 0; i < num_residuals; ++i) {
|
|
Packit |
ea1746 |
EXPECT_NEAR(residuals[i], actual_residuals[i], kTolerance)
|
|
Packit |
ea1746 |
<< "residual id: " << i;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
EXPECT_TRUE(cost_function.Evaluate(parameter_blocks.get(),
|
|
Packit |
ea1746 |
residuals.get(),
|
|
Packit |
ea1746 |
jacobian_blocks.get()));
|
|
Packit |
ea1746 |
EXPECT_TRUE(actual_cost_function.Evaluate(parameter_blocks.get(),
|
|
Packit |
ea1746 |
actual_residuals.get(),
|
|
Packit |
ea1746 |
actual_jacobian_blocks.get()));
|
|
Packit |
ea1746 |
for (int i = 0; i < num_residuals; ++i) {
|
|
Packit |
ea1746 |
EXPECT_NEAR(residuals[i], actual_residuals[i], kTolerance)
|
|
Packit |
ea1746 |
<< "residual : " << i;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
for (int i = 0; i < num_residuals * num_parameters; ++i) {
|
|
Packit |
ea1746 |
EXPECT_NEAR(jacobians[i], actual_jacobians[i], kTolerance)
|
|
Packit |
ea1746 |
<< "jacobian : " << i << " "
|
|
Packit |
ea1746 |
<< jacobians[i] << " " << actual_jacobians[i];
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct OneParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(const T* x1, T* residuals) const {
|
|
Packit |
ea1746 |
residuals[0] = x1[0] * x1[0];
|
|
Packit |
ea1746 |
residuals[1] = x1[1] * x1[1];
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct TwoParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(const T* x1, const T* x2, T* residuals) const {
|
|
Packit |
ea1746 |
residuals[0] = x1[0] * x1[0] + x2[0] * x2[0];
|
|
Packit |
ea1746 |
residuals[1] = x1[1] * x1[1] + x2[1] * x2[1];
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct ThreeParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(const T* x1, const T* x2, const T* x3, T* residuals) const {
|
|
Packit |
ea1746 |
residuals[0] = x1[0] * x1[0] + x2[0] * x2[0] + x3[0] * x3[0];
|
|
Packit |
ea1746 |
residuals[1] = x1[1] * x1[1] + x2[1] * x2[1] + x3[1] * x3[1];
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct FourParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(const T* x1, const T* x2, const T* x3, const T* x4,
|
|
Packit |
ea1746 |
T* residuals) const {
|
|
Packit |
ea1746 |
residuals[0] = x1[0] * x1[0] + x2[0] * x2[0] + x3[0] * x3[0]
|
|
Packit |
ea1746 |
+ x4[0] * x4[0];
|
|
Packit |
ea1746 |
residuals[1] = x1[1] * x1[1] + x2[1] * x2[1] + x3[1] * x3[1]
|
|
Packit |
ea1746 |
+ x4[1] * x4[1];
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct FiveParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(const T* x1, const T* x2, const T* x3, const T* x4,
|
|
Packit |
ea1746 |
const T* x5, T* residuals) const {
|
|
Packit |
ea1746 |
residuals[0] = x1[0] * x1[0] + x2[0] * x2[0] + x3[0] * x3[0]
|
|
Packit |
ea1746 |
+ x4[0] * x4[0] + x5[0] * x5[0];
|
|
Packit |
ea1746 |
residuals[1] = x1[1] * x1[1] + x2[1] * x2[1] + x3[1] * x3[1]
|
|
Packit |
ea1746 |
+ x4[1] * x4[1] + x5[1] * x5[1];
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct SixParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(const T* x1, const T* x2, const T* x3, const T* x4,
|
|
Packit |
ea1746 |
const T* x5, const T* x6, T* residuals) const {
|
|
Packit |
ea1746 |
residuals[0] = x1[0] * x1[0] + x2[0] * x2[0] + x3[0] * x3[0]
|
|
Packit |
ea1746 |
+ x4[0] * x4[0] + x5[0] * x5[0] + x6[0] * x6[0];
|
|
Packit |
ea1746 |
residuals[1] = x1[1] * x1[1] + x2[1] * x2[1] + x3[1] * x3[1]
|
|
Packit |
ea1746 |
+ x4[1] * x4[1] + x5[1] * x5[1] + x6[1] * x6[1];
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct SevenParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(const T* x1, const T* x2, const T* x3, const T* x4,
|
|
Packit |
ea1746 |
const T* x5, const T* x6, const T* x7, T* residuals) const {
|
|
Packit |
ea1746 |
residuals[0] = x1[0] * x1[0] + x2[0] * x2[0] + x3[0] * x3[0]
|
|
Packit |
ea1746 |
+ x4[0] * x4[0] + x5[0] * x5[0] + x6[0] * x6[0] + x7[0] * x7[0];
|
|
Packit |
ea1746 |
residuals[1] = x1[1] * x1[1] + x2[1] * x2[1] + x3[1] * x3[1]
|
|
Packit |
ea1746 |
+ x4[1] * x4[1] + x5[1] * x5[1] + x6[1] * x6[1] + x7[1] * x7[1];
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct EightParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(const T* x1, const T* x2, const T* x3, const T* x4,
|
|
Packit |
ea1746 |
const T* x5, const T* x6, const T* x7, const T* x8,
|
|
Packit |
ea1746 |
T* residuals) const {
|
|
Packit |
ea1746 |
residuals[0] = x1[0] * x1[0] + x2[0] * x2[0] + x3[0] * x3[0]
|
|
Packit |
ea1746 |
+ x4[0] * x4[0] + x5[0] * x5[0] + x6[0] * x6[0] + x7[0] * x7[0]
|
|
Packit |
ea1746 |
+ x8[0] * x8[0];
|
|
Packit |
ea1746 |
residuals[1] = x1[1] * x1[1] + x2[1] * x2[1] + x3[1] * x3[1]
|
|
Packit |
ea1746 |
+ x4[1] * x4[1] + x5[1] * x5[1] + x6[1] * x6[1] + x7[1] * x7[1]
|
|
Packit |
ea1746 |
+ x8[1] * x8[1];
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct NineParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(const T* x1, const T* x2, const T* x3, const T* x4,
|
|
Packit |
ea1746 |
const T* x5, const T* x6, const T* x7, const T* x8,
|
|
Packit |
ea1746 |
const T* x9, T* residuals) const {
|
|
Packit |
ea1746 |
residuals[0] = x1[0] * x1[0] + x2[0] * x2[0] + x3[0] * x3[0]
|
|
Packit |
ea1746 |
+ x4[0] * x4[0] + x5[0] * x5[0] + x6[0] * x6[0] + x7[0] * x7[0]
|
|
Packit |
ea1746 |
+ x8[0] * x8[0] + x9[0] * x9[0];
|
|
Packit |
ea1746 |
residuals[1] = x1[1] * x1[1] + x2[1] * x2[1] + x3[1] * x3[1]
|
|
Packit |
ea1746 |
+ x4[1] * x4[1] + x5[1] * x5[1] + x6[1] * x6[1] + x7[1] * x7[1]
|
|
Packit |
ea1746 |
+ x8[1] * x8[1] + x9[1] * x9[1];
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
struct TenParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(const T* x1, const T* x2, const T* x3, const T* x4,
|
|
Packit |
ea1746 |
const T* x5, const T* x6, const T* x7, const T* x8,
|
|
Packit |
ea1746 |
const T* x9, const T* x10, T* residuals) const {
|
|
Packit |
ea1746 |
residuals[0] = x1[0] * x1[0] + x2[0] * x2[0] + x3[0] * x3[0]
|
|
Packit |
ea1746 |
+ x4[0] * x4[0] + x5[0] * x5[0] + x6[0] * x6[0] + x7[0] * x7[0]
|
|
Packit |
ea1746 |
+ x8[0] * x8[0] + x9[0] * x9[0] + x10[0] * x10[0];
|
|
Packit |
ea1746 |
residuals[1] = x1[1] * x1[1] + x2[1] * x2[1] + x3[1] * x3[1]
|
|
Packit |
ea1746 |
+ x4[1] * x4[1] + x5[1] * x5[1] + x6[1] * x6[1] + x7[1] * x7[1]
|
|
Packit |
ea1746 |
+ x8[1] * x8[1] + x9[1] * x9[1] + x10[1] * x10[1];
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
class DynamicTwoParameterBlockFunctor {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
template <typename T>
|
|
Packit |
ea1746 |
bool operator()(T const* const* parameters, T* residuals) const {
|
|
Packit |
ea1746 |
for (int i = 0; i < 2; ++i) {
|
|
Packit |
ea1746 |
residuals[0] = parameters[i][0] * parameters[i][0];
|
|
Packit |
ea1746 |
residuals[1] = parameters[i][1] * parameters[i][1];
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define TEST_BODY(NAME) \
|
|
Packit |
ea1746 |
TEST(CostFunctionToFunctor, NAME) { \
|
|
Packit |
ea1746 |
scoped_ptr<CostFunction> cost_function( \
|
|
Packit |
ea1746 |
new AutoDiffCostFunction< \
|
|
Packit |
ea1746 |
CostFunctionToFunctor<2, PARAMETER_BLOCK_SIZES >, \
|
|
Packit |
ea1746 |
2, PARAMETER_BLOCK_SIZES>(new CostFunctionToFunctor< \
|
|
Packit |
ea1746 |
2, PARAMETER_BLOCK_SIZES >( \
|
|
Packit |
ea1746 |
new AutoDiffCostFunction< \
|
|
Packit |
ea1746 |
NAME##Functor, 2, PARAMETER_BLOCK_SIZES >( \
|
|
Packit |
ea1746 |
new NAME##Functor)))); \
|
|
Packit |
ea1746 |
\
|
|
Packit |
ea1746 |
scoped_ptr<CostFunction> actual_cost_function( \
|
|
Packit |
ea1746 |
new AutoDiffCostFunction<NAME##Functor, 2, PARAMETER_BLOCK_SIZES >( \
|
|
Packit |
ea1746 |
new NAME##Functor)); \
|
|
Packit |
ea1746 |
ExpectCostFunctionsAreEqual(*cost_function, *actual_cost_function); \
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define PARAMETER_BLOCK_SIZES 2
|
|
Packit |
ea1746 |
TEST_BODY(OneParameterBlock)
|
|
Packit |
ea1746 |
#undef PARAMETER_BLOCK_SIZES
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define PARAMETER_BLOCK_SIZES 2,2
|
|
Packit |
ea1746 |
TEST_BODY(TwoParameterBlock)
|
|
Packit |
ea1746 |
#undef PARAMETER_BLOCK_SIZES
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define PARAMETER_BLOCK_SIZES 2,2,2
|
|
Packit |
ea1746 |
TEST_BODY(ThreeParameterBlock)
|
|
Packit |
ea1746 |
#undef PARAMETER_BLOCK_SIZES
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define PARAMETER_BLOCK_SIZES 2,2,2,2
|
|
Packit |
ea1746 |
TEST_BODY(FourParameterBlock)
|
|
Packit |
ea1746 |
#undef PARAMETER_BLOCK_SIZES
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define PARAMETER_BLOCK_SIZES 2,2,2,2,2
|
|
Packit |
ea1746 |
TEST_BODY(FiveParameterBlock)
|
|
Packit |
ea1746 |
#undef PARAMETER_BLOCK_SIZES
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define PARAMETER_BLOCK_SIZES 2,2,2,2,2,2
|
|
Packit |
ea1746 |
TEST_BODY(SixParameterBlock)
|
|
Packit |
ea1746 |
#undef PARAMETER_BLOCK_SIZES
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define PARAMETER_BLOCK_SIZES 2,2,2,2,2,2,2
|
|
Packit |
ea1746 |
TEST_BODY(SevenParameterBlock)
|
|
Packit |
ea1746 |
#undef PARAMETER_BLOCK_SIZES
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define PARAMETER_BLOCK_SIZES 2,2,2,2,2,2,2,2
|
|
Packit |
ea1746 |
TEST_BODY(EightParameterBlock)
|
|
Packit |
ea1746 |
#undef PARAMETER_BLOCK_SIZES
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define PARAMETER_BLOCK_SIZES 2,2,2,2,2,2,2,2,2
|
|
Packit |
ea1746 |
TEST_BODY(NineParameterBlock)
|
|
Packit |
ea1746 |
#undef PARAMETER_BLOCK_SIZES
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#define PARAMETER_BLOCK_SIZES 2,2,2,2,2,2,2,2,2,2
|
|
Packit |
ea1746 |
TEST_BODY(TenParameterBlock)
|
|
Packit |
ea1746 |
#undef PARAMETER_BLOCK_SIZES
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#undef TEST_BODY
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST(CostFunctionToFunctor, DynamicNumberOfResiduals) {
|
|
Packit |
ea1746 |
scoped_ptr<CostFunction> cost_function(
|
|
Packit |
ea1746 |
new AutoDiffCostFunction<
|
|
Packit |
ea1746 |
CostFunctionToFunctor<ceres::DYNAMIC, 2, 2 >, ceres::DYNAMIC, 2, 2>(
|
|
Packit |
ea1746 |
new CostFunctionToFunctor<ceres::DYNAMIC, 2, 2 >(
|
|
Packit |
ea1746 |
new AutoDiffCostFunction<TwoParameterBlockFunctor, 2, 2, 2 >(
|
|
Packit |
ea1746 |
new TwoParameterBlockFunctor)), 2));
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
scoped_ptr<CostFunction> actual_cost_function(
|
|
Packit |
ea1746 |
new AutoDiffCostFunction<TwoParameterBlockFunctor, 2, 2, 2 >(
|
|
Packit |
ea1746 |
new TwoParameterBlockFunctor));
|
|
Packit |
ea1746 |
ExpectCostFunctionsAreEqual(*cost_function, *actual_cost_function);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST(CostFunctionToFunctor, DynamicCostFunctionToFunctor) {
|
|
Packit |
ea1746 |
DynamicAutoDiffCostFunction<DynamicTwoParameterBlockFunctor>*
|
|
Packit |
ea1746 |
actual_cost_function(
|
|
Packit |
ea1746 |
new DynamicAutoDiffCostFunction<DynamicTwoParameterBlockFunctor>(
|
|
Packit |
ea1746 |
new DynamicTwoParameterBlockFunctor));
|
|
Packit |
ea1746 |
actual_cost_function->AddParameterBlock(2);
|
|
Packit |
ea1746 |
actual_cost_function->AddParameterBlock(2);
|
|
Packit |
ea1746 |
actual_cost_function->SetNumResiduals(2);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
DynamicAutoDiffCostFunction<DynamicCostFunctionToFunctor> cost_function(
|
|
Packit |
ea1746 |
new DynamicCostFunctionToFunctor(actual_cost_function));
|
|
Packit |
ea1746 |
cost_function.AddParameterBlock(2);
|
|
Packit |
ea1746 |
cost_function.AddParameterBlock(2);
|
|
Packit |
ea1746 |
cost_function.SetNumResiduals(2);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
ExpectCostFunctionsAreEqual(cost_function, *actual_cost_function);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
} // namespace internal
|
|
Packit |
ea1746 |
} // namespace ceres
|