/[escript]/trunk/escript/test/DataArrayViewTestCase.cpp
ViewVC logotype

Annotation of /trunk/escript/test/DataArrayViewTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (hide annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years, 1 month ago) by ksteube
File size: 63533 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26