diff --git a/Eigen/src/Cholesky/Cholesky.h b/Eigen/src/Cholesky/Cholesky.h index 8d9b6e8d8..c1f05d768 100644 --- a/Eigen/src/Cholesky/Cholesky.h +++ b/Eigen/src/Cholesky/Cholesky.h @@ -66,7 +66,7 @@ template class Cholesky bool isPositiveDefinite(void) const { return m_isPositiveDefinite; } template - typename Derived::Eval solve(MatrixBase &b); + typename Derived::Eval solve(const MatrixBase &b) const; void compute(const MatrixType& matrix); @@ -110,10 +110,14 @@ void Cholesky::compute(const MatrixType& a) /** \returns the solution of A x = \a b using the current decomposition of A. * In other words, it returns \code A^-1 b \endcode computing * \code L^-* L^1 b \endcode from right to left. + * + * Example: \include Cholesky_solve.cpp + * Output: \verbinclude Cholesky_solve.out + * */ template template -typename Derived::Eval Cholesky::solve(MatrixBase &b) +typename Derived::Eval Cholesky::solve(const MatrixBase &b) const { const int size = m_matrix.rows(); ei_assert(size==b.size()); @@ -121,5 +125,14 @@ typename Derived::Eval Cholesky::solve(MatrixBase &b) return m_matrix.adjoint().template extract().inverseProduct(matrixL().inverseProduct(b)); } +/** \cholesky_module + * \returns the Cholesky decomposition of \c *this + */ +template +inline const Cholesky::type> +MatrixBase::cholesky() const +{ + return Cholesky::type>(derived()); +} #endif // EIGEN_CHOLESKY_H diff --git a/Eigen/src/Cholesky/CholeskyWithoutSquareRoot.h b/Eigen/src/Cholesky/CholeskyWithoutSquareRoot.h index 8905385cc..2d85f78db 100644 --- a/Eigen/src/Cholesky/CholeskyWithoutSquareRoot.h +++ b/Eigen/src/Cholesky/CholeskyWithoutSquareRoot.h @@ -77,7 +77,7 @@ template class CholeskyWithoutSquareRoot } template - typename Derived::Eval solve(MatrixBase &b); + typename Derived::Eval solve(const MatrixBase &b) const; void compute(const MatrixType& matrix); @@ -127,7 +127,7 @@ void CholeskyWithoutSquareRoot::compute(const MatrixType& a) */ template template -typename Derived::Eval CholeskyWithoutSquareRoot::solve(MatrixBase &vecB) +typename Derived::Eval CholeskyWithoutSquareRoot::solve(const MatrixBase &vecB) const { const int size = m_matrix.rows(); ei_assert(size==vecB.size()); @@ -140,5 +140,14 @@ typename Derived::Eval CholeskyWithoutSquareRoot::solve(MatrixBase +inline const CholeskyWithoutSquareRoot::type> +MatrixBase::choleskyNoSqrt() const +{ + return derived(); +} #endif // EIGEN_CHOLESKY_WITHOUT_SQUARE_ROOT_H diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index c6ea5f14f..bd4b64b05 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -532,6 +532,10 @@ template class MatrixBase void computeInverse(typename ei_eval::type *result) const; Scalar determinant() const; +/////////// Cholesky module /////////// + + const Cholesky::type> cholesky() const; + const CholeskyWithoutSquareRoot::type> choleskyNoSqrt() const; /////////// QR module /////////// diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index 0246b43cc..1fba262e2 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -96,6 +96,8 @@ void ei_cache_friendly_product( template class Inverse; template class QR; +template class Cholesky; +template class CholeskyWithoutSquareRoot; // Geometry module: template class Cross; diff --git a/Eigen/src/Geometry/AngleAxis.h b/Eigen/src/Geometry/AngleAxis.h index abb9b50f6..647e07513 100644 --- a/Eigen/src/Geometry/AngleAxis.h +++ b/Eigen/src/Geometry/AngleAxis.h @@ -29,7 +29,7 @@ * * \class AngleAxis * - * \brief Represents a 3D rotation as a rotation angle around an arbitray 3D axis + * \brief Represents a 3D rotation as a rotation angle around an arbitrary 3D axis * * \param _Scalar the scalar type, i.e., the type of the coefficients. * @@ -37,7 +37,14 @@ * \li \c AngleAxisf for \c float * \li \c AngleAxisd for \c double * - * \sa class Quaternion, class Transform + * \addexample AngleAxisForEuler \label How to define a rotation from Euler-angles + * + * Combined with MatrixBase::Unit{X,Y,Z}, AngleAxis can be used to easily + * mimic Euler-angles. Here is an example: + * \include AngleAxis_mimic_euler.cpp + * Output: \verbinclude AngleAxis_mimic_euler.out + * + * \sa class Quaternion, class Transform, MatrixBase::UnitX() */ template class AngleAxis diff --git a/doc/Doxyfile.in b/doc/Doxyfile.in index bade60a2b..4c5c71fd7 100644 --- a/doc/Doxyfile.in +++ b/doc/Doxyfile.in @@ -199,6 +199,7 @@ TAB_SIZE = 8 ALIASES = "only_for_vectors=This is only for vectors (either row-vectors or column-vectors), i.e. matrices which are known at compile-time to have either one row or one column." \ "array_module=This is defined in the %Array module. \code #include \endcode" \ "lu_module=This is defined in the %LU module. \code #include \endcode" \ + "cholesky_module=This is defined in the %Cholesky module. \code #include \endcode" \ "qr_module=This is defined in the %QR module. \code #include \endcode" \ "geometry_module=This is defined in the %Geometry module. \code #include \endcode" \ "addexample=\anchor" \ diff --git a/doc/buildexamplelist.sh b/doc/buildexamplelist.sh index 0a9bb7ec0..7d47ae39d 100755 --- a/doc/buildexamplelist.sh +++ b/doc/buildexamplelist.sh @@ -4,7 +4,7 @@ echo "namespace Eigen {" echo "/** \page ExampleList" echo "

