Skip to content

Commit 69b1780

Browse files
committed
Update test cases
1 parent bf348ed commit 69b1780

File tree

2 files changed

+130
-1
lines changed

2 files changed

+130
-1
lines changed

testsuite/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ derrick-bass-1 derrick-bass-3 exprctor expression-slicing extract free \
1818
gary-huber-1 indexexpr-base initialize int-math-func interlace iter \
1919
Josef-Wagenhuber levicivita loop1 matthias-troyer-1 matthias-troyer-2 \
2020
mattias-lindstroem-1 member_function minmax minsumpow module \
21-
multicomponent multicomponent-2 newet Olaf-Ronneberger-1 \
21+
multicomponent multicomponent-1 multicomponent-2 newet Olaf-Ronneberger-1 \
2222
patrik-jonsson-1 peter-bienstman-1 peter-bienstman-2 peter-bienstman-3 \
2323
peter-bienstman-4 peter-bienstman-5 peter-nordlund-1 peter-nordlund-2 \
2424
peter-nordlund-3 preexisting promote pthread qcd reduce reindex \
@@ -73,6 +73,7 @@ minmax_SOURCES = minmax.cpp
7373
minsumpow_SOURCES = minsumpow.cpp
7474
module_SOURCES = module1.cpp module2.cpp
7575
multicomponent_SOURCES = multicomponent.cpp
76+
multicomponent_1_SOURCES = multicomponent-1.cpp
7677
multicomponent_2_SOURCES = multicomponent-2.cpp
7778
newet_SOURCES = newet.cpp
7879
Olaf_Ronneberger_1_SOURCES = Olaf-Ronneberger-1.cpp

testsuite/multicomponent-1.cpp

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include "testsuite.h"
2+
#include <blitz/array.h>
3+
#include <blitz/array.cc>
4+
#include <blitz/tinyvec2.h>
5+
#include <blitz/tinyvec2.cc>
6+
#include <blitz/tinymat2.h>
7+
#include <blitz/tinymat2.cc>
8+
9+
BZ_USING_NAMESPACE(blitz)
10+
11+
static const double eps = 0.0001;
12+
13+
#define ISCLOSE(a, b) BZTEST(fabs((a)-(b))<eps)
14+
15+
#define __TEST_FOR_VECTOR_EXPR
16+
17+
typedef TinyMatrix<double, 2, 3> T_matrix;
18+
typedef TinyVector<double, 3> T_vector;
19+
typedef Array<double, 2> T_array_2;
20+
typedef Array<double, 1> T_array_1;
21+
typedef Array<T_vector, 1> T_array_1_of_vector;
22+
typedef Array<T_vector, 2> T_array_2_of_vector;
23+
typedef Array<T_matrix, 1> T_array_1_of_matrix;
24+
typedef Array<T_matrix, 2> T_array_2_of_matrix;
25+
26+
#ifndef __TEST_FOR_VECTOR_EXPR
27+
#define EXPR2(a) (T_vector(a * 2 + 1))
28+
#define EXPR3(a) (T_vector(a * 3 - 4))
29+
#else
30+
#define EXPR2(a) (a * 2 + 1)
31+
#define EXPR3(a) (a * 3 - 4)
32+
#endif
33+
34+
#define EXPR4(a, b) (a - b * 5 + 6)
35+
36+
int main() {
37+
38+
T_vector V1(1, 2, 3);
39+
T_vector V2 = EXPR2(V1);
40+
T_vector V3 = EXPR3(V1);
41+
T_vector V4 = EXPR4(V2, V1);
42+
cout << "V1 = " << V1 << endl;
43+
cout << "V2 = " << V2 << endl;
44+
cout << "V3 = " << V3 << endl;
45+
cout << "V4 = " << V4 << endl;
46+
47+
cout << "Testing for 1d-Array:" << endl;
48+
49+
//Here TinyVector is composite object like as Array in the left side
50+
T_array_1 A1(3);
51+
A1 = EXPR2(V1);
52+
cout << A1 << endl;
53+
for (int k = 0; k < 3; ++ k) { ISCLOSE(A1(k), V2(k)); }
54+
//Here we construct TinyVector as scalar value and fill Array
55+
T_array_1_of_vector A1V(5);
56+
A1V = EXPR2(V1);
57+
cout << A1V << endl;
58+
for (int i = 0; i < 5; ++ i)
59+
for (int k = 0; k < 3; ++ k) { ISCLOSE(A1V(i)(k), V2(k)); }
60+
//Partial assignment of a vector expression
61+
A1V(Range(1, 3)) = EXPR3(V1);
62+
cout << A1V << endl;
63+
for (int i = 0; i < 5; ++ i)
64+
for (int k = 0; k < 3; ++ k) {
65+
if ((i >= 1) && (i <= 3)) {
66+
ISCLOSE(A1V(i)(k), V3(k));
67+
}
68+
else {
69+
ISCLOSE(A1V(i)(k), V2(k));
70+
}
71+
}
72+
//Check for component wise assignment
73+
for (int k = 0; k < 3; ++ k) {
74+
A1V[k] = V4(k);
75+
}
76+
cout << A1V << endl;
77+
for (int i = 0; i < 5; ++ i)
78+
for (int k = 0; k < 3; ++ k) { ISCLOSE(A1V(i)(k), V4(k)); }
79+
80+
cout << "Testing for 2d-Array:" << endl;
81+
82+
//Here we construct TinyVector as scalar value and fill Array
83+
T_array_2_of_vector A2V(5, 4);
84+
A2V = EXPR2(V1);
85+
cout << A2V << endl;
86+
for (int i = 0; i < 5; ++ i)
87+
for (int j = 0; j < 4; ++ j)
88+
for (int k = 0; k < 3; ++ k) { ISCLOSE(A2V(i, j)(k), V2(k)); }
89+
//Partial assignment of a vector expression
90+
A2V(Range(2, 3), Range(1, 2)) = EXPR3(V1);
91+
cout << A2V << endl;
92+
for (int i = 0; i < 5; ++ i)
93+
for (int j = 0; j < 4; ++ j)
94+
for (int k = 0; k < 3; ++ k) {
95+
if ((i >= 2) && (i <= 3) &&
96+
(j >= 1) && (j <= 2)) {
97+
ISCLOSE(A2V(i, j)(k), V3(k));
98+
}
99+
else {
100+
ISCLOSE(A2V(i, j)(k), V2(k));
101+
}
102+
}
103+
//Check for component wise assignment
104+
for (int k = 0; k < 3; ++ k) {
105+
A2V[k] = V4(k);
106+
}
107+
cout << A2V << endl;
108+
for (int i = 0; i < 5; ++ i)
109+
for (int j = 0; j < 4; ++ j)
110+
for (int k = 0; k < 3; ++ k) { ISCLOSE(A2V(i, j)(k), V4(k)); }
111+
//Check for array expression
112+
T_array_2_of_vector A(5, 4);
113+
T_array_2_of_vector B(5, 4);
114+
T_array_2_of_vector C(5, 4);
115+
A = V1;
116+
B = V2;
117+
B(0, 3) = EXPR3(V1);
118+
B(4, 0) = V3;
119+
C = EXPR4(B, A);
120+
cout << C << endl;
121+
for (int i = 0; i < 5; ++ i)
122+
for (int j = 0; j < 4; ++ j)
123+
for (int k = 0; k < 3; ++ k) {
124+
ISCLOSE(C(i, j)(k), EXPR4(B(i, j)(k), A(i, j)(k)));
125+
}
126+
127+
return 0;
128+
}

0 commit comments

Comments
 (0)