diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2009-09-16 14:18:30 -0400 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2009-09-16 14:18:30 -0400 |
commit | 46be9c9ac14fc951599ecd5dc7cd3c1a44f8b9d5 (patch) | |
tree | 445525ccd7d9656faf81cee29fc0f102e482658c /Eigen/src/Core/Visitor.h | |
parent | 4a6e5694d60ef0dab6ed17e563372c94a2744a31 (diff) |
* fix super nasty bug: vector.maxCoeff(&index) didn't work when 'vector'
was a row-vector. Fixed by splitting the vector version from the matrix version.
* add unit test, the visitors weren't covered by any test!!
Diffstat (limited to 'Eigen/src/Core/Visitor.h')
-rw-r--r-- | Eigen/src/Core/Visitor.h | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/Eigen/src/Core/Visitor.h b/Eigen/src/Core/Visitor.h index 598c2db8d..590efc766 100644 --- a/Eigen/src/Core/Visitor.h +++ b/Eigen/src/Core/Visitor.h @@ -164,7 +164,7 @@ struct ei_functor_traits<ei_max_coeff_visitor<Scalar> > { /** \returns the minimum of all coefficients of *this * and puts in *row and *col its location. * - * \sa MatrixBase::maxCoeff(int*,int*), MatrixBase::visitor(), MatrixBase::minCoeff() + * \sa MatrixBase::minCoeff(int*), MatrixBase::maxCoeff(int*,int*), MatrixBase::visitor(), MatrixBase::minCoeff() */ template<typename Derived> typename ei_traits<Derived>::Scalar @@ -177,6 +177,22 @@ MatrixBase<Derived>::minCoeff(int* row, int* col) const return minVisitor.res; } +/** \returns the minimum of all coefficients of *this + * and puts in *index its location. + * + * \sa MatrixBase::minCoeff(int*,int*), MatrixBase::maxCoeff(int*,int*), MatrixBase::visitor(), MatrixBase::minCoeff() + */ +template<typename Derived> +typename ei_traits<Derived>::Scalar +MatrixBase<Derived>::minCoeff(int* index) const +{ + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + ei_min_coeff_visitor<Scalar> minVisitor; + this->visit(minVisitor); + *index = (RowsAtCompileTime==1) ? minVisitor.col : minVisitor.row; + return minVisitor.res; +} + /** \returns the maximum of all coefficients of *this * and puts in *row and *col its location. * @@ -193,5 +209,20 @@ MatrixBase<Derived>::maxCoeff(int* row, int* col) const return maxVisitor.res; } +/** \returns the maximum of all coefficients of *this + * and puts in *index its location. + * + * \sa MatrixBase::maxCoeff(int*,int*), MatrixBase::minCoeff(int*,int*), MatrixBase::visitor(), MatrixBase::maxCoeff() + */ +template<typename Derived> +typename ei_traits<Derived>::Scalar +MatrixBase<Derived>::maxCoeff(int* index) const +{ + EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) + ei_max_coeff_visitor<Scalar> maxVisitor; + this->visit(maxVisitor); + *index = (RowsAtCompileTime==1) ? maxVisitor.col : maxVisitor.row; + return maxVisitor.res; +} #endif // EIGEN_VISITOR_H |