99 const Teuchos::RCP<const MV> &
A)
101 using Teuchos::SetScientific;
105 typedef Teuchos::ScalarTraits<ScalarType> STS;
106 typedef typename STS::magnitudeType
MagType;
115 const MagType tol = Teuchos::as<MagType> (120) * STS::eps ();
225 if ( MVT::GetNumberVecs(*
A) <= 0 ) {
227 <<
"*** ERROR *** MultiVectorTraits::GetNumberVecs()." << endl
228 <<
"Returned <= 0." << endl;
237 if ( MVT::GetGlobalLength(*
A) <= 0 ) {
239 <<
"*** ERROR *** MultiVectorTraitsExt::GetGlobalLength()" << endl
240 <<
"Returned <= 0." << endl;
253 Teuchos::RCP<MV> B = MVT::Clone(*
A,
numvecs);
257 if ( MVT::GetNumberVecs(*B) !=
numvecs ) {
259 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
260 <<
"Did not allocate requested number of vectors." << endl;
263 if ( MVT::GetGlobalLength(*B) != MVT::GetGlobalLength(*
A) ) {
265 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
266 <<
"Did not allocate requested number of vectors." << endl;
269 MVT::MvNorm(*B,
norms);
272 <<
"*** WARNING *** MultiVecTraits::MvNorm()." << endl
273 <<
"Method resized the output vector." << endl;
279 <<
"*** ERROR *** MultiVecTraits::Clone()." << endl
280 <<
"Vector had negative norm." << endl;
303 Teuchos::RCP<MV> B = MVT::Clone(*
A,
numvecs);
307 MVT::MvNorm(*B,
norms);
311 <<
"*** ERROR *** MultiVecTraits::MvInit() "
312 <<
"and MultiVecTraits::MvNorm()" << endl
313 <<
"Supposedly zero vector has non-zero norm." << endl;
318 MVT::MvNorm(*B,
norms);
324 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
325 <<
"Random vector was empty (very unlikely)." << endl;
330 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
331 <<
"Vector had negative norm." << endl;
336 <<
"*** ERROR *** MutliVecTraits::MvRandom()." << endl
337 <<
"Vectors not random enough." << endl;
352 Teuchos::RCP<MV> B = MVT::Clone(*
A,
numvecs);
356 MVT::MvScale(*B,STS::zero());
357 MVT::MvNorm(*B,
norms);
361 <<
"*** ERROR *** MultiVecTraits::MvScale(alpha) "
362 <<
"Supposedly zero vector has non-zero norm." << endl;
369 MVT::MvScale(*B,
zeros);
370 MVT::MvNorm(*B,
norms);
374 <<
"*** ERROR *** MultiVecTraits::MvScale(alphas) "
375 <<
"Supposedly zero vector has non-zero norm." << endl;
396 Teuchos::RCP<MV> B = MVT::Clone(*
A,
numvecs);
400 MVT::MvNorm(*B,
norms);
405 <<
"*** ERROR *** MultiVecTraits::MvRandom()." << endl
406 <<
"Vector had negative norm." << endl;
412 <<
"Warning testing MultiVecTraits::MvInit()." << endl
413 <<
"Ones std::vector should have norm std::sqrt(dim)." << endl
414 <<
"norms[i]: " <<
norms[
i] <<
"\tdim: " << MVT::GetGlobalLength(*B) << endl << endl;
429 Teuchos::RCP<MV> B = MVT::Clone(*
A,
numvecs);
432 MVT::MvNorm(*B,
norms);
436 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
437 <<
"Vector had negative norm." << endl;
442 <<
"*** ERROR *** MultiVecTraits::MvInit()." << endl
443 <<
"Zero std::vector should have norm zero." << endl;
456 Teuchos::RCP<MV> B, C;
461 MVT::MvNorm(*B,
norms);
462 C = MVT::CloneCopy(*B,
ind);
464 if ( MVT::GetNumberVecs(*C) !=
numvecs_2 ) {
466 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
467 <<
"Wrong number of vectors." << endl;
470 if ( MVT::GetGlobalLength(*C) != MVT::GetGlobalLength(*B) ) {
472 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
473 <<
"Vector lengths don't match." << endl;
479 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
480 <<
"Copied vectors do not agree: "
483 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
489 MVT::MvInit(*B,
zero);
490 MVT::MvNorm(*C,
norms);
495 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." << endl
496 <<
"Copied vectors were not independent." << endl
499 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
511 Teuchos::RCP<MV> B, C;
516 MVT::MvNorm(*B,
norms);
517 C = MVT::CloneCopy(*B);
519 if ( MVT::GetNumberVecs(*C) !=
numvecs ) {
521 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
522 <<
"Wrong number of vectors." << endl;
528 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
529 <<
"Copied vectors do not agree: "
532 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
536 MVT::MvInit(*B,
zero);
537 MVT::MvNorm(*C,
norms);
542 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." << endl
543 <<
"Copied vectors were not independent." << endl
546 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
560 Teuchos::RCP<MV> B, C;
565 MVT::MvNorm(*B,
norms);
566 C = MVT::CloneViewNonConst(*B,
ind);
568 if ( MVT::GetNumberVecs(*C) !=
numvecs_2 ) {
570 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
571 <<
"Wrong number of vectors." << endl;
578 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." << endl
579 <<
"Viewed vectors do not agree." << endl;
594 Teuchos::RCP<const MV> C;
604 C = MVT::CloneView(*B,
ind);
606 if ( MVT::GetNumberVecs(*C) !=
numvecs_2 ) {
608 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
609 <<
"Wrong number of vectors." << endl;
616 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." << endl
617 <<
"Viewed vectors do not agree." << endl;
636 Teuchos::RCP<MV> B, C;
652 MVT::SetBlock(*C,
ind,*B);
661 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
662 <<
"Operation modified source vectors." << endl;
673 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
674 <<
"Copied vectors do not agree: " << endl
677 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
685 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
686 <<
"Incorrect vectors were modified." << endl
689 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
694 MVT::MvInit(*C,
zero);
701 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
702 <<
"Copied vectors were not independent." << endl
705 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
728 Teuchos::RCP<MV> B, C;
740 for (
int i=0;
i<setSize;
i++) {
748 MVT::SetBlock(*C,
ind,*B);
757 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
758 <<
"Operation modified source vectors." << endl;
770 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
771 <<
"Copied vectors do not agree: " << endl
773 <<
"Difference " <<
diff <<
" exceeds the tolerance 100*eps = "
784 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
785 <<
"Incorrect vectors were modified." << endl
787 <<
"Difference " <<
diff <<
" exceeds the tolerance 100*eps = "
793 MVT::MvInit(*C,
zero);
800 <<
"*** ERROR *** MultiVecTraits::SetBlock()." << endl
801 <<
"Copied vectors were not independent." << endl
804 <<
" exceeds the tolerance 100*eps = " <<
tol << endl;
833 Teuchos::RCP<MV> B, C;
835 Teuchos::RCP<DM> SDM = DMT::Create(
p,
q);
837 B = MVT::Clone(*
A,
p);
838 C = MVT::Clone(*
A,
q);
847 MVT::MvTransMv(
zero, *B, *C, *SDM );
848 DMT::SyncDeviceToHost(*SDM);
851 if ( DMT::GetNumRows(*SDM) !=
p || DMT::GetNumCols(*SDM) !=
q ) {
853 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
854 <<
"Routine resized DenseMatrix." << endl;
859 if (DMT::NormOne(*SDM) !=
zero ) {
861 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
862 <<
"Scalar argument processed incorrectly." << endl;
867 MVT::MvTransMv(
one, *B, *C, *SDM );
868 DMT::SyncDeviceToHost(*SDM);
872 for (
int i=0;
i<
p;
i++) {
873 for (
int j=0;
j<
q;
j++) {
874 if ( STS::magnitude(DMT::ValueConst(*SDM,
i,
j))
877 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
878 <<
"Triangle inequality did not hold: "
879 << STS::magnitude(DMT::ValueConst(*SDM,
i,
j))
889 MVT::MvTransMv(
one, *B, *C, *SDM );
890 DMT::SyncDeviceToHost(*SDM);
891 for (
int i=0;
i<
p;
i++) {
892 for (
int j=0;
j<
q;
j++) {
893 if ( DMT::ValueConst(*SDM,
i,
j) !=
zero ) {
895 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
896 <<
"Inner products not zero for C==0." << endl;
903 MVT::MvTransMv(
one, *B, *C, *SDM );
904 DMT::SyncDeviceToHost(*SDM);
905 for (
int i=0;
i<
p;
i++) {
906 for (
int j=0;
j<
q;
j++) {
907 if ( DMT::ValueConst(*SDM,
i,
j) !=
zero ) {
909 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." << endl
910 <<
"Inner products not zero for B==0." << endl;
926 Teuchos::RCP<MV> B, C;
927 std::vector<ScalarType>
iprods(
p+
q);
930 B = MVT::Clone(*
A,
p);
931 C = MVT::Clone(*
A,
p);
937 MVT::MvDot( *B, *C,
iprods );
940 <<
"*** ERROR *** MultiVecTraits::MvDot." << endl
941 <<
"Routine resized results std::vector." << endl;
948 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
949 <<
"Inner products not valid." << endl;
955 MVT::MvDot( *B, *C,
iprods );
956 for (
int i=0;
i<
p;
i++) {
959 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
960 <<
"Inner products not zero for B==0." << endl;
966 MVT::MvDot( *B, *C,
iprods );
967 for (
int i=0;
i<
p;
i++) {
970 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
971 <<
"Inner products not zero for C==0." << endl;
975 if constexpr (Teuchos::ScalarTraits<ScalarType>::isComplex) {
978 MVT::MvInit(*C, STS::one());
979 MVT::MvDot( *B, *C,
iprods );
981 auto size = MVT::GetGlobalLength(*B);
983 for (
int i=0;
i<
p;
i++) {
986 <<
"*** ERROR *** MultiVecTraits::MvDot()." << endl
987 <<
"Inner products gave bad value: " <<
iprods[
i] <<
". Expected: " <<
expected << endl;
1003 Teuchos::RCP<MV> B, C, D;
1008 Teuchos::RCP<DM> Alpha = DMT::Create(1,1);
1009 Teuchos::RCP<DM> Beta = DMT::Create(1,1);
1012 ScalarType alpha = DMT::ValueConst(*Alpha,0,0),
1013 beta = DMT::ValueConst(*Beta,0,0);
1015 B = MVT::Clone(*
A,
p);
1016 C = MVT::Clone(*
A,
p);
1017 D = MVT::Clone(*
A,
p);
1025 MVT::MvAddMv(
zero,*B,
one,*C,*D);
1029 for (
int i=0;
i<
p;
i++) {
1032 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1033 <<
"Input arguments were modified." << endl;
1038 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1039 <<
"Input arguments were modified." << endl;
1044 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1045 <<
"Assignment did not work." << endl;
1051 MVT::MvAddMv(
one,*B,
zero,*C,*D);
1055 for (
int i=0;
i<
p;
i++) {
1058 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1059 <<
"Input arguments were modified." << endl;
1064 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1065 <<
"Input arguments were modified." << endl;
1070 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1071 <<
"Assignment did not work." << endl;
1079 MVT::MvAddMv(alpha,*B,beta,*C,*D);
1084 for (
int i=0;
i<
p;
i++) {
1087 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1088 <<
"Input arguments were modified." << endl;
1093 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1094 <<
"Input arguments were modified." << endl;
1100 MVT::MvAddMv(alpha,*B,beta,*C,*D);
1106 for (
int i=0;
i<
p;
i++) {
1109 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1110 <<
"Input arguments were modified." << endl;
1115 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1116 <<
"Input arguments were modified." << endl;
1121 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." << endl
1122 <<
"Results varies depending on initial state of dest vectors." << endl;
1148 Teuchos::RCP<MV> B, D;
1149 Teuchos::RCP<const MV> C;
1150 std::vector<MagType>
normsB(
p),
1155 B = MVT::Clone(*
A,
p);
1157 D = MVT::CloneViewNonConst(*B,
lclindex);
1163 MVT::MvAddMv(
zero,*B,
one,*C,*D);
1165 for (
int i=0;
i<
p;
i++) {
1168 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1169 <<
"Assignment did not work." << endl;
1175 MVT::MvAddMv(
one,*B,
zero,*C,*D);
1177 for (
int i=0;
i<
p;
i++) {
1180 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" << endl
1181 <<
"Assignment did not work." << endl;
1199 const int p = 7,
q = 5;
1200 Teuchos::RCP<MV> B, C;
1201 Teuchos::RCP<DM> SDM = DMT::Create(
p,
q);
1205 B = MVT::Clone(*
A,
p);
1206 C = MVT::Clone(*
A,
q);
1214 MVT::MvTimesMatAddMv(
zero,*B,*SDM,
one,*C);
1217 for (
int i=0;
i<
p;
i++) {
1220 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1221 <<
"Input vectors were modified." << endl;
1225 for (
int i=0;
i<
q;
i++) {
1228 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1229 <<
"Arithmetic test 1 failed." << endl;
1240 MVT::MvTimesMatAddMv(
zero,*B,*SDM,
zero,*C);
1243 for (
int i=0;
i<
p;
i++) {
1246 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1247 <<
"Input vectors were modified." << endl;
1251 for (
int i=0;
i<
q;
i++) {
1254 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1255 <<
"Arithmetic test 2 failed: "
1270 DMT::Scale(*SDM,
zero);
1271 DMT::SyncDeviceToHost(*SDM);
1272 for (
int i=0;
i<
q;
i++) {
1273 DMT::Value(*SDM,
i,
i) =
one;
1275 DMT::SyncHostToDevice(*SDM);
1276 MVT::MvTimesMatAddMv(
one,*B,*SDM,
zero,*C);
1279 for (
int i=0;
i<
p;
i++) {
1282 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1283 <<
"Input vectors were modified." << endl;
1287 for (
int i=0;
i<
q;
i++) {
1290 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1291 <<
"Arithmetic test 3 failed: "
1305 DMT::Scale(*SDM,
zero);
1306 MVT::MvTimesMatAddMv(
one,*B,*SDM,
one,*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 4 failed." << endl;
1337 const int p = 5,
q = 7;
1338 Teuchos::RCP<MV> B, C;
1339 Teuchos::RCP<DM> SDM = DMT::Create(
p,
q);
1343 B = MVT::Clone(*
A,
p);
1344 C = MVT::Clone(*
A,
q);
1352 MVT::MvTimesMatAddMv(
zero,*B,*SDM,
one,*C);
1355 for (
int i=0;
i<
p;
i++) {
1358 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1359 <<
"Input vectors were modified." << endl;
1363 for (
int i=0;
i<
q;
i++) {
1366 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1367 <<
"Arithmetic test 5 failed." << endl;
1378 MVT::MvTimesMatAddMv(
zero,*B,*SDM,
zero,*C);
1381 for (
int i=0;
i<
p;
i++) {
1384 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1385 <<
"Input vectors were modified." << endl;
1389 for (
int i=0;
i<
q;
i++) {
1392 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1393 <<
"Arithmetic test 6 failed: "
1407 DMT::Scale(*SDM,
zero);
1408 DMT::SyncDeviceToHost(*SDM);
1409 for (
int i=0;
i<
p;
i++) {
1410 DMT::Value(*SDM,
i,
i) =
one;
1412 DMT::SyncHostToDevice(*SDM);
1413 MVT::MvTimesMatAddMv(
one,*B,*SDM,
zero,*C);
1416 for (
int i=0;
i<
p;
i++) {
1419 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1420 <<
"Input vectors were modified." << endl;
1424 for (
int i=0;
i<
p;
i++) {
1427 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1428 <<
"Arithmetic test 7 failed." << endl;
1432 for (
int i=
p;
i<
q;
i++) {
1435 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1436 <<
"Arithmetic test 7 failed." << endl;
1446 DMT::Scale(*SDM,
zero);
1447 MVT::MvTimesMatAddMv(
one,*B,*SDM,
one,*C);
1450 for (
int i=0;
i<
p;
i++) {
1453 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1454 <<
"Input vectors were modified." << endl;
1458 for (
int i=0;
i<
q;
i++) {
1461 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." << endl
1462 <<
"Arithmetic test 8 failed." << endl;