Commit 162e83a1 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

function avg() works

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: 1676
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 0ddc5b92
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.48 2005-03-21 09:35:32 tforb Exp $
* $Id: README.changelog,v 1.49 2005-04-21 15:21:10 tforb Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -21,13 +21,16 @@
/*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.48 2005-03-21 09:35:32 tforb Exp $
$Id: README.changelog,v 1.49 2005-04-21 15:21:10 tforb Exp $
\sa \ref page_project_status
Major changes in the interface of the library are marked by \b !!.
- \b 20/3/2005 (thof)
- \b 21/04/2005 (thof)
- aff::func::avg() and underlying code works.
- \b 20/03/2005 (thof)
- Added function templates to scan and map values in containers.
They are collected in subdirectory functions and use collector.h and
mapper.h
......@@ -211,7 +214,7 @@
/*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.48 2005-03-21 09:35:32 tforb Exp $
$Id: README.changelog,v 1.49 2005-04-21 15:21:10 tforb Exp $
\sa \ref page_changelog
......@@ -285,6 +288,9 @@
<TR><TD>libaff/lib/checkedcast.h</TD>
<TD>03/01/2003</TD><TD>03/01/2003</TD><TD>03/01/2003</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/collector.h</TD>
<TD>21/04/2005</TD><TD>21/04/2005 </TD><TD>21/04/2005</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/deepcopy.h</TD>
<TD>29/12/02</TD><TD>29/12/2002</TD><TD>29/12/02</TD><TD> </TD>
</TR>
......@@ -357,9 +363,6 @@
<TR><TD>libaff/lib/dump_simplerigidarray.h</TD>
<TD>19/12/02</TD><TD> </TD><TD>19/12/02</TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/collector.h</TD>
<TD></TD><TD> </TD><TD></TD><TD> </TD>
</TR>
<TR><TD>libaff/lib/mapper.h</TD>
<TD></TD><TD> </TD><TD></TD><TD> </TD>
</TR>
......@@ -372,7 +375,7 @@
<TD></TD><TD></TD><TD></TD><TD> </TD>
</TR>
<TR><TD>libaff/functions/avg.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><TD>libaff/functions/rms.h</TD>
<TD></TD><TD></TD><TD></TD><TD> </TD>
......@@ -390,6 +393,10 @@
<TD> </TD><TD> </TD><TD> </TD>
<TD> </TD>
</TR>
<TR><TD>libaff/tests/functionstest.cc</TD>
<TD>21/04/2005 </TD><TD>21/04/2005 </TD><TD>21/04/2005 </TD>
<TD>complete as soon as other functions are provided </TD>
</TR>
<TR><TD>libaff/tests/helpertest.cc</TD>
<TD>23/12/02</TD><TD> </TD><TD>23/12/02</TD>
<TD> </TD>
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: avg.h,v 1.2 2005-04-21 07:14:55 tforb Exp $
* $Id: avg.h,v 1.3 2005-04-21 15:21:11 tforb Exp $
* \author Thomas Forbriger
* \date 20/03/2005
*
......@@ -23,7 +23,7 @@
#define AFF_AVG_H_VERSION \
"AFF_AVG_H V1.0 "
#define AFF_AVG_H_CVSID \
"$Id: avg.h,v 1.2 2005-04-21 07:14:55 tforb Exp $"
"$Id: avg.h,v 1.3 2005-04-21 15:21:11 tforb Exp $"
#include<aff/lib/collector.h>
......@@ -34,13 +34,23 @@ namespace aff {
namespace util {
/*! utility class to extract average the 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 Extractavg {
typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue;
public:
Extractavg(const Tcont c): Msum(0), Mn(0) { }
void operator() (const Tvalue& v) { Msum+=v; }
//! initialize member data
Extractavg(const Tcont& c): Msum(0), Mn(0) { }
//! collect another value
void operator() (const Tvalue& v) { Msum+=v; ++Mn; }
//! return result of operation
Tvalue result() const { return(Msum/Tvalue(Mn)); }
private:
Tvalue Msum;
......@@ -49,15 +59,22 @@ namespace aff {
} // namespace util
template<class T>
/*----------------------------------------------------------------------*/
/*! Function template to extract the arithmetic mean 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 arithmetic mean of container contents
*
* \sa aff::func::util::collect, aff::func::util::Extractavg
*/
template<class C>
T avg(const typename C::Tcoc& c)
typename C::Tvalue avg(const C& c)
{
/*
return(aff::func::util::collect<C, T,
aff::func::util::Extractavg>(c));
*/
return(-18);
return(aff::func::util::collect<C, aff::func::util::Extractavg>(c));
} // avg()
} // namespace func
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: collector.h,v 1.2 2005-04-21 07:14:55 tforb Exp $
* $Id: collector.h,v 1.3 2005-04-21 15:21:11 tforb Exp $
* \author Thomas Forbriger
* \date 20/03/2005
*
......@@ -23,22 +23,42 @@
#define AFF_COLLECTOR_H_VERSION \
"AFF_COLLECTOR_H V1.0 "
#define AFF_COLLECTOR_H_CVSID \
"$Id: collector.h,v 1.2 2005-04-21 07:14:55 tforb Exp $"
"$Id: collector.h,v 1.3 2005-04-21 15:21:11 tforb Exp $"
#include<aff/iterator.h>
namespace aff {
/*! Some functions to work on container data
*/
namespace func {
/*! Some utilities for container data functions
*/
namespace util {
/*! Function template to extract information from container data
*
* This is a framework to browse through a container and extract
* information like the average or the minimum value. This function
* template is used by container functions like aff::func::avg().
*
* \param C any container class like aff::Array<double>
* \param F<T> any collector utility class like
* aff::func::util::Extractavg
* \return result of operation that is coded in F<T>
*
* \sa aff::func::avg(),
* aff::func::min(),
* aff::func::max(),
* aff::func::rms()
*/
template<class C, template<class> class F>
typename C::Tvalue collect(const typename C::Tcoc& c)
{
F<C> exfun(c);
aff::Browser<C> browser(c);
while(browser.valid)
while(browser.valid())
{
exfun(*browser);
++browser;
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: functionstest.cc,v 1.2 2005-04-21 07:14:56 tforb Exp $
* $Id: functionstest.cc,v 1.3 2005-04-21 15:21:11 tforb Exp $
* \author Thomas Forbriger
* \date 20/03/2005
*
......@@ -19,7 +19,7 @@
#define FUNCTIONSTEST_VERSION \
"FUNCTIONSTEST V1.0 test function templates"
#define FUNCTIONSTEST_CVSID \
"$Id: functionstest.cc,v 1.2 2005-04-21 07:14:56 tforb Exp $"
"$Id: functionstest.cc,v 1.3 2005-04-21 15:21:11 tforb Exp $"
#include <iostream>
#include <aff/dump.h>
......@@ -43,7 +43,7 @@ int main(int iargc, char* argv[])
CODE( subarray(A)(2,3)(1,2)=1. );
CODE( subarray(A)(2,3)(3,4)=-4. );
CODE( dump_array(A) );
cout << aff::func::avg<Tarray::Tvalue>(A);
CODE( cout << aff::func::avg(A) << endl );
}
/* ----- 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