[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN helpers.h
From: |
Christopher Mei |
Subject: |
[Toon-members] TooN helpers.h |
Date: |
Wed, 24 Jun 2009 13:51:32 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Christopher Mei <cmei> 09/06/24 13:51:32
Modified files:
. : helpers.h
Log message:
Modified accumulate*/min/max functions to use functors and
std::min/std::max.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/helpers.h?cvsroot=toon&r1=1.72&r2=1.73
Patches:
Index: helpers.h
===================================================================
RCS file: /cvsroot/toon/TooN/helpers.h,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -b -r1.72 -r1.73
--- helpers.h 24 Jun 2009 13:17:17 -0000 1.72
+++ helpers.h 24 Jun 2009 13:51:32 -0000 1.73
@@ -320,31 +320,31 @@
}
namespace Internal {
- template<int Size, typename Precision, typename Base, const Precision&
(*pFunc)(Precision,Precision)> inline Precision accumulate( const Vector<Size,
Precision, Base> & v ) {
+ template<int Size, typename Precision, typename Base, typename Func>
inline Precision accumulate( const Vector<Size, Precision, Base> & v, Func func
) {
if( v.size() == 0 ) {
return 0; // What should we return, exception?
}
Precision val = v[0];
for( int ii = 1; ii < v.size(); ii++ ) {
- val = pFunc( val, v[ii] );
+ val = func( val, v[ii] );
}
return val;
}
- template<int R, int C, typename Precision, typename Base, const
Precision& (*pFunc)(Precision,Precision)> inline Precision accumulate( const
Matrix<R, C, Precision, Base> & m ) {
+ template<int R, int C, typename Precision, typename Base, typename
Func> inline Precision accumulate( const Matrix<R, C, Precision, Base> & m,
Func func ) {
if( m.num_rows() == 0 || m.num_cols() == 0) {
return 0; // What should we return, exception?
}
Precision val = m[0][0];
for(int r=0; r<m.num_rows(); r++){
for(int c=0; c<m.num_cols(); c++){
- val = pFunc( val, m[r][c] );
+ val = func( val, m[r][c] );
}
}
return val;
}
- template<int R, int C, typename Precision, typename Base, const
Precision& (*pFunc)(Precision,Precision)> inline Vector<R, Precision>
accumulate_horizontal( const Matrix<R, C, Precision, Base> & m) {
+ template<int R, int C, typename Precision, typename Base, typename
Func> inline Vector<R, Precision> accumulate_horizontal( const Matrix<R, C,
Precision, Base> & m, Func func ) {
if( m.num_cols() == 0 || m.num_rows() == 0 ) {
return 0; // What should we return, exception?
}
@@ -352,14 +352,14 @@
for(int r=0; r<m.num_rows(); r++){
Precision val_row = m[r][0];
for(int c=1; c<m.num_cols(); c++){
- val_row = pFunc( val_row, m[r][c] );
+ val_row = func( val_row, m[r][c] );
}
result[r] = val_row;
}
return result;
}
- template<int R, int C, typename Precision, typename Base, const
Precision& (*pFunc)(Precision,Precision)> inline Vector<C, Precision>
accumulate_vertical( const Matrix<R, C, Precision, Base> & m) {
+ template<int R, int C, typename Precision, typename Base, typename
Func> inline Vector<C, Precision> accumulate_vertical( const Matrix<R, C,
Precision, Base> & m, Func func ) {
if( m.num_cols() == 0 || m.num_rows() == 0 ) {
return 0; // What should we return, exception?
}
@@ -367,42 +367,44 @@
for(int c=0; c<m.num_cols(); c++){
Precision val_col = m[0][c];
for(int r=1; r<m.num_rows(); r++){
- val_col = pFunc( val_col, m[r][c] );
+ val_col = func( val_col, m[r][c] );
}
result[c] = val_col;
}
return result;
}
}
- template<typename Precision> const Precision& non_const_min( Precision a,
Precision b ) {
- return std::min( a, b );
- }
- template<typename Precision> const Precision& non_const_max( Precision a,
Precision b ) {
- return std::max( a, b );
- }
template<int Size, typename Precision, typename Base> inline Precision
min( const Vector<Size, Precision, Base> & v) {
- return Internal::accumulate<Size,Precision,Base,non_const_min>( v );
+ return Internal::accumulate<Size,Precision,Base,
+ const Precision& (*) ( const Precision&, const Precision& )>( v,
std::min<Precision> );
}
template<int R, int C, typename Precision, typename Base> inline Precision
min( const Matrix<R, C, Precision, Base> & m) {
- return Internal::accumulate<R,C,Precision,Base,non_const_min>( m );
+ return Internal::accumulate<R,C,Precision,Base,
+ const Precision& (*) ( const Precision&, const Precision& )>( m,
std::min<Precision> );
}
template<int R, int C, typename Precision, typename Base> inline Vector<C,
Precision> min_vertical( const Matrix<R, C, Precision, Base> & m) {
- return
Internal::accumulate_vertical<R,C,Precision,Base,non_const_min>( m );
+ return Internal::accumulate_vertical<R,C,Precision,Base,
+ const Precision& (*) ( const Precision&, const Precision& )>( m,
std::min );
}
template<int R, int C, typename Precision, typename Base> inline Vector<R,
Precision> min_horizontal( const Matrix<R, C, Precision, Base> & m) {
- return
Internal::accumulate_horizontal<R,C,Precision,Base,non_const_min>( m );
+ return Internal::accumulate_horizontal<R,C,Precision,Base,
+ const Precision& (*) ( const Precision&, const Precision& )>( m,
std::min );
}
template<int Size, typename Precision, typename Base> inline Precision
max( const Vector<Size, Precision, Base> & v) {
- return Internal::accumulate<Size,Precision,Base,non_const_max>( v );
+ return Internal::accumulate<Size,Precision,Base,
+ const Precision& (*) ( const Precision&, const Precision& )>( v,
std::max );
}
template<int R, int C, typename Precision, typename Base> inline Precision
max( const Matrix<R, C, Precision, Base> & m) {
- return Internal::accumulate<R,C,Precision,Base,non_const_max>( m );
+ return Internal::accumulate<R,C,Precision,Base,
+ const Precision& (*) ( const Precision&, const Precision& )>(
m, std::max );
}
template<int R, int C, typename Precision, typename Base> inline Vector<C,
Precision> max_vertical( const Matrix<R, C, Precision, Base> & m) {
- return
Internal::accumulate_vertical<R,C,Precision,Base,non_const_max>( m );
+ return Internal::accumulate_vertical<R,C,Precision,Base,
+ const Precision& (*) ( const Precision&, const Precision& )>(
m, std::max );
}
template<int R, int C, typename Precision, typename Base> inline Vector<R,
Precision> max_horizontal( const Matrix<R, C, Precision, Base> & m) {
- return
Internal::accumulate_horizontal<R,C,Precision,Base,non_const_max>( m );
+ return Internal::accumulate_horizontal<R,C,Precision,Base,
+ const Precision& (*) ( const Precision&, const Precision& )>(
m, std::max );
}
}
#endif
- [Toon-members] TooN helpers.h, Edward Rosten, 2009/06/18
- [Toon-members] TooN helpers.h, Edward Rosten, 2009/06/22
- [Toon-members] TooN helpers.h, Christopher Mei, 2009/06/25
- [Toon-members] TooN helpers.h, Christopher Mei, 2009/06/25
- [Toon-members] TooN helpers.h,
Christopher Mei <=
- [Toon-members] TooN helpers.h, Christopher Mei, 2009/06/25
- [Toon-members] TooN helpers.h, Christopher Mei, 2009/06/26
- [Toon-members] TooN helpers.h, Christopher Mei, 2009/06/29
- [Toon-members] TooN helpers.h, Christopher Mei, 2009/06/29