File: patrik-jonsson-1.cpp

package info (click to toggle)
blitz%2B%2B 1%3A1.0.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,568 kB
  • sloc: cpp: 57,803; python: 1,941; fortran: 1,510; f90: 852; makefile: 833; sh: 321
file content (62 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "testsuite.h"
#include "blitz/array.h"
using namespace blitz;

// test functors

class crap {
public:
  double a(const double x) const { return 2*x; }
  double b(const double x, const double y) const { return y*x; }
  double operator()(const double x) const {return a(x); }
  BZ_DECLARE_FUNCTOR_RET(crap, double);
  BZ_DECLARE_MEMBER_FUNCTION_RET(crap, a, double);
  BZ_DECLARE_MEMBER_FUNCTION2_RET(crap, b, double);
};

class crap2 {
public:
  double operator()(const double x, const double y) const { return y*x; }
  BZ_DECLARE_FUNCTOR2_RET(crap2, double);
};

class crap3 {
public:
  double operator()(const double x, const double y, const double z) const
  { return z*y*x; }
  BZ_DECLARE_FUNCTOR3_RET(crap3, double);
};

int main(int, char**)
{
    crap c;
    crap2 c2;
    crap3 c3;

    Array<double,1> lam(10);
    double l = 0.0;
    for (Array<double,1>::iterator i=lam.begin();i!=lam.end();++i)
        *i = l++;

    Array<double,1> a(c.a(lam));
    for (int i=0;i<10;++i)
        BZTEST(a(i)==2.0*i);

    a=c.b(lam,lam);
    for (int i=0;i<10;++i)
        BZTEST(a(i)==i*i);

    a=c(lam);
    for (int i=0;i<10;++i)
        BZTEST(a(i)==2*i);

    a=c2(lam,lam);
    for (int i=0;i<10;++i)
        BZTEST(a(i)==i*i);

    a=c3(lam,lam,lam);
    for (int i=0;i<10;++i)
        BZTEST(a(i)==i*i*i);

    return 0;
}