added functions to allow for cwise min/max operations with scalar argument (bug #400).

added function for array.min(), array.max(), matrix.cwiseMin(), matrix.cwiseMax().

The matrix.cwiseMin/Max functions required the definition of the ConstantReturnType typedef.
However, it wasn't defined until after MatrixCwiseBinaryOps was included in Eigen/src/SparseCore/SparseMatrixBase.h,
so I moved those includes after the definition of the typedefs.

tests for both the regular and scalar min/max functions were added as well
This commit is contained in:
Abraham Bachrach
2012-01-11 11:00:30 -05:00
parent 238999045c
commit 039408cd66
5 changed files with 125 additions and 10 deletions

View File

@@ -29,6 +29,16 @@ operator/(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const
*/
EIGEN_MAKE_CWISE_BINARY_OP(min,internal::scalar_min_op)
/** \returns an expression of the coefficient-wise min of \c *this and scalar \a other
*
* \sa max()
*/
EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar>, const Derived, const ConstantReturnType>
(min)(const Scalar &other) const
{
return (min)(Derived::PlainObject::Constant(rows(), cols(), other));
}
/** \returns an expression of the coefficient-wise max of \c *this and \a other
*
* Example: \include Cwise_max.cpp
@@ -38,6 +48,16 @@ EIGEN_MAKE_CWISE_BINARY_OP(min,internal::scalar_min_op)
*/
EIGEN_MAKE_CWISE_BINARY_OP(max,internal::scalar_max_op)
/** \returns an expression of the coefficient-wise max of \c *this and scalar \a other
*
* \sa min()
*/
EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar>, const Derived, const ConstantReturnType>
(max)(const Scalar &other) const
{
return (max)(Derived::PlainObject::Constant(rows(), cols(), other));
}
/** \returns an expression of the coefficient-wise \< operator of *this and \a other
*
* Example: \include Cwise_less.cpp