10 #ifndef THYRA_VECTOR_STD_OPS_TESTER_HPP
11 #define THYRA_VECTOR_STD_OPS_TESTER_HPP
13 #include "Thyra_VectorStdOpsTester_decl.hpp"
14 #include "Thyra_TestingTools.hpp"
15 #include "RTOpPack_TOpSetAssendingValues.hpp"
16 #include "Teuchos_TestingHelpers.hpp"
17 #include "Teuchos_Assert.hpp"
21 #ifdef THYRA_VECTOR_STD_OPS_TESTER_DUMP
22 # include "RTOpPack_SPMD_apply_op.hpp"
23 #endif // THYRA_VECTOR_STD_OPS_TESTER_DUMP
32 template <
bool isComparable,
class Scalar>
33 class VectorStdOpsTesterComparable {
35 static bool checkComparableStdOps(
36 const VectorSpaceBase<Scalar> &vecSpc,
37 const Ptr<VectorBase<Scalar> > &z,
40 const Ptr<std::ostream> &out,
49 template <
class Scalar>
50 class VectorStdOpsTesterComparable<false,Scalar> {
52 static bool checkComparableStdOps(
53 const VectorSpaceBase<Scalar> &vecSpc,
54 const Ptr<VectorBase<Scalar> > &z,
57 const Ptr<std::ostream> &out,
62 <<
"\nThis scalar type does not support comparable operations so"
63 <<
" we can not test min(), max() and other such functions.\n";
69 template <
class Scalar>
70 class VectorStdOpsTesterComparable<true,Scalar> {
72 static bool checkComparableStdOps(
73 const VectorSpaceBase<Scalar> &vecSpc,
74 const Ptr<VectorBase<Scalar> > &z,
77 const Ptr<std::ostream> &out,
82 using Teuchos::outArg;
84 bool success =
true, result;
86 if (
nonnull(out)) *out <<
"\nTesting comparable operations ...\n";
88 const Scalar scalarSmall(1e-5), scalarMedium(2.0), scalarLarge(100.0);
89 if (
nonnull(out)) *out <<
"\nassign(z.ptr(),"<<scalarMedium<<
");\n";
90 assign(z.ptr(),Scalar(scalarMedium));
91 if(
nonnull(out) && dumpAll) *out <<
"\nz =\n" << *z;
92 if (
nonnull(out)) *out <<
"\nset_ele(0,"<<scalarSmall<<
",z.ptr());\n";
93 set_ele(0,scalarSmall,z.ptr());
94 if(
nonnull(out) && dumpAll) *out <<
"\nz =\n" << *z;
95 if (
nonnull(out)) *out <<
"\nset_ele(1,"<<scalarLarge<<
",z.ptr());\n";
96 set_ele(1,scalarLarge,z.ptr());
97 if(
nonnull(out) && dumpAll) *out <<
"\nz =\n" << *z;
98 if (
nonnull(out)) *out <<
"\nset_ele(vecSpc.dim()-2,"<<scalarSmall<<
",z.ptr());\n";
99 set_ele(vecSpc.dim()-2,scalarSmall,z.ptr());
100 if(
nonnull(out) && dumpAll) *out <<
"\nz =\n" << *z;
101 if (
nonnull(out)) *out <<
"\nset_ele(vecSpc.dim()-1,"<<scalarLarge<<
",z.ptr());\n";
102 set_ele(vecSpc.dim()-1,scalarLarge,z.ptr());
103 if(
nonnull(out) && dumpAll) *out <<
"\nz =\n" << *z;
105 Scalar minEle;
Ordinal minIndex;
106 Scalar maxEle;
Ordinal maxIndex;
108 if(!Teuchos::testRelErr<Scalar>(
109 "min(*z)",min(*z),
"scalarSmall",scalarSmall
110 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out
114 if (
nonnull(out)) *out <<
"\nmin(*z,&minEle,&minIndex);\n";
115 minEle = ST::zero(); minIndex = 0;
116 min(*z, outArg(minEle), outArg(minIndex));
117 if(!Teuchos::testRelErr<Scalar>(
118 "minEle",minEle,
"scalarSmall",scalarSmall
119 ,
"error_tol",error_tol,
"warning_tol",warning_tol, out
122 result = minIndex == 0;
123 if (
nonnull(out)) *out <<
"\nminIndex = " << minIndex <<
" == 0 ? " <<
passfail(result) << std::endl;
124 if(!result) success =
false;
126 if (
nonnull(out)) *out <<
"\nminGreaterThanBound(*z,"<<scalarMedium<<
",&minEle,&minIndex);\n";
127 minEle = ST::zero(); minIndex = 0;
128 minGreaterThanBound(*z, scalarMedium, outArg(minEle), outArg(minIndex));
129 if(!Teuchos::testRelErr<Scalar>(
130 "minEle",minEle,
"scalarLarge",scalarLarge
131 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out
134 result = minIndex == 1;
135 if (
nonnull(out)) *out <<
"\nminIndex = " << minIndex <<
" == 1 ? " <<
passfail(result) << std::endl;
136 if(!result) success =
false;
138 if (
nonnull(out)) *out <<
"\nminGreaterThanBound(*z,"<<scalarLarge<<
",&minEle,&minIndex);\n";
139 minEle = ST::zero(); minIndex = 0;
140 minGreaterThanBound(*z,scalarLarge, outArg(minEle), outArg(minIndex));
141 result = minIndex < 0;
142 if (
nonnull(out)) *out <<
"\nminIndex = " << minIndex <<
" < 0 ? " <<
passfail(result) << std::endl;
143 if(!result) success =
false;
145 if(!Teuchos::testRelErr<Scalar>(
146 "max(*z)",max(*z),
"scalarLarge",scalarLarge
147 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out)
150 if (
nonnull(out)) *out <<
"\nmax(*z,&maxEle,&maxIndex);\n";
151 maxEle = ST::zero(); maxIndex = 0;
152 max(*z, outArg(maxEle), outArg(maxIndex));
153 if(!Teuchos::testRelErr<Scalar>(
154 "maxEle",maxEle,
"scalarLarge",scalarLarge
155 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out)
157 result = maxIndex == 1;
158 if (
nonnull(out)) *out <<
"\nmaxIndex = " << maxIndex <<
" == 1 ? " <<
passfail(result) << std::endl;
159 if(!result) success =
false;
161 if (
nonnull(out)) *out <<
"\nmaxLessThanBound(*z,"<<scalarMedium<<
",&maxEle,&maxIndex);\n";
162 maxEle = ST::zero(); maxIndex = 0;
163 maxLessThanBound(*z, scalarMedium, outArg(maxEle), outArg(maxIndex));
164 if(!Teuchos::testRelErr<Scalar>(
165 "maxEle",maxEle,
"scalarSmall",scalarSmall
166 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out)
168 result = maxIndex == 0;
169 if (
nonnull(out)) *out <<
"\nmaxIndex = " << maxIndex <<
" == 0 ? " <<
passfail(result) << std::endl;
170 if(!result) success =
false;
172 if (
nonnull(out)) *out <<
"\nmaxLessThanBound(*z,"<<scalarSmall<<
",&maxEle,&maxIndex);\n";
173 maxEle = ST::zero(); maxIndex = 0;
174 maxLessThanBound(*z, scalarSmall, outArg(maxEle), outArg(maxIndex));
175 result = ( maxIndex < 0 );
176 if (
nonnull(out)) *out <<
"\nmaxIndex = " << maxIndex <<
" < 0 ? " <<
passfail(result) << std::endl;
177 if(!result) success =
false;
181 if (
nonnull(out)) *out <<
"\nTesting pair_wise_max(*v1, *v2, z0.ptr()) ...\n";
184 using Teuchos::tuple;
186 using Teuchos::outArg;
187 using Teuchos::inOutArg;
192 const Scalar alpha = as<Scalar>(2.0);
193 seed_randomize<Scalar>(12345);
194 randomize(as<Scalar>(-ST::one()),ST::one(),v1.ptr());
195 randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr());
198 pair_wise_max(alpha, *v1, *v2, z0.ptr());
200 V_VpV(v3.ptr(), *v1, *v2);
201 Vp_V(v1.ptr(), *v2, as<Scalar>(-ST::one()));
206 Vp_V(z0.ptr(), *v3, as<Scalar>(-ST::one()));
207 if(!testMaxErr<Scalar>(
208 "norm_2(*z0)",norm_2(*z0)
209 ,
"error_tol",error_tol,
"warning_tol",warning_tol,out.get()
222 template<
class Scalar>
223 void setEleTestCase(
const Ptr<VectorBase<Scalar> > &z,
const Ordinal i,
int &tc,
224 std::ostream &out,
bool &success)
227 out <<
"\n"<<tc<<
") set_ele(z, "<<i<<
");\n";
230 typedef ScalarTraits<Scalar> ST;
231 const Scalar val_i = as<Scalar>(i+1);
232 assign<Scalar>(z, ST::zero());
233 set_ele(i, val_i, z);
243 template <
class Scalar>
248 :warning_tol_(warning_tol_in),
249 error_tol_(error_tol_in)
253 template <
class Scalar>
256 std::ostream *out_out,
261 using Teuchos::tuple;
263 using Teuchos::outArg;
264 using Teuchos::inOutArg;
268 std::ostream &out = *out_out;
270 out <<
"\n*** Entering VectorStdOpsTester<"<<ST::name()<<
">::checkStdOps(...) ...\n"
271 <<
"using a \'" << vecSpc.
description() <<
"\' object ...\n";
274 out <<
"\nvecSpc.dim() = " << vecSpc.
dim() << std::endl;
279 "Error: n = "<<n<<
" must be least 4 or greater to"
280 " run Thyra::VectorStdOpsTester::checkStdOps(...)!" );
283 two = as<Scalar>(2.0),
284 three = as<Scalar>(3.0),
285 four = as<Scalar>(4.0);
289 out <<
"\nCreating vectors v1, v2, v3, v4, x and z ...\n";
291 v1 = createMember(vecSpc),
292 v2 = createMember(vecSpc),
293 v3 = createMember(vecSpc),
294 v4 = createMember(vecSpc),
295 y = createMember(vecSpc),
296 x = createMember(vecSpc),
297 z = createMember(vecSpc);
299 out <<
"\nassign(v1.ptr(), -2.0);\n";
300 assign<Scalar>(v1.
ptr(), -two);
301 out <<
"\nassign(v2.ptr(), -3.0);\n";
302 assign<Scalar>(v2.ptr(), -three);
303 out <<
"\nassign(v3.ptr(), -4.0);\n";
304 assign<Scalar>(v3.ptr(), -four);
305 out <<
"\ny[i] = i+1\n";
308 applyOp<Scalar>( setAssendOp,
315 out <<
"\n"<<tc<<
") sum(*y);\n";
318 Teuchos::testRelErr<Scalar>(
320 "0.5*(n+1)*n", as<Scalar>(0.5*(n+1)*n),
321 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out)),
325 out <<
"\n"<<tc<<
") nom_inf(*v1);\n";
328 Teuchos::testRelErr<Scalar>(
329 "norm_inf(*v1)", norm_inf(*v1),
331 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out)),
335 out <<
"\n"<<tc<<
") norm_2(*v1);\n";
338 Teuchos::testRelErr<Scalar>(
339 "norm_2(*v1)", norm_2(*v1),
340 "2.0*sqrt(vecSpc.dim())", as<Scalar>(2.0)*ST::squareroot(vecSpc.
dim()),
341 "error_tol", error_tol(),
"warning_tol",warning_tol(), inOutArg(out)),
345 out <<
"\n"<<tc<<
") norm_1(*v1);\n";
348 Teuchos::testRelErr<Scalar>(
349 "norm_1(*v1)" ,norm_1(*v1),
350 "2.0*vecSpc.dim()", as<Scalar>(2.0)*as<Scalar>(vecSpc.
dim()),
351 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out)),
355 out <<
"\n"<<tc<<
") abs(z.ptr(),*v1);\n";
358 abs<Scalar>(*v1, z.
ptr());
359 if(!Teuchos::testRelErr<Scalar>(
360 "sum(*z)", sum(*z),
"2.0*vecSpc.dim()", as<Scalar>(2.0)*as<Scalar>(vecSpc.
dim()),
361 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out))
367 out <<
"\n"<<tc<<
") val = get_ele(y, 0);\n";
370 const Scalar val = get_ele<Scalar>(*y, 0);
374 out <<
"\n"<<tc<<
") val = get_ele<Scalar>(*y, 1);\n";
377 const Scalar val = get_ele<Scalar>(*y, 1);
381 out <<
"\n"<<tc<<
") val = get_ele<Scalar>(*y, n-2);\n";
384 const Scalar val = get_ele<Scalar>(*y, n-2);
388 out <<
"\n"<<tc<<
") val = get_ele<Scalar>(*y, n-1);\n";
391 const Scalar val = get_ele<Scalar>(*y, n-1);
397 out <<
"\n"<<tc<<
") get_ele<Scalar>(*y, -1);\n";
403 out <<
"\n"<<tc<<
") get_ele<Scalar>(*y, n);\n";
409 #endif // THYRA_DEBUG
413 setEleTestCase<Scalar>(z.ptr(), 0, tc, out, success);
415 setEleTestCase<Scalar>(z.ptr(), 1, tc, out, success);
417 setEleTestCase<Scalar>(z.ptr(), n-2, tc, out, success);
419 setEleTestCase<Scalar>(z.ptr(), n-1, tc, out, success);
424 std::out_of_range, out, success);
426 TEUCHOS_TEST_THROW(set_ele(n, two, z.ptr()),
427 std::out_of_range, out, success);
429 #endif // THYRA_DEBUG
432 out <<
"\n"<<tc<<
") reciprocal(z.ptr(),*v1);\n";
435 reciprocal(*v1, z.
ptr());
436 if(!Teuchos::testRelErr<Scalar>(
437 "sum(*z)",sum(*z),
"-0.5*vecSpc.dim()",as<Scalar>(-0.5)*as<Scalar>(vecSpc.
dim())
438 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),inOutArg(out))
444 out <<
"\n"<<tc<<
") linear_combination(2,{0.5,0.25},{v1.ptr(),v2.ptr()},0.0,z.ptr());\n";
447 linear_combination<Scalar>(
448 tuple<Scalar>(0.5, 0.25)(),
453 Teuchos::testRelErr<Scalar>(
455 "(-0.5*2.0-0.25*3.0)*vecSpc.dim()", as<Scalar>((-0.5 * 2.0 - 0.25 * 3.0) *vecSpc.
dim()),
456 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out)),
460 out <<
"\nassign(z.ptr(), 2.0);\n";
462 assign(z.ptr(), as<Scalar>(2.0));
464 out <<
"\n"<<tc<<
") linear_combination(3,{0.5,0.25,0.125},{v1.ptr(),v2.ptr(),v2.ptr()},0.5,z.ptr());\n";
467 linear_combination<Scalar>(
468 tuple<Scalar>(0.5, 0.25, 0.125)(),
472 if(!Teuchos::testRelErr<Scalar>(
474 "(0.5*2.0-0.5*2.0-0.25*3.0-0.125*4.0)*vecSpc.dim()",
475 as<Scalar>(0.5*2.0-0.5*2.0-0.25*3.0-0.125*4.0)*as<Scalar>(vecSpc.
dim()),
476 "error_tol", error_tol(),
"warning_tol", warning_tol(), inOutArg(out)
482 out <<
"\n"<<tc<<
") assign(z.ptr(),2.0);\n";
485 assign(z.ptr(),as<Scalar>(2.0));
486 if(!Teuchos::testRelErr<Scalar>(
487 "norm_2(*z,*v2)",norm_2(*z,*v2)
488 ,
"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())))
489 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),inOutArg(out)
493 if(!VectorStdOpsTesterComparable<ST::isComparable,Scalar>::checkComparableStdOps(
494 vecSpc,z.ptr(),error_tol(),warning_tol(),inOutArg(out),dumpAll)
499 out <<
"\n"<<tc<<
") Testing Vt_S(z.ptr(),alpha) ...\n";
502 #ifdef THYRA_VECTOR_STD_OPS_TESTER_DUMP
503 RTOpPack::show_spmd_apply_op_dump =
true;
504 #endif // THYRA_VECTOR_STD_OPS_TESTER_DUMP
505 v1 = createMember(vecSpc);
506 v2 = createMember(vecSpc);
507 const Scalar alpha = as<Scalar>(1.2345);
508 seed_randomize<Scalar>(12345);
509 randomize(as<Scalar>(-ST::one()),ST::one(),v1.
ptr());
511 Vt_S(v1.
ptr(), alpha);
512 const Scalar norm_alpha_v1 = norm_2(*v1);
514 const Scalar mag_alpha = ST::magnitude(alpha);
516 const Scalar norm_2_v2 = norm_2(*v2);
518 const Scalar alpha_norm_v1 = mag_alpha * norm_2_v2;
520 if(!testMaxErr<Scalar>(
521 "norm_alpha_v1 - alpha_norm_v1",ST::magnitude(norm_alpha_v1-alpha_norm_v1)
522 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
525 #ifdef THYRA_VECTOR_STD_OPS_TESTER_DUMP
526 RTOpPack::show_spmd_apply_op_dump =
false;
527 #endif // THYRA_VECTOR_STD_OPS_TESTER_DUMP
531 out <<
"\n"<<tc<<
") Testing V_StV(z.ptr(),alpha,*v) ...\n";
534 v1 = createMember(vecSpc);
535 v2 = createMember(vecSpc);
536 z = createMember(vecSpc);
537 const Scalar alpha = as<Scalar>(-1.2345);
538 seed_randomize<Scalar>(12345);
539 randomize(as<Scalar>(-ST::one()),ST::one(),v1.
ptr());
540 V_StV(v2.ptr(),alpha,*v1);
541 Vt_S(v1.
ptr(),alpha);
543 Vp_V(z.ptr(),*v2,as<Scalar>(-ST::one()));
544 if(!testMaxErr<Scalar>(
545 "norm_2(*z)",norm_2(*z)
546 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
552 out <<
"\n"<<tc<<
") Testing Vp_StV(z.ptr(),alpha,*v) ...\n";
555 v1 = createMember(vecSpc);
556 v2 = createMember(vecSpc);
557 v3 = createMember(vecSpc);
558 z = createMember(vecSpc);
559 const Scalar alpha = as<Scalar>(-1.2345);
560 seed_randomize<Scalar>(12345);
561 randomize(as<Scalar>(-ST::one()),ST::one(),v1.
ptr());
562 randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr());
564 Vp_StV(v1.
ptr(),alpha,*v2);
565 V_StV(z.ptr(),alpha,*v2);
568 Vp_V(v3.ptr(),*z,as<Scalar>(-ST::one()));
569 if(!testMaxErr<Scalar>(
570 "norm_2(*v3)",norm_2(*v3)
571 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
577 out <<
"\n"<<tc<<
") Testing ele_wise_prod(alpha,*v1, *v2, z.ptr()) ...\n";
580 v1 = createMember(vecSpc);
581 v2 = createMember(vecSpc);
582 v3 = createMember(vecSpc);
583 z = createMember(vecSpc);
584 const Scalar alpha = as<Scalar>(-1.2345);
585 seed_randomize<Scalar>(12345);
586 randomize(as<Scalar>(-ST::one()),ST::one(),v1.
ptr());
587 randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr());
588 randomize(as<Scalar>(-ST::one()),ST::one(),v3.ptr());
591 ele_wise_prod(alpha, *v2, *v3, v1.
ptr());
592 ele_wise_prod_update(alpha, *v3, z.ptr());
595 Vp_V(v2.ptr(), *z, as<Scalar>(-ST::one()));
596 if(!testMaxErr<Scalar>(
597 "norm_2(*v2)",norm_2(*v2)
598 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
605 out <<
"\n"<<tc<<
") Testing ele_wise_scale(*v1, z.ptr()) ...\n";
608 v1 = createMember(vecSpc);
609 z = createMember(vecSpc);
610 V_S(v1.
ptr(), as<Scalar>(2.0));
611 V_S(z.ptr(), as<Scalar>(3.0));
612 ele_wise_scale( *v1, z.
ptr() );
613 if (!Teuchos::testRelErr<Scalar>(
614 "norm_2(*z)", norm_2(*z),
615 "ST::squareroot(n*sqr(3.0*2.0))", ST::squareroot(n*36.0),
616 "error_tol", error_tol(),
617 "warning_tol", warning_tol(),
624 out <<
"\n"<<tc<<
") Testing Vt_StV(z.ptr(), alpha, *v) ...\n";
627 v1 = createMember(vecSpc);
628 v2 = createMember(vecSpc);
629 v3 = createMember(vecSpc);
630 z = createMember(vecSpc);
631 const Scalar alpha = as<Scalar>(-1.2345);
632 seed_randomize<Scalar>(12345);
633 randomize(as<Scalar>(-ST::one()),ST::one(),v1.
ptr());
634 randomize(as<Scalar>(-ST::one()),ST::one(),v2.ptr());
636 Vt_StV(v1.
ptr(),alpha,*v2);
637 V_S(z.ptr(),ST::zero());
638 Vp_StVtV(z.ptr(),alpha,*v3,*v2);
640 Vp_V(v2.ptr(),*z,as<Scalar>(-ST::one()));
641 if(!testMaxErr<Scalar>(
642 "norm_2(*v2)",norm_2(*v2)
643 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
649 out <<
"\n"<<tc<<
") Testing V_StVpV(z.ptr(),alpha,*v1,*v2) ...\n";
652 v1 = createMember(vecSpc);
653 v2 = createMember(vecSpc);
654 v3 = createMember(vecSpc);
655 x = createMember(vecSpc);
656 z = createMember(vecSpc);
657 const Scalar alpha = as<Scalar>(1.2345);
658 seed_randomize<Scalar>(12345);
659 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v1.
ptr());
660 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
661 V_StVpV(v3.ptr(),alpha,*v1,*v2);
663 Vp_V(z.ptr(),*v2,alpha);
665 Vp_V(x.ptr(),*z,as<Scalar>(-ST::one()));
666 if(!testMaxErr<Scalar>(
667 "norm_2(*x)",norm_2(*x)
668 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
674 out <<
"\n"<<tc<<
") Testing V_VpStV(z.ptr(),*v1,alpha,*v2) ...\n";
677 v1 = createMember(vecSpc);
678 v2 = createMember(vecSpc);
679 v3 = createMember(vecSpc);
680 x = createMember(vecSpc);
681 z = createMember(vecSpc);
682 const Scalar alpha = as<Scalar>(1.2345);
683 seed_randomize<Scalar>(12345);
684 randomize<Scalar>(as<Scalar>(as<Scalar>(-10)*ST::one()),
685 as<Scalar>(as<Scalar>(10)*ST::one()), v1.
ptr());
686 randomize<Scalar>(as<Scalar>(as<Scalar>(-10)*ST::one()),
687 as<Scalar>(as<Scalar>(10)*ST::one()), v2.ptr());
688 V_VpStV(outArg(*v3), *v1, alpha, *v2);
690 Vp_StV(z.ptr(), alpha, *v2);
691 V_VmV(outArg(*x), *z, *v3);
692 if(!testMaxErr<Scalar>(
693 "norm_2(*x)",norm_2(*x)
694 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
700 out <<
"\n"<<tc<<
") Testing V_StVpStV(z.ptr(),alpha,*v1,beta,*v2) ...\n";
703 v1 = createMember(vecSpc);
704 v2 = createMember(vecSpc);
705 v3 = createMember(vecSpc);
706 x = createMember(vecSpc);
707 z = createMember(vecSpc);
708 const Scalar alpha = as<Scalar>(1.2345);
709 const Scalar beta = as<Scalar>(5.4321);
710 seed_randomize<Scalar>(12345);
711 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v1.
ptr());
712 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
713 V_StVpStV(v3.ptr(),alpha,*v1,beta,*v2);
714 V_StV(z.ptr(),alpha,*v1);
715 Vp_StV(z.ptr(),beta,*v2);
717 Vp_V(x.ptr(),*z,as<Scalar>(-ST::one()));
718 if(!testMaxErr<Scalar>(
719 "norm_2(*x)",norm_2(*x)
726 out <<
"\n"<<tc<<
") Testing Vp_V(v1.ptr(),*v2,beta) ...\n";
729 v1 = createMember(vecSpc);
730 v2 = createMember(vecSpc);
731 v3 = createMember(vecSpc);
732 x = createMember(vecSpc);
733 z = createMember(vecSpc);
734 const Scalar alpha = as<Scalar>(-2.0);
735 const Scalar beta = as<Scalar>(10.0);
737 seed_randomize<Scalar>(12345);
738 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
739 Vp_V(v1.
ptr(),*v2,beta);
741 V_StVpV(z.ptr(),beta,*v3,*v2);
742 V_StVpV(x.ptr(),as<Scalar>(-ST::one()),*z,*v1);
743 if(!testMaxErr<Scalar>(
744 "norm_2(*x)",norm_2(*x)
745 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
751 out <<
"\n"<<tc<<
") Testing Vp_V(v1.ptr(),*v2) ...\n";
754 v1 = createMember(vecSpc);
755 v2 = createMember(vecSpc);
756 v3 = createMember(vecSpc);
757 x = createMember(vecSpc);
758 z = createMember(vecSpc);
759 const Scalar alpha = as<Scalar>(-2.0);
761 seed_randomize<Scalar>(12345);
762 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v2.ptr());
765 V_StVpV(z.ptr(),ST::one(),*v3,*v2);
766 V_StVpV(x.ptr(),as<Scalar>(-ST::one()),*z,*v1);
767 if(!testMaxErr<Scalar>(
768 "norm_2(*x)",norm_2(*x)
769 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
775 out <<
"\n"<<tc<<
") Testing V_S(v1.ptr(),alpha) ...\n";
778 v1 = createMember(vecSpc);
779 v2 = createMember(vecSpc);
780 z = createMember(vecSpc);
781 const Scalar alpha = as<Scalar>(1.2345);
782 assign(v1.
ptr(),alpha);
784 V_StVpV(z.ptr(),as<Scalar>(-ST::one()),*v1,*v2);
785 if(!testMaxErr<Scalar>(
786 "norm_2(*z)",norm_2(*z)
787 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
793 out <<
"\n"<<tc<<
") Testing V_V(v1.ptr(),*v2) ...\n";
796 v1 = createMember(vecSpc);
797 v2 = createMember(vecSpc);
798 z = createMember(vecSpc);
799 seed_randomize<Scalar>(12345);
800 randomize(as<Scalar>(as<Scalar>(-10)*ST::one()),as<Scalar>(as<Scalar>(10)*ST::one()),v1.
ptr());
802 V_StVpV(z.ptr(),as<Scalar>(-ST::one()),*v1,*v2);
803 if(!testMaxErr<Scalar>(
804 "norm_2(*z)",norm_2(*z)
805 ,
"error_tol",error_tol(),
"warning_tol",warning_tol(),&out
812 out <<
"\n*** Leaving VectorStdOpsTester<"<<ST::name()<<
">::checkStdOps(...) ...\n";
823 #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.
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.