/[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

revision 712 by robwdcock, Mon Mar 27 02:43:09 2006 UTC revision 713 by gross, Thu Apr 27 05:03:44 2006 UTC
# Line 746  void DataTestCase::testOperations() { Line 746  void DataTestCase::testOperations() {
746    
747    // test unary operations    // test unary operations
748    
749      double tmp;
750    cout << "\tTest Data::pow." << endl;    cout << "\tTest Data::pow." << endl;
751    Data power(3.0,shape,FunctionSpace(),true);    Data power(3.0,shape,FunctionSpace(),true);
752    resultEx.copy(baseEx.powD(power));    resultEx.copy(baseEx.powD(power));
# Line 753  void DataTestCase::testOperations() { Line 754  void DataTestCase::testOperations() {
754    resultTag.copy(baseTag.powD(power));    resultTag.copy(baseTag.powD(power));
755    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
756      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
757        assert(resultEx.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));        tmp=pow(dataView.index(i,j),3.0);
758        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));
759        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));
760          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
761      }      }
762    }    }
763    
# Line 763  void DataTestCase::testOperations() { Line 765  void DataTestCase::testOperations() {
765    resultEx.copy(baseEx.sin());    resultEx.copy(baseEx.sin());
766    resultCon.copy(baseCon.sin());    resultCon.copy(baseCon.sin());
767    resultTag.copy(baseTag.sin());    resultTag.copy(baseTag.sin());
768    assert(true);    for (int i=0;i<shape[0];i++) {
769        for (int j=0;j<shape[1];j++) {
770          tmp=sin((double)dataView.index(i,j));
771          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
772          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
773          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
774        }
775      }
776    
777    cout << "\tTest Data::cos." << endl;    cout << "\tTest Data::cos." << endl;
778    resultEx.copy(baseEx.cos());    resultEx.copy(baseEx.cos());
779    resultCon.copy(baseCon.cos());    resultCon.copy(baseCon.cos());
780    resultTag.copy(baseTag.cos());    resultTag.copy(baseTag.cos());
781    assert(true);    for (int i=0;i<shape[0];i++) {
782        for (int j=0;j<shape[1];j++) {
783          tmp=cos((double)dataView.index(i,j));
784          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
785          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
786          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
787        }
788      }
789    
790    cout << "\tTest Data::tan." << endl;    cout << "\tTest Data::tan." << endl;
791    resultEx.copy(baseEx.tan());    resultEx.copy(baseEx.tan());
792    resultCon.copy(baseCon.tan());    resultCon.copy(baseCon.tan());
793    resultTag.copy(baseTag.tan());    resultTag.copy(baseTag.tan());
794    assert(true);    for (int i=0;i<shape[0];i++) {
795        for (int j=0;j<shape[1];j++) {
796          tmp=tan((double)dataView.index(i,j));
797          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
798          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
799          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
800        }
801      }
802    
803    cout << "\tTest Data::asin." << endl;    cout << "\tTest Data::asin." << endl;
804    resultEx.copy(baseEx.asin());    resultEx.copy(baseEx.asin());
# Line 793  void DataTestCase::testOperations() { Line 816  void DataTestCase::testOperations() {
816    resultEx.copy(baseEx.atan());    resultEx.copy(baseEx.atan());
817    resultCon.copy(baseCon.atan());    resultCon.copy(baseCon.atan());
818    resultTag.copy(baseTag.atan());    resultTag.copy(baseTag.atan());
819    assert(true);    for (int i=0;i<shape[0];i++) {
820        for (int j=0;j<shape[1];j++) {
821          tmp=atan((double)dataView.index(i,j));
822          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
823          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
824          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
825        }
826      }
827    
828    cout << "\tTest Data::sinh." << endl;    cout << "\tTest Data::sinh." << endl;
829    resultEx.copy(baseEx.sinh());    resultEx.copy(baseEx.sinh());
830    resultCon.copy(baseCon.sinh());    resultCon.copy(baseCon.sinh());
831    resultTag.copy(baseTag.sinh());    resultTag.copy(baseTag.sinh());
832    assert(true);    for (int i=0;i<shape[0];i++) {
833        for (int j=0;j<shape[1];j++) {
834          tmp=sinh((double)dataView.index(i,j));
835          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
836          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
837          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
838        }
839      }
840    
841    cout << "\tTest Data::cosh." << endl;    cout << "\tTest Data::cosh." << endl;
842    resultEx.copy(baseEx.cosh());    resultEx.copy(baseEx.cosh());
843    resultCon.copy(baseCon.cosh());    resultCon.copy(baseCon.cosh());
844    resultTag.copy(baseTag.cosh());    resultTag.copy(baseTag.cosh());
845    assert(true);    for (int i=0;i<shape[0];i++) {
846        for (int j=0;j<shape[1];j++) {
847          tmp=cosh((double)dataView.index(i,j));
848          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
849          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
850          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
851        }
852      }
853    
854    cout << "\tTest Data::tanh." << endl;    cout << "\tTest Data::tanh." << endl;
855    resultEx.copy(baseEx.tanh());    resultEx.copy(baseEx.tanh());
856    resultCon.copy(baseCon.tanh());    resultCon.copy(baseCon.tanh());
857    resultTag.copy(baseTag.tanh());    resultTag.copy(baseTag.tanh());
858    assert(true);    for (int i=0;i<shape[0];i++) {
859        for (int j=0;j<shape[1];j++) {
860          tmp=tanh((double)dataView.index(i,j));
861          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
862          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
863          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
864        }
865      }
866    
867    cout << "\tTest Data::asinh." << endl;    cout << "\tTest Data::asinh." << endl;
868    resultEx.copy(baseEx.asinh());    resultEx.copy(baseEx.asinh());
# Line 841  void DataTestCase::testOperations() { Line 892  void DataTestCase::testOperations() {
892    resultEx.copy(baseEx.abs());    resultEx.copy(baseEx.abs());
893    resultCon.copy(baseCon.abs());    resultCon.copy(baseCon.abs());
894    resultTag.copy(baseTag.abs());    resultTag.copy(baseTag.abs());
895    assert(true);    for (int i=0;i<shape[0];i++) {
896        for (int j=0;j<shape[1];j++) {
897          tmp=abs((double)dataView.index(i,j));
898          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
899          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
900          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
901        }
902      }
903    
904    cout << "\tTest Data::sign." << endl;    cout << "\tTest Data::sign." << endl;
905    resultEx.copy(baseEx.sign());    resultEx.copy(baseEx.sign());
# Line 853  void DataTestCase::testOperations() { Line 911  void DataTestCase::testOperations() {
911    resultEx.copy(baseEx.exp());    resultEx.copy(baseEx.exp());
912    resultCon.copy(baseCon.exp());    resultCon.copy(baseCon.exp());
913    resultTag.copy(baseTag.exp());    resultTag.copy(baseTag.exp());
914    assert(true);    for (int i=0;i<shape[0];i++) {
915        for (int j=0;j<shape[1];j++) {
916          tmp=exp((double)dataView.index(i,j));
917          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
918          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
919          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
920        }
921      }
922    
923    cout << "\tTest Data::sqrt." << endl;    cout << "\tTest Data::sqrt." << endl;
924    resultEx.copy(baseEx.sqrt());    resultEx.copy(baseEx.sqrt());
925    resultCon.copy(baseCon.sqrt());    resultCon.copy(baseCon.sqrt());
926    resultTag.copy(baseTag.sqrt());    resultTag.copy(baseTag.sqrt());
927    assert(true);    for (int i=0;i<shape[0];i++) {
928        for (int j=0;j<shape[1];j++) {
929          tmp=sqrt((double)dataView.index(i,j));
930          assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
931          assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
932          assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
933        }
934      }
935    
936    cout << "\tTest Data::neg." << endl;    cout << "\tTest Data::neg." << endl;
937    resultEx.copy(baseEx.neg());    resultEx.copy(baseEx.neg());
# Line 873  void DataTestCase::testOperations() { Line 945  void DataTestCase::testOperations() {
945    resultTag.copy(baseTag.pos());    resultTag.copy(baseTag.pos());
946    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
947      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
948        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)));
949        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)));
950        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)));
951      }      }
952    }    }
953    
954    // test reduction operations    // test reduction operations
955    
956    cout << "\tTest Data::Lsup." << endl;    cout << "\tTest Data::Lsup." << endl;
957    assert(baseEx.Lsup() == 5);    assert(std::abs(baseEx.Lsup() - 5) <= REL_TOL*5);
958    assert(baseCon.Lsup() == 5);    assert(std::abs(baseCon.Lsup() - 5) <= REL_TOL*5);
959    assert(baseTag.Lsup() == 5);    assert(std::abs(baseTag.Lsup() - 5) <= REL_TOL*5);
960    
961    cout << "\tTest Data::sup." << endl;    cout << "\tTest Data::sup." << endl;
962    assert(baseEx.sup() == 5);    assert(std::abs(baseEx.sup() - 5) <= REL_TOL*5);
963    assert(baseCon.sup() == 5);    assert(std::abs(baseCon.sup() - 5) <= REL_TOL*5);
964    assert(baseTag.sup() == 5);    assert(std::abs(baseTag.sup() - 5) <= REL_TOL*5);
965    
966    cout << "\tTest Data::inf." << endl;    cout << "\tTest Data::inf." << endl;
967    assert(baseEx.inf() == 0);    assert(std::abs(baseEx.inf() - 0) <= REL_TOL*0);
968    assert(baseCon.inf() == 0);    assert(std::abs(baseCon.inf() - 0) <= REL_TOL*0);
969    assert(baseTag.inf() == 0);    assert(std::abs(baseTag.inf() - 0) <= REL_TOL*0);
970    
971    // test data-point reduction operations    // test data-point reduction operations
972    
# Line 902  void DataTestCase::testOperations() { Line 974  void DataTestCase::testOperations() {
974    resultEx.copy(baseEx.minval());    resultEx.copy(baseEx.minval());
975    resultCon.copy(baseCon.minval());    resultCon.copy(baseCon.minval());
976    resultTag.copy(baseTag.minval());    resultTag.copy(baseTag.minval());
977    assert(resultEx.getPointDataView()() == 0);    assert(std::abs(resultEx.getPointDataView()() - 0) <= REL_TOL*0);
978    assert(resultCon.getPointDataView()() == 0);    assert(std::abs(resultCon.getPointDataView()() - 0) <= REL_TOL*0);
979    assert(resultTag.getPointDataView()() == 0);    assert(std::abs(resultTag.getPointDataView()() - 0) <= REL_TOL*0);
980    
981    cout << "\tTest Data::maxval." << endl;    cout << "\tTest Data::maxval." << endl;
982    resultEx.copy(baseEx.maxval());    resultEx.copy(baseEx.maxval());
983    resultCon.copy(baseCon.maxval());    resultCon.copy(baseCon.maxval());
984    resultTag.copy(baseTag.maxval());    resultTag.copy(baseTag.maxval());
985    assert(resultEx.getPointDataView()() == 5);    assert(std::abs(resultEx.getPointDataView()() - 5) <= REL_TOL*5);
986    assert(resultCon.getPointDataView()() == 5);    assert(std::abs(resultCon.getPointDataView()() - 5) <= REL_TOL*5);
987    assert(resultTag.getPointDataView()() == 5);    assert(std::abs(resultTag.getPointDataView()() - 5) <= REL_TOL*5);
988    
989    cout << "\tTest Data::trace." << endl;    cout << "\tTest Data::trace." << endl;
990    resultEx.copy(baseEx.trace());    resultEx.copy(baseEx.trace());
991    resultCon.copy(baseCon.trace());    resultCon.copy(baseCon.trace());
992    resultTag.copy(baseTag.trace());    resultTag.copy(baseTag.trace());
993    assert(resultEx.getPointDataView()() == 15);    assert(std::abs(resultEx.getPointDataView()() - 15) <= REL_TOL*15);
994    assert(resultCon.getPointDataView()() == 15);    assert(std::abs(resultCon.getPointDataView()() - 15) <= REL_TOL*15);
995    assert(resultTag.getPointDataView()() == 15);    assert(std::abs(resultTag.getPointDataView()() - 15) <= REL_TOL*15);
996    
997  }  }
998    

Legend:
Removed from v.712  
changed lines
  Added in v.713

  ViewVC Help
Powered by ViewVC 1.1.26