00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef EIGEN_REDUX_H
00027 #define EIGEN_REDUX_H
00028
00029 template<typename BinaryOp, typename Derived, int Start, int Length>
00030 struct ei_redux_impl
00031 {
00032 enum {
00033 HalfLength = Length/2
00034 };
00035
00036 typedef typename ei_result_of<BinaryOp(typename Derived::Scalar)>::type Scalar;
00037
00038 static Scalar run(const Derived &mat, const BinaryOp& func)
00039 {
00040 return func(
00041 ei_redux_impl<BinaryOp, Derived, Start, HalfLength>::run(mat, func),
00042 ei_redux_impl<BinaryOp, Derived, Start+HalfLength, Length - HalfLength>::run(mat, func));
00043 }
00044 };
00045
00046 template<typename BinaryOp, typename Derived, int Start>
00047 struct ei_redux_impl<BinaryOp, Derived, Start, 1>
00048 {
00049 enum {
00050 col = Start / Derived::RowsAtCompileTime,
00051 row = Start % Derived::RowsAtCompileTime
00052 };
00053
00054 typedef typename ei_result_of<BinaryOp(typename Derived::Scalar)>::type Scalar;
00055
00056 static Scalar run(const Derived &mat, const BinaryOp &)
00057 {
00058 return mat.coeff(row, col);
00059 }
00060 };
00061
00062 template<typename BinaryOp, typename Derived, int Start>
00063 struct ei_redux_impl<BinaryOp, Derived, Start, Dynamic>
00064 {
00065 typedef typename ei_result_of<BinaryOp(typename Derived::Scalar)>::type Scalar;
00066 static Scalar run(const Derived& mat, const BinaryOp& func)
00067 {
00068 ei_assert(mat.rows()>0 && mat.cols()>0 && "you are using a non initialized matrix");
00069 Scalar res;
00070 res = mat.coeff(0,0);
00071 for(int i = 1; i < mat.rows(); ++i)
00072 res = func(res, mat.coeff(i, 0));
00073 for(int j = 1; j < mat.cols(); ++j)
00074 for(int i = 0; i < mat.rows(); ++i)
00075 res = func(res, mat.coeff(i, j));
00076 return res;
00077 }
00078 };
00079
00087 template<typename Derived>
00088 template<typename BinaryOp>
00089 typename ei_result_of<BinaryOp(typename ei_traits<Derived>::Scalar)>::type
00090 MatrixBase<Derived>::redux(const BinaryOp& func) const
00091 {
00092 const bool unroll = SizeAtCompileTime * CoeffReadCost
00093 + (SizeAtCompileTime-1) * ei_functor_traits<BinaryOp>::Cost
00094 <= EIGEN_UNROLLING_LIMIT;
00095 return ei_redux_impl<BinaryOp, Derived, 0, unroll ? int(SizeAtCompileTime) : Dynamic>
00096 ::run(derived(), func);
00097 }
00098
00101 template<typename Derived>
00102 inline typename ei_traits<Derived>::Scalar
00103 MatrixBase<Derived>::minCoeff() const
00104 {
00105 return this->redux(Eigen::ei_scalar_min_op<Scalar>());
00106 }
00107
00110 template<typename Derived>
00111 inline typename ei_traits<Derived>::Scalar
00112 MatrixBase<Derived>::maxCoeff() const
00113 {
00114 return this->redux(Eigen::ei_scalar_max_op<Scalar>());
00115 }
00116
00117 #endif // EIGEN_REDUX_H