diff --git a/gtsam/linear/HessianFactor.h b/gtsam/linear/HessianFactor.h index f0c79d8fb..d1c362a54 100644 --- a/gtsam/linear/HessianFactor.h +++ b/gtsam/linear/HessianFactor.h @@ -186,25 +186,28 @@ namespace gtsam { virtual ~HessianFactor() {} /** Clone this HessianFactor */ - virtual GaussianFactor::shared_ptr clone() const { + GaussianFactor::shared_ptr clone() const override { return boost::make_shared(*this); } /** Print the factor for debugging and testing (implementing Testable) */ - virtual void print(const std::string& s = "", - const KeyFormatter& formatter = DefaultKeyFormatter) const; + void print(const std::string& s = "", + const KeyFormatter& formatter = DefaultKeyFormatter) const override; /** Compare to another factor for testing (implementing Testable) */ - virtual bool equals(const GaussianFactor& lf, double tol = 1e-9) const; + bool equals(const GaussianFactor& lf, double tol = 1e-9) const override; - /** Evaluate the factor error f(x), see above. */ - virtual double error(const VectorValues& c) const; /** 0.5*[x -1]'*H*[x -1] (also see constructor documentation) */ + /** + * Evaluate the factor error f(x). + * returns 0.5*[x -1]'*H*[x -1] (also see constructor documentation) + */ + double error(const VectorValues& c) const override; /** Return the dimension of the variable pointed to by the given key iterator * todo: Remove this in favor of keeping track of dimensions with variables? * @param variable An iterator pointing to the slot in this factor. You can * use, for example, begin() + 2 to get the 3rd variable in this factor. */ - virtual DenseIndex getDim(const_iterator variable) const { + DenseIndex getDim(const_iterator variable) const override { return info_.getDim(std::distance(begin(), variable)); } @@ -216,10 +219,10 @@ namespace gtsam { * stored stored in this factor. * @return a HessianFactor with negated Hessian matrices */ - virtual GaussianFactor::shared_ptr negate() const; + GaussianFactor::shared_ptr negate() const override; /** Check if the factor is empty. TODO: How should this be defined? */ - virtual bool empty() const { return size() == 0 /*|| rows() == 0*/; } + bool empty() const override { return size() == 0 /*|| rows() == 0*/; } /** Return the constant term \f$ f \f$ as described above * @return The constant term \f$ f \f$ @@ -280,7 +283,7 @@ namespace gtsam { * representation of the augmented information matrix, which stores only the * upper triangle. */ - virtual Matrix augmentedInformation() const; + Matrix augmentedInformation() const override; /// Return self-adjoint view onto the information matrix (NOT augmented). Eigen::SelfAdjointView informationView() const; @@ -288,33 +291,33 @@ namespace gtsam { /** Return the non-augmented information matrix represented by this * GaussianFactor. */ - virtual Matrix information() const; + Matrix information() const override; /// Return the diagonal of the Hessian for this factor - virtual VectorValues hessianDiagonal() const; + VectorValues hessianDiagonal() const override; /// Raw memory access version of hessianDiagonal - virtual void hessianDiagonal(double* d) const; + void hessianDiagonal(double* d) const override; /// Return the block diagonal of the Hessian for this factor - virtual std::map hessianBlockDiagonal() const; + std::map hessianBlockDiagonal() const override; /// Return (dense) matrix associated with factor - virtual std::pair jacobian() const; + std::pair jacobian() const override; /** * Return (dense) matrix associated with factor * The returned system is an augmented matrix: [A b] * @param set weight to use whitening to bake in weights */ - virtual Matrix augmentedJacobian() const; + Matrix augmentedJacobian() const override; /** Update an information matrix by adding the information corresponding to this factor * (used internally during elimination). * @param keys THe ordered vector of keys for the information matrix to be updated * @param info The information matrix to be updated */ - void updateHessian(const KeyVector& keys, SymmetricBlockMatrix* info) const; + void updateHessian(const KeyVector& keys, SymmetricBlockMatrix* info) const override; /** Update another Hessian factor * @param other the HessianFactor to be updated @@ -325,19 +328,19 @@ namespace gtsam { } /** y += alpha * A'*A*x */ - void multiplyHessianAdd(double alpha, const VectorValues& x, VectorValues& y) const; + void multiplyHessianAdd(double alpha, const VectorValues& x, VectorValues& y) const override; /// eta for Hessian - VectorValues gradientAtZero() const; + VectorValues gradientAtZero() const override; /// Raw memory access version of gradientAtZero - virtual void gradientAtZero(double* d) const; + void gradientAtZero(double* d) const override; /** * Compute the gradient at a key: * \grad f(x_i) = \sum_j G_ij*x_j - g_i */ - Vector gradient(Key key, const VectorValues& x) const; + Vector gradient(Key key, const VectorValues& x) const override; /** * In-place elimination that returns a conditional on (ordered) keys specified, and leaves diff --git a/gtsam/linear/JacobianFactor.h b/gtsam/linear/JacobianFactor.h index 53ce4b9ca..fad05a729 100644 --- a/gtsam/linear/JacobianFactor.h +++ b/gtsam/linear/JacobianFactor.h @@ -186,19 +186,19 @@ namespace gtsam { virtual ~JacobianFactor() {} /** Clone this JacobianFactor */ - virtual GaussianFactor::shared_ptr clone() const { + GaussianFactor::shared_ptr clone() const override { return boost::static_pointer_cast( boost::make_shared(*this)); } // Implementing Testable interface - virtual void print(const std::string& s = "", - const KeyFormatter& formatter = DefaultKeyFormatter) const; - virtual bool equals(const GaussianFactor& lf, double tol = 1e-9) const; + void print(const std::string& s = "", + const KeyFormatter& formatter = DefaultKeyFormatter) const override; + bool equals(const GaussianFactor& lf, double tol = 1e-9) const override; Vector unweighted_error(const VectorValues& c) const; /** (A*x-b) */ Vector error_vector(const VectorValues& c) const; /** (A*x-b)/sigma */ - virtual double error(const VectorValues& c) const; /** 0.5*(A*x-b)'*D*(A*x-b) */ + double error(const VectorValues& c) const override; /** 0.5*(A*x-b)'*D*(A*x-b) */ /** Return the augmented information matrix represented by this GaussianFactor. * The augmented information matrix contains the information matrix with an @@ -208,26 +208,26 @@ namespace gtsam { * augmented information matrix is described in more detail in HessianFactor, * which in fact stores an augmented information matrix. */ - virtual Matrix augmentedInformation() const; + Matrix augmentedInformation() const override; /** Return the non-augmented information matrix represented by this * GaussianFactor. */ - virtual Matrix information() const; + Matrix information() const override; /// Return the diagonal of the Hessian for this factor - virtual VectorValues hessianDiagonal() const; + VectorValues hessianDiagonal() const override; /// Raw memory access version of hessianDiagonal - virtual void hessianDiagonal(double* d) const; + void hessianDiagonal(double* d) const override; /// Return the block diagonal of the Hessian for this factor - virtual std::map hessianBlockDiagonal() const; + std::map hessianBlockDiagonal() const override; /** * @brief Returns (dense) A,b pair associated with factor, bakes in the weights */ - virtual std::pair jacobian() const; + std::pair jacobian() const override; /** * @brief Returns (dense) A,b pair associated with factor, does not bake in weights @@ -237,7 +237,7 @@ namespace gtsam { /** Return (dense) matrix associated with factor. The returned system is an augmented matrix: * [A b] * weights are baked in */ - virtual Matrix augmentedJacobian() const; + Matrix augmentedJacobian() const override; /** Return (dense) matrix associated with factor. The returned system is an augmented matrix: * [A b] @@ -255,10 +255,10 @@ namespace gtsam { * stored stored in this factor. * @return a HessianFactor with negated Hessian matrices */ - virtual GaussianFactor::shared_ptr negate() const; + GaussianFactor::shared_ptr negate() const override; /** Check if the factor is empty. TODO: How should this be defined? */ - virtual bool empty() const { return size() == 0 /*|| rows() == 0*/; } + bool empty() const override { return size() == 0 /*|| rows() == 0*/; } /** is noise model constrained ? */ bool isConstrained() const { @@ -268,7 +268,9 @@ namespace gtsam { /** Return the dimension of the variable pointed to by the given key iterator * todo: Remove this in favor of keeping track of dimensions with variables? */ - virtual DenseIndex getDim(const_iterator variable) const { return Ab_(variable - begin()).cols(); } + DenseIndex getDim(const_iterator variable) const override { + return Ab_(variable - begin()).cols(); + } /** * return the number of rows in the corresponding linear system @@ -309,17 +311,19 @@ namespace gtsam { * @param scatter A mapping from variable index to slot index in this HessianFactor * @param info The information matrix to be updated */ - void updateHessian(const KeyVector& keys, SymmetricBlockMatrix* info) const; + void updateHessian(const KeyVector& keys, SymmetricBlockMatrix* info) const override; /** Return A*x */ Vector operator*(const VectorValues& x) const; - /** x += A'*e. If x is initially missing any values, they are created and assumed to start as - * zero vectors. */ - void transposeMultiplyAdd(double alpha, const Vector& e, VectorValues& x) const; + /** x += alpha * A'*e. If x is initially missing any values, they are + * created and assumed to start as zero vectors. */ + void transposeMultiplyAdd(double alpha, const Vector& e, + VectorValues& x) const; /** y += alpha * A'*A*x */ - void multiplyHessianAdd(double alpha, const VectorValues& x, VectorValues& y) const; + void multiplyHessianAdd(double alpha, const VectorValues& x, + VectorValues& y) const override; /** * Raw memory access version of multiplyHessianAdd y += alpha * A'*A*x @@ -333,13 +337,13 @@ namespace gtsam { const std::vector& accumulatedDims) const; /// A'*b for Jacobian - VectorValues gradientAtZero() const; + VectorValues gradientAtZero() const override; /// A'*b for Jacobian (raw memory version) - virtual void gradientAtZero(double* d) const; + void gradientAtZero(double* d) const override; /// Compute the gradient wrt a key at any values - Vector gradient(Key key, const VectorValues& x) const; + Vector gradient(Key key, const VectorValues& x) const override; /** Return a whitened version of the factor, i.e. with unit diagonal noise model. */ JacobianFactor whiten() const;