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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 113 - (hide annotations)
Mon Feb 28 07:06:33 2005 UTC (14 years, 6 months ago) by jgs
Original Path: trunk/esys2/escript/test/DataArrayView/DataArrayViewTestCase.cpp
File size: 63517 byte(s)
*** empty log message ***

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26