Commit 76913c7d authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

new functions

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 1677
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 162e83a1
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: README.changelog,v 1.49 2005-04-21 15:21:10 tforb Exp $ * $Id: README.changelog,v 1.50 2005-04-21 15:34:21 tforb Exp $
* *
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
* *
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
/*! \page page_changelog ChangeLog (AFF) /*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.49 2005-04-21 15:21:10 tforb Exp $ $Id: README.changelog,v 1.50 2005-04-21 15:34:21 tforb Exp $
\sa \ref page_project_status \sa \ref page_project_status
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
- \b 21/04/2005 (thof) - \b 21/04/2005 (thof)
- aff::func::avg() and underlying code works. - aff::func::avg() and underlying code works.
- added code for functions aff::func::rms(), aff::func::min(),
aff::func::max()
- \b 20/03/2005 (thof) - \b 20/03/2005 (thof)
- Added function templates to scan and map values in containers. - Added function templates to scan and map values in containers.
...@@ -214,7 +216,7 @@ ...@@ -214,7 +216,7 @@
/*! \page page_project_status Project status (AFF) /*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.49 2005-04-21 15:21:10 tforb Exp $ $Id: README.changelog,v 1.50 2005-04-21 15:34:21 tforb Exp $
\sa \ref page_changelog \sa \ref page_changelog
...@@ -369,16 +371,16 @@ ...@@ -369,16 +371,16 @@
<TR><TD><BR><B>subdirectory "functions"</B></TD></TR> <TR><TD><BR><B>subdirectory "functions"</B></TD></TR>
<TR><TD>libaff/functions/max.h</TD> <TR><TD>libaff/functions/max.h</TD>
<TD></TD><TD></TD><TD></TD><TD> </TD> <TD>21/04/2005</TD><TD>21/04/2005</TD><TD>21/04/2005</TD><TD> </TD>
</TR> </TR>
<TR><TD>libaff/functions/min.h</TD> <TR><TD>libaff/functions/min.h</TD>
<TD></TD><TD></TD><TD></TD><TD> </TD> <TD>21/04/2005</TD><TD>21/04/2005</TD><TD>21/04/2005</TD><TD> </TD>
</TR> </TR>
<TR><TD>libaff/functions/avg.h</TD> <TR><TD>libaff/functions/avg.h</TD>
<TD>21/04/2005</TD><TD>21/04/2005</TD><TD>21/04/2005</TD><TD> </TD> <TD>21/04/2005</TD><TD>21/04/2005</TD><TD>21/04/2005</TD><TD> </TD>
</TR> </TR>
<TR><TD>libaff/functions/rms.h</TD> <TR><TD>libaff/functions/rms.h</TD>
<TD></TD><TD></TD><TD></TD><TD> </TD> <TD>21/04/2005</TD><TD>21/04/2005</TD><TD></TD><TD> </TD>
</TR> </TR>
<TR><TD>libaff/functions/valmap.h</TD> <TR><TD>libaff/functions/valmap.h</TD>
<TD></TD><TD></TD><TD></TD><TD> </TD> <TD></TD><TD></TD><TD></TD><TD> </TD>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: max.h,v 1.1 2005-03-21 09:35:33 tforb Exp $ * $Id: max.h,v 1.2 2005-04-21 15:34:21 tforb Exp $
* \author Thomas Forbriger * \author Thomas Forbriger
* \date 20/03/2005 * \date 20/03/2005
* *
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#define AFF_MAX_H_VERSION \ #define AFF_MAX_H_VERSION \
"AFF_MAX_H V1.0 " "AFF_MAX_H V1.0 "
#define AFF_MAX_H_CVSID \ #define AFF_MAX_H_CVSID \
"$Id: max.h,v 1.1 2005-03-21 09:35:33 tforb Exp $" "$Id: max.h,v 1.2 2005-04-21 15:34:21 tforb Exp $"
#include<aff/lib/collector.h> #include<aff/lib/collector.h>
...@@ -33,25 +33,48 @@ namespace aff { ...@@ -33,25 +33,48 @@ namespace aff {
namespace util { namespace util {
template<class T> /*! utility class to extract the largest value from a container
class MaxCollector { *
* This class should be used together with the
* aff::func::util::collect() function template.
*
* \param C any container class like aff::Array<double>
*/
template<class C>
class Extractmax {
typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue;
public: public:
typedef T Tvalue; //! initialize member data
MaxCollector(): Mval(Tvalue()) { } Extractmax(const Tcont& c): Mval(c(c.first())) { }
MaxCollector(const Tvalue& v): Mval(v) { } //! collect another value
MaxCollector operator() (cont Tvalue& v) void operator() (const Tvalue& v)
{ { Mval = Mval > v ? Mval : v; }
Mval //! return result of operation
Tvalue result() const { return(Mval); }
private: private:
T Mval; Tvalue Mval;
}; // class MaxCollector }; // class Extractmax
} // namespace util } // namespace util
template<class C, class T> /*----------------------------------------------------------------------*/
T max(const typename C<T>::Tcoc& c)
/*! Function template to extract the largest from the values
* stored in a container
*
* \param C any container class like aff::Array<double>
* (this value is deduced by the compiler)
* \param c any container of numerical values
* \return largest value of container contents
*
* \sa aff::func::util::collect, aff::func::util::Extractmax
*/
template<class C>
typename C::Tvalue max(const C& c)
{ {
} return(aff::func::util::collect<C, aff::func::util::Extractmax>(c));
} // min()
} // namespace func } // namespace func
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: min.h,v 1.1 2005-03-21 09:35:33 tforb Exp $ * $Id: min.h,v 1.2 2005-04-21 15:34:21 tforb Exp $
* \author Thomas Forbriger * \author Thomas Forbriger
* \date 20/03/2005 * \date 20/03/2005
* *
...@@ -23,11 +23,63 @@ ...@@ -23,11 +23,63 @@
#define AFF_MIN_H_VERSION \ #define AFF_MIN_H_VERSION \
"AFF_MIN_H V1.0 " "AFF_MIN_H V1.0 "
#define AFF_MIN_H_CVSID \ #define AFF_MIN_H_CVSID \
"$Id: min.h,v 1.1 2005-03-21 09:35:33 tforb Exp $" "$Id: min.h,v 1.2 2005-04-21 15:34:21 tforb Exp $"
namespace tf {
} #include<aff/lib/collector.h>
namespace aff {
namespace func {
namespace util {
/*! utility class to extract the smallest value from a container
*
* This class should be used together with the
* aff::func::util::collect() function template.
*
* \param C any container class like aff::Array<double>
*/
template<class C>
class Extractmin {
typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue;
public:
//! initialize member data
Extractmin(const Tcont& c): Mval(c(c.first())) { }
//! collect another value
void operator() (const Tvalue& v)
{ Mval = Mval < v ? Mval : v; }
//! return result of operation
Tvalue result() const { return(Mval); }
private:
Tvalue Mval;
}; // class Extractmin
} // namespace util
/*----------------------------------------------------------------------*/
/*! Function template to extract the smallest from the values
* stored in a container
*
* \param C any container class like aff::Array<double>
* (this value is deduced by the compiler)
* \param c any container of numerical values
* \return smallest value of container contents
*
* \sa aff::func::util::collect, aff::func::util::Extractmin
*/
template<class C>
typename C::Tvalue min(const C& c)
{
return(aff::func::util::collect<C, aff::func::util::Extractmin>(c));
} // min()
} // namespace func
} // namespace aff
#endif // AFF_MIN_H_VERSION (includeguard) #endif // AFF_MIN_H_VERSION (includeguard)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: rms.h,v 1.1 2005-03-21 09:35:34 tforb Exp $ * $Id: rms.h,v 1.2 2005-04-21 15:34:21 tforb Exp $
* \author Thomas Forbriger * \author Thomas Forbriger
* \date 20/03/2005 * \date 20/03/2005
* *
...@@ -23,11 +23,63 @@ ...@@ -23,11 +23,63 @@
#define AFF_RMS_H_VERSION \ #define AFF_RMS_H_VERSION \
"AFF_RMS_H V1.0 " "AFF_RMS_H V1.0 "
#define AFF_RMS_H_CVSID \ #define AFF_RMS_H_CVSID \
"$Id: rms.h,v 1.1 2005-03-21 09:35:34 tforb Exp $" "$Id: rms.h,v 1.2 2005-04-21 15:34:21 tforb Exp $"
namespace tf {
} #include<aff/lib/collector.h>
namespace aff {
namespace func {
namespace util {
/*! utility class to extract root mean square value from a container
*
* This class should be used together with the
* aff::func::util::collect() function template.
*
* \param C any container class like aff::Array<double>
*/
template<class C>
class Extractrms {
typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue;
public:
//! initialize member data
Extractrms(const Tcont& c): Msum(0), Mn(0) { }
//! collect another value
void operator() (const Tvalue& v) { Msum+=(v*v); ++Mn; }
//! return result of operation
Tvalue result() const { return(std::sqrt(Msum/Tvalue(Mn))); }
private:
Tvalue Msum;
int Mn;
}; // class Extractrms
} // namespace util
/*----------------------------------------------------------------------*/
/*! Function template to extract the root mean square from the values
* stored in a container
*
* \param C any container class like aff::Array<double>
* (this value is deduced by the compiler)
* \param c any container of numerical values
* \return root mean square of container contents
*
* \sa aff::func::util::collect, aff::func::util::Extractrms
*/
template<class C>
typename C::Tvalue rms(const C& c)
{
return(aff::func::util::collect<C, aff::func::util::Extractrms>(c));
} // rms()
} // namespace func
} // namespace aff
#endif // AFF_RMS_H_VERSION (includeguard) #endif // AFF_RMS_H_VERSION (includeguard)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: functionstest.cc,v 1.3 2005-04-21 15:21:11 tforb Exp $ * $Id: functionstest.cc,v 1.4 2005-04-21 15:34:22 tforb Exp $
* \author Thomas Forbriger * \author Thomas Forbriger
* \date 20/03/2005 * \date 20/03/2005
* *
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#define FUNCTIONSTEST_VERSION \ #define FUNCTIONSTEST_VERSION \
"FUNCTIONSTEST V1.0 test function templates" "FUNCTIONSTEST V1.0 test function templates"
#define FUNCTIONSTEST_CVSID \ #define FUNCTIONSTEST_CVSID \
"$Id: functionstest.cc,v 1.3 2005-04-21 15:21:11 tforb Exp $" "$Id: functionstest.cc,v 1.4 2005-04-21 15:34:22 tforb Exp $"
#include <iostream> #include <iostream>
#include <aff/dump.h> #include <aff/dump.h>
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
#include <aff/shaper.h> #include <aff/shaper.h>
#include <aff/subarray.h> #include <aff/subarray.h>
#include <aff/functions/avg.h> #include <aff/functions/avg.h>
#include <aff/functions/min.h>
#include <aff/functions/max.h>
#include <aff/functions/rms.h>
using namespace aff; using namespace aff;
...@@ -44,6 +47,9 @@ int main(int iargc, char* argv[]) ...@@ -44,6 +47,9 @@ int main(int iargc, char* argv[])
CODE( subarray(A)(2,3)(3,4)=-4. ); CODE( subarray(A)(2,3)(3,4)=-4. );
CODE( dump_array(A) ); CODE( dump_array(A) );
CODE( cout << aff::func::avg(A) << endl ); CODE( cout << aff::func::avg(A) << endl );
CODE( cout << aff::func::rms(A) << endl );
CODE( cout << aff::func::max(A) << endl );
CODE( cout << aff::func::min(A) << endl );
} }
/* ----- END OF functionstest.cc ----- */ /* ----- END OF functionstest.cc ----- */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment