|
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 <map>
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#include "ceres/ordered_groups.h"
|
|
Packit |
ea1746 |
#include "ceres/problem_impl.h"
|
|
Packit |
ea1746 |
#include "ceres/sized_cost_function.h"
|
|
Packit |
ea1746 |
#include "ceres/solver.h"
|
|
Packit |
ea1746 |
#include "ceres/trust_region_preprocessor.h"
|
|
Packit |
ea1746 |
#include "gtest/gtest.h"
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
namespace ceres {
|
|
Packit |
ea1746 |
namespace internal {
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST(TrustRegionPreprocessor, ZeroProblem) {
|
|
Packit |
ea1746 |
ProblemImpl problem;
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_TRUE(preprocessor.Preprocess(options, &problem, &pp));
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST(TrustRegionPreprocessor, ProblemWithInvalidParameterBlock) {
|
|
Packit |
ea1746 |
ProblemImpl problem;
|
|
Packit |
ea1746 |
double x = std::numeric_limits<double>::quiet_NaN();
|
|
Packit |
ea1746 |
problem.AddParameterBlock(&x, 1);
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_FALSE(preprocessor.Preprocess(options, &problem, &pp));
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST(TrustRegionPreprocessor, ParameterBlockBoundsAreInvalid) {
|
|
Packit |
ea1746 |
ProblemImpl problem;
|
|
Packit |
ea1746 |
double x = 1.0;
|
|
Packit |
ea1746 |
problem.AddParameterBlock(&x, 1);
|
|
Packit |
ea1746 |
problem.SetParameterUpperBound(&x, 0, 1.0);
|
|
Packit |
ea1746 |
problem.SetParameterLowerBound(&x, 0, 2.0);
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_FALSE(preprocessor.Preprocess(options, &problem, &pp));
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST(TrustRegionPreprocessor, ParamterBlockIsInfeasible) {
|
|
Packit |
ea1746 |
ProblemImpl problem;
|
|
Packit |
ea1746 |
double x = 3.0;
|
|
Packit |
ea1746 |
problem.AddParameterBlock(&x, 1);
|
|
Packit |
ea1746 |
problem.SetParameterUpperBound(&x, 0, 1.0);
|
|
Packit |
ea1746 |
problem.SetParameterLowerBound(&x, 0, 2.0);
|
|
Packit |
ea1746 |
problem.SetParameterBlockConstant(&x);
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_FALSE(preprocessor.Preprocess(options, &problem, &pp));
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
class FailingCostFunction : public SizedCostFunction<1, 1> {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
bool Evaluate(double const* const* parameters,
|
|
Packit |
ea1746 |
double* residuals,
|
|
Packit |
ea1746 |
double** jacobians) const {
|
|
Packit |
ea1746 |
return false;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST(TrustRegionPreprocessor, RemoveParameterBlocksFailed) {
|
|
Packit |
ea1746 |
ProblemImpl problem;
|
|
Packit |
ea1746 |
double x = 3.0;
|
|
Packit |
ea1746 |
problem.AddResidualBlock(new FailingCostFunction, NULL, &x);
|
|
Packit |
ea1746 |
problem.SetParameterBlockConstant(&x);
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_FALSE(preprocessor.Preprocess(options, &problem, &pp));
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST(TrustRegionPreprocessor, RemoveParameterBlocksSucceeds) {
|
|
Packit |
ea1746 |
ProblemImpl problem;
|
|
Packit |
ea1746 |
double x = 3.0;
|
|
Packit |
ea1746 |
problem.AddParameterBlock(&x, 1);
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_TRUE(preprocessor.Preprocess(options, &problem, &pp));
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
template<int kNumResiduals, int N1 = 0, int N2 = 0, int N3 = 0>
|
|
Packit |
ea1746 |
class DummyCostFunction : public SizedCostFunction<kNumResiduals, N1, N2, N3> {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
bool Evaluate(double const* const* parameters,
|
|
Packit |
ea1746 |
double* residuals,
|
|
Packit |
ea1746 |
double** jacobians) const {
|
|
Packit |
ea1746 |
for (int i = 0; i < kNumResiduals; ++i) {
|
|
Packit |
ea1746 |
residuals[i] = kNumResiduals * kNumResiduals + i;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
if (jacobians == NULL) {
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
if (jacobians[0] != NULL) {
|
|
Packit |
ea1746 |
MatrixRef j(jacobians[0], kNumResiduals, N1);
|
|
Packit |
ea1746 |
j.setOnes();
|
|
Packit |
ea1746 |
j *= kNumResiduals * N1;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
if (N2 == 0) {
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
if (jacobians[1] != NULL) {
|
|
Packit |
ea1746 |
MatrixRef j(jacobians[1], kNumResiduals, N2);
|
|
Packit |
ea1746 |
j.setOnes();
|
|
Packit |
ea1746 |
j *= kNumResiduals * N2;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
if (N3 == 0) {
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
if (jacobians[2] != NULL) {
|
|
Packit |
ea1746 |
MatrixRef j(jacobians[2], kNumResiduals, N3);
|
|
Packit |
ea1746 |
j.setOnes();
|
|
Packit |
ea1746 |
j *= kNumResiduals * N3;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
return true;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
class LinearSolverAndEvaluatorCreationTest : public ::testing::Test {
|
|
Packit |
ea1746 |
public:
|
|
Packit |
ea1746 |
virtual void SetUp() {
|
|
Packit |
ea1746 |
x_ = 1.0;
|
|
Packit |
ea1746 |
y_ = 1.0;
|
|
Packit |
ea1746 |
z_ = 1.0;
|
|
Packit |
ea1746 |
problem_.AddResidualBlock(new DummyCostFunction<1, 1, 1>, NULL, &x_, &y_;;
|
|
Packit |
ea1746 |
problem_.AddResidualBlock(new DummyCostFunction<1, 1, 1>, NULL, &y_, &z_;;
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
void PreprocessForGivenLinearSolverAndVerify(
|
|
Packit |
ea1746 |
const LinearSolverType linear_solver_type) {
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
options.linear_solver_type = linear_solver_type;
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_TRUE(preprocessor.Preprocess(options, &problem_, &pp));
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.options.linear_solver_type, linear_solver_type);
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.linear_solver_options.type, linear_solver_type);
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.evaluator_options.linear_solver_type, linear_solver_type);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.linear_solver.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.evaluator.get() != NULL);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
protected:
|
|
Packit |
ea1746 |
ProblemImpl problem_;
|
|
Packit |
ea1746 |
double x_;
|
|
Packit |
ea1746 |
double y_;
|
|
Packit |
ea1746 |
double z_;
|
|
Packit |
ea1746 |
};
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, DenseQR) {
|
|
Packit |
ea1746 |
PreprocessForGivenLinearSolverAndVerify(DENSE_QR);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, DenseNormalCholesky) {
|
|
Packit |
ea1746 |
PreprocessForGivenLinearSolverAndVerify(DENSE_NORMAL_CHOLESKY);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, DenseSchur) {
|
|
Packit |
ea1746 |
PreprocessForGivenLinearSolverAndVerify(DENSE_SCHUR);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#if defined(CERES_USE_EIGEN_SPARSE) || \
|
|
Packit |
ea1746 |
!defined(CERES_NO_SUITESPARSE) || \
|
|
Packit |
ea1746 |
!defined(CERES_NO_CXSPARSE)
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, SparseNormalCholesky) {
|
|
Packit |
ea1746 |
PreprocessForGivenLinearSolverAndVerify(SPARSE_NORMAL_CHOLESKY);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
#endif
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
#if defined(CERES_USE_EIGEN_SPARSE) || \
|
|
Packit |
ea1746 |
!defined(CERES_NO_SUITESPARSE) || \
|
|
Packit |
ea1746 |
!defined(CERES_NO_CXSPARSE)
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, SparseSchur) {
|
|
Packit |
ea1746 |
PreprocessForGivenLinearSolverAndVerify(SPARSE_SCHUR);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
#endif
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, CGNR) {
|
|
Packit |
ea1746 |
PreprocessForGivenLinearSolverAndVerify(CGNR);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, IterativeSchur) {
|
|
Packit |
ea1746 |
PreprocessForGivenLinearSolverAndVerify(ITERATIVE_SCHUR);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, MinimizerIsAwareOfBounds) {
|
|
Packit |
ea1746 |
problem_.SetParameterLowerBound(&x_, 0, 0.0);
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_TRUE(preprocessor.Preprocess(options, &problem_, &pp));
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.options.linear_solver_type, options.linear_solver_type);
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.linear_solver_options.type, options.linear_solver_type);
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.evaluator_options.linear_solver_type,
|
|
Packit |
ea1746 |
options.linear_solver_type);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.linear_solver.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.evaluator.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.minimizer_options.is_constrained);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, SchurTypeSolverWithBadOrdering) {
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
options.linear_solver_type = DENSE_SCHUR;
|
|
Packit |
ea1746 |
options.linear_solver_ordering.reset(new ParameterBlockOrdering);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&x_, 0);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&y_, 0);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&z_, 1);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_FALSE(preprocessor.Preprocess(options, &problem_, &pp));
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, SchurTypeSolverWithGoodOrdering) {
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
options.linear_solver_type = DENSE_SCHUR;
|
|
Packit |
ea1746 |
options.linear_solver_ordering.reset(new ParameterBlockOrdering);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&x_, 0);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&z_, 0);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&y_, 1);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_TRUE(preprocessor.Preprocess(options, &problem_, &pp));
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.options.linear_solver_type, DENSE_SCHUR);
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.linear_solver_options.type, DENSE_SCHUR);
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.evaluator_options.linear_solver_type, DENSE_SCHUR);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.linear_solver.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.evaluator.get() != NULL);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest,
|
|
Packit |
ea1746 |
SchurTypeSolverWithEmptyFirstEliminationGroup) {
|
|
Packit |
ea1746 |
problem_.SetParameterBlockConstant(&x_;;
|
|
Packit |
ea1746 |
problem_.SetParameterBlockConstant(&z_;;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
options.linear_solver_type = DENSE_SCHUR;
|
|
Packit |
ea1746 |
options.linear_solver_ordering.reset(new ParameterBlockOrdering);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&x_, 0);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&z_, 0);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&y_, 1);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_TRUE(preprocessor.Preprocess(options, &problem_, &pp));
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.options.linear_solver_type, DENSE_QR);
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.linear_solver_options.type, DENSE_QR);
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.evaluator_options.linear_solver_type, DENSE_QR);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.linear_solver.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.evaluator.get() != NULL);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest,
|
|
Packit |
ea1746 |
SchurTypeSolverWithEmptySecondEliminationGroup) {
|
|
Packit |
ea1746 |
problem_.SetParameterBlockConstant(&y_;;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
options.linear_solver_type = DENSE_SCHUR;
|
|
Packit |
ea1746 |
options.linear_solver_ordering.reset(new ParameterBlockOrdering);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&x_, 0);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&z_, 0);
|
|
Packit |
ea1746 |
options.linear_solver_ordering->AddElementToGroup(&y_, 1);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_TRUE(preprocessor.Preprocess(options, &problem_, &pp));
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.options.linear_solver_type, DENSE_SCHUR);
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.linear_solver_options.type, DENSE_SCHUR);
|
|
Packit |
ea1746 |
EXPECT_EQ(pp.evaluator_options.linear_solver_type, DENSE_SCHUR);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.linear_solver.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.evaluator.get() != NULL);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST(TrustRegionPreprocessorTest, InnerIterationsWithOneParameterBlock) {
|
|
Packit |
ea1746 |
ProblemImpl problem;
|
|
Packit |
ea1746 |
double x = 1.0;
|
|
Packit |
ea1746 |
problem.AddResidualBlock(new DummyCostFunction<1, 1>, NULL, &x);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
options.use_inner_iterations = true;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_TRUE(preprocessor.Preprocess(options, &problem, &pp));
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.linear_solver.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.evaluator.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.inner_iteration_minimizer.get() == NULL);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest,
|
|
Packit |
ea1746 |
InnerIterationsWithTwoParameterBlocks) {
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
options.use_inner_iterations = true;
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_TRUE(preprocessor.Preprocess(options, &problem_, &pp));
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.linear_solver.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.evaluator.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.inner_iteration_minimizer.get() != NULL);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest,
|
|
Packit |
ea1746 |
InvalidInnerIterationsOrdering) {
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
options.use_inner_iterations = true;
|
|
Packit |
ea1746 |
options.inner_iteration_ordering.reset(new ParameterBlockOrdering);
|
|
Packit |
ea1746 |
options.inner_iteration_ordering->AddElementToGroup(&x_, 0);
|
|
Packit |
ea1746 |
options.inner_iteration_ordering->AddElementToGroup(&z_, 0);
|
|
Packit |
ea1746 |
options.inner_iteration_ordering->AddElementToGroup(&y_, 0);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_FALSE(preprocessor.Preprocess(options, &problem_, &pp));
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TEST_F(LinearSolverAndEvaluatorCreationTest, ValidInnerIterationsOrdering) {
|
|
Packit |
ea1746 |
Solver::Options options;
|
|
Packit |
ea1746 |
options.use_inner_iterations = true;
|
|
Packit |
ea1746 |
options.inner_iteration_ordering.reset(new ParameterBlockOrdering);
|
|
Packit |
ea1746 |
options.inner_iteration_ordering->AddElementToGroup(&x_, 0);
|
|
Packit |
ea1746 |
options.inner_iteration_ordering->AddElementToGroup(&z_, 0);
|
|
Packit |
ea1746 |
options.inner_iteration_ordering->AddElementToGroup(&y_, 1);
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
TrustRegionPreprocessor preprocessor;
|
|
Packit |
ea1746 |
PreprocessedProblem pp;
|
|
Packit |
ea1746 |
EXPECT_TRUE(preprocessor.Preprocess(options, &problem_, &pp));
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.linear_solver.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.evaluator.get() != NULL);
|
|
Packit |
ea1746 |
EXPECT_TRUE(pp.inner_iteration_minimizer.get() != NULL);
|
|
Packit |
ea1746 |
}
|
|
Packit |
ea1746 |
|
|
Packit |
ea1746 |
} // namespace internal
|
|
Packit |
ea1746 |
} // namespace ceres
|