42 #ifndef BELOS_MVOPTESTER_HPP
43 #define BELOS_MVOPTESTER_HPP
63 #include "Teuchos_MatrixMarket_SetScientific.hpp"
83 template<
class ScalarType,
class MV >
93 typedef typename STS::magnitudeType MagType;
97 SetScientific<ScalarType> sci (om->stream (
Warnings));
102 const MagType tol = Teuchos::as<MagType> (100) * STS::eps ();
181 const ScalarType one = STS::one();
182 const ScalarType zero = STS::zero();
186 const int numvecs = 10;
187 const int numvecs_2 = 5;
189 std::vector<int> ind(numvecs_2);
210 if ( MVT::GetNumberVecs(*A) <= 0 ) {
212 <<
"*** ERROR *** MultiVectorTraits::GetNumberVecs()." << endl
213 <<
"Returned <= 0." << endl;
222 if ( MVT::GetVecLength(*A) <= 0 ) {
224 <<
"*** ERROR *** MultiVectorTraits::GetVecLength()" << endl
225 <<
"Returned <= 0." << endl;
234 if ( MVText::GetGlobalLength(*A) <= 0 ) {
236 <<
"*** ERROR *** MultiVectorTraitsExt::GetGlobalLength()" << endl
237 <<
"Returned <= 0." << endl;
251 std::vector<MagType> norms(2*numvecs);
252 bool ResizeWarning =
false;
253 if ( MVT::GetNumberVecs(*B) != numvecs ) {
255 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
256 <<
"Did not allocate requested number of vectors." << endl;
259 if ( MVText::GetGlobalLength(*B) != MVText::GetGlobalLength(*A) ) {
261 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
262 <<
"Did not allocate requested number of vectors." << endl;
265 MVT::MvNorm(*B, norms);
266 if ( norms.size() != 2*numvecs && ResizeWarning==false ) {
268 <<
"*** WARNING *** MultiVecTraits::MvNorm()." << endl
269 <<
"Method resized the output vector." << endl;
270 ResizeWarning =
true;
272 for (
int i=0; i<numvecs; i++) {
273 if ( norms[i] < zero_mag ) {
275 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
276 <<
"Vector had negative norm." << endl;
300 std::vector<MagType> norms(numvecs), norms2(numvecs);
303 MVT::MvNorm(*B, norms);
304 for (
int i=0; i<numvecs; i++) {
305 if ( norms[i] != zero_mag ) {
307 <<
"*** ERROR *** MultiVecTraits::MvInit() "
308 <<
"and MultiVecTraits::MvNorm()" << endl
309 <<
"Supposedly zero vector has non-zero norm." << endl;
314 MVT::MvNorm(*B, norms);
316 MVT::MvNorm(*B, norms2);
317 for (
int i=0; i<numvecs; i++) {
318 if ( norms[i] == zero_mag || norms2[i] == zero_mag ) {
320 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
321 <<
"Random vector was empty (very unlikely)." << endl;
324 else if ( norms[i] < zero_mag || norms2[i] < zero_mag ) {
326 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
327 <<
"Vector had negative norm." << endl;
330 else if ( norms[i] == norms2[i] ) {
332 <<
"*** ERROR *** MutliVecTraits::MvRandom()." << endl
333 <<
"Vectors not random enough." << endl;
349 std::vector<MagType> norms(numvecs);
352 MVT::MvScale(*B,STS::zero());
353 MVT::MvNorm(*B, norms);
354 for (
int i=0; i<numvecs; i++) {
355 if ( norms[i] != zero_mag ) {
357 <<
"*** ERROR *** MultiVecTraits::MvScale(alpha) "
358 <<
"Supposedly zero vector has non-zero norm." << endl;
364 std::vector<ScalarType> zeros(numvecs,STS::zero());
365 MVT::MvScale(*B,zeros);
366 MVT::MvNorm(*B, norms);
367 for (
int i=0; i<numvecs; i++) {
368 if ( norms[i] != zero_mag ) {
370 <<
"*** ERROR *** MultiVecTraits::MvScale(alphas) "
371 <<
"Supposedly zero vector has non-zero norm." << endl;
393 std::vector<MagType> norms(numvecs);
396 MVT::MvNorm(*B, norms);
397 bool BadNormWarning =
false;
398 for (
int i=0; i<numvecs; i++) {
399 if ( norms[i] < zero_mag ) {
401 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
402 <<
"Vector had negative norm." << endl;
405 else if ( norms[i] != STS::squareroot(MVT::GetVecLength(*B)) && !BadNormWarning ) {
408 <<
"Warning testing MultiVecTraits::MvInit()." << endl
409 <<
"Ones std::vector should have norm std::sqrt(dim)." << endl
410 <<
"norms[i]: " << norms[i] <<
"\tdim: " << MVText::GetGlobalLength(*B) << endl << endl;
411 BadNormWarning =
true;
426 std::vector<MagType> norms(numvecs);
427 MVT::MvInit(*B, zero_mag);
428 MVT::MvNorm(*B, norms);
429 for (
int i=0; i<numvecs; i++) {
430 if ( norms[i] < zero_mag ) {
432 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
433 <<
"Vector had negative norm." << endl;
436 else if ( norms[i] != zero_mag ) {
438 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
439 <<
"Zero std::vector should have norm zero." << endl;
453 std::vector<MagType> norms(numvecs), norms2(numvecs);
455 B = MVT::Clone(*A,numvecs);
457 MVT::MvNorm(*B, norms);
458 C = MVT::CloneCopy(*B,ind);
459 MVT::MvNorm(*C, norms2);
460 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
462 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
463 <<
"Wrong number of vectors." << endl;
466 if ( MVText::GetGlobalLength(*C) != MVText::GetGlobalLength(*B) ) {
468 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
469 <<
"Vector lengths don't match." << endl;
472 for (
int i=0; i<numvecs_2; i++) {
473 if (STS::magnitude (norms2[i] - norms[ind[i]]) > tol) {
475 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
476 <<
"Copied vectors do not agree: "
477 << norms2[i] <<
" != " << norms[ind[i]] << endl
478 <<
"Difference " << STS::magnitude (norms2[i] - norms[ind[i]])
479 <<
" exceeds the tolerance 100*eps = " << tol << endl;
485 MVT::MvInit(*B,zero);
486 MVT::MvNorm(*C, norms);
487 for (
int i=0; i<numvecs_2; i++) {
489 if (STS::magnitude (norms2[i] - norms[i]) > tol) {
491 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
492 <<
"Copied vectors were not independent." << endl
493 << norms2[i] <<
" != " << norms[i] << endl
494 <<
"Difference " << STS::magnitude (norms2[i] - norms[i])
495 <<
" exceeds the tolerance 100*eps = " << tol << endl;
508 std::vector<MagType> norms(numvecs), norms2(numvecs);
510 B = MVT::Clone(*A,numvecs);
512 MVT::MvNorm(*B, norms);
513 C = MVT::CloneCopy(*B);
514 MVT::MvNorm(*C, norms2);
515 if ( MVT::GetNumberVecs(*C) != numvecs ) {
517 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
518 <<
"Wrong number of vectors." << endl;
521 for (
int i=0; i<numvecs; i++) {
522 if (STS::magnitude (norms2[i] - norms[i]) > tol) {
524 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
525 <<
"Copied vectors do not agree: "
526 << norms2[i] <<
" != " << norms[i] << endl
527 <<
"Difference " << STS::magnitude (norms2[i] - norms[i])
528 <<
" exceeds the tolerance 100*eps = " << tol << endl;
532 MVT::MvInit(*B,zero);
533 MVT::MvNorm(*C, norms);
534 for (
int i=0; i<numvecs; i++) {
536 if (STS::magnitude (norms2[i] - norms[i]) > tol) {
538 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
539 <<
"Copied vectors were not independent." << endl
540 << norms2[i] <<
" != " << norms[i] << endl
541 <<
"Difference " << STS::magnitude (norms2[i] - norms[i])
542 <<
" exceeds the tolerance 100*eps = " << tol << endl;
557 std::vector<MagType> norms(numvecs), norms2(numvecs);
559 B = MVT::Clone(*A,numvecs);
561 MVT::MvNorm(*B, norms);
562 C = MVT::CloneViewNonConst(*B,ind);
563 MVT::MvNorm(*C, norms2);
564 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
566 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
567 <<
"Wrong number of vectors." << endl;
570 for (
int i=0; i<numvecs_2; i++) {
572 if (STS::magnitude (norms2[i] - norms[ind[i]]) > tol) {
574 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
575 <<
"Viewed vectors do not agree." << endl;
591 std::vector<MagType> normsB(numvecs), normsC(numvecs_2);
592 std::vector<int> allind(numvecs);
593 for (
int i=0; i<numvecs; i++) {
597 B = MVT::Clone(*A,numvecs);
599 MVT::MvNorm(*B, normsB);
600 C = MVT::CloneView(*B,ind);
601 MVT::MvNorm(*C, normsC);
602 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
604 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
605 <<
"Wrong number of vectors." << endl;
608 for (
int i=0; i<numvecs_2; i++) {
610 if (STS::magnitude (normsC[i] - normsB[ind[i]]) > tol) {
612 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
613 <<
"Viewed vectors do not agree." << endl;
633 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
634 normsC1(numvecs_2), normsC2(numvecs_2);
636 B = MVT::Clone(*A,numvecs);
637 C = MVT::Clone(*A,numvecs_2);
639 ind.resize(numvecs_2);
640 for (
int i=0; i<numvecs_2; i++) {
646 MVT::MvNorm(*B,normsB1);
647 MVT::MvNorm(*C,normsC1);
648 MVT::SetBlock(*C,ind,*B);
649 MVT::MvNorm(*B,normsB2);
650 MVT::MvNorm(*C,normsC2);
653 for (
int i=0; i<numvecs_2; i++) {
655 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
657 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
658 <<
"Operation modified source vectors." << endl;
664 for (
int i=0; i<numvecs; i++) {
667 if (STS::magnitude (normsB2[i] - normsC1[i/2]) > tol) {
669 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
670 <<
"Copied vectors do not agree: " << endl
671 << normsB2[i] <<
" != " << normsC1[i/2] << endl
672 <<
"Difference " << STS::magnitude (normsB2[i] - normsC1[i/2])
673 <<
" exceeds the tolerance 100*eps = " << tol << endl;
679 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
681 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
682 <<
"Incorrect vectors were modified." << endl
683 << normsB1[i] <<
" != " << normsB2[i] << endl
684 <<
"Difference " << STS::magnitude (normsB2[i] - normsB2[i])
685 <<
" exceeds the tolerance 100*eps = " << tol << endl;
690 MVT::MvInit(*C,zero);
691 MVT::MvNorm(*B,normsB1);
693 for (
int i=0; i<numvecs; i++) {
695 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
697 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
698 <<
"Copied vectors were not independent." << endl
699 << normsB1[i] <<
" != " << normsB2[i] << endl
700 <<
"Difference " << STS::magnitude (normsB1[i] - normsB2[i])
701 <<
" exceeds the tolerance 100*eps = " << tol << endl;
729 std::vector<MagType> normsB1(BSize), normsB2(BSize),
730 normsC1(CSize), normsC2(CSize);
732 B = MVT::Clone(*A,BSize);
733 C = MVT::Clone(*A,CSize);
736 for (
int i=0; i<setSize; i++) {
742 MVT::MvNorm(*B,normsB1);
743 MVT::MvNorm(*C,normsC1);
744 MVT::SetBlock(*C,ind,*B);
745 MVT::MvNorm(*B,normsB2);
746 MVT::MvNorm(*C,normsC2);
749 for (
int i=0; i<CSize; i++) {
751 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
753 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
754 <<
"Operation modified source vectors." << endl;
760 for (
int i=0; i<BSize; i++) {
763 const MagType diff = STS::magnitude (normsB2[i] - normsC1[i/2]);
766 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
767 <<
"Copied vectors do not agree: " << endl
768 << normsB2[i] <<
" != " << normsC1[i/2] << endl
769 <<
"Difference " << diff <<
" exceeds the tolerance 100*eps = "
776 const MagType diff = STS::magnitude (normsB1[i] - normsB2[i]);
780 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
781 <<
"Incorrect vectors were modified." << endl
782 << normsB1[i] <<
" != " << normsB2[i] << endl
783 <<
"Difference " << diff <<
" exceeds the tolerance 100*eps = "
789 MVT::MvInit(*C,zero);
790 MVT::MvNorm(*B,normsB1);
792 for (
int i=0; i<numvecs; i++) {
794 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
796 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
797 <<
"Copied vectors were not independent." << endl
798 << normsB1[i] <<
" != " << normsB2[i] << endl
799 <<
"Difference " << STS::magnitude (normsB1[i] - normsB2[i])
800 <<
" exceeds the tolerance 100*eps = " << tol << endl;
830 std::vector<MagType> normsB(p), normsC(q);
833 B = MVT::Clone(*A,p);
834 C = MVT::Clone(*A,q);
838 MVT::MvNorm(*B,normsB);
840 MVT::MvNorm(*C,normsC);
843 MVT::MvTransMv( zero, *B, *C, SDM );
848 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
849 <<
"Routine resized SerialDenseMatrix." << endl;
856 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
857 <<
"Scalar argument processed incorrectly." << endl;
862 MVT::MvTransMv( one, *B, *C, SDM );
866 for (
int i=0; i<p; i++) {
867 for (
int j=0; j<q; j++) {
868 if ( STS::magnitude(SDM(i,j))
869 > STS::magnitude(normsB[i]*normsC[j]) ) {
871 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
872 <<
"Triangle inequality did not hold: "
873 << STS::magnitude(SDM(i,j))
875 << STS::magnitude(normsB[i]*normsC[j])
883 MVT::MvTransMv( one, *B, *C, SDM );
884 for (
int i=0; i<p; i++) {
885 for (
int j=0; j<q; j++) {
886 if ( SDM(i,j) != zero ) {
888 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
889 <<
"Inner products not zero for C==0." << endl;
896 MVT::MvTransMv( one, *B, *C, SDM );
897 for (
int i=0; i<p; i++) {
898 for (
int j=0; j<q; j++) {
899 if ( SDM(i,j) != zero ) {
901 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
902 <<
"Inner products not zero for B==0." << endl;
920 std::vector<ScalarType> iprods(p+q);
921 std::vector<MagType> normsB(numvecs), normsC(numvecs);
923 B = MVT::Clone(*A,p);
924 C = MVT::Clone(*A,p);
928 MVT::MvNorm(*B,normsB);
929 MVT::MvNorm(*C,normsC);
930 MVT::MvDot( *B, *C, iprods );
931 if ( iprods.size() != p+q ) {
933 <<
"*** ERROR *** MultiVecTraits::MvDot." << endl
934 <<
"Routine resized results std::vector." << endl;
938 if ( STS::magnitude(iprods[i])
939 > STS::magnitude(normsB[i]*normsC[i]) ) {
941 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
942 <<
"Inner products not valid." << endl;
948 MVT::MvDot( *B, *C, iprods );
949 for (
int i=0; i<p; i++) {
950 if ( iprods[i] != zero ) {
952 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
953 <<
"Inner products not zero for B==0." << endl;
959 MVT::MvDot( *B, *C, iprods );
960 for (
int i=0; i<p; i++) {
961 if ( iprods[i] != zero ) {
963 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
964 <<
"Inner products not zero for C==0." << endl;
981 std::vector<MagType> normsB1(p), normsB2(p),
982 normsC1(p), normsC2(p),
983 normsD1(p), normsD2(p);
984 ScalarType alpha = STS::random(),
985 beta = STS::random();
987 B = MVT::Clone(*A,p);
988 C = MVT::Clone(*A,p);
989 D = MVT::Clone(*A,p);
993 MVT::MvNorm(*B,normsB1);
994 MVT::MvNorm(*C,normsC1);
997 MVT::MvAddMv(zero,*B,one,*C,*D);
998 MVT::MvNorm(*B,normsB2);
999 MVT::MvNorm(*C,normsC2);
1000 MVT::MvNorm(*D,normsD1);
1001 for (
int i=0; i<p; i++) {
1002 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1004 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1005 <<
"Input arguments were modified." << endl;
1008 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1010 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1011 <<
"Input arguments were modified." << endl;
1014 else if (STS::magnitude (normsC1[i] - normsD1[i]) > tol) {
1016 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1017 <<
"Assignment did not work." << endl;
1023 MVT::MvAddMv(one,*B,zero,*C,*D);
1024 MVT::MvNorm(*B,normsB2);
1025 MVT::MvNorm(*C,normsC2);
1026 MVT::MvNorm(*D,normsD1);
1027 for (
int i=0; i<p; i++) {
1028 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1030 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1031 <<
"Input arguments were modified." << endl;
1034 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1036 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1037 <<
"Input arguments were modified." << endl;
1040 else if (STS::magnitude (normsB1[i] - normsD1[i]) > tol) {
1042 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1043 <<
"Assignment did not work." << endl;
1051 MVT::MvAddMv(alpha,*B,beta,*C,*D);
1052 MVT::MvNorm(*B,normsB2);
1053 MVT::MvNorm(*C,normsC2);
1054 MVT::MvNorm(*D,normsD1);
1056 for (
int i=0; i<p; i++) {
1057 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1059 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1060 <<
"Input arguments were modified." << endl;
1063 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1065 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1066 <<
"Input arguments were modified." << endl;
1072 MVT::MvAddMv(alpha,*B,beta,*C,*D);
1073 MVT::MvNorm(*B,normsB2);
1074 MVT::MvNorm(*C,normsC2);
1075 MVT::MvNorm(*D,normsD2);
1078 for (
int i=0; i<p; i++) {
1079 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1081 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1082 <<
"Input arguments were modified." << endl;
1085 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1087 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1088 <<
"Input arguments were modified." << endl;
1091 else if (STS::magnitude (normsD1[i] - normsD2[i]) > tol) {
1093 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1094 <<
"Results varies depending on initial state of dest vectors." << endl;
1122 std::vector<MagType> normsB(p),
1124 std::vector<int> lclindex(p);
1125 for (
int i=0; i<p; i++) lclindex[i] = i;
1127 B = MVT::Clone(*A,p);
1128 C = MVT::CloneView(*B,lclindex);
1129 D = MVT::CloneViewNonConst(*B,lclindex);
1132 MVT::MvNorm(*B,normsB);
1135 MVT::MvAddMv(zero,*B,one,*C,*D);
1136 MVT::MvNorm(*D,normsD);
1137 for (
int i=0; i<p; i++) {
1138 if (STS::magnitude (normsB[i] - normsD[i]) > tol) {
1140 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1141 <<
"Assignment did not work." << endl;
1147 MVT::MvAddMv(one,*B,zero,*C,*D);
1148 MVT::MvNorm(*D,normsD);
1149 for (
int i=0; i<p; i++) {
1150 if (STS::magnitude (normsB[i] - normsD[i]) > tol) {
1152 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1153 <<
"Assignment did not work." << endl;
1171 const int p = 7, q = 5;
1174 std::vector<MagType> normsC1(q), normsC2(q),
1175 normsB1(p), normsB2(p);
1177 B = MVT::Clone(*A,p);
1178 C = MVT::Clone(*A,q);
1183 MVT::MvNorm(*B,normsB1);
1184 MVT::MvNorm(*C,normsC1);
1186 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1187 MVT::MvNorm(*B,normsB2);
1188 MVT::MvNorm(*C,normsC2);
1189 for (
int i=0; i<p; i++) {
1190 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1192 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1193 <<
"Input vectors were modified." << endl;
1197 for (
int i=0; i<q; i++) {
1198 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1200 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1201 <<
"Arithmetic test 1 failed." << endl;
1209 MVT::MvNorm(*B,normsB1);
1210 MVT::MvNorm(*C,normsC1);
1212 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1213 MVT::MvNorm(*B,normsB2);
1214 MVT::MvNorm(*C,normsC2);
1215 for (
int i=0; i<p; i++) {
1216 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1218 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1219 <<
"Input vectors were modified." << endl;
1223 for (
int i=0; i<q; i++) {
1224 if ( normsC2[i] != zero ) {
1226 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1227 <<
"Arithmetic test 2 failed: "
1240 MVT::MvNorm(*B,normsB1);
1241 MVT::MvNorm(*C,normsC1);
1243 for (
int i=0; i<q; i++) {
1246 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1247 MVT::MvNorm(*B,normsB2);
1248 MVT::MvNorm(*C,normsC2);
1249 for (
int i=0; i<p; i++) {
1250 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1252 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1253 <<
"Input vectors were modified." << endl;
1257 for (
int i=0; i<q; i++) {
1258 if (STS::magnitude (normsB1[i] - normsC2[i]) > tol) {
1260 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1261 <<
"Arithmetic test 3 failed: "
1273 MVT::MvNorm(*B,normsB1);
1274 MVT::MvNorm(*C,normsC1);
1276 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1277 MVT::MvNorm(*B,normsB2);
1278 MVT::MvNorm(*C,normsC2);
1279 for (
int i=0; i<p; i++) {
1280 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1282 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1283 <<
"Input vectors were modified." << endl;
1287 for (
int i=0; i<q; i++) {
1288 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1290 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1291 <<
"Arithmetic test 4 failed." << endl;
1307 const int p = 5, q = 7;
1310 std::vector<MagType> normsC1(q), normsC2(q),
1311 normsB1(p), normsB2(p);
1313 B = MVT::Clone(*A,p);
1314 C = MVT::Clone(*A,q);
1319 MVT::MvNorm(*B,normsB1);
1320 MVT::MvNorm(*C,normsC1);
1322 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1323 MVT::MvNorm(*B,normsB2);
1324 MVT::MvNorm(*C,normsC2);
1325 for (
int i=0; i<p; i++) {
1326 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1328 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1329 <<
"Input vectors were modified." << endl;
1333 for (
int i=0; i<q; i++) {
1334 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1336 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1337 <<
"Arithmetic test 5 failed." << endl;
1345 MVT::MvNorm(*B,normsB1);
1346 MVT::MvNorm(*C,normsC1);
1348 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1349 MVT::MvNorm(*B,normsB2);
1350 MVT::MvNorm(*C,normsC2);
1351 for (
int i=0; i<p; i++) {
1352 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1354 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1355 <<
"Input vectors were modified." << endl;
1359 for (
int i=0; i<q; i++) {
1360 if ( normsC2[i] != zero ) {
1362 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1363 <<
"Arithmetic test 6 failed: "
1375 MVT::MvNorm(*B,normsB1);
1376 MVT::MvNorm(*C,normsC1);
1378 for (
int i=0; i<p; i++) {
1381 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1382 MVT::MvNorm(*B,normsB2);
1383 MVT::MvNorm(*C,normsC2);
1384 for (
int i=0; i<p; i++) {
1385 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1387 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1388 <<
"Input vectors were modified." << endl;
1392 for (
int i=0; i<p; i++) {
1393 if (STS::magnitude (normsB1[i] - normsC2[i]) > tol) {
1395 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1396 <<
"Arithmetic test 7 failed." << endl;
1400 for (
int i=p; i<q; i++) {
1401 if ( normsC2[i] != zero ) {
1403 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1404 <<
"Arithmetic test 7 failed." << endl;
1412 MVT::MvNorm(*B,normsB1);
1413 MVT::MvNorm(*C,normsC1);
1415 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1416 MVT::MvNorm(*B,normsB2);
1417 MVT::MvNorm(*C,normsC2);
1418 for (
int i=0; i<p; i++) {
1419 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1421 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1422 <<
"Input vectors were modified." << endl;
1426 for (
int i=0; i<q; i++) {
1427 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1429 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1430 <<
"Arithmetic test 8 failed." << endl;
1463 template<
class ScalarType,
class MV,
class OP>
1473 typedef typename STS::magnitudeType MagType;
1477 SetScientific<ScalarType> sci (om->stream (
Warnings));
1482 const MagType tol = Teuchos::as<MagType> (100) * STS::eps ();
1494 typedef typename STS::magnitudeType MagType;
1496 const int numvecs = 10;
1499 C = MVT::Clone(*A,numvecs);
1501 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
1502 normsC1(numvecs), normsC2(numvecs);
1503 bool NonDeterministicWarning;
1514 MVT::MvNorm(*B,normsB1);
1515 OPT::Apply(*M,*B,*C);
1516 MVT::MvNorm(*B,normsB2);
1517 MVT::MvNorm(*C,normsC2);
1518 for (
int i=0; i<numvecs; i++) {
1519 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1521 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1522 <<
"Apply() modified the input vectors." << endl
1523 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1524 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1525 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1528 if (normsC2[i] != STS::zero()) {
1530 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1531 <<
"Operator applied to zero did not return zero." << endl;
1538 MVT::MvNorm(*B,normsB1);
1539 OPT::Apply(*M,*B,*C);
1540 MVT::MvNorm(*B,normsB2);
1541 MVT::MvNorm(*C,normsC2);
1542 bool ZeroWarning =
false;
1543 for (
int i=0; i<numvecs; i++) {
1544 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1546 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1547 <<
"Apply() modified the input vectors." << endl
1548 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1549 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1550 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1553 if (normsC2[i] == STS::zero() && ZeroWarning==
false ) {
1555 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1556 <<
"Operator applied to random vectors returned zero." << endl;
1563 MVT::MvNorm(*B,normsB1);
1565 OPT::Apply(*M,*B,*C);
1566 MVT::MvNorm(*B,normsB2);
1567 MVT::MvNorm(*C,normsC1);
1568 for (
int i=0; i<numvecs; i++) {
1569 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1571 <<
"*** ERROR *** OperatorTraits::Apply() [3]" << endl
1572 <<
"Apply() modified the input vectors." << endl
1573 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1574 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1575 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1586 OPT::Apply(*M,*B,*C);
1587 MVT::MvNorm(*B,normsB2);
1588 MVT::MvNorm(*C,normsC2);
1589 NonDeterministicWarning =
false;
1590 for (
int i=0; i<numvecs; i++) {
1591 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1593 <<
"*** ERROR *** OperatorTraits::Apply() [4]" << endl
1594 <<
"Apply() modified the input vectors." << endl
1595 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1596 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1597 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1600 if (normsC1[i] != normsC2[i] && !NonDeterministicWarning) {
1603 <<
"*** WARNING *** OperatorTraits::Apply() [4]" << endl
1604 <<
"Apply() returned two different results." << endl << endl;
1605 NonDeterministicWarning =
true;
ScalarTraits< ScalarType >::magnitudeType normOne() const
Collection of types and exceptions used within the Belos solvers.
Belos's basic output manager for sending information of select verbosity levels to the appropriate ou...
Class which manages the output and verbosity of the Belos solvers.
Declaration of basic traits for the multivector type.
int scale(const ScalarType alpha)
An extension of the MultiVecTraits class that adds a new vector length method.
Class which defines basic traits for the operator type.
Traits class which defines basic operations on multivectors.
bool TestOperatorTraits(const Teuchos::RCP< OutputManager< ScalarType > > &om, const Teuchos::RCP< const MV > &A, const Teuchos::RCP< const OP > &M)
Test correctness of OperatorTraits specialization and its operator implementation.
OrdinalType numCols() const
Class which defines basic traits for the operator type.
bool TestMultiVecTraits(const Teuchos::RCP< OutputManager< ScalarType > > &om, const Teuchos::RCP< const MV > &A)
Test correctness of a MultiVecTraits specialization and multivector implementation.
Belos header file which uses auto-configuration information to include necessary C++ headers...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
OrdinalType numRows() const