42 #ifndef BELOS_MVOPTESTER_HPP
43 #define BELOS_MVOPTESTER_HPP
63 #include "Teuchos_SetScientific.hpp"
84 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 ();
178 const ScalarType one = STS::one();
179 const ScalarType zero = STS::zero();
183 const int numvecs = 10;
184 const int numvecs_2 = 5;
186 std::vector<int> ind(numvecs_2);
207 if ( MVT::GetNumberVecs(*A) <= 0 ) {
209 <<
"*** ERROR *** MultiVectorTraits::GetNumberVecs()." << endl
210 <<
"Returned <= 0." << endl;
219 if ( MVT::GetGlobalLength(*A) <= 0 ) {
221 <<
"*** ERROR *** MultiVectorTraitsExt::GetGlobalLength()" << endl
222 <<
"Returned <= 0." << endl;
236 std::vector<MagType> norms(2*numvecs);
237 bool ResizeWarning =
false;
238 if ( MVT::GetNumberVecs(*B) != numvecs ) {
240 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
241 <<
"Did not allocate requested number of vectors." << endl;
244 if ( MVT::GetGlobalLength(*B) != MVT::GetGlobalLength(*A) ) {
246 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
247 <<
"Did not allocate requested number of vectors." << endl;
250 MVT::MvNorm(*B, norms);
251 if ( norms.size() != 2*numvecs && ResizeWarning==false ) {
253 <<
"*** WARNING *** MultiVecTraits::MvNorm()." << endl
254 <<
"Method resized the output vector." << endl;
255 ResizeWarning =
true;
257 for (
int i=0; i<numvecs; i++) {
258 if ( norms[i] < zero_mag ) {
260 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
261 <<
"Vector had negative norm." << endl;
285 std::vector<MagType> norms(numvecs), norms2(numvecs);
288 MVT::MvNorm(*B, norms);
289 for (
int i=0; i<numvecs; i++) {
290 if ( norms[i] != zero_mag ) {
292 <<
"*** ERROR *** MultiVecTraits::MvInit() "
293 <<
"and MultiVecTraits::MvNorm()" << endl
294 <<
"Supposedly zero vector has non-zero norm." << endl;
299 MVT::MvNorm(*B, norms);
301 MVT::MvNorm(*B, norms2);
302 for (
int i=0; i<numvecs; i++) {
303 if ( norms[i] == zero_mag || norms2[i] == zero_mag ) {
305 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
306 <<
"Random vector was empty (very unlikely)." << endl;
309 else if ( norms[i] < zero_mag || norms2[i] < zero_mag ) {
311 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
312 <<
"Vector had negative norm." << endl;
315 else if ( norms[i] == norms2[i] ) {
317 <<
"*** ERROR *** MutliVecTraits::MvRandom()." << endl
318 <<
"Vectors not random enough." << endl;
334 std::vector<MagType> norms(numvecs);
337 MVT::MvScale(*B,STS::zero());
338 MVT::MvNorm(*B, norms);
339 for (
int i=0; i<numvecs; i++) {
340 if ( norms[i] != zero_mag ) {
342 <<
"*** ERROR *** MultiVecTraits::MvScale(alpha) "
343 <<
"Supposedly zero vector has non-zero norm." << endl;
349 std::vector<ScalarType> zeros(numvecs,STS::zero());
350 MVT::MvScale(*B,zeros);
351 MVT::MvNorm(*B, norms);
352 for (
int i=0; i<numvecs; i++) {
353 if ( norms[i] != zero_mag ) {
355 <<
"*** ERROR *** MultiVecTraits::MvScale(alphas) "
356 <<
"Supposedly zero vector has non-zero norm." << endl;
378 std::vector<MagType> norms(numvecs);
381 MVT::MvNorm(*B, norms);
382 bool BadNormWarning =
false;
383 for (
int i=0; i<numvecs; i++) {
384 if ( norms[i] < zero_mag ) {
386 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
387 <<
"Vector had negative norm." << endl;
390 else if ( norms[i] != STS::squareroot(MVT::GetGlobalLength(*B)) && !BadNormWarning ) {
393 <<
"Warning testing MultiVecTraits::MvInit()." << endl
394 <<
"Ones std::vector should have norm std::sqrt(dim)." << endl
395 <<
"norms[i]: " << norms[i] <<
"\tdim: " << MVT::GetGlobalLength(*B) << endl << endl;
396 BadNormWarning =
true;
411 std::vector<MagType> norms(numvecs);
412 MVT::MvInit(*B, zero_mag);
413 MVT::MvNorm(*B, norms);
414 for (
int i=0; i<numvecs; i++) {
415 if ( norms[i] < zero_mag ) {
417 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
418 <<
"Vector had negative norm." << endl;
421 else if ( norms[i] != zero_mag ) {
423 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
424 <<
"Zero std::vector should have norm zero." << endl;
438 std::vector<MagType> norms(numvecs), norms2(numvecs);
440 B = MVT::Clone(*A,numvecs);
442 MVT::MvNorm(*B, norms);
443 C = MVT::CloneCopy(*B,ind);
444 MVT::MvNorm(*C, norms2);
445 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
447 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
448 <<
"Wrong number of vectors." << endl;
451 if ( MVT::GetGlobalLength(*C) != MVT::GetGlobalLength(*B) ) {
453 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
454 <<
"Vector lengths don't match." << endl;
457 for (
int i=0; i<numvecs_2; i++) {
458 if (STS::magnitude (norms2[i] - norms[ind[i]]) > tol) {
460 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
461 <<
"Copied vectors do not agree: "
462 << norms2[i] <<
" != " << norms[ind[i]] << endl
463 <<
"Difference " << STS::magnitude (norms2[i] - norms[ind[i]])
464 <<
" exceeds the tolerance 100*eps = " << tol << endl;
470 MVT::MvInit(*B,zero);
471 MVT::MvNorm(*C, norms);
472 for (
int i=0; i<numvecs_2; i++) {
474 if (STS::magnitude (norms2[i] - norms[i]) > tol) {
476 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
477 <<
"Copied vectors were not independent." << endl
478 << norms2[i] <<
" != " << norms[i] << endl
479 <<
"Difference " << STS::magnitude (norms2[i] - norms[i])
480 <<
" exceeds the tolerance 100*eps = " << tol << endl;
493 std::vector<MagType> norms(numvecs), norms2(numvecs);
495 B = MVT::Clone(*A,numvecs);
497 MVT::MvNorm(*B, norms);
498 C = MVT::CloneCopy(*B);
499 MVT::MvNorm(*C, norms2);
500 if ( MVT::GetNumberVecs(*C) != numvecs ) {
502 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
503 <<
"Wrong number of vectors." << endl;
506 for (
int i=0; i<numvecs; i++) {
507 if (STS::magnitude (norms2[i] - norms[i]) > tol) {
509 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
510 <<
"Copied vectors do not agree: "
511 << norms2[i] <<
" != " << norms[i] << endl
512 <<
"Difference " << STS::magnitude (norms2[i] - norms[i])
513 <<
" exceeds the tolerance 100*eps = " << tol << endl;
517 MVT::MvInit(*B,zero);
518 MVT::MvNorm(*C, norms);
519 for (
int i=0; i<numvecs; i++) {
521 if (STS::magnitude (norms2[i] - norms[i]) > tol) {
523 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
524 <<
"Copied vectors were not independent." << endl
525 << norms2[i] <<
" != " << norms[i] << endl
526 <<
"Difference " << STS::magnitude (norms2[i] - norms[i])
527 <<
" exceeds the tolerance 100*eps = " << tol << endl;
542 std::vector<MagType> norms(numvecs), norms2(numvecs);
544 B = MVT::Clone(*A,numvecs);
546 MVT::MvNorm(*B, norms);
547 C = MVT::CloneViewNonConst(*B,ind);
548 MVT::MvNorm(*C, norms2);
549 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
551 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
552 <<
"Wrong number of vectors." << endl;
555 for (
int i=0; i<numvecs_2; i++) {
557 if (STS::magnitude (norms2[i] - norms[ind[i]]) > tol) {
559 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
560 <<
"Viewed vectors do not agree." << endl;
576 std::vector<MagType> normsB(numvecs), normsC(numvecs_2);
577 std::vector<int> allind(numvecs);
578 for (
int i=0; i<numvecs; i++) {
582 B = MVT::Clone(*A,numvecs);
584 MVT::MvNorm(*B, normsB);
585 C = MVT::CloneView(*B,ind);
586 MVT::MvNorm(*C, normsC);
587 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
589 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
590 <<
"Wrong number of vectors." << endl;
593 for (
int i=0; i<numvecs_2; i++) {
595 if (STS::magnitude (normsC[i] - normsB[ind[i]]) > tol) {
597 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
598 <<
"Viewed vectors do not agree." << endl;
618 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
619 normsC1(numvecs_2), normsC2(numvecs_2);
621 B = MVT::Clone(*A,numvecs);
622 C = MVT::Clone(*A,numvecs_2);
624 ind.resize(numvecs_2);
625 for (
int i=0; i<numvecs_2; i++) {
631 MVT::MvNorm(*B,normsB1);
632 MVT::MvNorm(*C,normsC1);
633 MVT::SetBlock(*C,ind,*B);
634 MVT::MvNorm(*B,normsB2);
635 MVT::MvNorm(*C,normsC2);
638 for (
int i=0; i<numvecs_2; i++) {
640 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
642 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
643 <<
"Operation modified source vectors." << endl;
649 for (
int i=0; i<numvecs; i++) {
652 if (STS::magnitude (normsB2[i] - normsC1[i/2]) > tol) {
654 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
655 <<
"Copied vectors do not agree: " << endl
656 << normsB2[i] <<
" != " << normsC1[i/2] << endl
657 <<
"Difference " << STS::magnitude (normsB2[i] - normsC1[i/2])
658 <<
" exceeds the tolerance 100*eps = " << tol << endl;
664 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
666 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
667 <<
"Incorrect vectors were modified." << endl
668 << normsB1[i] <<
" != " << normsB2[i] << endl
669 <<
"Difference " << STS::magnitude (normsB2[i] - normsB2[i])
670 <<
" exceeds the tolerance 100*eps = " << tol << endl;
675 MVT::MvInit(*C,zero);
676 MVT::MvNorm(*B,normsB1);
678 for (
int i=0; i<numvecs; i++) {
680 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
682 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
683 <<
"Copied vectors were not independent." << endl
684 << normsB1[i] <<
" != " << normsB2[i] << endl
685 <<
"Difference " << STS::magnitude (normsB1[i] - normsB2[i])
686 <<
" exceeds the tolerance 100*eps = " << tol << endl;
714 std::vector<MagType> normsB1(BSize), normsB2(BSize),
715 normsC1(CSize), normsC2(CSize);
717 B = MVT::Clone(*A,BSize);
718 C = MVT::Clone(*A,CSize);
721 for (
int i=0; i<setSize; i++) {
727 MVT::MvNorm(*B,normsB1);
728 MVT::MvNorm(*C,normsC1);
729 MVT::SetBlock(*C,ind,*B);
730 MVT::MvNorm(*B,normsB2);
731 MVT::MvNorm(*C,normsC2);
734 for (
int i=0; i<CSize; i++) {
736 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
738 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
739 <<
"Operation modified source vectors." << endl;
745 for (
int i=0; i<BSize; i++) {
748 const MagType diff = STS::magnitude (normsB2[i] - normsC1[i/2]);
751 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
752 <<
"Copied vectors do not agree: " << endl
753 << normsB2[i] <<
" != " << normsC1[i/2] << endl
754 <<
"Difference " << diff <<
" exceeds the tolerance 100*eps = "
761 const MagType diff = STS::magnitude (normsB1[i] - normsB2[i]);
765 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
766 <<
"Incorrect vectors were modified." << endl
767 << normsB1[i] <<
" != " << normsB2[i] << endl
768 <<
"Difference " << diff <<
" exceeds the tolerance 100*eps = "
774 MVT::MvInit(*C,zero);
775 MVT::MvNorm(*B,normsB1);
777 for (
int i=0; i<numvecs; i++) {
779 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
781 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
782 <<
"Copied vectors were not independent." << endl
783 << normsB1[i] <<
" != " << normsB2[i] << endl
784 <<
"Difference " << STS::magnitude (normsB1[i] - normsB2[i])
785 <<
" exceeds the tolerance 100*eps = " << tol << endl;
815 std::vector<MagType> normsB(p), normsC(q);
818 B = MVT::Clone(*A,p);
819 C = MVT::Clone(*A,q);
823 MVT::MvNorm(*B,normsB);
825 MVT::MvNorm(*C,normsC);
828 MVT::MvTransMv( zero, *B, *C, SDM );
833 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
834 <<
"Routine resized SerialDenseMatrix." << endl;
841 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
842 <<
"Scalar argument processed incorrectly." << endl;
847 MVT::MvTransMv( one, *B, *C, SDM );
851 for (
int i=0; i<p; i++) {
852 for (
int j=0; j<q; j++) {
853 if ( STS::magnitude(SDM(i,j))
854 > STS::magnitude(normsB[i]*normsC[j]) ) {
856 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
857 <<
"Triangle inequality did not hold: "
858 << STS::magnitude(SDM(i,j))
860 << STS::magnitude(normsB[i]*normsC[j])
868 MVT::MvTransMv( one, *B, *C, SDM );
869 for (
int i=0; i<p; i++) {
870 for (
int j=0; j<q; j++) {
871 if ( SDM(i,j) != zero ) {
873 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
874 <<
"Inner products not zero for C==0." << endl;
881 MVT::MvTransMv( one, *B, *C, SDM );
882 for (
int i=0; i<p; i++) {
883 for (
int j=0; j<q; j++) {
884 if ( SDM(i,j) != zero ) {
886 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
887 <<
"Inner products not zero for B==0." << endl;
905 std::vector<ScalarType> iprods(p+q);
906 std::vector<MagType> normsB(numvecs), normsC(numvecs);
908 B = MVT::Clone(*A,p);
909 C = MVT::Clone(*A,p);
913 MVT::MvNorm(*B,normsB);
914 MVT::MvNorm(*C,normsC);
915 MVT::MvDot( *B, *C, iprods );
916 if ( iprods.size() != p+q ) {
918 <<
"*** ERROR *** MultiVecTraits::MvDot." << endl
919 <<
"Routine resized results std::vector." << endl;
923 if ( STS::magnitude(iprods[i])
924 > STS::magnitude(normsB[i]*normsC[i]) ) {
926 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
927 <<
"Inner products not valid." << endl;
933 MVT::MvDot( *B, *C, iprods );
934 for (
int i=0; i<p; i++) {
935 if ( iprods[i] != zero ) {
937 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
938 <<
"Inner products not zero for B==0." << endl;
944 MVT::MvDot( *B, *C, iprods );
945 for (
int i=0; i<p; i++) {
946 if ( iprods[i] != zero ) {
948 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
949 <<
"Inner products not zero for C==0." << endl;
966 std::vector<MagType> normsB1(p), normsB2(p),
967 normsC1(p), normsC2(p),
968 normsD1(p), normsD2(p);
971 Teuchos::randomSyncedMatrix( Alpha );
972 Teuchos::randomSyncedMatrix( Beta );
973 ScalarType alpha = Alpha(0,0),
976 B = MVT::Clone(*A,p);
977 C = MVT::Clone(*A,p);
978 D = MVT::Clone(*A,p);
982 MVT::MvNorm(*B,normsB1);
983 MVT::MvNorm(*C,normsC1);
986 MVT::MvAddMv(zero,*B,one,*C,*D);
987 MVT::MvNorm(*B,normsB2);
988 MVT::MvNorm(*C,normsC2);
989 MVT::MvNorm(*D,normsD1);
990 for (
int i=0; i<p; i++) {
991 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
993 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
994 <<
"Input arguments were modified." << endl;
997 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
999 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1000 <<
"Input arguments were modified." << endl;
1003 else if (STS::magnitude (normsC1[i] - normsD1[i]) > tol) {
1005 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1006 <<
"Assignment did not work." << endl;
1012 MVT::MvAddMv(one,*B,zero,*C,*D);
1013 MVT::MvNorm(*B,normsB2);
1014 MVT::MvNorm(*C,normsC2);
1015 MVT::MvNorm(*D,normsD1);
1016 for (
int i=0; i<p; i++) {
1017 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1019 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1020 <<
"Input arguments were modified." << endl;
1023 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1025 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1026 <<
"Input arguments were modified." << endl;
1029 else if (STS::magnitude (normsB1[i] - normsD1[i]) > tol) {
1031 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1032 <<
"Assignment did not work." << endl;
1040 MVT::MvAddMv(alpha,*B,beta,*C,*D);
1041 MVT::MvNorm(*B,normsB2);
1042 MVT::MvNorm(*C,normsC2);
1043 MVT::MvNorm(*D,normsD1);
1045 for (
int i=0; i<p; i++) {
1046 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1048 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1049 <<
"Input arguments were modified." << endl;
1052 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1054 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1055 <<
"Input arguments were modified." << endl;
1061 MVT::MvAddMv(alpha,*B,beta,*C,*D);
1062 MVT::MvNorm(*B,normsB2);
1063 MVT::MvNorm(*C,normsC2);
1064 MVT::MvNorm(*D,normsD2);
1067 for (
int i=0; i<p; i++) {
1068 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1070 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1071 <<
"Input arguments were modified." << endl;
1074 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1076 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1077 <<
"Input arguments were modified." << endl;
1080 else if (STS::magnitude (normsD1[i] - normsD2[i]) > tol) {
1082 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1083 <<
"Results varies depending on initial state of dest vectors." << endl;
1111 std::vector<MagType> normsB(p),
1113 std::vector<int> lclindex(p);
1114 for (
int i=0; i<p; i++) lclindex[i] = i;
1116 B = MVT::Clone(*A,p);
1117 C = MVT::CloneView(*B,lclindex);
1118 D = MVT::CloneViewNonConst(*B,lclindex);
1121 MVT::MvNorm(*B,normsB);
1124 MVT::MvAddMv(zero,*B,one,*C,*D);
1125 MVT::MvNorm(*D,normsD);
1126 for (
int i=0; i<p; i++) {
1127 if (STS::magnitude (normsB[i] - normsD[i]) > tol) {
1129 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1130 <<
"Assignment did not work." << endl;
1136 MVT::MvAddMv(one,*B,zero,*C,*D);
1137 MVT::MvNorm(*D,normsD);
1138 for (
int i=0; i<p; i++) {
1139 if (STS::magnitude (normsB[i] - normsD[i]) > tol) {
1141 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1142 <<
"Assignment did not work." << endl;
1160 const int p = 7, q = 5;
1163 std::vector<MagType> normsC1(q), normsC2(q),
1164 normsB1(p), normsB2(p);
1166 B = MVT::Clone(*A,p);
1167 C = MVT::Clone(*A,q);
1172 MVT::MvNorm(*B,normsB1);
1173 MVT::MvNorm(*C,normsC1);
1174 Teuchos::randomSyncedMatrix(SDM);
1175 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1176 MVT::MvNorm(*B,normsB2);
1177 MVT::MvNorm(*C,normsC2);
1178 for (
int i=0; i<p; i++) {
1179 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1181 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1182 <<
"Input vectors were modified." << endl;
1186 for (
int i=0; i<q; i++) {
1187 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1189 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1190 <<
"Arithmetic test 1 failed." << endl;
1198 MVT::MvNorm(*B,normsB1);
1199 MVT::MvNorm(*C,normsC1);
1200 Teuchos::randomSyncedMatrix(SDM);
1201 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1202 MVT::MvNorm(*B,normsB2);
1203 MVT::MvNorm(*C,normsC2);
1204 for (
int i=0; i<p; i++) {
1205 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1207 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1208 <<
"Input vectors were modified." << endl;
1212 for (
int i=0; i<q; i++) {
1213 if ( normsC2[i] != zero ) {
1215 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1216 <<
"Arithmetic test 2 failed: "
1229 MVT::MvNorm(*B,normsB1);
1230 MVT::MvNorm(*C,normsC1);
1232 for (
int i=0; i<q; i++) {
1235 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1236 MVT::MvNorm(*B,normsB2);
1237 MVT::MvNorm(*C,normsC2);
1238 for (
int i=0; i<p; i++) {
1239 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1241 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1242 <<
"Input vectors were modified." << endl;
1246 for (
int i=0; i<q; i++) {
1247 if (STS::magnitude (normsB1[i] - normsC2[i]) > tol) {
1249 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1250 <<
"Arithmetic test 3 failed: "
1262 MVT::MvNorm(*B,normsB1);
1263 MVT::MvNorm(*C,normsC1);
1265 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1266 MVT::MvNorm(*B,normsB2);
1267 MVT::MvNorm(*C,normsC2);
1268 for (
int i=0; i<p; i++) {
1269 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1271 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1272 <<
"Input vectors were modified." << endl;
1276 for (
int i=0; i<q; i++) {
1277 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1279 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1280 <<
"Arithmetic test 4 failed." << endl;
1296 const int p = 5, q = 7;
1299 std::vector<MagType> normsC1(q), normsC2(q),
1300 normsB1(p), normsB2(p);
1302 B = MVT::Clone(*A,p);
1303 C = MVT::Clone(*A,q);
1308 MVT::MvNorm(*B,normsB1);
1309 MVT::MvNorm(*C,normsC1);
1310 Teuchos::randomSyncedMatrix(SDM);
1311 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1312 MVT::MvNorm(*B,normsB2);
1313 MVT::MvNorm(*C,normsC2);
1314 for (
int i=0; i<p; i++) {
1315 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1317 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1318 <<
"Input vectors were modified." << endl;
1322 for (
int i=0; i<q; i++) {
1323 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1325 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1326 <<
"Arithmetic test 5 failed." << endl;
1334 MVT::MvNorm(*B,normsB1);
1335 MVT::MvNorm(*C,normsC1);
1336 Teuchos::randomSyncedMatrix(SDM);
1337 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1338 MVT::MvNorm(*B,normsB2);
1339 MVT::MvNorm(*C,normsC2);
1340 for (
int i=0; i<p; i++) {
1341 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1343 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1344 <<
"Input vectors were modified." << endl;
1348 for (
int i=0; i<q; i++) {
1349 if ( normsC2[i] != zero ) {
1351 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1352 <<
"Arithmetic test 6 failed: "
1364 MVT::MvNorm(*B,normsB1);
1365 MVT::MvNorm(*C,normsC1);
1367 for (
int i=0; i<p; i++) {
1370 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1371 MVT::MvNorm(*B,normsB2);
1372 MVT::MvNorm(*C,normsC2);
1373 for (
int i=0; i<p; i++) {
1374 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1376 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1377 <<
"Input vectors were modified." << endl;
1381 for (
int i=0; i<p; i++) {
1382 if (STS::magnitude (normsB1[i] - normsC2[i]) > tol) {
1384 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1385 <<
"Arithmetic test 7 failed." << endl;
1389 for (
int i=p; i<q; i++) {
1390 if ( normsC2[i] != zero ) {
1392 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1393 <<
"Arithmetic test 7 failed." << endl;
1401 MVT::MvNorm(*B,normsB1);
1402 MVT::MvNorm(*C,normsC1);
1404 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1405 MVT::MvNorm(*B,normsB2);
1406 MVT::MvNorm(*C,normsC2);
1407 for (
int i=0; i<p; i++) {
1408 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1410 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1411 <<
"Input vectors were modified." << endl;
1415 for (
int i=0; i<q; i++) {
1416 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1418 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1419 <<
"Arithmetic test 8 failed." << endl;
1452 template<
class ScalarType,
class MV,
class OP>
1462 typedef typename STS::magnitudeType MagType;
1466 SetScientific<ScalarType> sci (om->stream (
Warnings));
1471 const MagType tol = Teuchos::as<MagType> (100) * STS::eps ();
1483 typedef typename STS::magnitudeType MagType;
1485 const int numvecs = 10;
1488 C = MVT::Clone(*A,numvecs);
1490 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
1491 normsC1(numvecs), normsC2(numvecs);
1492 bool NonDeterministicWarning;
1503 MVT::MvNorm(*B,normsB1);
1504 OPT::Apply(*M,*B,*C);
1505 MVT::MvNorm(*B,normsB2);
1506 MVT::MvNorm(*C,normsC2);
1507 for (
int i=0; i<numvecs; i++) {
1508 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1510 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1511 <<
"Apply() modified the input vectors." << endl
1512 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1513 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1514 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1517 if (normsC2[i] != STS::zero()) {
1519 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1520 <<
"Operator applied to zero did not return zero." << endl;
1527 MVT::MvNorm(*B,normsB1);
1528 OPT::Apply(*M,*B,*C);
1529 MVT::MvNorm(*B,normsB2);
1530 MVT::MvNorm(*C,normsC2);
1531 bool ZeroWarning =
false;
1532 for (
int i=0; i<numvecs; i++) {
1533 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1535 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1536 <<
"Apply() modified the input vectors." << endl
1537 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1538 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1539 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1542 if (normsC2[i] == STS::zero() && ZeroWarning==
false ) {
1544 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1545 <<
"Operator applied to random vectors returned zero." << endl;
1552 MVT::MvNorm(*B,normsB1);
1554 OPT::Apply(*M,*B,*C);
1555 MVT::MvNorm(*B,normsB2);
1556 MVT::MvNorm(*C,normsC1);
1557 for (
int i=0; i<numvecs; i++) {
1558 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1560 <<
"*** ERROR *** OperatorTraits::Apply() [3]" << endl
1561 <<
"Apply() modified the input vectors." << endl
1562 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1563 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1564 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1575 OPT::Apply(*M,*B,*C);
1576 MVT::MvNorm(*B,normsB2);
1577 MVT::MvNorm(*C,normsC2);
1578 NonDeterministicWarning =
false;
1579 for (
int i=0; i<numvecs; i++) {
1580 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1582 <<
"*** ERROR *** OperatorTraits::Apply() [4]" << endl
1583 <<
"Apply() modified the input vectors." << endl
1584 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1585 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1586 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1589 if (normsC1[i] != normsC2[i] && !NonDeterministicWarning) {
1592 <<
"*** WARNING *** OperatorTraits::Apply() [4]" << endl
1593 <<
"Apply() returned two different results." << endl << endl;
1594 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)
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