10 #ifndef BELOS_MVOPTESTER_HPP
11 #define BELOS_MVOPTESTER_HPP
31 #include "Teuchos_SetScientific.hpp"
52 template<
class ScalarType,
class MV >
61 typedef typename STS::magnitudeType MagType;
65 SetScientific<ScalarType> sci (om->stream (
Warnings));
70 const MagType tol = Teuchos::as<MagType> (100) * STS::eps ();
146 const ScalarType one = STS::one();
147 const ScalarType zero = STS::zero();
151 const int numvecs = 10;
152 const int numvecs_2 = 5;
154 std::vector<int> ind(numvecs_2);
175 if ( MVT::GetNumberVecs(*A) <= 0 ) {
177 <<
"*** ERROR *** MultiVectorTraits::GetNumberVecs()." << endl
178 <<
"Returned <= 0." << endl;
187 if ( MVT::GetGlobalLength(*A) <= 0 ) {
189 <<
"*** ERROR *** MultiVectorTraitsExt::GetGlobalLength()" << endl
190 <<
"Returned <= 0." << endl;
205 std::vector<MagType> norms(2*numvecs);
206 bool ResizeWarning =
false;
207 if ( MVT::GetNumberVecs(*B) != numvecs ) {
209 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
210 <<
"Did not allocate requested number of vectors." << endl;
213 if ( MVT::GetGlobalLength(*B) != MVT::GetGlobalLength(*A) ) {
215 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
216 <<
"Did not allocate requested number of vectors." << endl;
219 MVT::MvNorm(*B, norms);
220 if ( norms.size() != 2*numvecs && ResizeWarning==false ) {
222 <<
"*** WARNING *** MultiVecTraits::MvNorm()." << endl
223 <<
"Method resized the output vector." << endl;
224 ResizeWarning =
true;
226 for (
int i=0; i<numvecs; i++) {
227 if ( norms[i] < zero_mag ) {
229 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
230 <<
"Vector had negative norm." << endl;
254 std::vector<MagType> norms(numvecs), norms2(numvecs);
257 MVT::MvNorm(*B, norms);
258 for (
int i=0; i<numvecs; i++) {
259 if ( norms[i] != zero_mag ) {
261 <<
"*** ERROR *** MultiVecTraits::MvInit() "
262 <<
"and MultiVecTraits::MvNorm()" << endl
263 <<
"Supposedly zero vector has non-zero norm." << endl;
268 MVT::MvNorm(*B, norms);
270 MVT::MvNorm(*B, norms2);
271 for (
int i=0; i<numvecs; i++) {
272 if ( norms[i] == zero_mag || norms2[i] == zero_mag ) {
274 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
275 <<
"Random vector was empty (very unlikely)." << endl;
278 else if ( norms[i] < zero_mag || norms2[i] < zero_mag ) {
280 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
281 <<
"Vector had negative norm." << endl;
284 else if ( norms[i] == norms2[i] ) {
286 <<
"*** ERROR *** MutliVecTraits::MvRandom()." << endl
287 <<
"Vectors not random enough." << endl;
303 std::vector<MagType> norms(numvecs);
306 MVT::MvScale(*B,STS::zero());
307 MVT::MvNorm(*B, norms);
308 for (
int i=0; i<numvecs; i++) {
309 if ( norms[i] != zero_mag ) {
311 <<
"*** ERROR *** MultiVecTraits::MvScale(alpha) "
312 <<
"Supposedly zero vector has non-zero norm." << endl;
318 std::vector<ScalarType> zeros(numvecs,STS::zero());
319 MVT::MvScale(*B,zeros);
320 MVT::MvNorm(*B, norms);
321 for (
int i=0; i<numvecs; i++) {
322 if ( norms[i] != zero_mag ) {
324 <<
"*** ERROR *** MultiVecTraits::MvScale(alphas) "
325 <<
"Supposedly zero vector has non-zero norm." << endl;
347 std::vector<MagType> norms(numvecs);
350 MVT::MvNorm(*B, norms);
351 bool BadNormWarning =
false;
352 for (
int i=0; i<numvecs; i++) {
353 if ( norms[i] < zero_mag ) {
355 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
356 <<
"Vector had negative norm." << endl;
359 else if ( norms[i] != STS::squareroot(MVT::GetGlobalLength(*B)) && !BadNormWarning ) {
362 <<
"Warning testing MultiVecTraits::MvInit()." << endl
363 <<
"Ones std::vector should have norm std::sqrt(dim)." << endl
364 <<
"norms[i]: " << norms[i] <<
"\tdim: " << MVT::GetGlobalLength(*B) << endl << endl;
365 BadNormWarning =
true;
380 std::vector<MagType> norms(numvecs);
381 MVT::MvInit(*B, zero_mag);
382 MVT::MvNorm(*B, norms);
383 for (
int i=0; i<numvecs; i++) {
384 if ( norms[i] < zero_mag ) {
386 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
387 <<
"Vector had negative norm." << endl;
390 else if ( norms[i] != zero_mag ) {
392 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
393 <<
"Zero std::vector should have norm zero." << endl;
407 std::vector<MagType> norms(numvecs), norms2(numvecs);
409 B = MVT::Clone(*A,numvecs);
411 MVT::MvNorm(*B, norms);
412 C = MVT::CloneCopy(*B,ind);
413 MVT::MvNorm(*C, norms2);
414 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
416 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
417 <<
"Wrong number of vectors." << endl;
420 if ( MVT::GetGlobalLength(*C) != MVT::GetGlobalLength(*B) ) {
422 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
423 <<
"Vector lengths don't match." << endl;
426 for (
int i=0; i<numvecs_2; i++) {
427 if (STS::magnitude (norms2[i] - norms[ind[i]]) > tol) {
429 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
430 <<
"Copied vectors do not agree: "
431 << norms2[i] <<
" != " << norms[ind[i]] << endl
432 <<
"Difference " << STS::magnitude (norms2[i] - norms[ind[i]])
433 <<
" exceeds the tolerance 100*eps = " << tol << endl;
439 MVT::MvInit(*B,zero);
440 MVT::MvNorm(*C, norms);
441 for (
int i=0; i<numvecs_2; i++) {
443 if (STS::magnitude (norms2[i] - norms[i]) > tol) {
445 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
446 <<
"Copied vectors were not independent." << endl
447 << norms2[i] <<
" != " << norms[i] << endl
448 <<
"Difference " << STS::magnitude (norms2[i] - norms[i])
449 <<
" exceeds the tolerance 100*eps = " << tol << endl;
462 std::vector<MagType> norms(numvecs), norms2(numvecs);
464 B = MVT::Clone(*A,numvecs);
466 MVT::MvNorm(*B, norms);
467 C = MVT::CloneCopy(*B);
468 MVT::MvNorm(*C, norms2);
469 if ( MVT::GetNumberVecs(*C) != numvecs ) {
471 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
472 <<
"Wrong number of vectors." << endl;
475 for (
int i=0; i<numvecs; i++) {
476 if (STS::magnitude (norms2[i] - norms[i]) > tol) {
478 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
479 <<
"Copied vectors do not agree: "
480 << norms2[i] <<
" != " << norms[i] << endl
481 <<
"Difference " << STS::magnitude (norms2[i] - norms[i])
482 <<
" exceeds the tolerance 100*eps = " << tol << endl;
486 MVT::MvInit(*B,zero);
487 MVT::MvNorm(*C, norms);
488 for (
int i=0; i<numvecs; i++) {
490 if (STS::magnitude (norms2[i] - norms[i]) > tol) {
492 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
493 <<
"Copied vectors were not independent." << endl
494 << norms2[i] <<
" != " << norms[i] << endl
495 <<
"Difference " << STS::magnitude (norms2[i] - norms[i])
496 <<
" exceeds the tolerance 100*eps = " << tol << endl;
511 std::vector<MagType> norms(numvecs), norms2(numvecs);
513 B = MVT::Clone(*A,numvecs);
515 MVT::MvNorm(*B, norms);
516 C = MVT::CloneViewNonConst(*B,ind);
517 MVT::MvNorm(*C, norms2);
518 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
520 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
521 <<
"Wrong number of vectors." << endl;
524 for (
int i=0; i<numvecs_2; i++) {
526 if (STS::magnitude (norms2[i] - norms[ind[i]]) > tol) {
528 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
529 <<
"Viewed vectors do not agree." << endl;
545 std::vector<MagType> normsB(numvecs), normsC(numvecs_2);
546 std::vector<int> allind(numvecs);
547 for (
int i=0; i<numvecs; i++) {
551 B = MVT::Clone(*A,numvecs);
553 MVT::MvNorm(*B, normsB);
554 C = MVT::CloneView(*B,ind);
555 MVT::MvNorm(*C, normsC);
556 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
558 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
559 <<
"Wrong number of vectors." << endl;
562 for (
int i=0; i<numvecs_2; i++) {
564 if (STS::magnitude (normsC[i] - normsB[ind[i]]) > tol) {
566 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
567 <<
"Viewed vectors do not agree." << endl;
587 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
588 normsC1(numvecs_2), normsC2(numvecs_2);
590 B = MVT::Clone(*A,numvecs);
591 C = MVT::Clone(*A,numvecs_2);
593 ind.resize(numvecs_2);
594 for (
int i=0; i<numvecs_2; i++) {
600 MVT::MvNorm(*B,normsB1);
601 MVT::MvNorm(*C,normsC1);
602 MVT::SetBlock(*C,ind,*B);
603 MVT::MvNorm(*B,normsB2);
604 MVT::MvNorm(*C,normsC2);
607 for (
int i=0; i<numvecs_2; i++) {
609 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
611 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
612 <<
"Operation modified source vectors." << endl;
618 for (
int i=0; i<numvecs; i++) {
621 if (STS::magnitude (normsB2[i] - normsC1[i/2]) > tol) {
623 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
624 <<
"Copied vectors do not agree: " << endl
625 << normsB2[i] <<
" != " << normsC1[i/2] << endl
626 <<
"Difference " << STS::magnitude (normsB2[i] - normsC1[i/2])
627 <<
" exceeds the tolerance 100*eps = " << tol << endl;
633 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
635 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
636 <<
"Incorrect vectors were modified." << endl
637 << normsB1[i] <<
" != " << normsB2[i] << endl
638 <<
"Difference " << STS::magnitude (normsB2[i] - normsB2[i])
639 <<
" exceeds the tolerance 100*eps = " << tol << endl;
644 MVT::MvInit(*C,zero);
645 MVT::MvNorm(*B,normsB1);
647 for (
int i=0; i<numvecs; i++) {
649 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
651 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
652 <<
"Copied vectors were not independent." << endl
653 << normsB1[i] <<
" != " << normsB2[i] << endl
654 <<
"Difference " << STS::magnitude (normsB1[i] - normsB2[i])
655 <<
" exceeds the tolerance 100*eps = " << tol << endl;
683 std::vector<MagType> normsB1(BSize), normsB2(BSize),
684 normsC1(CSize), normsC2(CSize);
686 B = MVT::Clone(*A,BSize);
687 C = MVT::Clone(*A,CSize);
690 for (
int i=0; i<setSize; i++) {
696 MVT::MvNorm(*B,normsB1);
697 MVT::MvNorm(*C,normsC1);
698 MVT::SetBlock(*C,ind,*B);
699 MVT::MvNorm(*B,normsB2);
700 MVT::MvNorm(*C,normsC2);
703 for (
int i=0; i<CSize; i++) {
705 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
707 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
708 <<
"Operation modified source vectors." << endl;
714 for (
int i=0; i<BSize; i++) {
717 const MagType diff = STS::magnitude (normsB2[i] - normsC1[i/2]);
720 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
721 <<
"Copied vectors do not agree: " << endl
722 << normsB2[i] <<
" != " << normsC1[i/2] << endl
723 <<
"Difference " << diff <<
" exceeds the tolerance 100*eps = "
730 const MagType diff = STS::magnitude (normsB1[i] - normsB2[i]);
734 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
735 <<
"Incorrect vectors were modified." << endl
736 << normsB1[i] <<
" != " << normsB2[i] << endl
737 <<
"Difference " << diff <<
" exceeds the tolerance 100*eps = "
743 MVT::MvInit(*C,zero);
744 MVT::MvNorm(*B,normsB1);
746 for (
int i=0; i<numvecs; i++) {
748 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
750 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
751 <<
"Copied vectors were not independent." << endl
752 << normsB1[i] <<
" != " << normsB2[i] << endl
753 <<
"Difference " << STS::magnitude (normsB1[i] - normsB2[i])
754 <<
" exceeds the tolerance 100*eps = " << tol << endl;
784 std::vector<MagType> normsB(p), normsC(q);
787 B = MVT::Clone(*A,p);
788 C = MVT::Clone(*A,q);
792 MVT::MvNorm(*B,normsB);
794 MVT::MvNorm(*C,normsC);
797 MVT::MvTransMv( zero, *B, *C, SDM );
802 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
803 <<
"Routine resized SerialDenseMatrix." << endl;
810 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
811 <<
"Scalar argument processed incorrectly." << endl;
816 MVT::MvTransMv( one, *B, *C, SDM );
820 for (
int i=0; i<p; i++) {
821 for (
int j=0; j<q; j++) {
822 if ( STS::magnitude(SDM(i,j))
823 > STS::magnitude(normsB[i]*normsC[j]) ) {
825 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
826 <<
"Triangle inequality did not hold: "
827 << STS::magnitude(SDM(i,j))
829 << STS::magnitude(normsB[i]*normsC[j])
837 MVT::MvTransMv( one, *B, *C, SDM );
838 for (
int i=0; i<p; i++) {
839 for (
int j=0; j<q; j++) {
840 if ( SDM(i,j) != zero ) {
842 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
843 <<
"Inner products not zero for C==0." << endl;
850 MVT::MvTransMv( one, *B, *C, SDM );
851 for (
int i=0; i<p; i++) {
852 for (
int j=0; j<q; j++) {
853 if ( SDM(i,j) != zero ) {
855 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
856 <<
"Inner products not zero for B==0." << endl;
874 std::vector<ScalarType> iprods(p+q);
875 std::vector<MagType> normsB(numvecs), normsC(numvecs);
877 B = MVT::Clone(*A,p);
878 C = MVT::Clone(*A,p);
882 MVT::MvNorm(*B,normsB);
883 MVT::MvNorm(*C,normsC);
884 MVT::MvDot( *B, *C, iprods );
885 if ( iprods.size() != p+q ) {
887 <<
"*** ERROR *** MultiVecTraits::MvDot." << endl
888 <<
"Routine resized results std::vector." << endl;
892 if ( STS::magnitude(iprods[i])
893 > STS::magnitude(normsB[i]*normsC[i]) ) {
895 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
896 <<
"Inner products not valid." << endl;
902 MVT::MvDot( *B, *C, iprods );
903 for (
int i=0; i<p; i++) {
904 if ( iprods[i] != zero ) {
906 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
907 <<
"Inner products not zero for B==0." << endl;
913 MVT::MvDot( *B, *C, iprods );
914 for (
int i=0; i<p; i++) {
915 if ( iprods[i] != zero ) {
917 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
918 <<
"Inner products not zero for C==0." << endl;
935 std::vector<MagType> normsB1(p), normsB2(p),
936 normsC1(p), normsC2(p),
937 normsD1(p), normsD2(p);
940 Teuchos::randomSyncedMatrix( Alpha );
941 Teuchos::randomSyncedMatrix( Beta );
942 ScalarType alpha = Alpha(0,0),
945 B = MVT::Clone(*A,p);
946 C = MVT::Clone(*A,p);
947 D = MVT::Clone(*A,p);
951 MVT::MvNorm(*B,normsB1);
952 MVT::MvNorm(*C,normsC1);
955 MVT::MvAddMv(zero,*B,one,*C,*D);
956 MVT::MvNorm(*B,normsB2);
957 MVT::MvNorm(*C,normsC2);
958 MVT::MvNorm(*D,normsD1);
959 for (
int i=0; i<p; i++) {
960 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
962 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
963 <<
"Input arguments were modified." << endl;
966 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
968 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
969 <<
"Input arguments were modified." << endl;
972 else if (STS::magnitude (normsC1[i] - normsD1[i]) > tol) {
974 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
975 <<
"Assignment did not work." << endl;
981 MVT::MvAddMv(one,*B,zero,*C,*D);
982 MVT::MvNorm(*B,normsB2);
983 MVT::MvNorm(*C,normsC2);
984 MVT::MvNorm(*D,normsD1);
985 for (
int i=0; i<p; i++) {
986 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
988 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
989 <<
"Input arguments were modified." << endl;
992 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
994 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
995 <<
"Input arguments were modified." << endl;
998 else if (STS::magnitude (normsB1[i] - normsD1[i]) > tol) {
1000 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1001 <<
"Assignment did not work." << endl;
1009 MVT::MvAddMv(alpha,*B,beta,*C,*D);
1010 MVT::MvNorm(*B,normsB2);
1011 MVT::MvNorm(*C,normsC2);
1012 MVT::MvNorm(*D,normsD1);
1014 for (
int i=0; i<p; i++) {
1015 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1017 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1018 <<
"Input arguments were modified." << endl;
1021 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1023 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1024 <<
"Input arguments were modified." << endl;
1030 MVT::MvAddMv(alpha,*B,beta,*C,*D);
1031 MVT::MvNorm(*B,normsB2);
1032 MVT::MvNorm(*C,normsC2);
1033 MVT::MvNorm(*D,normsD2);
1036 for (
int i=0; i<p; i++) {
1037 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1039 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1040 <<
"Input arguments were modified." << endl;
1043 else if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1045 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1046 <<
"Input arguments were modified." << endl;
1049 else if (STS::magnitude (normsD1[i] - normsD2[i]) > tol) {
1051 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1052 <<
"Results varies depending on initial state of dest vectors." << endl;
1080 std::vector<MagType> normsB(p),
1082 std::vector<int> lclindex(p);
1083 for (
int i=0; i<p; i++) lclindex[i] = i;
1085 B = MVT::Clone(*A,p);
1086 C = MVT::CloneView(*B,lclindex);
1087 D = MVT::CloneViewNonConst(*B,lclindex);
1090 MVT::MvNorm(*B,normsB);
1093 MVT::MvAddMv(zero,*B,one,*C,*D);
1094 MVT::MvNorm(*D,normsD);
1095 for (
int i=0; i<p; i++) {
1096 if (STS::magnitude (normsB[i] - normsD[i]) > tol) {
1098 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1099 <<
"Assignment did not work." << endl;
1105 MVT::MvAddMv(one,*B,zero,*C,*D);
1106 MVT::MvNorm(*D,normsD);
1107 for (
int i=0; i<p; i++) {
1108 if (STS::magnitude (normsB[i] - normsD[i]) > tol) {
1110 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1111 <<
"Assignment did not work." << endl;
1129 const int p = 7, q = 5;
1132 std::vector<MagType> normsC1(q), normsC2(q),
1133 normsB1(p), normsB2(p);
1135 B = MVT::Clone(*A,p);
1136 C = MVT::Clone(*A,q);
1141 MVT::MvNorm(*B,normsB1);
1142 MVT::MvNorm(*C,normsC1);
1143 Teuchos::randomSyncedMatrix(SDM);
1144 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1145 MVT::MvNorm(*B,normsB2);
1146 MVT::MvNorm(*C,normsC2);
1147 for (
int i=0; i<p; i++) {
1148 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1150 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1151 <<
"Input vectors were modified." << endl;
1155 for (
int i=0; i<q; i++) {
1156 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1158 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1159 <<
"Arithmetic test 1 failed." << endl;
1167 MVT::MvNorm(*B,normsB1);
1168 MVT::MvNorm(*C,normsC1);
1169 Teuchos::randomSyncedMatrix(SDM);
1170 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1171 MVT::MvNorm(*B,normsB2);
1172 MVT::MvNorm(*C,normsC2);
1173 for (
int i=0; i<p; i++) {
1174 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1176 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1177 <<
"Input vectors were modified." << endl;
1181 for (
int i=0; i<q; i++) {
1182 if ( normsC2[i] != zero ) {
1184 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1185 <<
"Arithmetic test 2 failed: "
1198 MVT::MvNorm(*B,normsB1);
1199 MVT::MvNorm(*C,normsC1);
1201 for (
int i=0; i<q; i++) {
1204 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1205 MVT::MvNorm(*B,normsB2);
1206 MVT::MvNorm(*C,normsC2);
1207 for (
int i=0; i<p; i++) {
1208 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1210 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1211 <<
"Input vectors were modified." << endl;
1215 for (
int i=0; i<q; i++) {
1216 if (STS::magnitude (normsB1[i] - normsC2[i]) > tol) {
1218 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1219 <<
"Arithmetic test 3 failed: "
1231 MVT::MvNorm(*B,normsB1);
1232 MVT::MvNorm(*C,normsC1);
1234 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1235 MVT::MvNorm(*B,normsB2);
1236 MVT::MvNorm(*C,normsC2);
1237 for (
int i=0; i<p; i++) {
1238 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1240 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1241 <<
"Input vectors were modified." << endl;
1245 for (
int i=0; i<q; i++) {
1246 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1248 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1249 <<
"Arithmetic test 4 failed." << endl;
1265 const int p = 5, q = 7;
1268 std::vector<MagType> normsC1(q), normsC2(q),
1269 normsB1(p), normsB2(p);
1271 B = MVT::Clone(*A,p);
1272 C = MVT::Clone(*A,q);
1277 MVT::MvNorm(*B,normsB1);
1278 MVT::MvNorm(*C,normsC1);
1279 Teuchos::randomSyncedMatrix(SDM);
1280 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1281 MVT::MvNorm(*B,normsB2);
1282 MVT::MvNorm(*C,normsC2);
1283 for (
int i=0; i<p; i++) {
1284 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1286 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1287 <<
"Input vectors were modified." << endl;
1291 for (
int i=0; i<q; i++) {
1292 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1294 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1295 <<
"Arithmetic test 5 failed." << endl;
1303 MVT::MvNorm(*B,normsB1);
1304 MVT::MvNorm(*C,normsC1);
1305 Teuchos::randomSyncedMatrix(SDM);
1306 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1307 MVT::MvNorm(*B,normsB2);
1308 MVT::MvNorm(*C,normsC2);
1309 for (
int i=0; i<p; i++) {
1310 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1312 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1313 <<
"Input vectors were modified." << endl;
1317 for (
int i=0; i<q; i++) {
1318 if ( normsC2[i] != zero ) {
1320 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1321 <<
"Arithmetic test 6 failed: "
1333 MVT::MvNorm(*B,normsB1);
1334 MVT::MvNorm(*C,normsC1);
1336 for (
int i=0; i<p; i++) {
1339 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1340 MVT::MvNorm(*B,normsB2);
1341 MVT::MvNorm(*C,normsC2);
1342 for (
int i=0; i<p; i++) {
1343 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1345 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1346 <<
"Input vectors were modified." << endl;
1350 for (
int i=0; i<p; i++) {
1351 if (STS::magnitude (normsB1[i] - normsC2[i]) > tol) {
1353 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1354 <<
"Arithmetic test 7 failed." << endl;
1358 for (
int i=p; i<q; i++) {
1359 if ( normsC2[i] != zero ) {
1361 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1362 <<
"Arithmetic test 7 failed." << endl;
1370 MVT::MvNorm(*B,normsB1);
1371 MVT::MvNorm(*C,normsC1);
1373 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1374 MVT::MvNorm(*B,normsB2);
1375 MVT::MvNorm(*C,normsC2);
1376 for (
int i=0; i<p; i++) {
1377 if (STS::magnitude (normsB1[i] - normsB2[i]) > tol) {
1379 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1380 <<
"Input vectors were modified." << endl;
1384 for (
int i=0; i<q; i++) {
1385 if (STS::magnitude (normsC1[i] - normsC2[i]) > tol) {
1387 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1388 <<
"Arithmetic test 8 failed." << endl;
1421 template<
class ScalarType,
class MV,
class OP>
1431 typedef typename STS::magnitudeType MagType;
1435 SetScientific<ScalarType> sci (om->stream (
Warnings));
1440 const MagType tol = Teuchos::as<MagType> (100) * STS::eps ();
1452 typedef typename STS::magnitudeType MagType;
1454 const int numvecs = 10;
1457 C = MVT::Clone(*A,numvecs);
1459 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
1460 normsC1(numvecs), normsC2(numvecs);
1461 bool NonDeterministicWarning;
1472 MVT::MvNorm(*B,normsB1);
1473 OPT::Apply(*M,*B,*C);
1474 MVT::MvNorm(*B,normsB2);
1475 MVT::MvNorm(*C,normsC2);
1476 for (
int i=0; i<numvecs; i++) {
1477 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1479 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1480 <<
"Apply() modified the input vectors." << endl
1481 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1482 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1483 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1486 if (normsC2[i] != STS::zero()) {
1488 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1489 <<
"Operator applied to zero did not return zero." << endl;
1496 MVT::MvNorm(*B,normsB1);
1497 OPT::Apply(*M,*B,*C);
1498 MVT::MvNorm(*B,normsB2);
1499 MVT::MvNorm(*C,normsC2);
1500 bool ZeroWarning =
false;
1501 for (
int i=0; i<numvecs; i++) {
1502 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1504 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1505 <<
"Apply() modified the input vectors." << endl
1506 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1507 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1508 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1511 if (normsC2[i] == STS::zero() && ZeroWarning==
false ) {
1513 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1514 <<
"Operator applied to random vectors returned zero." << endl;
1521 MVT::MvNorm(*B,normsB1);
1523 OPT::Apply(*M,*B,*C);
1524 MVT::MvNorm(*B,normsB2);
1525 MVT::MvNorm(*C,normsC1);
1526 for (
int i=0; i<numvecs; i++) {
1527 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1529 <<
"*** ERROR *** OperatorTraits::Apply() [3]" << endl
1530 <<
"Apply() modified the input vectors." << endl
1531 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1532 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1533 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1544 OPT::Apply(*M,*B,*C);
1545 MVT::MvNorm(*B,normsB2);
1546 MVT::MvNorm(*C,normsC2);
1547 NonDeterministicWarning =
false;
1548 for (
int i=0; i<numvecs; i++) {
1549 if (STS::magnitude (normsB2[i] - normsB1[i]) > tol) {
1551 <<
"*** ERROR *** OperatorTraits::Apply() [4]" << endl
1552 <<
"Apply() modified the input vectors." << endl
1553 <<
"Original: " << normsB1[i] <<
"; After: " << normsB2[i] << endl
1554 <<
"Difference " << STS::magnitude (normsB2[i] - normsB1[i])
1555 <<
" exceeds the tolerance 100*eps = " << tol << endl;
1558 if (normsC1[i] != normsC2[i] && !NonDeterministicWarning) {
1561 <<
"*** WARNING *** OperatorTraits::Apply() [4]" << endl
1562 <<
"Apply() returned two different results." << endl << endl;
1563 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