Selected list of examples

" -grep \\addexample $1/Eigen/* -R | cut -d \\ -f 2- | \ +grep \\addexample $1/Eigen/src/*/*.h -R | cut -d \\ -f 2- | \ while read example; do anchor=`echo "$example" | cut -d " " -f 2` diff --git a/doc/snippets/AngleAxis_mimic_euler.cpp b/doc/snippets/AngleAxis_mimic_euler.cpp new file mode 100644 index 000000000..be6b8adbe --- /dev/null +++ b/doc/snippets/AngleAxis_mimic_euler.cpp @@ -0,0 +1,4 @@ +Matrix3f m = AngleAxisf(0.25*M_PI, Vector3f::UnitX()) + * AngleAxisf(0.5*M_PI, Vector3f::UnitY()) + * AngleAxisf(0.33*M_PI, Vector3f::UnitZ()); +cout << m << endl; diff --git a/doc/snippets/CMakeLists.txt b/doc/snippets/CMakeLists.txt index faf6440e8..72bd7770a 100644 --- a/doc/snippets/CMakeLists.txt +++ b/doc/snippets/CMakeLists.txt @@ -20,4 +20,6 @@ ADD_CUSTOM_COMMAND( ARGS >${CMAKE_CURRENT_BINARY_DIR}/${snippet}.out ) ADD_DEPENDENCIES(all_snippets ${compile_snippet_target}) +set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${compile_snippet_src} + PROPERTIES OBJECT_DEPENDS ${snippet_src}) ENDFOREACH(snippet_src) diff --git a/doc/snippets/Cholesky_solve.cpp b/doc/snippets/Cholesky_solve.cpp new file mode 100644 index 000000000..4f9ac9c1e --- /dev/null +++ b/doc/snippets/Cholesky_solve.cpp @@ -0,0 +1,6 @@ +typedef Matrix DataMatrix; +// let's generate some samples on the 3D plane of equation z = 2x+3y (with some noise) +DataMatrix samples = DataMatrix::random(12,2); +VectorXf elevations = 2*samples.col(0) + 3*samples.col(1) + VectorXf::random(12)*0.1; +// and let's solve samples * x = elevations in least square sense: +cout << (samples.adjoint() * samples).cholesky().solve((samples.adjoint()*elevations).eval()) << endl; diff --git a/doc/snippets/compile_snippet.cpp.in b/doc/snippets/compile_snippet.cpp.in index 5876aab9c..950f06654 100644 --- a/doc/snippets/compile_snippet.cpp.in +++ b/doc/snippets/compile_snippet.cpp.in @@ -1,8 +1,11 @@ #include #include #include +#include +#include USING_PART_OF_NAMESPACE_EIGEN +using namespace Eigen; using namespace std; int main(int, char**)