From 8fe8ebc3a67041e91504338d16862ba3cc4c7e14 Mon Sep 17 00:00:00 2001 From: Sameer Agarwal Date: Fri, 18 Feb 2022 15:51:17 -0800 Subject: [PATCH] Add final specifier to public classes Change-Id: Ib7291dc68d5d4141ee821689743481fc84768606 --- include/ceres/autodiff_cost_function.h | 5 +++-- include/ceres/autodiff_first_order_function.h | 5 ++--- include/ceres/autodiff_manifold.h | 5 ++--- include/ceres/conditioned_cost_function.h | 2 +- .../ceres/dynamic_autodiff_cost_function.h | 2 +- .../dynamic_numeric_diff_cost_function.h | 2 +- include/ceres/loss_function.h | 20 +++++++++---------- include/ceres/manifold.h | 14 ++++++------- include/ceres/normal_prior.h | 2 +- include/ceres/numeric_diff_cost_function.h | 5 +++-- .../ceres/numeric_diff_first_order_function.h | 5 ++--- 11 files changed, 33 insertions(+), 34 deletions(-) diff --git a/include/ceres/autodiff_cost_function.h b/include/ceres/autodiff_cost_function.h index 993daf159..c080fef96 100644 --- a/include/ceres/autodiff_cost_function.h +++ b/include/ceres/autodiff_cost_function.h @@ -151,7 +151,8 @@ namespace ceres { template // Number of parameters in each parameter block. -class AutoDiffCostFunction : public SizedCostFunction { +class AutoDiffCostFunction final + : public SizedCostFunction { public: // Takes ownership of functor by default. Uses the template-provided // value for the number of residuals ("kNumResiduals"). @@ -215,7 +216,7 @@ class AutoDiffCostFunction : public SizedCostFunction { jacobians); }; - const CostFunctor & functor() const { return *functor_; } + const CostFunctor& functor() const { return *functor_; } private: std::unique_ptr functor_; diff --git a/include/ceres/autodiff_first_order_function.h b/include/ceres/autodiff_first_order_function.h index 4ace559a3..5a51952ed 100644 --- a/include/ceres/autodiff_first_order_function.h +++ b/include/ceres/autodiff_first_order_function.h @@ -102,7 +102,7 @@ namespace ceres { // seen where instead of using a_ directly, a_ is wrapped with T(a_). template -class AutoDiffFirstOrderFunction : public FirstOrderFunction { +class AutoDiffFirstOrderFunction final : public FirstOrderFunction { public: // Takes ownership of functor. explicit AutoDiffFirstOrderFunction(FirstOrderFunctor* functor) @@ -110,7 +110,6 @@ class AutoDiffFirstOrderFunction : public FirstOrderFunction { static_assert(kNumParameters > 0, "kNumParameters must be positive"); } - bool Evaluate(const double* const parameters, double* cost, double* gradient) const override { @@ -141,7 +140,7 @@ class AutoDiffFirstOrderFunction : public FirstOrderFunction { int NumParameters() const override { return kNumParameters; } - const FirstOrderFunctor & functor() const { return *functor_; } + const FirstOrderFunctor& functor() const { return *functor_; } private: std::unique_ptr functor_; diff --git a/include/ceres/autodiff_manifold.h b/include/ceres/autodiff_manifold.h index 7b5f63966..978e13e7f 100644 --- a/include/ceres/autodiff_manifold.h +++ b/include/ceres/autodiff_manifold.h @@ -145,14 +145,13 @@ namespace ceres { // Manifold* manifold = new AutoDiffManifold; template -class AutoDiffManifold : public Manifold { +class AutoDiffManifold final : public Manifold { public: AutoDiffManifold() : functor_(std::make_unique()) {} // Takes ownership of functor. explicit AutoDiffManifold(Functor* functor) : functor_(functor) {} - int AmbientSize() const override { return kAmbientSize; } int TangentSize() const override { return kTangentSize; } @@ -172,7 +171,7 @@ class AutoDiffManifold : public Manifold { bool MinusJacobian(const double* x, double* jacobian) const override; - const Functor & functor() const { return *functor_; } + const Functor& functor() const { return *functor_; } private: std::unique_ptr functor_; diff --git a/include/ceres/conditioned_cost_function.h b/include/ceres/conditioned_cost_function.h index e80728d0b..e4c3decbf 100644 --- a/include/ceres/conditioned_cost_function.h +++ b/include/ceres/conditioned_cost_function.h @@ -71,7 +71,7 @@ namespace ceres { // ccf_residual[i] = f_i(my_cost_function_residual[i]) // // and the Jacobian will be affected appropriately. -class CERES_EXPORT ConditionedCostFunction : public CostFunction { +class CERES_EXPORT ConditionedCostFunction final : public CostFunction { public: // Builds a cost function based on a wrapped cost function, and a // per-residual conditioner. Takes ownership of all of the wrapped cost diff --git a/include/ceres/dynamic_autodiff_cost_function.h b/include/ceres/dynamic_autodiff_cost_function.h index 28129565c..d72be6d20 100644 --- a/include/ceres/dynamic_autodiff_cost_function.h +++ b/include/ceres/dynamic_autodiff_cost_function.h @@ -77,7 +77,7 @@ namespace ceres { // pass. There is a tradeoff with the size of the passes; you may want // to experiment with the stride. template -class DynamicAutoDiffCostFunction : public DynamicCostFunction { +class DynamicAutoDiffCostFunction final : public DynamicCostFunction { public: // Takes ownership by default. DynamicAutoDiffCostFunction(CostFunctor* functor, diff --git a/include/ceres/dynamic_numeric_diff_cost_function.h b/include/ceres/dynamic_numeric_diff_cost_function.h index 9cbc8ee28..793fb0554 100644 --- a/include/ceres/dynamic_numeric_diff_cost_function.h +++ b/include/ceres/dynamic_numeric_diff_cost_function.h @@ -77,7 +77,7 @@ namespace ceres { // cost_function.AddParameterBlock(10); // cost_function.SetNumResiduals(21); template -class DynamicNumericDiffCostFunction : public DynamicCostFunction { +class DynamicNumericDiffCostFunction final : public DynamicCostFunction { public: explicit DynamicNumericDiffCostFunction( const CostFunctor* functor, diff --git a/include/ceres/loss_function.h b/include/ceres/loss_function.h index fc6f358b0..8a5a37ff6 100644 --- a/include/ceres/loss_function.h +++ b/include/ceres/loss_function.h @@ -129,7 +129,7 @@ class CERES_EXPORT LossFunction { // It is not normally necessary to use this, as passing nullptr for the // loss function when building the problem accomplishes the same // thing. -class CERES_EXPORT TrivialLoss : public LossFunction { +class CERES_EXPORT TrivialLoss final : public LossFunction { public: void Evaluate(double, double*) const override; }; @@ -172,7 +172,7 @@ class CERES_EXPORT TrivialLoss : public LossFunction { // // The scaling parameter 'a' corresponds to 'delta' on this page: // http://en.wikipedia.org/wiki/Huber_Loss_Function -class CERES_EXPORT HuberLoss : public LossFunction { +class CERES_EXPORT HuberLoss final : public LossFunction { public: explicit HuberLoss(double a) : a_(a), b_(a * a) {} void Evaluate(double, double*) const override; @@ -188,7 +188,7 @@ class CERES_EXPORT HuberLoss : public LossFunction { // rho(s) = 2 (sqrt(1 + s) - 1). // // At s = 0: rho = [0, 1, -1 / (2 * a^2)]. -class CERES_EXPORT SoftLOneLoss : public LossFunction { +class CERES_EXPORT SoftLOneLoss final : public LossFunction { public: explicit SoftLOneLoss(double a) : b_(a * a), c_(1 / b_) {} void Evaluate(double, double*) const override; @@ -205,7 +205,7 @@ class CERES_EXPORT SoftLOneLoss : public LossFunction { // rho(s) = log(1 + s). // // At s = 0: rho = [0, 1, -1 / a^2]. -class CERES_EXPORT CauchyLoss : public LossFunction { +class CERES_EXPORT CauchyLoss final : public LossFunction { public: explicit CauchyLoss(double a) : b_(a * a), c_(1 / b_) {} void Evaluate(double, double*) const override; @@ -226,7 +226,7 @@ class CERES_EXPORT CauchyLoss : public LossFunction { // rho(s) = a atan(s / a). // // At s = 0: rho = [0, 1, 0]. -class CERES_EXPORT ArctanLoss : public LossFunction { +class CERES_EXPORT ArctanLoss final : public LossFunction { public: explicit ArctanLoss(double a) : a_(a), b_(1 / (a * a)) {} void Evaluate(double, double*) const override; @@ -265,7 +265,7 @@ class CERES_EXPORT ArctanLoss : public LossFunction { // concentrated in the range a - b to a + b. // // At s = 0: rho = [0, ~0, ~0]. -class CERES_EXPORT TolerantLoss : public LossFunction { +class CERES_EXPORT TolerantLoss final : public LossFunction { public: explicit TolerantLoss(double a, double b); void Evaluate(double, double*) const override; @@ -284,7 +284,7 @@ class CERES_EXPORT TolerantLoss : public LossFunction { // rho(s) = a^2 / 3 for s > a^2. // // At s = 0: rho = [0, 1, -2 / a^2] -class CERES_EXPORT TukeyLoss : public ceres::LossFunction { +class CERES_EXPORT TukeyLoss final : public ceres::LossFunction { public: explicit TukeyLoss(double a) : a_squared_(a * a) {} void Evaluate(double, double*) const override; @@ -296,7 +296,7 @@ class CERES_EXPORT TukeyLoss : public ceres::LossFunction { // Composition of two loss functions. The error is the result of first // evaluating g followed by f to yield the composition f(g(s)). // The loss functions must not be nullptr. -class CERES_EXPORT ComposedLoss : public LossFunction { +class CERES_EXPORT ComposedLoss final : public LossFunction { public: explicit ComposedLoss(const LossFunction* f, Ownership ownership_f, @@ -327,7 +327,7 @@ class CERES_EXPORT ComposedLoss : public LossFunction { // function, rho = nullptr is a valid input and will result in the input // being scaled by a. This provides a simple way of implementing a // scaled ResidualBlock. -class CERES_EXPORT ScaledLoss : public LossFunction { +class CERES_EXPORT ScaledLoss final : public LossFunction { public: // Constructs a ScaledLoss wrapping another loss function. Takes // ownership of the wrapped loss function or not depending on the @@ -389,7 +389,7 @@ class CERES_EXPORT ScaledLoss : public LossFunction { // // Solve(options, &problem, &summary) // -class CERES_EXPORT LossFunctionWrapper : public LossFunction { +class CERES_EXPORT LossFunctionWrapper final : public LossFunction { public: LossFunctionWrapper(LossFunction* rho, Ownership ownership) : rho_(rho), ownership_(ownership) {} diff --git a/include/ceres/manifold.h b/include/ceres/manifold.h index a3ec9df30..964baec78 100644 --- a/include/ceres/manifold.h +++ b/include/ceres/manifold.h @@ -223,7 +223,7 @@ class CERES_EXPORT Manifold { // subtraction: // Plus(x, delta) = x + delta // Minus(y, x) = y - x. -class CERES_EXPORT EuclideanManifold : public Manifold { +class CERES_EXPORT EuclideanManifold final : public Manifold { public: EuclideanManifold(int size); int AmbientSize() const override; @@ -246,7 +246,7 @@ class CERES_EXPORT EuclideanManifold : public Manifold { }; // Hold a subset of the parameters inside a parameter block constant. -class CERES_EXPORT SubsetManifold : public Manifold { +class CERES_EXPORT SubsetManifold final : public Manifold { public: SubsetManifold(int size, const std::vector& constant_parameters); int AmbientSize() const override; @@ -281,7 +281,7 @@ class CERES_EXPORT SubsetManifold : public Manifold { // // is the manifold for a rigid transformation, where the rotation is represented // using a quaternion. -class CERES_EXPORT ProductManifold : public Manifold { +class CERES_EXPORT ProductManifold final : public Manifold { public: ProductManifold(const ProductManifold&) = delete; ProductManifold& operator=(const ProductManifold&) = delete; @@ -357,7 +357,7 @@ class CERES_EXPORT ProductManifold : public Manifold { // (|q|=1), q^-1 = [q0; -q1; -q2; -q3] // // and to_delta( [q0; u_{3x1}] ) = u / |u| * atan2(|u|, q0) -class CERES_EXPORT QuaternionManifold : public Manifold { +class CERES_EXPORT QuaternionManifold final : public Manifold { public: int AmbientSize() const override { return 4; } int TangentSize() const override { return 3; } @@ -381,7 +381,7 @@ class CERES_EXPORT QuaternionManifold : public Manifold { // // Since Ceres operates on parameter blocks which are raw double pointers this // difference is important and requires a different manifold. -class CERES_EXPORT EigenQuaternionManifold : public Manifold { +class CERES_EXPORT EigenQuaternionManifold final : public Manifold { public: int AmbientSize() const override { return 4; } int TangentSize() const override { return 3; } @@ -431,7 +431,7 @@ class CERES_EXPORT EigenQuaternionManifold : public Manifold { // Hertzberg, R. Wagner, U. Frese and L. Schroder for more details // (https://arxiv.org/pdf/1107.1119.pdf) template -class SphereManifold : public Manifold { +class SphereManifold final : public Manifold { public: static_assert( AmbientSpaceDimension == DYNAMIC || AmbientSpaceDimension > 1, @@ -502,7 +502,7 @@ class SphereManifold : public Manifold { // LineManifold manifold(ambient_dim); // template -class LineManifold : public Manifold { +class LineManifold final : public Manifold { public: static_assert(AmbientSpaceDimension == DYNAMIC || AmbientSpaceDimension >= 2, "The ambient space must be at least 2."); diff --git a/include/ceres/normal_prior.h b/include/ceres/normal_prior.h index 14ab379f4..c5c7f3e62 100644 --- a/include/ceres/normal_prior.h +++ b/include/ceres/normal_prior.h @@ -57,7 +57,7 @@ namespace ceres { // which would be the case if the covariance matrix S is rank // deficient. -class CERES_EXPORT NormalPrior : public CostFunction { +class CERES_EXPORT NormalPrior final : 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. diff --git a/include/ceres/numeric_diff_cost_function.h b/include/ceres/numeric_diff_cost_function.h index f147b160d..7235327af 100644 --- a/include/ceres/numeric_diff_cost_function.h +++ b/include/ceres/numeric_diff_cost_function.h @@ -179,7 +179,8 @@ template // Parameters dimensions for each block. -class NumericDiffCostFunction : public SizedCostFunction { +class NumericDiffCostFunction final + : public SizedCostFunction { public: NumericDiffCostFunction( CostFunctor* functor, @@ -246,7 +247,7 @@ class NumericDiffCostFunction : public SizedCostFunction { return true; } - const CostFunctor & functor() const { return *functor_; } + const CostFunctor& functor() const { return *functor_; } private: std::unique_ptr functor_; diff --git a/include/ceres/numeric_diff_first_order_function.h b/include/ceres/numeric_diff_first_order_function.h index cd24c969c..5841765b1 100644 --- a/include/ceres/numeric_diff_first_order_function.h +++ b/include/ceres/numeric_diff_first_order_function.h @@ -43,7 +43,6 @@ #include "ceres/numeric_diff_options.h" #include "ceres/types.h" - namespace ceres { // Creates FirstOrderFunctions as needed by the GradientProblem @@ -103,7 +102,7 @@ namespace ceres { template -class NumericDiffFirstOrderFunction : public FirstOrderFunction { +class NumericDiffFirstOrderFunction final : public FirstOrderFunction { public: NumericDiffFirstOrderFunction( FirstOrderFunctor* functor, @@ -151,7 +150,7 @@ class NumericDiffFirstOrderFunction : public FirstOrderFunction { int NumParameters() const override { return kNumParameters; } - const FirstOrderFunctor & functor() const { return *functor_; } + const FirstOrderFunctor& functor() const { return *functor_; } private: std::unique_ptr functor_;