mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 16:40:38 +08:00
Let NumericDiffFirstOrderFunction take a dynamically sized parameter vector
Also fix a template naming lint along the way. Change-Id: Iabb98aeec2ff9609a19c3778b9ea2da37771c985
This commit is contained in:
committed by
Sameer Agarwal
parent
6c27ac6d50
commit
4cd257cf4a
@@ -50,10 +50,34 @@ class QuadraticCostFunctor {
|
||||
double a_;
|
||||
};
|
||||
|
||||
TEST(NumericDiffFirstOrderFunction, BilinearDifferentiationTest) {
|
||||
std::unique_ptr<FirstOrderFunction> function(
|
||||
new NumericDiffFirstOrderFunction<QuadraticCostFunctor, CENTRAL, 4>(
|
||||
new QuadraticCostFunctor(1.0)));
|
||||
TEST(NumericDiffFirstOrderFunction, BilinearDifferentiationTestStatic) {
|
||||
auto function = std::make_unique<
|
||||
NumericDiffFirstOrderFunction<QuadraticCostFunctor, CENTRAL, 4>>(
|
||||
new QuadraticCostFunctor(1.0));
|
||||
|
||||
double parameters[4] = {1.0, 2.0, 3.0, 4.0};
|
||||
double gradient[4];
|
||||
double cost;
|
||||
|
||||
function->Evaluate(parameters, &cost, nullptr);
|
||||
EXPECT_EQ(cost, 13.0);
|
||||
|
||||
cost = -1.0;
|
||||
function->Evaluate(parameters, &cost, gradient);
|
||||
|
||||
EXPECT_EQ(cost, 13.0);
|
||||
|
||||
const double kTolerance = 1e-9;
|
||||
EXPECT_NEAR(gradient[0], parameters[1], kTolerance);
|
||||
EXPECT_NEAR(gradient[1], parameters[0], kTolerance);
|
||||
EXPECT_NEAR(gradient[2], parameters[3], kTolerance);
|
||||
EXPECT_NEAR(gradient[3], parameters[2], kTolerance);
|
||||
}
|
||||
|
||||
TEST(NumericDiffFirstOrderFunction, BilinearDifferentiationTestDynamic) {
|
||||
auto function = std::make_unique<
|
||||
NumericDiffFirstOrderFunction<QuadraticCostFunctor, CENTRAL>>(
|
||||
new QuadraticCostFunctor(1.0), 4);
|
||||
|
||||
double parameters[4] = {1.0, 2.0, 3.0, 4.0};
|
||||
double gradient[4];
|
||||
|
||||
Reference in New Issue
Block a user