/[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/Data/DataTestCase.cpp revision 622 by robwdcock, Wed Mar 22 14:00:08 2006 UTC trunk/escript/test/DataTestCase.cpp revision 1312 by ksteube, Mon Sep 24 06:18:44 2007 UTC
# Line 1  Line 1 
 // $Id$  
 /*  
  *****************************************************************************  
  *                                                                           *  
  *       COPYRIGHT  ACcESS  -  All Rights Reserved                           *  
  *                                                                           *  
  * This software is the property of ACcESS. No part of this code             *  
  * may be copied in any form or by any means without the expressed written   *  
  * consent of ACcESS.  Copying, use or modification of this software         *  
  * by any unauthorised person is illegal unless that person has a software   *  
  * license agreement with ACcESS.                                            *  
  *                                                                           *  
  *****************************************************************************  
 */  
1    
2  #include "DataTestCase.h"  /* $Id$ */
   
 #include "FunctionSpace.h"  
 #include "EsysException.h"  
3    
4  #include "Data.h"  /*******************************************************
5     *
6     *           Copyright 2003-2007 by ACceSS MNRF
7     *       Copyright 2007 by University of Queensland
8     *
9     *                http://esscc.uq.edu.au
10     *        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     *******************************************************/
15    
16  #include <iostream>  #include <iostream>
17    #if (defined _WIN32) && (defined __INTEL_COMPILER)
18    #include <mathimf.h>
19    #else
20  #include <math.h>  #include <math.h>
21    #endif
22    
23    #include "DataTestCase.h"
24    
25    #include "escript/FunctionSpace.h"
26    #include "esysUtils/EsysException.h"
27    
28    #include "escript/Data.h"
29    
30    
31  using namespace std;  using namespace std;
32  using namespace CppUnitTest;  using namespace CppUnitTest;
# Line 746  void DataTestCase::testOperations() { Line 751  void DataTestCase::testOperations() {
751    
752    // test unary operations    // test unary operations
753    
754      double tmp;
755    cout << "\tTest Data::pow." << endl;    cout << "\tTest Data::pow." << endl;
756    Data power(3.0,shape,FunctionSpace(),true);    Data power(3.0,shape,FunctionSpace(),true);
757    resultEx.copy(baseEx.powD(power));    resultEx.copy(baseEx.powD(power));
# Line 753  void DataTestCase::testOperations() { Line 759  void DataTestCase::testOperations() {
759    resultTag.copy(baseTag.powD(power));    resultTag.copy(baseTag.powD(power));
760    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
761      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
762        assert(resultEx.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));        tmp=pow(dataView.index(i,j),3.0);
763        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));
764        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));
765          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
766      }      }
767    }    }
768    
# Line 763  void DataTestCase::testOperations() { Line 770  void DataTestCase::testOperations() {
770    resultEx.copy(baseEx.sin());    resultEx.copy(baseEx.sin());
771    resultCon.copy(baseCon.sin());    resultCon.copy(baseCon.sin());
772    resultTag.copy(baseTag.sin());    resultTag.copy(baseTag.sin());
773    assert(true);    for (int i=0;i<shape[0];i++) {
774        for (int j=0;j<shape[1];j++) {
775          tmp=sin((double)dataView.index(i,j));
776          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
777          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
778          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
779        }
780      }
781    
782    cout << "\tTest Data::cos." << endl;    cout << "\tTest Data::cos." << endl;
783    resultEx.copy(baseEx.cos());    resultEx.copy(baseEx.cos());
784    resultCon.copy(baseCon.cos());    resultCon.copy(baseCon.cos());
785    resultTag.copy(baseTag.cos());    resultTag.copy(baseTag.cos());
786    assert(true);    for (int i=0;i<shape[0];i++) {
787        for (int j=0;j<shape[1];j++) {
788          tmp=cos((double)dataView.index(i,j));
789          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
790          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
791          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
792        }
793      }
794    
795    cout << "\tTest Data::tan." << endl;    cout << "\tTest Data::tan." << endl;
796    resultEx.copy(baseEx.tan());    resultEx.copy(baseEx.tan());
797    resultCon.copy(baseCon.tan());    resultCon.copy(baseCon.tan());
798    resultTag.copy(baseTag.tan());    resultTag.copy(baseTag.tan());
799    assert(true);    for (int i=0;i<shape[0];i++) {
800        for (int j=0;j<shape[1];j++) {
801          tmp=tan((double)dataView.index(i,j));
802          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
803          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
804          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
805        }
806      }
807    
808    cout << "\tTest Data::asin." << endl;    cout << "\tTest Data::asin." << endl;
809    resultEx.copy(baseEx.asin());    resultEx.copy(baseEx.asin());
# Line 793  void DataTestCase::testOperations() { Line 821  void DataTestCase::testOperations() {
821    resultEx.copy(baseEx.atan());    resultEx.copy(baseEx.atan());
822    resultCon.copy(baseCon.atan());    resultCon.copy(baseCon.atan());
823    resultTag.copy(baseTag.atan());    resultTag.copy(baseTag.atan());
824    assert(true);    for (int i=0;i<shape[0];i++) {
825        for (int j=0;j<shape[1];j++) {
826          tmp=atan((double)dataView.index(i,j));
827          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
828          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
829          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
830        }
831      }
832    
833    cout << "\tTest Data::sinh." << endl;    cout << "\tTest Data::sinh." << endl;
834    resultEx.copy(baseEx.sinh());    resultEx.copy(baseEx.sinh());
835    resultCon.copy(baseCon.sinh());    resultCon.copy(baseCon.sinh());
836    resultTag.copy(baseTag.sinh());    resultTag.copy(baseTag.sinh());
837    assert(true);    for (int i=0;i<shape[0];i++) {
838        for (int j=0;j<shape[1];j++) {
839          tmp=sinh((double)dataView.index(i,j));
840          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
841          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
842          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
843        }
844      }
845    
846    cout << "\tTest Data::cosh." << endl;    cout << "\tTest Data::cosh." << endl;
847    resultEx.copy(baseEx.cosh());    resultEx.copy(baseEx.cosh());
848    resultCon.copy(baseCon.cosh());    resultCon.copy(baseCon.cosh());
849    resultTag.copy(baseTag.cosh());    resultTag.copy(baseTag.cosh());
850    assert(true);    for (int i=0;i<shape[0];i++) {
851        for (int j=0;j<shape[1];j++) {
852          tmp=cosh((double)dataView.index(i,j));
853          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
854          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
855          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
856        }
857      }
858    
859    cout << "\tTest Data::tanh." << endl;    cout << "\tTest Data::tanh." << endl;
860    resultEx.copy(baseEx.tanh());    resultEx.copy(baseEx.tanh());
861    resultCon.copy(baseCon.tanh());    resultCon.copy(baseCon.tanh());
862    resultTag.copy(baseTag.tanh());    resultTag.copy(baseTag.tanh());
863    assert(true);    for (int i=0;i<shape[0];i++) {
864        for (int j=0;j<shape[1];j++) {
865          tmp=tanh((double)dataView.index(i,j));
866          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
867          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
868          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
869        }
870      }
871    
872    cout << "\tTest Data::asinh." << endl;    cout << "\tTest Data::asinh." << endl;
873    resultEx.copy(baseEx.asinh());    resultEx.copy(baseEx.asinh());
# Line 841  void DataTestCase::testOperations() { Line 897  void DataTestCase::testOperations() {
897    resultEx.copy(baseEx.abs());    resultEx.copy(baseEx.abs());
898    resultCon.copy(baseCon.abs());    resultCon.copy(baseCon.abs());
899    resultTag.copy(baseTag.abs());    resultTag.copy(baseTag.abs());
900    assert(true);    for (int i=0;i<shape[0];i++) {
901        for (int j=0;j<shape[1];j++) {
902          tmp=abs((double)dataView.index(i,j));
903          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
904          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
905          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
906        }
907      }
908    
909    cout << "\tTest Data::sign." << endl;    cout << "\tTest Data::sign." << endl;
910    resultEx.copy(baseEx.sign());    resultEx.copy(baseEx.sign());
# Line 853  void DataTestCase::testOperations() { Line 916  void DataTestCase::testOperations() {
916    resultEx.copy(baseEx.exp());    resultEx.copy(baseEx.exp());
917    resultCon.copy(baseCon.exp());    resultCon.copy(baseCon.exp());
918    resultTag.copy(baseTag.exp());    resultTag.copy(baseTag.exp());
919    assert(true);    for (int i=0;i<shape[0];i++) {
920        for (int j=0;j<shape[1];j++) {
921          tmp=exp((double)dataView.index(i,j));
922          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
923          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
924          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
925        }
926      }
927    
928    cout << "\tTest Data::sqrt." << endl;    cout << "\tTest Data::sqrt." << endl;
929    resultEx.copy(baseEx.sqrt());    resultEx.copy(baseEx.sqrt());
930    resultCon.copy(baseCon.sqrt());    resultCon.copy(baseCon.sqrt());
931    resultTag.copy(baseTag.sqrt());    resultTag.copy(baseTag.sqrt());
932    assert(true);    for (int i=0;i<shape[0];i++) {
933        for (int j=0;j<shape[1];j++) {
934          tmp=sqrt((double)dataView.index(i,j));
935          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
936          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
937          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
938        }
939      }
940    
941    cout << "\tTest Data::neg." << endl;    cout << "\tTest Data::neg." << endl;
942    resultEx.copy(baseEx.neg());    resultEx.copy(baseEx.neg());
# Line 873  void DataTestCase::testOperations() { Line 950  void DataTestCase::testOperations() {
950    resultTag.copy(baseTag.pos());    resultTag.copy(baseTag.pos());
951    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
952      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
953        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)));
954        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)));
955        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)));
956      }      }
957    }    }
958    
959    // test reduction operations    // test reduction operations
960    
961    cout << "\tTest Data::Lsup." << endl;    cout << "\tTest Data::Lsup." << endl;
962    assert(baseEx.Lsup() == 5);    assert(std::abs(baseEx.Lsup() - 5) <= REL_TOL*5);
963    assert(baseCon.Lsup() == 5);    assert(std::abs(baseCon.Lsup() - 5) <= REL_TOL*5);
964    assert(baseTag.Lsup() == 5);    assert(std::abs(baseTag.Lsup() - 5) <= REL_TOL*5);
965    
966    cout << "\tTest Data::sup." << endl;    cout << "\tTest Data::sup." << endl;
967    assert(baseEx.sup() == 5);    assert(std::abs(baseEx.sup() - 5) <= REL_TOL*5);
968    assert(baseCon.sup() == 5);    assert(std::abs(baseCon.sup() - 5) <= REL_TOL*5);
969    assert(baseTag.sup() == 5);    assert(std::abs(baseTag.sup() - 5) <= REL_TOL*5);
970    
971    cout << "\tTest Data::inf." << endl;    cout << "\tTest Data::inf." << endl;
972    assert(baseEx.inf() == 0);    assert(std::abs(baseEx.inf() - 0) <= REL_TOL*0);
973    assert(baseCon.inf() == 0);    assert(std::abs(baseCon.inf() - 0) <= REL_TOL*0);
974    assert(baseTag.inf() == 0);    assert(std::abs(baseTag.inf() - 0) <= REL_TOL*0);
975    
976    // test data-point reduction operations    // test data-point reduction operations
977    
# Line 902  void DataTestCase::testOperations() { Line 979  void DataTestCase::testOperations() {
979    resultEx.copy(baseEx.minval());    resultEx.copy(baseEx.minval());
980    resultCon.copy(baseCon.minval());    resultCon.copy(baseCon.minval());
981    resultTag.copy(baseTag.minval());    resultTag.copy(baseTag.minval());
982    assert(resultEx.getPointDataView()() == 0);    assert(std::abs(resultEx.getPointDataView()() - 0) <= REL_TOL*0);
983    assert(resultCon.getPointDataView()() == 0);    assert(std::abs(resultCon.getPointDataView()() - 0) <= REL_TOL*0);
984    assert(resultTag.getPointDataView()() == 0);    assert(std::abs(resultTag.getPointDataView()() - 0) <= REL_TOL*0);
985    
986    cout << "\tTest Data::maxval." << endl;    cout << "\tTest Data::maxval." << endl;
987    resultEx.copy(baseEx.maxval());    resultEx.copy(baseEx.maxval());
988    resultCon.copy(baseCon.maxval());    resultCon.copy(baseCon.maxval());
989    resultTag.copy(baseTag.maxval());    resultTag.copy(baseTag.maxval());
990    assert(resultEx.getPointDataView()() == 5);    assert(std::abs(resultEx.getPointDataView()() - 5) <= REL_TOL*5);
991    assert(resultCon.getPointDataView()() == 5);    assert(std::abs(resultCon.getPointDataView()() - 5) <= REL_TOL*5);
992    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);  
993    
994  }  }
995    
 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);  
   
 }  
996    
997  void DataTestCase::testMemAlloc() {  void DataTestCase::testMemAlloc() {
998    

Legend:
Removed from v.622  
changed lines
  Added in v.1312

  ViewVC Help
Powered by ViewVC 1.1.26