55 const Teuchos::RCP<const MV> &
A)
57 using Teuchos::SetScientific;
60 typedef Teuchos::ScalarTraits<ScalarType> STS;
61 typedef typename STS::magnitudeType
MagType;
70 const MagType tol = Teuchos::as<MagType> (100) * STS::eps ();
175 if ( MVT::GetNumberVecs(*
A) <= 0 ) {
177 <<
"*** ERROR *** MultiVectorTraits::GetNumberVecs()." << endl
178 <<
"Returned <= 0." << endl;
187 if ( MVT::GetGlobalLength(*
A) <= 0 ) {
189 <<
"*** ERROR *** MultiVectorTraitsExt::GetGlobalLength()" << endl
190 <<
"Returned <= 0." << endl;
203 Teuchos::RCP<MV> B = MVT::Clone(*
A,
numvecs);
207 if ( MVT::GetNumberVecs(*B) !=
numvecs ) {
209 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
210 <<
"Did not allocate requested number of vectors." << endl;
213 if ( MVT::GetGlobalLength(*B) != MVT::GetGlobalLength(*
A) ) {
215 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
216 <<
"Did not allocate requested number of vectors." << endl;
219 MVT::MvNorm(*B,
norms);
222 <<
"*** WARNING *** MultiVecTraits::MvNorm()." << endl
223 <<
"Method resized the output vector." << endl;
229 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
230 <<
"Vector had negative norm." << endl;
253 Teuchos::RCP<MV> B = MVT::Clone(*
A,
numvecs);
257 MVT::MvNorm(*B,
norms);
261 <<
"*** ERROR *** MultiVecTraits::MvInit() "
262 <<
"and MultiVecTraits::MvNorm()" << endl
263 <<
"Supposedly zero vector has non-zero norm." << endl;
268 MVT::MvNorm(*B,
norms);
274 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
275 <<
"Random vector was empty (very unlikely)." << endl;
280 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
281 <<
"Vector had negative norm." << endl;
286 <<
"*** ERROR *** MutliVecTraits::MvRandom()." << endl
287 <<
"Vectors not random enough." << endl;
302 Teuchos::RCP<MV> B = MVT::Clone(*
A,
numvecs);
306 MVT::MvScale(*B,STS::zero());
307 MVT::MvNorm(*B,
norms);
311 <<
"*** ERROR *** MultiVecTraits::MvScale(alpha) "
312 <<
"Supposedly zero vector has non-zero norm." << endl;
319 MVT::MvScale(*B,
zeros);
320 MVT::MvNorm(*B,
norms);
324 <<
"*** ERROR *** MultiVecTraits::MvScale(alphas) "
325 <<
"Supposedly zero vector has non-zero norm." << endl;
346 Teuchos::RCP<MV> B = MVT::Clone(*
A,
numvecs);
350 MVT::MvNorm(*B,
norms);
355 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
356 <<
"Vector had negative norm." << endl;
362 <<
"Warning testing MultiVecTraits::MvInit()." << endl
363 <<
"Ones std::vector should have norm std::sqrt(dim)." << endl
364 <<
"norms[i]: " <<
norms[
i] <<
"\tdim: " << MVT::GetGlobalLength(*B) << endl << endl;
379 Teuchos::RCP<MV> B = MVT::Clone(*
A,
numvecs);
382 MVT::MvNorm(*B,
norms);
386 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
387 <<
"Vector had negative norm." << endl;
392 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
393 <<
"Zero std::vector should have norm zero." << endl;
406 Teuchos::RCP<MV> B, C;
411 MVT::MvNorm(*B,
norms);
412 C = MVT::CloneCopy(*B,
ind);
414 if ( MVT::GetNumberVecs(*C) !=
numvecs_2 ) {
416 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
417 <<
"Wrong number of vectors." << endl;
420 if ( MVT::GetGlobalLength(*C) != MVT::GetGlobalLength(*B) ) {
422 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
423 <<
"Vector lengths don't match." << endl;
429 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
430 <<
"Copied vectors do not agree: "
433 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
439 MVT::MvInit(*B,
zero);
440 MVT::MvNorm(*C,
norms);
445 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
446 <<
"Copied vectors were not independent." << endl
449 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
461 Teuchos::RCP<MV> B, C;
466 MVT::MvNorm(*B,
norms);
467 C = MVT::CloneCopy(*B);
469 if ( MVT::GetNumberVecs(*C) !=
numvecs ) {
471 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
472 <<
"Wrong number of vectors." << endl;
478 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
479 <<
"Copied vectors do not agree: "
482 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
486 MVT::MvInit(*B,
zero);
487 MVT::MvNorm(*C,
norms);
492 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
493 <<
"Copied vectors were not independent." << endl
496 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
510 Teuchos::RCP<MV> B, C;
515 MVT::MvNorm(*B,
norms);
516 C = MVT::CloneViewNonConst(*B,
ind);
518 if ( MVT::GetNumberVecs(*C) !=
numvecs_2 ) {
520 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
521 <<
"Wrong number of vectors." << endl;
528 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
529 <<
"Viewed vectors do not agree." << endl;
544 Teuchos::RCP<const MV> C;
554 C = MVT::CloneView(*B,
ind);
556 if ( MVT::GetNumberVecs(*C) !=
numvecs_2 ) {
558 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
559 <<
"Wrong number of vectors." << endl;
566 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
567 <<
"Viewed vectors do not agree." << endl;
586 Teuchos::RCP<MV> B, C;
602 MVT::SetBlock(*C,
ind,*B);
611 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
612 <<
"Operation modified source vectors." << endl;
623 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
624 <<
"Copied vectors do not agree: " << endl
627 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
635 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
636 <<
"Incorrect vectors were modified." << endl
639 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
644 MVT::MvInit(*C,
zero);
651 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
652 <<
"Copied vectors were not independent." << endl
655 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
678 Teuchos::RCP<MV> B, C;
690 for (
int i=0;
i<setSize;
i++) {
698 MVT::SetBlock(*C,
ind,*B);
707 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
708 <<
"Operation modified source vectors." << endl;
720 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
721 <<
"Copied vectors do not agree: " << endl
723 <<
"Difference " <<
diff <<
" exceeds the tolerance 100*eps = "
734 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
735 <<
"Incorrect vectors were modified." << endl
737 <<
"Difference " <<
diff <<
" exceeds the tolerance 100*eps = "
743 MVT::MvInit(*C,
zero);
750 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
751 <<
"Copied vectors were not independent." << endl
754 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
783 Teuchos::RCP<MV> B, C;
785 Teuchos::SerialDenseMatrix<int,ScalarType> SDM(
p,
q);
787 B = MVT::Clone(*
A,
p);
788 C = MVT::Clone(*
A,
q);
797 MVT::MvTransMv(
zero, *B, *C, SDM );
800 if ( SDM.numRows() !=
p || SDM.numCols() !=
q ) {
802 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
803 <<
"Routine resized SerialDenseMatrix." << endl;
808 if ( SDM.normOne() !=
zero ) {
810 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
811 <<
"Scalar argument processed incorrectly." << endl;
816 MVT::MvTransMv(
one, *B, *C, SDM );
820 for (
int i=0;
i<
p;
i++) {
821 for (
int j=0;
j<
q;
j++) {
822 if ( STS::magnitude(SDM(
i,
j))
825 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
826 <<
"Triangle inequality did not hold: "
827 << STS::magnitude(SDM(
i,
j))
837 MVT::MvTransMv(
one, *B, *C, SDM );
838 for (
int i=0;
i<
p;
i++) {
839 for (
int j=0;
j<
q;
j++) {
842 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
843 <<
"Inner products not zero for C==0." << endl;
850 MVT::MvTransMv(
one, *B, *C, SDM );
851 for (
int i=0;
i<
p;
i++) {
852 for (
int j=0;
j<
q;
j++) {
855 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
856 <<
"Inner products not zero for B==0." << endl;
873 Teuchos::RCP<MV> B, C;
874 std::vector<ScalarType>
iprods(
p+
q);
877 B = MVT::Clone(*
A,
p);
878 C = MVT::Clone(*
A,
p);
884 MVT::MvDot( *B, *C,
iprods );
887 <<
"*** ERROR *** MultiVecTraits::MvDot." << endl
888 <<
"Routine resized results std::vector." << endl;
895 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
896 <<
"Inner products not valid." << endl;
902 MVT::MvDot( *B, *C,
iprods );
903 for (
int i=0;
i<
p;
i++) {
906 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
907 <<
"Inner products not zero for B==0." << endl;
913 MVT::MvDot( *B, *C,
iprods );
914 for (
int i=0;
i<
p;
i++) {
917 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
918 <<
"Inner products not zero for C==0." << endl;
934 Teuchos::RCP<MV> B, C, D;
939 Teuchos::SerialDenseMatrix<int,ScalarType> Alpha(1,1), Beta(1,1);
940 Teuchos::randomSyncedMatrix( Alpha );
941 Teuchos::randomSyncedMatrix( Beta );
945 B = MVT::Clone(*
A,
p);
946 C = MVT::Clone(*
A,
p);
947 D = MVT::Clone(*
A,
p);
955 MVT::MvAddMv(
zero,*B,
one,*C,*D);
959 for (
int i=0;
i<
p;
i++) {
962 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
963 <<
"Input arguments were modified." << endl;
968 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
969 <<
"Input arguments were modified." << endl;
974 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
975 <<
"Assignment did not work." << endl;
981 MVT::MvAddMv(
one,*B,
zero,*C,*D);
985 for (
int i=0;
i<
p;
i++) {
988 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
989 <<
"Input arguments were modified." << endl;
994 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
995 <<
"Input arguments were modified." << endl;
1000 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1001 <<
"Assignment did not work." << endl;
1009 MVT::MvAddMv(alpha,*B,beta,*C,*D);
1014 for (
int i=0;
i<
p;
i++) {
1017 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1018 <<
"Input arguments were modified." << endl;
1023 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1024 <<
"Input arguments were modified." << endl;
1030 MVT::MvAddMv(alpha,*B,beta,*C,*D);
1036 for (
int i=0;
i<
p;
i++) {
1039 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1040 <<
"Input arguments were modified." << endl;
1045 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1046 <<
"Input arguments were modified." << endl;
1051 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1052 <<
"Results varies depending on initial state of dest vectors." << endl;
1078 Teuchos::RCP<MV> B, D;
1079 Teuchos::RCP<const MV> C;
1080 std::vector<MagType>
normsB(
p),
1085 B = MVT::Clone(*
A,
p);
1087 D = MVT::CloneViewNonConst(*B,
lclindex);
1093 MVT::MvAddMv(
zero,*B,
one,*C,*D);
1095 for (
int i=0;
i<
p;
i++) {
1098 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1099 <<
"Assignment did not work." << endl;
1105 MVT::MvAddMv(
one,*B,
zero,*C,*D);
1107 for (
int i=0;
i<
p;
i++) {
1110 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1111 <<
"Assignment did not work." << endl;
1129 const int p = 7,
q = 5;
1130 Teuchos::RCP<MV> B, C;
1131 Teuchos::SerialDenseMatrix<int,ScalarType> SDM(
p,
q);
1135 B = MVT::Clone(*
A,
p);
1136 C = MVT::Clone(*
A,
q);
1143 Teuchos::randomSyncedMatrix(SDM);
1144 MVT::MvTimesMatAddMv(
zero,*B,SDM,
one,*C);
1147 for (
int i=0;
i<
p;
i++) {
1150 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1151 <<
"Input vectors were modified." << endl;
1155 for (
int i=0;
i<
q;
i++) {
1158 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1159 <<
"Arithmetic test 1 failed." << endl;
1169 Teuchos::randomSyncedMatrix(SDM);
1170 MVT::MvTimesMatAddMv(
zero,*B,SDM,
zero,*C);
1173 for (
int i=0;
i<
p;
i++) {
1176 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1177 <<
"Input vectors were modified." << endl;
1181 for (
int i=0;
i<
q;
i++) {
1184 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1185 <<
"Arithmetic test 2 failed: "
1201 for (
int i=0;
i<
q;
i++) {
1204 MVT::MvTimesMatAddMv(
one,*B,SDM,
zero,*C);
1207 for (
int i=0;
i<
p;
i++) {
1210 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1211 <<
"Input vectors were modified." << endl;
1215 for (
int i=0;
i<
q;
i++) {
1218 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1219 <<
"Arithmetic test 3 failed: "
1234 MVT::MvTimesMatAddMv(
one,*B,SDM,
one,*C);
1237 for (
int i=0;
i<
p;
i++) {
1240 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1241 <<
"Input vectors were modified." << endl;
1245 for (
int i=0;
i<
q;
i++) {
1248 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1249 <<
"Arithmetic test 4 failed." << endl;
1265 const int p = 5,
q = 7;
1266 Teuchos::RCP<MV> B, C;
1267 Teuchos::SerialDenseMatrix<int,ScalarType> SDM(
p,
q);
1271 B = MVT::Clone(*
A,
p);
1272 C = MVT::Clone(*
A,
q);
1279 Teuchos::randomSyncedMatrix(SDM);
1280 MVT::MvTimesMatAddMv(
zero,*B,SDM,
one,*C);
1283 for (
int i=0;
i<
p;
i++) {
1286 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1287 <<
"Input vectors were modified." << endl;
1291 for (
int i=0;
i<
q;
i++) {
1294 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1295 <<
"Arithmetic test 5 failed." << endl;
1305 Teuchos::randomSyncedMatrix(SDM);
1306 MVT::MvTimesMatAddMv(
zero,*B,SDM,
zero,*C);
1309 for (
int i=0;
i<
p;
i++) {
1312 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1313 <<
"Input vectors were modified." << endl;
1317 for (
int i=0;
i<
q;
i++) {
1320 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1321 <<
"Arithmetic test 6 failed: "
1336 for (
int i=0;
i<
p;
i++) {
1339 MVT::MvTimesMatAddMv(
one,*B,SDM,
zero,*C);
1342 for (
int i=0;
i<
p;
i++) {
1345 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1346 <<
"Input vectors were modified." << endl;
1350 for (
int i=0;
i<
p;
i++) {
1353 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1354 <<
"Arithmetic test 7 failed." << endl;
1358 for (
int i=
p;
i<
q;
i++) {
1361 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1362 <<
"Arithmetic test 7 failed." << endl;
1373 MVT::MvTimesMatAddMv(
one,*B,SDM,
one,*C);
1376 for (
int i=0;
i<
p;
i++) {
1379 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1380 <<
"Input vectors were modified." << endl;
1384 for (
int i=0;
i<
q;
i++) {
1387 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1388 <<
"Arithmetic test 8 failed." << endl;
bool TestOperatorTraits(const Teuchos::RCP< OutputManager< ScalarType > > &om, const Teuchos::RCP< const MV > &A, const Teuchos::RCP< const OP > &M)
Test correctness of OperatorTraits specialization and its operator implementation.