42 #ifndef THYRA_VECTOR_STD_OPS_TESTER_HPP
43 #define THYRA_VECTOR_STD_OPS_TESTER_HPP
45 #include "Thyra_VectorStdOpsTester_decl.hpp"
46 #include "Thyra_TestingTools.hpp"
47 #include "RTOpPack_TOpSetAssendingValues.hpp"
48 #include "Teuchos_TestingHelpers.hpp"
49 #include "Teuchos_Assert.hpp"
53 #ifdef THYRA_VECTOR_STD_OPS_TESTER_DUMP
54 # include "RTOpPack_SPMD_apply_op.hpp"
55 #endif // THYRA_VECTOR_STD_OPS_TESTER_DUMP
64 template <
bool isComparable,
class Scalar>
65 class VectorStdOpsTesterComparable {
67 static bool checkComparableStdOps(
68 const VectorSpaceBase<Scalar> &vecSpc,
69 const Ptr<VectorBase<Scalar> > &z,
72 const Ptr<std::ostream> &out,
81 template <
class Scalar>
82 class VectorStdOpsTesterComparable<false,Scalar> {
84 static bool checkComparableStdOps(
85 const VectorSpaceBase<Scalar> &vecSpc,
86 const Ptr<VectorBase<Scalar> > &z,
89 const Ptr<std::ostream> &out,
94 <<
"\nThis scalar type does not support comparable operations so"
95 <<
" we can not test min(), max() and other such functions.\n";
101 template <
class Scalar>
102 class VectorStdOpsTesterComparable<true,Scalar> {
104 static bool checkComparableStdOps(
105 const VectorSpaceBase<Scalar> &vecSpc,
106 const Ptr<VectorBase<Scalar> > &z,
109 const Ptr<std::ostream> &out,
114 using Teuchos::outArg;
116 bool success =
true, result;
118 if (
nonnull(out)) *out <<
"\nTesting comparable operations ...\n";
120 const Scalar scalarSmall(1e-5), scalarMedium(2.0), scalarLarge(100.0);
121 if (
nonnull(out)) *out <<
"\nassign(z.ptr(),"<<scalarMedium<<
");\n";
122 assign(z.ptr(),Scalar(scalarMedium));
123 if(
nonnull(out) && dumpAll) *out <<
"\nz =\n" << *z;
124 if (
nonnull(out)) *out <<
"\nset_ele(0,"<<scalarSmall<<
",z.ptr());\n";
125 set_ele(0,scalarSmall,z.ptr());
126 if(
nonnull(out) && dumpAll) *out <<
"\nz =\n" << *z;
127 if (
nonnull(out)) *out <<
"\nset_ele(1,"<<scalarLarge<<
",z.ptr());\n";
128 set_ele(1,scalarLarge,z.ptr());
129 if(
nonnull(out) && dumpAll) *out <<
"\nz =\n" << *z;
130 if (
nonnull(out)) *out <<
"\nset_ele(vecSpc.dim()-2,"<<scalarSmall<<
",z.ptr());\n";
131 set_ele(vecSpc.dim()-2,scalarSmall,z.ptr());
132 if(
nonnull(out) && dumpAll) *out <<
"\nz =\n" << *z;
133 if (
nonnull(out)) *out <<
"\nset_ele(vecSpc.dim()-1,"<<scalarLarge<<
",z.ptr());\n";
134 set_ele(vecSpc.dim()-1,scalarLarge,z.ptr());
135 if(
nonnull(out) && dumpAll) *out <<
"\nz =\n" << *z;
137 Scalar minEle;
Ordinal minIndex;
138 Scalar maxEle;
Ordinal maxIndex;
140 if(!Teuchos::testRelErr<Scalar>(
141 "min(*z)",min(*z),
"scalarSmall",scalarSmall
142 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out
146 if (
nonnull(out)) *out <<
"\nmin(*z,&minEle,&minIndex);\n";
147 minEle = ST::zero(); minIndex = 0;
148 min(*z, outArg(minEle), outArg(minIndex));
149 if(!Teuchos::testRelErr<Scalar>(
150 "minEle",minEle,
"scalarSmall",scalarSmall
151 ,
"error_tol",error_tol,
"warning_tol",warning_tol, out
154 result = minIndex == 0;
155 if (
nonnull(out)) *out <<
"\nminIndex = " << minIndex <<
" == 0 ? " <<
passfail(result) << std::endl;
156 if(!result) success =
false;
158 if (
nonnull(out)) *out <<
"\nminGreaterThanBound(*z,"<<scalarMedium<<
",&minEle,&minIndex);\n";
159 minEle = ST::zero(); minIndex = 0;
160 minGreaterThanBound(*z, scalarMedium, outArg(minEle), outArg(minIndex));
161 if(!Teuchos::testRelErr<Scalar>(
162 "minEle",minEle,
"scalarLarge",scalarLarge
163 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out
166 result = minIndex == 1;
167 if (
nonnull(out)) *out <<
"\nminIndex = " << minIndex <<
" == 1 ? " <<
passfail(result) << std::endl;
168 if(!result) success =
false;
170 if (
nonnull(out)) *out <<
"\nminGreaterThanBound(*z,"<<scalarLarge<<
",&minEle,&minIndex);\n";
171 minEle = ST::zero(); minIndex = 0;
172 minGreaterThanBound(*z,scalarLarge, outArg(minEle), outArg(minIndex));
173 result = minIndex < 0;
174 if (
nonnull(out)) *out <<
"\nminIndex = " << minIndex <<
" < 0 ? " <<
passfail(result) << std::endl;
175 if(!result) success =
false;
177 if(!Teuchos::testRelErr<Scalar>(
178 "max(*z)",max(*z),
"scalarLarge",scalarLarge
179 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out)
182 if (
nonnull(out)) *out <<
"\nmax(*z,&maxEle,&maxIndex);\n";
183 maxEle = ST::zero(); maxIndex = 0;
184 max(*z, outArg(maxEle), outArg(maxIndex));
185 if(!Teuchos::testRelErr<Scalar>(
186 "maxEle",maxEle,
"scalarLarge",scalarLarge
187 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out)
189 result = maxIndex == 1;
190 if (
nonnull(out)) *out <<
"\nmaxIndex = " << maxIndex <<
" == 1 ? " <<
passfail(result) << std::endl;
191 if(!result) success =
false;
193 if (
nonnull(out)) *out <<
"\nmaxLessThanBound(*z,"<<scalarMedium<<
",&maxEle,&maxIndex);\n";
194 maxEle = ST::zero(); maxIndex = 0;
195 maxLessThanBound(*z, scalarMedium, outArg(maxEle), outArg(maxIndex));
196 if(!Teuchos::testRelErr<Scalar>(
197 "maxEle",maxEle,
"scalarSmall",scalarSmall
198 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out)
200 result = maxIndex == 0;
201 if (
nonnull(out)) *out <<
"\nmaxIndex = " << maxIndex <<
" == 0 ? " <<
passfail(result) << std::endl;
202 if(!result) success =
false;
204 if (
nonnull(out)) *out <<
"\nmaxLessThanBound(*z,"<<scalarSmall<<
",&maxEle,&maxIndex);\n";
205 maxEle = ST::zero(); maxIndex = 0;
206 maxLessThanBound(*z, scalarSmall, outArg(maxEle), outArg(maxIndex));
207 result = ( maxIndex < 0 );
208 if (
nonnull(out)) *out <<
"\nmaxIndex = " << maxIndex <<
" < 0 ? " <<
passfail(result) << std::endl;
209 if(!result) success =
false;
213 if (
nonnull(out)) *out <<
"\nTesting pair_wise_max(*v1, *v2, z0.ptr()) ...\n";
216 using Teuchos::tuple;
218 using Teuchos::outArg;
219 using Teuchos::inOutArg;
224 const Scalar alpha = as<Scalar>(2.0);
225 seed_randomize<Scalar>(12345);
226 randomize(as<Scalar>(-ST::one()),ST::one(),v1.ptr());
227 randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr());
230 pair_wise_max(alpha, *v1, *v2, z0.ptr());
232 V_VpV(v3.ptr(), *v1, *v2);
233 Vp_V(v1.ptr(), *v2, as<Scalar>(-ST::one()));
238 Vp_V(z0.ptr(), *v3, as<Scalar>(-ST::one()));
239 if(!testMaxErr<Scalar>(
240 "norm_2(*z0)",norm_2(*z0)
241 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out.get()
254 template<
class Scalar>
255 void setEleTestCase(
const Ptr<VectorBase<Scalar> > &z,
const Ordinal i,
int &tc,
256 std::ostream &out,
bool &success)
259 out <<
"\n"<<tc<<
") set_ele(z, "<<i<<
");\n";
262 typedef ScalarTraits<Scalar> ST;
263 const Scalar val_i = as<Scalar>(i+1);
264 assign<Scalar>(z, ST::zero());
265 set_ele(i, val_i, z);
275 template <
class Scalar>
280 :warning_tol_(warning_tol_in),
281 error_tol_(error_tol_in)
285 template <
class Scalar>
288 std::ostream *out_out,
293 using Teuchos::tuple;
295 using Teuchos::outArg;
296 using Teuchos::inOutArg;
300 std::ostream &out = *out_out;
302 out <<
"\n*** Entering VectorStdOpsTester<"<<ST::name()<<
">::checkStdOps(...) ...\n"
303 <<
"using a \'" << vecSpc.
description() <<
"\' object ...\n";
306 out <<
"\nvecSpc.dim() = " << vecSpc.
dim() << std::endl;
311 "Error: n = "<<n<<
" must be least 4 or greater to"
312 " run Thyra::VectorStdOpsTester::checkStdOps(...)!" );
315 two = as<Scalar>(2.0),
316 three = as<Scalar>(3.0),
317 four = as<Scalar>(4.0);
321 out <<
"\nCreating vectors v1, v2, v3, v4, x and z ...\n";
323 v1 = createMember(vecSpc),
324 v2 = createMember(vecSpc),
325 v3 = createMember(vecSpc),
326 v4 = createMember(vecSpc),
327 y = createMember(vecSpc),
328 x = createMember(vecSpc),
329 z = createMember(vecSpc);
331 out <<
"\nassign(v1.ptr(), -2.0);\n";
332 assign<Scalar>(v1.
ptr(), -two);
333 out <<
"\nassign(v2.ptr(), -3.0);\n";
334 assign<Scalar>(v2.ptr(), -three);
335 out <<
"\nassign(v3.ptr(), -4.0);\n";
336 assign<Scalar>(v3.ptr(), -four);
337 out <<
"\ny[i] = i+1\n";
340 applyOp<Scalar>( setAssendOp,
347 out <<
"\n"<<tc<<
") sum(*y);\n";
350 Teuchos::testRelErr<Scalar>(
352 "0.5*(n+1)*n", as<Scalar>(0.5*(n+1)*n),
353 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out)),
357 out <<
"\n"<<tc<<
") nom_inf(*v1);\n";
360 Teuchos::testRelErr<Scalar>(
361 "norm_inf(*v1)", norm_inf(*v1),
363 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out)),
367 out <<
"\n"<<tc<<
") norm_2(*v1);\n";
370 Teuchos::testRelErr<Scalar>(
371 "norm_2(*v1)", norm_2(*v1),
372 "2.0*sqrt(vecSpc.dim())", as<Scalar>(2.0)*ST::squareroot(vecSpc.
dim()),
373 "error_tol", error_tol(),
"warning_tol",warning_tol(), inOutArg(out)),
377 out <<
"\n"<<tc<<
") norm_1(*v1);\n";
380 Teuchos::testRelErr<Scalar>(
381 "norm_1(*v1)" ,norm_1(*v1),
382 "2.0*vecSpc.dim()", as<Scalar>(2.0)*as<Scalar>(vecSpc.
dim()),
383 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out)),
387 out <<
"\n"<<tc<<
") abs(z.ptr(),*v1);\n";
390 abs<Scalar>(*v1, z.
ptr());
391 if(!Teuchos::testRelErr<Scalar>(
392 "sum(*z)", sum(*z),
"2.0*vecSpc.dim()", as<Scalar>(2.0)*as<Scalar>(vecSpc.
dim()),
393 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out))
399 out <<
"\n"<<tc<<
") val = get_ele(y, 0);\n";
402 const Scalar val = get_ele<Scalar>(*y, 0);
406 out <<
"\n"<<tc<<
") val = get_ele<Scalar>(*y, 1);\n";
409 const Scalar val = get_ele<Scalar>(*y, 1);
413 out <<
"\n"<<tc<<
") val = get_ele<Scalar>(*y, n-2);\n";
416 const Scalar val = get_ele<Scalar>(*y, n-2);
420 out <<
"\n"<<tc<<
") val = get_ele<Scalar>(*y, n-1);\n";
423 const Scalar val = get_ele<Scalar>(*y, n-1);
429 out <<
"\n"<<tc<<
") get_ele<Scalar>(*y, -1);\n";
435 out <<
"\n"<<tc<<
") get_ele<Scalar>(*y, n);\n";
441 #endif // THYRA_DEBUG
445 setEleTestCase<Scalar>(z.ptr(), 0, tc, out, success);
447 setEleTestCase<Scalar>(z.ptr(), 1, tc, out, success);
449 setEleTestCase<Scalar>(z.ptr(), n-2, tc, out, success);
451 setEleTestCase<Scalar>(z.ptr(), n-1, tc, out, success);
456 std::out_of_range, out, success);
458 TEUCHOS_TEST_THROW(set_ele(n, two, z.ptr()),
459 std::out_of_range, out, success);
461 #endif // THYRA_DEBUG
464 out <<
"\n"<<tc<<
") reciprocal(z.ptr(),*v1);\n";
467 reciprocal(*v1, z.
ptr());
468 if(!Teuchos::testRelErr<Scalar>(
469 "sum(*z)",sum(*z),
"-0.5*vecSpc.dim()",as<Scalar>(-0.5)*as<Scalar>(vecSpc.
dim())
470 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),inOutArg(out))
476 out <<
"\n"<<tc<<
") linear_combination(2,{0.5,0.25},{v1.ptr(),v2.ptr()},0.0,z.ptr());\n";
479 linear_combination<Scalar>(
480 tuple<Scalar>(0.5, 0.25)(),
485 Teuchos::testRelErr<Scalar>(
487 "(-0.5*2.0-0.25*3.0)*vecSpc.dim()", as<Scalar>((-0.5 * 2.0 - 0.25 * 3.0) *vecSpc.
dim()),
488 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out)),
492 out <<
"\nassign(z.ptr(), 2.0);\n";
494 assign(z.ptr(), as<Scalar>(2.0));
496 out <<
"\n"<<tc<<
") linear_combination(3,{0.5,0.25,0.125},{v1.ptr(),v2.ptr(),v2.ptr()},0.5,z.ptr());\n";
499 linear_combination<Scalar>(
500 tuple<Scalar>(0.5, 0.25, 0.125)(),
504 if(!Teuchos::testRelErr<Scalar>(
506 "(0.5*2.0-0.5*2.0-0.25*3.0-0.125*4.0)*vecSpc.dim()",
507 as<Scalar>(0.5*2.0-0.5*2.0-0.25*3.0-0.125*4.0)*as<Scalar>(vecSpc.
dim()),
508 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out)
514 out <<
"\n"<<tc<<
") assign(z.ptr(),2.0);\n";
517 assign(z.ptr(),as<Scalar>(2.0));
518 if(!Teuchos::testRelErr<Scalar>(
519 "norm_2(*z,*v2)",norm_2(*z,*v2)
520 ,
"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())))
521 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),inOutArg(out)
525 if(!VectorStdOpsTesterComparable<ST::isComparable,Scalar>::checkComparableStdOps(
526 vecSpc,z.ptr(),error_tol(),warning_tol(),inOutArg(out),dumpAll)
531 out <<
"\n"<<tc<<
") Testing Vt_S(z.ptr(),alpha) ...\n";
534 #ifdef THYRA_VECTOR_STD_OPS_TESTER_DUMP
535 RTOpPack::show_spmd_apply_op_dump =
true;
536 #endif // THYRA_VECTOR_STD_OPS_TESTER_DUMP
537 v1 = createMember(vecSpc);
538 v2 = createMember(vecSpc);
539 const Scalar alpha = as<Scalar>(1.2345);
540 seed_randomize<Scalar>(12345);
541 randomize(as<Scalar>(-ST::one()),ST::one(),v1.
ptr());
543 Vt_S(v1.
ptr(), alpha);
544 const Scalar norm_alpha_v1 = norm_2(*v1);
546 const Scalar mag_alpha = ST::magnitude(alpha);
548 const Scalar norm_2_v2 = norm_2(*v2);
550 const Scalar alpha_norm_v1 = mag_alpha * norm_2_v2;
552 if(!testMaxErr<Scalar>(
553 "norm_alpha_v1 - alpha_norm_v1",ST::magnitude(norm_alpha_v1-alpha_norm_v1)
554 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
557 #ifdef THYRA_VECTOR_STD_OPS_TESTER_DUMP
558 RTOpPack::show_spmd_apply_op_dump =
false;
559 #endif // THYRA_VECTOR_STD_OPS_TESTER_DUMP
563 out <<
"\n"<<tc<<
") Testing V_StV(z.ptr(),alpha,*v) ...\n";
566 v1 = createMember(vecSpc);
567 v2 = createMember(vecSpc);
568 z = createMember(vecSpc);
569 const Scalar alpha = as<Scalar>(-1.2345);
570 seed_randomize<Scalar>(12345);
571 randomize(as<Scalar>(-ST::one()),ST::one(),v1.
ptr());
572 V_StV(v2.ptr(),alpha,*v1);
573 Vt_S(v1.
ptr(),alpha);
575 Vp_V(z.ptr(),*v2,as<Scalar>(-ST::one()));
576 if(!testMaxErr<Scalar>(
577 "norm_2(*z)",norm_2(*z)
578 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
584 out <<
"\n"<<tc<<
") Testing Vp_StV(z.ptr(),alpha,*v) ...\n";
587 v1 = createMember(vecSpc);
588 v2 = createMember(vecSpc);
589 v3 = createMember(vecSpc);
590 z = createMember(vecSpc);
591 const Scalar alpha = as<Scalar>(-1.2345);
592 seed_randomize<Scalar>(12345);
593 randomize(as<Scalar>(-ST::one()),ST::one(),v1.
ptr());
594 randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr());
596 Vp_StV(v1.
ptr(),alpha,*v2);
597 V_StV(z.ptr(),alpha,*v2);
600 Vp_V(v3.ptr(),*z,as<Scalar>(-ST::one()));
601 if(!testMaxErr<Scalar>(
602 "norm_2(*v3)",norm_2(*v3)
603 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
609 out <<
"\n"<<tc<<
") Testing ele_wise_prod(alpha,*v1, *v2, z.ptr()) ...\n";
612 v1 = createMember(vecSpc);
613 v2 = createMember(vecSpc);
614 v3 = createMember(vecSpc);
615 z = createMember(vecSpc);
616 const Scalar alpha = as<Scalar>(-1.2345);
617 seed_randomize<Scalar>(12345);
618 randomize(as<Scalar>(-ST::one()),ST::one(),v1.
ptr());
619 randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr());
620 randomize(as<Scalar>(-ST::one()),ST::one(),v3.ptr());
623 ele_wise_prod(alpha, *v2, *v3, v1.
ptr());
624 ele_wise_prod_update(alpha, *v3, z.ptr());
627 Vp_V(v2.ptr(), *z, as<Scalar>(-ST::one()));
628 if(!testMaxErr<Scalar>(
629 "norm_2(*v2)",norm_2(*v2)
630 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
637 out <<
"\n"<<tc<<
") Testing ele_wise_scale(*v1, z.ptr()) ...\n";
640 v1 = createMember(vecSpc);
641 z = createMember(vecSpc);
642 V_S(v1.
ptr(), as<Scalar>(2.0));
643 V_S(z.ptr(), as<Scalar>(3.0));
644 ele_wise_scale( *v1, z.
ptr() );
645 if (!Teuchos::testRelErr<Scalar>(
646 "norm_2(*z)", norm_2(*z),
647 "ST::squareroot(n*sqr(3.0*2.0))", ST::squareroot(n*36.0),
648 "error_tol", error_tol(),
649 "warning_tol", warning_tol(),
656 out <<
"\n"<<tc<<
") Testing Vt_StV(z.ptr(), alpha, *v) ...\n";
659 v1 = createMember(vecSpc);
660 v2 = createMember(vecSpc);
661 v3 = createMember(vecSpc);
662 z = createMember(vecSpc);
663 const Scalar alpha = as<Scalar>(-1.2345);
664 seed_randomize<Scalar>(12345);
665 randomize(as<Scalar>(-ST::one()),ST::one(),v1.
ptr());
666 randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr());
668 Vt_StV(v1.
ptr(),alpha,*v2);
669 V_S(z.ptr(),ST::zero());
670 Vp_StVtV(z.ptr(),alpha,*v3,*v2);
672 Vp_V(v2.ptr(),*z,as<Scalar>(-ST::one()));
673 if(!testMaxErr<Scalar>(
674 "norm_2(*v2)",norm_2(*v2)
675 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
681 out <<
"\n"<<tc<<
") Testing V_StVpV(z.ptr(),alpha,*v1,*v2) ...\n";
684 v1 = createMember(vecSpc);
685 v2 = createMember(vecSpc);
686 v3 = createMember(vecSpc);
687 x = createMember(vecSpc);
688 z = createMember(vecSpc);
689 const Scalar alpha = as<Scalar>(1.2345);
690 seed_randomize<Scalar>(12345);
691 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v1.
ptr());
692 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
693 V_StVpV(v3.ptr(),alpha,*v1,*v2);
695 Vp_V(z.ptr(),*v2,alpha);
697 Vp_V(x.ptr(),*z,as<Scalar>(-ST::one()));
698 if(!testMaxErr<Scalar>(
699 "norm_2(*x)",norm_2(*x)
700 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
706 out <<
"\n"<<tc<<
") Testing V_VpStV(z.ptr(),*v1,alpha,*v2) ...\n";
709 v1 = createMember(vecSpc);
710 v2 = createMember(vecSpc);
711 v3 = createMember(vecSpc);
712 x = createMember(vecSpc);
713 z = createMember(vecSpc);
714 const Scalar alpha = as<Scalar>(1.2345);
715 seed_randomize<Scalar>(12345);
716 randomize<Scalar>(as<Scalar>(as<Scalar>(-10)*ST::one()),
717 as<Scalar>(as<Scalar>(10)*ST::one()), v1.
ptr());
718 randomize<Scalar>(as<Scalar>(as<Scalar>(-10)*ST::one()),
719 as<Scalar>(as<Scalar>(10)*ST::one()), v2.ptr());
720 V_VpStV(outArg(*v3), *v1, alpha, *v2);
722 Vp_StV(z.ptr(), alpha, *v2);
723 V_VmV(outArg(*x), *z, *v3);
724 if(!testMaxErr<Scalar>(
725 "norm_2(*x)",norm_2(*x)
726 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
732 out <<
"\n"<<tc<<
") Testing V_StVpStV(z.ptr(),alpha,*v1,beta,*v2) ...\n";
735 v1 = createMember(vecSpc);
736 v2 = createMember(vecSpc);
737 v3 = createMember(vecSpc);
738 x = createMember(vecSpc);
739 z = createMember(vecSpc);
740 const Scalar alpha = as<Scalar>(1.2345);
741 const Scalar beta = as<Scalar>(5.4321);
742 seed_randomize<Scalar>(12345);
743 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v1.
ptr());
744 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
745 V_StVpStV(v3.ptr(),alpha,*v1,beta,*v2);
746 V_StV(z.ptr(),alpha,*v1);
747 Vp_StV(z.ptr(),beta,*v2);
749 Vp_V(x.ptr(),*z,as<Scalar>(-ST::one()));
750 if(!testMaxErr<Scalar>(
751 "norm_2(*x)",norm_2(*x)
758 out <<
"\n"<<tc<<
") Testing Vp_V(v1.ptr(),*v2,beta) ...\n";
761 v1 = createMember(vecSpc);
762 v2 = createMember(vecSpc);
763 v3 = createMember(vecSpc);
764 x = createMember(vecSpc);
765 z = createMember(vecSpc);
766 const Scalar alpha = as<Scalar>(-2.0);
767 const Scalar beta = as<Scalar>(10.0);
769 seed_randomize<Scalar>(12345);
770 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
771 Vp_V(v1.
ptr(),*v2,beta);
773 V_StVpV(z.ptr(),beta,*v3,*v2);
774 V_StVpV(x.ptr(),as<Scalar>(-ST::one()),*z,*v1);
775 if(!testMaxErr<Scalar>(
776 "norm_2(*x)",norm_2(*x)
777 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
783 out <<
"\n"<<tc<<
") Testing Vp_V(v1.ptr(),*v2) ...\n";
786 v1 = createMember(vecSpc);
787 v2 = createMember(vecSpc);
788 v3 = createMember(vecSpc);
789 x = createMember(vecSpc);
790 z = createMember(vecSpc);
791 const Scalar alpha = as<Scalar>(-2.0);
793 seed_randomize<Scalar>(12345);
794 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
797 V_StVpV(z.ptr(),ST::one(),*v3,*v2);
798 V_StVpV(x.ptr(),as<Scalar>(-ST::one()),*z,*v1);
799 if(!testMaxErr<Scalar>(
800 "norm_2(*x)",norm_2(*x)
801 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
807 out <<
"\n"<<tc<<
") Testing V_S(v1.ptr(),alpha) ...\n";
810 v1 = createMember(vecSpc);
811 v2 = createMember(vecSpc);
812 z = createMember(vecSpc);
813 const Scalar alpha = as<Scalar>(1.2345);
814 assign(v1.
ptr(),alpha);
816 V_StVpV(z.ptr(),as<Scalar>(-ST::one()),*v1,*v2);
817 if(!testMaxErr<Scalar>(
818 "norm_2(*z)",norm_2(*z)
819 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
825 out <<
"\n"<<tc<<
") Testing V_V(v1.ptr(),*v2) ...\n";
828 v1 = createMember(vecSpc);
829 v2 = createMember(vecSpc);
830 z = createMember(vecSpc);
831 seed_randomize<Scalar>(12345);
832 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v1.
ptr());
834 V_StVpV(z.ptr(),as<Scalar>(-ST::one()),*v1,*v2);
835 if(!testMaxErr<Scalar>(
836 "norm_2(*z)",norm_2(*z)
837 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
844 out <<
"\n*** Leaving VectorStdOpsTester<"<<ST::name()<<
">::checkStdOps(...) ...\n";
855 #endif // THYRA_VECTOR_STD_OPS_TESTER_HPP
VectorStdOpsTester(const ScalarMag &warning_tol=0, const ScalarMag &error_tol=0)
const std::string passfail(const bool result)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Abstract interface for objects that represent a space for vectors.
KOKKOS_INLINE_FUNCTION RealType abs(const complex< RealType > &x)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
#define TEUCHOS_TEST_ASSERT(v1, out, success)
virtual std::string description() const
Abstract interface for finite-dimensional dense vectors.
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
bool nonnull(const boost::shared_ptr< T > &p)
TypeTo as(const TypeFrom &t)
bool checkStdOps(const VectorSpaceBase< Scalar > &vecSpc, std::ostream *out=0, const bool &dumpAll=false)
Run the tests using a vector space.
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_EQUALITY_CONST(v1, v2, out, success)
#define TEUCHOS_TEST_THROW(code, ExceptType, out, success)
virtual Ordinal dim() const =0
Return the dimension of the vector space.