Commit 52ac1c7a authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

new function

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: 1683
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 76913c7d
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: README.changelog,v 1.50 2005-04-21 15:34:21 tforb Exp $ * $Id: README.changelog,v 1.51 2005-04-28 11:38:04 tforb Exp $
* *
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) * Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
* *
...@@ -21,12 +21,17 @@ ...@@ -21,12 +21,17 @@
/*! \page page_changelog ChangeLog (AFF) /*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.50 2005-04-21 15:34:21 tforb Exp $ $Id: README.changelog,v 1.51 2005-04-28 11:38:04 tforb Exp $
\sa \ref page_project_status \sa \ref page_project_status
Major changes in the interface of the library are marked by \b !!. Major changes in the interface of the library are marked by \b !!.
- \b 28/04/2005 (thof)
- added code for aff::func::histo()
- introduced Tretval to all collector help classes and to collect function
itself
- \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(), - added code for functions aff::func::rms(), aff::func::min(),
...@@ -216,7 +221,7 @@ ...@@ -216,7 +221,7 @@
/*! \page page_project_status Project status (AFF) /*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.50 2005-04-21 15:34:21 tforb Exp $ $Id: README.changelog,v 1.51 2005-04-28 11:38:04 tforb Exp $
\sa \ref page_changelog \sa \ref page_changelog
...@@ -370,13 +375,16 @@ ...@@ -370,13 +375,16 @@
</TR> </TR>
<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/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/min.h</TD> <TR><TD>libaff/functions/histo.h</TD>
<TD>28/04/2005</TD><TD>28/04/2005</TD><TD>28/04/2005</TD><TD> </TD>
</TR>
<TR><TD>libaff/functions/max.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/avg.h</TD> <TR><TD>libaff/functions/min.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>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: avg.h,v 1.3 2005-04-21 15:21:11 tforb Exp $ * $Id: avg.h,v 1.4 2005-04-28 11:38:05 tforb Exp $
* \author Thomas Forbriger * \author Thomas Forbriger
* \date 20/03/2005 * \date 20/03/2005
* *
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* *
* REVISIONS and CHANGES * REVISIONS and CHANGES
* - 20/03/2005 V1.0 Thomas Forbriger * - 20/03/2005 V1.0 Thomas Forbriger
* - 28/04/2005 V1.1 provide return type
* *
* ============================================================================ * ============================================================================
*/ */
...@@ -21,9 +22,9 @@ ...@@ -21,9 +22,9 @@
#ifndef AFF_AVG_H_VERSION #ifndef AFF_AVG_H_VERSION
#define AFF_AVG_H_VERSION \ #define AFF_AVG_H_VERSION \
"AFF_AVG_H V1.0 " "AFF_AVG_H V1.1 "
#define AFF_AVG_H_CVSID \ #define AFF_AVG_H_CVSID \
"$Id: avg.h,v 1.3 2005-04-21 15:21:11 tforb Exp $" "$Id: avg.h,v 1.4 2005-04-28 11:38:05 tforb Exp $"
#include<aff/lib/collector.h> #include<aff/lib/collector.h>
...@@ -46,12 +47,13 @@ namespace aff { ...@@ -46,12 +47,13 @@ namespace aff {
typedef typename C::Tcoc Tcont; typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue; typedef typename C::Tvalue Tvalue;
public: public:
typedef Tvalue Tretval;
//! initialize member data //! initialize member data
Extractavg(const Tcont& c): Msum(0), Mn(0) { } Extractavg(const Tcont& c): Msum(0), Mn(0) { }
//! collect another value //! collect another value
void operator() (const Tvalue& v) { Msum+=v; ++Mn; } void operator() (const Tvalue& v) { Msum+=v; ++Mn; }
//! return result of operation //! return result of operation
Tvalue result() const { return(Msum/Tvalue(Mn)); } Tretval result() const { return(Msum/Tvalue(Mn)); }
private: private:
Tvalue Msum; Tvalue Msum;
int Mn; int Mn;
......
/*! \file histo.h
* \brief count elements of same value (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: histo.h,v 1.1 2005-04-28 11:38:05 tforb Exp $
* \author Thomas Forbriger
* \date 28/04/2005
*
* count elements of same value (prototypes)
*
* Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach)
*
* REVISIONS and CHANGES
* - 28/04/2005 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef AFF_HISTO_H_VERSION
#define AFF_HISTO_H_VERSION \
"AFF_HISTO_H V1.0 "
#define AFF_HISTO_H_CVSID \
"$Id: histo.h,v 1.1 2005-04-28 11:38:05 tforb Exp $"
#include<aff/lib/collector.h>
#include<map>
namespace aff {
namespace func {
namespace util {
/*! utility class to count elements of the same value
*
* 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 Extracthisto {
typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue;
public:
typedef typename std::map<Tvalue,int> Tmap;
typedef Tmap Tretval;
//! initialize member data
Extracthisto(const Tcont& c) { }
//! collect another value
void operator() (const Tvalue& v)
{ ++Mmap[v]; }
//! return result of operation
Tretval result() const { return(Mmap); }
private:
Tmap Mmap;
}; // class Extracthisto
} // namespace util
/*----------------------------------------------------------------------*/
/*! Function template to count elements of the same value
*
* \param C any container class like aff::Array<double>
* (this value is deduced by the compiler)
* \param c any container of numerical values
* \return a map the associates every value with the number of elements
* that have this value
*
* \sa aff::func::util::collect, aff::func::util::Extracthisto
*/
template<class C>
typename aff::func::util::Extracthisto<C>::Tmap histo(const C& c)
{
return(aff::func::util::collect<C, aff::func::util::Extracthisto>(c));
} // histo()
} // namespace func
} // namespace aff
#endif // AFF_HISTO_H_VERSION (includeguard)
/* ----- END OF histo.h ----- */
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: max.h,v 1.2 2005-04-21 15:34:21 tforb Exp $ * $Id: max.h,v 1.3 2005-04-28 11:38:05 tforb Exp $
* \author Thomas Forbriger * \author Thomas Forbriger
* \date 20/03/2005 * \date 20/03/2005
* *
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* *
* REVISIONS and CHANGES * REVISIONS and CHANGES
* - 20/03/2005 V1.0 Thomas Forbriger * - 20/03/2005 V1.0 Thomas Forbriger
* - 28/04/2005 V1.1 provide return type
* *
* ============================================================================ * ============================================================================
*/ */
...@@ -21,9 +22,9 @@ ...@@ -21,9 +22,9 @@
#ifndef AFF_MAX_H_VERSION #ifndef AFF_MAX_H_VERSION
#define AFF_MAX_H_VERSION \ #define AFF_MAX_H_VERSION \
"AFF_MAX_H V1.0 " "AFF_MAX_H V1.1 "
#define AFF_MAX_H_CVSID \ #define AFF_MAX_H_CVSID \
"$Id: max.h,v 1.2 2005-04-21 15:34:21 tforb Exp $" "$Id: max.h,v 1.3 2005-04-28 11:38:05 tforb Exp $"
#include<aff/lib/collector.h> #include<aff/lib/collector.h>
...@@ -45,13 +46,14 @@ namespace aff { ...@@ -45,13 +46,14 @@ namespace aff {
typedef typename C::Tcoc Tcont; typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue; typedef typename C::Tvalue Tvalue;
public: public:
typedef Tvalue Tretval;
//! initialize member data //! initialize member data
Extractmax(const Tcont& c): Mval(c(c.first())) { } Extractmax(const Tcont& c): Mval(c(c.first())) { }
//! collect another value //! collect another value
void operator() (const Tvalue& v) void operator() (const Tvalue& v)
{ Mval = Mval > v ? Mval : v; } { Mval = Mval > v ? Mval : v; }
//! return result of operation //! return result of operation
Tvalue result() const { return(Mval); } Tretval result() const { return(Mval); }
private: private:
Tvalue Mval; Tvalue Mval;
}; // class Extractmax }; // class Extractmax
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: min.h,v 1.2 2005-04-21 15:34:21 tforb Exp $ * $Id: min.h,v 1.3 2005-04-28 11:38:05 tforb Exp $
* \author Thomas Forbriger * \author Thomas Forbriger
* \date 20/03/2005 * \date 20/03/2005
* *
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* *
* REVISIONS and CHANGES * REVISIONS and CHANGES
* - 20/03/2005 V1.0 Thomas Forbriger * - 20/03/2005 V1.0 Thomas Forbriger
* - 28/04/2005 V1.1 provide return type
* *
* ============================================================================ * ============================================================================
*/ */
...@@ -21,9 +22,9 @@ ...@@ -21,9 +22,9 @@
#ifndef AFF_MIN_H_VERSION #ifndef AFF_MIN_H_VERSION
#define AFF_MIN_H_VERSION \ #define AFF_MIN_H_VERSION \
"AFF_MIN_H V1.0 " "AFF_MIN_H V1.1 "
#define AFF_MIN_H_CVSID \ #define AFF_MIN_H_CVSID \
"$Id: min.h,v 1.2 2005-04-21 15:34:21 tforb Exp $" "$Id: min.h,v 1.3 2005-04-28 11:38:05 tforb Exp $"
#include<aff/lib/collector.h> #include<aff/lib/collector.h>
...@@ -46,13 +47,14 @@ namespace aff { ...@@ -46,13 +47,14 @@ namespace aff {
typedef typename C::Tcoc Tcont; typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue; typedef typename C::Tvalue Tvalue;
public: public:
typedef Tvalue Tretval;
//! initialize member data //! initialize member data
Extractmin(const Tcont& c): Mval(c(c.first())) { } Extractmin(const Tcont& c): Mval(c(c.first())) { }
//! collect another value //! collect another value
void operator() (const Tvalue& v) void operator() (const Tvalue& v)
{ Mval = Mval < v ? Mval : v; } { Mval = Mval < v ? Mval : v; }
//! return result of operation //! return result of operation
Tvalue result() const { return(Mval); } Tretval result() const { return(Mval); }
private: private:
Tvalue Mval; Tvalue Mval;
}; // class Extractmin }; // class Extractmin
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: rms.h,v 1.2 2005-04-21 15:34:21 tforb Exp $ * $Id: rms.h,v 1.3 2005-04-28 11:38:05 tforb Exp $
* \author Thomas Forbriger * \author Thomas Forbriger
* \date 20/03/2005 * \date 20/03/2005
* *
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* *
* REVISIONS and CHANGES * REVISIONS and CHANGES
* - 20/03/2005 V1.0 Thomas Forbriger * - 20/03/2005 V1.0 Thomas Forbriger
* - 28/04/2005 V1.1 provide return type
* *
* ============================================================================ * ============================================================================
*/ */
...@@ -21,9 +22,9 @@ ...@@ -21,9 +22,9 @@
#ifndef AFF_RMS_H_VERSION #ifndef AFF_RMS_H_VERSION
#define AFF_RMS_H_VERSION \ #define AFF_RMS_H_VERSION \
"AFF_RMS_H V1.0 " "AFF_RMS_H V1.1 "
#define AFF_RMS_H_CVSID \ #define AFF_RMS_H_CVSID \
"$Id: rms.h,v 1.2 2005-04-21 15:34:21 tforb Exp $" "$Id: rms.h,v 1.3 2005-04-28 11:38:05 tforb Exp $"
#include<aff/lib/collector.h> #include<aff/lib/collector.h>
...@@ -46,12 +47,13 @@ namespace aff { ...@@ -46,12 +47,13 @@ namespace aff {
typedef typename C::Tcoc Tcont; typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue; typedef typename C::Tvalue Tvalue;
public: public:
typedef Tvalue Tretval;
//! initialize member data //! initialize member data
Extractrms(const Tcont& c): Msum(0), Mn(0) { } Extractrms(const Tcont& c): Msum(0), Mn(0) { }
//! collect another value //! collect another value
void operator() (const Tvalue& v) { Msum+=(v*v); ++Mn; } void operator() (const Tvalue& v) { Msum+=(v*v); ++Mn; }
//! return result of operation //! return result of operation
Tvalue result() const { return(std::sqrt(Msum/Tvalue(Mn))); } Tretval result() const { return(std::sqrt(Msum/Tvalue(Mn))); }
private: private:
Tvalue Msum; Tvalue Msum;
int Mn; int Mn;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: collector.h,v 1.3 2005-04-21 15:21:11 tforb Exp $ * $Id: collector.h,v 1.4 2005-04-28 11:38:06 tforb Exp $
* \author Thomas Forbriger * \author Thomas Forbriger
* \date 20/03/2005 * \date 20/03/2005
* *
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* *
* REVISIONS and CHANGES * REVISIONS and CHANGES
* - 20/03/2005 V1.0 Thomas Forbriger * - 20/03/2005 V1.0 Thomas Forbriger
* - 28/04/2005 V1.1 use Tretval type
* *
* ============================================================================ * ============================================================================
*/ */
...@@ -21,9 +22,9 @@ ...@@ -21,9 +22,9 @@
#ifndef AFF_COLLECTOR_H_VERSION #ifndef AFF_COLLECTOR_H_VERSION
#define AFF_COLLECTOR_H_VERSION \ #define AFF_COLLECTOR_H_VERSION \
"AFF_COLLECTOR_H V1.0 " "AFF_COLLECTOR_H V1.1"
#define AFF_COLLECTOR_H_CVSID \ #define AFF_COLLECTOR_H_CVSID \
"$Id: collector.h,v 1.3 2005-04-21 15:21:11 tforb Exp $" "$Id: collector.h,v 1.4 2005-04-28 11:38:06 tforb Exp $"
#include<aff/iterator.h> #include<aff/iterator.h>
...@@ -54,7 +55,7 @@ namespace aff { ...@@ -54,7 +55,7 @@ namespace aff {
* aff::func::rms() * aff::func::rms()
*/ */
template<class C, template<class> class F> template<class C, template<class> class F>
typename C::Tvalue collect(const typename C::Tcoc& c) typename F<C>::Tretval collect(const typename C::Tcoc& c)
{ {
F<C> exfun(c); F<C> exfun(c);
aff::Browser<C> browser(c); aff::Browser<C> browser(c);
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *
* $Id: functionstest.cc,v 1.4 2005-04-21 15:34:22 tforb Exp $ * $Id: functionstest.cc,v 1.5 2005-04-28 11:38:06 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.4 2005-04-21 15:34:22 tforb Exp $" "$Id: functionstest.cc,v 1.5 2005-04-28 11:38:06 tforb Exp $"
#include <iostream> #include <iostream>
#include <aff/dump.h> #include <aff/dump.h>
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <aff/functions/min.h> #include <aff/functions/min.h>
#include <aff/functions/max.h> #include <aff/functions/max.h>
#include <aff/functions/rms.h> #include <aff/functions/rms.h>
#include <aff/functions/histo.h>
using namespace aff; using namespace aff;
...@@ -50,6 +51,11 @@ int main(int iargc, char* argv[]) ...@@ -50,6 +51,11 @@ int main(int iargc, char* argv[])
CODE( cout << aff::func::rms(A) << endl ); CODE( cout << aff::func::rms(A) << endl );
CODE( cout << aff::func::max(A) << endl ); CODE( cout << aff::func::max(A) << endl );
CODE( cout << aff::func::min(A) << endl ); CODE( cout << aff::func::min(A) << endl );
CODE( typedef aff::func::util::Extracthisto<Tarray>::Tmap Tmap );
CODE( Tmap mymap=aff::func::histo(A) );
CODE( typedef Tmap::const_iterator Tmapit );
CODE( for (Tmapit i=mymap.begin(); i!=mymap.end(); ++i) \
{ cout << i->first << "\t" << i->second << 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