diff options
author | Gael Guennebaud <g.gael@free.fr> | 2008-09-09 09:30:23 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2008-09-09 09:30:23 +0000 |
commit | 703539110b5c26f01ac37fe6114afdbb5c3c6c99 (patch) | |
tree | 16be3c0fbdab00bcfa895799f1f73b5015afb30a | |
parent | c41ceee7508965a9f571e6b67f3e396943c6376c (diff) |
add the missing templated version of block for sub-vectors
-rw-r--r-- | Eigen/Geometry | 7 | ||||
-rw-r--r-- | Eigen/src/Array/AllAndAny.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/Block.h | 38 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixBase.h | 3 | ||||
-rw-r--r-- | doc/QuickStartGuide.dox | 2 | ||||
-rw-r--r-- | doc/snippets/MatrixBase_template_int.cpp | 5 | ||||
-rw-r--r-- | test/submatrices.cpp | 16 |
7 files changed, 67 insertions, 8 deletions
diff --git a/Eigen/Geometry b/Eigen/Geometry index 1ac279b99..2a2dfda2b 100644 --- a/Eigen/Geometry +++ b/Eigen/Geometry @@ -1,7 +1,7 @@ #ifndef EIGEN_GEOMETRY_MODULE_H #define EIGEN_GEOMETRY_MODULE_H -#include "Core" +#include "Array" #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -23,11 +23,6 @@ namespace Eigen { * \endcode */ -// the Geometry module use cwiseCos and cwiseSin which are defined in the Array module -#include "src/Array/CwiseOperators.h" -#include "src/Array/Functors.h" -#include "src/Array/PartialRedux.h" - #include "src/Geometry/OrthoMethods.h" #include "src/Geometry/RotationBase.h" #include "src/Geometry/Rotation2D.h" diff --git a/Eigen/src/Array/AllAndAny.h b/Eigen/src/Array/AllAndAny.h index 76cc2db84..cc4560b2f 100644 --- a/Eigen/src/Array/AllAndAny.h +++ b/Eigen/src/Array/AllAndAny.h @@ -89,7 +89,7 @@ struct ei_any_unroller<Derived, Dynamic> * \sa MatrixBase::any(), Cwise::operator<() */ template<typename Derived> -bool MatrixBase<Derived>::all(void) const +inline bool MatrixBase<Derived>::all(void) const { const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT; @@ -113,7 +113,7 @@ bool MatrixBase<Derived>::all(void) const * \sa MatrixBase::all() */ template<typename Derived> -bool MatrixBase<Derived>::any(void) const +inline bool MatrixBase<Derived>::any(void) const { const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost) <= EIGEN_UNROLLING_LIMIT; diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 18fcdbb2b..71ad6d5f1 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -451,6 +451,44 @@ MatrixBase<Derived>::end(int size) const ColsAtCompileTime == 1 ? 1 : size); } +/** \returns a fixed-size expression of a sub-vector of \c *this + * + * \only_for_vectors + * + * The template parameter \a Size is the number of coefficients in the block + * + * \param start the index of the first element of the sub-vector + * + * Example: \include MatrixBase_template_int.cpp + * Output: \verbinclude MatrixBase_template_int.out + * + * \sa class Block + */ +template<typename Derived> +template<int Size> +inline typename BlockReturnType<Derived,Size>::SubVectorType +MatrixBase<Derived>::block(int start) +{ + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); + return Block<Derived, (RowsAtCompileTime == 1 ? 1 : Size), + (ColsAtCompileTime == 1 ? 1 : Size)> + (derived(), RowsAtCompileTime == 1 ? 0 : start, + ColsAtCompileTime == 1 ? 0 : start); +} + +/** This is the const version of block<int>(int).*/ +template<typename Derived> +template<int Size> +inline const typename BlockReturnType<Derived,Size>::SubVectorType +MatrixBase<Derived>::block(int start) const +{ + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); + return Block<Derived, (RowsAtCompileTime == 1 ? 1 : Size), + (ColsAtCompileTime == 1 ? 1 : Size)> + (derived(), RowsAtCompileTime == 1 ? 0 : start, + ColsAtCompileTime == 1 ? 0 : start); +} + /** \returns a fixed-size expression of the first coefficients of *this. * * \only_for_vectors diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index a9d15032c..81aae3593 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -381,6 +381,9 @@ template<typename Derived> class MatrixBase template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType end(); template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType end() const; + template<int Size> typename BlockReturnType<Derived,Size>::SubVectorType block(int start); + template<int Size> const typename BlockReturnType<Derived,Size>::SubVectorType block(int start) const; + DiagonalCoeffs<Derived> diagonal(); const DiagonalCoeffs<Derived> diagonal() const; diff --git a/doc/QuickStartGuide.dox b/doc/QuickStartGuide.dox index 8d1799fdd..d55e07856 100644 --- a/doc/QuickStartGuide.dox +++ b/doc/QuickStartGuide.dox @@ -351,6 +351,8 @@ mat = 2 7 8 \endcode</td></tr> </table> +Also note that maxCoeff and minCoeff can takes optional arguments returning the coordinates of the respective min/max coeff: \link MatrixBase::maxCoeff(int*,int*) const maxCoeff(int* i, int* j) \endlink, \link MatrixBase::minCoeff(int*,int*) const minCoeff(int* i, int* j) \endlink. + <span class="note">\b Side \b note: The all() and any() functions are especially useful in combinaison with coeff-wise comparison operators (\ref CwiseAll "example").</span> diff --git a/doc/snippets/MatrixBase_template_int.cpp b/doc/snippets/MatrixBase_template_int.cpp new file mode 100644 index 000000000..4041a2214 --- /dev/null +++ b/doc/snippets/MatrixBase_template_int.cpp @@ -0,0 +1,5 @@ +RowVector5i v = RowVector5i::Random(); +cout << "Here is the vector v:" << endl << v << endl; +cout << "Here is v.block<2>(1):" << endl << v.start<2>() << endl; +v.block<2>(2).setZero(); +cout << "Now the vector v is:" << endl << v << endl; diff --git a/test/submatrices.cpp b/test/submatrices.cpp index 74bf8c7af..369930df1 100644 --- a/test/submatrices.cpp +++ b/test/submatrices.cpp @@ -123,6 +123,22 @@ template<typename MatrixType> void submatrices(const MatrixType& m) VERIFY_IS_APPROX(b, m1.block(3,3,BlockRows,BlockCols)); } + if (rows>2) + { + // test sub vectors + VERIFY_IS_APPROX(v1.template start<2>(), v1.block(0,0,2,1)); + VERIFY_IS_APPROX(v1.template start<2>(), v1.start(2)); + VERIFY_IS_APPROX(v1.template start<2>(), v1.block(0,2)); + VERIFY_IS_APPROX(v1.template start<2>(), v1.template block<2>(0)); + int i = rows-2; + VERIFY_IS_APPROX(v1.template end<2>(), v1.block(i,0,2,1)); + VERIFY_IS_APPROX(v1.template end<2>(), v1.end(2)); + VERIFY_IS_APPROX(v1.template end<2>(), v1.block(i,2)); + VERIFY_IS_APPROX(v1.template end<2>(), v1.template block<2>(i)); + i = ei_random(0,rows-2); + VERIFY_IS_APPROX(v1.block(i,2), v1.template block<2>(i)); + } + // stress some basic stuffs with block matrices VERIFY(ones.col(c1).sum() == Scalar(rows)); VERIFY(ones.row(r1).sum() == Scalar(cols)); |