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

Diff of /trunk/escript/test/DataTestCase.cpp

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

branches/ROBW_XPLATFORM/escript/test/DataTestCase.cpp revision 636 by robwdcock, Thu Mar 23 09:46:31 2006 UTC trunk/escript/test/DataTestCase.cpp revision 1026 by phornby, Tue Mar 13 08:25:00 2007 UTC
# Line 12  Line 12 
12   *                                                                           *   *                                                                           *
13   *****************************************************************************   *****************************************************************************
14  */  */
15    #include <iostream>
16    #if (defined _WIN32) && (defined __INTEL_COMPILER)
17    #include <mathimf.h>
18    #else
19    #include <math.h>
20    #endif
21    
22  #include "DataTestCase.h"  #include "DataTestCase.h"
23    
24  #include "FunctionSpace.h"  #include "escript/FunctionSpace.h"
25  #include "EsysException.h"  #include "esysUtils/EsysException.h"
26    
27  #include "Data.h"  #include "escript/Data.h"
28    
 #include <iostream>  
 #include <math.h>  
29    
30  using namespace std;  using namespace std;
31  using namespace CppUnitTest;  using namespace CppUnitTest;
# Line 746  void DataTestCase::testOperations() { Line 750  void DataTestCase::testOperations() {
750    
751    // test unary operations    // test unary operations
752    
753      double tmp;
754    cout << "\tTest Data::pow." << endl;    cout << "\tTest Data::pow." << endl;
755    Data power(3.0,shape,FunctionSpace(),true);    Data power(3.0,shape,FunctionSpace(),true);
756    resultEx.copy(baseEx.powD(power));    resultEx.copy(baseEx.powD(power));
# Line 753  void DataTestCase::testOperations() { Line 758  void DataTestCase::testOperations() {
758    resultTag.copy(baseTag.powD(power));    resultTag.copy(baseTag.powD(power));
759    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
760      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
761        assert(resultEx.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));        tmp=pow(dataView.index(i,j),3.0);
762        assert(resultCon.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));        assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
763        assert(resultTag.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));        assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
764          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
765      }      }
766    }    }
767    
# Line 763  void DataTestCase::testOperations() { Line 769  void DataTestCase::testOperations() {
769    resultEx.copy(baseEx.sin());    resultEx.copy(baseEx.sin());
770    resultCon.copy(baseCon.sin());    resultCon.copy(baseCon.sin());
771    resultTag.copy(baseTag.sin());    resultTag.copy(baseTag.sin());
772    assert(true);    for (int i=0;i<shape[0];i++) {
773        for (int j=0;j<shape[1];j++) {
774          tmp=sin((double)dataView.index(i,j));
775          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
776          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
777          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
778        }
779      }
780    
781    cout << "\tTest Data::cos." << endl;    cout << "\tTest Data::cos." << endl;
782    resultEx.copy(baseEx.cos());    resultEx.copy(baseEx.cos());
783    resultCon.copy(baseCon.cos());    resultCon.copy(baseCon.cos());
784    resultTag.copy(baseTag.cos());    resultTag.copy(baseTag.cos());
785    assert(true);    for (int i=0;i<shape[0];i++) {
786        for (int j=0;j<shape[1];j++) {
787          tmp=cos((double)dataView.index(i,j));
788          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
789          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
790          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
791        }
792      }
793    
794    cout << "\tTest Data::tan." << endl;    cout << "\tTest Data::tan." << endl;
795    resultEx.copy(baseEx.tan());    resultEx.copy(baseEx.tan());
796    resultCon.copy(baseCon.tan());    resultCon.copy(baseCon.tan());
797    resultTag.copy(baseTag.tan());    resultTag.copy(baseTag.tan());
798    assert(true);    for (int i=0;i<shape[0];i++) {
799        for (int j=0;j<shape[1];j++) {
800          tmp=tan((double)dataView.index(i,j));
801          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
802          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
803          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
804        }
805      }
806    
807    cout << "\tTest Data::asin." << endl;    cout << "\tTest Data::asin." << endl;
808    resultEx.copy(baseEx.asin());    resultEx.copy(baseEx.asin());
# Line 793  void DataTestCase::testOperations() { Line 820  void DataTestCase::testOperations() {
820    resultEx.copy(baseEx.atan());    resultEx.copy(baseEx.atan());
821    resultCon.copy(baseCon.atan());    resultCon.copy(baseCon.atan());
822    resultTag.copy(baseTag.atan());    resultTag.copy(baseTag.atan());
823    assert(true);    for (int i=0;i<shape[0];i++) {
824        for (int j=0;j<shape[1];j++) {
825          tmp=atan((double)dataView.index(i,j));
826          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
827          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
828          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
829        }
830      }
831    
832    cout << "\tTest Data::sinh." << endl;    cout << "\tTest Data::sinh." << endl;
833    resultEx.copy(baseEx.sinh());    resultEx.copy(baseEx.sinh());
834    resultCon.copy(baseCon.sinh());    resultCon.copy(baseCon.sinh());
835    resultTag.copy(baseTag.sinh());    resultTag.copy(baseTag.sinh());
836    assert(true);    for (int i=0;i<shape[0];i++) {
837        for (int j=0;j<shape[1];j++) {
838          tmp=sinh((double)dataView.index(i,j));
839          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
840          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
841          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
842        }
843      }
844    
845    cout << "\tTest Data::cosh." << endl;    cout << "\tTest Data::cosh." << endl;
846    resultEx.copy(baseEx.cosh());    resultEx.copy(baseEx.cosh());
847    resultCon.copy(baseCon.cosh());    resultCon.copy(baseCon.cosh());
848    resultTag.copy(baseTag.cosh());    resultTag.copy(baseTag.cosh());
849    assert(true);    for (int i=0;i<shape[0];i++) {
850        for (int j=0;j<shape[1];j++) {
851          tmp=cosh((double)dataView.index(i,j));
852          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
853          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
854          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
855        }
856      }
857    
858    cout << "\tTest Data::tanh." << endl;    cout << "\tTest Data::tanh." << endl;
859    resultEx.copy(baseEx.tanh());    resultEx.copy(baseEx.tanh());
860    resultCon.copy(baseCon.tanh());    resultCon.copy(baseCon.tanh());
861    resultTag.copy(baseTag.tanh());    resultTag.copy(baseTag.tanh());
862    assert(true);    for (int i=0;i<shape[0];i++) {
863        for (int j=0;j<shape[1];j++) {
864          tmp=tanh((double)dataView.index(i,j));
865          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
866          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
867          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
868        }
869      }
870    
871    cout << "\tTest Data::asinh." << endl;    cout << "\tTest Data::asinh." << endl;
872    resultEx.copy(baseEx.asinh());    resultEx.copy(baseEx.asinh());
# Line 841  void DataTestCase::testOperations() { Line 896  void DataTestCase::testOperations() {
896    resultEx.copy(baseEx.abs());    resultEx.copy(baseEx.abs());
897    resultCon.copy(baseCon.abs());    resultCon.copy(baseCon.abs());
898    resultTag.copy(baseTag.abs());    resultTag.copy(baseTag.abs());
899    assert(true);    for (int i=0;i<shape[0];i++) {
900        for (int j=0;j<shape[1];j++) {
901          tmp=abs((double)dataView.index(i,j));
902          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
903          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
904          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
905        }
906      }
907    
908    cout << "\tTest Data::sign." << endl;    cout << "\tTest Data::sign." << endl;
909    resultEx.copy(baseEx.sign());    resultEx.copy(baseEx.sign());
# Line 853  void DataTestCase::testOperations() { Line 915  void DataTestCase::testOperations() {
915    resultEx.copy(baseEx.exp());    resultEx.copy(baseEx.exp());
916    resultCon.copy(baseCon.exp());    resultCon.copy(baseCon.exp());
917    resultTag.copy(baseTag.exp());    resultTag.copy(baseTag.exp());
918    assert(true);    for (int i=0;i<shape[0];i++) {
919        for (int j=0;j<shape[1];j++) {
920          tmp=exp((double)dataView.index(i,j));
921          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
922          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
923          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
924        }
925      }
926    
927    cout << "\tTest Data::sqrt." << endl;    cout << "\tTest Data::sqrt." << endl;
928    resultEx.copy(baseEx.sqrt());    resultEx.copy(baseEx.sqrt());
929    resultCon.copy(baseCon.sqrt());    resultCon.copy(baseCon.sqrt());
930    resultTag.copy(baseTag.sqrt());    resultTag.copy(baseTag.sqrt());
931    assert(true);    for (int i=0;i<shape[0];i++) {
932        for (int j=0;j<shape[1];j++) {
933          tmp=sqrt((double)dataView.index(i,j));
934          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
935          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
936          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
937        }
938      }
939    
940    cout << "\tTest Data::neg." << endl;    cout << "\tTest Data::neg." << endl;
941    resultEx.copy(baseEx.neg());    resultEx.copy(baseEx.neg());
# Line 873  void DataTestCase::testOperations() { Line 949  void DataTestCase::testOperations() {
949    resultTag.copy(baseTag.pos());    resultTag.copy(baseTag.pos());
950    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
951      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
952        assert(resultEx.getPointDataView()(i,j) == dataView.index(i,j));        assert(std::abs(resultEx.getPointDataView()(i,j) - dataView.index(i,j)) <= REL_TOL*std::abs(dataView.index(i,j)));
953        assert(resultCon.getPointDataView()(i,j) == dataView.index(i,j));        assert(std::abs(resultCon.getPointDataView()(i,j) - dataView.index(i,j)) <= REL_TOL*std::abs(dataView.index(i,j)));
954        assert(resultTag.getPointDataView()(i,j) == dataView.index(i,j));        assert(std::abs(resultTag.getPointDataView()(i,j) - dataView.index(i,j)) <= REL_TOL*std::abs(dataView.index(i,j)));
955      }      }
956    }    }
957    
958    // test reduction operations    // test reduction operations
959    
960    cout << "\tTest Data::Lsup." << endl;    cout << "\tTest Data::Lsup." << endl;
961    assert(baseEx.Lsup() == 5);    assert(std::abs(baseEx.Lsup() - 5) <= REL_TOL*5);
962    assert(baseCon.Lsup() == 5);    assert(std::abs(baseCon.Lsup() - 5) <= REL_TOL*5);
963    assert(baseTag.Lsup() == 5);    assert(std::abs(baseTag.Lsup() - 5) <= REL_TOL*5);
964    
965    cout << "\tTest Data::sup." << endl;    cout << "\tTest Data::sup." << endl;
966    assert(baseEx.sup() == 5);    assert(std::abs(baseEx.sup() - 5) <= REL_TOL*5);
967    assert(baseCon.sup() == 5);    assert(std::abs(baseCon.sup() - 5) <= REL_TOL*5);
968    assert(baseTag.sup() == 5);    assert(std::abs(baseTag.sup() - 5) <= REL_TOL*5);
969    
970    cout << "\tTest Data::inf." << endl;    cout << "\tTest Data::inf." << endl;
971    assert(baseEx.inf() == 0);    assert(std::abs(baseEx.inf() - 0) <= REL_TOL*0);
972    assert(baseCon.inf() == 0);    assert(std::abs(baseCon.inf() - 0) <= REL_TOL*0);
973    assert(baseTag.inf() == 0);    assert(std::abs(baseTag.inf() - 0) <= REL_TOL*0);
974    
975    // test data-point reduction operations    // test data-point reduction operations
976    
# Line 902  void DataTestCase::testOperations() { Line 978  void DataTestCase::testOperations() {
978    resultEx.copy(baseEx.minval());    resultEx.copy(baseEx.minval());
979    resultCon.copy(baseCon.minval());    resultCon.copy(baseCon.minval());
980    resultTag.copy(baseTag.minval());    resultTag.copy(baseTag.minval());
981    assert(resultEx.getPointDataView()() == 0);    assert(std::abs(resultEx.getPointDataView()() - 0) <= REL_TOL*0);
982    assert(resultCon.getPointDataView()() == 0);    assert(std::abs(resultCon.getPointDataView()() - 0) <= REL_TOL*0);
983    assert(resultTag.getPointDataView()() == 0);    assert(std::abs(resultTag.getPointDataView()() - 0) <= REL_TOL*0);
984    
985    cout << "\tTest Data::maxval." << endl;    cout << "\tTest Data::maxval." << endl;
986    resultEx.copy(baseEx.maxval());    resultEx.copy(baseEx.maxval());
987    resultCon.copy(baseCon.maxval());    resultCon.copy(baseCon.maxval());
988    resultTag.copy(baseTag.maxval());    resultTag.copy(baseTag.maxval());
989    assert(resultEx.getPointDataView()() == 5);    assert(std::abs(resultEx.getPointDataView()() - 5) <= REL_TOL*5);
990    assert(resultCon.getPointDataView()() == 5);    assert(std::abs(resultCon.getPointDataView()() - 5) <= REL_TOL*5);
991    assert(resultTag.getPointDataView()() == 5);    assert(std::abs(resultTag.getPointDataView()() - 5) <= REL_TOL*5);
   
   cout << "\tTest Data::trace." << endl;  
   resultEx.copy(baseEx.trace());  
   resultCon.copy(baseCon.trace());  
   resultTag.copy(baseTag.trace());  
   assert(resultEx.getPointDataView()() == 15);  
   assert(resultCon.getPointDataView()() == 15);  
   assert(resultTag.getPointDataView()() == 15);  
