42 #ifndef ANASAZI_MVOPTESTER_HPP 43 #define ANASAZI_MVOPTESTER_HPP 66 #include "Teuchos_MatrixMarket_SetScientific.hpp" 67 #include "Teuchos_RCP.hpp" 68 #include "Teuchos_as.hpp" 77 template<
class ScalarType,
class MV >
80 const Teuchos::RCP<const MV> &A ) {
83 using Teuchos::MatrixMarket::details::SetScientific;
160 typedef Teuchos::ScalarTraits<ScalarType> SCT;
161 typedef typename SCT::magnitudeType MagType;
163 const ScalarType one = SCT::one();
164 const ScalarType zero = SCT::zero();
165 const MagType zero_mag = Teuchos::ScalarTraits<MagType>::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);
182 TEUCHOS_TEST_FOR_EXCEPT(numvecs_2 != 5);
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;
218 Teuchos::RCP<MV> B = MVT::Clone(*A,numvecs);
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;
267 Teuchos::RCP<MV> B = MVT::Clone(*A,numvecs);
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;
316 Teuchos::RCP<MV> B = MVT::Clone(*A,numvecs);
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;
360 Teuchos::RCP<MV> B = MVT::Clone(*A,numvecs);
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;
393 Teuchos::RCP<MV> B = MVT::Clone(*A,numvecs);
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;
420 Teuchos::RCP<MV> B, C;
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;
473 Teuchos::RCP<MV> B, C;
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;
519 Teuchos::RCP<MV> B, C;
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;
552 Teuchos::RCP<const MV> constB, C;
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;
593 Teuchos::RCP<MV> B, C;
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;
686 Teuchos::RCP<MV> B, C;
687 std::vector<MagType> normsB(p), normsC(q);
688 Teuchos::SerialDenseMatrix<int,ScalarType> SDM(p,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 );
703 if ( SDM.numRows() != p || SDM.numCols() != q ) {
705 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
706 <<
"Routine resized SerialDenseMatrix." << endl;
711 if ( SDM.normOne() != zero ) {
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;
772 Teuchos::SerialDenseMatrix<int, ScalarType> largeSDM(p+1,q+1);
773 Teuchos::SerialDenseMatrix<int, ScalarType> SDM2(Teuchos::View, largeSDM, p, q);
774 largeSDM.putScalar( one );
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;
800 Teuchos::RCP<MV> B, C;
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;
861 Teuchos::RCP<MV> B, C, D;
862 std::vector<MagType> normsB1(p), normsB2(p),
863 normsC1(p), normsC2(p),
864 normsD1(p), normsD2(p);
865 ScalarType alpha = SCT::random(),
866 beta = SCT::random();
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;
1001 Teuchos::RCP<MV> B, D;
1002 Teuchos::RCP<const MV> C;
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;
1053 Teuchos::RCP<MV> B, C;
1054 Teuchos::SerialDenseMatrix<int,ScalarType> SDM(p,q);
1055 std::vector<MagType> normsC1(q), normsC2(q),
1056 normsB1(p), normsB2(p);
1058 B = MVT::Clone(*A,p);
1059 C = MVT::Clone(*A,q);
1064 MVT::MvNorm(*B,normsB1);
1065 MVT::MvNorm(*C,normsC1);
1067 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1068 MVT::MvNorm(*B,normsB2);
1069 MVT::MvNorm(*C,normsC2);
1070 for (
int i=0; i<p; i++) {
1071 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1073 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1074 <<
"Input vectors were modified." << endl;
1078 for (
int i=0; i<q; i++) {
1079 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1081 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1082 <<
"Arithmetic test 1 failed." << endl;
1090 MVT::MvNorm(*B,normsB1);
1091 MVT::MvNorm(*C,normsC1);
1093 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1094 MVT::MvNorm(*B,normsB2);
1095 MVT::MvNorm(*C,normsC2);
1096 for (
int i=0; i<p; i++) {
1097 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1099 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1100 <<
"Input vectors were modified." << endl;
1104 for (
int i=0; i<q; i++) {
1105 if ( normsC2[i] != zero ) {
1107 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1108 <<
"Arithmetic test 2 failed: " 1121 MVT::MvNorm(*B,normsB1);
1122 MVT::MvNorm(*C,normsC1);
1124 for (
int i=0; i<q; i++) {
1127 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1128 MVT::MvNorm(*B,normsB2);
1129 MVT::MvNorm(*C,normsC2);
1130 for (
int i=0; i<p; i++) {
1131 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1133 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1134 <<
"Input vectors were modified." << endl;
1138 for (
int i=0; i<q; i++) {
1139 if ( SCT::magnitude( normsB1[i] - normsC2[i] ) > tol ) {
1141 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1142 <<
"Arithmetic test 3 failed: " 1154 MVT::MvNorm(*B,normsB1);
1155 MVT::MvNorm(*C,normsC1);
1157 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1158 MVT::MvNorm(*B,normsB2);
1159 MVT::MvNorm(*C,normsC2);
1160 for (
int i=0; i<p; i++) {
1161 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1163 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1164 <<
"Input vectors were modified." << endl;
1168 for (
int i=0; i<q; i++) {
1169 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1171 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1172 <<
"Arithmetic test 4 failed." << endl;
1188 const int p = 5, q = 7;
1189 Teuchos::RCP<MV> B, C;
1190 Teuchos::SerialDenseMatrix<int,ScalarType> SDM(p,q);
1191 std::vector<MagType> normsC1(q), normsC2(q),
1192 normsB1(p), normsB2(p);
1194 B = MVT::Clone(*A,p);
1195 C = MVT::Clone(*A,q);
1200 MVT::MvNorm(*B,normsB1);
1201 MVT::MvNorm(*C,normsC1);
1203 MVT::MvTimesMatAddMv(zero,*B,SDM,one,*C);
1204 MVT::MvNorm(*B,normsB2);
1205 MVT::MvNorm(*C,normsC2);
1206 for (
int i=0; i<p; i++) {
1207 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1209 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1210 <<
"Input vectors were modified." << endl;
1214 for (
int i=0; i<q; i++) {
1215 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1217 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1218 <<
"Arithmetic test 5 failed." << endl;
1226 MVT::MvNorm(*B,normsB1);
1227 MVT::MvNorm(*C,normsC1);
1229 MVT::MvTimesMatAddMv(zero,*B,SDM,zero,*C);
1230 MVT::MvNorm(*B,normsB2);
1231 MVT::MvNorm(*C,normsC2);
1232 for (
int i=0; i<p; i++) {
1233 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1235 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1236 <<
"Input vectors were modified." << endl;
1240 for (
int i=0; i<q; i++) {
1241 if ( normsC2[i] != zero ) {
1243 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1244 <<
"Arithmetic test 6 failed: " 1256 MVT::MvNorm(*B,normsB1);
1257 MVT::MvNorm(*C,normsC1);
1259 for (
int i=0; i<p; i++) {
1262 MVT::MvTimesMatAddMv(one,*B,SDM,zero,*C);
1263 MVT::MvNorm(*B,normsB2);
1264 MVT::MvNorm(*C,normsC2);
1265 for (
int i=0; i<p; i++) {
1266 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1268 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1269 <<
"Input vectors were modified." << endl;
1273 for (
int i=0; i<p; i++) {
1274 if ( SCT::magnitude( normsB1[i] - normsC2[i] ) > tol ) {
1276 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1277 <<
"Arithmetic test 7 failed." << endl;
1281 for (
int i=p; i<q; i++) {
1282 if ( normsC2[i] != zero ) {
1284 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1285 <<
"Arithmetic test 7 failed." << endl;
1293 MVT::MvNorm(*B,normsB1);
1294 MVT::MvNorm(*C,normsC1);
1296 MVT::MvTimesMatAddMv(one,*B,SDM,one,*C);
1297 MVT::MvNorm(*B,normsB2);
1298 MVT::MvNorm(*C,normsC2);
1299 for (
int i=0; i<p; i++) {
1300 if ( SCT::magnitude( normsB1[i] - normsB2[i] ) > tol ) {
1302 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1303 <<
"Input vectors were modified." << endl;
1307 for (
int i=0; i<q; i++) {
1308 if ( SCT::magnitude( normsC1[i] - normsC2[i] ) > tol ) {
1310 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1311 <<
"Arithmetic test 8 failed." << endl;
1328 template<
class ScalarType,
class MV,
class OP>
1331 const Teuchos::RCP<const MV> &A,
1332 const Teuchos::RCP<const OP> &M) {
1344 typedef Teuchos::ScalarTraits<ScalarType> SCT;
1346 typedef typename SCT::magnitudeType MagType;
1348 const MagType tol = SCT::eps()*100;
1350 const int numvecs = 10;
1352 Teuchos::RCP<MV> B = MVT::Clone(*A,numvecs),
1353 C = MVT::Clone(*A,numvecs);
1355 std::vector<MagType> normsB1(numvecs), normsB2(numvecs),
1356 normsC1(numvecs), normsC2(numvecs);
1367 MVT::MvNorm(*B,normsB1);
1368 OPT::Apply(*M,*B,*C);
1369 MVT::MvNorm(*B,normsB2);
1370 MVT::MvNorm(*C,normsC2);
1371 for (
int i=0; i<numvecs; i++) {
1372 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1374 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1375 <<
"Apply() modified the input vectors." << endl;
1378 if (normsC2[i] != SCT::zero()) {
1380 <<
"*** ERROR *** OperatorTraits::Apply() [1]" << endl
1381 <<
"Operator applied to zero did not return zero." << endl;
1388 MVT::MvNorm(*B,normsB1);
1389 OPT::Apply(*M,*B,*C);
1390 MVT::MvNorm(*B,normsB2);
1391 MVT::MvNorm(*C,normsC2);
1392 bool ZeroWarning =
false;
1393 for (
int i=0; i<numvecs; i++) {
1394 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1396 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1397 <<
"Apply() modified the input vectors." << endl;
1400 if (normsC2[i] == SCT::zero() && ZeroWarning==
false ) {
1402 <<
"*** ERROR *** OperatorTraits::Apply() [2]" << endl
1403 <<
"Operator applied to random vectors returned zero." << endl;
1410 MVT::MvNorm(*B,normsB1);
1412 OPT::Apply(*M,*B,*C);
1413 MVT::MvNorm(*B,normsB2);
1414 MVT::MvNorm(*C,normsC1);
1415 for (
int i=0; i<numvecs; i++) {
1416 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1418 <<
"*** ERROR *** OperatorTraits::Apply() [3]" << endl
1419 <<
"Apply() modified the input vectors." << endl;
1430 OPT::Apply(*M,*B,*C);
1431 MVT::MvNorm(*B,normsB2);
1432 MVT::MvNorm(*C,normsC2);
1433 for (
int i=0; i<numvecs; i++) {
1434 if ( SCT::magnitude( normsB2[i] - normsB1[i] ) > tol ) {
1436 <<
"*** ERROR *** OperatorTraits::Apply() [4]" << endl
1437 <<
"Apply() modified the input vectors." << endl;
1440 if ( SCT::magnitude( normsC1[i] - normsC2[i]) > tol ) {
1443 <<
"*** WARNING *** OperatorTraits::Apply() [4]" << endl
1444 <<
"Apply() returned two different results." << endl << endl;
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.
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package...
Abstract class definition for Anasazi Output Managers.
Output managers remove the need for the eigensolver to know any information about the required output...
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...
Types and exceptions used within Anasazi solvers and interfaces.