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

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

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

revision 1751 by jfenwick, Wed Sep 3 04:56:50 2008 UTC revision 1752 by jfenwick, Fri Sep 5 06:26:29 2008 UTC
# Line 153  void DataTestCase::testSlicing() { Line 153  void DataTestCase::testSlicing() {
153    {    {
154    
155      cout << "\tTest get-slicing DataTagged" << endl;      cout << "\tTest get-slicing DataTagged" << endl;
   
156      //      //
157      // create a DataTagged with a default value only      // create a DataTagged with a default value only
158    
# Line 163  void DataTestCase::testSlicing() { Line 162  void DataTestCase::testSlicing() {
162      Data data(1.3,viewShape,FunctionSpace(),false);      Data data(1.3,viewShape,FunctionSpace(),false);
163      data.tag();      data.tag();
164      data.getDataAtOffset(data.getDataOffset(0,0)+getRelIndex(viewShape,0,0))=1.0;      data.getDataAtOffset(data.getDataOffset(0,0)+getRelIndex(viewShape,0,0))=1.0;
165      data.getDataAtOffset(data.getDataOffset(0,0)+getRelIndex(viewShape,1,1))=1.0;        data.getDataAtOffset(data.getDataOffset(0,0)+getRelIndex(viewShape,1,1))=2.0;  
166  //     data.getDataPoint(0,0)(0,0)=1.0;  //     data.getDataPoint(0,0)(0,0)=1.0;
167  //     data.getDataPoint(0,0)(1,1)=2.0;  //     data.getDataPoint(0,0)(1,1)=2.0;
168    
169      //cout << data.toString() << endl;      //cout << data.toString() << endl;
   
170      //      //
171      // create a scalar slice      // create a scalar slice
172    
# Line 177  void DataTestCase::testSlicing() { Line 175  void DataTestCase::testSlicing() {
175      region.push_back(DataTypes::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
176    
177      Data slice1(data.getSlice(region));      Data slice1(data.getSlice(region));
   
178      //cout << slice1.toString() << endl;      //cout << slice1.toString() << endl;
179    
180      assert(slice1.isTagged());      assert(slice1.isTagged());
181      assert(slice1.getDataPointRank()==0);      assert(slice1.getDataPointRank()==0);
182      assert(slice1.getDataPoint(0,0)==1.0);      assert(slice1.getDataPoint(0,0)==1.0);
   
183      //      //
184      // create a rank 2 slice with one value      // create a rank 2 slice with one value
185    
# Line 197  void DataTestCase::testSlicing() { Line 193  void DataTestCase::testSlicing() {
193    
194      assert(slice2.isTagged());      assert(slice2.isTagged());
195      assert(slice2.getDataPointRank()==2);      assert(slice2.getDataPointRank()==2);
196      assert(slice2.getDataAtOffset(slice2.getDataOffset(0,0)+getRelIndex(slice2.getDataPointShape(),1,1))==1.0);  
197        assert(slice2.getDataAtOffset(slice2.getDataOffset(0,0)+getRelIndex(slice2.getDataPointShape(),0,0))==1.0);
198    
199      //      //
200      // create a rank 2 slice with four values      // create a rank 2 slice with four values
# Line 244  void DataTestCase::testSlicing() { Line 241  void DataTestCase::testSlicing() {
241      assert(slice4.isTagged());      assert(slice4.isTagged());
242      assert(slice4.getDataPointRank()==2);      assert(slice4.getDataPointRank()==2);
243      assert(getRef(slice4,0,0,0,0)==0);      assert(getRef(slice4,0,0,0,0)==0);
244      assert(getRef(slice3,0,0,0,1)==2);      assert(getRef(slice4,0,0,0,1)==2);
245      assert(getRef(slice3,0,0,0,2)==4);      assert(getRef(slice4,0,0,0,2)==4);
246      assert(getRef(slice3,0,0,1,0)==1);      assert(getRef(slice4,0,0,1,0)==1);
247      assert(getRef(slice3,0,0,1,1)==3);      assert(getRef(slice4,0,0,1,1)==3);
248      assert(getRef(slice3,0,0,1,2)==5);      assert(getRef(slice4,0,0,1,2)==5);
249    
250    }    }
251    
# Line 459  void DataTestCase::testAll() { Line 456  void DataTestCase::testAll() {
456    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
457      viewData[i]=i;      viewData[i]=i;
458    }    }
459    DataArrayView myView(viewData,viewShape);  //   DataArrayView myView(viewData,viewShape);
460    
461    bool expanded=true;    bool expanded=true;
462    Data exData(myView,FunctionSpace(),expanded);    Data exData(viewData,viewShape,FunctionSpace(),expanded);
463    Data cData(myView);  //   Data cData(myView);
464      Data cData(viewData,viewShape,FunctionSpace());
465    Data result;    Data result;
466    
467    assert(exData.isExpanded());    assert(exData.isExpanded());
# Line 488  void DataTestCase::testMore() { Line 486  void DataTestCase::testMore() {
486    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
487      viewData[i]=i;      viewData[i]=i;
488    }    }
489    DataArrayView myView(viewData,viewShape);  //   DataArrayView myView(viewData,viewShape);
490    
491    bool expanded=true;    bool expanded=true;
492    Data exData(myView,FunctionSpace(),expanded);    Data exData(viewData,viewShape,FunctionSpace(),expanded);
493    Data cData(myView);    Data cData(viewData,viewShape);
494    Data result;    Data result;
495    
496    assert(exData.isExpanded());    assert(exData.isExpanded());
# Line 534  void DataTestCase::testDataConstant() { Line 532  void DataTestCase::testDataConstant() {
532    for (int i=0;i<DataTypes::noValues(viewShape);++i) {    for (int i=0;i<DataTypes::noValues(viewShape);++i) {
533      viewData[i]=i;      viewData[i]=i;
534    }    }
535    DataArrayView myView(viewData,viewShape);  //   DataArrayView myView(viewData,viewShape);
536    
537    Data left(myView);    Data left(viewData,viewShape);
538    Data right(myView);    Data right(viewData,viewShape);
539    Data result;    Data result;
540    
541    cout << "\tTest some basic operations" << endl;    cout << "\tTest some basic operations" << endl;
# Line 644  void DataTestCase::testDataTagged() { Line 642  void DataTestCase::testDataTagged() {
642    
643      assert(myData.getLength()==6);      assert(myData.getLength()==6);
644    
645        int offset=myData.getDataOffset(0,0);
646  //    myDataView = myData.getDataPoint(0,0);  //    myDataView = myData.getDataPoint(0,0);
647  //     assert(myDataView==eTwoView);  //     assert(myDataView==eTwoView);
648  //     assert(!myDataView.isEmpty());  //     assert(!myDataView.isEmpty());
649  //     assert(myDataView.getOffset()==3);      assert(offset==3);
650      assert(myData.getDataPointRank()==1);      assert(myData.getDataPointRank()==1);
651      assert(myData.getNoValues()==3);      assert(myData.getNoValues()==3);
652  //    assert(myDataView.getShape().size()==1);  //    assert(myDataView.getShape().size()==1);
653      assert(myData.getDataAtOffset(0)==2);  
654      assert(myData.getDataAtOffset(1)==3);      assert(myData.getDataAtOffset(offset+0)==2);
655      assert(myData.getDataAtOffset(2)==4);      assert(myData.getDataAtOffset(offset+1)==3);
656        assert(myData.getDataAtOffset(offset+2)==4);
657    
658      sampleData=myData.getSampleDataByTag(1);      sampleData=myData.getSampleDataByTag(1);
659      for (int i=0; i<myData.getNoValues(); i++) {      for (int i=0; i<myData.getNoValues(); i++) {
# Line 771  void DataTestCase::testOperations() { Line 771  void DataTestCase::testOperations() {
771    DataTypes::ValueType data(DataTypes::noValues(shape),0);    DataTypes::ValueType data(DataTypes::noValues(shape),0);
772    
773    // construct DataArrayView    // construct DataArrayView
774    DataArrayView dataView(data,shape);  //   DataArrayView dataView(data,shape);
775    
776    // assign values to the data    // assign values to the data
777    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
778      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
779        dataView(i,j)=dataView.index(i,j);        data[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j);
780      }      }
781    }    }
782    
783    Data baseEx(dataView,FunctionSpace(),true);    Data baseEx(data,shape,FunctionSpace(),true);
784    Data baseCon(dataView,FunctionSpace(),false);    Data baseCon(data,shape,FunctionSpace(),false);
785    Data baseTag(dataView,FunctionSpace(),false);    Data baseTag(data,shape,FunctionSpace(),false);
786    baseTag.tag();    baseTag.tag();
787    
788    assert(baseEx.isExpanded());    assert(baseEx.isExpanded());
# Line 803  void DataTestCase::testOperations() { Line 803  void DataTestCase::testOperations() {
803    resultTag.copy(baseTag.powD(power));    resultTag.copy(baseTag.powD(power));
804    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
805      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
806        tmp=pow((double)dataView.index(i,j),(double)3.0);        tmp=pow((double)data[getRelIndex(shape,i,j)],(double)3.0);
807        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
808        assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));
809        assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));
# Line 816  void DataTestCase::testOperations() { Line 816  void DataTestCase::testOperations() {
816    resultTag.copy(baseTag.sin());    resultTag.copy(baseTag.sin());
817    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
818      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
819        tmp=sin((double)dataView.index(i,j));        tmp=sin((double)data[getRelIndex(shape,i,j)]);
820        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
821        assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));
822        assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));
# Line 829  void DataTestCase::testOperations() { Line 829  void DataTestCase::testOperations() {
829    resultTag.copy(baseTag.cos());    resultTag.copy(baseTag.cos());
830    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
831      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
832        tmp=cos((double)dataView.index(i,j));        tmp=cos((double)data[getRelIndex(shape,i,j)]);
833        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
834        assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));
835        assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));
# Line 842  void DataTestCase::testOperations() { Line 842  void DataTestCase::testOperations() {
842    resultTag.copy(baseTag.tan());    resultTag.copy(baseTag.tan());
843    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
844      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
845        tmp=tan((double)dataView.index(i,j));        tmp=tan((double)data[getRelIndex(shape,i,j)]);
846        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
847        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
848        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
# Line 867  void DataTestCase::testOperations() { Line 867  void DataTestCase::testOperations() {
867    resultTag.copy(baseTag.atan());    resultTag.copy(baseTag.atan());
868    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
869      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
870        tmp=atan((double)dataView.index(i,j));        tmp=atan((double)data[getRelIndex(shape,i,j)]);
871        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
872        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
873        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
# Line 880  void DataTestCase::testOperations() { Line 880  void DataTestCase::testOperations() {
880    resultTag.copy(baseTag.sinh());    resultTag.copy(baseTag.sinh());
881    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
882      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
883        tmp=sinh((double)dataView.index(i,j));        tmp=sinh((double)data[getRelIndex(shape,i,j)]);
884        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
885        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
886        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
# Line 893  void DataTestCase::testOperations() { Line 893  void DataTestCase::testOperations() {
893    resultTag.copy(baseTag.cosh());    resultTag.copy(baseTag.cosh());
894    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
895      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
896        tmp=cosh((double)dataView.index(i,j));        tmp=cosh((double)data[getRelIndex(shape,i,j)]);
897        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
898        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
899        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
# Line 906  void DataTestCase::testOperations() { Line 906  void DataTestCase::testOperations() {
906    resultTag.copy(baseTag.tanh());    resultTag.copy(baseTag.tanh());
907    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
908      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
909        tmp=tanh((double)dataView.index(i,j));        tmp=tanh((double)data[getRelIndex(shape,i,j)]);
910        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
911        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
912        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
# Line 943  void DataTestCase::testOperations() { Line 943  void DataTestCase::testOperations() {
943    resultTag.copy(baseTag.abs());    resultTag.copy(baseTag.abs());
944    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
945      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
946        tmp=abs((double)dataView.index(i,j));        tmp=abs((double)data[getRelIndex(shape,i,j)]);
947        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
948        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
949        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
# Line 962  void DataTestCase::testOperations() { Line 962  void DataTestCase::testOperations() {
962    resultTag.copy(baseTag.exp());    resultTag.copy(baseTag.exp());
963    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
964      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
965        tmp=exp((double)dataView.index(i,j));        tmp=exp((double)data[getRelIndex(shape,i,j)]);
966        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
967        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
968        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
# Line 975  void DataTestCase::testOperations() { Line 975  void DataTestCase::testOperations() {
975    resultTag.copy(baseTag.sqrt());    resultTag.copy(baseTag.sqrt());
976    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
977      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
978        tmp=sqrt((double)dataView.index(i,j));        tmp=sqrt((double)data[getRelIndex(shape,i,j)]);
979        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
980        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
981        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));        assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
# Line 994  void DataTestCase::testOperations() { Line 994  void DataTestCase::testOperations() {
994    resultTag.copy(baseTag.pos());    resultTag.copy(baseTag.pos());
995    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
996      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
997        assert(std::abs(getRef(resultEx,i,j) - dataView.index(i,j)) <= REL_TOL*std::abs(dataView.index(i,j)));        assert(std::abs(getRef(resultEx,i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
998        assert(std::abs(getRef(resultCon,i,j) - dataView.index(i,j)) <= REL_TOL*std::abs(dataView.index(i,j)));        assert(std::abs(getRef(resultCon,i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
999        assert(std::abs(getRef(resultTag,i,j) - dataView.index(i,j)) <= REL_TOL*std::abs(dataView.index(i,j)));        assert(std::abs(getRef(resultTag,i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
1000      }      }
1001    }    }
1002    

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

  ViewVC Help
Powered by ViewVC 1.1.26