functionstest.cc 3.06 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
/*! \file functionstest.cc
 * \brief test function templates
 * 
 * ----------------------------------------------------------------------------
 * 
thomas.forbriger's avatar
thomas.forbriger committed
6
 * $Id$
thomas.forbriger's avatar
thomas.forbriger committed
7
8
9
10
 * \author Thomas Forbriger
 * \date 20/03/2005
 * 
 * test function templates
thomas.forbriger's avatar
thomas.forbriger committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 *
 * ----
 * 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
 * ----
thomas.forbriger's avatar
thomas.forbriger committed
27
28
29
30
31
 * 
 * Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach) 
 * 
 * REVISIONS and CHANGES 
 *  - 20/03/2005   V1.0   Thomas Forbriger
thomas.forbriger's avatar
thomas.forbriger committed
32
 *  - 19/06/2006   V1.1   check functions with containers of const
thomas.forbriger's avatar
thomas.forbriger committed
33
34
35
36
 * 
 * ============================================================================
 */
#define FUNCTIONSTEST_VERSION \
thomas.forbriger's avatar
thomas.forbriger committed
37
  "FUNCTIONSTEST   V1.1   test function templates"
thomas.forbriger's avatar
thomas.forbriger committed
38
#define FUNCTIONSTEST_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
39
  "$Id$"
thomas.forbriger's avatar
thomas.forbriger committed
40
41

#include <iostream>
thomas.forbriger's avatar
thomas.forbriger committed
42
43
44
45
46
#include <aff/dump.h>
#include <aff/array.h>
#include <aff/shaper.h>
#include <aff/subarray.h>
#include <aff/functions/avg.h>
thomas.forbriger's avatar
thomas.forbriger committed
47
48
#include <aff/functions/min.h>
#include <aff/functions/max.h>
thomas.forbriger's avatar
thomas.forbriger committed
49
#include <aff/functions/absmax.h>
thomas.forbriger's avatar
thomas.forbriger committed
50
#include <aff/functions/rms.h>
thomas.forbriger's avatar
thomas.forbriger committed
51
52
#include <aff/functions/sum.h>
#include <aff/functions/sqrsum.h>
thomas.forbriger's avatar
thomas.forbriger committed
53
#include <aff/functions/histo.h>
thomas.forbriger's avatar
thomas.forbriger committed
54
#include <aff/functions/valmap.h>
thomas.forbriger's avatar
thomas.forbriger committed
55
56

using namespace aff;
thomas.forbriger's avatar
thomas.forbriger committed
57
58
59
60
61

using std::cout;
using std::cerr;
using std::endl;

thomas.forbriger's avatar
thomas.forbriger committed
62
63
typedef std::map<double, int> Tvalmap;

thomas.forbriger's avatar
thomas.forbriger committed
64
65
int main(int iargc, char* argv[])
{
thomas.forbriger's avatar
thomas.forbriger committed
66
67
68
  CODE( typedef aff::Array<double> Tarray );
  CODE( Tarray A(3,4) );
  CODE( A=5 );
thomas.forbriger's avatar
thomas.forbriger committed
69
  CODE( Tarray::Tcoc AC=A );
thomas.forbriger's avatar
thomas.forbriger committed
70
71
  CODE( subarray(A)(1,1)(2,4)=2. );
  CODE( subarray(A)(2,3)(1,2)=1. );
thomas.forbriger's avatar
thomas.forbriger committed
72
  CODE( subarray(A)(2,3)(3,4)=-7. );
thomas.forbriger's avatar
thomas.forbriger committed
73
  CODE( dump_array(A) );
thomas.forbriger's avatar
thomas.forbriger committed
74
  CODE( cout << aff::func::avg(A) << endl );
thomas.forbriger's avatar
thomas.forbriger committed
75
76
77
  CODE( cout << aff::func::rms(A) << endl );
  CODE( cout << aff::func::max(A) << endl );
  CODE( cout << aff::func::min(A) << endl );
thomas.forbriger's avatar
thomas.forbriger committed
78
  CODE( cout << aff::func::absmax(A) << endl );
thomas.forbriger's avatar
thomas.forbriger committed
79
  CODE( cout << aff::func::min(AC) << endl );
thomas.forbriger's avatar
thomas.forbriger committed
80
81
  CODE( cout << aff::func::sum(A) << endl );
  CODE( cout << aff::func::sqrsum(A) << endl );
thomas.forbriger's avatar
thomas.forbriger committed
82
83
84
85
86
  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; } );
thomas.forbriger's avatar
thomas.forbriger committed
87
88
89
90
91
  CODE( Tvalmap avalmap );
  CODE( avalmap[-4.]=1 );
  CODE( avalmap[1.]=2 );
  CODE( avalmap[2.]=3 );
  CODE( avalmap[5.]=4 );
thomas.forbriger's avatar
thomas.forbriger committed
92
93
  CODE( aff::Array<Tvalmap::mapped_type> B=
          aff::func::valmap<aff::Array>(A, avalmap) );
thomas.forbriger's avatar
thomas.forbriger committed
94
  CODE( dump_array(B) );
thomas.forbriger's avatar
thomas.forbriger committed
95
96
97
}

/* ----- END OF functionstest.cc ----- */