Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_VectorStdOpsTester_def.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_VECTOR_STD_OPS_TESTER_HPP
00030 #define THYRA_VECTOR_STD_OPS_TESTER_HPP
00031 
00032 #include "Thyra_VectorStdOpsTester_decl.hpp"
00033 #include "Thyra_TestingTools.hpp"
00034 #include "RTOpPack_TOpSetAssendingValues.hpp"
00035 #include "Teuchos_TestingHelpers.hpp"
00036 #include "Teuchos_Assert.hpp"
00037 
00038 //#define THYRA_VECTOR_STD_OPS_TESTER_DUMP
00039 
00040 #ifdef THYRA_VECTOR_STD_OPS_TESTER_DUMP
00041 #  include "RTOpPack_SPMD_apply_op.hpp"
00042 #endif // THYRA_VECTOR_STD_OPS_TESTER_DUMP
00043 
00044 
00045 namespace Thyra {
00046 
00047 
00048 // VectorStdOpsTesterComparable (using partial specialization to only do tests in some cases)
00049 
00050 
00051 template <bool isComparable, class Scalar>
00052 class VectorStdOpsTesterComparable {
00053 public:
00054   static bool checkComparableStdOps(
00055     const VectorSpaceBase<Scalar>                                 &vecSpc
00056     ,const Ptr<VectorBase<Scalar> >                               &z
00057     ,const typename Teuchos::ScalarTraits<Scalar>::magnitudeType  &error_tol
00058     ,const typename Teuchos::ScalarTraits<Scalar>::magnitudeType  &warning_tol
00059     ,std::ostream                                                 *out
00060     ,const bool                                                   &dumpAll
00061     )
00062     {
00063       return Teuchos::ScalarTraits<Scalar>::ThisShouldNotCompile();
00064     }
00065 };
00066 
00067 
00068 template <class Scalar>
00069 class VectorStdOpsTesterComparable<false,Scalar> {
00070 public:
00071   static bool checkComparableStdOps(
00072     const VectorSpaceBase<Scalar>                                 &vecSpc
00073     ,const Ptr<VectorBase<Scalar> >                               &z
00074     ,const typename Teuchos::ScalarTraits<Scalar>::magnitudeType  &error_tol
00075     ,const typename Teuchos::ScalarTraits<Scalar>::magnitudeType  &warning_tol
00076     ,std::ostream                                                 *out
00077     ,const bool                                                   &dumpAll
00078     )
00079     {
00080       if(out) *out << "\nThis scalar type does not support comparable operations so we can not test min(), max() and other such functions.\n";
00081       return true;
00082     }
00083 };
00084 
00085 
00086 template <class Scalar>
00087 class VectorStdOpsTesterComparable<true,Scalar> {
00088 public:
00089   static bool checkComparableStdOps(
00090     const VectorSpaceBase<Scalar>                                 &vecSpc
00091     ,const Ptr<VectorBase<Scalar> >                               &z
00092     ,const typename Teuchos::ScalarTraits<Scalar>::magnitudeType  &error_tol
00093     ,const typename Teuchos::ScalarTraits<Scalar>::magnitudeType  &warning_tol
00094     ,std::ostream                                                 *out
00095     ,const bool                                                   &dumpAll
00096     )
00097     {
00098       typedef Teuchos::ScalarTraits<Scalar> ST;
00099       using Teuchos::outArg;
00100 
00101       bool success = true, result;
00102       
00103       if(out) *out << "\nTesting comparable operations ...\n";
00104       
00105       const Scalar scalarSmall(1e-5), scalarMedium(2.0), scalarLarge(100.0);
00106       if(out) *out << "\nassign(z.ptr(),"<<scalarMedium<<");\n";
00107       assign(z.ptr(),Scalar(scalarMedium));
00108       if(out && dumpAll) *out << "\nz =\n" << *z;
00109       if(out) *out << "\nset_ele(0,"<<scalarSmall<<",z.ptr());\n";
00110       set_ele(0,scalarSmall,z.ptr());
00111       if(out && dumpAll) *out << "\nz =\n" << *z;
00112       if(out) *out << "\nset_ele(1,"<<scalarLarge<<",z.ptr());\n";
00113       set_ele(1,scalarLarge,z.ptr());
00114       if(out && dumpAll) *out << "\nz =\n" << *z;
00115       if(out) *out << "\nset_ele(vecSpc.dim()-2,"<<scalarSmall<<",z.ptr());\n";
00116       set_ele(vecSpc.dim()-2,scalarSmall,z.ptr());
00117       if(out && dumpAll) *out << "\nz =\n" << *z;
00118       if(out) *out << "\nset_ele(vecSpc.dim()-1,"<<scalarLarge<<",z.ptr());\n";
00119       set_ele(vecSpc.dim()-1,scalarLarge,z.ptr());
00120       if(out && dumpAll) *out << "\nz =\n" << *z;
00121 
00122       Scalar minEle; Ordinal minIndex;
00123       Scalar maxEle; Ordinal maxIndex;
00124 
00125       if(!testRelErr<Scalar>(
00126            "min(*z)",min(*z),"scalarSmall",scalarSmall
00127            ,"error_tol",error_tol,"warning_tol",warning_tol,out
00128            )
00129         ) success=false;
00130 
00131       if(out) *out << "\nmin(*z,&minEle,&minIndex);\n";
00132       minEle = ST::zero(); minIndex = 0;
00133       min(*z, outArg(minEle), outArg(minIndex));
00134       if(!testRelErr<Scalar>(
00135            "minEle",minEle,"scalarSmall",scalarSmall
00136            ,"error_tol",error_tol,"warning_tol",warning_tol,out
00137            )
00138         ) success=false;
00139       result = minIndex == 0;
00140       if(out) *out << "\nminIndex = " << minIndex << " == 0 ? " << passfail(result) << std::endl;
00141       if(!result) success = false;
00142 
00143       if(out) *out << "\nminGreaterThanBound(*z,"<<scalarMedium<<",&minEle,&minIndex);\n";
00144       minEle = ST::zero(); minIndex = 0;
00145       minGreaterThanBound(*z, scalarMedium, outArg(minEle), outArg(minIndex));
00146       if(!testRelErr<Scalar>(
00147            "minEle",minEle,"scalarLarge",scalarLarge
00148            ,"error_tol",error_tol,"warning_tol",warning_tol,out
00149            )
00150         ) success=false;
00151       result = minIndex == 1;
00152       if(out) *out << "\nminIndex = " << minIndex << " == 1 ? " << passfail(result) << std::endl;
00153       if(!result) success = false;
00154 
00155       if(out) *out << "\nminGreaterThanBound(*z,"<<scalarLarge<<",&minEle,&minIndex);\n";
00156       minEle = ST::zero(); minIndex = 0;
00157       minGreaterThanBound(*z,scalarLarge, outArg(minEle), outArg(minIndex));
00158       result = minIndex < 0;
00159       if(out) *out << "\nminIndex = " << minIndex << " < 0 ? " << passfail(result) << std::endl;
00160       if(!result) success = false;
00161     
00162       if(!testRelErr<Scalar>(
00163            "max(*z)",max(*z),"scalarLarge",scalarLarge
00164            ,"error_tol",error_tol,"warning_tol",warning_tol,out)
00165         ) success=false;
00166 
00167       if(out) *out << "\nmax(*z,&maxEle,&maxIndex);\n";
00168       maxEle = ST::zero(); maxIndex = 0;
00169       max(*z, outArg(maxEle), outArg(maxIndex));
00170       if(!testRelErr<Scalar>(
00171            "maxEle",maxEle,"scalarLarge",scalarLarge
00172            ,"error_tol",error_tol,"warning_tol",warning_tol,out)
00173         ) success=false;
00174       result = maxIndex == 1;
00175       if(out) *out << "\nmaxIndex = " << maxIndex << " == 1 ? " << passfail(result) << std::endl;
00176       if(!result) success = false;
00177 
00178       if(out) *out << "\nmaxLessThanBound(*z,"<<scalarMedium<<",&maxEle,&maxIndex);\n";
00179       maxEle = ST::zero(); maxIndex = 0;
00180       maxLessThanBound(*z, scalarMedium, outArg(maxEle), outArg(maxIndex));
00181       if(!testRelErr<Scalar>(
00182            "maxEle",maxEle,"scalarSmall",scalarSmall
00183            ,"error_tol",error_tol,"warning_tol",warning_tol,out)
00184         ) success=false;
00185       result = maxIndex == 0;
00186       if(out) *out << "\nmaxIndex = " << maxIndex << " == 0 ? " << passfail(result) << std::endl;
00187       if(!result) success = false;
00188 
00189       if(out) *out << "\nmaxLessThanBound(*z,"<<scalarSmall<<",&maxEle,&maxIndex);\n";
00190       maxEle = ST::zero(); maxIndex = 0;
00191       maxLessThanBound(*z, scalarSmall, outArg(maxEle), outArg(maxIndex));
00192       result = ( maxIndex < 0 );
00193       if(out) *out << "\nmaxIndex = " << maxIndex << " < 0 ? " << passfail(result) << std::endl;
00194       if(!result) success = false;
00195       
00196       return success;
00197     }
00198 };
00199 
00200 
00201 // Other helpers
00202 
00203 
00204 template<class Scalar>
00205 void setEleTestCase( const Ptr<VectorBase<Scalar> > &z, const Ordinal i, int &tc,
00206   std::ostream &out, bool &success)
00207 {
00208   using Teuchos::as;
00209   out << "\n"<<tc<<") set_ele(z, "<<i<<");\n";
00210   ++tc;
00211   {
00212     typedef ScalarTraits<Scalar> ST;
00213     const Scalar val_i = as<Scalar>(i+1);
00214     assign<Scalar>(z, ST::zero());
00215     set_ele(i, val_i, z);
00216     TEUCHOS_TEST_EQUALITY_CONST(get_ele(*z, i), val_i, out, success);
00217     TEUCHOS_TEST_EQUALITY_CONST(sum(*z), val_i, out, success);
00218   }
00219 }
00220 
00221 
00222 // VectorStdOpsTester
00223 
00224 
00225 template <class Scalar>
00226 VectorStdOpsTester<Scalar>::VectorStdOpsTester(
00227   const ScalarMag &warning_tol_in,
00228   const ScalarMag &error_tol_in
00229   )
00230   :warning_tol_(warning_tol_in),
00231    error_tol_(error_tol_in)
00232 {}
00233 
00234 
00235 template <class Scalar>
00236 bool VectorStdOpsTester<Scalar>::checkStdOps(
00237   const VectorSpaceBase<Scalar> &vecSpc,
00238   std::ostream *out_out,
00239   const bool &dumpAll
00240   )
00241 {
00242   using Teuchos::as;
00243   using Teuchos::tuple;
00244   using Teuchos::null;
00245   using Teuchos::outArg;
00246   typedef Teuchos::ScalarTraits<Scalar> ST;
00247 
00248   TEUCHOS_ASSERT(out_out);
00249   std::ostream &out = *out_out;
00250 
00251   out << "\n*** Entering VectorStdOpsTester<"<<ST::name()<<">::checkStdOps(...) ...\n"
00252       << "using a \'" << vecSpc.description() << "\' object ...\n";
00253 
00254   bool success = true;
00255   out << "\nvecSpc.dim() = " << vecSpc.dim() << std::endl;
00256 
00257   const Ordinal n = vecSpc.dim();
00258 
00259   TEST_FOR_EXCEPTION( n < 4, std::logic_error,
00260     "Error: n = "<<n<<" must be least 4 or greater to"
00261     " run Thyra::VectorStdOpsTester::checkStdOps(...)!" );
00262 
00263   const Scalar
00264     two = as<Scalar>(2.0),
00265     three = as<Scalar>(3.0),
00266     four = as<Scalar>(4.0);
00267 
00268   int tc = 0;
00269 
00270   out << "\nCreating vectors v1, v2, v3, v4, x and z ...\n";
00271   Teuchos::RCP<VectorBase<Scalar> >
00272     v1 = createMember(vecSpc),
00273     v2 = createMember(vecSpc),
00274     v3 = createMember(vecSpc),
00275     v4 = createMember(vecSpc),
00276     y = createMember(vecSpc),
00277     x = createMember(vecSpc),
00278     z = createMember(vecSpc);
00279 
00280   out << "\nassign(v1.ptr(), -2.0);\n";
00281   assign<Scalar>(v1.ptr(), -two);
00282   out << "\nassign(v2.ptr(), -3.0);\n";
00283   assign<Scalar>(v2.ptr(), -three);
00284   out << "\nassign(v3.ptr(), -4.0);\n";
00285   assign<Scalar>(v3.ptr(), -four);
00286   out << "\ny[i] = i+1\n";
00287   {
00288     RTOpPack::TOpSetAssendingValues<Scalar> setAssendOp(ST::zero());
00289     applyOp<Scalar>( setAssendOp,
00290       ArrayView<const Ptr<const VectorBase<Scalar> > >(null),
00291       tuple<Ptr<VectorBase<Scalar> > >(y.ptr())(),
00292       null );
00293   }
00294 
00295   // sum
00296   out << "\n"<<tc<<") sum(*y);\n";
00297   ++tc;
00298   TEUCHOS_TEST_ASSERT(
00299     testRelErr<Scalar>(
00300       "sum(*y)", sum(*y),
00301       "0.5*(n+1)*n", as<Scalar>(0.5*(n+1)*n),
00302       "error_tol", error_tol(), "warning_tol", warning_tol(), &out),
00303     out, success);
00304 
00305   // norm_inf
00306   out << "\n"<<tc<<") nom_inf(*v1);\n";
00307   ++tc;
00308   TEUCHOS_TEST_ASSERT(
00309     testRelErr<Scalar>(
00310       "norm_inf(*v1)", norm_inf(*v1),
00311       "2.0", two,
00312       "error_tol", error_tol(), "warning_tol", warning_tol(), &out),
00313     out, success);
00314 
00315   // norm_2
00316   out << "\n"<<tc<<") norm_2(*v1);\n";
00317   ++tc;
00318   TEUCHOS_TEST_ASSERT(
00319     testRelErr<Scalar>(
00320       "norm_2(*v1)", norm_2(*v1),
00321       "2.0*sqrt(vecSpc.dim())", as<Scalar>(2.0)*ST::squareroot(vecSpc.dim()),
00322       "error_tol", error_tol(), "warning_tol",warning_tol(), &out),
00323     out, success);
00324 
00325   // norm_1
00326   out << "\n"<<tc<<") norm_1(*v1);\n";
00327   ++tc;
00328   TEUCHOS_TEST_ASSERT(
00329     testRelErr<Scalar>(
00330       "norm_1(*v1)" ,norm_1(*v1),
00331       "2.0*vecSpc.dim()", as<Scalar>(2.0)*as<Scalar>(vecSpc.dim()),
00332       "error_tol", error_tol(), "warning_tol", warning_tol(), &out),
00333     out, success);
00334   
00335   // abs
00336   out << "\n"<<tc<<") abs(z.ptr(),*v1);\n";
00337   ++tc;
00338   {
00339     abs(z.ptr(), *v1);
00340     if(!testRelErr<Scalar>(
00341          "sum(*z)",sum(*z),"2.0*vecSpc.dim()",as<Scalar>(2.0)*as<Scalar>(vecSpc.dim())
00342          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out)
00343       ) success=false;
00344   }
00345 
00346   // get_ele
00347 
00348   out << "\n"<<tc<<") val = get_ele(y, 0);\n";
00349   ++tc;
00350   {
00351     const Scalar val = get_ele<Scalar>(*y, 0);
00352     TEUCHOS_TEST_EQUALITY_CONST( val, as<Scalar>(1), out, success );
00353   }
00354 
00355   out << "\n"<<tc<<") val = get_ele<Scalar>(*y, 1);\n";
00356   ++tc;
00357   {
00358     const Scalar val = get_ele<Scalar>(*y, 1);
00359     TEUCHOS_TEST_EQUALITY_CONST( val, as<Scalar>(2), out, success );
00360   }
00361 
00362   out << "\n"<<tc<<") val = get_ele<Scalar>(*y, n-2);\n";
00363   ++tc;
00364   {
00365     const Scalar val = get_ele<Scalar>(*y, n-2);
00366     TEUCHOS_TEST_EQUALITY_CONST( val, as<Scalar>(n-1), out, success );
00367   }
00368 
00369   out << "\n"<<tc<<") val = get_ele<Scalar>(*y, n-1);\n";
00370   ++tc;
00371   {
00372     const Scalar val = get_ele<Scalar>(*y, n-1);
00373     TEUCHOS_TEST_EQUALITY_CONST( val, as<Scalar>(n), out, success );
00374   }
00375 
00376 #ifdef THYRA_DEBUG
00377 
00378   out << "\n"<<tc<<") get_ele<Scalar>(*y, -1);\n";
00379   ++tc;
00380   {
00381     TEUCHOS_TEST_THROW(get_ele<Scalar>(*y, -1), std::out_of_range, out, success );
00382   }
00383 
00384   out << "\n"<<tc<<") get_ele<Scalar>(*y, n);\n";
00385   ++tc;
00386   {
00387     TEUCHOS_TEST_THROW(get_ele<Scalar>(*y, n), std::out_of_range, out, success );
00388   }
00389 
00390 #endif // THYRA_DEBUG
00391 
00392   // set_ele
00393 
00394   setEleTestCase<Scalar>(z.ptr(), 0, tc, out, success);
00395 
00396   setEleTestCase<Scalar>(z.ptr(), 1, tc, out, success);
00397 
00398   setEleTestCase<Scalar>(z.ptr(), n-2, tc, out, success);
00399 
00400   setEleTestCase<Scalar>(z.ptr(), n-1, tc, out, success);
00401 
00402 #ifdef THYRA_DEBUG
00403 
00404   TEUCHOS_TEST_THROW(set_ele(-1, two, z.ptr()),
00405     std::out_of_range, out, success);
00406 
00407   TEUCHOS_TEST_THROW(set_ele(n, two, z.ptr()),
00408     std::out_of_range, out, success);
00409 
00410 #endif // THYRA_DEBUG
00411     
00412   // reciprocal
00413   out << "\n"<<tc<<") reciprocal(z.ptr(),*v1);\n";
00414   ++tc;
00415   {
00416     reciprocal(z.ptr(), *v1);
00417     if(!testRelErr<Scalar>(
00418          "sum(*z)",sum(*z),"-0.5*vecSpc.dim()",as<Scalar>(-0.5)*as<Scalar>(vecSpc.dim())
00419          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out)
00420       ) success=false;
00421   }
00422     
00423   // linear_combination
00424 
00425   out << "\n"<<tc<<") linear_combination(2,{0.5,0.25},{v1.ptr(),v2.ptr()},0.0,z.ptr());\n";
00426   ++tc;
00427   {
00428     linear_combination<Scalar>(
00429       tuple<Scalar>(0.5, 0.25)(),
00430       tuple<Ptr<const VectorBase<Scalar> > >(v1.ptr(), v2.ptr())(),
00431       ST::zero(),
00432       z.ptr());
00433     TEUCHOS_TEST_ASSERT(
00434       testRelErr<Scalar>(
00435         "sum(*z)", sum(*z),
00436         "(-0.5*2.0-0.25*3.0)*vecSpc.dim()", as<Scalar>((-0.5 * 2.0 - 0.25 * 3.0) *vecSpc.dim()),
00437         "error_tol", error_tol(), "warning_tol", warning_tol(), &out),
00438       out, success);
00439   }
00440 
00441   out << "\nassign(z.ptr(), 2.0);\n";
00442   ++tc;
00443   assign(z.ptr(), as<Scalar>(2.0));
00444 
00445   out << "\n"<<tc<<") linear_combination(3,{0.5,0.25,0.125},{v1.ptr(),v2.ptr(),v2.ptr()},0.5,z.ptr());\n";
00446   ++tc;
00447   {
00448     linear_combination<Scalar>(
00449       tuple<Scalar>(0.5, 0.25, 0.125)(),
00450       tuple<Ptr<const VectorBase<Scalar> > >(v1.ptr(), v2.ptr(),  v3.ptr())(),
00451       as<Scalar>(0.5),
00452       z.ptr());
00453     if(!testRelErr<Scalar>(
00454          "sum(*z)", sum(*z),
00455          "(0.5*2.0-0.5*2.0-0.25*3.0-0.125*4.0)*vecSpc.dim()",
00456          as<Scalar>(0.5*2.0-0.5*2.0-0.25*3.0-0.125*4.0)*as<Scalar>(vecSpc.dim()),
00457          "error_tol", error_tol(), "warning_tol", warning_tol(), &out
00458         )
00459       ) success=false;
00460   }
00461   
00462   // assgin
00463   out << "\n"<<tc<<") assign(z.ptr(),2.0);\n";
00464   ++tc;
00465   {
00466     assign(z.ptr(),as<Scalar>(2.0));
00467     if(!testRelErr<Scalar>(
00468          "norm_2(*z,*v2)",norm_2(*z,*v2)
00469          ,"sqrt(2.0*3.0*3.0*vecSpc.dim())",ST::magnitude(ST::squareroot(as<Scalar>(2.0*3.0*3.0)*as<Scalar>(vecSpc.dim())))
00470          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00471         )
00472       ) success=false;
00473 
00474     if(!VectorStdOpsTesterComparable<ST::isComparable,Scalar>::checkComparableStdOps(
00475          vecSpc,z.ptr(),error_tol(),warning_tol(),&out,dumpAll)
00476       ) success=false;
00477   }
00478 
00479   // Test Vt_S
00480   out << "\n"<<tc<<") Testing Vt_S(z.ptr(),alpha) ...\n";
00481   ++tc;
00482   {
00483 #ifdef THYRA_VECTOR_STD_OPS_TESTER_DUMP
00484     RTOpPack::show_spmd_apply_op_dump = true;
00485 #endif // THYRA_VECTOR_STD_OPS_TESTER_DUMP
00486     v1  = createMember(vecSpc);
00487     v2  = createMember(vecSpc);
00488     const Scalar alpha = as<Scalar>(1.2345);
00489     seed_randomize<Scalar>(12345);
00490     randomize(as<Scalar>(-ST::one()),ST::one(),v1.ptr());
00491     V_V(v2.ptr(),*v1);
00492     Vt_S(v1.ptr(), alpha);
00493     const Scalar norm_alpha_v1 = norm_2(*v1);
00494     //out << "norm_alpha_v1 = " << norm_alpha_v1 << "\n";
00495     const Scalar mag_alpha = ST::magnitude(alpha);
00496     //out << "mag_alpha = " << mag_alpha << "\n";
00497     const Scalar norm_2_v2 = norm_2(*v2);
00498     //out << "norm_2_v2 = " << norm_2_v2 << "\n";
00499     const Scalar alpha_norm_v1 = mag_alpha * norm_2_v2;
00500     //out << "alpha_norm_v1 = " << alpha_norm_v1 << "\n";
00501     if(!testMaxErr<Scalar>(
00502          "norm_alpha_v1 - alpha_norm_v1",ST::magnitude(norm_alpha_v1-alpha_norm_v1)
00503          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00504         )
00505       ) success=false;
00506 #ifdef THYRA_VECTOR_STD_OPS_TESTER_DUMP
00507     RTOpPack::show_spmd_apply_op_dump = false;
00508 #endif // THYRA_VECTOR_STD_OPS_TESTER_DUMP
00509   }
00510   
00511   // Test V_StV
00512   out << "\n"<<tc<<") Testing V_StV(z.ptr(),alpha,*v) ...\n";
00513   ++tc;
00514   {
00515     v1  = createMember(vecSpc);
00516     v2  = createMember(vecSpc);
00517     z   = createMember(vecSpc);
00518     const Scalar alpha = as<Scalar>(-1.2345);
00519     seed_randomize<Scalar>(12345);
00520     randomize(as<Scalar>(-ST::one()),ST::one(),v1.ptr());
00521     V_StV(v2.ptr(),alpha,*v1);
00522     Vt_S(v1.ptr(),alpha);
00523     V_V(z.ptr(),*v1);
00524     Vp_V(z.ptr(),*v2,as<Scalar>(-ST::one()));
00525     if(!testMaxErr<Scalar>(
00526          "norm_2(*z)",norm_2(*z)
00527          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00528         )
00529       ) success=false;
00530   }
00531 
00532   // Test Vp_StV
00533   out << "\n"<<tc<<") Testing Vp_StV(z.ptr(),alpha,*v) ...\n";
00534   ++tc;
00535   {
00536     v1  = createMember(vecSpc);
00537     v2  = createMember(vecSpc);
00538     v3  = createMember(vecSpc);
00539     z   = createMember(vecSpc);
00540     const Scalar alpha = as<Scalar>(-1.2345);
00541     seed_randomize<Scalar>(12345);
00542     randomize(as<Scalar>(-ST::one()),ST::one(),v1.ptr()); // v1 = rand
00543     randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr()); // v2 = rand
00544     V_V(v3.ptr(),*v1); // v3 = v1
00545     Vp_StV(v1.ptr(),alpha,*v2); // v1 += alpha*v2
00546     V_StV(z.ptr(),alpha,*v2); // z = alpha*v2
00547     Vp_V(z.ptr(),*v3); // z += v3
00548     V_V(v3.ptr(),*v1); // v3 = v1
00549     Vp_V(v3.ptr(),*z,as<Scalar>(-ST::one())); // v3 -= z
00550     if(!testMaxErr<Scalar>(
00551          "norm_2(*v3)",norm_2(*v3)
00552          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00553         )
00554       ) success=false;
00555   }
00556   
00557   // Test ele_wise_prod
00558   out << "\n"<<tc<<") Testing ele_wise_prod(alpha,*v1, *v2, z.ptr()) ...\n";
00559   ++tc;
00560   {
00561     v1  = createMember(vecSpc);
00562     v2  = createMember(vecSpc);
00563     v3  = createMember(vecSpc);
00564     z   = createMember(vecSpc);
00565     const Scalar alpha = as<Scalar>(-1.2345);
00566     seed_randomize<Scalar>(12345);
00567     randomize(as<Scalar>(-ST::one()),ST::one(),v1.ptr()); // v1 = rand
00568     randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr()); // v2 = rand
00569     randomize(as<Scalar>(-ST::one()),ST::one(),v3.ptr()); // v3 = rand
00570     V_V(v4.ptr(), *v1); // v4 = v1
00571     V_V(z.ptr(), *v2); // z = v2
00572     ele_wise_prod(alpha, *v2, *v3, v1.ptr()); // v1 += alpha * v2 * v3
00573     ele_wise_prod_update(alpha, *v3, z.ptr()); // z *= alpha * v3
00574     Vp_V(z.ptr(), *v4); // z += v4
00575     V_V(v2.ptr(), *v1); // v2 = v1
00576     Vp_V(v2.ptr(), *z, as<Scalar>(-ST::one())); // v2 -= z
00577     if(!testMaxErr<Scalar>(
00578          "norm_2(*v2)",norm_2(*v2)
00579          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00580         )
00581       ) success=false;
00582   }
00583 
00584   // Test Vt_StV
00585   out << "\n"<<tc<<") Testing Vt_StV(z.ptr(), alpha, *v) ...\n";
00586   ++tc;
00587   {
00588     v1  = createMember(vecSpc);
00589     v2  = createMember(vecSpc);
00590     v3  = createMember(vecSpc);
00591     z   = createMember(vecSpc);
00592     const Scalar alpha = as<Scalar>(-1.2345);
00593     seed_randomize<Scalar>(12345);
00594     randomize(as<Scalar>(-ST::one()),ST::one(),v1.ptr()); // v1 = rand
00595     randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr()); // v2 = rand
00596     V_V(v3.ptr(),*v1); // v3 = v1
00597     Vt_StV(v1.ptr(),alpha,*v2); // v1 *= alpha*v2
00598     V_S(z.ptr(),ST::zero()); // z = 0
00599     Vp_StVtV(z.ptr(),alpha,*v3,*v2); // z += alpha*v3*v2
00600     V_V(v2.ptr(),*v1); // v2 = v1
00601     Vp_V(v2.ptr(),*z,as<Scalar>(-ST::one())); // v2 -= z
00602     if(!testMaxErr<Scalar>(
00603          "norm_2(*v2)",norm_2(*v2)
00604          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00605         )
00606       ) success=false;
00607   }
00608 
00609   // Test V_StVpV
00610   out << "\n"<<tc<<") Testing V_StVpV(z.ptr(),alpha,*v1,*v2) ...\n";
00611   ++tc;
00612   {
00613     v1 = createMember(vecSpc);
00614     v2 = createMember(vecSpc);
00615     v3 = createMember(vecSpc);
00616     x  = createMember(vecSpc);
00617     z  = createMember(vecSpc);
00618     const Scalar alpha = as<Scalar>(1.2345);
00619     seed_randomize<Scalar>(12345);
00620     randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v1.ptr());
00621     randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
00622     V_StVpV(v3.ptr(),alpha,*v1,*v2);
00623     V_V(z.ptr(),*v1);
00624     Vp_V(z.ptr(),*v2,alpha);
00625     V_V(x.ptr(),*v3);
00626     Vp_V(x.ptr(),*z,as<Scalar>(-ST::one()));
00627     if(!testMaxErr<Scalar>(
00628          "norm_2(*x)",norm_2(*x)
00629          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00630         )
00631       ) success=false;
00632   }
00633 
00634   // Test V_VpStV
00635   out << "\n"<<tc<<") Testing V_VpStV(z.ptr(),*v1,alpha,*v2) ...\n";
00636   ++tc;
00637   {
00638     v1 = createMember(vecSpc);
00639     v2 = createMember(vecSpc);
00640     v3 = createMember(vecSpc);
00641     x  = createMember(vecSpc);
00642     z  = createMember(vecSpc);
00643     const Scalar alpha = as<Scalar>(1.2345);
00644     seed_randomize<Scalar>(12345);
00645     randomize<Scalar>(as<Scalar>(as<Scalar>(-10)*ST::one()),
00646       as<Scalar>(as<Scalar>(10)*ST::one()), v1.ptr());
00647     randomize<Scalar>(as<Scalar>(as<Scalar>(-10)*ST::one()),
00648       as<Scalar>(as<Scalar>(10)*ST::one()), v2.ptr());
00649     V_VpStV(outArg(*v3), *v1, alpha, *v2);
00650     V_V(z.ptr(), *v1);
00651     Vp_StV(z.ptr(), alpha, *v2);
00652     V_VmV(outArg(*x), *z, *v3);
00653     if(!testMaxErr<Scalar>(
00654          "norm_2(*x)",norm_2(*x)
00655          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00656         )
00657       ) success=false;
00658   }
00659 
00660   // Test V_StVpStV
00661   out << "\n"<<tc<<") Testing V_StVpStV(z.ptr(),alpha,*v1,beta,*v2) ...\n";
00662   ++tc;
00663   {
00664     v1 = createMember(vecSpc);
00665     v2 = createMember(vecSpc);
00666     v3 = createMember(vecSpc);
00667     x  = createMember(vecSpc);
00668     z  = createMember(vecSpc);
00669     const Scalar alpha = as<Scalar>(1.2345);
00670     const Scalar beta = as<Scalar>(5.4321);
00671     seed_randomize<Scalar>(12345);
00672     randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v1.ptr());
00673     randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
00674     V_StVpStV(v3.ptr(),alpha,*v1,beta,*v2);
00675     V_StV(z.ptr(),alpha,*v1);
00676     Vp_StV(z.ptr(),beta,*v2);
00677     V_V(x.ptr(),*v3);
00678     Vp_V(x.ptr(),*z,as<Scalar>(-ST::one()));
00679     if(!testMaxErr<Scalar>(
00680          "norm_2(*x)",norm_2(*x)
00681          ,"10*error_tol",ScalarMag(ScalarMag(10)*error_tol()),"warning_tol",warning_tol(),&out
00682         )
00683       ) success=false;
00684   }
00685 
00686   // Test Vp_V
00687   out << "\n"<<tc<<") Testing Vp_V(v1.ptr(),*v2,beta) ...\n";
00688   ++tc;
00689   {
00690     v1 = createMember(vecSpc);
00691     v2 = createMember(vecSpc);
00692     v3 = createMember(vecSpc);
00693     x  = createMember(vecSpc);
00694     z  = createMember(vecSpc);
00695     const Scalar alpha = as<Scalar>(-2.0);
00696     const Scalar beta = as<Scalar>(10.0);
00697     V_S(v1.ptr(),alpha);
00698     seed_randomize<Scalar>(12345);
00699     randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
00700     Vp_V(v1.ptr(),*v2,beta); 
00701     V_S(v3.ptr(),alpha);
00702     V_StVpV(z.ptr(),beta,*v3,*v2);
00703     V_StVpV(x.ptr(),as<Scalar>(-ST::one()),*z,*v1);
00704     if(!testMaxErr<Scalar>(
00705          "norm_2(*x)",norm_2(*x)
00706          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00707         )
00708       ) success=false;
00709   }
00710   
00711   // Test Vp_V
00712   out << "\n"<<tc<<") Testing Vp_V(v1.ptr(),*v2) ...\n";
00713   ++tc;
00714   {
00715     v1 = createMember(vecSpc);
00716     v2 = createMember(vecSpc);
00717     v3 = createMember(vecSpc);
00718     x  = createMember(vecSpc);
00719     z  = createMember(vecSpc);
00720     const Scalar alpha = as<Scalar>(-2.0);
00721     V_S(v1.ptr(),alpha);
00722     seed_randomize<Scalar>(12345);
00723     randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
00724     Vp_V(v1.ptr(),*v2); 
00725     V_S(v3.ptr(),alpha);
00726     V_StVpV(z.ptr(),ST::one(),*v3,*v2);
00727     V_StVpV(x.ptr(),as<Scalar>(-ST::one()),*z,*v1);
00728     if(!testMaxErr<Scalar>(
00729          "norm_2(*x)",norm_2(*x)
00730          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00731         )
00732       ) success=false;
00733   }
00734 
00735   // Test V_S
00736   out << "\n"<<tc<<") Testing V_S(v1.ptr(),alpha) ...\n";
00737   ++tc;
00738   {
00739     v1 = createMember(vecSpc);
00740     v2 = createMember(vecSpc);
00741     z  = createMember(vecSpc);
00742     const Scalar alpha = as<Scalar>(1.2345);
00743     assign(v1.ptr(),alpha);
00744     V_S(v2.ptr(),alpha);
00745     V_StVpV(z.ptr(),as<Scalar>(-ST::one()),*v1,*v2);
00746     if(!testMaxErr<Scalar>(
00747          "norm_2(*z)",norm_2(*z)
00748          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00749         )
00750       ) success=false;
00751   }
00752   
00753   // Test V_V
00754   out << "\n"<<tc<<") Testing V_V(v1.ptr(),*v2) ...\n";
00755   ++tc;
00756   {
00757     v1 = createMember(vecSpc);
00758     v2 = createMember(vecSpc);
00759     z  = createMember(vecSpc);
00760     seed_randomize<Scalar>(12345);
00761     randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v1.ptr());
00762     V_V(v2.ptr(),*v1);
00763     V_StVpV(z.ptr(),as<Scalar>(-ST::one()),*v1,*v2);
00764     if(!testMaxErr<Scalar>(
00765          "norm_2(*z)",norm_2(*z)
00766          ,"error_tol",error_tol(),"warning_tol",warning_tol(),&out
00767         )
00768       ) success=false;
00769   }
00770 
00771   // ToDo: Add tests for *all* standard operators!
00772 
00773   out << "\n*** Leaving VectorStdOpsTester<"<<ST::name()<<">::checkStdOps(...) ...\n";
00774 
00775   return success;
00776 
00777 
00778 }
00779 
00780 
00781 } // namespace Thyra
00782 
00783 
00784 #endif // THYRA_VECTOR_STD_OPS_TESTER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines