Commit b4cc9220 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: 2306
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 1fa6bcb5
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: README.changelog,v 1.61 2006-06-21 11:24:27 tforb Exp $
* $Id: README.changelog,v 1.62 2007-06-13 15:24:09 tforb Exp $
*
* Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt)
*
......@@ -21,12 +21,15 @@
/*! \page page_changelog ChangeLog (AFF)
$Id: README.changelog,v 1.61 2006-06-21 11:24:27 tforb Exp $
$Id: README.changelog,v 1.62 2007-06-13 15:24:09 tforb Exp $
\sa \ref page_project_status
Major changes in the interface of the library are marked by \b !!.
- \b 13/06/2007 (thof)
- added aff::func::sum() and aff::func::sqrsum()
- \b 20/06/2006 (thof)
- aff::Series objects may now be initialized with size zero
defined by aff::LinearShape
......@@ -251,7 +254,7 @@
/*! \page page_project_status Project status (AFF)
$Id: README.changelog,v 1.61 2006-06-21 11:24:27 tforb Exp $
$Id: README.changelog,v 1.62 2007-06-13 15:24:09 tforb Exp $
\sa \ref page_changelog
......@@ -419,6 +422,12 @@
<TR><TD>libaff/functions/rms.h</TD>
<TD>21/04/2005</TD><TD>21/04/2005</TD><TD>28/04/2005</TD><TD> </TD>
</TR>
<TR><TD>libaff/functions/sqrsum.h</TD>
<TD>13/06/2007</TD><TD>13/06/2007</TD><TD>13/06/2007</TD><TD> </TD>
</TR>
<TR><TD>libaff/functions/sum.h</TD>
<TD>13/06/2007</TD><TD>13/06/2007</TD><TD>13/06/2007</TD><TD> </TD>
</TR>
<TR><TD>libaff/functions/valmap.h</TD>
<TD>28/04/2005</TD><TD>28/04/2005</TD><TD>28/04/2005</TD><TD> </TD>
</TR>
......
/*! \file sqrsum.h
* \brief evaluate square of sum of all samples (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: sqrsum.h,v 1.1 2007-06-13 15:24:09 tforb Exp $
* \author Thomas Forbriger
* \date 13/06/2007
*
* evaluate square of sum of all samples (prototypes)
*
* Copyright (c) 2007 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
* REVISIONS and CHANGES
* - 13/06/2007 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef AFF_SQRSUM_H_VERSION
#define AFF_SQRSUM_H_VERSION \
"AFF_SQRSUM_H V1.0 "
#define AFF_SQRSUM_H_CVSID \
"$Id: sqrsum.h,v 1.1 2007-06-13 15:24:09 tforb Exp $"
#include<aff/lib/collector.h>
namespace aff {
namespace func {
namespace util {
/*! utility class to extract the sum of the square of all samples from
* the 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 Extractsqrsum {
typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue;
public:
typedef Tvalue Tretval;
//! initialize member data
Extractsqrsum(const Tcont& c): Msum(0), Mn(0) { }
//! collect another value
void operator() (const Tvalue& v) { Msum+=(v*v); ++Mn; }
//! return result of operation
Tretval result() const { return(Msum); }
private:
Tvalue Msum;
int Mn;
}; // class Extractsqrsum
} // namespace util
/*----------------------------------------------------------------------*/
/*! Function template to extract the sum of the square of all samples
* 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 sum of the square of all samples in the container
*
* \sa aff::func::util::collect, aff::func::util::Extractsqrsum
*/
template<class C>
typename C::Tvalue sqrsum(const C& c)
{
return(aff::func::util::collect<C, aff::func::util::Extractsqrsum>(c));
} // sqrsum()
} // namespace func
} // namespace aff
#endif // AFF_SQRSUM_H_VERSION (includeguard)
/* ----- END OF sqrsum.h ----- */
/*! \file sum.h
* \brief evaluate sum of all samples (prototypes)
*
* ----------------------------------------------------------------------------
*
* $Id: sum.h,v 1.1 2007-06-13 15:24:10 tforb Exp $
* \author Thomas Forbriger
* \date 13/06/2007
*
* evaluate sum of all samples (prototypes)
*
* Copyright (c) 2007 by Thomas Forbriger (BFO Schiltach)
*
* ----
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ----
*
* REVISIONS and CHANGES
* - 13/06/2007 V1.0 Thomas Forbriger
*
* ============================================================================
*/
// include guard
#ifndef AFF_SUM_H_VERSION
#define AFF_SUM_H_VERSION \
"AFF_SUM_H V1.0 "
#define AFF_SUM_H_CVSID \
"$Id: sum.h,v 1.1 2007-06-13 15:24:10 tforb Exp $"
#include<aff/lib/collector.h>
namespace aff {
namespace func {
namespace util {
/*! utility class to extract the sum of all samples from the 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 Extractsum {
typedef typename C::Tcoc Tcont;
typedef typename C::Tvalue Tvalue;
public:
typedef Tvalue Tretval;
//! initialize member data
Extractsum(const Tcont& c): Msum(0), Mn(0) { }
//! collect another value
void operator() (const Tvalue& v) { Msum+=v; ++Mn; }
//! return result of operation
Tretval result() const { return(Msum); }
private:
Tvalue Msum;
int Mn;
}; // class Extractsum
} // namespace util
/*----------------------------------------------------------------------*/
/*! Function template to extract the sum of all samples
* 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 sum of all samples in the container
*
* \sa aff::func::util::collect, aff::func::util::Extractsum
*/
template<class C>
typename C::Tvalue sum(const C& c)
{
return(aff::func::util::collect<C, aff::func::util::Extractsum>(c));
} // sum()
} // namespace func
} // namespace aff
#endif // AFF_SUM_H_VERSION (includeguard)
/* ----- END OF sum.h ----- */
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: functionstest.cc,v 1.10 2006-06-20 07:26:30 tforb Exp $
* $Id: functionstest.cc,v 1.11 2007-06-13 15:24:10 tforb Exp $
* \author Thomas Forbriger
* \date 20/03/2005
*
......@@ -36,7 +36,7 @@
#define FUNCTIONSTEST_VERSION \
"FUNCTIONSTEST V1.1 test function templates"
#define FUNCTIONSTEST_CVSID \
"$Id: functionstest.cc,v 1.10 2006-06-20 07:26:30 tforb Exp $"
"$Id: functionstest.cc,v 1.11 2007-06-13 15:24:10 tforb Exp $"
#include <iostream>
#include <aff/dump.h>
......@@ -47,6 +47,8 @@
#include <aff/functions/min.h>
#include <aff/functions/max.h>
#include <aff/functions/rms.h>
#include <aff/functions/sum.h>
#include <aff/functions/sqrsum.h>
#include <aff/functions/histo.h>
#include <aff/functions/valmap.h>
......@@ -73,6 +75,8 @@ int main(int iargc, char* argv[])
CODE( cout << aff::func::max(A) << endl );
CODE( cout << aff::func::min(A) << endl );
CODE( cout << aff::func::min(AC) << endl );
CODE( cout << aff::func::sum(A) << endl );
CODE( cout << aff::func::sqrsum(A) << endl );
CODE( typedef aff::func::util::Extracthisto<Tarray>::Tmap Tmap );
CODE( Tmap mymap=aff::func::histo(A) );
CODE( typedef Tmap::const_iterator Tmapit );
......
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