10 #ifndef ANASAZI_MVOPTESTER_HPP
11 #define ANASAZI_MVOPTESTER_HPP
34 #include "Teuchos_SetScientific.hpp"
45 template<
class ScalarType,
class MV >
129 typedef typename SCT::magnitudeType MagType;
131 const ScalarType one = SCT::one();
132 const ScalarType zero = SCT::zero();
134 const MagType tol = SCT::eps()*100;
137 const int numvecs = 10;
138 const int numvecs_2 = 5;
140 std::vector<int> ind(numvecs_2);
161 if ( MVT::GetNumberVecs(*A) <= 0 ) {
163 <<
"*** ERROR *** MultiVectorTraits::GetNumberVecs()." << endl
164 <<
"Returned <= 0." << endl;
172 if ( MVT::GetGlobalLength(*A) <= 0 ) {
174 <<
"*** ERROR *** MultiVectorTraitsExt::GetGlobalLength()" << endl
175 <<
"Returned <= 0." << endl;
188 std::vector<MagType> norms(2*numvecs);
189 bool ResizeWarning =
false;
190 if ( MVT::GetNumberVecs(*B) != numvecs ) {
192 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
193 <<
"Did not allocate requested number of vectors." << endl;
196 if ( MVT::GetGlobalLength(*B) != MVT::GetGlobalLength(*A) ) {
198 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
199 <<
"Did not allocate requested number of vectors." << endl;
202 MVT::MvNorm(*B, norms);
203 if ( (
int)norms.size() != 2*numvecs && (ResizeWarning ==
false) ) {
205 <<
"*** WARNING *** MultiVecTraits::MvNorm()." << endl
206 <<
"Method resized the output vector." << endl;
207 ResizeWarning =
true;
209 for (
int i=0; i<numvecs; i++) {
210 if ( norms[i] < zero_mag ) {
212 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
213 <<
"Vector had negative norm." << endl;
237 std::vector<MagType> norms(numvecs), norms2(numvecs);
240 MVT::MvNorm(*B, norms);
241 for (
int i=0; i<numvecs; i++) {
242 if ( norms[i] != zero_mag ) {
244 <<
"*** ERROR *** MultiVecTraits::MvInit() "
245 <<
"and MultiVecTraits::MvNorm()" << endl
246 <<
"Supposedly zero vector has non-zero norm." << endl;
251 MVT::MvNorm(*B, norms);
253 MVT::MvNorm(*B, norms2);
254 for (
int i=0; i<numvecs; i++) {
255 if ( norms[i] == zero_mag || norms2[i] == zero_mag ) {
257 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
258 <<
"Random vector was empty (very unlikely)." << endl;
261 else if ( norms[i] < zero_mag || norms2[i] < zero_mag ) {
263 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
264 <<
"Vector had negative norm." << endl;
267 else if ( norms[i] == norms2[i] ) {
269 <<
"*** ERROR *** MutliVecTraits::MvRandom()." << endl
270 <<
"Vectors not random enough." << endl;
286 std::vector<MagType> norms(numvecs);
289 MVT::MvScale(*B,SCT::zero());
290 MVT::MvNorm(*B, norms);
291 for (
int i=0; i<numvecs; i++) {
292 if ( norms[i] != zero_mag ) {
294 <<
"*** ERROR *** MultiVecTraits::MvScale(alpha) "
295 <<
"Supposedly zero vector has non-zero norm." << endl;
301 std::vector<ScalarType> zeros(numvecs,SCT::zero());
302 MVT::MvScale(*B,zeros);
303 MVT::MvNorm(*B, norms);
304 for (
int i=0; i<numvecs; i++) {
305 if ( norms[i] != zero_mag ) {
307 <<
"*** ERROR *** MultiVecTraits::MvScale(alphas) "
308 <<
"Supposedly zero vector has non-zero norm." << endl;
330 std::vector<MagType> norms(numvecs);
333 MVT::MvNorm(*B, norms);
334 bool BadNormWarning =
false;
335 for (
int i=0; i<numvecs; i++) {
336 if ( norms[i] < zero_mag ) {
338 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
339 <<
"Vector had negative norm." << endl;
342 else if ( norms[i] != SCT::squareroot(MVT::GetGlobalLength(*B)) && !BadNormWarning ) {
345 <<
"Warning testing MultiVecTraits::MvInit()." << endl
346 <<
"Ones vector should have norm sqrt(dim)." << endl
347 <<
"norms[i]: " << norms[i] <<
"\tdim: " << MVT::GetGlobalLength(*B) << endl << endl;
348 BadNormWarning =
true;
363 std::vector<MagType> norms(numvecs);
364 MVT::MvInit(*B, zero_mag);
365 MVT::MvNorm(*B, norms);
366 for (
int i=0; i<numvecs; i++) {
367 if ( norms[i] < zero_mag ) {
369 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
370 <<
"Vector had negative norm." << endl;
373 else if ( norms[i] != zero_mag ) {
375 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
376 <<
"Zero vector should have norm zero." << endl;
390 std::vector<MagType> norms(numvecs), norms2(ind.size());
392 B = MVT::Clone(*A,numvecs);
394 MVT::MvNorm(*B, norms);
395 C = MVT::CloneCopy(*B,ind);
396 MVT::MvNorm(*C, norms2);
397 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
399 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
400 <<
"Wrong number of vectors." << endl;
403 if ( MVT::GetGlobalLength(*C) != MVT::GetGlobalLength(*B) ) {
405 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
406 <<
"Vector lengths don't match." << endl;
409 for (
int i=0; i<numvecs_2; i++) {
410 if ( SCT::magnitude( norms2[i] - norms[ind[i]] ) > tol ) {
412 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
413 <<
"Copied vectors do not agree:"
414 << norms2[i] <<
" != " << norms[ind[i]] << endl
415 <<
"Difference " << SCT::magnitude (norms2[i] - norms[ind[i]])
416 <<
" exceeds the tolerance 100*eps = " << tol << endl;
421 MVT::MvInit(*B,zero);
422 MVT::MvNorm(*C, norms2);
423 for (
int i=0; i<numvecs_2; i++) {
424 if ( SCT::magnitude( norms2[i] - norms2[i] ) > tol ) {
426 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
427 <<
"Copied vectors were not independent." << endl
428 <<
"Difference " << SCT::magnitude (norms2[i] - norms[i])
429 <<
" exceeds the tolerance 100*eps = " << tol << endl;
443 std::vector<MagType> norms(numvecs), norms2(numvecs);
445 B = MVT::Clone(*A,numvecs);
447 MVT::MvNorm(*B, norms);
448 C = MVT::CloneCopy(*B);
449 MVT::MvNorm(*C, norms2);
450 if ( MVT::GetNumberVecs(*C) != numvecs ) {
452 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
453 <<
"Wrong number of vectors." << endl;
456 for (
int i=0; i<numvecs; i++) {
457 if ( SCT::magnitude( norms2[i] - norms[i] ) > tol ) {
459 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
460 <<
"Copied vectors do not agree." << endl
461 <<
"Difference " << SCT::magnitude (norms2[i] - norms[i])
462 <<
" exceeds the tolerance 100*eps = " << tol << endl;
466 MVT::MvInit(*B,zero);
467 MVT::MvNorm(*C, norms);
468 for (
int i=0; i<numvecs; i++) {
469 if ( SCT::magnitude( norms2[i] - norms[i] ) > tol ) {
471 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
472 <<
"Copied vectors were not independent." << endl
473 <<
"Difference " << SCT::magnitude (norms2[i] - norms[i])
474 <<
" exceeds the tolerance 100*eps = " << tol << endl;
489 std::vector<MagType> norms(numvecs), norms2(ind.size());
491 B = MVT::Clone(*A,numvecs);
493 MVT::MvNorm(*B, norms);
494 C = MVT::CloneViewNonConst(*B,ind);
495 MVT::MvNorm(*C, norms2);
496 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
498 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
499 <<
"Wrong number of vectors." << endl;
502 for (
int i=0; i<numvecs_2; i++) {
503 if ( SCT::magnitude( norms2[i] - norms[ind[i]] ) > tol ) {
505 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
506 <<
"Viewed vectors do not agree." << endl;
522 std::vector<MagType> normsB(numvecs), normsC(ind.size());
523 std::vector<int> allind(numvecs);
524 for (
int i=0; i<numvecs; i++) {
528 B = MVT::Clone(*A,numvecs);
530 MVT::MvNorm(*B, normsB);
531 C = MVT::CloneView(*B,ind);
532 MVT::MvNorm(*C, normsC);
533 if ( MVT::GetNumberVecs(*C) != numvecs_2 ) {
535 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
536 <<
"Wrong number of vectors." << endl;
539 for (
int i=0; i<numvecs_2; i++) {
540 if ( SCT::magnitude( normsC[i] - normsB[ind[i]] ) > tol ) {
542 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
543 <<
"Viewed vectors do not agree." << endl;
563 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
564 normsC1(numvecs_2), normsC2(numvecs_2);
566 B = MVT::Clone(*A,numvecs);
567 C = MVT::Clone(*A,numvecs_2);
569 ind.resize(numvecs_2);
570 for (
int i=0; i<numvecs_2; i++) {
576 MVT::MvNorm(*B,normsB1);
577 MVT::MvNorm(*C,normsC1);
578 MVT::SetBlock(*C,ind,*B);
579 MVT::MvNorm(*B,normsB2);
580 MVT::MvNorm(*C,normsC2);
583 for (
int i=0; i<numvecs_2; i++) {
584 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
586 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
587 <<
"Operation modified source vectors." << endl;
593 for (
int i=0; i<numvecs; i++) {
596 if ( SCT::magnitude(normsB2[i]-normsC1[i/2]) > tol ) {
598 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
599 <<
"Copied vectors do not agree." << endl
600 <<
"Difference " << SCT::magnitude (normsB2[i] - normsC1[i/2])
601 <<
" exceeds the tolerance 100*eps = " << tol << endl;
607 if ( SCT::magnitude(normsB1[i]-normsB2[i]) > tol ) {
609 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
610 <<
"Incorrect vectors were modified." << endl;
615 MVT::MvInit(*C,zero);
616 MVT::MvNorm(*B,normsB1);
618 for (
int i=0; i<numvecs; i++) {
619 if ( SCT::magnitude(normsB1[i]-normsB2[i]) > tol ) {
621 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
622 <<
"Copied vectors were not independent." << endl;
656 std::vector<MagType> normsB(p), normsC(q);
659 B = MVT::Clone(*A,p);
660 C = MVT::Clone(*A,q);
664 MVT::MvNorm(*B,normsB);
666 MVT::MvNorm(*C,normsC);
669 MVT::MvTransMv( zero, *B, *C, SDM );
674 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
675 <<
"Routine resized SerialDenseMatrix." << endl;
682 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
683 <<
"Scalar argument processed incorrectly." << endl;
688 MVT::MvTransMv( one, *B, *C, SDM );
692 for (
int i=0; i<p; i++) {
693 for (
int j=0; j<q; j++) {
694 if ( SCT::magnitude(SDM(i,j))
695 > SCT::magnitude(normsB[i]*normsC[j]) ) {
697 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
698 <<
"Triangle inequality did not hold: "
699 << SCT::magnitude(SDM(i,j))
701 << SCT::magnitude(normsB[i]*normsC[j])
709 MVT::MvTransMv( one, *B, *C, SDM );
710 for (
int i=0; i<p; i++) {
711 for (
int j=0; j<q; j++) {
712 if ( SDM(i,j) != zero ) {
714 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
715 <<
"Inner products not zero for C==0." << endl;
722 MVT::MvTransMv( one, *B, *C, SDM );
723 for (
int i=0; i<p; i++) {
724 for (
int j=0; j<q; j++) {
725 if ( SDM(i,j) != zero ) {
727 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
728 <<
"Inner products not zero for B==0." << endl;
746 MVT::MvTransMv( one, *B, *C, SDM2 );
747 for (
int i=0; i<p; i++) {
748 for (
int j=0; j<q; j++) {
749 if ( SDM2(i,j) != zero ) {
751 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
752 <<
"Inner products not zero for C==0 when using a view into Teuchos::SerialDenseMatrix<>." << endl;
770 std::vector<ScalarType> iprods(q);
771 std::vector<MagType> normsB(p), normsC(p);
773 B = MVT::Clone(*A,p);
774 C = MVT::Clone(*A,p);
778 MVT::MvNorm(*B,normsB);
779 MVT::MvNorm(*C,normsC);
780 MVT::MvDot( *B, *C, iprods );
781 if ( (
int)iprods.size() != q ) {
783 <<
"*** ERROR *** MultiVecTraits::MvDot." << endl
784 <<
"Routine resized results vector." << endl;
787 for (
int i=0; i<p; i++) {
788 if ( SCT::magnitude(iprods[i])
789 > SCT::magnitude(normsB[i]*normsC[i]) ) {
791 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
792 <<
"Inner products not valid." << endl;
798 MVT::MvDot( *B, *C, iprods );
799 for (
int i=0; i<p; i++) {
800 if ( iprods[i] != zero ) {
802 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
803 <<
"Inner products not zero for B==0." << endl;
809 MVT::MvDot( *B, *C, iprods );
810 for (
int i=0; i<p; i++) {
811 if ( iprods[i] != zero ) {
813 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
814 <<
"Inner products not zero for C==0." << endl;
831 std::vector<MagType> normsB1(p), normsB2(p),
832 normsC1(p), normsC2(p),
833 normsD1(p), normsD2(p);
834 ScalarType alpha = MagType(0.5) * SCT::one();
835 ScalarType beta = MagType(0.33) * SCT::one();
837 B = MVT::Clone(*A,p);
838 C = MVT::Clone(*A,p);
839 D = MVT::Clone(*A,p);
843 MVT::MvNorm(*B,normsB1);
844 MVT::MvNorm(*C,normsC1);
847 MVT::MvAddMv(zero,*B,one,*C,*D);
848 MVT::MvNorm(*B,normsB2);
849 MVT::MvNorm(*C,normsC2);
850 MVT::MvNorm(*D,normsD1);
851 for (
int i=0; i<p; i++) {
852 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
854 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
855 <<
"Input arguments were modified." << endl;
858 else if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
860 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
861 <<
"Input arguments were modified." << endl;
864 else if ( SCT::magnitude(normsC1[i]-normsD1[i]) > tol ) {
866 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
867 <<
"Assignment did not work." << endl;
873 MVT::MvAddMv(one,*B,zero,*C,*D);
874 MVT::MvNorm(*B,normsB2);
875 MVT::MvNorm(*C,normsC2);
876 MVT::MvNorm(*D,normsD1);
877 for (
int i=0; i<p; i++) {
878 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
880 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
881 <<
"Input arguments were modified." << endl;
884 else if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
886 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
887 <<
"Input arguments were modified." << endl;
890 else if ( SCT::magnitude( normsB1[i] - normsD1[i] ) > tol ) {
892 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
893 <<
"Assignment did not work." << endl;
901 MVT::MvAddMv(alpha,*B,beta,*C,*D);
902 MVT::MvNorm(*B,normsB2);
903 MVT::MvNorm(*C,normsC2);
904 MVT::MvNorm(*D,normsD1);
906 for (
int i=0; i<p; i++) {
907 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
909 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
910 <<
"Input arguments were modified." << endl;
913 else if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
915 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
916 <<
"Input arguments were modified." << endl;
922 MVT::MvAddMv(alpha,*B,beta,*C,*D);
923 MVT::MvNorm(*B,normsB2);
924 MVT::MvNorm(*C,normsC2);
925 MVT::MvNorm(*D,normsD2);
928 for (
int i=0; i<p; i++) {
929 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
931 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
932 <<
"Input arguments were modified." << endl;
935 else if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
937 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
938 <<
"Input arguments were modified." << endl;
941 else if ( SCT::magnitude( normsD1[i] - normsD2[i] ) > tol ) {
943 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
944 <<
"Results varies depending on initial state of dest vectors." << endl;
972 std::vector<MagType> normsB(p),
974 std::vector<int> lclindex(p);
975 for (
int i=0; i<p; i++) lclindex[i] = i;
977 B = MVT::Clone(*A,p);
978 C = MVT::CloneView(*B,lclindex);
979 D = MVT::CloneViewNonConst(*B,lclindex);
982 MVT::MvNorm(*B,normsB);
985 MVT::MvAddMv(zero,*B,one,*C,*D);
986 MVT::MvNorm(*D,normsD);
987 for (
int i=0; i<p; i++) {
988 if ( SCT::magnitude( normsB[i] - normsD[i] ) > tol ) {
990 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
991 <<
"Assignment did not work." << endl;
997 MVT::MvAddMv(one,*B,zero,*C,*D);
998 MVT::MvNorm(*D,normsD);
999 for (
int i=0; i<p; i++) {
1000 if ( SCT::magnitude( normsB[i] - normsD[i] ) > tol ) {
1002 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1003 <<
"Assignment did not work." << endl;
1021 const int p = 7, q = 5;
1026 std::vector<MagType> normsC1(q), normsC2(q),
1027 normsB1(p), normsB2(p);
1029 B = MVT::Clone(*A,p);
1030 C = MVT::Clone(*A,q);
1033 Vp = MVT::Clone(*A,p);
1034 Vq = MVT::Clone(*A,q);
1037 MVT::MvTransMv( one, *Vp, *Vq, SDM );
1042 MVT::MvNorm(*B,normsB1);
1043 MVT::MvNorm(*C,normsC1);
1044 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1045 MVT::MvNorm(*B,normsB2);
1046 MVT::MvNorm(*C,normsC2);
1047 for (
int i=0; i<p; i++) {
1048 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1050 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1051 <<
"Input vectors were modified." << endl;
1055 for (
int i=0; i<q; i++) {
1056 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1058 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1059 <<
"Arithmetic test 1 failed." << endl;
1067 MVT::MvNorm(*B,normsB1);
1068 MVT::MvNorm(*C,normsC1);
1071 MVT::MvTransMv( one, *Vp, *Vq, SDM );
1072 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1073 MVT::MvNorm(*B,normsB2);
1074 MVT::MvNorm(*C,normsC2);
1075 for (
int i=0; i<p; i++) {
1076 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1078 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1079 <<
"Input vectors were modified." << endl;
1083 for (
int i=0; i<q; i++) {
1084 if ( normsC2[i] != zero ) {
1086 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1087 <<
"Arithmetic test 2 failed: "
1100 MVT::MvNorm(*B,normsB1);
1101 MVT::MvNorm(*C,normsC1);
1103 for (
int i=0; i<q; i++) {
1106 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1107 MVT::MvNorm(*B,normsB2);
1108 MVT::MvNorm(*C,normsC2);
1109 for (
int i=0; i<p; i++) {
1110 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1112 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1113 <<
"Input vectors were modified." << endl;
1117 for (
int i=0; i<q; i++) {
1118 if ( SCT::magnitude( normsB1[i] - normsC2[i] ) > tol ) {
1120 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1121 <<
"Arithmetic test 3 failed: "
1133 MVT::MvNorm(*B,normsB1);
1134 MVT::MvNorm(*C,normsC1);
1136 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1137 MVT::MvNorm(*B,normsB2);
1138 MVT::MvNorm(*C,normsC2);
1139 for (
int i=0; i<p; i++) {
1140 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1142 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1143 <<
"Input vectors were modified." << endl;
1147 for (
int i=0; i<q; i++) {
1148 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1150 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1151 <<
"Arithmetic test 4 failed." << endl;
1167 const int p = 5, q = 7;
1171 std::vector<MagType> normsC1(q), normsC2(q),
1172 normsB1(p), normsB2(p);
1174 B = MVT::Clone(*A,p);
1175 C = MVT::Clone(*A,q);
1178 Vp = MVT::Clone(*A,p);
1179 Vq = MVT::Clone(*A,q);
1182 MVT::MvTransMv( one, *Vp, *Vq, SDM );
1187 MVT::MvNorm(*B,normsB1);
1188 MVT::MvNorm(*C,normsC1);
1189 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1190 MVT::MvNorm(*B,normsB2);
1191 MVT::MvNorm(*C,normsC2);
1192 for (
int i=0; i<p; i++) {
1193 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1195 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1196 <<
"Input vectors were modified." << endl;
1200 for (
int i=0; i<q; i++) {
1201 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1203 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1204 <<
"Arithmetic test 5 failed." << endl;
1212 MVT::MvNorm(*B,normsB1);
1213 MVT::MvNorm(*C,normsC1);
1216 MVT::MvTransMv( one, *Vp, *Vq, SDM );
1217 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1218 MVT::MvNorm(*B,normsB2);
1219 MVT::MvNorm(*C,normsC2);
1220 for (
int i=0; i<p; i++) {
1221 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1223 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1224 <<
"Input vectors were modified." << endl;
1228 for (
int i=0; i<q; i++) {
1229 if ( normsC2[i] != zero ) {
1231 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1232 <<
"Arithmetic test 6 failed: "
1244 MVT::MvNorm(*B,normsB1);
1245 MVT::MvNorm(*C,normsC1);
1247 for (
int i=0; i<p; i++) {
1250 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1251 MVT::MvNorm(*B,normsB2);
1252 MVT::MvNorm(*C,normsC2);
1253 for (
int i=0; i<p; i++) {
1254 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1256 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1257 <<
"Input vectors were modified." << endl;
1261 for (
int i=0; i<p; i++) {
1262 if ( SCT::magnitude( normsB1[i] - normsC2[i] ) > tol ) {
1264 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1265 <<
"Arithmetic test 7 failed." << endl;
1269 for (
int i=p; i<q; i++) {
1270 if ( normsC2[i] != zero ) {
1272 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1273 <<
"Arithmetic test 7 failed." << endl;
1281 MVT::MvNorm(*B,normsB1);
1282 MVT::MvNorm(*C,normsC1);
1284 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1285 MVT::MvNorm(*B,normsB2);
1286 MVT::MvNorm(*C,normsC2);
1287 for (
int i=0; i<p; i++) {
1288 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1290 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1291 <<
"Input vectors were modified." << endl;
1295 for (
int i=0; i<q; i++) {
1296 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1298 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1299 <<
"Arithmetic test 8 failed." << endl;
1316 template<
class ScalarType,
class MV,
class OP>
1334 typedef typename SCT::magnitudeType MagType;
1336 const MagType tol = SCT::eps()*100;
1338 const int numvecs = 10;
1341 C = MVT::Clone(*A,numvecs);
1343 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
1344 normsC1(numvecs), normsC2(numvecs);
1355 MVT::MvNorm(*B,normsB1);
1356 OPT::Apply(*M,*B,*C);
1357 MVT::MvNorm(*B,normsB2);
1358 MVT::MvNorm(*C,normsC2);
1359 for (
int i=0; i<numvecs; i++) {
1360 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1362 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1363 <<
"Apply() modified the input vectors." << endl;
1366 if (normsC2[i] != SCT::zero()) {
1368 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1369 <<
"Operator applied to zero did not return zero." << endl;
1376 MVT::MvNorm(*B,normsB1);
1377 OPT::Apply(*M,*B,*C);
1378 MVT::MvNorm(*B,normsB2);
1379 MVT::MvNorm(*C,normsC2);
1380 bool ZeroWarning =
false;
1381 for (
int i=0; i<numvecs; i++) {
1382 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1384 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1385 <<
"Apply() modified the input vectors." << endl;
1388 if (normsC2[i] == SCT::zero() && ZeroWarning==
false ) {
1390 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1391 <<
"Operator applied to random vectors returned zero." << endl;
1398 MVT::MvNorm(*B,normsB1);
1400 OPT::Apply(*M,*B,*C);
1401 MVT::MvNorm(*B,normsB2);
1402 MVT::MvNorm(*C,normsC1);
1403 for (
int i=0; i<numvecs; i++) {
1404 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1406 <<
"*** ERROR *** OperatorTraits::Apply() [3]" << endl
1407 <<
"Apply() modified the input vectors." << endl;
1418 OPT::Apply(*M,*B,*C);
1419 MVT::MvNorm(*B,normsB2);
1420 MVT::MvNorm(*C,normsC2);
1421 for (
int i=0; i<numvecs; i++) {
1422 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1424 <<
"*** ERROR *** OperatorTraits::Apply() [4]" << endl
1425 <<
"Apply() modified the input vectors." << endl;
1428 if ( SCT::magnitude( normsC1[i] - normsC2[i]) > tol ) {
1431 <<
"*** WARNING *** OperatorTraits::Apply() [4]" << endl
1432 <<
"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