29 #ifndef ANASAZI_MVOPTESTER_HPP
30 #define ANASAZI_MVOPTESTER_HPP
63 template<
class ScalarType,
class MV >
150 typedef typename SCT::magnitudeType MagType;
152 const ScalarType one = SCT::one();
153 const ScalarType zero = SCT::zero();
157 const int numvecs = 10;
158 const int numvecs_2 = 5;
160 std::vector<int> ind(numvecs_2);
181 if ( MVT::GetNumberVecs(*A) <= 0 ) {
183 <<
"*** ERROR *** MultiVectorTraits::GetNumberVecs()." << endl
184 <<
"Returned <= 0." << endl;
193 if ( MVT::GetVecLength(*A) <= 0 ) {
195 <<
"*** ERROR *** MultiVectorTraits::GetVecLength()" << endl
196 <<
"Returned <= 0." << endl;
205 if ( MVText::GetGlobalLength(*A) <= 0 ) {
207 <<
"*** ERROR *** MultiVectorTraitsExt::GetGlobalLength()" << endl
208 <<
"Returned <= 0." << endl;
220 std::vector<MagType> norms(numvecs);
221 if ( MVT::GetNumberVecs(*B) != numvecs ) {
223 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
224 <<
"Did not allocate requested number of vectors." << endl;
227 if ( MVText::GetGlobalLength(*B) != MVText::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() != numvecs ) {
236 <<
"*** ERROR *** MultiVecTraits::MvNorm()." << endl
237 <<
"Method resized the output vector." << endl;
239 for (
int i=0; i<numvecs; i++) {
240 if ( norms[i] < zero_mag ) {
242 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
243 <<
"Vector had negative norm." << endl;
267 std::vector<MagType> norms(numvecs), norms2(numvecs);
270 MVT::MvNorm(*B, norms);
271 for (
int i=0; i<numvecs; i++) {
272 if ( norms[i] != zero_mag ) {
274 <<
"*** ERROR *** MultiVecTraits::MvInit() "
275 <<
"and MultiVecTraits::MvNorm()" << endl
276 <<
"Supposedly zero vector has non-zero norm." << endl;
281 MVT::MvNorm(*B, norms);
283 MVT::MvNorm(*B, norms2);
284 for (
int i=0; i<numvecs; i++) {
285 if ( norms[i] == zero_mag || norms2[i] == zero_mag ) {
287 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
288 <<
"Random vector was empty (very unlikely)." << endl;
291 else if ( norms[i] < zero_mag || norms2[i] < zero_mag ) {
293 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
294 <<
"Vector had negative norm." << endl;
297 else if ( norms[i] == norms2[i] ) {
299 <<
"*** ERROR *** MutliVecTraits::MvRandom()." << endl
300 <<
"Vectors not random enough." << endl;
316 std::vector<MagType> norms(numvecs);
319 MVT::MvScale(*B,SCT::zero());
320 MVT::MvNorm(*B, norms);
321 for (
int i=0; i<numvecs; i++) {
322 if ( norms[i] != zero_mag ) {
324 <<
"*** ERROR *** MultiVecTraits::MvScale(alpha) "
325 <<
"Supposedly zero vector has non-zero norm." << endl;
331 std::vector<ScalarType> zeros(numvecs,SCT::zero());
332 MVT::MvScale(*B,zeros);
333 MVT::MvNorm(*B, norms);
334 for (
int i=0; i<numvecs; i++) {
335 if ( norms[i] != zero_mag ) {
337 <<
"*** ERROR *** MultiVecTraits::MvScale(alphas) "
338 <<
"Supposedly zero vector has non-zero norm." << endl;
360 std::vector<MagType> norms(numvecs);
363 MVT::MvNorm(*B, norms);
364 bool BadNormWarning =
false;
365 for (
int i=0; i<numvecs; i++) {
366 if ( norms[i] < zero_mag ) {
368 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
369 <<
"Vector had negative norm." << endl;
372 else if ( norms[i] != SCT::squareroot(MVT::GetVecLength(*B)) && !BadNormWarning ) {
375 <<
"Warning testing MultiVecTraits::MvInit()." << endl
376 <<
"Ones vector should have norm sqrt(dim)." << endl
377 <<
"norms[i]: " << norms[i] <<
"\tdim: " << MVText::GetGlobalLength(*B) << endl << endl;
378 BadNormWarning =
true;
393 std::vector<MagType> norms(numvecs);
394 MVT::MvInit(*B, zero_mag);
395 MVT::MvNorm(*B, norms);
396 for (
int i=0; i<numvecs; i++) {
397 if ( norms[i] < zero_mag ) {
399 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
400 <<
"Vector had negative norm." << endl;
403 else if ( norms[i] != zero_mag ) {
405 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
406 <<
"Zero vector should have norm zero." << endl;
420 std::vector<MagType> norms(numvecs), norms2(ind.size());
422 B = MVT::Clone(*A,numvecs);
424 MVT::MvNorm(*B, norms);
425 C = MVT::CloneCopy(*B,ind);
426 MVT::MvNorm(*C, norms2);
427 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
429 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
430 <<
"Wrong number of vectors." << endl;
433 if ( MVText::GetGlobalLength(*C) != MVText::GetGlobalLength(*B) ) {
435 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
436 <<
"Vector lengths don't match." << endl;
439 for (
int i=0; i<numvecs_2; i++) {
440 if ( norms2[i] != norms[ind[i]] ) {
442 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
443 <<
"Copied vectors do not agree:"
444 << norms2[i] <<
" != " << norms[ind[i]] << endl;
448 MVT::MvInit(*B,zero);
449 MVT::MvNorm(*C, norms2);
450 for (
int i=0; i<numvecs_2; i++) {
451 if ( norms2[i] != norms2[i] ) {
453 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
454 <<
"Copied vectors were not independent." << endl;
468 std::vector<MagType> norms(numvecs), norms2(numvecs);
470 B = MVT::Clone(*A,numvecs);
472 MVT::MvNorm(*B, norms);
473 C = MVT::CloneCopy(*B);
474 MVT::MvNorm(*C, norms2);
475 if ( MVT::GetNumberVecs(*C) != numvecs ) {
477 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
478 <<
"Wrong number of vectors." << endl;
481 for (
int i=0; i<numvecs; i++) {
482 if ( norms2[i] != norms[i] ) {
484 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
485 <<
"Copied vectors do not agree." << endl;
489 MVT::MvInit(*B,zero);
490 MVT::MvNorm(*C, norms);
491 for (
int i=0; i<numvecs; i++) {
492 if ( norms2[i] != norms[i] ) {
494 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
495 <<
"Copied vectors were not independent." << endl;
510 std::vector<MagType> norms(numvecs), norms2(ind.size());
512 B = MVT::Clone(*A,numvecs);
514 MVT::MvNorm(*B, norms);
515 C = MVT::CloneViewNonConst(*B,ind);
516 MVT::MvNorm(*C, norms2);
517 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
519 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
520 <<
"Wrong number of vectors." << endl;
523 for (
int i=0; i<numvecs_2; i++) {
524 if ( norms2[i] != norms[ind[i]] ) {
526 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
527 <<
"Viewed vectors do not agree." << endl;
543 std::vector<MagType> normsB(numvecs), normsC(ind.size());
544 std::vector<int> allind(numvecs);
545 for (
int i=0; i<numvecs; i++) {
549 B = MVT::Clone(*A,numvecs);
551 MVT::MvNorm(*B, normsB);
552 C = MVT::CloneView(*B,ind);
553 MVT::MvNorm(*C, normsC);
554 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
556 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
557 <<
"Wrong number of vectors." << endl;
560 for (
int i=0; i<numvecs_2; i++) {
561 if ( normsC[i] != normsB[ind[i]] ) {
563 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
564 <<
"Viewed vectors do not agree." << endl;
584 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
585 normsC1(numvecs_2), normsC2(numvecs_2);
587 B = MVT::Clone(*A,numvecs);
588 C = MVT::Clone(*A,numvecs_2);
590 ind.resize(numvecs_2);
591 for (
int i=0; i<numvecs_2; i++) {
597 MVT::MvNorm(*B,normsB1);
598 MVT::MvNorm(*C,normsC1);
599 MVT::SetBlock(*C,ind,*B);
600 MVT::MvNorm(*B,normsB2);
601 MVT::MvNorm(*C,normsC2);
604 for (
int i=0; i<numvecs_2; i++) {
605 if ( normsC1[i] != normsC2[i] ) {
607 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
608 <<
"Operation modified source vectors." << endl;
614 for (
int i=0; i<numvecs; i++) {
617 if ( normsB2[i] != normsC1[i/2] ) {
619 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
620 <<
"Copied vectors do not agree." << endl;
626 if ( normsB1[i] != normsB2[i] ) {
628 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
629 <<
"Incorrect vectors were modified." << endl;
634 MVT::MvInit(*C,zero);
635 MVT::MvNorm(*B,normsB1);
637 for (
int i=0; i<numvecs; i++) {
638 if ( normsB1[i] != normsB2[i] ) {
640 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
641 <<
"Copied vectors were not independent." << endl;
675 std::vector<MagType> normsB(p), normsC(q);
678 B = MVT::Clone(*A,p);
679 C = MVT::Clone(*A,q);
683 MVT::MvNorm(*B,normsB);
685 MVT::MvNorm(*C,normsC);
688 MVT::MvTransMv( zero, *B, *C, SDM );
693 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
694 <<
"Routine resized SerialDenseMatrix." << endl;
701 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
702 <<
"Scalar argument processed incorrectly." << endl;
707 MVT::MvTransMv( one, *B, *C, SDM );
711 for (
int i=0; i<p; i++) {
712 for (
int j=0; j<q; j++) {
713 if ( SCT::magnitude(SDM(i,j))
714 > SCT::magnitude(normsB[i]*normsC[j]) ) {
716 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
717 <<
"Triangle inequality did not hold: "
718 << SCT::magnitude(SDM(i,j))
720 << SCT::magnitude(normsB[i]*normsC[j])
728 MVT::MvTransMv( one, *B, *C, SDM );
729 for (
int i=0; i<p; i++) {
730 for (
int j=0; j<q; j++) {
731 if ( SDM(i,j) != zero ) {
733 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
734 <<
"Inner products not zero for C==0." << endl;
741 MVT::MvTransMv( one, *B, *C, SDM );
742 for (
int i=0; i<p; i++) {
743 for (
int j=0; j<q; j++) {
744 if ( SDM(i,j) != zero ) {
746 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
747 <<
"Inner products not zero for B==0." << endl;
765 MVT::MvTransMv( one, *B, *C, SDM2 );
766 for (
int i=0; i<p; i++) {
767 for (
int j=0; j<q; j++) {
768 if ( SDM2(i,j) != zero ) {
770 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
771 <<
"Inner products not zero for C==0 when using a view into Teuchos::SerialDenseMatrix<>." << endl;
788 std::vector<ScalarType> iprods(p);
789 std::vector<MagType> normsB(p), normsC(p);
791 B = MVT::Clone(*A,p);
792 C = MVT::Clone(*A,p);
796 MVT::MvNorm(*B,normsB);
797 MVT::MvNorm(*C,normsC);
798 MVT::MvDot( *B, *C, iprods );
799 if ( (
int)iprods.size() != p ) {
801 <<
"*** ERROR *** MultiVecTraits::MvDot." << endl
802 <<
"Routine resized results vector." << endl;
805 for (
int i=0; i<p; i++) {
806 if ( SCT::magnitude(iprods[i])
807 > SCT::magnitude(normsB[i]*normsC[i]) ) {
809 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
810 <<
"Inner products not valid." << endl;
816 MVT::MvDot( *B, *C, iprods );
817 for (
int i=0; i<p; i++) {
818 if ( iprods[i] != zero ) {
820 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
821 <<
"Inner products not zero for B==0." << endl;
827 MVT::MvDot( *B, *C, iprods );
828 for (
int i=0; i<p; i++) {
829 if ( iprods[i] != zero ) {
831 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
832 <<
"Inner products not zero for C==0." << endl;
849 std::vector<MagType> normsB1(p), normsB2(p),
850 normsC1(p), normsC2(p),
851 normsD1(p), normsD2(p);
852 ScalarType alpha = SCT::random(),
853 beta = SCT::random();
855 B = MVT::Clone(*A,p);
856 C = MVT::Clone(*A,p);
857 D = MVT::Clone(*A,p);
861 MVT::MvNorm(*B,normsB1);
862 MVT::MvNorm(*C,normsC1);
865 MVT::MvAddMv(zero,*B,one,*C,*D);
866 MVT::MvNorm(*B,normsB2);
867 MVT::MvNorm(*C,normsC2);
868 MVT::MvNorm(*D,normsD1);
869 for (
int i=0; i<p; i++) {
870 if ( normsB1[i] != normsB2[i] ) {
872 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
873 <<
"Input arguments were modified." << endl;
876 else if ( normsC1[i] != normsC2[i] ) {
878 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
879 <<
"Input arguments were modified." << endl;
882 else if ( normsC1[i] != normsD1[i] ) {
884 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
885 <<
"Assignment did not work." << endl;
891 MVT::MvAddMv(one,*B,zero,*C,*D);
892 MVT::MvNorm(*B,normsB2);
893 MVT::MvNorm(*C,normsC2);
894 MVT::MvNorm(*D,normsD1);
895 for (
int i=0; i<p; i++) {
896 if ( normsB1[i] != normsB2[i] ) {
898 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
899 <<
"Input arguments were modified." << endl;
902 else if ( normsC1[i] != normsC2[i] ) {
904 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
905 <<
"Input arguments were modified." << endl;
908 else if ( normsB1[i] != normsD1[i] ) {
910 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
911 <<
"Assignment did not work." << endl;
919 MVT::MvAddMv(alpha,*B,beta,*C,*D);
920 MVT::MvNorm(*B,normsB2);
921 MVT::MvNorm(*C,normsC2);
922 MVT::MvNorm(*D,normsD1);
924 for (
int i=0; i<p; i++) {
925 if ( normsB1[i] != normsB2[i] ) {
927 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
928 <<
"Input arguments were modified." << endl;
931 else if ( normsC1[i] != normsC2[i] ) {
933 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
934 <<
"Input arguments were modified." << endl;
940 MVT::MvAddMv(alpha,*B,beta,*C,*D);
941 MVT::MvNorm(*B,normsB2);
942 MVT::MvNorm(*C,normsC2);
943 MVT::MvNorm(*D,normsD2);
946 for (
int i=0; i<p; i++) {
947 if ( normsB1[i] != normsB2[i] ) {
949 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
950 <<
"Input arguments were modified." << endl;
953 else if ( normsC1[i] != normsC2[i] ) {
955 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
956 <<
"Input arguments were modified." << endl;
959 else if ( normsD1[i] != normsD2[i] ) {
961 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
962 <<
"Results varies depending on initial state of dest vectors." << endl;
990 std::vector<MagType> normsB(p),
992 std::vector<int> lclindex(p);
993 for (
int i=0; i<p; i++) lclindex[i] = i;
995 B = MVT::Clone(*A,p);
996 C = MVT::CloneView(*B,lclindex);
997 D = MVT::CloneViewNonConst(*B,lclindex);
1000 MVT::MvNorm(*B,normsB);
1003 MVT::MvAddMv(zero,*B,one,*C,*D);
1004 MVT::MvNorm(*D,normsD);
1005 for (
int i=0; i<p; i++) {
1006 if ( normsB[i] != normsD[i] ) {
1008 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1009 <<
"Assignment did not work." << endl;
1015 MVT::MvAddMv(one,*B,zero,*C,*D);
1016 MVT::MvNorm(*D,normsD);
1017 for (
int i=0; i<p; i++) {
1018 if ( normsB[i] != normsD[i] ) {
1020 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1021 <<
"Assignment did not work." << endl;
1039 const int p = 7, q = 5;
1042 std::vector<MagType> normsC1(q), normsC2(q),
1043 normsB1(p), normsB2(p);
1045 B = MVT::Clone(*A,p);
1046 C = MVT::Clone(*A,q);
1051 MVT::MvNorm(*B,normsB1);
1052 MVT::MvNorm(*C,normsC1);
1054 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1055 MVT::MvNorm(*B,normsB2);
1056 MVT::MvNorm(*C,normsC2);
1057 for (
int i=0; i<p; i++) {
1058 if ( normsB1[i] != normsB2[i] ) {
1060 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1061 <<
"Input vectors were modified." << endl;
1065 for (
int i=0; i<q; i++) {
1066 if ( normsC1[i] != normsC2[i] ) {
1068 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1069 <<
"Arithmetic test 1 failed." << endl;
1077 MVT::MvNorm(*B,normsB1);
1078 MVT::MvNorm(*C,normsC1);
1080 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1081 MVT::MvNorm(*B,normsB2);
1082 MVT::MvNorm(*C,normsC2);
1083 for (
int i=0; i<p; i++) {
1084 if ( normsB1[i] != normsB2[i] ) {
1086 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1087 <<
"Input vectors were modified." << endl;
1091 for (
int i=0; i<q; i++) {
1092 if ( normsC2[i] != zero ) {
1094 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1095 <<
"Arithmetic test 2 failed: "
1108 MVT::MvNorm(*B,normsB1);
1109 MVT::MvNorm(*C,normsC1);
1111 for (
int i=0; i<q; i++) {
1114 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1115 MVT::MvNorm(*B,normsB2);
1116 MVT::MvNorm(*C,normsC2);
1117 for (
int i=0; i<p; i++) {
1118 if ( normsB1[i] != normsB2[i] ) {
1120 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1121 <<
"Input vectors were modified." << endl;
1125 for (
int i=0; i<q; i++) {
1126 if ( normsB1[i] != normsC2[i] ) {
1128 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1129 <<
"Arithmetic test 3 failed: "
1141 MVT::MvNorm(*B,normsB1);
1142 MVT::MvNorm(*C,normsC1);
1144 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1145 MVT::MvNorm(*B,normsB2);
1146 MVT::MvNorm(*C,normsC2);
1147 for (
int i=0; i<p; i++) {
1148 if ( normsB1[i] != normsB2[i] ) {
1150 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1151 <<
"Input vectors were modified." << endl;
1155 for (
int i=0; i<q; i++) {
1156 if ( normsC1[i] != normsC2[i] ) {
1158 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1159 <<
"Arithmetic test 4 failed." << endl;
1175 const int p = 5, q = 7;
1178 std::vector<MagType> normsC1(q), normsC2(q),
1179 normsB1(p), normsB2(p);
1181 B = MVT::Clone(*A,p);
1182 C = MVT::Clone(*A,q);
1187 MVT::MvNorm(*B,normsB1);
1188 MVT::MvNorm(*C,normsC1);
1190 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1191 MVT::MvNorm(*B,normsB2);
1192 MVT::MvNorm(*C,normsC2);
1193 for (
int i=0; i<p; i++) {
1194 if ( normsB1[i] != normsB2[i] ) {
1196 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1197 <<
"Input vectors were modified." << endl;
1201 for (
int i=0; i<q; i++) {
1202 if ( normsC1[i] != normsC2[i] ) {
1204 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1205 <<
"Arithmetic test 5 failed." << endl;
1213 MVT::MvNorm(*B,normsB1);
1214 MVT::MvNorm(*C,normsC1);
1216 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1217 MVT::MvNorm(*B,normsB2);
1218 MVT::MvNorm(*C,normsC2);
1219 for (
int i=0; i<p; i++) {
1220 if ( normsB1[i] != normsB2[i] ) {
1222 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1223 <<
"Input vectors were modified." << endl;
1227 for (
int i=0; i<q; i++) {
1228 if ( normsC2[i] != zero ) {
1230 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1231 <<
"Arithmetic test 6 failed: "
1243 MVT::MvNorm(*B,normsB1);
1244 MVT::MvNorm(*C,normsC1);
1246 for (
int i=0; i<p; i++) {
1249 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1250 MVT::MvNorm(*B,normsB2);
1251 MVT::MvNorm(*C,normsC2);
1252 for (
int i=0; i<p; i++) {
1253 if ( normsB1[i] != normsB2[i] ) {
1255 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1256 <<
"Input vectors were modified." << endl;
1260 for (
int i=0; i<p; i++) {
1261 if ( normsB1[i] != normsC2[i] ) {
1263 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1264 <<
"Arithmetic test 7 failed." << endl;
1268 for (
int i=p; i<q; i++) {
1269 if ( normsC2[i] != zero ) {
1271 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1272 <<
"Arithmetic test 7 failed." << endl;
1280 MVT::MvNorm(*B,normsB1);
1281 MVT::MvNorm(*C,normsC1);
1283 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1284 MVT::MvNorm(*B,normsB2);
1285 MVT::MvNorm(*C,normsC2);
1286 for (
int i=0; i<p; i++) {
1287 if ( normsB1[i] != normsB2[i] ) {
1289 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1290 <<
"Input vectors were modified." << endl;
1294 for (
int i=0; i<q; i++) {
1295 if ( normsC1[i] != normsC2[i] ) {
1297 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1298 <<
"Arithmetic test 8 failed." << endl;
1315 template<
class ScalarType,
class MV,
class OP>
1333 typedef typename SCT::magnitudeType MagType;
1335 const int numvecs = 10;
1338 C = MVT::Clone(*A,numvecs);
1340 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
1341 normsC1(numvecs), normsC2(numvecs);
1342 bool NonDeterministicWarning;
1353 MVT::MvNorm(*B,normsB1);
1354 OPT::Apply(*M,*B,*C);
1355 MVT::MvNorm(*B,normsB2);
1356 MVT::MvNorm(*C,normsC2);
1357 for (
int i=0; i<numvecs; i++) {
1358 if (normsB2[i] != normsB1[i]) {
1360 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1361 <<
"Apply() modified the input vectors." << endl;
1364 if (normsC2[i] != SCT::zero()) {
1366 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1367 <<
"Operator applied to zero did not return zero." << endl;
1374 MVT::MvNorm(*B,normsB1);
1375 OPT::Apply(*M,*B,*C);
1376 MVT::MvNorm(*B,normsB2);
1377 MVT::MvNorm(*C,normsC2);
1378 bool ZeroWarning =
false;
1379 for (
int i=0; i<numvecs; i++) {
1380 if (normsB2[i] != normsB1[i]) {
1382 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1383 <<
"Apply() modified the input vectors." << endl;
1386 if (normsC2[i] == SCT::zero() && ZeroWarning==
false ) {
1388 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1389 <<
"Operator applied to random vectors returned zero." << endl;
1396 MVT::MvNorm(*B,normsB1);
1398 OPT::Apply(*M,*B,*C);
1399 MVT::MvNorm(*B,normsB2);
1400 MVT::MvNorm(*C,normsC1);
1401 for (
int i=0; i<numvecs; i++) {
1402 if (normsB2[i] != normsB1[i]) {
1404 <<
"*** ERROR *** OperatorTraits::Apply() [3]" << endl
1405 <<
"Apply() modified the input vectors." << endl;
1416 OPT::Apply(*M,*B,*C);
1417 MVT::MvNorm(*B,normsB2);
1418 MVT::MvNorm(*C,normsC2);
1419 NonDeterministicWarning =
false;
1420 for (
int i=0; i<numvecs; i++) {
1421 if (normsB2[i] != normsB1[i]) {
1423 <<
"*** ERROR *** OperatorTraits::Apply() [4]" << endl
1424 <<
"Apply() modified the input vectors." << endl;
1427 if (normsC1[i] != normsC2[i] && !NonDeterministicWarning) {
1430 <<
"*** WARNING *** OperatorTraits::Apply() [4]" << endl
1431 <<
"Apply() returned two different results." << endl << endl;
1432 NonDeterministicWarning =
true;
ScalarTraits< ScalarType >::magnitudeType normOne() const
An extension of the MultiVecTraits class that adds a new vector length method.This traits class provi...
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