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
00027
00028
00029
00030
00031
00032 #ifndef TOON_INCLUDE_HELPERS_H
00033 #define TOON_INCLUDE_HELPERS_H
00034
00035 #include <TooN/TooN.h>
00036 #include <cmath>
00037
00038 #ifndef M_PI
00039 #define M_PI 3.14159265358979323846
00040 #define M_SQRT1_2 0.70710678118654752440
00041 #endif
00042
00043 namespace TooN {
00044
00045
00046
00047 template<int Size, class Precision, class Base> TOON_DEPRECATED void Fill(Vector<Size, Precision, Base>& v, const Precision& p)
00048 {
00049 for(int i=0; i < v.size(); i++)
00050 v[i]= p;
00051 }
00052
00053
00054
00055 template<int Rows, int Cols, class Precision, class Base> TOON_DEPRECATED void Fill(Matrix<Rows, Cols, Precision, Base>& m, const Precision& p)
00056 {
00057 for(int i=0; i < m.num_rows(); i++)
00058 for(int j=0; j < m.num_cols(); j++)
00059 m[i][j] = p;
00060 }
00061
00062
00063
00064
00065 template<int Size, class Precision, class Base> inline Precision norm(const Vector<Size, Precision, Base>& v)
00066 {
00067 using std::sqrt;
00068 return sqrt(v*v);
00069 }
00070
00071
00072
00073
00074 template<int Size, class Precision, class Base> inline Precision norm_sq(const Vector<Size, Precision, Base>& v)
00075 {
00076 return v*v;
00077 }
00078
00079
00080
00081
00082
00083 template<int Size, class Precision, class Base> inline Vector<Size, Precision> unit(const Vector<Size, Precision, Base> & v)
00084 {
00085 using std::sqrt;
00086 return v * (1/sqrt(v*v));
00087 }
00088
00089
00090
00091
00092 template<int Size, class Precision, class Base> inline void normalize(Vector<Size, Precision, Base>& v)
00093 {
00094 using std::sqrt;
00095 v /= sqrt(v*v);
00096 }
00097
00098
00099
00100
00101 template<int Size, typename Precision, typename Base> inline Vector<(Size==Dynamic?Dynamic:Size-1), Precision> project( const Vector<Size, Precision, Base> & v){
00102 return v.template slice<0, End<-1> >() / v[v.size() - 1];
00103 }
00104
00105
00106
00107
00108
00109 template<int Size, typename Precision, typename Base> inline Vector<(Size==Dynamic?Dynamic:Size+1), Precision> unproject( const Vector<Size, Precision, Base> & v){
00110 Vector<(Size==Dynamic?Dynamic:Size+1), Precision> result(v.size()+1);
00111 result.template slice<0,End<-1> >() = v;
00112 result[v.size()] = 1;
00113 return result;
00114 }
00115
00116
00117
00118
00119 template<int R, int C, typename Precision, typename Base> inline Matrix<R-1, C, Precision> project( const Matrix<R,C, Precision, Base> & m){
00120 Matrix<R-1, C, Precision> result = m.template slice(0,0,R-1,m.num_cols());
00121 for( int c = 0; c < m.num_cols(); ++c ) {
00122 result.slice(0,c,R-1,1) /= m[R-1][c];
00123 }
00124 return result;
00125 }
00126
00127 template<int C, typename Precision, typename Base> inline Matrix<-1, C, Precision> project( const Matrix<-1,C, Precision, Base> & m){
00128 Matrix<-1, C, Precision> result = m.template slice(0,0,m.num_rows()-1,m.num_cols());
00129 for( int c = 0; c < m.num_cols(); ++c ) {
00130 result.slice(0,c,m.num_rows()-1,1) /= m[m.num_rows()-1][c];
00131 }
00132 return result;
00133 }
00134
00135
00136
00137
00138 template<int R, int C, typename Precision, typename Base> inline Matrix<R+1, C, Precision> unproject( const Matrix<R, C, Precision, Base> & m){
00139 Matrix<R+1, C, Precision> result;
00140 result.template slice<0,0,R,C>() = m;
00141 result[R] = Ones;
00142 return result;
00143 }
00144
00145 template<int C, typename Precision, typename Base> inline Matrix<-1, C, Precision> unproject( const Matrix<-1, C, Precision, Base> & m){
00146 Matrix<-1, C, Precision> result( m.num_rows()+1, m.num_cols() );
00147 result.template slice(0,0,m.num_rows(),m.num_cols()) = m;
00148 result[m.num_rows()] = Ones;
00149 return result;
00150 }
00151
00152
00153
00154
00155 template <int R, int C, typename P, typename B>
00156 P inline norm_fro( const Matrix<R,C,P,B> & m ){
00157 using std::sqrt;
00158 P n = 0;
00159 for(int r = 0; r < m.num_rows(); ++r)
00160 for(int c = 0; c < m.num_cols(); ++c)
00161 n += m[r][c] * m[r][c];
00162
00163 return sqrt(n);
00164 }
00165
00166
00167
00168
00169 template <int R, int C, typename P, typename B>
00170 P inline norm_inf( const Matrix<R,C,P,B> & m ){
00171 using std::abs;
00172 using std::max;
00173 P n = 0;
00174 for(int r = 0; r < m.num_rows(); ++r){
00175 P s = 0;
00176 for(int c = 0; c < m.num_cols(); ++c)
00177 s += abs(m(r,c));
00178 n = max(n,s);
00179 }
00180 return n;
00181 }
00182
00183
00184
00185
00186 template <int R, int C, typename P, typename B>
00187 P inline norm_1( const Matrix<R,C,P,B> & m ){
00188 using std::abs;
00189 using std::max;
00190 P n = 0;
00191 for(int c = 0; c < m.num_cols(); ++c){
00192 P s = 0;
00193 for(int r = 0; r < m.num_rows(); ++r)
00194 s += abs(m(r,c));
00195 n = max(n,s);
00196 }
00197 return n;
00198 }
00199
00200 namespace Internal {
00201
00202
00203
00204 template <int R, int C, typename P, typename B>
00205 inline Matrix<R, C, P> exp_taylor( const Matrix<R,C,P,B> & m ){
00206 TooN::SizeMismatch<R, C>::test(m.num_rows(), m.num_cols());
00207 Matrix<R,C,P> result = TooN::Zeros(m.num_rows(), m.num_cols());
00208 Matrix<R,C,P> f = TooN::Identity(m.num_rows());
00209 P k = 1;
00210 while(norm_inf((result+f)-result) > 0){
00211 result += f;
00212 f = (m * f) / k;
00213 k += 1;
00214 }
00215 return result;
00216 }
00217 };
00218
00219
00220
00221
00222
00223
00224
00225 template <int R, int C, typename P, typename B>
00226 inline Matrix<R, C, P> exp( const Matrix<R,C,P,B> & m ){
00227 using std::max;
00228 SizeMismatch<R, C>::test(m.num_rows(), m.num_cols());
00229 const P l = log2(norm_inf(m));
00230 const int s = max(0,(int)ceil(l));
00231 Matrix<R,C,P> result = Internal::exp_taylor(m/(1<<s));
00232 for(int i = 0; i < s; ++i)
00233 result = result * result;
00234 return result;
00235 }
00236
00237
00238
00239 template<int S, class P, class B> bool isfinite(const Vector<S, P, B>& v)
00240 {
00241 using std::isfinite;
00242 for(int i=0; i < v.size(); i++)
00243 if(!isfinite(v[i]))
00244 return 0;
00245 return 1;
00246 }
00247
00248
00249
00250 template<int S, class P, class B> bool isnan(const Vector<S, P, B>& v)
00251 {
00252 using std::isnan;
00253 for(int i=0; i < v.size(); i++)
00254 if(isnan(v[i]))
00255 return 1;
00256 return 0;
00257 }
00258
00259
00260
00261
00262
00263 template<int Rows, int Cols, typename Precision, typename Base>
00264 void Symmetrize(Matrix<Rows,Cols,Precision,Base>& m){
00265 SizeMismatch<Rows,Cols>::test(m.num_rows(), m.num_cols());
00266 for(int r=0; r<m.num_rows()-1; r++){
00267 for(int c=r+1; c<m.num_cols(); c++){
00268 const Precision temp=(m(r,c)+m(c,r))/2;
00269 m(r,c)=temp;
00270 m(c,r)=temp;
00271 }
00272 }
00273 }
00274
00275
00276
00277 template<int Rows, int Cols, typename Precision, typename Base>
00278 Precision trace(const Matrix<Rows, Cols, Precision, Base> & m ){
00279 SizeMismatch<Rows,Cols>::test(m.num_rows(), m.num_cols());
00280 Precision tr = 0;
00281 for(int i = 0; i < m.num_rows(); ++i)
00282 tr += m(i,i);
00283 return tr;
00284 }
00285
00286
00287
00288
00289
00290 template<int Size, class P, class B> inline TooN::Matrix<3, 3, P> cross_product_matrix(const Vector<Size, P, B>& vec)
00291 {
00292 SizeMismatch<Size,3>::test(vec.size(), 3);
00293
00294 TooN::Matrix<3> result;
00295
00296 result(0,0) = 0;
00297 result(0,1) = -vec[2];
00298 result(0,2) = vec[1];
00299 result(1,0) = vec[2];
00300 result(1,1) = 0;
00301 result(1,2) = -vec[0];
00302 result(2,0) = -vec[1];
00303 result(2,1) = vec[0];
00304 result(2,2) = 0;
00305
00306 return result;
00307 }
00308
00309 namespace Internal {
00310 template<int Size, typename Precision, typename Base, typename Func, typename Ret> inline Ret accumulate( const Vector<Size, Precision, Base> & v ) {
00311 Func func;
00312 if( v.size() == 0 ) {
00313 return func.null();
00314 }
00315 func.initialise( v[0], 0 );
00316 for( int ii = 1; ii < v.size(); ii++ ) {
00317 func( v[ii], ii );
00318 }
00319 return func.ret();
00320 }
00321
00322 template<int R, int C, typename Precision, typename Base, typename Func, typename Ret> inline Ret accumulate( const Matrix<R, C, Precision, Base> & m ) {
00323 Func func;
00324 if( m.num_rows() == 0 || m.num_cols() == 0) {
00325 return func.null();
00326 }
00327 func.initialise( m[0][0], 0, 0 );
00328 for(int r=0; r<m.num_rows(); r++){
00329 for(int c=0; c<m.num_cols(); c++){
00330 func( m[r][c], r, c );
00331 }
00332 }
00333 return func.ret();
00334 }
00335 template<int R, int C, typename Precision, typename Base, typename Func, typename Ret> inline Ret accumulate_horizontal( const Matrix<R, C, Precision, Base> & m ) {
00336 Func func( m.num_rows() );
00337 if( m.num_cols() == 0 || m.num_rows() == 0 ) {
00338 func.null();
00339 }
00340 for(int r=0; r<m.num_rows(); r++){
00341 func.initialise( m[r][0], r, 0 );
00342 for(int c=1; c<m.num_cols(); c++){
00343 func( m[r][c], r, c );
00344 }
00345 }
00346 return func.ret();
00347 }
00348 template<int R, int C, typename Precision, typename Base, typename Func, typename Ret> inline Ret accumulate_vertical( const Matrix<R, C, Precision, Base> & m ) {
00349 Func func( m.num_cols() );
00350 if( m.num_cols() == 0 || m.num_rows() == 0 ) {
00351 func.null();
00352 }
00353 for(int c=0; c<m.num_cols(); c++){
00354 func.initialise( m[0][c], 0, c );
00355 for(int r=1; r<m.num_rows(); r++){
00356 func( m[r][c], r, c );
00357 }
00358 }
00359 return func.ret();
00360 }
00361
00362 template<typename Precision, typename ComparisonFunctor>
00363 class accumulate_functor_vector {
00364 Precision bestVal;
00365 public:
00366 Precision null() {
00367 return 0;
00368 }
00369 void initialise( Precision initialVal, int ) {
00370 bestVal = initialVal;
00371 }
00372 void operator()( Precision curVal, int ) {
00373 if( ComparisonFunctor()( curVal, bestVal ) ) {
00374 bestVal = curVal;
00375 }
00376 }
00377 Precision ret() { return bestVal; }
00378 };
00379 template<typename Precision, typename ComparisonFunctor>
00380 class accumulate_element_functor_vector {
00381 Precision bestVal;
00382 int nBestIndex;
00383 public:
00384 std::pair<Precision,int> null() {
00385 return std::pair<Precision,int>( 0, 0 );
00386 }
00387 void initialise( Precision initialVal, int nIndex ) {
00388 bestVal = initialVal;
00389 nBestIndex = nIndex;
00390 }
00391 void operator()( Precision curVal, int nIndex ) {
00392 if( ComparisonFunctor()( curVal, bestVal ) ) {
00393 bestVal = curVal;
00394 nBestIndex = nIndex;
00395 }
00396 }
00397 std::pair<Precision,int> ret() {
00398 return std::pair<Precision,int>( bestVal, nBestIndex );
00399 }
00400 };
00401 template<typename Precision, typename ComparisonFunctor>
00402 class accumulate_functor_matrix {
00403 Precision bestVal;
00404 public:
00405 Precision null() {
00406 return 0;
00407 }
00408 void initialise( Precision initialVal, int, int ) {
00409 bestVal = initialVal;
00410 }
00411 void operator()( Precision curVal, int, int ) {
00412 if( ComparisonFunctor()( curVal, bestVal ) ) {
00413 bestVal = curVal;
00414 }
00415 }
00416 Precision ret() { return bestVal; }
00417 };
00418 template<typename Precision, typename ComparisonFunctor>
00419 class accumulate_element_functor_matrix {
00420 Precision bestVal;
00421 int nBestRow;
00422 int nBestCol;
00423 public:
00424 std::pair<Precision,std::pair<int,int> > null() {
00425 return std::pair<Precision,std::pair<int,int> >( 0, std::pair<int,int>( 0, 0 ) );
00426 }
00427 void initialise( Precision initialVal, int nRow, int nCol ) {
00428 bestVal = initialVal;
00429 nBestRow = nRow;
00430 nBestCol = nCol;
00431 }
00432 void operator()( Precision curVal, int nRow, int nCol ) {
00433 if( ComparisonFunctor()( curVal, bestVal ) ) {
00434 bestVal = curVal;
00435 nBestRow = nRow;
00436 nBestCol = nCol;
00437 }
00438 }
00439 std::pair<Precision,std::pair<int,int> > ret() {
00440 return std::pair<Precision,std::pair<int,int> >( bestVal,
00441 std::pair<int,int>( nBestRow, nBestCol ) );
00442 }
00443 };
00444 template<typename Precision, typename ComparisonFunctor>
00445 class accumulate_vertical_functor {
00446 Vector<Dynamic,Precision>* bestVal;
00447 public:
00448 accumulate_vertical_functor() {
00449 bestVal = NULL;
00450 }
00451 accumulate_vertical_functor( int nNumCols ) {
00452 bestVal = new Vector<Dynamic,Precision>( nNumCols );
00453 }
00454 Vector<Dynamic,Precision> null() {
00455 return Vector<Dynamic,Precision>( 0 );
00456 }
00457 void initialise( Precision initialVal, int, int nCol ) {
00458 (*bestVal)[nCol] = initialVal;
00459 }
00460 void operator()( Precision curVal, int, int nCol ) {
00461 if( ComparisonFunctor()( curVal, (*bestVal)[nCol] ) ) {
00462 (*bestVal)[nCol] = curVal;
00463 }
00464 }
00465 Vector<Dynamic,Precision> ret() {
00466 if( bestVal == NULL ) {
00467 return null();
00468 }
00469 Vector<Dynamic,Precision> vRet = *bestVal;
00470 delete bestVal;
00471 return vRet;
00472 }
00473 };
00474 template<typename Precision, typename ComparisonFunctor>
00475 class accumulate_element_vertical_functor {
00476 Vector<Dynamic,Precision>* bestVal;
00477 Vector<Dynamic,Precision>* bestIndices;
00478 public:
00479 accumulate_element_vertical_functor() {
00480 bestVal = NULL;
00481 bestIndices = NULL;
00482 }
00483 accumulate_element_vertical_functor( int nNumCols ) {
00484 bestVal = new Vector<Dynamic,Precision>( nNumCols );
00485 bestIndices = new Vector<Dynamic,Precision>( nNumCols );
00486 }
00487 std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > null() {
00488 Vector<Dynamic,Precision> vEmpty( 0 );
00489 return std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> >( vEmpty, vEmpty );
00490 }
00491 void initialise( Precision initialVal, int nRow, int nCol ) {
00492 (*bestVal)[nCol] = initialVal;
00493 (*bestIndices)[nCol] = nRow;
00494 }
00495 void operator()( Precision curVal, int nRow, int nCol ) {
00496 if( ComparisonFunctor()( curVal, (*bestVal)[nCol] ) ) {
00497 (*bestVal)[nCol] = curVal;
00498 (*bestIndices)[nCol] = nRow;
00499 }
00500 }
00501 std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > ret() {
00502 if( bestVal == NULL ) {
00503 return null();
00504 }
00505 std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > vRet =
00506 std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > (*bestVal, *bestIndices );
00507 delete bestVal; bestVal = NULL;
00508 delete bestIndices; bestIndices = NULL;
00509 return vRet;
00510 }
00511 };
00512 template<typename Precision, typename ComparisonFunctor>
00513 class accumulate_horizontal_functor {
00514 Vector<Dynamic,Precision>* bestVal;
00515 public:
00516 accumulate_horizontal_functor() {
00517 bestVal = NULL;
00518 }
00519 accumulate_horizontal_functor( int nNumRows ) {
00520 bestVal = new Vector<Dynamic,Precision>( nNumRows );
00521 }
00522 Vector<Dynamic,Precision> null() {
00523 return Vector<Dynamic,Precision>( 0 );
00524 }
00525 void initialise( Precision initialVal, int nRow, int ) {
00526 (*bestVal)[nRow] = initialVal;
00527 }
00528 void operator()( Precision curVal, int nRow, int ) {
00529 if( ComparisonFunctor()( curVal, (*bestVal)[nRow] ) ) {
00530 (*bestVal)[nRow] = curVal;
00531 }
00532 }
00533 Vector<Dynamic,Precision> ret() {
00534 if( bestVal == NULL ) {
00535 return null();
00536 }
00537 Vector<Dynamic,Precision> vRet = *bestVal;
00538 delete bestVal; bestVal = NULL;
00539 return vRet;
00540 }
00541 };
00542 template<typename Precision, typename ComparisonFunctor>
00543 class accumulate_element_horizontal_functor {
00544 Vector<Dynamic,Precision>* bestVal;
00545 Vector<Dynamic,Precision>* bestIndices;
00546 public:
00547 accumulate_element_horizontal_functor() {
00548 bestVal = NULL;
00549 bestIndices = NULL;
00550 }
00551 accumulate_element_horizontal_functor( int nNumRows ) {
00552 bestVal = new Vector<Dynamic,Precision>( nNumRows );
00553 bestIndices = new Vector<Dynamic,Precision>( nNumRows );
00554 }
00555 std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > null() {
00556 Vector<Dynamic,Precision> vEmpty( 0 );
00557 return std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> >( vEmpty, vEmpty );
00558 }
00559 void initialise( Precision initialVal, int nRow, int nCol ) {
00560 (*bestVal)[nRow] = initialVal;
00561 (*bestIndices)[nRow] = nCol;
00562 }
00563 void operator()( Precision curVal, int nRow, int nCol ) {
00564 if( ComparisonFunctor()( curVal, (*bestVal)[nRow] ) ) {
00565 (*bestVal)[nRow] = curVal;
00566 (*bestIndices)[nRow] = nCol;
00567 }
00568 }
00569 std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > ret() {
00570 if( bestVal == NULL ) {
00571 return null();
00572 }
00573 std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > vRet =
00574 std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> >( *bestVal, *bestIndices );
00575 delete bestVal; bestVal = NULL;
00576 delete bestIndices; bestIndices = NULL;
00577 return vRet;
00578 }
00579 };
00580 }
00581
00582
00583
00584
00585 template<int Size, typename Precision, typename Base> inline Precision min( const Vector<Size, Precision, Base>& v) {
00586 typedef Internal::accumulate_functor_vector<Precision, std::less<Precision> > vector_accumulate_functor;
00587 return Internal::accumulate<Size,Precision,Base,
00588 vector_accumulate_functor, Precision >( v );
00589 }
00590
00591
00592
00593 template<int Size, typename Precision, typename Base> inline Precision max( const Vector<Size, Precision, Base>& v) {
00594 typedef Internal::accumulate_functor_vector<Precision, std::greater<Precision> > vector_accumulate_functor;
00595 return Internal::accumulate<Size,Precision,Base,
00596 vector_accumulate_functor, Precision >( v );
00597 }
00598
00599
00600
00601 template<int R, int C, typename Precision, typename Base> inline Precision min( const Matrix<R, C, Precision, Base> & m) {
00602 typedef Internal::accumulate_functor_matrix<Precision, std::less<Precision> > matrix_accumulate_functor;
00603 return Internal::accumulate<R,C,Precision,Base,
00604 matrix_accumulate_functor, Precision>( m );
00605 }
00606
00607
00608
00609 template<int R, int C, typename Precision, typename Base> inline Precision max( const Matrix<R, C, Precision, Base> & m) {
00610 typedef Internal::accumulate_functor_matrix<Precision, std::greater<Precision> > matrix_accumulate_functor;
00611 return Internal::accumulate<R,C,Precision,Base,
00612 matrix_accumulate_functor, Precision>( m );
00613 }
00614
00615
00616
00617 template<int R, int C, typename Precision, typename Base> inline Vector<Dynamic,Precision> min_vertical( const Matrix<R, C, Precision, Base> & m) {
00618 typedef Internal::accumulate_vertical_functor<Precision,std::less<Precision> > matrix_accumulate_vertical_functor;
00619 return Internal::accumulate_vertical<R,C,Precision,Base,
00620 matrix_accumulate_vertical_functor, Vector<Dynamic,Precision> >( m );
00621 }
00622
00623
00624
00625 template<int R, int C, typename Precision, typename Base> inline Vector<Dynamic,Precision> max_vertical( const Matrix<R, C, Precision, Base> & m) {
00626 typedef Internal::accumulate_vertical_functor<Precision,std::greater<Precision> > matrix_accumulate_vertical_functor;
00627 return Internal::accumulate_vertical<R,C,Precision,Base,
00628 matrix_accumulate_vertical_functor, Vector<Dynamic,Precision> >( m );
00629 }
00630
00631
00632
00633 template<int R, int C, typename Precision, typename Base> inline Vector<Dynamic,Precision> min_horizontal( const Matrix<R, C, Precision, Base> & m) {
00634 typedef Internal::accumulate_horizontal_functor<Precision,std::less<Precision> > matrix_accumulate_horizontal_functor;
00635 return Internal::accumulate_horizontal<R,C,Precision,Base,
00636 matrix_accumulate_horizontal_functor, Vector<Dynamic,Precision> >( m );
00637 }
00638
00639
00640
00641 template<int R, int C, typename Precision, typename Base> inline Vector<Dynamic,Precision> max_horizontal( const Matrix<R, C, Precision, Base> & m) {
00642 typedef Internal::accumulate_horizontal_functor<Precision,std::greater<Precision> > matrix_accumulate_horizontal_functor;
00643 return Internal::accumulate_horizontal<R,C,Precision,Base,
00644 matrix_accumulate_horizontal_functor, Vector<Dynamic,Precision> >( m );
00645 }
00646
00647
00648
00649 template<int Size, typename Precision, typename Base> inline std::pair<Precision,int> min_element( const Vector<Size, Precision, Base>& v) {
00650 typedef Internal::accumulate_element_functor_vector<Precision, std::less<Precision> > vector_accumulate_functor;
00651 return Internal::accumulate<Size,Precision,Base,
00652 vector_accumulate_functor, std::pair<Precision,int> >( v );
00653 }
00654
00655
00656
00657 template<int Size, typename Precision, typename Base> inline std::pair<Precision,int> max_element( const Vector<Size, Precision, Base>& v) {
00658 typedef Internal::accumulate_element_functor_vector<Precision, std::greater<Precision> > vector_accumulate_functor;
00659 return Internal::accumulate<Size,Precision,Base,
00660 vector_accumulate_functor, std::pair<Precision,int> >( v );
00661 }
00662
00663
00664
00665
00666 template<int R, int C, typename Precision, typename Base> inline std::pair<Precision,std::pair<int,int> > min_element( const Matrix<R, C, Precision, Base> & m) {
00667 typedef Internal::accumulate_element_functor_matrix<Precision, std::less<Precision> > matrix_accumulate_functor;
00668 typedef std::pair<Precision,std::pair<int,int> > Ret;
00669 return Internal::accumulate<R,C,Precision,Base,
00670 matrix_accumulate_functor, Ret>( m );
00671 }
00672
00673
00674
00675
00676 template<int R, int C, typename Precision, typename Base> inline std::pair<Precision,std::pair<int,int> > max_element( const Matrix<R, C, Precision, Base> & m) {
00677 typedef Internal::accumulate_element_functor_matrix<Precision, std::greater<Precision> > matrix_accumulate_functor;
00678 typedef std::pair<Precision,std::pair<int,int> > Ret;
00679 return Internal::accumulate<R,C,Precision,Base,
00680 matrix_accumulate_functor, Ret>( m );
00681 }
00682
00683
00684
00685
00686
00687 template<int R, int C, typename Precision, typename Base> inline std::pair<Vector<Dynamic,Precision>,Vector<Dynamic,Precision> > min_element_vertical( const Matrix<R, C, Precision, Base> & m) {
00688 typedef Internal::accumulate_element_vertical_functor<Precision,std::less<Precision> > matrix_accumulate_vertical_functor;
00689 typedef std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > Ret;
00690 return Internal::accumulate_vertical<R,C,Precision,Base,
00691 matrix_accumulate_vertical_functor, Ret >( m );
00692 }
00693
00694
00695
00696
00697
00698 template<int R, int C, typename Precision, typename Base> inline std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > max_element_vertical( const Matrix<R, C, Precision, Base> & m) {
00699 typedef Internal::accumulate_element_vertical_functor<Precision,std::greater<Precision> > matrix_accumulate_vertical_functor;
00700 typedef std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > Ret;
00701 return Internal::accumulate_vertical<R,C,Precision,Base,
00702 matrix_accumulate_vertical_functor, Ret >( m );
00703 }
00704
00705
00706
00707
00708
00709 template<int R, int C, typename Precision, typename Base> inline std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > min_element_horizontal( const Matrix<R, C, Precision, Base> & m) {
00710 typedef Internal::accumulate_element_horizontal_functor<Precision,std::less<Precision> > matrix_accumulate_vertical_functor;
00711 typedef std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > Ret;
00712 return Internal::accumulate_horizontal<R,C,Precision,Base,
00713 matrix_accumulate_vertical_functor, Ret >( m );
00714 }
00715
00716
00717
00718
00719
00720 template<int R, int C, typename Precision, typename Base> inline std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > max_element_horizontal( const Matrix<R, C, Precision, Base> & m) {
00721 typedef Internal::accumulate_element_horizontal_functor<Precision,std::greater<Precision> > matrix_accumulate_vertical_functor;
00722 typedef std::pair<Vector< Dynamic, Precision >,Vector< Dynamic, Precision > > Ret;
00723 return Internal::accumulate_horizontal<R,C,Precision,Base,
00724 matrix_accumulate_vertical_functor, Ret >( m );
00725 }
00726 }
00727 #endif