/[escript]/branches/arrayview_from_1695_trunk/escript/test/DataArrayViewTestCase.cpp
ViewVC logotype

Contents of /branches/arrayview_from_1695_trunk/escript/test/DataArrayViewTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1697 - (show annotations)
Mon Aug 11 06:29:54 2008 UTC (11 years, 1 month ago) by jfenwick
File size: 65806 byte(s)
Moved ValueType, ShapeType, RegionType, RegionLoopRangeType and maxRank
From DataArrayView.h to DataTypes.h

This is a simple rename but did require modifying a lot of files.


1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #include "escript/DataArrayView.h"
17 #include "escript/DataAlgorithm.h"
18 #include "escript/DataVector.h"
19 #include "esysUtils/EsysException.h"
20
21 #include "DataArrayViewTestCase.h"
22 #include "escript/DataTypes.h"
23
24 #include <iostream>
25
26 using namespace CppUnitTest;
27 using namespace esysUtils;
28 using namespace escript;
29 using namespace std;
30
31 void DataArrayViewTestCase::setUp() {
32 //
33 // This is called before each test is run
34
35 }
36
37 void DataArrayViewTestCase::tearDown() {
38 //
39 // This is called after each test has been run
40
41 }
42
43 void DataArrayViewTestCase::testResultSliceShape() {
44
45 cout << endl;
46 cout << "\tTest getResultSliceShape method." << endl;
47
48 DataTypes::RegionType region;
49 DataTypes::ShapeType resultShape;
50
51 region.push_back(DataTypes::RegionType::value_type(1,5));
52 resultShape.push_back(4);
53 assert(DataArrayView::getResultSliceShape(region)==resultShape);
54
55 region.push_back(DataTypes::RegionType::value_type(2,5));
56 resultShape.push_back(3);
57 assert(DataArrayView::getResultSliceShape(region)==resultShape);
58
59 region.push_back(DataTypes::RegionType::value_type(3,9));
60 resultShape.push_back(6);
61 assert(DataArrayView::getResultSliceShape(region)==resultShape);
62
63 region.push_back(DataTypes::RegionType::value_type(1,7));
64 resultShape.push_back(6);
65 assert(DataArrayView::getResultSliceShape(region)==resultShape);
66
67 }
68
69 void DataArrayViewTestCase::testSlicing() {
70
71 {
72 cout << endl;
73 cout << "\tSlice a scalar to a scalar.";
74
75 // Define slice region.
76 DataTypes::RegionType region;
77
78 // Define shape of views.
79 DataTypes::ShapeType sourceShape;
80
81 // Create source and target views.
82 int len = DataArrayView::noValues(sourceShape);
83 DataVector sourceData(len, 2.0, len);
84 DataArrayView sourceView(sourceData, sourceShape);
85 DataVector targetData(1, 2.0, 1);
86 DataArrayView targetView(targetData, DataTypes::ShapeType());
87
88 // Copy source view to target view.
89 targetView.copySlice(sourceView,region);
90
91 // Check results of copy.
92 assert(sourceView==targetView);
93 }
94
95 {
96 cout << endl;
97 cout << "\tSlice a scalar from a scalar.";
98
99 // Define slice region.
100 DataTypes::RegionType region;
101
102 // Define shape of views.
103 DataTypes::ShapeType sourceShape;
104
105 // Create source and target views.
106 int len = DataArrayView::noValues(sourceShape);
107 DataVector sourceData(len, 2.0, len);
108 DataArrayView sourceView(sourceData, sourceShape);
109 DataVector targetData(1, 2.0, 1);
110 DataArrayView targetView(targetData, DataTypes::ShapeType());
111
112 // Copy source view to target view.
113 targetView.copySliceFrom(sourceView,region);
114
115 // Check results of copy.
116 assert(sourceView==targetView);
117 }
118
119 {
120 cout << endl;
121 cout << "\tSlice a 1 dimensional slice to a 1 dimensional array.";
122
123 // Define slice region.
124 DataTypes::RegionType region;
125 region.push_back(DataTypes::RegionType::value_type(2,4));
126
127 // Define shapes of views.
128 DataTypes::ShapeType sourceShape;
129 sourceShape.push_back(6);
130 DataTypes::ShapeType targetShape = DataArrayView::getResultSliceShape(region);
131
132 // Create source and target views.
133 int len = DataArrayView::noValues(sourceShape);
134 DataVector sourceData(len, 2.0, len);
135 DataArrayView sourceView(sourceData, sourceShape);
136 for (int i=0;i<sourceShape[0];i++) {
137 sourceView(i)=i;
138 }
139
140 len = DataArrayView::noValues(targetShape);
141 DataVector targetData(len, 2.0, len);
142 DataArrayView targetView(targetData, targetShape);
143
144 // Copy source view to target view.
145 targetView.copySlice(sourceView,region);
146
147 // Check results of copy.
148 for (int i=region[0].first;i<region[0].second;i++) {
149 assert(sourceView(i)==
150 targetView(i-region[0].first));
151 }
152 }
153
154 {
155 cout << endl;
156 cout << "\tSlice a 1 dimensional slice to a scalar.";
157
158 // Define slice region.
159 DataTypes::RegionType region;
160 region.push_back(DataTypes::RegionType::value_type(2,3));
161
162 // Define shapes of views.
163 DataTypes::ShapeType sourceShape;
164 sourceShape.push_back(6);
165 DataTypes::ShapeType targetShape;
166
167 // Create source and target views.
168 int len = DataArrayView::noValues(sourceShape);
169 DataVector sourceData(len, 2.0, len);
170 DataArrayView sourceView(sourceData, sourceShape);
171
172 for (int i=0;i<sourceShape[0];i++) {
173 sourceView(i)=i;
174 }
175
176 len = DataArrayView::noValues(targetShape);
177 DataVector targetData(len, 2.0, len);
178 DataArrayView targetView(targetData, targetShape);
179
180 // Copy source view to target view.
181 targetView.copySlice(sourceView,region);
182
183 // Check results of copy.
184 for (int i=region[0].first;i<region[0].second;i++) {
185 assert(sourceView(i)==
186 targetView());
187 }
188 }
189
190 {
191 cout << endl;
192 cout << "\tSlice a 1 dimensional slice from a 1 dimensional array.";
193
194 // Define slice region.
195 DataTypes::RegionType region;
196 region.push_back(DataTypes::RegionType::value_type(2,4));
197
198 // Define shapes of views.
199 DataTypes::ShapeType sourceShape = DataArrayView::getResultSliceShape(region);
200 DataTypes::ShapeType targetShape;
201 targetShape.push_back(6);
202
203 // Create source and target views.
204 int len = DataArrayView::noValues(sourceShape);
205 DataVector sourceData(len, 2.0, len);
206 DataArrayView sourceView(sourceData, sourceShape);
207 for (int i=0;i<sourceShape[0];i++) {
208 sourceView(i)=i;
209 }
210
211 len = DataArrayView::noValues(targetShape);
212 DataVector targetData(len, 2.0, len);
213 DataArrayView targetView(targetData, targetShape);
214
215 // Copy source view to target view.
216 targetView.copySliceFrom(sourceView,region);
217
218 // Check results of copy.
219 for (int i=region[0].first;i<region[0].second;i++) {
220 assert(sourceView(i-region[0].first)==
221 targetView(i));
222 }
223 }
224
225 {
226 cout << endl;
227 cout << "\tSlice a 1 dimensional slice from a scalar.";
228
229 // Define slice region.
230 DataTypes::RegionType region;
231 region.push_back(DataTypes::RegionType::value_type(2,4));
232
233 // Define shapes of views.
234 DataTypes::ShapeType sourceShape;
235 DataTypes::ShapeType targetShape;
236 targetShape.push_back(6);
237
238 // Create source and target views.
239 int len = DataArrayView::noValues(sourceShape);
240 DataVector sourceData(len, 2.0, len);
241 DataArrayView sourceView(sourceData, sourceShape);
242 sourceView()=5;
243
244 len = DataArrayView::noValues(targetShape);
245 DataVector targetData(len, 2.0, len);
246 DataArrayView targetView(targetData, targetShape);
247
248 // Copy source view to target view.
249 targetView.copySliceFrom(sourceView,region);
250
251 // Check results of copy.
252 for (int i=region[0].first;i<region[0].second;i++) {
253 assert(sourceView()==
254 targetView(i));
255 }
256 }
257
258 {
259 cout << endl;
260 cout << "\tSlice a 2 dimensional slice to a 2 dimensional array.";
261
262 // Define slice region.
263 DataTypes::RegionType region;
264 region.push_back(DataTypes::RegionType::value_type(2,4));
265 region.push_back(DataTypes::RegionType::value_type(0,2));
266
267 // Define shapes of views.
268 DataTypes::ShapeType sourceShape;
269 sourceShape.push_back(6);
270 sourceShape.push_back(3);
271 DataTypes::ShapeType targetShape = DataArrayView::getResultSliceShape(region);
272
273 // Create source and target views.
274 int len = DataArrayView::noValues(sourceShape);
275 DataVector sourceData(len, 2.0, len);
276 DataArrayView sourceView(sourceData, sourceShape);
277 int val=0;
278 for (int i=0;i<sourceShape[0];i++) {
279 for (int j=0;j<sourceShape[1];j++) {
280 sourceView(i,j)=val++;
281 }
282 }
283
284 len = DataArrayView::noValues(targetShape);
285 DataVector targetData(len, 2.0, len);
286 DataArrayView targetView(targetData, targetShape);
287
288 // Copy source view to target view.
289 targetView.copySlice(sourceView,region);
290
291 // Check results of copy.
292 for (int i=region[0].first;i<region[0].second;i++) {
293 for (int j=region[1].first;j<region[1].second;j++) {
294 assert(sourceView(i,j)==
295 targetView(i-region[0].first,j-region[1].first));
296 }
297 }
298 }
299
300 {
301 cout << endl;
302 cout << "\tSlice a 2 dimensional slice to a 1 dimensional array.";
303
304 // Define slice region.
305 DataTypes::RegionType region;
306 region.push_back(DataTypes::RegionType::value_type(0,3));
307 region.push_back(DataTypes::RegionType::value_type(1,2));
308
309 // Define shapes of views.
310 DataTypes::ShapeType sourceShape;
311 sourceShape.push_back(3);
312 sourceShape.push_back(6);
313 DataTypes::ShapeType targetShape;
314 targetShape.push_back(3);
315
316 // Create source and target views.
317 int len = DataArrayView::noValues(sourceShape);
318 DataVector sourceData(len, 2.0, len);
319 DataArrayView sourceView(sourceData, sourceShape);
320 int val=0;
321 for (int i=0;i<sourceShape[0];i++) {
322 for (int j=0;j<sourceShape[1];j++) {
323 sourceView(i,j)=val++;
324 }
325 }
326
327 len = DataArrayView::noValues(targetShape);
328 DataVector targetData(len, 2.0, len);
329 DataArrayView targetView(targetData, targetShape);
330
331 // Copy source view to target view.
332 targetView.copySlice(sourceView,region);
333
334 // Check results of copy.
335 for (int i=region[0].first;i<region[0].second;i++) {
336 for (int j=region[1].first;j<region[1].second;j++) {
337 assert(sourceView(i,j)==
338 targetView(i-region[0].first));
339 }
340 }
341 }
342
343 {
344 cout << endl;
345 cout << "\tSlice a 2 dimensional slice to a scalar.";
346
347 // Define slice region.
348 DataTypes::RegionType region;
349 region.push_back(DataTypes::RegionType::value_type(2,3));
350 region.push_back(DataTypes::RegionType::value_type(1,2));
351
352 // Define shapes of views.
353 DataTypes::ShapeType sourceShape;
354 sourceShape.push_back(3);
355 sourceShape.push_back(6);
356 DataTypes::ShapeType targetShape;
357
358 // Create source and target views.
359 int len = DataArrayView::noValues(sourceShape);
360 DataVector sourceData(len, 2.0, len);
361 DataArrayView sourceView(sourceData, sourceShape);
362 int val=0;
363 for (int i=0;i<sourceShape[0];i++) {
364 for (int j=0;j<sourceShape[1];j++) {
365 sourceView(i,j)=val++;
366 }
367 }
368
369 len = DataArrayView::noValues(targetShape);
370 DataVector targetData(len, 2.0, len);
371 DataArrayView targetView(targetData, targetShape);
372
373 // Copy source view to target view.
374 targetView.copySlice(sourceView,region);
375 // Check results of copy.
376 for (int i=region[0].first;i<region[0].second;i++) {
377 for (int j=region[1].first;j<region[1].second;j++) {
378 assert(sourceView(i,j)==
379 targetView());
380 }
381 }
382 }
383
384 {
385 cout << endl;
386 cout << "\tSlice a 2 dimensional slice from a 2 dimensional array.";
387
388 // Define slice region.
389 DataTypes::RegionType region;
390 region.push_back(DataTypes::RegionType::value_type(2,4));
391 region.push_back(DataTypes::RegionType::value_type(0,2));
392
393 // Define shapes of views.
394 DataTypes::ShapeType sourceShape = DataArrayView::getResultSliceShape(region);
395 DataTypes::ShapeType targetShape;
396 targetShape.push_back(6);
397 targetShape.push_back(3);
398
399 // Create source and target views.
400 int len = DataArrayView::noValues(sourceShape);
401 DataVector sourceData(len, 2.0, len);
402 DataArrayView sourceView(sourceData, sourceShape);
403 int val=0;
404 for (int i=0;i<sourceShape[0];i++) {
405 for (int j=0;j<sourceShape[1];j++) {
406 sourceView(i,j)=val++;
407 }
408 }
409
410 len = DataArrayView::noValues(targetShape);
411 DataVector targetData(len, 2.0, len);
412 DataArrayView targetView(targetData, targetShape);
413
414 // Copy source view to target view.
415 targetView.copySliceFrom(sourceView,region);
416
417 // Check results of copy.
418 for (int i=region[0].first;i<region[0].second;i++) {
419 for (int j=region[1].first;j<region[1].second;j++) {
420 assert(sourceView(i-region[0].first,j-region[1].first)==
421 targetView(i,j));
422 }
423 }
424 }
425
426 {
427 cout << endl;
428 cout << "\tSlice a 2 dimensional slice from a scalar.";
429
430 // Define slice region.
431 DataTypes::RegionType region;
432 region.push_back(DataTypes::RegionType::value_type(2,4));
433 region.push_back(DataTypes::RegionType::value_type(0,2));
434
435 // Define shapes of views.
436 DataTypes::ShapeType sourceShape;
437 DataTypes::ShapeType targetShape;
438 targetShape.push_back(6);
439 targetShape.push_back(3);
440
441 // Create source and target views.
442 int len = DataArrayView::noValues(sourceShape);
443 DataVector sourceData(len, 2.0, len);
444 DataArrayView sourceView(sourceData, sourceShape);
445 sourceView()=5;
446
447 len = DataArrayView::noValues(targetShape);
448 DataVector targetData(len, 2.0, len);
449 DataArrayView targetView(targetData, targetShape);
450
451 // Copy source view to target view.
452 targetView.copySliceFrom(sourceView,region);
453
454 // Check results of copy.
455 for (int i=region[0].first;i<region[0].second;i++) {
456 for (int j=region[1].first;j<region[1].second;j++) {
457 assert(sourceView()==
458 targetView(i,j));
459 }
460 }
461 }
462
463 {
464 cout << endl;
465 cout << "\tSlice a 3 dimensional slice to a 3 dimensional array.";
466
467 // Define slice region.
468 DataTypes::RegionType region;
469 region.push_back(DataTypes::RegionType::value_type(2,4));
470 region.push_back(DataTypes::RegionType::value_type(0,2));
471 region.push_back(DataTypes::RegionType::value_type(5,9));
472
473 // Define shapes of views.
474 DataTypes::ShapeType sourceShape;
475 sourceShape.push_back(6);
476 sourceShape.push_back(3);
477 sourceShape.push_back(13);
478 DataTypes::ShapeType targetShape = DataArrayView::getResultSliceShape(region);
479
480 // Create source and target views.
481 int len = DataArrayView::noValues(sourceShape);
482 DataVector sourceData(len, 2.0, len);
483 DataArrayView sourceView(sourceData, sourceShape);
484 int val=0;
485 for (int i=0;i<sourceShape[0];i++) {
486 for (int j=0;j<sourceShape[1];j++) {
487 for (int k=0;k<sourceShape[2];k++) {
488 sourceView(i,j,k)=val++;
489 }
490 }
491 }
492
493 len = DataArrayView::noValues(targetShape);
494 DataVector targetData(len, 2.0, len);
495 DataArrayView targetView(targetData, targetShape);
496
497 // Copy source view to target view.
498 targetView.copySlice(sourceView,region);
499
500 // Check results of copy.
501 for (int i=region[0].first;i<region[0].second;i++) {
502 for (int j=region[1].first;j<region[1].second;j++) {
503 for (int k=region[2].first;k<region[2].second;k++) {
504 assert(sourceView(i,j,k)==
505 targetView(i-region[0].first,j-region[1].first,k-region[2].first));
506 }
507 }
508 }
509 }
510
511 {
512 cout << endl;
513 cout << "\tSlice a 3 dimensional slice to a 2 dimensional array.";
514
515 // Define slice region.
516 DataTypes::RegionType region;
517 region.push_back(DataTypes::RegionType::value_type(2,4));
518 region.push_back(DataTypes::RegionType::value_type(0,1));
519 region.push_back(DataTypes::RegionType::value_type(5,9));
520
521 // Define shapes of views.
522 DataTypes::ShapeType sourceShape;
523 sourceShape.push_back(6);
524 sourceShape.push_back(3);
525 sourceShape.push_back(13);
526 DataTypes::ShapeType targetShape;
527 targetShape.push_back(2);
528 targetShape.push_back(4);
529
530 // Create source and target views.
531 int len = DataArrayView::noValues(sourceShape);
532 DataVector sourceData(len, 2.0, len);
533 DataArrayView sourceView(sourceData, sourceShape);
534 int val=0;
535 for (int i=0;i<sourceShape[0];i++) {
536 for (int j=0;j<sourceShape[1];j++) {
537 for (int k=0;k<sourceShape[2];k++) {
538 sourceView(i,j,k)=val++;
539 }
540 }
541 }
542
543 len = DataArrayView::noValues(targetShape);
544 DataVector targetData(len, 2.0, len);
545 DataArrayView targetView(targetData, targetShape);
546
547 // Copy source view to target view.
548 targetView.copySlice(sourceView,region);
549
550 // Check results of copy.
551 for (int i=region[0].first;i<region[0].second;i++) {
552 for (int j=region[1].first;j<region[1].second;j++) {
553 for (int k=region[2].first;k<region[2].second;k++) {
554 assert(sourceView(i,j,k)==
555 targetView(i-region[0].first,k-region[2].first));
556 }
557 }
558 }
559 }
560
561 {
562 cout << endl;
563 cout << "\tSlice a 3 dimensional slice to a 1 dimensional array.";
564
565 // Define slice region.
566 DataTypes::RegionType region;
567 region.push_back(DataTypes::RegionType::value_type(3,4));
568 region.push_back(DataTypes::RegionType::value_type(0,1));
569 region.push_back(DataTypes::RegionType::value_type(5,9));
570
571 // Define shapes of views.
572 DataTypes::ShapeType sourceShape;
573 sourceShape.push_back(6);
574 sourceShape.push_back(3);
575 sourceShape.push_back(13);
576 DataTypes::ShapeType targetShape;
577 targetShape.push_back(4);
578
579 // Create source and target views.
580 int len = DataArrayView::noValues(sourceShape);
581 DataVector sourceData(len, 2.0, len);
582 DataArrayView sourceView(sourceData, sourceShape);
583 int val=0;
584 for (int i=0;i<sourceShape[0];i++) {
585 for (int j=0;j<sourceShape[1];j++) {
586 for (int k=0;k<sourceShape[2];k++) {
587 sourceView(i,j,k)=val++;
588 }
589 }
590 }
591
592 len = DataArrayView::noValues(targetShape);
593 DataVector targetData(len, 2.0, len);
594 DataArrayView targetView(targetData, targetShape);
595
596 // Copy source view to target view.
597 targetView.copySlice(sourceView,region);
598
599 // Check results of copy.
600 for (int i=region[0].first;i<region[0].second;i++) {
601 for (int j=region[1].first;j<region[1].second;j++) {
602 for (int k=region[2].first;k<region[2].second;k++) {
603 assert(sourceView(i,j,k)==
604 targetView(k-region[2].first));
605 }
606 }
607 }
608 }
609
610 {
611 cout << endl;
612 cout << "\tSlice a 3 dimensional slice to a scalar.";
613
614 // Define slice region.
615 DataTypes::RegionType region;
616 region.push_back(DataTypes::RegionType::value_type(3,4));
617 region.push_back(DataTypes::RegionType::value_type(0,1));
618 region.push_back(DataTypes::RegionType::value_type(5,6));
619
620 // Define shapes of views.
621 DataTypes::ShapeType sourceShape;
622 sourceShape.push_back(6);
623 sourceShape.push_back(3);
624 sourceShape.push_back(13);
625 DataTypes::ShapeType targetShape;
626
627 // Create source and target views.
628 int len = DataArrayView::noValues(sourceShape);
629 DataVector sourceData(len, 2.0, len);
630 DataArrayView sourceView(sourceData, sourceShape);
631 int val=0;
632 for (int i=0;i<sourceShape[0];i++) {
633 for (int j=0;j<sourceShape[1];j++) {
634 for (int k=0;k<sourceShape[2];k++) {
635 sourceView(i,j,k)=val++;
636 }
637 }
638 }
639
640 len = DataArrayView::noValues(targetShape);
641 DataVector targetData(len, 2.0, len);
642 DataArrayView targetView(targetData, targetShape);
643
644 // Copy source view to target view.
645 targetView.copySlice(sourceView,region);
646
647 // Check results of copy.
648 for (int i=region[0].first;i<region[0].second;i++) {
649 for (int j=region[1].first;j<region[1].second;j++) {
650 for (int k=region[2].first;k<region[2].second;k++) {
651 assert(sourceView(i,j,k)==
652 targetView());
653 }
654 }
655 }
656 }
657
658 {
659 cout << endl;
660 cout << "\tSlice a 3 dimensional slice from a 3 dimensional array.";
661
662 // Define slice region.
663 DataTypes::RegionType region;
664 region.push_back(DataTypes::RegionType::value_type(4,7));
665 region.push_back(DataTypes::RegionType::value_type(2,5));
666 region.push_back(DataTypes::RegionType::value_type(6,7));
667
668 // Define shapes of views.
669 DataTypes::ShapeType sourceShape = DataArrayView::getResultSliceShape(region);
670 DataTypes::ShapeType targetShape;
671 targetShape.push_back(11);
672 targetShape.push_back(8);
673 targetShape.push_back(9);
674
675 // Create source and target views.
676 int len = DataArrayView::noValues(sourceShape);
677 DataVector sourceData(len, 2.0, len);
678 DataArrayView sourceView(sourceData, sourceShape);
679 int val=0;
680 for (int i=0;i<sourceShape[0];i++) {
681 for (int j=0;j<sourceShape[1];j++) {
682 for (int k=0;k<sourceShape[2];k++) {
683 sourceView(i,j,k)=val++;
684 }
685 }
686 }
687
688 len = DataArrayView::noValues(targetShape);
689 DataVector targetData(len, 2.0, len);
690 DataArrayView targetView(targetData, targetShape);
691
692 // Copy source view to target view.
693 targetView.copySliceFrom(sourceView,region);
694
695 // Check results of copy.
696 for (int i=region[0].first;i<region[0].second;i++) {
697 for (int j=region[1].first;j<region[1].second;j++) {
698 for (int k=region[2].first;k<region[2].second;k++) {
699 assert(sourceView(i-region[0].first,j-region[1].first,k-region[2].first)==
700 targetView(i,j,k));
701 }
702 }
703 }
704 }
705
706 {
707 cout << endl;
708 cout << "\tSlice a 3 dimensional slice from a scalar.";
709
710 // Define slice region.
711 DataTypes::RegionType region;
712 region.push_back(DataTypes::RegionType::value_type(4,7));
713 region.push_back(DataTypes::RegionType::value_type(2,5));
714 region.push_back(DataTypes::RegionType::value_type(6,7));
715
716 // Define shapes of views.
717 DataTypes::ShapeType sourceShape;
718 DataTypes::ShapeType targetShape;
719 targetShape.push_back(11);
720 targetShape.push_back(8);
721 targetShape.push_back(9);
722
723 // Create source and target views.
724 int len = DataArrayView::noValues(sourceShape);
725 DataVector sourceData(len, 2.0, len);
726 DataArrayView sourceView(sourceData, sourceShape);
727 sourceView()=5;
728
729 len = DataArrayView::noValues(targetShape);
730 DataVector targetData(len, 2.0, len);
731 DataArrayView targetView(targetData, targetShape);
732
733 // Copy source view to target view.
734 targetView.copySliceFrom(sourceView,region);
735
736 // Check results of copy.
737 for (int i=region[0].first;i<region[0].second;i++) {
738 for (int j=region[1].first;j<region[1].second;j++) {
739 for (int k=region[2].first;k<region[2].second;k++) {
740 assert(sourceView()==
741 targetView(i,j,k));
742 }
743 }
744 }
745 }
746
747 {
748 cout << endl;
749 cout << "\tSlice a 4 dimensional slice to a 4 dimensional array.";
750
751 // Define slice region.
752 DataTypes::RegionType region;
753 region.push_back(DataTypes::RegionType::value_type(2,4));
754 region.push_back(DataTypes::RegionType::value_type(0,2));
755 region.push_back(DataTypes::RegionType::value_type(5,9));
756 region.push_back(DataTypes::RegionType::value_type(3,5));
757
758 // Define shapes of views.
759 DataTypes::ShapeType sourceShape;
760 sourceShape.push_back(6);
761 sourceShape.push_back(3);
762 sourceShape.push_back(13);
763 sourceShape.push_back(9);
764 DataTypes::ShapeType targetShape = DataArrayView::getResultSliceShape(region);
765
766 // Create source and target views.
767 int len = DataArrayView::noValues(sourceShape);
768 DataVector sourceData(len, 2.0, len);
769 DataArrayView sourceView(sourceData, sourceShape);
770 int val=0;
771 for (int i=0;i<sourceShape[0];i++) {
772 for (int j=0;j<sourceShape[1];j++) {
773 for (int k=0;k<sourceShape[2];k++) {
774 for (int l=0;l<sourceShape[3];l++) {
775 sourceView(i,j,k,l)=val++;
776 }
777 }
778 }
779 }
780
781 len = DataArrayView::noValues(targetShape);
782 DataVector targetData(len, 2.0, len);
783 DataArrayView targetView(targetData, targetShape);
784
785 // Copy source view to target view.
786 targetView.copySlice(sourceView,region);
787
788 // Check results of copy.
789 for (int i=region[0].first;i<region[0].second;i++) {
790 for (int j=region[1].first;j<region[1].second;j++) {
791 for (int k=region[2].first;k<region[2].second;k++) {
792 for (int l=region[3].first;l<region[3].second;l++) {
793 assert(sourceView(i,j,k,l)==
794 targetView(i-region[0].first,j-region[1].first,k-region[2].first,l-region[3].first));
795 }
796 }
797 }
798 }
799 }
800
801 {
802 cout << endl;
803 cout << "\tSlice a 4 dimensional slice to a 3 dimensional array.";
804
805 // Define slice region.
806 DataTypes::RegionType region;
807 region.push_back(DataTypes::RegionType::value_type(2,4));
808 region.push_back(DataTypes::RegionType::value_type(0,2));
809 region.push_back(DataTypes::RegionType::value_type(5,6));
810 region.push_back(DataTypes::RegionType::value_type(3,5));
811
812 // Define shapes of views.
813 DataTypes::ShapeType sourceShape;
814 sourceShape.push_back(6);
815 sourceShape.push_back(3);
816 sourceShape.push_back(13);
817 sourceShape.push_back(9);
818 DataTypes::ShapeType targetShape;
819 targetShape.push_back(2);
820 targetShape.push_back(2);
821 targetShape.push_back(2);
822
823 // Create source and target views.
824 int len = DataArrayView::noValues(sourceShape);
825 DataVector sourceData(len, 2.0, len);
826 DataArrayView sourceView(sourceData, sourceShape);
827 int val=0;
828 for (int i=0;i<sourceShape[0];i++) {
829 for (int j=0;j<sourceShape[1];j++) {
830 for (int k=0;k<sourceShape[2];k++) {
831 for (int l=0;l<sourceShape[3];l++) {
832 sourceView(i,j,k,l)=val++;
833 }
834 }
835 }
836 }
837
838 len = DataArrayView::noValues(targetShape);
839 DataVector targetData(len, 2.0, len);
840 DataArrayView targetView(targetData, targetShape);
841
842 // Copy source view to target view.
843 targetView.copySlice(sourceView,region);
844
845 // Check results of copy.
846 for (int i=region[0].first;i<region[0].second;i++) {
847 for (int j=region[1].first;j<region[1].second;j++) {
848 for (int k=region[2].first;k<region[2].second;k++) {
849 for (int l=region[3].first;l<region[3].second;l++) {
850 assert(sourceView(i,j,k,l)==
851 targetView(i-region[0].first,j-region[1].first,l-region[3].first));
852 }
853 }
854 }
855 }
856 }
857
858 {
859 cout << endl;
860 cout << "\tSlice a 4 dimensional slice to a 2 dimensional array.";
861
862 // Define slice region.
863 DataTypes::RegionType region;
864 region.push_back(DataTypes::RegionType::value_type(2,4));
865 region.push_back(DataTypes::RegionType::value_type(0,2));
866 region.push_back(DataTypes::RegionType::value_type(5,6));
867 region.push_back(DataTypes::RegionType::value_type(4,5));
868
869 // Define shapes of views.
870 DataTypes::ShapeType sourceShape;
871 sourceShape.push_back(6);
872 sourceShape.push_back(3);
873 sourceShape.push_back(13);
874 sourceShape.push_back(9);
875 DataTypes::ShapeType targetShape;
876 targetShape.push_back(2);
877 targetShape.push_back(2);
878
879 // Create source and target views.
880 int len = DataArrayView::noValues(sourceShape);
881 DataVector sourceData(len, 2.0, len);
882 DataArrayView sourceView(sourceData, sourceShape);
883 int val=0;
884 for (int i=0;i<sourceShape[0];i++) {
885 for (int j=0;j<sourceShape[1];j++) {
886 for (int k=0;k<sourceShape[2];k++) {
887 for (int l=0;l<sourceShape[3];l++) {
888 sourceView(i,j,k,l)=val++;
889 }
890 }
891 }
892 }
893
894 len = DataArrayView::noValues(targetShape);
895 DataVector targetData(len, 2.0, len);
896 DataArrayView targetView(targetData, targetShape);
897
898 // Copy source view to target view.
899 targetView.copySlice(sourceView,region);
900
901 // Check results of copy.
902 for (int i=region[0].first;i<region[0].second;i++) {
903 for (int j=region[1].first;j<region[1].second;j++) {
904 for (int k=region[2].first;k<region[2].second;k++) {
905 for (int l=region[3].first;l<region[3].second;l++) {
906 assert(sourceView(i,j,k,l)==
907 targetView(i-region[0].first,j-region[1].first));
908 }
909 }
910 }
911 }
912 }
913
914 {
915 cout << endl;
916 cout << "\tSlice a 4 dimensional slice to a 1 dimensional array.";
917
918 // Define slice region.
919 DataTypes::RegionType region;
920 region.push_back(DataTypes::RegionType::value_type(3,4));
921 region.push_back(DataTypes::RegionType::value_type(0,2));
922 region.push_back(DataTypes::RegionType::value_type(5,6));
923 region.push_back(DataTypes::RegionType::value_type(4,5));
924
925 // Define shapes of views.
926 DataTypes::ShapeType sourceShape;
927 sourceShape.push_back(6);
928 sourceShape.push_back(3);
929 sourceShape.push_back(13);
930 sourceShape.push_back(9);
931 DataTypes::ShapeType targetShape;
932 targetShape.push_back(2);
933
934 // Create source and target views.
935 int len = DataArrayView::noValues(sourceShape);
936 DataVector sourceData(len, 2.0, len);
937 DataArrayView sourceView(sourceData, sourceShape);
938 int val=0;
939 for (int i=0;i<sourceShape[0];i++) {
940 for (int j=0;j<sourceShape[1];j++) {
941 for (int k=0;k<sourceShape[2];k++) {
942 for (int l=0;l<sourceShape[3];l++) {
943 sourceView(i,j,k,l)=val++;
944 }
945 }
946 }
947 }
948
949 len = DataArrayView::noValues(targetShape);
950 DataVector targetData(len, 2.0, len);
951 DataArrayView targetView(targetData, targetShape);
952
953 // Copy source view to target view.
954 targetView.copySlice(sourceView,region);
955
956 // Check results of copy.
957 for (int i=region[0].first;i<region[0].second;i++) {
958 for (int j=region[1].first;j<region[1].second;j++) {
959 for (int k=region[2].first;k<region[2].second;k++) {
960 for (int l=region[3].first;l<region[3].second;l++) {
961 assert(sourceView(i,j,k,l)==
962 targetView(j-region[1].first));
963 }
964 }
965 }
966 }
967 }
968
969 {
970 cout << endl;
971 cout << "\tSlice a 4 dimensional slice to a scalar.";
972
973 // Define slice region.
974 DataTypes::RegionType region;
975 region.push_back(DataTypes::RegionType::value_type(3,4));
976 region.push_back(DataTypes::RegionType::value_type(1,2));
977 region.push_back(DataTypes::RegionType::value_type(5,6));
978 region.push_back(DataTypes::RegionType::value_type(4,5));
979
980 // Define shapes of views.
981 DataTypes::ShapeType sourceShape;
982 sourceShape.push_back(6);
983 sourceShape.push_back(3);
984 sourceShape.push_back(13);
985 sourceShape.push_back(9);
986 DataTypes::ShapeType targetShape;
987
988 // Create source and target views.
989 int len = DataArrayView::noValues(sourceShape);
990 DataVector sourceData(len, 2.0, len);
991 DataArrayView sourceView(sourceData, sourceShape);
992 int val=0;
993 for (int i=0;i<sourceShape[0];i++) {
994 for (int j=0;j<sourceShape[1];j++) {
995 for (int k=0;k<sourceShape[2];k++) {
996 for (int l=0;l<sourceShape[3];l++) {
997 sourceView(i,j,k,l)=val++;
998 }
999 }
1000 }
1001 }
1002
1003 len = DataArrayView::noValues(targetShape);
1004 DataVector targetData(len, 2.0, len);
1005 DataArrayView targetView(targetData, targetShape);
1006
1007 // Copy source view to target view.
1008 targetView.copySlice(sourceView,region);
1009
1010 // Check results of copy.
1011 for (int i=region[0].first;i<region[0].second;i++) {
1012 for (int j=region[1].first;j<region[1].second;j++) {
1013 for (int k=region[2].first;k<region[2].second;k++) {
1014 for (int l=region[3].first;l<region[3].second;l++) {
1015 assert(sourceView(i,j,k,l)==
1016 targetView());
1017 }
1018 }
1019 }
1020 }
1021 }
1022
1023 {
1024 cout << endl;
1025 cout << "\tSlice a 4 dimensional slice from a 4 dimensional array.";
1026
1027 // Define slice region.
1028 DataTypes::RegionType region;
1029 region.push_back(DataTypes::RegionType::value_type(14,37));
1030 region.push_back(DataTypes::RegionType::value_type(22,57));
1031 region.push_back(DataTypes::RegionType::value_type(63,71));
1032 region.push_back(DataTypes::RegionType::value_type(23,51));
1033
1034 // Define shapes of views.
1035 DataTypes::ShapeType sourceShape = DataArrayView::getResultSliceShape(region);
1036 DataTypes::ShapeType targetShape;
1037 targetShape.push_back(50);
1038 targetShape.push_back(65);
1039 targetShape.push_back(80);
1040 targetShape.push_back(90);
1041
1042 // Create source and target views.
1043 int len = DataArrayView::noValues(sourceShape);
1044 DataVector sourceData(len, 2.0, len);
1045 DataArrayView sourceView(sourceData, sourceShape);
1046 int val=0;
1047 for (int i=0;i<sourceShape[0];i++) {
1048 for (int j=0;j<sourceShape[1];j++) {
1049 for (int k=0;k<sourceShape[2];k++) {
1050 for (int l=0;l<sourceShape[3];l++) {
1051 sourceView(i,j,k,l)=val++;
1052 }
1053 }
1054 }
1055 }
1056
1057 len = DataArrayView::noValues(targetShape);
1058 DataVector targetData(len, 2.0, len);
1059 DataArrayView targetView(targetData, targetShape);
1060
1061 // Copy source view to target view.
1062 targetView.copySliceFrom(sourceView,region);
1063
1064 // Check results of copy.
1065 for (int i=region[0].first;i<region[0].second;i++) {
1066 for (int j=region[1].first;j<region[1].second;j++) {
1067 for (int k=region[2].first;k<region[2].second;k++) {
1068 for (int l=region[3].first;l<region[3].second;l++) {
1069 assert(sourceView(i-region[0].first,j-region[1].first,k-region[2].first,l-region[3].first)==
1070 targetView(i,j,k,l));
1071 }
1072 }
1073 }
1074 }
1075 }
1076
1077 {
1078 cout << endl;
1079 cout << "\tSlice a 4 dimensional slice from a scalar.";
1080
1081 // Define slice region.
1082 DataTypes::RegionType region;
1083 region.push_back(DataTypes::RegionType::value_type(14,37));
1084 region.push_back(DataTypes::RegionType::value_type(22,57));
1085 region.push_back(DataTypes::RegionType::value_type(63,71));
1086 region.push_back(DataTypes::RegionType::value_type(23,51));
1087
1088 // Define shapes of views.
1089 DataTypes::ShapeType sourceShape;
1090 DataTypes::ShapeType targetShape;
1091 targetShape.push_back(50);
1092 targetShape.push_back(65);
1093 targetShape.push_back(80);
1094 targetShape.push_back(90);
1095
1096 // Create source and target views.
1097 int len = DataArrayView::noValues(sourceShape);
1098 DataVector sourceData(len, 2.0, len);
1099 DataArrayView sourceView(sourceData, sourceShape);
1100 sourceView()=5;
1101
1102 len = DataArrayView::noValues(targetShape);
1103 DataVector targetData(len, 2.0, len);
1104 DataArrayView targetView(targetData, targetShape);
1105
1106 // Copy source view to target view.
1107 targetView.copySliceFrom(sourceView,region);
1108
1109 // Check results of copy.
1110 for (int i=region[0].first;i<region[0].second;i++) {
1111 for (int j=region[1].first;j<region[1].second;j++) {
1112 for (int k=region[2].first;k<region[2].second;k++) {
1113 for (int l=region[3].first;l<region[3].second;l++) {
1114 assert(sourceView()==
1115 targetView(i,j,k,l));
1116 }
1117 }
1118 }
1119 }
1120 }
1121
1122 cout << endl;
1123
1124 }
1125
1126 void DataArrayViewTestCase::testShapeToString() {
1127
1128 cout << endl;
1129 cout << "\tTest shapeToString for a variety of shapes." << endl;
1130
1131 DataTypes::ShapeType shape;
1132 assert(DataArrayView::shapeToString(shape)=="()");
1133 shape.push_back(5);
1134 assert(DataArrayView::shapeToString(shape)=="(5)");
1135 shape.push_back(2);
1136 assert(DataArrayView::shapeToString(shape)=="(5,2)");
1137 shape.push_back(9);
1138 assert(DataArrayView::shapeToString(shape)=="(5,2,9)");
1139 shape.push_back(4);
1140 assert(DataArrayView::shapeToString(shape)=="(5,2,9,4)");
1141
1142 }
1143
1144 void DataArrayViewTestCase::testScalarView() {
1145
1146 cout << endl;
1147 cout << "\tTest functionality of scalar views." << endl;
1148
1149 // Create a vector containing enough data for three scalars
1150 // and check three scalar views return the appropriate data
1151 DataTypes::ShapeType vShape;
1152 DataTypes::ValueType vData(3);
1153 vData[0]=0;
1154 vData[1]=1;
1155 vData[2]=2;
1156
1157 // create the three scalar views
1158 DataArrayView zView(vData,vShape,0);
1159 DataArrayView oView(vData,vShape,1);
1160 DataArrayView tView(vData,vShape,2);
1161
1162 // check attributes of the three scalar views
1163 assert(zView()==0);
1164 assert(oView()==1);
1165 assert(tView()==2);
1166 assert(zView.noValues()==1);
1167 assert(oView.noValues()==1);
1168 assert(tView.noValues()==1);
1169 assert(zView.getRank()==0);
1170 assert(oView.getRank()==0);
1171 assert(tView.getRank()==0);
1172
1173 // copy the one view to the zero view
1174 zView.copy(oView);
1175 assert(zView==oView);
1176 zView.checkShape(oView.getShape());
1177
1178 // create a single vector view of all the data
1179 vShape.push_back(3);
1180 DataArrayView oneVView(vData,vShape,0);
1181
1182 // test shape mismatch functions
1183 if (!zView.checkShape(oneVView.getShape())) {
1184 assert(true);
1185 } else {
1186 assert(false);
1187 }
1188
1189 // test some unary ops
1190 zView.unaryOp(negate<double>());
1191 assert(zView()==-1);
1192 zView.binaryOp(oView,plus<double>());
1193 assert(zView()==0);
1194
1195 // test operator !=
1196 assert(zView!=oView);
1197
1198 }
1199
1200 void DataArrayViewTestCase::testAll()
1201 {
1202
1203 {
1204 cout << endl;
1205 cout << "\tTest empty DataArrayView.";
1206
1207 // default constructor
1208 DataArrayView defView;
1209
1210 // check all attributes
1211 assert(defView.isEmpty());
1212 assert(defView.getOffset()==0);
1213 assert(defView.getRank()==0);
1214 assert(defView.noValues()==0);
1215 assert(defView.getShape().empty());
1216 assert(defView.checkShape(DataTypes::ShapeType()));
1217 }
1218
1219 {
1220 cout << endl;
1221 cout << "\tTest DataArrayView - shape (5).";
1222
1223 // define the shape for the DataArrayView
1224 DataTypes::ShapeType shape;
1225 shape.push_back(5);
1226
1227 // allocate the data for the DataArrayView
1228 DataTypes::ValueType data(DataArrayView::noValues(shape),0);
1229
1230 // constructor
1231 int offset=0;
1232 DataArrayView dataView(data,shape,offset);
1233
1234 // check all attributes
1235 assert(!dataView.isEmpty());
1236 assert(dataView.getOffset()==0);
1237 assert(dataView.getRank()==1);
1238 assert(dataView.noValues()==5);
1239 assert(dataView.getShape()==shape);
1240 assert(dataView.checkShape(shape));
1241
1242 // assign values to the data
1243 for (int i=0;i<shape[0];i++) {
1244 dataView(i)=dataView.index(i);
1245 assert(dataView(i)==i);
1246 }
1247
1248 }
1249
1250 {
1251 cout << endl;
1252 cout << "\tTest DataArrayView - shape (2,3).";
1253
1254 // define the shape for the DataArrayView
1255 DataTypes::ShapeType shape;
1256 shape.push_back(2);
1257 shape.push_back(3);
1258
1259 // allocate the data for the DataArrayView
1260 int npoints=4;
1261 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
1262
1263 // constructor
1264 DataArrayView dataView(data,shape);
1265
1266 // check all attributes
1267 assert(!dataView.isEmpty());
1268 assert(dataView.getOffset()==0);
1269 assert(dataView.getRank()==2);
1270 assert(dataView.noValues()==6);
1271 assert(dataView.getShape()==shape);
1272 assert(dataView.checkShape(shape));
1273
1274 // step the view along each block of this shape in the underlying data
1275 for (int p=0;p<npoints;p++) {
1276
1277 assert(dataView.getOffset()==p*dataView.noValues());
1278
1279 // assign values to the data
1280 for (int i=0;i<shape[0];i++) {
1281 for (int j=0;j<shape[1];j++) {
1282 dataView(i,j)=dataView.index(i,j);
1283 assert(dataView(i,j)==dataView.index(i,j));
1284 }
1285 }
1286
1287 if (p<npoints-1) {
1288 dataView.incrOffset();
1289 }
1290
1291 }
1292
1293 }
1294
1295 {
1296 cout << endl;
1297 cout << "\tTest DataArrayView - shape (4,7,9).";
1298
1299 // define the shape for the DataArrayView
1300 DataTypes::ShapeType shape;
1301 shape.push_back(4);
1302 shape.push_back(7);
1303 shape.push_back(9);
1304
1305 // allocate the data for the DataArrayView
1306 int npoints=10;
1307 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
1308
1309 // constructor
1310 DataArrayView dataView(data,shape);
1311
1312 // check all attributes
1313 assert(!dataView.isEmpty());
1314 assert(dataView.getOffset()==0);
1315 assert(dataView.getRank()==3);
1316 assert(dataView.noValues()==252);
1317 assert(dataView.getShape()==shape);
1318 assert(dataView.checkShape(shape));
1319
1320 // step the view along each block of this shape in the underlying data
1321 for (int p=0;p<npoints;p++) {
1322
1323 assert(dataView.getOffset()==p*dataView.noValues());
1324
1325 // assign values to the data
1326 for (int i=0;i<shape[0];i++) {
1327 for (int j=0;j<shape[1];j++) {
1328 for (int k=0;k<shape[2];k++) {
1329 dataView(i,j,k)=dataView.index(i,j,k);
1330 assert(dataView(i,j,k)==dataView.index(i,j,k));
1331 }
1332 }
1333 }
1334
1335 if (p<npoints-1) {
1336 dataView.incrOffset();
1337 }
1338
1339 }
1340
1341 }
1342
1343 {
1344 cout << endl;
1345 cout << "\tTest DataArrayView - shape (12,4,5,14).";
1346
1347 // define the shape for the DataArrayView
1348 DataTypes::ShapeType shape;
1349 shape.push_back(12);
1350 shape.push_back(4);
1351 shape.push_back(5);
1352 shape.push_back(14);
1353
1354 // allocate the data for the DataArrayView
1355 int npoints=100;
1356 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
1357
1358 // constructor
1359 DataArrayView dataView(data,shape);
1360
1361 // check all attributes
1362 assert(!dataView.isEmpty());
1363 assert(dataView.getOffset()==0);
1364 assert(dataView.getRank()==4);
1365 assert(dataView.noValues()==3360);
1366 assert(dataView.getShape()==shape);
1367 assert(dataView.checkShape(shape));
1368
1369 // step the view along each block of this shape in the underlying data
1370 for (int p=0;p<npoints;p++) {
1371
1372 assert(dataView.getOffset()==p*dataView.noValues());
1373
1374 // assign values to the data
1375 for (int i=0;i<shape[0];i++) {
1376 for (int j=0;j<shape[1];j++) {
1377 for (int k=0;k<shape[2];k++) {
1378 for (int l=0;l<shape[3];l++) {
1379 dataView(i,j,k,l)=dataView.index(i,j,k,l);
1380 assert(dataView(i,j,k,l)==dataView.index(i,j,k,l));
1381 }
1382 }
1383 }
1384 }
1385
1386 if (p<npoints-1) {
1387 dataView.incrOffset();
1388 }
1389
1390 }
1391
1392 }
1393
1394 {
1395 cout << endl;
1396 cout << "\tTest DataArrayView copy constructor - shape (5).";
1397
1398 // define the shape for the DataArrayView
1399 DataTypes::ShapeType shape;
1400 shape.push_back(5);
1401
1402 // allocate the data for the DataArrayView
1403 DataTypes::ValueType data(DataArrayView::noValues(shape),0);
1404
1405 // constructor
1406 DataArrayView dataView(data,shape);
1407
1408 // copy constructor
1409 DataArrayView dataViewCopy(dataView);
1410
1411 // check all attributes
1412 assert(!dataViewCopy.isEmpty());
1413 assert(dataViewCopy.getOffset()==0);
1414 assert(dataViewCopy.getRank()==1);
1415 assert(dataViewCopy.noValues()==5);
1416 assert(dataViewCopy.getShape()==shape);
1417 assert(dataViewCopy.checkShape(shape));
1418
1419 // check data
1420 assert(dataView.getData()==dataViewCopy.getData());
1421 for (int i=0;i<dataView.getData().size();i++) {
1422 assert(dataView.getData(i)==dataViewCopy.getData(i));
1423 }
1424
1425 }
1426
1427 {
1428 cout << endl;
1429 cout << "\tTest DataArrayView copy constructor - shape (5,6,7).";
1430
1431 // define the shape for the DataArrayView
1432 DataTypes::ShapeType shape;
1433 shape.push_back(5);
1434 shape.push_back(6);
1435 shape.push_back(7);
1436
1437 // allocate the data for the DataArrayView
1438 DataTypes::ValueType data(DataArrayView::noValues(shape),0);
1439
1440 // constructor
1441 DataArrayView dataView(data,shape);
1442
1443 // copy constructor
1444 DataArrayView dataViewCopy(dataView);
1445
1446 // check all attributes
1447 assert(!dataViewCopy.isEmpty());
1448 assert(dataViewCopy.getOffset()==0);
1449 assert(dataViewCopy.getRank()==3);
1450 assert(dataViewCopy.noValues()==210);
1451 assert(dataViewCopy.getShape()==shape);
1452 assert(dataViewCopy.checkShape(shape));
1453
1454 // check data
1455 assert(dataView.getData()==dataViewCopy.getData());
1456 for (int i=0;i<dataView.getData().size();i++) {
1457 assert(dataView.getData(i)==dataViewCopy.getData(i));
1458 }
1459
1460 }
1461
1462 {
1463 cout << endl;
1464 cout << "\tTest DataArrayView copy method - shape (2,3).";
1465
1466 // define the shape for the DataArrayViews
1467 DataTypes::ShapeType shape;
1468 shape.push_back(2);
1469 shape.push_back(3);
1470
1471 // allocate the data for the DataArrayViews
1472 int npoints=4;
1473 DataTypes::ValueType data1(DataArrayView::noValues(shape)*npoints,0);
1474 DataTypes::ValueType data2(DataArrayView::noValues(shape)*npoints,0);
1475
1476 // construct two views
1477 DataArrayView dataView1(data1,shape);
1478 DataArrayView dataView2(data2,shape);
1479
1480 // step the views along each block of this shape in the underlying data arrays
1481 for (int p=0;p<npoints;p++) {
1482
1483 // assign values to the data underlying the first view
1484 for (int i=0;i<shape[0];i++) {
1485 for (int j=0;j<shape[1];j++) {
1486 dataView1(i,j)=dataView1.index(i,j);
1487 }
1488 }
1489
1490 // copy data from the first view to the second
1491 dataView2.copy(dataView1);
1492
1493 // check the data underlying the second view
1494 for (int i=0;i<shape[0];i++) {
1495 for (int j=0;j<shape[1];j++) {
1496 assert(dataView2(i,j)==dataView1.index(i,j));
1497 }
1498 }
1499
1500 if (p<npoints-1) {
1501 dataView1.incrOffset();
1502 dataView2.incrOffset();
1503 }
1504
1505 }
1506
1507 }
1508
1509 {
1510 cout << endl;
1511 cout << "\tTest DataArrayView copy method - shape (2,3,8,9).";
1512
1513 // define the shape for the DataArrayViews
1514 DataTypes::ShapeType shape;
1515 shape.push_back(2);
1516 shape.push_back(3);
1517 shape.push_back(8);
1518 shape.push_back(9);
1519
1520 // allocate the data for the DataArrayViews
1521 int npoints=10;
1522 DataTypes::ValueType data1(DataArrayView::noValues(shape)*npoints,0);
1523 DataTypes::ValueType data2(DataArrayView::noValues(shape)*npoints,0);
1524
1525 // construct two views
1526 DataArrayView dataView1(data1,shape);
1527 DataArrayView dataView2(data2,shape);
1528
1529 // step the views along each block of this shape in the underlying data arrays
1530 for (int p=0;p<npoints;p++) {
1531
1532 // assign values to the data underlying the first view
1533 for (int i=0;i<shape[0];i++) {
1534 for (int j=0;j<shape[1];j++) {
1535 for (int k=0;k<shape[2];k++) {
1536 for (int l=0;l<shape[3];l++) {
1537 dataView1(i,j,k,l)=dataView1.index(i,j,k,l);
1538 }
1539 }
1540 }
1541 }
1542
1543 // copy data from the first view to the second
1544 dataView2.copy(dataView1);
1545
1546 // check the data underlying the second view
1547 for (int i=0;i<shape[0];i++) {
1548 for (int j=0;j<shape[1];j++) {
1549 for (int k=0;k<shape[2];k++) {
1550 for (int l=0;l<shape[3];l++) {
1551 assert(dataView2(i,j,k,l)==dataView1.index(i,j,k,l));
1552 }
1553 }
1554 }
1555 }
1556
1557 if (p<npoints-1) {
1558 dataView1.incrOffset();
1559 dataView2.incrOffset();
1560 }
1561
1562 }
1563
1564 }
1565
1566 {
1567 cout << endl;
1568 cout << "\tTest DataArrayView copy with offset method - shape (2,3).";
1569
1570 // define the shape for the DataArrayViews
1571 DataTypes::ShapeType shape;
1572 shape.push_back(2);
1573 shape.push_back(3);
1574
1575 // allocate the data for the DataArrayViews
1576 int npoints=4;
1577 DataTypes::ValueType data1(DataArrayView::noValues(shape)*npoints,0);
1578 DataTypes::ValueType data2(DataArrayView::noValues(shape)*npoints,0);
1579
1580 // construct two views
1581 DataArrayView dataView1(data1,shape);
1582 DataArrayView dataView2(data2,shape);
1583
1584 // assign values to the data underlying the first view
1585 for (int i=0;i<shape[0];i++) {
1586 for (int j=0;j<shape[1];j++) {
1587 dataView1(i,j)=dataView1.index(i,j);
1588 }
1589 }
1590
1591 // copy data from the first view to the second at an offset
1592 dataView2.copy(12,dataView1,0);
1593
1594 // check the data underlying the second view
1595 dataView2.setOffset(12);
1596 for (int i=0;i<shape[0];i++) {
1597 for (int j=0;j<shape[1];j++) {
1598 assert(dataView2(i,j)==dataView1.index(i,j));
1599 }
1600 }
1601
1602 }
1603
1604 {
1605 cout << endl;
1606 cout << "\tTest DataArrayView copy with value method - shape (5,8).";
1607
1608 // define the shape for the DataArrayView
1609 DataTypes::ShapeType shape;
1610 shape.push_back(5);
1611 shape.push_back(8);
1612
1613 // allocate the data for the DataArrayView
1614 int npoints=4;
1615 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
1616
1617 // construct view
1618 DataArrayView dataView(data,shape);
1619
1620 // copy a value to the view at an offset
1621 dataView.copy(80,5);
1622
1623 // check the data underlying the second view
1624 dataView.setOffset(80);
1625 for (int i=0;i<shape[0];i++) {
1626 for (int j=0;j<shape[1];j++) {
1627 assert(dataView(i,j)==5);
1628 }
1629 }
1630
1631 }
1632
1633 #if defined DOASSERT
1634 {
1635 cout << endl;
1636 cout << "\tTest too many indices for shape exception.";
1637
1638 DataTypes::ShapeType shape;
1639 DataTypes::ValueType data(DataArrayView::noValues(shape),0);
1640 DataArrayView dataView(data,shape);
1641
1642 // Should be a scalar
1643 dataView()=1;
1644
1645 try {
1646 dataView(1)=1;
1647 assert(false);
1648 }
1649 catch (EsysException& e) {
1650 assert(true);
1651 }
1652
1653 try {
1654 dataView(1,1)=1;
1655 assert(false);
1656 }
1657 catch (EsysException& e) {
1658 assert(true);
1659 }
1660
1661 try {
1662 dataView(1,1,1)=1;
1663 assert(false);
1664 }
1665 catch (EsysException& e) {
1666 assert(true);
1667 }
1668
1669 try {
1670 dataView(1,1,1,1)=1;
1671 assert(false);
1672 }
1673 catch (EsysException& e) {
1674 assert(true);
1675 }
1676
1677 }
1678 #endif
1679
1680 #if defined DOASSERT
1681 {
1682 cout << endl;
1683 cout << "\tTest invalid index exception.";
1684
1685 DataTypes::ShapeType shape;
1686 shape.push_back(4);
1687 DataTypes::ValueType data(DataArrayView::noValues(shape),0);
1688 DataArrayView dataView(data,shape);
1689
1690 try {
1691 dataView(4000)=1;
1692 assert(false);
1693 }
1694 catch (EsysException& e) {
1695 assert(true);
1696 }
1697 }
1698 #endif
1699
1700 {
1701 cout << endl;
1702 cout << "\tTest insufficient data exception.";
1703
1704 DataTypes::ShapeType shape;
1705 DataTypes::ValueType data;
1706
1707 try {
1708 DataArrayView dataView(data,shape);
1709 assert(false);
1710 }
1711 catch (EsysException&) {
1712 assert(true);
1713 }
1714 }
1715
1716 cout << endl;
1717
1718 }
1719
1720 void DataArrayViewTestCase::testMatMult()
1721 {
1722
1723 {
1724 cout << endl;
1725 cout << "\tTest result shape." << endl;
1726
1727 DataTypes::ShapeType leftShape;
1728 leftShape.push_back(1);
1729 leftShape.push_back(3);
1730 DataTypes::ValueType leftData(DataArrayView::noValues(leftShape),0);
1731 DataArrayView leftDataView(leftData,leftShape);
1732
1733 DataTypes::ShapeType rightShape;
1734 rightShape.push_back(3);
1735 rightShape.push_back(2);
1736 DataTypes::ValueType rightData(DataArrayView::noValues(rightShape),0);
1737 DataArrayView rightDataView(rightData,rightShape);
1738
1739 DataTypes::ShapeType resultShape=DataArrayView::determineResultShape(leftDataView,rightDataView);
1740
1741 assert(resultShape.size()==2);
1742 assert(resultShape[0]==1);
1743 assert(resultShape[1]==2);
1744
1745 DataTypes::ValueType resultData(DataArrayView::noValues(resultShape),0);
1746 DataArrayView resultDataView(resultData,resultShape);
1747
1748 cout << "\tTest matrix multiplication.";
1749 double aValue=0.0;
1750 for (int i=0;i<leftShape[0];i++) {
1751 for (int j=0;j<leftShape[1];j++) {
1752 leftDataView(i,j)=++aValue;
1753 }
1754 }
1755 aValue=0.0;
1756 for (int i=0;i<rightShape[0];i++) {
1757 for (int j=0;j<rightShape[1];j++) {
1758 rightDataView(i,j)=++aValue;
1759 }
1760 }
1761
1762 DataArrayView::matMult(leftDataView,rightDataView,resultDataView);
1763 }
1764
1765 cout << endl;
1766
1767 }
1768
1769 void DataArrayViewTestCase::testUnaryOp()
1770 {
1771
1772 // This typedef allows function names to be cast to pointers
1773 // to unary functions of the appropriate type.
1774 typedef double (*UnaryDFunPtr)(double);
1775
1776 {
1777 cout << endl;
1778 cout << "\tTest unaryOp on scalar DataArrayView.";
1779
1780 // define the shape for the DataArrayView
1781 DataTypes::ShapeType shape;
1782
1783 // allocate the data for the DataArrayView
1784 int npoints=4;
1785 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
1786
1787 // constructor
1788 DataArrayView dataView(data,shape);
1789
1790 double tmp;
1791 // step the view along each data point in the underlying data
1792 for (int p=0;p<npoints;p++) {
1793
1794 // assign values to the data point
1795 dataView()=p;
1796
1797 // apply a unary operation to this data point
1798 dataView.unaryOp((UnaryDFunPtr)std::sin);
1799
1800 // check the results
1801 tmp = std::sin((double)p);
1802 assert(std::abs(dataView()-tmp)<=REL_TOL*std::abs(tmp));
1803
1804 if (p<npoints-1) {
1805 dataView.incrOffset();
1806 }
1807
1808 }
1809
1810 }
1811
1812 {
1813 cout << endl;
1814 cout << "\tTest unaryOp on shape (2,3) DataArrayView.";
1815
1816 // define the shape for the DataArrayView
1817 DataTypes::ShapeType shape;
1818 shape.push_back(2);
1819 shape.push_back(3);
1820
1821 // allocate the data for the DataArrayView
1822 int npoints=4;
1823 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
1824
1825 // constructor
1826 DataArrayView dataView(data,shape);
1827
1828 // step the view along each data point in the underlying data
1829 for (int p=0;p<npoints;p++) {
1830
1831 // assign values to the data point
1832 for (int i=0;i<shape[0];i++) {
1833 for (int j=0;j<shape[1];j++) {
1834 dataView(i,j)=dataView.index(i,j);
1835 }
1836 }
1837
1838 // apply a unary operation to this data point
1839 dataView.unaryOp((UnaryDFunPtr)std::sqrt);
1840
1841 // check the results
1842 for (int i=0;i<shape[0];i++) {
1843 for (int j=0;j<shape[1];j++) {
1844 assert(std::abs(dataView(i,j)-std::sqrt((double)dataView.index(i,j)))<=REL_TOL*std::sqrt((double)dataView.index(i,j)));
1845 }
1846 }
1847
1848 if (p<npoints-1) {
1849 dataView.incrOffset();
1850 }
1851
1852 }
1853
1854 }
1855
1856 {
1857 cout << endl;
1858 cout << "\tTest unaryOp on shape (9,8,5,11) DataArrayView.";
1859
1860 // define the shape for the DataArrayView
1861 DataTypes::ShapeType shape;
1862 shape.push_back(9);
1863 shape.push_back(8);
1864 shape.push_back(5);
1865 shape.push_back(11);
1866
1867 // allocate the data for the DataArrayView
1868 int npoints=4;
1869 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
1870
1871 // constructor
1872 DataArrayView dataView(data,shape);
1873
1874 // step the view along each data point in the underlying data
1875 for (int p=0;p<npoints;p++) {
1876
1877 // assign values to the data point
1878 for (int i=0;i<shape[0];i++) {
1879 for (int j=0;j<shape[1];j++) {
1880 for (int k=0;k<shape[2];k++) {
1881 for (int l=0;l<shape[3];l++) {
1882 dataView(i,j,k,l)=dataView.index(i,j,k,l)+1;
1883 }
1884 }
1885 }
1886 }
1887
1888 // apply a unary operation to this data point
1889 dataView.unaryOp((UnaryDFunPtr)std::log);
1890
1891 // check the results
1892 for (int i=0;i<shape[0];i++) {
1893 for (int j=0;j<shape[1];j++) {
1894 for (int k=0;k<shape[2];k++) {
1895 for (int l=0;l<shape[3];l++) {
1896 assert(std::abs(dataView(i,j,k,l)-std::log(1+(double)dataView.index(i,j,k,l)))<=REL_TOL*std::abs(std::log(1+(double)dataView.index(i,j,k,l))));
1897 }
1898 }
1899 }
1900 }
1901
1902 if (p<npoints-1) {
1903 dataView.incrOffset();
1904 }
1905
1906 }
1907
1908 }
1909
1910 cout << endl;
1911
1912 }
1913
1914 void DataArrayViewTestCase::testBinaryOp()
1915 {
1916
1917 // This typedef allows function names to be cast to pointers
1918 // to binary functions of the appropriate type.
1919 typedef double (*BinaryDFunPtr)(double,double);
1920
1921 {
1922 cout << endl;
1923 cout << "\tTest binaryOp on scalar DataArrayViews.";
1924
1925 // define the shape for the DataArrayViews
1926 DataTypes::ShapeType shape;
1927
1928 // allocate the data for the DataArrayViews
1929 int npoints=4;
1930 DataTypes::ValueType data1(DataArrayView::noValues(shape)*npoints,0);
1931 DataTypes::ValueType data2(DataArrayView::noValues(shape)*npoints,0);
1932
1933 // constructor
1934 DataArrayView dataView1(data1,shape);
1935 DataArrayView dataView2(data2,shape);
1936
1937 // step the views along each data point in the underlying data
1938 for (int p=0;p<npoints;p++) {
1939
1940 // assign values to the data points
1941 dataView1()=p;
1942 dataView2()=p;
1943
1944 // apply a binary operation to these data points
1945 dataView1.binaryOp(dataView2,plus<double>());
1946
1947 // check the results
1948 assert(dataView1()==p+p);
1949
1950 if (p<npoints-1) {
1951 dataView1.incrOffset();
1952 dataView2.incrOffset();
1953 }
1954
1955 }
1956
1957 }
1958
1959 {
1960 cout << endl;
1961 cout << "\tTest binaryOp on shape (2,3) DataArrayViews.";
1962
1963 // define the shape for the DataArrayViews
1964 DataTypes::ShapeType shape;
1965 shape.push_back(2);
1966 shape.push_back(3);
1967
1968 // allocate the data for the DataArrayViews
1969 int npoints=4;
1970 DataTypes::ValueType data1(DataArrayView::noValues(shape)*npoints,0);
1971 DataTypes::ValueType data2(DataArrayView::noValues(shape)*npoints,0);
1972
1973 // constructor
1974 DataArrayView dataView1(data1,shape);
1975 DataArrayView dataView2(data2,shape);
1976
1977 // step the views along each data point in the underlying data
1978 for (int p=0;p<npoints;p++) {
1979
1980 // assign values to the data points
1981 for (int i=0;i<shape[0];i++) {
1982 for (int j=0;j<shape[1];j++) {
1983 dataView1(i,j)=dataView1.index(i,j);
1984 dataView2(i,j)=dataView2.index(i,j);
1985 }
1986 }
1987
1988 // apply a binary operation to these data points
1989 dataView1.binaryOp(dataView2,multiplies<double>());
1990
1991 // check the results
1992 for (int i=0;i<shape[0];i++) {
1993 for (int j=0;j<shape[1];j++) {
1994 assert(dataView1(i,j)==dataView1.index(i,j)*dataView2.index(i,j));
1995 }
1996 }
1997
1998 if (p<npoints-1) {
1999 dataView1.incrOffset();
2000 dataView2.incrOffset();
2001 }
2002
2003 }
2004
2005 }
2006
2007 {
2008 cout << endl;
2009 cout << "\tTest binaryOp on shape (9,8,5,11) DataArrayViews.";
2010
2011 // define the shape for the DataArrayViews
2012 DataTypes::ShapeType shape;
2013 shape.push_back(9);
2014 shape.push_back(8);
2015 shape.push_back(5);
2016 shape.push_back(11);
2017
2018 // allocate the data for the DataArrayViews
2019 int npoints=4;
2020 DataTypes::ValueType data1(DataArrayView::noValues(shape)*npoints,0);
2021 DataTypes::ValueType data2(DataArrayView::noValues(shape)*npoints,0);
2022
2023 // constructor
2024 DataArrayView dataView1(data1,shape);
2025 DataArrayView dataView2(data2,shape);
2026
2027 // step the views along each data point in the underlying data
2028 for (int p=0;p<npoints;p++) {
2029
2030 // assign values to the data points
2031 for (int i=0;i<shape[0];i++) {
2032 for (int j=0;j<shape[1];j++) {
2033 for (int k=0;k<shape[2];k++) {
2034 for (int l=0;l<shape[3];l++) {
2035 dataView1(i,j,k,l)=dataView1.index(i,j,k,l);
2036 dataView2(i,j,k,l)=dataView2.index(i,j,k,l);
2037 }
2038 }
2039 }
2040 }
2041
2042 // apply a binary operation to these data points
2043 dataView1.binaryOp(dataView2,multiplies<double>());
2044
2045 // check the results
2046 for (int i=0;i<shape[0];i++) {
2047 for (int j=0;j<shape[1];j++) {
2048 for (int k=0;k<shape[2];k++) {
2049 for (int l=0;l<shape[3];l++) {
2050 assert(dataView1(i,j,k,l)==dataView1.index(i,j,k,l)*dataView2.index(i,j,k,l));
2051 }
2052 }
2053 }
2054 }
2055
2056 if (p<npoints-1) {
2057 dataView1.incrOffset();
2058 dataView2.incrOffset();
2059 }
2060
2061 }
2062
2063 }
2064
2065 {
2066 cout << endl;
2067 cout << "\tTest binaryOp on scalar DataArrayView and single value.";
2068
2069 // define the shape for the DataArrayView
2070 DataTypes::ShapeType shape;
2071
2072 // allocate the data for the DataArrayView
2073 int npoints=4;
2074 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
2075
2076 // constructor
2077 DataArrayView dataView(data,shape);
2078
2079 // step the view along each data point in the underlying data
2080 for (int p=0;p<npoints;p++) {
2081
2082 // assign values to the data point
2083 dataView()=p;
2084
2085 // apply a binary operation to this data point
2086 dataView.binaryOp(4.9,plus<double>());
2087
2088 // check the results
2089 assert(dataView()==4.9+p);
2090
2091 if (p<npoints-1) {
2092 dataView.incrOffset();
2093 }
2094
2095 }
2096
2097 }
2098
2099 {
2100 cout << endl;
2101 cout << "\tTest binaryOp on shape (2,3) DataArrayView and single value.";
2102
2103 // define the shape for the DataArrayView
2104 DataTypes::ShapeType shape;
2105 shape.push_back(2);
2106 shape.push_back(3);
2107
2108 // allocate the data for the DataArrayView
2109 int npoints=4;
2110 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
2111
2112 // constructor
2113 DataArrayView dataView(data,shape);
2114
2115 // step the view along each data point in the underlying data
2116 for (int p=0;p<npoints;p++) {
2117
2118 // assign values to the data point
2119 for (int i=0;i<shape[0];i++) {
2120 for (int j=0;j<shape[1];j++) {
2121 dataView(i,j)=dataView.index(i,j);
2122 }
2123 }
2124
2125 // apply a binary operation to the data point
2126 dataView.binaryOp(5.8,multiplies<double>());
2127
2128 double tmp;
2129 // check the results
2130 for (int i=0;i<shape[0];i++) {
2131 for (int j=0;j<shape[1];j++) {
2132 tmp=5.8*dataView.index(i,j);
2133 assert(std::abs(dataView(i,j)-tmp)<=REL_TOL*std::abs(tmp));
2134 }
2135 }
2136
2137 if (p<npoints-1) {
2138 dataView.incrOffset();
2139 }
2140
2141 }
2142
2143 }
2144
2145 {
2146 cout << endl;
2147 cout << "\tTest binaryOp on shape (9,8,5,11) DataArrayView and single value.";
2148
2149 // define the shape for the DataArrayView
2150 DataTypes::ShapeType shape;
2151 shape.push_back(9);
2152 shape.push_back(8);
2153 shape.push_back(5);
2154 shape.push_back(11);
2155
2156 // allocate the data for the DataArrayView
2157 int npoints=4;
2158 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
2159
2160 // constructor
2161 DataArrayView dataView(data,shape);
2162
2163 // step the view along each data point in the underlying data
2164 for (int p=0;p<npoints;p++) {
2165
2166 // assign values to the data point
2167 for (int i=0;i<shape[0];i++) {
2168 for (int j=0;j<shape[1];j++) {
2169 for (int k=0;k<shape[2];k++) {
2170 for (int l=0;l<shape[3];l++) {
2171 dataView(i,j,k,l)=dataView.index(i,j,k,l);
2172 }
2173 }
2174 }
2175 }
2176
2177 // apply a binary operation to the data point
2178 dataView.binaryOp(5.4,multiplies<double>());
2179
2180 double tmp;
2181 // check the results
2182 for (int i=0;i<shape[0];i++) {
2183 for (int j=0;j<shape[1];j++) {
2184 for (int k=0;k<shape[2];k++) {
2185 for (int l=0;l<shape[3];l++) {
2186 tmp=5.4*dataView.index(i,j,k,l);
2187 assert(std::abs(dataView(i,j,k,l)-tmp)<=REL_TOL*std::abs(tmp));
2188 }
2189 }
2190 }
2191 }
2192
2193 if (p<npoints-1) {
2194 dataView.incrOffset();
2195 }
2196
2197 }
2198
2199 }
2200
2201 cout << endl;
2202
2203 }
2204
2205 void DataArrayViewTestCase::testReductionOp()
2206 {
2207
2208 {
2209 cout << endl;
2210 cout << "\tTest reductionOp on scalar DataArrayView.";
2211
2212 // define the shape for the DataArrayView
2213 DataTypes::ShapeType shape;
2214
2215 // allocate the data for the DataArrayView
2216 int npoints=4;
2217 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
2218
2219 // constructor
2220 DataArrayView dataView(data,shape);
2221
2222 // step the view along each data point in the underlying data
2223 for (int p=0;p<npoints;p++) {
2224
2225 // assign values to the data point
2226 dataView()=p;
2227
2228 // apply a reduction operation to this data point and check the results
2229 FMax fmax_func;
2230 assert(std::abs(dataView.reductionOp(fmax_func,numeric_limits<double>::max()*-1)-p)<=REL_TOL*p);
2231
2232 if (p<npoints-1) {
2233 dataView.incrOffset();
2234 }
2235
2236 }
2237
2238 }
2239
2240 {
2241 cout << endl;
2242 cout << "\tTest reductionOp on shape (2,3) DataArrayView.";
2243
2244 // define the shape for the DataArrayView
2245 DataTypes::ShapeType shape;
2246 shape.push_back(2);
2247 shape.push_back(3);
2248
2249 // allocate the data for the DataArrayView
2250 int npoints=4;
2251 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
2252
2253 // constructor
2254 DataArrayView dataView(data,shape);
2255
2256 // step the view along each data point in the underlying data
2257 for (int p=0;p<npoints;p++) {
2258
2259 // assign values to the data point
2260 for (int i=0;i<shape[0];i++) {
2261 for (int j=0;j<shape[1];j++) {
2262 dataView(i,j)=dataView.index(i,j);
2263 }
2264 }
2265
2266 // apply a reduction operation to this data point and check the results
2267 FMin fmin_func;
2268 assert(std::abs(dataView.reductionOp(fmin_func,numeric_limits<double>::max())-dataView.index(0,0))<=REL_TOL*std::abs(dataView.index(0,0)));
2269
2270 if (p<npoints-1) {
2271 dataView.incrOffset();
2272 }
2273
2274 }
2275
2276 }
2277
2278 {
2279 cout << endl;
2280 cout << "\tTest reductionOp on shape (9,8,5,11) DataArrayView.";
2281
2282 // define the shape for the DataArrayView
2283 DataTypes::ShapeType shape;
2284 shape.push_back(9);
2285 shape.push_back(8);
2286 shape.push_back(5);
2287 shape.push_back(11);
2288
2289 // allocate the data for the DataArrayView
2290 int npoints=4;
2291 DataTypes::ValueType data(DataArrayView::noValues(shape)*npoints,0);
2292
2293 // constructor
2294 DataArrayView dataView(data,shape);
2295
2296 // step the view along each data point in the underlying data
2297 for (int p=0;p<npoints;p++) {
2298
2299 // assign values to the data point
2300 for (int i=0;i<shape[0];i++) {
2301 for (int j=0;j<shape[1];j++) {
2302 for (int k=0;k<shape[2];k++) {
2303 for (int l=0;l<shape[3];l++) {
2304 dataView(i,j,k,l)=dataView.index(i,j,k,l);
2305 }
2306 }
2307 }
2308 }
2309
2310 // apply a reduction operation to this data point and check the results
2311 AbsMax absmax_func;
2312 assert(dataView.reductionOp(absmax_func,0)==dataView.index(8,7,4,10));
2313
2314 if (p<npoints-1) {
2315 dataView.incrOffset();
2316 }
2317
2318 }
2319
2320 }
2321
2322 cout << endl;
2323
2324 }
2325
2326 TestSuite* DataArrayViewTestCase::suite ()
2327 {
2328 //
2329 // create the suite of tests to perform.
2330 TestSuite *testSuite = new TestSuite ("DataArrayViewTestCase");
2331
2332 testSuite->addTest (new TestCaller< DataArrayViewTestCase>("testAll",&DataArrayViewTestCase::testAll));
2333 testSuite->addTest (new TestCaller< DataArrayViewTestCase>("testShapeToString",&DataArrayViewTestCase::testShapeToString));
2334 testSuite->addTest (new TestCaller< DataArrayViewTestCase>("testScalarView",&DataArrayViewTestCase::testScalarView));
2335 testSuite->addTest (new TestCaller< DataArrayViewTestCase>("testResultSliceShape",&DataArrayViewTestCase::testResultSliceShape));
2336 testSuite->addTest (new TestCaller< DataArrayViewTestCase>("testSlicing",&DataArrayViewTestCase::testSlicing));
2337 testSuite->addTest (new TestCaller< DataArrayViewTestCase>("testUnaryOp",&DataArrayViewTestCase::testUnaryOp));
2338 testSuite->addTest (new TestCaller< DataArrayViewTestCase>("testBinaryOp",&DataArrayViewTestCase::testBinaryOp));
2339 testSuite->addTest (new TestCaller< DataArrayViewTestCase>("testReductionOp",&DataArrayViewTestCase::testReductionOp));
2340 testSuite->addTest (new TestCaller< DataArrayViewTestCase>("testMatMult",&DataArrayViewTestCase::testMatMult));
2341 return testSuite;
2342 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26