42 #ifndef ANASAZI_MVOPTESTER_HPP
43 #define ANASAZI_MVOPTESTER_HPP
66 #include "Teuchos_SetScientific.hpp"
77 template<
class ScalarType,
class MV >
161 typedef typename SCT::magnitudeType MagType;
163 const ScalarType one = SCT::one();
164 const ScalarType zero = SCT::zero();
166 const MagType tol = SCT::eps()*100;
169 const int numvecs = 10;
170 const int numvecs_2 = 5;
172 std::vector<int> ind(numvecs_2);
193 if ( MVT::GetNumberVecs(*A) <= 0 ) {
195 <<
"*** ERROR *** MultiVectorTraits::GetNumberVecs()." << endl
196 <<
"Returned <= 0." << endl;
204 if ( MVT::GetGlobalLength(*A) <= 0 ) {
206 <<
"*** ERROR *** MultiVectorTraitsExt::GetGlobalLength()" << endl
207 <<
"Returned <= 0." << endl;
219 std::vector<MagType> norms(2*numvecs);
220 bool ResizeWarning =
false;
221 if ( MVT::GetNumberVecs(*B) != numvecs ) {
223 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
224 <<
"Did not allocate requested number of vectors." << endl;
227 if ( MVT::GetGlobalLength(*B) != MVT::GetGlobalLength(*A) ) {
229 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
230 <<
"Did not allocate requested number of vectors." << endl;
233 MVT::MvNorm(*B, norms);
234 if ( (
int)norms.size() != 2*numvecs && (ResizeWarning ==
false) ) {
236 <<
"*** WARNING *** MultiVecTraits::MvNorm()." << endl
237 <<
"Method resized the output vector." << endl;
238 ResizeWarning =
true;
240 for (
int i=0; i<numvecs; i++) {
241 if ( norms[i] < zero_mag ) {
243 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
244 <<
"Vector had negative norm." << endl;
268 std::vector<MagType> norms(numvecs), norms2(numvecs);
271 MVT::MvNorm(*B, norms);
272 for (
int i=0; i<numvecs; i++) {
273 if ( norms[i] != zero_mag ) {
275 <<
"*** ERROR *** MultiVecTraits::MvInit() "
276 <<
"and MultiVecTraits::MvNorm()" << endl
277 <<
"Supposedly zero vector has non-zero norm." << endl;
282 MVT::MvNorm(*B, norms);
284 MVT::MvNorm(*B, norms2);
285 for (
int i=0; i<numvecs; i++) {
286 if ( norms[i] == zero_mag || norms2[i] == zero_mag ) {
288 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
289 <<
"Random vector was empty (very unlikely)." << endl;
292 else if ( norms[i] < zero_mag || norms2[i] < zero_mag ) {
294 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
295 <<
"Vector had negative norm." << endl;
298 else if ( norms[i] == norms2[i] ) {
300 <<
"*** ERROR *** MutliVecTraits::MvRandom()." << endl
301 <<
"Vectors not random enough." << endl;
317 std::vector<MagType> norms(numvecs);
320 MVT::MvScale(*B,SCT::zero());
321 MVT::MvNorm(*B, norms);
322 for (
int i=0; i<numvecs; i++) {
323 if ( norms[i] != zero_mag ) {
325 <<
"*** ERROR *** MultiVecTraits::MvScale(alpha) "
326 <<
"Supposedly zero vector has non-zero norm." << endl;
332 std::vector<ScalarType> zeros(numvecs,SCT::zero());
333 MVT::MvScale(*B,zeros);
334 MVT::MvNorm(*B, norms);
335 for (
int i=0; i<numvecs; i++) {
336 if ( norms[i] != zero_mag ) {
338 <<
"*** ERROR *** MultiVecTraits::MvScale(alphas) "
339 <<
"Supposedly zero vector has non-zero norm." << endl;
361 std::vector<MagType> norms(numvecs);
364 MVT::MvNorm(*B, norms);
365 bool BadNormWarning =
false;
366 for (
int i=0; i<numvecs; i++) {
367 if ( norms[i] < zero_mag ) {
369 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
370 <<
"Vector had negative norm." << endl;
373 else if ( norms[i] != SCT::squareroot(MVT::GetGlobalLength(*B)) && !BadNormWarning ) {
376 <<
"Warning testing MultiVecTraits::MvInit()." << endl
377 <<
"Ones vector should have norm sqrt(dim)." << endl
378 <<
"norms[i]: " << norms[i] <<
"\tdim: " << MVT::GetGlobalLength(*B) << endl << endl;
379 BadNormWarning =
true;
394 std::vector<MagType> norms(numvecs);
395 MVT::MvInit(*B, zero_mag);
396 MVT::MvNorm(*B, norms);
397 for (
int i=0; i<numvecs; i++) {
398 if ( norms[i] < zero_mag ) {
400 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
401 <<
"Vector had negative norm." << endl;
404 else if ( norms[i] != zero_mag ) {
406 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
407 <<
"Zero vector should have norm zero." << endl;
421 std::vector<MagType> norms(numvecs), norms2(ind.size());
423 B = MVT::Clone(*A,numvecs);
425 MVT::MvNorm(*B, norms);
426 C = MVT::CloneCopy(*B,ind);
427 MVT::MvNorm(*C, norms2);
428 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
430 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
431 <<
"Wrong number of vectors." << endl;
434 if ( MVT::GetGlobalLength(*C) != MVT::GetGlobalLength(*B) ) {
436 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
437 <<
"Vector lengths don't match." << endl;
440 for (
int i=0; i<numvecs_2; i++) {
441 if ( SCT::magnitude( norms2[i] - norms[ind[i]] ) > tol ) {
443 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
444 <<
"Copied vectors do not agree:"
445 << norms2[i] <<
" != " << norms[ind[i]] << endl
446 <<
"Difference " << SCT::magnitude (norms2[i] - norms[ind[i]])
447 <<
" exceeds the tolerance 100*eps = " << tol << endl;
452 MVT::MvInit(*B,zero);
453 MVT::MvNorm(*C, norms2);
454 for (
int i=0; i<numvecs_2; i++) {
455 if ( SCT::magnitude( norms2[i] - norms2[i] ) > tol ) {
457 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
458 <<
"Copied vectors were not independent." << endl
459 <<
"Difference " << SCT::magnitude (norms2[i] - norms[i])
460 <<
" exceeds the tolerance 100*eps = " << tol << endl;
474 std::vector<MagType> norms(numvecs), norms2(numvecs);
476 B = MVT::Clone(*A,numvecs);
478 MVT::MvNorm(*B, norms);
479 C = MVT::CloneCopy(*B);
480 MVT::MvNorm(*C, norms2);
481 if ( MVT::GetNumberVecs(*C) != numvecs ) {
483 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
484 <<
"Wrong number of vectors." << endl;
487 for (
int i=0; i<numvecs; i++) {
488 if ( SCT::magnitude( norms2[i] - norms[i] ) > tol ) {
490 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
491 <<
"Copied vectors do not agree." << endl
492 <<
"Difference " << SCT::magnitude (norms2[i] - norms[i])
493 <<
" exceeds the tolerance 100*eps = " << tol << endl;
497 MVT::MvInit(*B,zero);
498 MVT::MvNorm(*C, norms);
499 for (
int i=0; i<numvecs; i++) {
500 if ( SCT::magnitude( norms2[i] - norms[i] ) > tol ) {
502 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
503 <<
"Copied vectors were not independent." << endl
504 <<
"Difference " << SCT::magnitude (norms2[i] - norms[i])
505 <<
" exceeds the tolerance 100*eps = " << tol << endl;
520 std::vector<MagType> norms(numvecs), norms2(ind.size());
522 B = MVT::Clone(*A,numvecs);
524 MVT::MvNorm(*B, norms);
525 C = MVT::CloneViewNonConst(*B,ind);
526 MVT::MvNorm(*C, norms2);
527 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
529 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
530 <<
"Wrong number of vectors." << endl;
533 for (
int i=0; i<numvecs_2; i++) {
534 if ( SCT::magnitude( norms2[i] - norms[ind[i]] ) > tol ) {
536 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
537 <<
"Viewed vectors do not agree." << endl;
553 std::vector<MagType> normsB(numvecs), normsC(ind.size());
554 std::vector<int> allind(numvecs);
555 for (
int i=0; i<numvecs; i++) {
559 B = MVT::Clone(*A,numvecs);
561 MVT::MvNorm(*B, normsB);
562 C = MVT::CloneView(*B,ind);
563 MVT::MvNorm(*C, normsC);
564 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
566 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
567 <<
"Wrong number of vectors." << endl;
570 for (
int i=0; i<numvecs_2; i++) {
571 if ( SCT::magnitude( normsC[i] - normsB[ind[i]] ) > tol ) {
573 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
574 <<
"Viewed vectors do not agree." << endl;
594 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
595 normsC1(numvecs_2), normsC2(numvecs_2);
597 B = MVT::Clone(*A,numvecs);
598 C = MVT::Clone(*A,numvecs_2);
600 ind.resize(numvecs_2);
601 for (
int i=0; i<numvecs_2; i++) {
607 MVT::MvNorm(*B,normsB1);
608 MVT::MvNorm(*C,normsC1);
609 MVT::SetBlock(*C,ind,*B);
610 MVT::MvNorm(*B,normsB2);
611 MVT::MvNorm(*C,normsC2);
614 for (
int i=0; i<numvecs_2; i++) {
615 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
617 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
618 <<
"Operation modified source vectors." << endl;
624 for (
int i=0; i<numvecs; i++) {
627 if ( SCT::magnitude(normsB2[i]-normsC1[i/2]) > tol ) {
629 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
630 <<
"Copied vectors do not agree." << endl
631 <<
"Difference " << SCT::magnitude (normsB2[i] - normsC1[i/2])
632 <<
" exceeds the tolerance 100*eps = " << tol << endl;
638 if ( SCT::magnitude(normsB1[i]-normsB2[i]) > tol ) {
640 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
641 <<
"Incorrect vectors were modified." << endl;
646 MVT::MvInit(*C,zero);
647 MVT::MvNorm(*B,normsB1);
649 for (
int i=0; i<numvecs; i++) {
650 if ( SCT::magnitude(normsB1[i]-normsB2[i]) > tol ) {
652 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
653 <<
"Copied vectors were not independent." << endl;
687 std::vector<MagType> normsB(p), normsC(q);
690 B = MVT::Clone(*A,p);
691 C = MVT::Clone(*A,q);
695 MVT::MvNorm(*B,normsB);
697 MVT::MvNorm(*C,normsC);
700 MVT::MvTransMv( zero, *B, *C, SDM );
705 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
706 <<
"Routine resized SerialDenseMatrix." << endl;
713 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
714 <<
"Scalar argument processed incorrectly." << endl;
719 MVT::MvTransMv( one, *B, *C, SDM );
723 for (
int i=0; i<p; i++) {
724 for (
int j=0; j<q; j++) {
725 if ( SCT::magnitude(SDM(i,j))
726 > SCT::magnitude(normsB[i]*normsC[j]) ) {
728 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
729 <<
"Triangle inequality did not hold: "
730 << SCT::magnitude(SDM(i,j))
732 << SCT::magnitude(normsB[i]*normsC[j])
740 MVT::MvTransMv( one, *B, *C, SDM );
741 for (
int i=0; i<p; i++) {
742 for (
int j=0; j<q; j++) {
743 if ( SDM(i,j) != zero ) {
745 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
746 <<
"Inner products not zero for C==0." << endl;
753 MVT::MvTransMv( one, *B, *C, SDM );
754 for (
int i=0; i<p; i++) {
755 for (
int j=0; j<q; j++) {
756 if ( SDM(i,j) != zero ) {
758 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
759 <<
"Inner products not zero for B==0." << endl;
777 MVT::MvTransMv( one, *B, *C, SDM2 );
778 for (
int i=0; i<p; i++) {
779 for (
int j=0; j<q; j++) {
780 if ( SDM2(i,j) != zero ) {
782 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
783 <<
"Inner products not zero for C==0 when using a view into Teuchos::SerialDenseMatrix<>." << endl;
801 std::vector<ScalarType> iprods(q);
802 std::vector<MagType> normsB(p), normsC(p);
804 B = MVT::Clone(*A,p);
805 C = MVT::Clone(*A,p);
809 MVT::MvNorm(*B,normsB);
810 MVT::MvNorm(*C,normsC);
811 MVT::MvDot( *B, *C, iprods );
812 if ( (
int)iprods.size() != q ) {
814 <<
"*** ERROR *** MultiVecTraits::MvDot." << endl
815 <<
"Routine resized results vector." << endl;
818 for (
int i=0; i<p; i++) {
819 if ( SCT::magnitude(iprods[i])
820 > SCT::magnitude(normsB[i]*normsC[i]) ) {
822 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
823 <<
"Inner products not valid." << endl;
829 MVT::MvDot( *B, *C, iprods );
830 for (
int i=0; i<p; i++) {
831 if ( iprods[i] != zero ) {
833 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
834 <<
"Inner products not zero for B==0." << endl;
840 MVT::MvDot( *B, *C, iprods );
841 for (
int i=0; i<p; i++) {
842 if ( iprods[i] != zero ) {
844 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
845 <<
"Inner products not zero for C==0." << endl;
862 std::vector<MagType> normsB1(p), normsB2(p),
863 normsC1(p), normsC2(p),
864 normsD1(p), normsD2(p);
865 ScalarType alpha = 0.5 * SCT::one(),
866 beta = 0.33 * SCT::one();
868 B = MVT::Clone(*A,p);
869 C = MVT::Clone(*A,p);
870 D = MVT::Clone(*A,p);
874 MVT::MvNorm(*B,normsB1);
875 MVT::MvNorm(*C,normsC1);
878 MVT::MvAddMv(zero,*B,one,*C,*D);
879 MVT::MvNorm(*B,normsB2);
880 MVT::MvNorm(*C,normsC2);
881 MVT::MvNorm(*D,normsD1);
882 for (
int i=0; i<p; i++) {
883 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
885 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
886 <<
"Input arguments were modified." << endl;
889 else if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
891 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
892 <<
"Input arguments were modified." << endl;
895 else if ( SCT::magnitude(normsC1[i]-normsD1[i]) > tol ) {
897 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
898 <<
"Assignment did not work." << endl;
904 MVT::MvAddMv(one,*B,zero,*C,*D);
905 MVT::MvNorm(*B,normsB2);
906 MVT::MvNorm(*C,normsC2);
907 MVT::MvNorm(*D,normsD1);
908 for (
int i=0; i<p; i++) {
909 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
911 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
912 <<
"Input arguments were modified." << endl;
915 else if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
917 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
918 <<
"Input arguments were modified." << endl;
921 else if ( SCT::magnitude( normsB1[i] - normsD1[i] ) > tol ) {
923 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
924 <<
"Assignment did not work." << endl;
932 MVT::MvAddMv(alpha,*B,beta,*C,*D);
933 MVT::MvNorm(*B,normsB2);
934 MVT::MvNorm(*C,normsC2);
935 MVT::MvNorm(*D,normsD1);
937 for (
int i=0; i<p; i++) {
938 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
940 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
941 <<
"Input arguments were modified." << endl;
944 else if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
946 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
947 <<
"Input arguments were modified." << endl;
953 MVT::MvAddMv(alpha,*B,beta,*C,*D);
954 MVT::MvNorm(*B,normsB2);
955 MVT::MvNorm(*C,normsC2);
956 MVT::MvNorm(*D,normsD2);
959 for (
int i=0; i<p; i++) {
960 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
962 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
963 <<
"Input arguments were modified." << endl;
966 else if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
968 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
969 <<
"Input arguments were modified." << endl;
972 else if ( SCT::magnitude( normsD1[i] - normsD2[i] ) > tol ) {
974 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
975 <<
"Results varies depending on initial state of dest vectors." << endl;
1003 std::vector<MagType> normsB(p),
1005 std::vector<int> lclindex(p);
1006 for (
int i=0; i<p; i++) lclindex[i] = i;
1008 B = MVT::Clone(*A,p);
1009 C = MVT::CloneView(*B,lclindex);
1010 D = MVT::CloneViewNonConst(*B,lclindex);
1013 MVT::MvNorm(*B,normsB);
1016 MVT::MvAddMv(zero,*B,one,*C,*D);
1017 MVT::MvNorm(*D,normsD);
1018 for (
int i=0; i<p; i++) {
1019 if ( SCT::magnitude( normsB[i] - normsD[i] ) > tol ) {
1021 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1022 <<
"Assignment did not work." << endl;
1028 MVT::MvAddMv(one,*B,zero,*C,*D);
1029 MVT::MvNorm(*D,normsD);
1030 for (
int i=0; i<p; i++) {
1031 if ( SCT::magnitude( normsB[i] - normsD[i] ) > tol ) {
1033 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1034 <<
"Assignment did not work." << endl;
1052 const int p = 7, q = 5;
1057 std::vector<MagType> normsC1(q), normsC2(q),
1058 normsB1(p), normsB2(p);
1060 B = MVT::Clone(*A,p);
1061 C = MVT::Clone(*A,q);
1064 Vp = MVT::Clone(*A,p);
1065 Vq = MVT::Clone(*A,q);
1068 MVT::MvTransMv( one, *Vp, *Vq, SDM );
1073 MVT::MvNorm(*B,normsB1);
1074 MVT::MvNorm(*C,normsC1);
1075 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1076 MVT::MvNorm(*B,normsB2);
1077 MVT::MvNorm(*C,normsC2);
1078 for (
int i=0; i<p; i++) {
1079 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1081 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1082 <<
"Input vectors were modified." << endl;
1086 for (
int i=0; i<q; i++) {
1087 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1089 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1090 <<
"Arithmetic test 1 failed." << endl;
1098 MVT::MvNorm(*B,normsB1);
1099 MVT::MvNorm(*C,normsC1);
1102 MVT::MvTransMv( one, *Vp, *Vq, SDM );
1103 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1104 MVT::MvNorm(*B,normsB2);
1105 MVT::MvNorm(*C,normsC2);
1106 for (
int i=0; i<p; i++) {
1107 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1109 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1110 <<
"Input vectors were modified." << endl;
1114 for (
int i=0; i<q; i++) {
1115 if ( normsC2[i] != zero ) {
1117 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1118 <<
"Arithmetic test 2 failed: "
1131 MVT::MvNorm(*B,normsB1);
1132 MVT::MvNorm(*C,normsC1);
1134 for (
int i=0; i<q; i++) {
1137 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1138 MVT::MvNorm(*B,normsB2);
1139 MVT::MvNorm(*C,normsC2);
1140 for (
int i=0; i<p; i++) {
1141 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1143 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1144 <<
"Input vectors were modified." << endl;
1148 for (
int i=0; i<q; i++) {
1149 if ( SCT::magnitude( normsB1[i] - normsC2[i] ) > tol ) {
1151 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1152 <<
"Arithmetic test 3 failed: "
1164 MVT::MvNorm(*B,normsB1);
1165 MVT::MvNorm(*C,normsC1);
1167 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1168 MVT::MvNorm(*B,normsB2);
1169 MVT::MvNorm(*C,normsC2);
1170 for (
int i=0; i<p; i++) {
1171 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1173 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1174 <<
"Input vectors were modified." << endl;
1178 for (
int i=0; i<q; i++) {
1179 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1181 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1182 <<
"Arithmetic test 4 failed." << endl;
1198 const int p = 5, q = 7;
1202 std::vector<MagType> normsC1(q), normsC2(q),
1203 normsB1(p), normsB2(p);
1205 B = MVT::Clone(*A,p);
1206 C = MVT::Clone(*A,q);
1209 Vp = MVT::Clone(*A,p);
1210 Vq = MVT::Clone(*A,q);
1213 MVT::MvTransMv( one, *Vp, *Vq, SDM );
1218 MVT::MvNorm(*B,normsB1);
1219 MVT::MvNorm(*C,normsC1);
1220 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1221 MVT::MvNorm(*B,normsB2);
1222 MVT::MvNorm(*C,normsC2);
1223 for (
int i=0; i<p; i++) {
1224 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1226 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1227 <<
"Input vectors were modified." << endl;
1231 for (
int i=0; i<q; i++) {
1232 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1234 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1235 <<
"Arithmetic test 5 failed." << endl;
1243 MVT::MvNorm(*B,normsB1);
1244 MVT::MvNorm(*C,normsC1);
1247 MVT::MvTransMv( one, *Vp, *Vq, SDM );
1248 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1249 MVT::MvNorm(*B,normsB2);
1250 MVT::MvNorm(*C,normsC2);
1251 for (
int i=0; i<p; i++) {
1252 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1254 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1255 <<
"Input vectors were modified." << endl;
1259 for (
int i=0; i<q; i++) {
1260 if ( normsC2[i] != zero ) {
1262 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1263 <<
"Arithmetic test 6 failed: "
1275 MVT::MvNorm(*B,normsB1);
1276 MVT::MvNorm(*C,normsC1);
1278 for (
int i=0; i<p; i++) {
1281 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1282 MVT::MvNorm(*B,normsB2);
1283 MVT::MvNorm(*C,normsC2);
1284 for (
int i=0; i<p; i++) {
1285 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1287 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1288 <<
"Input vectors were modified." << endl;
1292 for (
int i=0; i<p; i++) {
1293 if ( SCT::magnitude( normsB1[i] - normsC2[i] ) > tol ) {
1295 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1296 <<
"Arithmetic test 7 failed." << endl;
1300 for (
int i=p; i<q; i++) {
1301 if ( normsC2[i] != zero ) {
1303 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1304 <<
"Arithmetic test 7 failed." << endl;
1312 MVT::MvNorm(*B,normsB1);
1313 MVT::MvNorm(*C,normsC1);
1315 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1316 MVT::MvNorm(*B,normsB2);
1317 MVT::MvNorm(*C,normsC2);
1318 for (
int i=0; i<p; i++) {
1319 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1321 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1322 <<
"Input vectors were modified." << endl;
1326 for (
int i=0; i<q; i++) {
1327 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1329 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1330 <<
"Arithmetic test 8 failed." << endl;
1347 template<
class ScalarType,
class MV,
class OP>
1365 typedef typename SCT::magnitudeType MagType;
1367 const MagType tol = SCT::eps()*100;
1369 const int numvecs = 10;
1372 C = MVT::Clone(*A,numvecs);
1374 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
1375 normsC1(numvecs), normsC2(numvecs);
1386 MVT::MvNorm(*B,normsB1);
1387 OPT::Apply(*M,*B,*C);
1388 MVT::MvNorm(*B,normsB2);
1389 MVT::MvNorm(*C,normsC2);
1390 for (
int i=0; i<numvecs; i++) {
1391 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1393 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1394 <<
"Apply() modified the input vectors." << endl;
1397 if (normsC2[i] != SCT::zero()) {
1399 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1400 <<
"Operator applied to zero did not return zero." << endl;
1407 MVT::MvNorm(*B,normsB1);
1408 OPT::Apply(*M,*B,*C);
1409 MVT::MvNorm(*B,normsB2);
1410 MVT::MvNorm(*C,normsC2);
1411 bool ZeroWarning =
false;
1412 for (
int i=0; i<numvecs; i++) {
1413 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1415 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1416 <<
"Apply() modified the input vectors." << endl;
1419 if (normsC2[i] == SCT::zero() && ZeroWarning==
false ) {
1421 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1422 <<
"Operator applied to random vectors returned zero." << endl;
1429 MVT::MvNorm(*B,normsB1);
1431 OPT::Apply(*M,*B,*C);
1432 MVT::MvNorm(*B,normsB2);
1433 MVT::MvNorm(*C,normsC1);
1434 for (
int i=0; i<numvecs; i++) {
1435 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1437 <<
"*** ERROR *** OperatorTraits::Apply() [3]" << endl
1438 <<
"Apply() modified the input vectors." << endl;
1449 OPT::Apply(*M,*B,*C);
1450 MVT::MvNorm(*B,normsB2);
1451 MVT::MvNorm(*C,normsC2);
1452 for (
int i=0; i<numvecs; i++) {
1453 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1455 <<
"*** ERROR *** OperatorTraits::Apply() [4]" << endl
1456 <<
"Apply() modified the input vectors." << endl;
1459 if ( SCT::magnitude( normsC1[i] - normsC2[i]) > tol ) {
1462 <<
"*** WARNING *** OperatorTraits::Apply() [4]" << endl
1463 <<
"Apply() returned two different results." << endl << endl;
ScalarTraits< ScalarType >::magnitudeType normOne() const
bool TestOperatorTraits(const Teuchos::RCP< OutputManager< ScalarType > > &om, const Teuchos::RCP< const MV > &A, const Teuchos::RCP< const OP > &M)
This function tests the correctness of an operator implementation with respect to an OperatorTraits s...
Declaration of basic traits for the multivector type.
Virtual base class which defines basic traits for the operator type.
int scale(const ScalarType alpha)
Abstract class definition for Anasazi Output Managers.
Output managers remove the need for the eigensolver to know any information about the required output...
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Traits class which defines basic operations on multivectors.
Virtual base class which defines basic traits for the operator type.
bool TestMultiVecTraits(const Teuchos::RCP< OutputManager< ScalarType > > &om, const Teuchos::RCP< const MV > &A)
This is a function to test the correctness of a MultiVecTraits specialization and multivector impleme...
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
OrdinalType numCols() const
Types and exceptions used within Anasazi solvers and interfaces.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
OrdinalType numRows() const