992    
993  }  }
994    
 void DataTestCase::testRefValue() {  
   
   //  
   // Note - this test can't be run as boost::python::numeric::array  
   // objects can only be created and used from within a python thread!  
   //  
   
   cout << endl;  
   
   cout << "\tTest Data object RefValue methods." << endl;  
   
   // Create three Data object - DataExpanded, DataConstant and DataEmpty  
   DataArrayView::ShapeType viewShape;  
   viewShape.push_back(3);  
   DataArrayView::ValueType viewData(3);  
   for (int i=0;i<viewShape[0];++i) {  
     viewData[i]=i;  
   }  
   DataArrayView myView(viewData,viewShape);  
   
   bool expanded=true;  
   
   Data expandedData(myView,FunctionSpace(),expanded);  
   Data constantData(myView);  
   Data emptyData;  
   
   assert(expandedData.isExpanded());  
   assert(constantData.isConstant());  
   assert(emptyData.isEmpty());  
   
   // Check assertions are thrown for RefValue methods on DataEmpty  
   
   int ref = 0;  
   boost::python::numeric::array num_array(1.0);  
   
   try {  
       emptyData.getRefValue(ref,num_array);  
       assert(false);  
   }  
   catch (EsysException& e) {  
       assert(true);  
   }  
   try {  
       emptyData.setRefValue(ref,num_array);  
       assert(false);  
   }  
   catch (EsysException& e) {  
       assert(true);  
   }  
   
   // Check assertions are thrown for RefValue methods on DataConstant  
   try {  
       constantData.getRefValue(ref,num_array);  
       assert(false);  
   }  
   catch (EsysException& e) {  
       assert(true);  
   }  
   try {  
       constantData.setRefValue(ref,num_array);  
       assert(false);  
   }  
   catch (EsysException& e) {  
       assert(true);  
   }  
   
   // Check calls to RefValue methods on DataExpanded  
   expandedData.getRefValue(ref,num_array);  
   expandedData.setRefValue(ref,num_array);  
   
 }  
995    
996  void DataTestCase::testMemAlloc() {  void DataTestCase::testMemAlloc() {
997    

Legend:
Removed from v.636  
changed lines
  Added in v.1026

  ViewVC Help
Powered by ViewVC 1.1.26