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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/escript/test/DataArrayView/DataArrayViewTestCase.cpp revision 468 by jgs, Wed Jan 25 06:50:39 2006 UTC trunk/escript/test/DataArrayViewTestCase.cpp revision 1325 by matt, Mon Oct 1 06:28:24 2007 UTC
# Line 1  Line 1 
1  /*  
2   *****************************************************************************  /* $Id$ */
3   *                                                                           *  
4   *       COPYRIGHT  ACcESS  -  All Rights Reserved                           *  /*******************************************************
5   *                                                                           *   *
6   * This software is the property of ACcESS. No part of this code             *   *           Copyright 2003-2007 by ACceSS MNRF
7   * may be copied in any form or by any means without the expressed written   *   *       Copyright 2007 by University of Queensland
8   * consent of ACcESS.  Copying, use or modification of this software         *   *
9   * by any unauthorised person is illegal unless that person has a software   *   *                http://esscc.uq.edu.au
10   * license agreement with ACcESS.                                            *   *        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  #include "escript/Data/DataArray.h"   *******************************************************/
15  #include "escript/Data/DataArrayView.h"  
16  #include "escript/Data/DataAlgorithm.h"  #include "escript/DataArrayView.h"
17  #include "EsysException.h"  #include "escript/DataAlgorithm.h"
18    #include "escript/DataVector.h"
19    #include "esysUtils/EsysException.h"
20    
21  #include "DataArrayViewTestCase.h"  #include "DataArrayViewTestCase.h"
22    
# Line 28  using namespace std; Line 30  using namespace std;
30  void DataArrayViewTestCase::setUp() {  void DataArrayViewTestCase::setUp() {
31    //    //
32    // This is called before each test is run    // This is called before each test is run
33    
34  }  }
35    
36  void DataArrayViewTestCase::tearDown() {  void DataArrayViewTestCase::tearDown() {
37    //    //
38    // This is called after each test has been run    // This is called after each test has been run
39    
40  }  }
41    
42  void DataArrayViewTestCase::testResultSliceShape() {  void DataArrayViewTestCase::testResultSliceShape() {
# Line 76  void DataArrayViewTestCase::testSlicing( Line 78  void DataArrayViewTestCase::testSlicing(
78      DataArrayView::ShapeType sourceShape;      DataArrayView::ShapeType sourceShape;
79    
80      // Create source and target views.      // Create source and target views.
81      DataArray source(sourceShape,2.0);      int len = DataArrayView::noValues(sourceShape);
82      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
83        DataArrayView sourceView(sourceData, sourceShape);
84      DataArray target;      DataVector targetData(1, 2.0, 1);
85      DataArrayView targetView=target.getView();      DataArrayView targetView(targetData, DataArrayView::ShapeType());
86    
87      // Copy source view to target view.      // Copy source view to target view.
88      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 100  void DataArrayViewTestCase::testSlicing( Line 102  void DataArrayViewTestCase::testSlicing(
102      DataArrayView::ShapeType sourceShape;      DataArrayView::ShapeType sourceShape;
103    
104      // Create source and target views.      // Create source and target views.
105      DataArray source(sourceShape,2.0);      int len = DataArrayView::noValues(sourceShape);
106      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
107        DataArrayView sourceView(sourceData, sourceShape);
108      DataArray target;      DataVector targetData(1, 2.0, 1);
109      DataArrayView targetView=target.getView();      DataArrayView targetView(targetData, DataArrayView::ShapeType());
110    
111      // Copy source view to target view.      // Copy source view to target view.
112      targetView.copySliceFrom(sourceView,region);      targetView.copySliceFrom(sourceView,region);
# Line 127  void DataArrayViewTestCase::testSlicing( Line 129  void DataArrayViewTestCase::testSlicing(
129      DataArrayView::ShapeType targetShape = DataArrayView::getResultSliceShape(region);      DataArrayView::ShapeType targetShape = DataArrayView::getResultSliceShape(region);
130    
131      // Create source and target views.      // Create source and target views.
132      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
133      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
134        DataArrayView sourceView(sourceData, sourceShape);
135      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
136        sourceView(i)=i;        sourceView(i)=i;
137      }      }
138    
139      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
140      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
141        DataArrayView targetView(targetData, targetShape);
142    
143      // Copy source view to target view.      // Copy source view to target view.
144      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 160  void DataArrayViewTestCase::testSlicing( Line 164  void DataArrayViewTestCase::testSlicing(
164      DataArrayView::ShapeType targetShape;      DataArrayView::ShapeType targetShape;
165    
166      // Create source and target views.      // Create source and target views.
167      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
168      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
169        DataArrayView sourceView(sourceData, sourceShape);
170    
171      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
172        sourceView(i)=i;        sourceView(i)=i;
173      }      }
174    
175      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
176      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
177        DataArrayView targetView(targetData, targetShape);
178    
179      // Copy source view to target view.      // Copy source view to target view.
180      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 193  void DataArrayViewTestCase::testSlicing( Line 200  void DataArrayViewTestCase::testSlicing(
200      targetShape.push_back(6);      targetShape.push_back(6);
201    
202      // Create source and target views.      // Create source and target views.
203      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
204      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
205        DataArrayView sourceView(sourceData, sourceShape);
206      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
207        sourceView(i)=i;        sourceView(i)=i;
208      }      }
209    
210      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
211      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
212        DataArrayView targetView(targetData, targetShape);
213    
214      // Copy source view to target view.      // Copy source view to target view.
215      targetView.copySliceFrom(sourceView,region);      targetView.copySliceFrom(sourceView,region);
# Line 226  void DataArrayViewTestCase::testSlicing( Line 235  void DataArrayViewTestCase::testSlicing(
235      targetShape.push_back(6);      targetShape.push_back(6);
236    
237      // Create source and target views.      // Create source and target views.
238      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
239      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
240        DataArrayView sourceView(sourceData, sourceShape);
241      sourceView()=5;      sourceView()=5;
242    
243      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
244      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
245        DataArrayView targetView(targetData, targetShape);
246    
247      // Copy source view to target view.      // Copy source view to target view.
248      targetView.copySliceFrom(sourceView,region);      targetView.copySliceFrom(sourceView,region);
# Line 259  void DataArrayViewTestCase::testSlicing( Line 270  void DataArrayViewTestCase::testSlicing(
270      DataArrayView::ShapeType targetShape = DataArrayView::getResultSliceShape(region);      DataArrayView::ShapeType targetShape = DataArrayView::getResultSliceShape(region);
271    
272      // Create source and target views.      // Create source and target views.
273      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
274      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
275        DataArrayView sourceView(sourceData, sourceShape);
276      int val=0;      int val=0;
277      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
278        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 268  void DataArrayViewTestCase::testSlicing( Line 280  void DataArrayViewTestCase::testSlicing(
280        }        }
281      }      }
282    
283      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
284      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
285        DataArrayView targetView(targetData, targetShape);
286    
287      // Copy source view to target view.      // Copy source view to target view.
288      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 300  void DataArrayViewTestCase::testSlicing( Line 313  void DataArrayViewTestCase::testSlicing(
313      targetShape.push_back(3);      targetShape.push_back(3);
314    
315      // Create source and target views.      // Create source and target views.
316      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
317      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
318        DataArrayView sourceView(sourceData, sourceShape);
319      int val=0;      int val=0;
320      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
321        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 309  void DataArrayViewTestCase::testSlicing( Line 323  void DataArrayViewTestCase::testSlicing(
323        }        }
324      }      }
325    
326      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
327      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
328        DataArrayView targetView(targetData, targetShape);
329    
330      // Copy source view to target view.      // Copy source view to target view.
331      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 340  void DataArrayViewTestCase::testSlicing( Line 355  void DataArrayViewTestCase::testSlicing(
355      DataArrayView::ShapeType targetShape;      DataArrayView::ShapeType targetShape;
356    
357      // Create source and target views.      // Create source and target views.
358      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
359      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
360        DataArrayView sourceView(sourceData, sourceShape);
361      int val=0;      int val=0;
362      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
363        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 349  void DataArrayViewTestCase::testSlicing( Line 365  void DataArrayViewTestCase::testSlicing(
365        }        }
366      }      }
367    
368      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
369      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
370        DataArrayView targetView(targetData, targetShape);
371    
372      // Copy source view to target view.      // Copy source view to target view.
373      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 379  void DataArrayViewTestCase::testSlicing( Line 396  void DataArrayViewTestCase::testSlicing(
396      targetShape.push_back(3);      targetShape.push_back(3);
397    
398      // Create source and target views.      // Create source and target views.
399      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
400      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
401        DataArrayView sourceView(sourceData, sourceShape);
402      int val=0;      int val=0;
403      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
404        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 388  void DataArrayViewTestCase::testSlicing( Line 406  void DataArrayViewTestCase::testSlicing(
406        }        }
407      }      }
408    
409      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
410      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
411        DataArrayView targetView(targetData, targetShape);
412    
413      // Copy source view to target view.      // Copy source view to target view.
414      targetView.copySliceFrom(sourceView,region);      targetView.copySliceFrom(sourceView,region);
# Line 419  void DataArrayViewTestCase::testSlicing( Line 438  void DataArrayViewTestCase::testSlicing(
438      targetShape.push_back(3);      targetShape.push_back(3);
439    
440      // Create source and target views.      // Create source and target views.
441      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
442      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
443        DataArrayView sourceView(sourceData, sourceShape);
444      sourceView()=5;      sourceView()=5;
445    
446      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
447      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
448        DataArrayView targetView(targetData, targetShape);
449    
450      // Copy source view to target view.      // Copy source view to target view.
451      targetView.copySliceFrom(sourceView,region);      targetView.copySliceFrom(sourceView,region);
# Line 456  void DataArrayViewTestCase::testSlicing( Line 477  void DataArrayViewTestCase::testSlicing(
477      DataArrayView::ShapeType targetShape = DataArrayView::getResultSliceShape(region);      DataArrayView::ShapeType targetShape = DataArrayView::getResultSliceShape(region);
478    
479      // Create source and target views.      // Create source and target views.
480      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
481      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
482        DataArrayView sourceView(sourceData, sourceShape);
483      int val=0;      int val=0;
484      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
485        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 467  void DataArrayViewTestCase::testSlicing( Line 489  void DataArrayViewTestCase::testSlicing(
489        }        }
490      }      }
491    
492      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
493      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
494        DataArrayView targetView(targetData, targetShape);
495    
496      // Copy source view to target view.      // Copy source view to target view.
497      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 504  void DataArrayViewTestCase::testSlicing( Line 527  void DataArrayViewTestCase::testSlicing(
527      targetShape.push_back(4);      targetShape.push_back(4);
528    
529      // Create source and target views.      // Create source and target views.
530      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
531      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
532        DataArrayView sourceView(sourceData, sourceShape);
533      int val=0;      int val=0;
534      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
535        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 515  void DataArrayViewTestCase::testSlicing( Line 539  void DataArrayViewTestCase::testSlicing(
539        }        }
540      }      }
541    
542      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
543      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
544        DataArrayView targetView(targetData, targetShape);
545    
546      // Copy source view to target view.      // Copy source view to target view.
547      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 551  void DataArrayViewTestCase::testSlicing( Line 576  void DataArrayViewTestCase::testSlicing(
576      targetShape.push_back(4);      targetShape.push_back(4);
577    
578      // Create source and target views.      // Create source and target views.
579      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
580      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
581        DataArrayView sourceView(sourceData, sourceShape);
582      int val=0;      int val=0;
583      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
584        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 562  void DataArrayViewTestCase::testSlicing( Line 588  void DataArrayViewTestCase::testSlicing(
588        }        }
589      }      }
590    
591      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
592      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
593        DataArrayView targetView(targetData, targetShape);
594    
595      // Copy source view to target view.      // Copy source view to target view.
596      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 597  void DataArrayViewTestCase::testSlicing( Line 624  void DataArrayViewTestCase::testSlicing(
624      DataArrayView::ShapeType targetShape;      DataArrayView::ShapeType targetShape;
625    
626      // Create source and target views.      // Create source and target views.
627      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
628      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
629        DataArrayView sourceView(sourceData, sourceShape);
630      int val=0;      int val=0;
631      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
632        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 608  void DataArrayViewTestCase::testSlicing( Line 636  void DataArrayViewTestCase::testSlicing(
636        }        }
637      }      }
638    
639      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
640      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
641        DataArrayView targetView(targetData, targetShape);
642    
643      // Copy source view to target view.      // Copy source view to target view.
644      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 643  void DataArrayViewTestCase::testSlicing( Line 672  void DataArrayViewTestCase::testSlicing(
672      targetShape.push_back(9);      targetShape.push_back(9);
673    
674      // Create source and target views.      // Create source and target views.
675      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
676      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
677        DataArrayView sourceView(sourceData, sourceShape);
678      int val=0;      int val=0;
679      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
680        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 654  void DataArrayViewTestCase::testSlicing( Line 684  void DataArrayViewTestCase::testSlicing(
684        }        }
685      }      }
686    
687      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
688      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
689        DataArrayView targetView(targetData, targetShape);
690    
691      // Copy source view to target view.      // Copy source view to target view.
692      targetView.copySliceFrom(sourceView,region);      targetView.copySliceFrom(sourceView,region);
# Line 689  void DataArrayViewTestCase::testSlicing( Line 720  void DataArrayViewTestCase::testSlicing(
720      targetShape.push_back(9);      targetShape.push_back(9);
721    
722      // Create source and target views.      // Create source and target views.
723      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
724      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
725        DataArrayView sourceView(sourceData, sourceShape);
726      sourceView()=5;      sourceView()=5;
727    
728      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
729      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
730        DataArrayView targetView(targetData, targetShape);
731    
732      // Copy source view to target view.      // Copy source view to target view.
733      targetView.copySliceFrom(sourceView,region);      targetView.copySliceFrom(sourceView,region);
# Line 730  void DataArrayViewTestCase::testSlicing( Line 763  void DataArrayViewTestCase::testSlicing(
763      DataArrayView::ShapeType targetShape = DataArrayView::getResultSliceShape(region);      DataArrayView::ShapeType targetShape = DataArrayView::getResultSliceShape(region);
764    
765      // Create source and target views.      // Create source and target views.
766      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
767      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
768        DataArrayView sourceView(sourceData, sourceShape);
769      int val=0;      int val=0;
770      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
771        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 743  void DataArrayViewTestCase::testSlicing( Line 777  void DataArrayViewTestCase::testSlicing(
777        }        }
778      }      }
779    
780      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
781      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
782        DataArrayView targetView(targetData, targetShape);
783    
784      // Copy source view to target view.      // Copy source view to target view.
785      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 785  void DataArrayViewTestCase::testSlicing( Line 820  void DataArrayViewTestCase::testSlicing(
820      targetShape.push_back(2);      targetShape.push_back(2);
821    
822      // Create source and target views.      // Create source and target views.
823      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
824      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
825        DataArrayView sourceView(sourceData, sourceShape);
826      int val=0;      int val=0;
827      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
828        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 798  void DataArrayViewTestCase::testSlicing( Line 834  void DataArrayViewTestCase::testSlicing(
834        }        }
835      }      }
836    
837      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
838      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
839        DataArrayView targetView(targetData, targetShape);
840    
841      // Copy source view to target view.      // Copy source view to target view.
842      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 839  void DataArrayViewTestCase::testSlicing( Line 876  void DataArrayViewTestCase::testSlicing(
876      targetShape.push_back(2);      targetShape.push_back(2);
877    
878      // Create source and target views.      // Create source and target views.
879      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
880      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
881        DataArrayView sourceView(sourceData, sourceShape);
882      int val=0;      int val=0;
883      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
884        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 852  void DataArrayViewTestCase::testSlicing( Line 890  void DataArrayViewTestCase::testSlicing(
890        }        }
891      }      }
892    
893      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
894      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
895        DataArrayView targetView(targetData, targetShape);
896    
897      // Copy source view to target view.      // Copy source view to target view.
898      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 892  void DataArrayViewTestCase::testSlicing( Line 931  void DataArrayViewTestCase::testSlicing(
931      targetShape.push_back(2);      targetShape.push_back(2);
932    
933      // Create source and target views.      // Create source and target views.
934      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
935      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
936        DataArrayView sourceView(sourceData, sourceShape);
937      int val=0;      int val=0;
938      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
939        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 905  void DataArrayViewTestCase::testSlicing( Line 945  void DataArrayViewTestCase::testSlicing(
945        }        }
946      }      }
947    
948      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
949      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
950        DataArrayView targetView(targetData, targetShape);
951    
952      // Copy source view to target view.      // Copy source view to target view.
953      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 944  void DataArrayViewTestCase::testSlicing( Line 985  void DataArrayViewTestCase::testSlicing(
985      DataArrayView::ShapeType targetShape;      DataArrayView::ShapeType targetShape;
986    
987      // Create source and target views.      // Create source and target views.
988      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
989      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
990        DataArrayView sourceView(sourceData, sourceShape);
991      int val=0;      int val=0;
992      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
993        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 957  void DataArrayViewTestCase::testSlicing( Line 999  void DataArrayViewTestCase::testSlicing(
999        }        }
1000      }      }
1001    
1002      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
1003      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
1004        DataArrayView targetView(targetData, targetShape);
1005    
1006      // Copy source view to target view.      // Copy source view to target view.
1007      targetView.copySlice(sourceView,region);      targetView.copySlice(sourceView,region);
# Line 996  void DataArrayViewTestCase::testSlicing( Line 1039  void DataArrayViewTestCase::testSlicing(
1039      targetShape.push_back(90);      targetShape.push_back(90);
1040    
1041      // Create source and target views.      // Create source and target views.
1042      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
1043      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
1044        DataArrayView sourceView(sourceData, sourceShape);
1045      int val=0;      int val=0;
1046      for (int i=0;i<sourceShape[0];i++) {      for (int i=0;i<sourceShape[0];i++) {
1047        for (int j=0;j<sourceShape[1];j++) {        for (int j=0;j<sourceShape[1];j++) {
# Line 1009  void DataArrayViewTestCase::testSlicing( Line 1053  void DataArrayViewTestCase::testSlicing(
1053        }        }
1054      }      }
1055    
1056      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
1057      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
1058        DataArrayView targetView(targetData, targetShape);
1059    
1060      // Copy source view to target view.      // Copy source view to target view.
1061      targetView.copySliceFrom(sourceView,region);      targetView.copySliceFrom(sourceView,region);
# Line 1048  void DataArrayViewTestCase::testSlicing( Line 1093  void DataArrayViewTestCase::testSlicing(
1093      targetShape.push_back(90);      targetShape.push_back(90);
1094    
1095      // Create source and target views.      // Create source and target views.
1096      DataArray source(sourceShape);      int len = DataArrayView::noValues(sourceShape);
1097      DataArrayView sourceView=source.getView();      DataVector sourceData(len, 2.0, len);
1098        DataArrayView sourceView(sourceData, sourceShape);
1099      sourceView()=5;      sourceView()=5;
1100    
1101      DataArray target(targetShape);      len = DataArrayView::noValues(targetShape);
1102      DataArrayView targetView=target.getView();      DataVector targetData(len, 2.0, len);
1103        DataArrayView targetView(targetData, targetShape);
1104    
1105      // Copy source view to target view.      // Copy source view to target view.
1106      targetView.copySliceFrom(sourceView,region);      targetView.copySliceFrom(sourceView,region);
# Line 1582  void DataArrayViewTestCase::testAll() Line 1629  void DataArrayViewTestCase::testAll()
1629    
1630    }    }
1631    
1632      #if defined DOASSERT
1633    {    {
1634      cout << endl;      cout << endl;
1635      cout << "\tTest too many indices for shape exception.";      cout << "\tTest too many indices for shape exception.";
# Line 1626  void DataArrayViewTestCase::testAll() Line 1674  void DataArrayViewTestCase::testAll()
1674      }      }
1675    
1676    }    }
1677      #endif
1678    
1679      #if defined DOASSERT
1680    {    {
1681      cout << endl;      cout << endl;
1682      cout << "\tTest invalid index exception.";      cout << "\tTest invalid index exception.";
# Line 1644  void DataArrayViewTestCase::testAll() Line 1694  void DataArrayViewTestCase::testAll()
1694        assert(true);        assert(true);
1695      }      }
1696    }    }
1697      #endif
1698    
1699    {    {
1700      cout << endl;      cout << endl;
# Line 1692  void DataArrayViewTestCase::testMatMult( Line 1743  void DataArrayViewTestCase::testMatMult(
1743    
1744      DataArrayView::ValueType resultData(DataArrayView::noValues(resultShape),0);      DataArrayView::ValueType resultData(DataArrayView::noValues(resultShape),0);
1745      DataArrayView resultDataView(resultData,resultShape);      DataArrayView resultDataView(resultData,resultShape);
1746      
1747      cout << "\tTest matrix multiplication.";      cout << "\tTest matrix multiplication.";
1748      double aValue=0.0;      double aValue=0.0;
1749      for (int i=0;i<leftShape[0];i++) {      for (int i=0;i<leftShape[0];i++) {
# Line 1747  void DataArrayViewTestCase::testUnaryOp( Line 1798  void DataArrayViewTestCase::testUnaryOp(
1798    
1799        // check the results        // check the results
1800        tmp = std::sin((double)p);        tmp = std::sin((double)p);
1801        assert(dataView()==tmp);        assert(std::abs(dataView()-tmp)<=REL_TOL*std::abs(tmp));
1802    
1803        if (p<npoints-1) {        if (p<npoints-1) {
1804          dataView.incrOffset();          dataView.incrOffset();
# Line 1789  void DataArrayViewTestCase::testUnaryOp( Line 1840  void DataArrayViewTestCase::testUnaryOp(
1840        // check the results        // check the results
1841        for (int i=0;i<shape[0];i++) {        for (int i=0;i<shape[0];i++) {
1842          for (int j=0;j<shape[1];j++) {          for (int j=0;j<shape[1];j++) {
1843            assert(dataView(i,j)==std::sqrt((double)dataView.index(i,j)));            assert(std::abs(dataView(i,j)-std::sqrt((double)dataView.index(i,j)))<=REL_TOL*std::sqrt((double)dataView.index(i,j)));
1844          }          }
1845        }        }
1846    
# Line 1827  void DataArrayViewTestCase::testUnaryOp( Line 1878  void DataArrayViewTestCase::testUnaryOp(
1878          for (int j=0;j<shape[1];j++) {          for (int j=0;j<shape[1];j++) {
1879            for (int k=0;k<shape[2];k++) {            for (int k=0;k<shape[2];k++) {
1880              for (int l=0;l<shape[3];l++) {              for (int l=0;l<shape[3];l++) {
1881                dataView(i,j,k,l)=dataView.index(i,j,k,l);                dataView(i,j,k,l)=dataView.index(i,j,k,l)+1;
1882              }              }
1883            }            }
1884          }          }
# Line 1841  void DataArrayViewTestCase::testUnaryOp( Line 1892  void DataArrayViewTestCase::testUnaryOp(
1892          for (int j=0;j<shape[1];j++) {          for (int j=0;j<shape[1];j++) {
1893            for (int k=0;k<shape[2];k++) {            for (int k=0;k<shape[2];k++) {
1894              for (int l=0;l<shape[3];l++) {              for (int l=0;l<shape[3];l++) {
1895                assert(dataView(i,j,k,l)==std::log((double)dataView.index(i,j,k,l)));                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))));
1896              }              }
1897            }            }
1898          }          }
# Line 2078  void DataArrayViewTestCase::testBinaryOp Line 2129  void DataArrayViewTestCase::testBinaryOp
2129        for (int i=0;i<shape[0];i++) {        for (int i=0;i<shape[0];i++) {
2130          for (int j=0;j<shape[1];j++) {          for (int j=0;j<shape[1];j++) {
2131            tmp=5.8*dataView.index(i,j);            tmp=5.8*dataView.index(i,j);
2132            assert(dataView(i,j)==tmp);            assert(std::abs(dataView(i,j)-tmp)<=REL_TOL*std::abs(tmp));
2133          }          }
2134        }        }
2135    
# Line 2132  void DataArrayViewTestCase::testBinaryOp Line 2183  void DataArrayViewTestCase::testBinaryOp
2183            for (int k=0;k<shape[2];k++) {            for (int k=0;k<shape[2];k++) {
2184              for (int l=0;l<shape[3];l++) {              for (int l=0;l<shape[3];l++) {
2185                tmp=5.4*dataView.index(i,j,k,l);                tmp=5.4*dataView.index(i,j,k,l);
2186                assert(dataView(i,j,k,l)==tmp);                assert(std::abs(dataView(i,j,k,l)-tmp)<=REL_TOL*std::abs(tmp));
2187              }              }
2188            }            }
2189          }          }
# Line 2175  void DataArrayViewTestCase::testReductio Line 2226  void DataArrayViewTestCase::testReductio
2226    
2227        // apply a reduction operation to this data point and check the results        // apply a reduction operation to this data point and check the results
2228        FMax fmax_func;        FMax fmax_func;
2229        assert(dataView.reductionOp(fmax_func,numeric_limits<double>::max()*-1)==p);        assert(std::abs(dataView.reductionOp(fmax_func,numeric_limits<double>::max()*-1)-p)<=REL_TOL*p);
2230    
2231        if (p<npoints-1) {        if (p<npoints-1) {
2232          dataView.incrOffset();          dataView.incrOffset();
# Line 2213  void DataArrayViewTestCase::testReductio Line 2264  void DataArrayViewTestCase::testReductio
2264    
2265        // apply a reduction operation to this data point and check the results        // apply a reduction operation to this data point and check the results
2266        FMin fmin_func;        FMin fmin_func;
2267        assert(dataView.reductionOp(fmin_func,numeric_limits<double>::max())==dataView.index(0,0));        assert(std::abs(dataView.reductionOp(fmin_func,numeric_limits<double>::max())-dataView.index(0,0))<=REL_TOL*std::abs(dataView.index(0,0)));
2268    
2269        if (p<npoints-1) {        if (p<npoints-1) {
2270          dataView.incrOffset();          dataView.incrOffset();

Legend:
Removed from v.468  
changed lines
  Added in v.1325

  ViewVC Help
Powered by ViewVC 1.1.26