functionstest.cc 2.79 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: functionstest.cc,v 1.9 2006-03-28 16:03:11 tforb Exp $
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
32
33
34
35
36
37
 * 
 * Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach) 
 * 
 * REVISIONS and CHANGES 
 *  - 20/03/2005   V1.0   Thomas Forbriger
 * 
 * ============================================================================
 */
#define FUNCTIONSTEST_VERSION \
  "FUNCTIONSTEST   V1.0   test function templates"
#define FUNCTIONSTEST_CVSID \
thomas.forbriger's avatar
thomas.forbriger committed
38
  "$Id: functionstest.cc,v 1.9 2006-03-28 16:03:11 tforb Exp $"
thomas.forbriger's avatar
thomas.forbriger committed
39
40

#include <iostream>
thomas.forbriger's avatar
thomas.forbriger committed
41
42
43
44
45
#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
46
47
48
#include <aff/functions/min.h>
#include <aff/functions/max.h>
#include <aff/functions/rms.h>
thomas.forbriger's avatar
thomas.forbriger committed
49
#include <aff/functions/histo.h>
thomas.forbriger's avatar
thomas.forbriger committed
50
#include <aff/functions/valmap.h>
thomas.forbriger's avatar
thomas.forbriger committed
51
52

using namespace aff;
thomas.forbriger's avatar
thomas.forbriger committed
53
54
55
56
57

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

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

thomas.forbriger's avatar
thomas.forbriger committed
60
61
int main(int iargc, char* argv[])
{
thomas.forbriger's avatar
thomas.forbriger committed
62
63
64
65
66
67
68
  CODE( typedef aff::Array<double> Tarray );
  CODE( Tarray A(3,4) );
  CODE( A=5 );
  CODE( subarray(A)(1,1)(2,4)=2. );
  CODE( subarray(A)(2,3)(1,2)=1. );
  CODE( subarray(A)(2,3)(3,4)=-4. );
  CODE( dump_array(A) );
thomas.forbriger's avatar
thomas.forbriger committed
69
  CODE( cout << aff::func::avg(A) << endl );
thomas.forbriger's avatar
thomas.forbriger committed
70
71
72
  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
73
74
75
76
77
  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
78
79
80
81
82
  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
83
84
  CODE( aff::Array<Tvalmap::mapped_type> B=
          aff::func::valmap<aff::Array>(A, avalmap) );
thomas.forbriger's avatar
thomas.forbriger committed
85
  CODE( dump_array(B) );
thomas.forbriger's avatar
thomas.forbriger committed
86
87
88
}

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