Run clang-format on the public headers. Also update copyright year. Change-Id: I8508d4fd4564c646ec2281a1b3b2c36136b54b46
diff --git a/include/ceres/autodiff_cost_function.h b/include/ceres/autodiff_cost_function.h index 667e912..b192867 100644 --- a/include/ceres/autodiff_cost_function.h +++ b/include/ceres/autodiff_cost_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -126,6 +126,7 @@ #define CERES_PUBLIC_AUTODIFF_COST_FUNCTION_H_ #include <memory> + #include "ceres/internal/autodiff.h" #include "ceres/sized_cost_function.h" #include "ceres/types.h" @@ -154,8 +155,7 @@ public: // Takes ownership of functor. Uses the template-provided value for the // number of residuals ("kNumResiduals"). - explicit AutoDiffCostFunction(CostFunctor* functor) - : functor_(functor) { + explicit AutoDiffCostFunction(CostFunctor* functor) : functor_(functor) { static_assert(kNumResiduals != DYNAMIC, "Can't run the fixed-size constructor if the number of " "residuals is set to ceres::DYNAMIC.");
diff --git a/include/ceres/autodiff_first_order_function.h b/include/ceres/autodiff_first_order_function.h index c5bde62..b98d845 100644 --- a/include/ceres/autodiff_first_order_function.h +++ b/include/ceres/autodiff_first_order_function.h
@@ -28,7 +28,6 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) - #ifndef CERES_PUBLIC_AUTODIFF_FIRST_ORDER_FUNCTION_H_ #define CERES_PUBLIC_AUTODIFF_FIRST_ORDER_FUNCTION_H_
diff --git a/include/ceres/autodiff_local_parameterization.h b/include/ceres/autodiff_local_parameterization.h index 455e9bb..9d59a46 100644 --- a/include/ceres/autodiff_local_parameterization.h +++ b/include/ceres/autodiff_local_parameterization.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -34,8 +34,9 @@ #define CERES_PUBLIC_AUTODIFF_LOCAL_PARAMETERIZATION_H_ #include <memory> -#include "ceres/local_parameterization.h" + #include "ceres/internal/autodiff.h" +#include "ceres/local_parameterization.h" namespace ceres {
diff --git a/include/ceres/c_api.h b/include/ceres/c_api.h index df7c9b6..0e6e590 100644 --- a/include/ceres/c_api.h +++ b/include/ceres/c_api.h
@@ -1,5 +1,5 @@ /* Ceres Solver - A fast non-linear least squares minimizer - * Copyright 2015 Google Inc. All rights reserved. + * Copyright 2019 Google Inc. All rights reserved. * http://ceres-solver.org/ * * Redistribution and use in source and binary forms, with or without @@ -143,4 +143,4 @@ #include "ceres/internal/reenable_warnings.h" -#endif /* CERES_PUBLIC_C_API_H_ */ +#endif /* CERES_PUBLIC_C_API_H_ */
diff --git a/include/ceres/ceres.h b/include/ceres/ceres.h index 88875a0..d249351 100644 --- a/include/ceres/ceres.h +++ b/include/ceres/ceres.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without
diff --git a/include/ceres/conditioned_cost_function.h b/include/ceres/conditioned_cost_function.h index 54a2e59..a57ee20 100644 --- a/include/ceres/conditioned_cost_function.h +++ b/include/ceres/conditioned_cost_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -34,12 +34,12 @@ #ifndef CERES_PUBLIC_CONDITIONED_COST_FUNCTION_H_ #define CERES_PUBLIC_CONDITIONED_COST_FUNCTION_H_ +#include <memory> #include <vector> -#include <memory> #include "ceres/cost_function.h" -#include "ceres/types.h" #include "ceres/internal/disable_warnings.h" +#include "ceres/types.h" namespace ceres {
diff --git a/include/ceres/context.h b/include/ceres/context.h index cf7c436..d08e32b 100644 --- a/include/ceres/context.h +++ b/include/ceres/context.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2018 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without
diff --git a/include/ceres/cost_function.h b/include/ceres/cost_function.h index 39425e8..d1550c1 100644 --- a/include/ceres/cost_function.h +++ b/include/ceres/cost_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2017 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -46,8 +46,9 @@ #include <cstdint> #include <vector> -#include "ceres/internal/port.h" + #include "ceres/internal/disable_warnings.h" +#include "ceres/internal/port.h" namespace ceres { @@ -120,18 +121,14 @@ return parameter_block_sizes_; } - int num_residuals() const { - return num_residuals_; - } + int num_residuals() const { return num_residuals_; } protected: std::vector<int32_t>* mutable_parameter_block_sizes() { return ¶meter_block_sizes_; } - void set_num_residuals(int num_residuals) { - num_residuals_ = num_residuals; - } + void set_num_residuals(int num_residuals) { num_residuals_ = num_residuals; } private: // Cost function signature metadata: number of inputs & their sizes,
diff --git a/include/ceres/cost_function_to_functor.h b/include/ceres/cost_function_to_functor.h index 32ed277..cbd6186 100644 --- a/include/ceres/cost_function_to_functor.h +++ b/include/ceres/cost_function_to_functor.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -124,8 +124,8 @@ } } - CHECK_EQ(accumulate(parameter_block_sizes.begin(), - parameter_block_sizes.end(), 0), + CHECK_EQ(accumulate( + parameter_block_sizes.begin(), parameter_block_sizes.end(), 0), ParameterDims::kNumParameters); }
diff --git a/include/ceres/covariance.h b/include/ceres/covariance.h index da9f525..5db0afb 100644 --- a/include/ceres/covariance.h +++ b/include/ceres/covariance.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -34,6 +34,7 @@ #include <memory> #include <utility> #include <vector> + #include "ceres/internal/disable_warnings.h" #include "ceres/internal/port.h" #include "ceres/types.h" @@ -349,10 +350,9 @@ // covariance computation. Please see the documentation for // Covariance::Options for more on the conditions under which this // function returns false. - bool Compute( - const std::vector<std::pair<const double*, - const double*>>& covariance_blocks, - Problem* problem); + bool Compute(const std::vector<std::pair<const double*, const double*>>& + covariance_blocks, + Problem* problem); // Compute a part of the covariance matrix. // @@ -425,8 +425,8 @@ // a square matrix whose row and column count is equal to the sum of // the sizes of the individual parameter blocks. The covariance // matrix will be a row-major matrix. - bool GetCovarianceMatrix(const std::vector<const double *> ¶meter_blocks, - double *covariance_matrix); + bool GetCovarianceMatrix(const std::vector<const double*>& parameter_blocks, + double* covariance_matrix); // Return the covariance matrix corresponding to parameter_blocks // in the tangent space if a local parameterization is associated
diff --git a/include/ceres/crs_matrix.h b/include/ceres/crs_matrix.h index 23687c4..bc618fa 100644 --- a/include/ceres/crs_matrix.h +++ b/include/ceres/crs_matrix.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -32,8 +32,9 @@ #define CERES_PUBLIC_CRS_MATRIX_H_ #include <vector> -#include "ceres/internal/port.h" + #include "ceres/internal/disable_warnings.h" +#include "ceres/internal/port.h" namespace ceres {
diff --git a/include/ceres/cubic_interpolation.h b/include/ceres/cubic_interpolation.h index 080d35a..9b9ea4a 100644 --- a/include/ceres/cubic_interpolation.h +++ b/include/ceres/cubic_interpolation.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -31,8 +31,8 @@ #ifndef CERES_PUBLIC_CUBIC_INTERPOLATION_H_ #define CERES_PUBLIC_CUBIC_INTERPOLATION_H_ -#include "ceres/internal/port.h" #include "Eigen/Core" +#include "ceres/internal/port.h" #include "glog/logging.h" namespace ceres { @@ -120,11 +120,10 @@ // CubicInterpolator<Grid1D<double, 1>> interpolator(grid); // double f, dfdx; // interpolator.Evaluator(1.5, &f, &dfdx); -template<typename Grid> +template <typename Grid> class CubicInterpolator { public: - explicit CubicInterpolator(const Grid& grid) - : grid_(grid) { + explicit CubicInterpolator(const Grid& grid) : grid_(grid) { // The + casts the enum into an int before doing the // comparison. It is needed to prevent // "-Wunnamed-type-template-args" related errors. @@ -135,7 +134,7 @@ const int n = std::floor(x); Eigen::Matrix<double, Grid::DATA_DIMENSION, 1> p0, p1, p2, p3; grid_.GetValue(n - 1, p0.data()); - grid_.GetValue(n, p1.data()); + grid_.GetValue(n, p1.data()); grid_.GetValue(n + 1, p2.data()); grid_.GetValue(n + 2, p3.data()); CubicHermiteSpline<Grid::DATA_DIMENSION>(p0, p1, p2, p3, x - n, f, dfdx); @@ -144,11 +143,10 @@ // The following two Evaluate overloads are needed for interfacing // with automatic differentiation. The first is for when a scalar // evaluation is done, and the second one is for when Jets are used. - void Evaluate(const double& x, double* f) const { - Evaluate(x, f, NULL); - } + void Evaluate(const double& x, double* f) const { Evaluate(x, f, NULL); } - template<typename JetT> void Evaluate(const JetT& x, JetT* f) const { + template <typename JetT> + void Evaluate(const JetT& x, JetT* f) const { double fx[Grid::DATA_DIMENSION], dfdx[Grid::DATA_DIMENSION]; Evaluate(x.a, fx, dfdx); for (int i = 0; i < Grid::DATA_DIMENSION; ++i) { @@ -182,9 +180,7 @@ // // f01, f11, .. fn1, f02, f12, .. , fn2 // -template <typename T, - int kDataDimension = 1, - bool kInterleaved = true> +template <typename T, int kDataDimension = 1, bool kInterleaved = true> struct Grid1D { public: enum { DATA_DIMENSION = kDataDimension }; @@ -252,11 +248,10 @@ // double f, dfdr, dfdc; // interpolator.Evaluate(1.2, 2.5, &f, &dfdr, &dfdc); -template<typename Grid> +template <typename Grid> class BiCubicInterpolator { public: - explicit BiCubicInterpolator(const Grid& grid) - : grid_(grid) { + explicit BiCubicInterpolator(const Grid& grid) : grid_(grid) { // The + casts the enum into an int before doing the // comparison. It is needed to prevent // "-Wunnamed-type-template-args" related errors. @@ -266,8 +261,8 @@ // Evaluate the interpolated function value and/or its // derivative. Uses the nearest point on the grid boundary if r or // c is out of bounds. - void Evaluate(double r, double c, - double* f, double* dfdr, double* dfdc) const { + void Evaluate( + double r, double c, double* f, double* dfdr, double* dfdc) const { // BiCubic interpolation requires 16 values around the point being // evaluated. We will use pij, to indicate the elements of the // 4x4 grid of values. @@ -292,40 +287,40 @@ Eigen::Matrix<double, Grid::DATA_DIMENSION, 1> df0dc, df1dc, df2dc, df3dc; grid_.GetValue(row - 1, col - 1, p0.data()); - grid_.GetValue(row - 1, col , p1.data()); + grid_.GetValue(row - 1, col, p1.data()); grid_.GetValue(row - 1, col + 1, p2.data()); grid_.GetValue(row - 1, col + 2, p3.data()); - CubicHermiteSpline<Grid::DATA_DIMENSION>(p0, p1, p2, p3, c - col, - f0.data(), df0dc.data()); + CubicHermiteSpline<Grid::DATA_DIMENSION>( + p0, p1, p2, p3, c - col, f0.data(), df0dc.data()); grid_.GetValue(row, col - 1, p0.data()); - grid_.GetValue(row, col , p1.data()); + grid_.GetValue(row, col, p1.data()); grid_.GetValue(row, col + 1, p2.data()); grid_.GetValue(row, col + 2, p3.data()); - CubicHermiteSpline<Grid::DATA_DIMENSION>(p0, p1, p2, p3, c - col, - f1.data(), df1dc.data()); + CubicHermiteSpline<Grid::DATA_DIMENSION>( + p0, p1, p2, p3, c - col, f1.data(), df1dc.data()); grid_.GetValue(row + 1, col - 1, p0.data()); - grid_.GetValue(row + 1, col , p1.data()); + grid_.GetValue(row + 1, col, p1.data()); grid_.GetValue(row + 1, col + 1, p2.data()); grid_.GetValue(row + 1, col + 2, p3.data()); - CubicHermiteSpline<Grid::DATA_DIMENSION>(p0, p1, p2, p3, c - col, - f2.data(), df2dc.data()); + CubicHermiteSpline<Grid::DATA_DIMENSION>( + p0, p1, p2, p3, c - col, f2.data(), df2dc.data()); grid_.GetValue(row + 2, col - 1, p0.data()); - grid_.GetValue(row + 2, col , p1.data()); + grid_.GetValue(row + 2, col, p1.data()); grid_.GetValue(row + 2, col + 1, p2.data()); grid_.GetValue(row + 2, col + 2, p3.data()); - CubicHermiteSpline<Grid::DATA_DIMENSION>(p0, p1, p2, p3, c - col, - f3.data(), df3dc.data()); + CubicHermiteSpline<Grid::DATA_DIMENSION>( + p0, p1, p2, p3, c - col, f3.data(), df3dc.data()); // Interpolate vertically the interpolated value from each row and // compute the derivative along the columns. CubicHermiteSpline<Grid::DATA_DIMENSION>(f0, f1, f2, f3, r - row, f, dfdr); if (dfdc != NULL) { // Interpolate vertically the derivative along the columns. - CubicHermiteSpline<Grid::DATA_DIMENSION>(df0dc, df1dc, df2dc, df3dc, - r - row, dfdc, NULL); + CubicHermiteSpline<Grid::DATA_DIMENSION>( + df0dc, df1dc, df2dc, df3dc, r - row, dfdc, NULL); } } @@ -336,9 +331,8 @@ Evaluate(r, c, f, NULL, NULL); } - template<typename JetT> void Evaluate(const JetT& r, - const JetT& c, - JetT* f) const { + template <typename JetT> + void Evaluate(const JetT& r, const JetT& c, JetT* f) const { double frc[Grid::DATA_DIMENSION]; double dfdr[Grid::DATA_DIMENSION]; double dfdc[Grid::DATA_DIMENSION]; @@ -389,12 +383,17 @@ enum { DATA_DIMENSION = kDataDimension }; Grid2D(const T* data, - const int row_begin, const int row_end, - const int col_begin, const int col_end) + const int row_begin, + const int row_end, + const int col_begin, + const int col_end) : data_(data), - row_begin_(row_begin), row_end_(row_end), - col_begin_(col_begin), col_end_(col_end), - num_rows_(row_end - row_begin), num_cols_(col_end - col_begin), + row_begin_(row_begin), + row_end_(row_end), + col_begin_(col_begin), + col_end_(col_end), + num_rows_(row_end - row_begin), + num_cols_(col_end - col_begin), num_values_(num_rows_ * num_cols_) { CHECK_GE(kDataDimension, 1); CHECK_LT(row_begin, row_end); @@ -407,11 +406,8 @@ const int col_idx = std::min(std::max(col_begin_, c), col_end_ - 1) - col_begin_; - const int n = - (kRowMajor) - ? num_cols_ * row_idx + col_idx - : num_rows_ * col_idx + row_idx; - + const int n = (kRowMajor) ? num_cols_ * row_idx + col_idx + : num_rows_ * col_idx + row_idx; if (kInterleaved) { for (int i = 0; i < kDataDimension; ++i) {
diff --git a/include/ceres/dynamic_autodiff_cost_function.h b/include/ceres/dynamic_autodiff_cost_function.h index 1b60b4f..7b75150 100644 --- a/include/ceres/dynamic_autodiff_cost_function.h +++ b/include/ceres/dynamic_autodiff_cost_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -79,7 +79,7 @@ class DynamicAutoDiffCostFunction : public DynamicCostFunction { public: explicit DynamicAutoDiffCostFunction(CostFunctor* functor) - : functor_(functor) {} + : functor_(functor) {} virtual ~DynamicAutoDiffCostFunction() {} @@ -108,9 +108,8 @@ // num_residuals() derivatives. This is done with small, fixed-size jets. const int num_parameter_blocks = static_cast<int>(parameter_block_sizes().size()); - const int num_parameters = std::accumulate(parameter_block_sizes().begin(), - parameter_block_sizes().end(), - 0); + const int num_parameters = std::accumulate( + parameter_block_sizes().begin(), parameter_block_sizes().end(), 0); // Allocate scratch space for the strided evaluation. using JetT = Jet<double, Stride>; @@ -168,8 +167,8 @@ // Evaluate all of the strides. Each stride is a chunk of the derivative to // evaluate, typically some size proportional to the size of the SIMD // registers of the CPU. - int num_strides = static_cast<int>(ceil(num_active_parameters / - static_cast<float>(Stride))); + int num_strides = static_cast<int>( + ceil(num_active_parameters / static_cast<float>(Stride))); int current_derivative_section = 0; int current_derivative_section_cursor = 0; @@ -179,7 +178,7 @@ // non-constant #Stride parameters. const int initial_derivative_section = current_derivative_section; const int initial_derivative_section_cursor = - current_derivative_section_cursor; + current_derivative_section_cursor; int active_parameter_count = 0; parameter_cursor = 0; @@ -189,9 +188,9 @@ ++j, parameter_cursor++) { input_jets[parameter_cursor].v.setZero(); if (active_parameter_count < Stride && - parameter_cursor >= ( - start_derivative_section[current_derivative_section] + - current_derivative_section_cursor)) { + parameter_cursor >= + (start_derivative_section[current_derivative_section] + + current_derivative_section_cursor)) { if (jacobians[i] != NULL) { input_jets[parameter_cursor].v[active_parameter_count] = 1.0; ++active_parameter_count; @@ -218,9 +217,9 @@ for (int j = 0; j < parameter_block_sizes()[i]; ++j, parameter_cursor++) { if (active_parameter_count < Stride && - parameter_cursor >= ( - start_derivative_section[current_derivative_section] + - current_derivative_section_cursor)) { + parameter_cursor >= + (start_derivative_section[current_derivative_section] + + current_derivative_section_cursor)) { if (jacobians[i] != NULL) { for (int k = 0; k < num_residuals(); ++k) { jacobians[i][k * parameter_block_sizes()[i] + j] =
diff --git a/include/ceres/dynamic_cost_function.h b/include/ceres/dynamic_cost_function.h index 6c0aa31..6e8a076 100644 --- a/include/ceres/dynamic_cost_function.h +++ b/include/ceres/dynamic_cost_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2016 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without
diff --git a/include/ceres/dynamic_cost_function_to_functor.h b/include/ceres/dynamic_cost_function_to_functor.h index 7ea76ca..8d174d8 100644 --- a/include/ceres/dynamic_cost_function_to_functor.h +++ b/include/ceres/dynamic_cost_function_to_functor.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -119,8 +119,8 @@ const int num_parameter_blocks = static_cast<int>(parameter_block_sizes.size()); const int num_residuals = cost_function_->num_residuals(); - const int num_parameters = std::accumulate(parameter_block_sizes.begin(), - parameter_block_sizes.end(), 0); + const int num_parameters = std::accumulate( + parameter_block_sizes.begin(), parameter_block_sizes.end(), 0); internal::FixedArray<double> parameters(num_parameters); internal::FixedArray<double*> parameter_blocks(num_parameter_blocks);
diff --git a/include/ceres/dynamic_numeric_diff_cost_function.h b/include/ceres/dynamic_numeric_diff_cost_function.h index a9d7f14..119b3f8 100644 --- a/include/ceres/dynamic_numeric_diff_cost_function.h +++ b/include/ceres/dynamic_numeric_diff_cost_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -59,7 +59,9 @@ // numeric diff; the expected interface for the cost functors is: // // struct MyCostFunctor { -// bool operator()(double const* const* parameters, double* residuals) const { +// bool operator()(double const* +// const* parameters, +// double* residuals) const { // // Use parameters[i] to access the i'th parameter block. // } // } @@ -80,10 +82,7 @@ const CostFunctor* functor, Ownership ownership = TAKE_OWNERSHIP, const NumericDiffOptions& options = NumericDiffOptions()) - : functor_(functor), - ownership_(ownership), - options_(options) { - } + : functor_(functor), ownership_(ownership), options_(options) {} virtual ~DynamicNumericDiffCostFunction() { if (ownership_ != TAKE_OWNERSHIP) { @@ -106,9 +105,7 @@ const bool status = internal::VariadicEvaluate<internal::DynamicParameterDims>( - *functor_.get(), - parameters, - residuals); + *functor_.get(), parameters, residuals); if (jacobians == NULL || !status) { return status; } @@ -119,8 +116,8 @@ std::vector<double*> parameters_references_copy(block_sizes.size()); parameters_references_copy[0] = ¶meters_copy[0]; for (size_t block = 1; block < block_sizes.size(); ++block) { - parameters_references_copy[block] = parameters_references_copy[block - 1] - + block_sizes[block - 1]; + parameters_references_copy[block] = + parameters_references_copy[block - 1] + block_sizes[block - 1]; } // Copy the parameters into the local temp space. @@ -132,18 +129,20 @@ for (size_t block = 0; block < block_sizes.size(); ++block) { if (jacobians[block] != NULL && - !NumericDiff<CostFunctor, method, ceres::DYNAMIC, - internal::DynamicParameterDims, ceres::DYNAMIC, + !NumericDiff<CostFunctor, + method, + ceres::DYNAMIC, + internal::DynamicParameterDims, + ceres::DYNAMIC, ceres::DYNAMIC>:: - EvaluateJacobianForParameterBlock( - functor_.get(), - residuals, - options_, - this->num_residuals(), - block, - block_sizes[block], - ¶meters_references_copy[0], - jacobians[block])) { + EvaluateJacobianForParameterBlock(functor_.get(), + residuals, + options_, + this->num_residuals(), + block, + block_sizes[block], + ¶meters_references_copy[0], + jacobians[block])) { return false; } }
diff --git a/include/ceres/evaluation_callback.h b/include/ceres/evaluation_callback.h index 24122a8..b9f5bbb 100644 --- a/include/ceres/evaluation_callback.h +++ b/include/ceres/evaluation_callback.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2018 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without
diff --git a/include/ceres/first_order_function.h b/include/ceres/first_order_function.h index 4413543..1420153 100644 --- a/include/ceres/first_order_function.h +++ b/include/ceres/first_order_function.h
@@ -28,7 +28,6 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) - #ifndef CERES_PUBLIC_FIRST_ORDER_FUNCTION_H_ #define CERES_PUBLIC_FIRST_ORDER_FUNCTION_H_
diff --git a/include/ceres/gradient_checker.h b/include/ceres/gradient_checker.h index e23df76..b79cf86 100644 --- a/include/ceres/gradient_checker.h +++ b/include/ceres/gradient_checker.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without
diff --git a/include/ceres/gradient_problem.h b/include/ceres/gradient_problem.h index 7e6d2e9..49d605e 100644 --- a/include/ceres/gradient_problem.h +++ b/include/ceres/gradient_problem.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -32,8 +32,9 @@ #define CERES_PUBLIC_GRADIENT_PROBLEM_H_ #include <memory> -#include "ceres/internal/port.h" + #include "ceres/first_order_function.h" +#include "ceres/internal/port.h" #include "ceres/local_parameterization.h" namespace ceres {
diff --git a/include/ceres/gradient_problem_solver.h b/include/ceres/gradient_problem_solver.h index 9d26a2e..181699d 100644 --- a/include/ceres/gradient_problem_solver.h +++ b/include/ceres/gradient_problem_solver.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -34,10 +34,11 @@ #include <cmath> #include <string> #include <vector> + +#include "ceres/internal/disable_warnings.h" #include "ceres/internal/port.h" #include "ceres/iteration_callback.h" #include "ceres/types.h" -#include "ceres/internal/disable_warnings.h" namespace ceres { @@ -61,8 +62,7 @@ // Minimizer options ---------------------------------------- LineSearchDirectionType line_search_direction_type = LBFGS; LineSearchType line_search_type = WOLFE; - NonlinearConjugateGradientType nonlinear_conjugate_gradient_type = - FLETCHER_REEVES; + NonlinearConjugateGradientType nonlinear_conjugate_gradient_type = FLETCHER_REEVES; // The LBFGS hessian approximation is a low rank approximation to // the inverse of the Hessian matrix. The rank of the @@ -319,7 +319,8 @@ // If the line search direction is NONLINEAR_CONJUGATE_GRADIENT, // then this indicates the particular variant of non-linear // conjugate gradient used. - NonlinearConjugateGradientType nonlinear_conjugate_gradient_type = FLETCHER_REEVES; + NonlinearConjugateGradientType nonlinear_conjugate_gradient_type = + FLETCHER_REEVES; // If the type of the line search direction is LBFGS, then this // indicates the rank of the Hessian approximation.
diff --git a/include/ceres/iteration_callback.h b/include/ceres/iteration_callback.h index bd1e782..0a743ec 100644 --- a/include/ceres/iteration_callback.h +++ b/include/ceres/iteration_callback.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -35,42 +35,22 @@ #ifndef CERES_PUBLIC_ITERATION_CALLBACK_H_ #define CERES_PUBLIC_ITERATION_CALLBACK_H_ -#include "ceres/types.h" #include "ceres/internal/disable_warnings.h" +#include "ceres/types.h" namespace ceres { // This struct describes the state of the optimizer after each // iteration of the minimization. struct CERES_EXPORT IterationSummary { - IterationSummary() - : iteration(0), - step_is_valid(false), - step_is_nonmonotonic(false), - step_is_successful(false), - cost(0.0), - cost_change(0.0), - gradient_max_norm(0.0), - gradient_norm(0.0), - step_norm(0.0), - eta(0.0), - step_size(0.0), - line_search_function_evaluations(0), - line_search_gradient_evaluations(0), - line_search_iterations(0), - linear_solver_iterations(0), - iteration_time_in_seconds(0.0), - step_solver_time_in_seconds(0.0), - cumulative_time_in_seconds(0.0) {} - // Current iteration number. - int iteration; + int iteration = 0; // Step was numerically valid, i.e., all values are finite and the // step reduces the value of the linearized model. // // Note: step_is_valid is always true when iteration = 0. - bool step_is_valid; + bool step_is_valid = false; // Step did not reduce the value of the objective function // sufficiently, but it was accepted because of the relaxed @@ -78,7 +58,7 @@ // algorithm. // // Note: step_is_nonmonotonic is always false when iteration = 0; - bool step_is_nonmonotonic; + bool step_is_nonmonotonic = false; // Whether or not the minimizer accepted this step or not. If the // ordinary trust region algorithm is used, this means that the @@ -90,68 +70,68 @@ // step and the step is declared successful. // // Note: step_is_successful is always true when iteration = 0. - bool step_is_successful; + bool step_is_successful = false; // Value of the objective function. - double cost; + double cost = 0.90; // Change in the value of the objective function in this // iteration. This can be positive or negative. - double cost_change; + double cost_change = 0.0; // Infinity norm of the gradient vector. - double gradient_max_norm; + double gradient_max_norm = 0.0; // 2-norm of the gradient vector. - double gradient_norm; + double gradient_norm = 0.0; // 2-norm of the size of the step computed by the optimization // algorithm. - double step_norm; + double step_norm = 0.0; // For trust region algorithms, the ratio of the actual change in // cost and the change in the cost of the linearized approximation. - double relative_decrease; + double relative_decrease = 0.0; // Size of the trust region at the end of the current iteration. For // the Levenberg-Marquardt algorithm, the regularization parameter // mu = 1.0 / trust_region_radius. - double trust_region_radius; + double trust_region_radius = 0.0; // For the inexact step Levenberg-Marquardt algorithm, this is the // relative accuracy with which the Newton(LM) step is solved. This // number affects only the iterative solvers capable of solving // linear systems inexactly. Factorization-based exact solvers // ignore it. - double eta; + double eta = 0.0; // Step sized computed by the line search algorithm. - double step_size; + double step_size = 0.0; // Number of function value evaluations used by the line search algorithm. - int line_search_function_evaluations; + int line_search_function_evaluations = 0; // Number of function gradient evaluations used by the line search algorithm. - int line_search_gradient_evaluations; + int line_search_gradient_evaluations = 0; // Number of iterations taken by the line search algorithm. - int line_search_iterations; + int line_search_iterations = 0; // Number of iterations taken by the linear solver to solve for the // Newton step. - int linear_solver_iterations; + int linear_solver_iterations = 0; // All times reported below are wall times. // Time (in seconds) spent inside the minimizer loop in the current // iteration. - double iteration_time_in_seconds; + double iteration_time_in_seconds = 0.0; // Time (in seconds) spent inside the trust region step solver. - double step_solver_time_in_seconds; + double step_solver_time_in_seconds = 0.0; // Time (in seconds) since the user called Solve(). - double cumulative_time_in_seconds; + double cumulative_time_in_seconds = 0.0; }; // Interface for specifying callbacks that are executed at the end of
diff --git a/include/ceres/local_parameterization.h b/include/ceres/local_parameterization.h index c63790c..93c7973 100644 --- a/include/ceres/local_parameterization.h +++ b/include/ceres/local_parameterization.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without
diff --git a/include/ceres/loss_function.h b/include/ceres/loss_function.h index e494ef0..1294100 100644 --- a/include/ceres/loss_function.h +++ b/include/ceres/loss_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without
diff --git a/include/ceres/normal_prior.h b/include/ceres/normal_prior.h index 1fe9f55..14ab379 100644 --- a/include/ceres/normal_prior.h +++ b/include/ceres/normal_prior.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -35,8 +35,8 @@ #define CERES_PUBLIC_NORMAL_PRIOR_H_ #include "ceres/cost_function.h" -#include "ceres/internal/eigen.h" #include "ceres/internal/disable_warnings.h" +#include "ceres/internal/eigen.h" namespace ceres { @@ -57,7 +57,7 @@ // which would be the case if the covariance matrix S is rank // deficient. -class CERES_EXPORT NormalPrior: public CostFunction { +class CERES_EXPORT NormalPrior : public CostFunction { public: // Check that the number of rows in the vector b are the same as the // number of columns in the matrix A, crash otherwise. @@ -65,6 +65,7 @@ bool Evaluate(double const* const* parameters, double* residuals, double** jacobians) const override; + private: Matrix A_; Vector b_;
diff --git a/include/ceres/numeric_diff_cost_function.h b/include/ceres/numeric_diff_cost_function.h index a0678a0..493412b 100644 --- a/include/ceres/numeric_diff_cost_function.h +++ b/include/ceres/numeric_diff_cost_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -98,6 +98,8 @@ // NumericDiffCostFunction also supports cost functions with a // runtime-determined number of residuals. For example: // +// clang-format off +// // CostFunction* cost_function // = new NumericDiffCostFunction<MyScalarCostFunctor, CENTRAL, DYNAMIC, 2, 2>( // new CostFunctorWithDynamicNumResiduals(1.0), ^ ^ ^ @@ -109,6 +111,8 @@ // Indicate dynamic number of residuals --------------------+ | | // Dimension of x ------------------------------------------------+ | // Dimension of y ---------------------------------------------------+ +// clang-format on +// // // The central difference method is considerably more accurate at the cost of // twice as many function evaluations than forward difference. Consider using @@ -182,9 +186,7 @@ Ownership ownership = TAKE_OWNERSHIP, int num_residuals = kNumResiduals, const NumericDiffOptions& options = NumericDiffOptions()) - : functor_(functor), - ownership_(ownership), - options_(options) { + : functor_(functor), ownership_(ownership), options_(options) { if (kNumResiduals == DYNAMIC) { SizedCostFunction<kNumResiduals, Ns...>::set_num_residuals(num_residuals); } @@ -210,9 +212,8 @@ constexpr int kNumParameterBlocks = ParameterDims::kNumParameterBlocks; // Get the function value (residuals) at the the point to evaluate. - if (!internal::VariadicEvaluate<ParameterDims>(*functor_, - parameters, - residuals)) { + if (!internal::VariadicEvaluate<ParameterDims>( + *functor_, parameters, residuals)) { return false; } @@ -226,18 +227,19 @@ ParameterDims::GetUnpackedParameters(parameters_copy.data()); for (int block = 0; block < kNumParameterBlocks; ++block) { - memcpy(parameters_reference_copy[block], parameters[block], + memcpy(parameters_reference_copy[block], + parameters[block], sizeof(double) * ParameterDims::GetDim(block)); } - internal::EvaluateJacobianForParameterBlocks<ParameterDims>::template Apply< - method, kNumResiduals>( - functor_.get(), - residuals, - options_, - SizedCostFunction<kNumResiduals, Ns...>::num_residuals(), - parameters_reference_copy.data(), - jacobians); + internal::EvaluateJacobianForParameterBlocks<ParameterDims>:: + template Apply<method, kNumResiduals>( + functor_.get(), + residuals, + options_, + SizedCostFunction<kNumResiduals, Ns...>::num_residuals(), + parameters_reference_copy.data(), + jacobians); return true; }
diff --git a/include/ceres/numeric_diff_options.h b/include/ceres/numeric_diff_options.h index a77be44..64919ed 100644 --- a/include/ceres/numeric_diff_options.h +++ b/include/ceres/numeric_diff_options.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without
diff --git a/include/ceres/ordered_groups.h b/include/ceres/ordered_groups.h index 0bff41f..954663c 100644 --- a/include/ceres/ordered_groups.h +++ b/include/ceres/ordered_groups.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -35,6 +35,7 @@ #include <set> #include <unordered_map> #include <vector> + #include "ceres/internal/port.h" #include "glog/logging.h" @@ -161,17 +162,13 @@ // group for every integer. int GroupSize(const int group) const { auto it = group_to_elements_.find(group); - return (it == group_to_elements_.end()) ? 0 : it->second.size(); + return (it == group_to_elements_.end()) ? 0 : it->second.size(); } - int NumElements() const { - return element_to_group_.size(); - } + int NumElements() const { return element_to_group_.size(); } // Number of groups with one or more elements. - int NumGroups() const { - return group_to_elements_.size(); - } + int NumGroups() const { return group_to_elements_.size(); } // The first group with one or more elements. Calling this when // there are no groups with non-zero elements will result in a @@ -185,9 +182,7 @@ return group_to_elements_; } - const std::map<T, int>& element_to_group() const { - return element_to_group_; - } + const std::map<T, int>& element_to_group() const { return element_to_group_; } private: std::map<int, std::set<T>> group_to_elements_;
diff --git a/include/ceres/problem.h b/include/ceres/problem.h index 1b57eec..278d80f 100644 --- a/include/ceres/problem.h +++ b/include/ceres/problem.h
@@ -239,7 +239,8 @@ double* x0, Ts*... xs) { const std::array<double*, sizeof...(Ts) + 1> parameter_blocks{{x0, xs...}}; - return AddResidualBlock(cost_function, loss_function, + return AddResidualBlock(cost_function, + loss_function, parameter_blocks.data(), static_cast<int>(parameter_blocks.size())); } @@ -252,11 +253,10 @@ // Add a residual block by providing a pointer to the parameter block array // and the number of parameter blocks. - ResidualBlockId AddResidualBlock( - CostFunction* cost_function, - LossFunction* loss_function, - double* const* const parameter_blocks, - int num_parameter_blocks); + ResidualBlockId AddResidualBlock(CostFunction* cost_function, + LossFunction* loss_function, + double* const* const parameter_blocks, + int num_parameter_blocks); // Add a parameter block with appropriate size to the problem. // Repeated calls with the same arguments are ignored. Repeated @@ -451,8 +451,8 @@ // The cost is evaluated at x = 1. If you wish to evaluate the // problem at x = 2, then // - // x = 2; - // problem.Evaluate(Problem::EvaluateOptions(), &cost, nullptr, nullptr, nullptr); + // x = 2; + // problem.Evaluate(Problem::EvaluateOptions(), &cost, nullptr, nullptr, nullptr); // // is the way to do so. // @@ -518,6 +518,7 @@ double* cost, double* residuals, double** jacobians) const; + private: friend class Solver; friend class Covariance;
diff --git a/include/ceres/rotation.h b/include/ceres/rotation.h index 3020a2d..7d5c8ef 100644 --- a/include/ceres/rotation.h +++ b/include/ceres/rotation.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -84,7 +84,7 @@ // and quaternion is a 4-tuple that will contain the resulting quaternion. // The implementation may be used with auto-differentiation up to the first // derivative, higher derivatives may have unexpected results near the origin. -template<typename T> +template <typename T> void AngleAxisToQuaternion(const T* angle_axis, T* quaternion); // Convert a quaternion to the equivalent combined axis-angle representation. @@ -93,7 +93,7 @@ // rotation in radians, and whose direction is the axis of rotation. // The implementation may be used with auto-differentiation up to the first // derivative, higher derivatives may have unexpected results near the origin. -template<typename T> +template <typename T> void QuaternionToAngleAxis(const T* quaternion, T* angle_axis); // Conversions between 3x3 rotation matrix (in column major order) and @@ -104,8 +104,7 @@ template <typename T, int row_stride, int col_stride> void RotationMatrixToQuaternion( - const MatrixAdapter<const T, row_stride, col_stride>& R, - T* quaternion); + const MatrixAdapter<const T, row_stride, col_stride>& R, T* quaternion); // Conversions between 3x3 rotation matrix (in column major order) and // axis-angle rotation representations. Templated for use with @@ -115,16 +114,14 @@ template <typename T, int row_stride, int col_stride> void RotationMatrixToAngleAxis( - const MatrixAdapter<const T, row_stride, col_stride>& R, - T* angle_axis); + const MatrixAdapter<const T, row_stride, col_stride>& R, T* angle_axis); template <typename T> void AngleAxisToRotationMatrix(const T* angle_axis, T* R); template <typename T, int row_stride, int col_stride> void AngleAxisToRotationMatrix( - const T* angle_axis, - const MatrixAdapter<T, row_stride, col_stride>& R); + const T* angle_axis, const MatrixAdapter<T, row_stride, col_stride>& R); // Conversions between 3x3 rotation matrix (in row major order) and // Euler angle (in degrees) rotation representations. @@ -137,8 +134,7 @@ template <typename T, int row_stride, int col_stride> void EulerAnglesToRotationMatrix( - const T* euler, - const MatrixAdapter<T, row_stride, col_stride>& R); + const T* euler, const MatrixAdapter<T, row_stride, col_stride>& R); // Convert a 4-vector to a 3x3 scaled rotation matrix. // @@ -159,25 +155,23 @@ // such that det(Q) = 1 and Q*Q' = I // // WARNING: The rotation matrix is ROW MAJOR -template <typename T> inline -void QuaternionToScaledRotation(const T q[4], T R[3 * 3]); +template <typename T> +inline void QuaternionToScaledRotation(const T q[4], T R[3 * 3]); -template <typename T, int row_stride, int col_stride> inline -void QuaternionToScaledRotation( - const T q[4], - const MatrixAdapter<T, row_stride, col_stride>& R); +template <typename T, int row_stride, int col_stride> +inline void QuaternionToScaledRotation( + const T q[4], const MatrixAdapter<T, row_stride, col_stride>& R); // Same as above except that the rotation matrix is normalized by the // Frobenius norm, so that R * R' = I (and det(R) = 1). // // WARNING: The rotation matrix is ROW MAJOR -template <typename T> inline -void QuaternionToRotation(const T q[4], T R[3 * 3]); +template <typename T> +inline void QuaternionToRotation(const T q[4], T R[3 * 3]); -template <typename T, int row_stride, int col_stride> inline -void QuaternionToRotation( - const T q[4], - const MatrixAdapter<T, row_stride, col_stride>& R); +template <typename T, int row_stride, int col_stride> +inline void QuaternionToRotation( + const T q[4], const MatrixAdapter<T, row_stride, col_stride>& R); // Rotates a point pt by a quaternion q: // @@ -190,51 +184,51 @@ // // Inplace rotation is not supported. pt and result must point to different // memory locations, otherwise the result will be undefined. -template <typename T> inline -void UnitQuaternionRotatePoint(const T q[4], const T pt[3], T result[3]); +template <typename T> +inline void UnitQuaternionRotatePoint(const T q[4], const T pt[3], T result[3]); // With this function you do not need to assume that q has unit norm. // It does assume that the norm is non-zero. // // Inplace rotation is not supported. pt and result must point to different // memory locations, otherwise the result will be undefined. -template <typename T> inline -void QuaternionRotatePoint(const T q[4], const T pt[3], T result[3]); +template <typename T> +inline void QuaternionRotatePoint(const T q[4], const T pt[3], T result[3]); // zw = z * w, where * is the Quaternion product between 4 vectors. // // Inplace quaternion product is not supported. The resulting quaternion zw must // not share the memory with the input quaternion z and w, otherwise the result // will be undefined. -template<typename T> inline -void QuaternionProduct(const T z[4], const T w[4], T zw[4]); +template <typename T> +inline void QuaternionProduct(const T z[4], const T w[4], T zw[4]); // xy = x cross y; // -// Inplace cross product is not supported. The resulting vector x_cross_y must not -// share the memory with the input vectors x and y, otherwise the result will be -// undefined. -template<typename T> inline -void CrossProduct(const T x[3], const T y[3], T x_cross_y[3]); +// Inplace cross product is not supported. The resulting vector x_cross_y must +// not share the memory with the input vectors x and y, otherwise the result +// will be undefined. +template <typename T> +inline void CrossProduct(const T x[3], const T y[3], T x_cross_y[3]); -template<typename T> inline -T DotProduct(const T x[3], const T y[3]); +template <typename T> +inline T DotProduct(const T x[3], const T y[3]); // y = R(angle_axis) * x; // // Inplace rotation is not supported. pt and result must point to different // memory locations, otherwise the result will be undefined. -template<typename T> inline -void AngleAxisRotatePoint(const T angle_axis[3], const T pt[3], T result[3]); +template <typename T> +inline void AngleAxisRotatePoint(const T angle_axis[3], + const T pt[3], + T result[3]); // --- IMPLEMENTATION -template<typename T, int row_stride, int col_stride> +template <typename T, int row_stride, int col_stride> struct MatrixAdapter { T* pointer_; - explicit MatrixAdapter(T* pointer) - : pointer_(pointer) - {} + explicit MatrixAdapter(T* pointer) : pointer_(pointer) {} T& operator()(int r, int c) const { return pointer_[r * row_stride + c * col_stride]; @@ -251,7 +245,7 @@ return MatrixAdapter<T, 3, 1>(pointer); } -template<typename T> +template <typename T> inline void AngleAxisToQuaternion(const T* angle_axis, T* quaternion) { const T& a0 = angle_axis[0]; const T& a1 = angle_axis[1]; @@ -280,7 +274,7 @@ } } -template<typename T> +template <typename T> inline void QuaternionToAngleAxis(const T* quaternion, T* angle_axis) { const T& q1 = quaternion[1]; const T& q2 = quaternion[2]; @@ -307,9 +301,8 @@ // = atan(-sin(theta), -cos(theta)) // const T two_theta = - T(2.0) * ((cos_theta < T(0.0)) - ? atan2(-sin_theta, -cos_theta) - : atan2(sin_theta, cos_theta)); + T(2.0) * ((cos_theta < T(0.0)) ? atan2(-sin_theta, -cos_theta) + : atan2(sin_theta, cos_theta)); const T k = two_theta / sin_theta; angle_axis[0] = q1 * k; angle_axis[1] = q2 * k; @@ -335,8 +328,7 @@ // Ken Shoemake, 1987 SIGGRAPH course notes template <typename T, int row_stride, int col_stride> void RotationMatrixToQuaternion( - const MatrixAdapter<const T, row_stride, col_stride>& R, - T* quaternion) { + const MatrixAdapter<const T, row_stride, col_stride>& R, T* quaternion) { const T trace = R(0, 0) + R(1, 1) + R(2, 2); if (trace >= 0.0) { T t = sqrt(trace + T(1.0)); @@ -378,8 +370,7 @@ template <typename T, int row_stride, int col_stride> void RotationMatrixToAngleAxis( - const MatrixAdapter<const T, row_stride, col_stride>& R, - T* angle_axis) { + const MatrixAdapter<const T, row_stride, col_stride>& R, T* angle_axis) { T quaternion[4]; RotationMatrixToQuaternion(R, quaternion); QuaternionToAngleAxis(quaternion, angle_axis); @@ -393,8 +384,7 @@ template <typename T, int row_stride, int col_stride> void AngleAxisToRotationMatrix( - const T* angle_axis, - const MatrixAdapter<T, row_stride, col_stride>& R) { + const T* angle_axis, const MatrixAdapter<T, row_stride, col_stride>& R) { static const T kOne = T(1.0); const T theta2 = DotProduct(angle_axis, angle_axis); if (theta2 > T(std::numeric_limits<double>::epsilon())) { @@ -409,6 +399,7 @@ const T costheta = cos(theta); const T sintheta = sin(theta); + // clang-format off R(0, 0) = costheta + wx*wx*(kOne - costheta); R(1, 0) = wz*sintheta + wx*wy*(kOne - costheta); R(2, 0) = -wy*sintheta + wx*wz*(kOne - costheta); @@ -418,15 +409,16 @@ R(0, 2) = wy*sintheta + wx*wz*(kOne - costheta); R(1, 2) = -wx*sintheta + wy*wz*(kOne - costheta); R(2, 2) = costheta + wz*wz*(kOne - costheta); + // clang-format on } else { // Near zero, we switch to using the first order Taylor expansion. - R(0, 0) = kOne; - R(1, 0) = angle_axis[2]; + R(0, 0) = kOne; + R(1, 0) = angle_axis[2]; R(2, 0) = -angle_axis[1]; R(0, 1) = -angle_axis[2]; - R(1, 1) = kOne; - R(2, 1) = angle_axis[0]; - R(0, 2) = angle_axis[1]; + R(1, 1) = kOne; + R(2, 1) = angle_axis[0]; + R(0, 2) = angle_axis[1]; R(1, 2) = -angle_axis[0]; R(2, 2) = kOne; } @@ -441,8 +433,7 @@ template <typename T, int row_stride, int col_stride> void EulerAnglesToRotationMatrix( - const T* euler, - const MatrixAdapter<T, row_stride, col_stride>& R) { + const T* euler, const MatrixAdapter<T, row_stride, col_stride>& R) { const double kPi = 3.14159265358979323846; const T degrees_to_radians(kPi / 180.0); @@ -457,28 +448,27 @@ const T c3 = cos(pitch); const T s3 = sin(pitch); - R(0, 0) = c1*c2; - R(0, 1) = -s1*c3 + c1*s2*s3; - R(0, 2) = s1*s3 + c1*s2*c3; + R(0, 0) = c1 * c2; + R(0, 1) = -s1 * c3 + c1 * s2 * s3; + R(0, 2) = s1 * s3 + c1 * s2 * c3; - R(1, 0) = s1*c2; - R(1, 1) = c1*c3 + s1*s2*s3; - R(1, 2) = -c1*s3 + s1*s2*c3; + R(1, 0) = s1 * c2; + R(1, 1) = c1 * c3 + s1 * s2 * s3; + R(1, 2) = -c1 * s3 + s1 * s2 * c3; R(2, 0) = -s2; - R(2, 1) = c2*s3; - R(2, 2) = c2*c3; + R(2, 1) = c2 * s3; + R(2, 2) = c2 * c3; } -template <typename T> inline -void QuaternionToScaledRotation(const T q[4], T R[3 * 3]) { +template <typename T> +inline void QuaternionToScaledRotation(const T q[4], T R[3 * 3]) { QuaternionToScaledRotation(q, RowMajorAdapter3x3(R)); } -template <typename T, int row_stride, int col_stride> inline -void QuaternionToScaledRotation( - const T q[4], - const MatrixAdapter<T, row_stride, col_stride>& R) { +template <typename T, int row_stride, int col_stride> +inline void QuaternionToScaledRotation( + const T q[4], const MatrixAdapter<T, row_stride, col_stride>& R) { // Make convenient names for elements of q. T a = q[0]; T b = q[1]; @@ -497,22 +487,24 @@ T cd = c * d; T dd = d * d; - R(0, 0) = aa + bb - cc - dd; R(0, 1) = T(2) * (bc - ad); R(0, 2) = T(2) * (ac + bd); // NOLINT - R(1, 0) = T(2) * (ad + bc); R(1, 1) = aa - bb + cc - dd; R(1, 2) = T(2) * (cd - ab); // NOLINT - R(2, 0) = T(2) * (bd - ac); R(2, 1) = T(2) * (ab + cd); R(2, 2) = aa - bb - cc + dd; // NOLINT + // clang-format off + R(0, 0) = aa + bb - cc - dd; R(0, 1) = T(2) * (bc - ad); R(0, 2) = T(2) * (ac + bd); + R(1, 0) = T(2) * (ad + bc); R(1, 1) = aa - bb + cc - dd; R(1, 2) = T(2) * (cd - ab); + R(2, 0) = T(2) * (bd - ac); R(2, 1) = T(2) * (ab + cd); R(2, 2) = aa - bb - cc + dd; + // clang-format on } -template <typename T> inline -void QuaternionToRotation(const T q[4], T R[3 * 3]) { +template <typename T> +inline void QuaternionToRotation(const T q[4], T R[3 * 3]) { QuaternionToRotation(q, RowMajorAdapter3x3(R)); } -template <typename T, int row_stride, int col_stride> inline -void QuaternionToRotation(const T q[4], - const MatrixAdapter<T, row_stride, col_stride>& R) { +template <typename T, int row_stride, int col_stride> +inline void QuaternionToRotation( + const T q[4], const MatrixAdapter<T, row_stride, col_stride>& R) { QuaternionToScaledRotation(q, R); - T normalizer = q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]; + T normalizer = q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]; normalizer = T(1) / normalizer; for (int i = 0; i < 3; ++i) { @@ -522,10 +514,13 @@ } } -template <typename T> inline -void UnitQuaternionRotatePoint(const T q[4], const T pt[3], T result[3]) { +template <typename T> +inline void UnitQuaternionRotatePoint(const T q[4], + const T pt[3], + T result[3]) { DCHECK_NE(pt, result) << "Inplace rotation is not supported."; + // clang-format off const T t2 = q[0] * q[1]; const T t3 = q[0] * q[2]; const T t4 = q[0] * q[3]; @@ -538,43 +533,44 @@ result[0] = T(2) * ((t8 + t1) * pt[0] + (t6 - t4) * pt[1] + (t3 + t7) * pt[2]) + pt[0]; // NOLINT result[1] = T(2) * ((t4 + t6) * pt[0] + (t5 + t1) * pt[1] + (t9 - t2) * pt[2]) + pt[1]; // NOLINT result[2] = T(2) * ((t7 - t3) * pt[0] + (t2 + t9) * pt[1] + (t5 + t8) * pt[2]) + pt[2]; // NOLINT + // clang-format on } -template <typename T> inline -void QuaternionRotatePoint(const T q[4], const T pt[3], T result[3]) { +template <typename T> +inline void QuaternionRotatePoint(const T q[4], const T pt[3], T result[3]) { DCHECK_NE(pt, result) << "Inplace rotation is not supported."; // 'scale' is 1 / norm(q). - const T scale = T(1) / sqrt(q[0] * q[0] + - q[1] * q[1] + - q[2] * q[2] + - q[3] * q[3]); + const T scale = + T(1) / sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]); // Make unit-norm version of q. const T unit[4] = { - scale * q[0], - scale * q[1], - scale * q[2], - scale * q[3], + scale * q[0], + scale * q[1], + scale * q[2], + scale * q[3], }; UnitQuaternionRotatePoint(unit, pt, result); } -template<typename T> inline -void QuaternionProduct(const T z[4], const T w[4], T zw[4]) { +template <typename T> +inline void QuaternionProduct(const T z[4], const T w[4], T zw[4]) { DCHECK_NE(z, zw) << "Inplace quaternion product is not supported."; DCHECK_NE(w, zw) << "Inplace quaternion product is not supported."; + // clang-format off zw[0] = z[0] * w[0] - z[1] * w[1] - z[2] * w[2] - z[3] * w[3]; zw[1] = z[0] * w[1] + z[1] * w[0] + z[2] * w[3] - z[3] * w[2]; zw[2] = z[0] * w[2] - z[1] * w[3] + z[2] * w[0] + z[3] * w[1]; zw[3] = z[0] * w[3] + z[1] * w[2] - z[2] * w[1] + z[3] * w[0]; + // clang-format on } // xy = x cross y; -template<typename T> inline -void CrossProduct(const T x[3], const T y[3], T x_cross_y[3]) { +template <typename T> +inline void CrossProduct(const T x[3], const T y[3], T x_cross_y[3]) { DCHECK_NE(x, x_cross_y) << "Inplace cross product is not supported."; DCHECK_NE(y, x_cross_y) << "Inplace cross product is not supported."; @@ -583,13 +579,15 @@ x_cross_y[2] = x[0] * y[1] - x[1] * y[0]; } -template<typename T> inline -T DotProduct(const T x[3], const T y[3]) { +template <typename T> +inline T DotProduct(const T x[3], const T y[3]) { return (x[0] * y[0] + x[1] * y[1] + x[2] * y[2]); } -template<typename T> inline -void AngleAxisRotatePoint(const T angle_axis[3], const T pt[3], T result[3]) { +template <typename T> +inline void AngleAxisRotatePoint(const T angle_axis[3], + const T pt[3], + T result[3]) { DCHECK_NE(pt, result) << "Inplace rotation is not supported."; const T theta2 = DotProduct(angle_axis, angle_axis); @@ -609,15 +607,15 @@ const T sintheta = sin(theta); const T theta_inverse = T(1.0) / theta; - const T w[3] = { angle_axis[0] * theta_inverse, - angle_axis[1] * theta_inverse, - angle_axis[2] * theta_inverse }; + const T w[3] = {angle_axis[0] * theta_inverse, + angle_axis[1] * theta_inverse, + angle_axis[2] * theta_inverse}; // Explicitly inlined evaluation of the cross product for // performance reasons. - const T w_cross_pt[3] = { w[1] * pt[2] - w[2] * pt[1], - w[2] * pt[0] - w[0] * pt[2], - w[0] * pt[1] - w[1] * pt[0] }; + const T w_cross_pt[3] = {w[1] * pt[2] - w[2] * pt[1], + w[2] * pt[0] - w[0] * pt[2], + w[0] * pt[1] - w[1] * pt[0]}; const T tmp = (w[0] * pt[0] + w[1] * pt[1] + w[2] * pt[2]) * (T(1.0) - costheta); @@ -642,9 +640,9 @@ // // Explicitly inlined evaluation of the cross product for // performance reasons. - const T w_cross_pt[3] = { angle_axis[1] * pt[2] - angle_axis[2] * pt[1], - angle_axis[2] * pt[0] - angle_axis[0] * pt[2], - angle_axis[0] * pt[1] - angle_axis[1] * pt[0] }; + const T w_cross_pt[3] = {angle_axis[1] * pt[2] - angle_axis[2] * pt[1], + angle_axis[2] * pt[0] - angle_axis[0] * pt[2], + angle_axis[0] * pt[1] - angle_axis[1] * pt[0]}; result[0] = pt[0] + w_cross_pt[0]; result[1] = pt[1] + w_cross_pt[1];
diff --git a/include/ceres/sized_cost_function.h b/include/ceres/sized_cost_function.h index 50d0363..8e92f1b 100644 --- a/include/ceres/sized_cost_function.h +++ b/include/ceres/sized_cost_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -53,7 +53,7 @@ static_assert(internal::StaticParameterDims<Ns...>::kIsValid, "Invalid parameter block dimension detected. Each parameter " "block dimension must be bigger than zero."); - + using ParameterDims = internal::StaticParameterDims<Ns...>; SizedCostFunction() { @@ -61,7 +61,7 @@ *mutable_parameter_block_sizes() = std::vector<int32_t>{Ns...}; } - virtual ~SizedCostFunction() { } + virtual ~SizedCostFunction() {} // Subclasses must implement Evaluate(). };
diff --git a/include/ceres/solver.h b/include/ceres/solver.h index ab7e9c2..47b9850 100644 --- a/include/ceres/solver.h +++ b/include/ceres/solver.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -36,12 +36,13 @@ #include <string> #include <unordered_set> #include <vector> + #include "ceres/crs_matrix.h" -#include "ceres/problem.h" #include "ceres/internal/disable_warnings.h" #include "ceres/internal/port.h" #include "ceres/iteration_callback.h" #include "ceres/ordered_groups.h" +#include "ceres/problem.h" #include "ceres/types.h" namespace ceres { @@ -1051,7 +1052,8 @@ }; // Helper function which avoids going through the interface. -CERES_EXPORT void Solve(const Solver::Options& options, Problem* problem, +CERES_EXPORT void Solve(const Solver::Options& options, + Problem* problem, Solver::Summary* summary); } // namespace ceres
diff --git a/include/ceres/tiny_solver.h b/include/ceres/tiny_solver.h index e5e70b3..47db582 100644 --- a/include/ceres/tiny_solver.h +++ b/include/ceres/tiny_solver.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2017 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -124,11 +124,11 @@ // // int NumParameters() const; // -template<typename Function, - typename LinearSolver = Eigen::LDLT< - Eigen::Matrix<typename Function::Scalar, - Function::NUM_PARAMETERS, - Function::NUM_PARAMETERS>>> +template <typename Function, + typename LinearSolver = + Eigen::LDLT<Eigen::Matrix<typename Function::Scalar, + Function::NUM_PARAMETERS, + Function::NUM_PARAMETERS>>> class TinySolver { public: // This class needs to have an Eigen aligned operator new as it contains @@ -168,7 +168,7 @@ Status status = HIT_MAX_ITERATIONS; }; - bool Update(const Function& function, const Parameters &x) { + bool Update(const Function& function, const Parameters& x) { if (!function(x.data(), error_.data(), jacobian_.data())) { return false; }
diff --git a/include/ceres/tiny_solver_autodiff_function.h b/include/ceres/tiny_solver_autodiff_function.h index 7ed752a..b782f54 100644 --- a/include/ceres/tiny_solver_autodiff_function.h +++ b/include/ceres/tiny_solver_autodiff_function.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2017 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -37,8 +37,8 @@ #include <memory> #include <type_traits> -#include "Eigen/Core" +#include "Eigen/Core" #include "ceres/jet.h" #include "ceres/types.h" // For kImpossibleValue. @@ -103,10 +103,10 @@ // solver.Solve(f, &x); // // WARNING: The cost function adapter is not thread safe. -template<typename CostFunctor, - int kNumResiduals, - int kNumParameters, - typename T = double> +template <typename CostFunctor, + int kNumResiduals, + int kNumParameters, + typename T = double> class TinySolverAutoDiffFunction { public: // This class needs to have an Eigen aligned operator new as it contains @@ -126,9 +126,7 @@ // This is similar to AutoDifferentiate(), but since there is only one // parameter block it is easier to inline to avoid overhead. - bool operator()(const T* parameters, - T* residuals, - T* jacobian) const { + bool operator()(const T* parameters, T* residuals, T* jacobian) const { if (jacobian == NULL) { // No jacobian requested, so just directly call the cost function with // doubles, skipping jets and derivatives. @@ -154,9 +152,7 @@ // Copy the jacobian out of the derivative part of the residual jets. Eigen::Map<Eigen::Matrix<T, kNumResiduals, kNumParameters>> jacobian_matrix( - jacobian, - num_residuals_, - kNumParameters); + jacobian, num_residuals_, kNumParameters); for (int r = 0; r < num_residuals_; ++r) { residuals[r] = jet_residuals_[r].a; // Note that while this looks like a fast vectorized write, in practice it @@ -190,7 +186,7 @@ // The number of residuals is dynamically sized and the number of // parameters is statically sized. - template<int R> + template <int R> typename std::enable_if<(R == Eigen::Dynamic), void>::type Initialize( const CostFunctor& function) { jet_residuals_.resize(function.NumResiduals()); @@ -198,7 +194,7 @@ } // The number of parameters and residuals are statically sized. - template<int R> + template <int R> typename std::enable_if<(R != Eigen::Dynamic), void>::type Initialize( const CostFunctor& /* function */) { num_residuals_ = kNumResiduals;
diff --git a/include/ceres/tiny_solver_cost_function_adapter.h b/include/ceres/tiny_solver_cost_function_adapter.h index 63ac6c6..18ccb39 100644 --- a/include/ceres/tiny_solver_cost_function_adapter.h +++ b/include/ceres/tiny_solver_cost_function_adapter.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2017 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -28,7 +28,6 @@ // // Author: sameeragarwal@google.com (Sameer Agarwal) - #ifndef CERES_PUBLIC_TINY_SOLVER_COST_FUNCTION_ADAPTER_H_ #define CERES_PUBLIC_TINY_SOLVER_COST_FUNCTION_ADAPTER_H_
diff --git a/include/ceres/types.h b/include/ceres/types.h index ed448b2..3a19b73 100644 --- a/include/ceres/types.h +++ b/include/ceres/types.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -39,8 +39,8 @@ #include <string> -#include "ceres/internal/port.h" #include "ceres/internal/disable_warnings.h" +#include "ceres/internal/port.h" namespace ceres {
diff --git a/include/ceres/version.h b/include/ceres/version.h index 20fbe22..50aa212 100644 --- a/include/ceres/version.h +++ b/include/ceres/version.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2015 Google Inc. All rights reserved. +// Copyright 2019 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without