diff options
Diffstat (limited to 'extern/ceres/internal/ceres/line_search.cc')
-rw-r--r-- | extern/ceres/internal/ceres/line_search.cc | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/extern/ceres/internal/ceres/line_search.cc b/extern/ceres/internal/ceres/line_search.cc index 7e871a20a53..7e7d97f6d93 100644 --- a/extern/ceres/internal/ceres/line_search.cc +++ b/extern/ceres/internal/ceres/line_search.cc @@ -34,6 +34,7 @@ #include <cmath> #include <iomanip> #include <iostream> // NOLINT +#include <memory> #include "ceres/evaluator.h" #include "ceres/function_sample.h" @@ -65,27 +66,26 @@ ostream& operator<<(ostream& os, const FunctionSample& sample) { return os; } +LineSearch::~LineSearch() = default; + LineSearch::LineSearch(const LineSearch::Options& options) : options_(options) {} -LineSearch* LineSearch::Create(const LineSearchType line_search_type, - const LineSearch::Options& options, - string* error) { - LineSearch* line_search = NULL; +std::unique_ptr<LineSearch> LineSearch::Create( + const LineSearchType line_search_type, + const LineSearch::Options& options, + string* error) { switch (line_search_type) { case ceres::ARMIJO: - line_search = new ArmijoLineSearch(options); - break; + return std::make_unique<ArmijoLineSearch>(options); case ceres::WOLFE: - line_search = new WolfeLineSearch(options); - break; + return std::make_unique<WolfeLineSearch>(options); default: *error = string("Invalid line search algorithm type: ") + LineSearchTypeToString(line_search_type) + string(", unable to create line search."); - return NULL; } - return line_search; + return nullptr; } LineSearchFunction::LineSearchFunction(Evaluator* evaluator) @@ -119,13 +119,13 @@ void LineSearchFunction::Evaluate(const double x, } output->vector_x_is_valid = true; - double* gradient = NULL; + double* gradient = nullptr; if (evaluate_gradient) { output->vector_gradient.resize(direction_.rows(), 1); gradient = output->vector_gradient.data(); } const bool eval_status = evaluator_->Evaluate( - output->vector_x.data(), &(output->value), NULL, gradient, NULL); + output->vector_x.data(), &(output->value), nullptr, gradient, nullptr); if (!eval_status || !std::isfinite(output->value)) { return; @@ -249,12 +249,12 @@ double LineSearch::InterpolatingPolynomialMinimizingStepSize( if (interpolation_type == QUADRATIC) { // Two point interpolation using function values and the // gradient at the lower bound. - samples.push_back(FunctionSample(current.x, current.value)); + samples.emplace_back(current.x, current.value); if (previous.value_is_valid) { // Three point interpolation, using function values and the // gradient at the lower bound. - samples.push_back(FunctionSample(previous.x, previous.value)); + samples.emplace_back(previous.x, previous.value); } } else if (interpolation_type == CUBIC) { // Two point interpolation using the function values and the gradients. |