make Visitor honors nesting requirements (fix prod.maxCoeff(i) and similar)

This commit is contained in:
Gael Guennebaud 2015-11-18 23:27:18 +01:00
parent b3b9d7a14c
commit 7dc0c4e8f6
2 changed files with 10 additions and 2 deletions

View File

@ -76,14 +76,17 @@ template<typename Derived>
template<typename Visitor> template<typename Visitor>
void DenseBase<Derived>::visit(Visitor& visitor) const void DenseBase<Derived>::visit(Visitor& visitor) const
{ {
typedef typename internal::remove_all<typename Derived::Nested>::type ThisNested;
typename Derived::Nested thisNested(derived());
enum { unroll = SizeAtCompileTime != Dynamic enum { unroll = SizeAtCompileTime != Dynamic
&& CoeffReadCost != Dynamic && CoeffReadCost != Dynamic
&& (SizeAtCompileTime == 1 || internal::functor_traits<Visitor>::Cost != Dynamic) && (SizeAtCompileTime == 1 || internal::functor_traits<Visitor>::Cost != Dynamic)
&& SizeAtCompileTime * CoeffReadCost + (SizeAtCompileTime-1) * internal::functor_traits<Visitor>::Cost && SizeAtCompileTime * CoeffReadCost + (SizeAtCompileTime-1) * internal::functor_traits<Visitor>::Cost
<= EIGEN_UNROLLING_LIMIT }; <= EIGEN_UNROLLING_LIMIT };
return internal::visitor_impl<Visitor, Derived, return internal::visitor_impl<Visitor, ThisNested,
unroll ? int(SizeAtCompileTime) : Dynamic unroll ? int(SizeAtCompileTime) : Dynamic
>::run(derived(), visitor); >::run(thisNested, visitor);
} }
namespace internal { namespace internal {

View File

@ -55,6 +55,11 @@ template<typename MatrixType> void matrixVisitor(const MatrixType& p)
VERIFY_IS_APPROX(maxc, eigen_maxc); VERIFY_IS_APPROX(maxc, eigen_maxc);
VERIFY_IS_APPROX(minc, m.minCoeff()); VERIFY_IS_APPROX(minc, m.minCoeff());
VERIFY_IS_APPROX(maxc, m.maxCoeff()); VERIFY_IS_APPROX(maxc, m.maxCoeff());
eigen_maxc = (m.adjoint()*m).maxCoeff(&eigen_maxrow,&eigen_maxcol);
eigen_maxc = (m.adjoint()*m).eval().maxCoeff(&maxrow,&maxcol);
VERIFY(maxrow == eigen_maxrow);
VERIFY(maxcol == eigen_maxcol);
} }
template<typename VectorType> void vectorVisitor(const VectorType& w) template<typename VectorType> void vectorVisitor(const VectorType& w)