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

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

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

revision 1751 by jfenwick, Tue Aug 12 01:13:16 2008 UTC revision 1752 by jfenwick, Fri Sep 5 06:26:29 2008 UTC
# Line 20  Line 20 
20  #endif  #endif
21    
22  #include "escript/DataExpanded.h"  #include "escript/DataExpanded.h"
23  #include "escript/DataArrayView.h"  // #include "escript/DataArrayView.h"
24  #include "escript/DataAlgorithm.h"  #include "escript/DataAlgorithm.h"
25  #include "DataAlgorithmAdapterTestCase.h"  #include "DataAlgorithmAdapterTestCase.h"
26    #include "escript/DataTypes.h"
27    
28  #include <iostream>  #include <iostream>
29  #include <algorithm>  #include <algorithm>
# Line 31  Line 32 
32  using namespace CppUnitTest;  using namespace CppUnitTest;
33  using namespace std;  using namespace std;
34  using namespace escript;  using namespace escript;
35    using namespace escript::DataTypes;
36    
37  void DataAlgorithmAdapterTestCase::setUp() {  void DataAlgorithmAdapterTestCase::setUp() {
38    //    //
# Line 44  void DataAlgorithmAdapterTestCase::tearD Line 46  void DataAlgorithmAdapterTestCase::tearD
46    
47  }  }
48    
49    
50    namespace
51    {
52    
53    ValueType::reference
54    getSRef(DataAbstract& data,int sample, int point)
55    {
56       return data.getVector()[data.getPointOffset(sample,point)];
57    }
58    
59    
60    }
61    
62  void DataAlgorithmAdapterTestCase::testAll() {  void DataAlgorithmAdapterTestCase::testAll() {
63    
64    cout << endl;    cout << endl;
# Line 161  void DataAlgorithmAdapterTestCase::testA Line 176  void DataAlgorithmAdapterTestCase::testA
176      DataTypes::ValueType dataArray(DataTypes::noValues(shape),0);      DataTypes::ValueType dataArray(DataTypes::noValues(shape),0);
177    
178      // construct DataArrayView      // construct DataArrayView
179      DataArrayView dataView(dataArray,shape);  //     DataArrayView dataView(dataArray,shape);
180    
181      // assign values to the data point      // assign values to the data point
182      for (int i=0;i<shape[0];i++) {      for (int i=0;i<shape[0];i++) {
183        for (int j=0;j<shape[1];j++) {        for (int j=0;j<shape[1];j++) {
184          dataView(i,j)=dataView.index(i,j);          dataArray[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j);
185        }        }
186      }      }
187    
188      // create a few Data objects from the created DataArrayView      // create a few Data objects from the created DataArrayView
189      DataExpanded dataExp(dataView,FunctionSpace());      DataExpanded dataExp(FunctionSpace(),shape,dataArray);
190      DataConstant dataCon(dataView,FunctionSpace());      DataConstant dataCon(FunctionSpace(),shape,dataArray);
191      DataTagged   dataTag(dataCon);      DataTagged   dataTag(dataCon);
192    
193      // test algorithm on DataExpanded      // test algorithm on DataExpanded
# Line 212  void DataAlgorithmAdapterTestCase::testD Line 227  void DataAlgorithmAdapterTestCase::testD
227      DataTypes::ValueType dataArray2(DataTypes::noValues(shape2),0);      DataTypes::ValueType dataArray2(DataTypes::noValues(shape2),0);
228    
229      // construct DataArrayViews      // construct DataArrayViews
230      DataArrayView dataView(dataArray,shape);  //     DataArrayView dataView(dataArray,shape);
231      DataArrayView dataView2(dataArray2,shape2);  //     DataArrayView dataView2(dataArray2,shape2);
232    
233      // assign values to the data point      // assign values to the data point
234      for (int i=0;i<shape[0];i++) {      for (int i=0;i<shape[0];i++) {
235        for (int j=0;j<shape[1];j++) {        for (int j=0;j<shape[1];j++) {
236          dataView(i,j)=dataView.index(i,j);          dataArray[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j);
237        }        }
238      }      }
239    
240      // create a few Data objects from the created DataArrayViews      // create a few Data objects from the created DataArrayViews
241      DataExpanded dataExp(dataView,FunctionSpace());      DataExpanded dataExp(FunctionSpace(),shape,dataArray);
242      DataConstant dataCon(dataView,FunctionSpace());      DataConstant dataCon(FunctionSpace(),shape,dataArray);
243      DataTagged   dataTag(dataCon);      DataTagged   dataTag(dataCon);
244    
245      // and create Data objects to receive the results of the dp_algorithm calls      // and create Data objects to receive the results of the dp_algorithm calls
246      DataExpanded dataExp2(dataView2,FunctionSpace());      DataExpanded dataExp2(FunctionSpace(),shape2,dataArray2);
247      DataConstant dataCon2(dataView2,FunctionSpace());      DataConstant dataCon2(FunctionSpace(),shape2,dataArray2);
248      DataTagged   dataTag2(dataCon2);      DataTagged   dataTag2(dataCon2);
249    
250      // test dp_algorithm on DataExpanded      // test dp_algorithm on DataExpanded
251      FMin fmin_func;      FMin fmin_func;
252      escript::dp_algorithm(dataExp,dataExp2,fmin_func,numeric_limits<double>::max());      escript::dp_algorithm(dataExp,dataExp2,fmin_func,numeric_limits<double>::max());
253      assert(std::abs(dataExp2.getDataPoint(0,0)()-0)<=REL_TOL*0);      assert(std::abs(getSRef(dataExp2,0,0)-0)<=REL_TOL*0);
254      FMax fmax_func;      FMax fmax_func;
255      escript::dp_algorithm(dataExp,dataExp2,fmax_func,numeric_limits<double>::max()*-1);      escript::dp_algorithm(dataExp,dataExp2,fmax_func,numeric_limits<double>::max()*-1);
256      assert(std::abs(dataExp2.getDataPoint(0,0)()-5)<=REL_TOL*5);      assert(std::abs(getSRef(dataExp2,0,0)-5)<=REL_TOL*5);
257    
258      // test dp_algorithm on DataTagged      // test dp_algorithm on DataTagged
259      escript::dp_algorithm(dataTag,dataTag2,fmin_func,numeric_limits<double>::max());      escript::dp_algorithm(dataTag,dataTag2,fmin_func,numeric_limits<double>::max());
260      assert(std::abs(dataTag2.getDataPoint(0,0)()-0)<=REL_TOL*0);      assert(std::abs(getSRef(dataTag2,0,0)-0)<=REL_TOL*0);
261      escript::dp_algorithm(dataTag,dataTag2,fmax_func,numeric_limits<double>::max()*-1);      escript::dp_algorithm(dataTag,dataTag2,fmax_func,numeric_limits<double>::max()*-1);
262      assert(std::abs(dataTag2.getDataPoint(0,0)()-5)<=REL_TOL*5);      assert(std::abs(getSRef(dataTag2,0,0)-5)<=REL_TOL*5);
263    
264      // test dp_algorithm on DataConstant      // test dp_algorithm on DataConstant
265      escript::dp_algorithm(dataCon,dataCon2,fmin_func,numeric_limits<double>::max());      escript::dp_algorithm(dataCon,dataCon2,fmin_func,numeric_limits<double>::max());
266      assert(std::abs(dataCon2.getDataPoint(0,0)()-0)<=REL_TOL*0);      assert(std::abs(getSRef(dataCon2,0,0)-0)<=REL_TOL*0);
267      escript::dp_algorithm(dataCon,dataCon2,fmax_func,numeric_limits<double>::max()*-1);      escript::dp_algorithm(dataCon,dataCon2,fmax_func,numeric_limits<double>::max()*-1);
268      assert(std::abs(dataCon2.getDataPoint(0,0)()-5)<=REL_TOL*5);      assert(std::abs(getSRef(dataCon2,0,0)-5)<=REL_TOL*5);
269    
270    }    }
271    

Legend:
Removed from v.1751  
changed lines
  Added in v.1752

  ViewVC Help
Powered by ViewVC 1.1.26