File: tinyvec.cpp

package info (click to toggle)
blitz%2B%2B 1%3A1.0.2%2Bds-4.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,580 kB
  • sloc: cpp: 57,803; python: 1,941; fortran: 1,510; f90: 852; makefile: 838; sh: 321
file content (78 lines) | stat: -rw-r--r-- 1,480 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "testsuite.h"
#include <blitz/array.h>

using namespace blitz;

typedef TinyVector<int,3> tv3;

int main()
{
  tv3 A, B;
    A = 1, 2, 3;
    B = 0, 1, 2;

    BZTEST(A[0]==1);
    BZTEST(A[1]==2);
    BZTEST(A[2]==3);
    BZTEST(B[0]==0);
    BZTEST(B[1]==1);
    BZTEST(B[2]==2);

    A += B*B;
    BZTEST(all(A==tv3(1,3,7)));

    //cout << A << endl;

    A *= 10;
    BZTEST(all(A==tv3(10,30,70)));

    //cout << A << endl;

    tv3::iterator it=B.begin(), end=B.end();
    cout << "(" << *it;
    for (it++; it != end; ++it) 
        cout << "," << *it;
    cout << ")" << endl;

// test tinyvector dot(), product(), and sum() functions

    int dotAB = dot(A,B); 
    BZTEST(dotAB==170);
    int dotAB2 = dot(A,B+B);
    BZTEST(dotAB2==2*dotAB);
    int dotA2B = dot(A+A,B);
    BZTEST(dotA2B==2*dotAB);
    int dotA2B2 = dot(A+A,B+B);
    BZTEST(dotA2B2==4*dotAB);
    int prod1 = product(A);
    BZTEST(prod1==21000);
    int prod2 = product(A+B);
    BZTEST(prod2==22320);
    int sum1 = sum(A);
    BZTEST(sum1==110);
    int sum2 = sum(A-B);
    BZTEST(sum2==sum1-sum(B));

    // (cross product is tested in levicivita.cpp)

    // test funcs
    B=-1,-2,-3;
    A=abs(B);
    BZTEST(A[0]==1);
    BZTEST(A[1]==2);
    BZTEST(A[2]==3);

    TinyVector<double,3> C,D;
    D=1,4,9;
    C=sqrt(D);
    BZTEST(C[0]==1);
    BZTEST(C[1]==2);
    BZTEST(C[2]==3);

    // test expr constructor
    tv3 E(A+B*B);
    BZTEST(all(E==tv3(2,6,12)));

    return 0;
}