1c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This file is part of Eigen, a lightweight C++ template library
2c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// for linear algebra.
3c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//
4c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath//
6c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// This Source Code Form is subject to the terms of the Mozilla
7c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// Public License v. 2.0. If a copy of the MPL was not distributed
8c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
10c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#ifndef EIGEN_VISITOR_H
11c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#define EIGEN_VISITOR_H
12c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
13c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathnamespace Eigen {
14c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
15c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathnamespace internal {
16c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
17c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Visitor, typename Derived, int UnrollCount>
18c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathstruct visitor_impl
19c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
20c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  enum {
21c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    col = (UnrollCount-1) / Derived::RowsAtCompileTime,
22c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    row = (UnrollCount-1) % Derived::RowsAtCompileTime
23c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  };
24c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
25c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  static inline void run(const Derived &mat, Visitor& visitor)
26c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  {
27c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    visitor_impl<Visitor, Derived, UnrollCount-1>::run(mat, visitor);
28c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    visitor(mat.coeff(row, col), row, col);
29c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  }
30c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
31c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
32c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Visitor, typename Derived>
33c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathstruct visitor_impl<Visitor, Derived, 1>
34c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
35c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  static inline void run(const Derived &mat, Visitor& visitor)
36c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  {
37c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    return visitor.init(mat.coeff(0, 0), 0, 0);
38c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  }
39c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
40c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
41c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Visitor, typename Derived>
42c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathstruct visitor_impl<Visitor, Derived, Dynamic>
43c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
44c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename Derived::Index Index;
45c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  static inline void run(const Derived& mat, Visitor& visitor)
46c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  {
47c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    visitor.init(mat.coeff(0,0), 0, 0);
48c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    for(Index i = 1; i < mat.rows(); ++i)
49c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      visitor(mat.coeff(i, 0), i, 0);
50c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    for(Index j = 1; j < mat.cols(); ++j)
51c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      for(Index i = 0; i < mat.rows(); ++i)
52c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath        visitor(mat.coeff(i, j), i, j);
53c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  }
54c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
55c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
56c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} // end namespace internal
57c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
58c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath/** Applies the visitor \a visitor to the whole coefficients of the matrix or vector.
59c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
60c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * The template parameter \a Visitor is the type of the visitor and provides the following interface:
61c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \code
62c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * struct MyVisitor {
63c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *   // called for the first coefficient
64c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *   void init(const Scalar& value, Index i, Index j);
65c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *   // called for all other coefficients
66c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *   void operator() (const Scalar& value, Index i, Index j);
67c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * };
68c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \endcode
69c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
70c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \note compared to one or two \em for \em loops, visitors offer automatic
71c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * unrolling for small fixed size matrix.
72c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
73c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \sa minCoeff(Index*,Index*), maxCoeff(Index*,Index*), DenseBase::redux()
74c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  */
75c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Derived>
76c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Visitor>
77c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathvoid DenseBase<Derived>::visit(Visitor& visitor) const
78c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
79c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  enum { unroll = SizeAtCompileTime != Dynamic
80c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                   && CoeffReadCost != Dynamic
81c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                   && (SizeAtCompileTime == 1 || internal::functor_traits<Visitor>::Cost != Dynamic)
82c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                   && SizeAtCompileTime * CoeffReadCost + (SizeAtCompileTime-1) * internal::functor_traits<Visitor>::Cost
83c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath                      <= EIGEN_UNROLLING_LIMIT };
84c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  return internal::visitor_impl<Visitor, Derived,
85c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      unroll ? int(SizeAtCompileTime) : Dynamic
86c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    >::run(derived(), visitor);
87c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
88c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
89c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathnamespace internal {
90c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
91c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath/** \internal
92c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \brief Base class to implement min and max visitors
93c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  */
94c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate <typename Derived>
95c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathstruct coeff_visitor
96c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
97c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename Derived::Index Index;
98c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename Derived::Scalar Scalar;
99c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  Index row, col;
100c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  Scalar res;
101c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  inline void init(const Scalar& value, Index i, Index j)
102c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  {
103c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    res = value;
104c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    row = i;
105c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    col = j;
106c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  }
107c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
108c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
109c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath/** \internal
110c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \brief Visitor computing the min coefficient with its value and coordinates
111c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
112c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \sa DenseBase::minCoeff(Index*, Index*)
113c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  */
114c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate <typename Derived>
115c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathstruct min_coeff_visitor : coeff_visitor<Derived>
116c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
117c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename Derived::Index Index;
118c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename Derived::Scalar Scalar;
119c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  void operator() (const Scalar& value, Index i, Index j)
120c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  {
121c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    if(value < this->res)
122c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
123c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      this->res = value;
124c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      this->row = i;
125c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      this->col = j;
126c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
127c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  }
128c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
129c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
130c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Scalar>
131c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathstruct functor_traits<min_coeff_visitor<Scalar> > {
132c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  enum {
133c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    Cost = NumTraits<Scalar>::AddCost
134c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  };
135c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
136c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
137c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath/** \internal
138c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \brief Visitor computing the max coefficient with its value and coordinates
139c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
140c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \sa DenseBase::maxCoeff(Index*, Index*)
141c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  */
142c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate <typename Derived>
143c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathstruct max_coeff_visitor : coeff_visitor<Derived>
144c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
145c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename Derived::Index Index;
146c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  typedef typename Derived::Scalar Scalar;
147c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  void operator() (const Scalar& value, Index i, Index j)
148c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  {
149c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    if(value > this->res)
150c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    {
151c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      this->res = value;
152c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      this->row = i;
153c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath      this->col = j;
154c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    }
155c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  }
156c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
157c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
158c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Scalar>
159c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathstruct functor_traits<max_coeff_visitor<Scalar> > {
160c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  enum {
161c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath    Cost = NumTraits<Scalar>::AddCost
162c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  };
163c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath};
164c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
165c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} // end namespace internal
166c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
1677faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez/** \returns the minimum of all coefficients of *this and puts in *row and *col its location.
1687faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  * \warning the result is undefined if \c *this contains NaN.
169c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
170c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \sa DenseBase::minCoeff(Index*), DenseBase::maxCoeff(Index*,Index*), DenseBase::visitor(), DenseBase::minCoeff()
171c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  */
172c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Derived>
173c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename IndexType>
174c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtypename internal::traits<Derived>::Scalar
1757faaa9f3f0df9d23790277834d426c3d992ac3baCarlos HernandezDenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const
176c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
177c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  internal::min_coeff_visitor<Derived> minVisitor;
178c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  this->visit(minVisitor);
1797faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  *rowId = minVisitor.row;
1807faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  if (colId) *colId = minVisitor.col;
181c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  return minVisitor.res;
182c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
183c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
1847faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez/** \returns the minimum of all coefficients of *this and puts in *index its location.
1857faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  * \warning the result is undefined if \c *this contains NaN.
186c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
187c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::visitor(), DenseBase::minCoeff()
188c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  */
189c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Derived>
190c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename IndexType>
191c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtypename internal::traits<Derived>::Scalar
192c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan KamathDenseBase<Derived>::minCoeff(IndexType* index) const
193c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
194c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
195c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  internal::min_coeff_visitor<Derived> minVisitor;
196c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  this->visit(minVisitor);
197c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *index = (RowsAtCompileTime==1) ? minVisitor.col : minVisitor.row;
198c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  return minVisitor.res;
199c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
200c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
2017faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez/** \returns the maximum of all coefficients of *this and puts in *row and *col its location.
2027faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  * \warning the result is undefined if \c *this contains NaN.
203c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
204c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visitor(), DenseBase::maxCoeff()
205c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  */
206c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Derived>
207c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename IndexType>
208c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtypename internal::traits<Derived>::Scalar
2097faaa9f3f0df9d23790277834d426c3d992ac3baCarlos HernandezDenseBase<Derived>::maxCoeff(IndexType* rowPtr, IndexType* colPtr) const
210c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
211c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  internal::max_coeff_visitor<Derived> maxVisitor;
212c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  this->visit(maxVisitor);
2137faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  *rowPtr = maxVisitor.row;
2147faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  if (colPtr) *colPtr = maxVisitor.col;
215c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  return maxVisitor.res;
216c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
217c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
2187faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez/** \returns the maximum of all coefficients of *this and puts in *index its location.
2197faaa9f3f0df9d23790277834d426c3d992ac3baCarlos Hernandez  * \warning the result is undefined if \c *this contains NaN.
220c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *
221c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  * \sa DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visitor(), DenseBase::maxCoeff()
222c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  */
223c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename Derived>
224c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtemplate<typename IndexType>
225c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamathtypename internal::traits<Derived>::Scalar
226c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan KamathDenseBase<Derived>::maxCoeff(IndexType* index) const
227c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath{
228c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
229c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  internal::max_coeff_visitor<Derived> maxVisitor;
230c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  this->visit(maxVisitor);
231c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  *index = (RowsAtCompileTime==1) ? maxVisitor.col : maxVisitor.row;
232c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath  return maxVisitor.res;
233c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath}
234c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
235c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath} // end namespace Eigen
236c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath
237c981c48f5bc9aefeffc0bcb0cc3934c2fae179ddNarayan Kamath#endif // EIGEN_VISITOR_H
238