Skip to content

Commit

Permalink
Fix typo in Vectowise::any()
Browse files Browse the repository at this point in the history
  • Loading branch information
ggael committed Sep 16, 2015
1 parent f198be4 commit 7731b9b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
18 changes: 9 additions & 9 deletions Eigen/src/Core/VectorwiseOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifndef EIGEN_PARTIAL_REDUX_H
#define EIGEN_PARTIAL_REDUX_H

namespace Eigen {
namespace Eigen {

/** \class PartialReduxExpr
* \ingroup Core_Module
Expand Down Expand Up @@ -230,7 +230,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
isVertical ? 1 : m_matrix.rows(),
isHorizontal ? 1 : m_matrix.cols());
}

template<typename OtherDerived> struct OppositeExtendedType {
typedef Replicate<OtherDerived,
isHorizontal ? 1 : ExpressionType::RowsAtCompileTime,
Expand Down Expand Up @@ -292,7 +292,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp

/** \returns a row (or column) vector expression of the smallest coefficient
* of each column (or row) of the referenced expression.
*
*
* \warning the result is undefined if \c *this contains NaN.
*
* Example: \include PartialRedux_minCoeff.cpp
Expand All @@ -305,7 +305,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp

/** \returns a row (or column) vector expression of the largest coefficient
* of each column (or row) of the referenced expression.
*
*
* \warning the result is undefined if \c *this contains NaN.
*
* Example: \include PartialRedux_maxCoeff.cpp
Expand Down Expand Up @@ -343,7 +343,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp

/** \returns a row (or column) vector expression of the norm
* of each column (or row) of the referenced expression, using
* Blue's algorithm.
* Blue's algorithm.
* This is a vector with real entries, even if the original matrix has complex entries.
*
* \sa DenseBase::blueNorm() */
Expand Down Expand Up @@ -408,7 +408,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
* \sa DenseBase::any() */
EIGEN_DEVICE_FUNC
const AnyReturnType any() const
{ return Any(_expression()); }
{ return AnyReturnType(_expression()); }

/** \returns a row (or column) vector expression representing
* the number of \c true coefficients of each respective column (or row).
Expand Down Expand Up @@ -579,7 +579,7 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
EIGEN_STATIC_ASSERT_SAME_XPR_KIND(ExpressionType, OtherDerived)
return m_matrix / extendedTo(other.derived());
}

/** \returns an expression where each column of row of the referenced matrix are normalized.
* The referenced matrix is \b not modified.
* \sa MatrixBase::normalized(), normalize()
Expand All @@ -589,8 +589,8 @@ template<typename ExpressionType, int Direction> class VectorwiseOp
const ExpressionTypeNestedCleaned,
const typename OppositeExtendedType<typename ReturnType<internal::member_norm,RealScalar>::Type>::Type>
normalized() const { return m_matrix.cwiseQuotient(extendedToOpposite(this->norm())); }


/** Normalize in-place each row or columns of the referenced matrix.
* \sa MatrixBase::normalize(), normalized()
*/
Expand Down
20 changes: 16 additions & 4 deletions test/vectorwiseop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ template<typename ArrayType> void vectorwiseop_array(const ArrayType& m)

VERIFY_RAISES_ASSERT(m2.rowwise() /= rowvec.transpose());
VERIFY_RAISES_ASSERT(m1.rowwise() / rowvec.transpose());

m2 = m1;
// yes, there might be an aliasing issue there but ".rowwise() /="
// is supposed to evaluate " m2.colwise().sum()" into a temporary to avoid
Expand All @@ -111,6 +111,18 @@ template<typename ArrayType> void vectorwiseop_array(const ArrayType& m)
m2.rowwise() /= m2.colwise().sum();
VERIFY_IS_APPROX(m2, m1.rowwise() / m1.colwise().sum());
}

// all/any
Array<bool,Dynamic,Dynamic> mb(rows,cols);
mb = (m1.real()<=0.7).colwise().all();
VERIFY( (mb.col(c) == (m1.real().col(c)<=0.7).all()).all() );
mb = (m1.real()<=0.7).rowwise().all();
VERIFY( (mb.row(r) == (m1.real().row(r)<=0.7).all()).all() );

mb = (m1.real()>=0.7).colwise().any();
VERIFY( (mb.col(c) == (m1.real().col(c)>=0.7).any()).all() );
mb = (m1.real()>=0.7).rowwise().any();
VERIFY( (mb.row(r) == (m1.real().row(r)>=0.7).any()).all() );
}

template<typename MatrixType> void vectorwiseop_matrix(const MatrixType& m)
Expand Down Expand Up @@ -172,19 +184,19 @@ template<typename MatrixType> void vectorwiseop_matrix(const MatrixType& m)

VERIFY_RAISES_ASSERT(m2.rowwise() -= rowvec.transpose());
VERIFY_RAISES_ASSERT(m1.rowwise() - rowvec.transpose());

// test norm
rrres = m1.colwise().norm();
VERIFY_IS_APPROX(rrres(c), m1.col(c).norm());
rcres = m1.rowwise().norm();
VERIFY_IS_APPROX(rcres(r), m1.row(r).norm());

// test normalized
m2 = m1.colwise().normalized();
VERIFY_IS_APPROX(m2.col(c), m1.col(c).normalized());
m2 = m1.rowwise().normalized();
VERIFY_IS_APPROX(m2.row(r), m1.row(r).normalized());

// test normalize
m2 = m1;
m2.colwise().normalize();
Expand Down

0 comments on commit 7731b9b

Please sign in to comment.