34 #ifdef HAVE_TEUCHOS_COMPLEX
35 #define SType1 std::complex<float>
41 #ifdef HAVE_TEUCHOS_COMPLEX
42 #define SType2 std::complex<double>
48 #define OType long int
79 template<
typename TYPE>
90 template<
typename TYPE>
91 void PrintVector(TYPE* Vector,
OType Size, std::string Name,
bool Matlab = 0);
93 template<
typename TYPE>
96 template<
typename TYPE1,
typename TYPE2>
99 template<
typename TYPE1,
typename TYPE2>
102 template<
typename TYPE1,
typename TYPE2>
107 template<
typename TYPE1,
typename TYPE2>
116 int main(
int argc,
char *argv[])
122 bool InvalidCmdLineArgs = 0;
124 for(i = 1; i < argc; i++)
126 if(argv[i][0] ==
'-')
137 InvalidCmdLineArgs = 1;
147 InvalidCmdLineArgs = 1;
157 InvalidCmdLineArgs = 1;
161 InvalidCmdLineArgs = 1;
170 if(InvalidCmdLineArgs || (argc > 4))
172 std::cout <<
"Invalid command line arguments detected. Use the following flags:" << std::endl
173 <<
"\t -v enables verbose mode (reports number of failed/successful tests)" << std::endl
174 <<
"\t -d enables debug mode (same as verbose with output of each test, not recommended for large numbers of tests)" << std::endl
175 <<
"\t -m enables matlab-style output; only has an effect if debug mode is enabled" << std::endl;
190 SType1 SType1alpha, SType1beta;
196 SType2 SType2alpha, SType2beta;
197 SType1 SType1ASUMresult, SType1DOTresult, SType1NRM2result, SType1SINresult;
198 SType2 SType2ASUMresult, SType2DOTresult, SType2NRM2result, SType2SINresult;
199 MType1 SType1COSresult;
200 MType2 SType2COSresult;
202 OType SType1IAMAXresult;
203 OType SType2IAMAXresult;
204 OType TotalTestCount = 1, GoodTestSubcount, GoodTestCount = 0, M, M2, N, N2, P, K, LDA, LDB, LDC, Mx, My;
213 std::srand(time(NULL));
220 GoodTestSubcount = 0;
230 SType2SINresult =
ConvertType(SType1SINresult, convertTo);
234 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
235 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
236 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
237 std::cout <<
"SType1beta = " << SType1beta << std::endl;
238 std::cout <<
"SType2beta = " << SType2beta << std::endl;
241 SType1BLAS.
ROTG(&SType1alpha, &SType1beta, &SType1COSresult, &SType1SINresult);
242 SType2BLAS.
ROTG(&SType2alpha, &SType2beta, &SType2COSresult, &SType2SINresult);
245 std::cout <<
"SType1 ROTG COS result: " << SType1COSresult << std::endl;
246 std::cout <<
"SType2 ROTG COS result: " << SType2COSresult << std::endl;
247 std::cout <<
"SType1 ROTG SIN result: " << SType1SINresult << std::endl;
248 std::cout <<
"SType2 ROTG SIN result: " << SType2SINresult << std::endl;
250 GoodTestSubcount += (
CompareScalars(SType1COSresult, SType2COSresult, TOL) &&
253 GoodTestCount += GoodTestSubcount;
254 if(verbose || debug) std::cout <<
"ROTG: " << GoodTestSubcount <<
" of " << ROTGTESTS <<
" tests were successful." << std::endl;
255 if(debug) std::cout << std::endl;
265 GoodTestSubcount = 0;
270 if (incx == 0) incx = 1;
271 if (incy == 0) incy = 1;
273 Mx = M*std::abs(incx);
274 My = M*std::abs(incy);
275 if (Mx == 0) { Mx = 1; }
276 if (My == 0) { My = 1; }
281 for(j = 0; j < Mx; j++)
286 for(j = 0; j < My; j++)
297 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
298 std::cout <<
"c1 = " << c1 <<
", s1 = " << s1 << std::endl;
299 std::cout <<
"c2 = " << c2 <<
", s2 = " << s2 << std::endl;
300 std::cout <<
"incx = " << incx <<
", incy = " << incy << std::endl;
302 PrintVector(SType1y, My,
"SType1y_before_operation", matlab);
304 PrintVector(SType2y, My,
"SType2y_before_operation", matlab);
307 SType1BLAS.
ROT(M, SType1x, incx, SType1y, incy, &c1, &s1);
308 SType2BLAS.
ROT(M, SType2x, incx, SType2y, incy, &c2, &s2);
311 PrintVector(SType1y, My,
"SType1y_after_operation", matlab);
312 PrintVector(SType2y, My,
"SType2y_after_operation", matlab);
314 GoodTestSubcount += (
CompareVectors(SType1x, SType2x, Mx, TOL) &&
321 GoodTestCount += GoodTestSubcount;
322 if(verbose || debug) std::cout <<
"ROT: " << GoodTestSubcount <<
" of " << ROTTESTS <<
" tests were successful." << std::endl;
323 if(debug) std::cout << std::endl;
331 GoodTestSubcount = 0;
340 for(j = 0; j < M2; j++)
347 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
352 SType1ASUMresult = SType1BLAS.
ASUM(M, SType1x, incx);
353 SType2ASUMresult = SType2BLAS.
ASUM(M, SType2x, incx);
356 std::cout <<
"SType1 ASUM result: " << SType1ASUMresult << std::endl;
357 std::cout <<
"SType2 ASUM result: " << SType2ASUMresult << std::endl;
359 GoodTestSubcount +=
CompareScalars(SType1ASUMresult, SType2ASUMresult, TOL);
363 GoodTestCount += GoodTestSubcount;
364 if(verbose || debug) std::cout <<
"ASUM: " << GoodTestSubcount <<
" of " << ASUMTESTS <<
" tests were successful." << std::endl;
365 if(debug) std::cout << std::endl;
374 GoodTestSubcount = 0;
380 Mx = M*std::abs(incx);
381 My = M*std::abs(incy);
382 if (Mx == 0) { Mx = 1; }
383 if (My == 0) { My = 1; }
388 for(j = 0; j < Mx; j++)
393 for(j = 0; j < My; j++)
402 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
403 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
404 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
406 PrintVector(SType1y, My,
"SType1y_before_operation", matlab);
408 PrintVector(SType2y, My,
"SType2y_before_operation", matlab);
411 SType1BLAS.
AXPY(M, SType1alpha, SType1x, incx, SType1y, incy);
412 SType2BLAS.
AXPY(M, SType2alpha, SType2x, incx, SType2y, incy);
415 PrintVector(SType1y, My,
"SType1y_after_operation", matlab);
416 PrintVector(SType2y, My,
"SType2y_after_operation", matlab);
424 GoodTestCount += GoodTestSubcount;
425 if(verbose || debug) std::cout <<
"AXPY: " << GoodTestSubcount <<
" of " << AXPYTESTS <<
" tests were successful." << std::endl;
426 if(debug) std::cout << std::endl;
434 GoodTestSubcount = 0;
440 Mx = M*std::abs(incx);
441 My = M*std::abs(incy);
442 if (Mx == 0) { Mx = 1; }
443 if (My == 0) { My = 1; }
448 for(j = 0; j < Mx; j++)
453 for(j = 0; j < My; j++)
460 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
462 PrintVector(SType1y, My,
"SType1y_before_operation", matlab);
464 PrintVector(SType2y, My,
"SType2y_before_operation", matlab);
467 SType1BLAS.
COPY(M, SType1x, incx, SType1y, incy);
468 SType2BLAS.
COPY(M, SType2x, incx, SType2y, incy);
471 PrintVector(SType1y, My,
"SType1y_after_operation", matlab);
472 PrintVector(SType2y, My,
"SType2y_after_operation", matlab);
480 GoodTestCount += GoodTestSubcount;
if(verbose || debug) std::cout <<
"COPY: " << GoodTestSubcount <<
" of " << COPYTESTS <<
" tests were successful." << std::endl;
481 if(debug) std::cout << std::endl;
489 GoodTestSubcount = 0;
495 Mx = M*std::abs(incx);
496 My = M*std::abs(incy);
497 if (Mx == 0) { Mx = 1; }
498 if (My == 0) { My = 1; }
503 for(j = 0; j < Mx; j++)
508 for(j = 0; j < My; j++)
515 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
522 SType1DOTresult = SType1BLAS.
DOT(M, SType1x, incx, SType1y, incy);
523 SType2DOTresult = SType2BLAS.
DOT(M, SType2x, incx, SType2y, incy);
526 std::cout <<
"SType1 DOT result: " << SType1DOTresult << std::endl;
527 std::cout <<
"SType2 DOT result: " << SType2DOTresult << std::endl;
529 GoodTestSubcount +=
CompareScalars(SType1DOTresult, SType2DOTresult, TOL);
535 GoodTestCount += GoodTestSubcount;
536 if(verbose || debug) std::cout <<
"DOT: " << GoodTestSubcount <<
" of " << DOTTESTS <<
" tests were successful." << std::endl;
537 if(debug) std::cout << std::endl;
545 GoodTestSubcount = 0;
553 for(j = 0; j < M2; j++)
560 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
565 SType1NRM2result = SType1BLAS.
NRM2(M, SType1x, incx);
566 SType2NRM2result = SType2BLAS.
NRM2(M, SType2x, incx);
569 std::cout <<
"SType1 NRM2 result: " << SType1NRM2result << std::endl;
570 std::cout <<
"SType2 NRM2 result: " << SType2NRM2result << std::endl;
572 GoodTestSubcount +=
CompareScalars(SType1NRM2result, SType2NRM2result, TOL);
576 GoodTestCount += GoodTestSubcount;
if(verbose || debug) std::cout <<
"NRM2: " << GoodTestSubcount <<
" of " << NRM2TESTS <<
" tests were successful." << std::endl;
577 if(debug) std::cout << std::endl;
585 GoodTestSubcount = 0;
596 for(j = 0; j < M2; j++)
605 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
606 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
607 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
608 PrintVector(SType1x, M2,
"SType1x_before_operation", matlab);
609 PrintVector(SType2x, M2,
"SType2x_before_operation", matlab);
612 SType1BLAS.
SCAL(M, SType1alpha, SType1x, incx);
613 SType2BLAS.
SCAL(M, SType2alpha, SType2x, incx);
616 PrintVector(SType1x, M2,
"SType1x_after_operation", matlab);
617 PrintVector(SType2x, M2,
"SType2x_after_operation", matlab);
623 GoodTestCount += GoodTestSubcount;
624 if(verbose || debug) std::cout <<
"SCAL: " << GoodTestSubcount <<
" of " << SCALTESTS <<
" tests were successful." << std::endl;
625 if(debug) std::cout << std::endl;
633 GoodTestSubcount = 0;
641 for(j = 0; j < M2; j++)
648 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
653 SType1IAMAXresult = SType1BLAS.
IAMAX(M, SType1x, incx);
654 SType2IAMAXresult = SType2BLAS.
IAMAX(M, SType2x, incx);
657 std::cout <<
"SType1 IAMAX result: " << SType1IAMAXresult << std::endl;
658 std::cout <<
"SType2 IAMAX result: " << SType2IAMAXresult << std::endl;
660 GoodTestSubcount += (SType1IAMAXresult == SType2IAMAXresult);
664 GoodTestCount += GoodTestSubcount;
665 if(verbose || debug) std::cout <<
"IAMAX: " << GoodTestSubcount <<
" of " << IAMAXTESTS <<
" tests were successful." << std::endl;
666 if(debug) std::cout << std::endl;
676 GoodTestSubcount = 0;
694 M2 = M*std::abs(incy);
695 N2 = N*std::abs(incx);
697 M2 = N*std::abs(incy);
698 N2 = M*std::abs(incx);
711 SType1A =
new SType1[LDA * N];
714 SType2A =
new SType2[LDA * N];
718 for(j = 0; j < LDA * N; j++)
723 for(j = 0; j < N2; j++)
728 for(j = 0; j < M2; j++)
735 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
736 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
737 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
738 std::cout <<
"SType1beta = " << SType1beta << std::endl;
739 std::cout <<
"SType2beta = " << SType2beta << std::endl;
740 PrintMatrix(SType1A, M, N, LDA,
"SType1A", matlab);
742 PrintVector(SType1y, M2,
"SType1y_before_operation", matlab);
743 PrintMatrix(SType2A, M, N, LDA,
"SType2A", matlab);
745 PrintVector(SType2y, M2,
"SType2y_before_operation", matlab);
748 SType1BLAS.
GEMV(TRANS, M, N, SType1alpha, SType1A, LDA, SType1x, incx, SType1beta, SType1y, incy);
749 SType2BLAS.
GEMV(TRANS, M, N, SType2alpha, SType2A, LDA, SType2x, incx, SType2beta, SType2y, incy);
752 PrintVector(SType1y, M2,
"SType1y_after_operation", matlab);
753 PrintVector(SType2y, M2,
"SType2y_after_operation", matlab);
763 GoodTestCount += GoodTestSubcount;
764 if(verbose || debug) std::cout <<
"GEMV: " << GoodTestSubcount <<
" of " << GEMVTESTS <<
" tests were successful." << std::endl;
765 if(debug) std::cout << std::endl;
773 GoodTestSubcount = 0;
789 N2 = N*std::abs(incx);
793 for(j = 0; j < N2; j++)
803 SType1A =
new SType1[LDA * N];
804 SType2A =
new SType2[LDA * N];
806 for(j = 0; j < N; j++)
811 for(k = 0; k < N; k++)
816 SType1A[j*LDA+k] = SType1zero;
818 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
822 while (SType1A[j*LDA+k] == SType1zero) {
825 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
827 SType1A[j*LDA+k] = SType1one;
828 SType2A[j*LDA+k] = SType2one;
835 for(k = 0; k < N; k++)
840 SType1A[j*LDA+k] = SType1zero;
842 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
846 while (SType1A[j*LDA+k] == SType1zero) {
849 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
851 SType1A[j*LDA+k] = SType1one;
852 SType2A[j*LDA+k] = SType2one;
861 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
863 PrintVector(SType1x, N2,
"SType1x_before_operation", matlab);
864 PrintMatrix(SType2A, N, N, LDA,
"SType2A", matlab);
865 PrintVector(SType2x, N2,
"SType2x_before_operation", matlab);
868 SType1BLAS.
TRMV(UPLO, TRANSA, DIAG, N, SType1A, LDA, SType1x, incx);
869 SType2BLAS.
TRMV(UPLO, TRANSA, DIAG, N, SType2A, LDA, SType2x, incx);
872 PrintVector(SType1x, N2,
"SType1x_after_operation", matlab);
873 PrintVector(SType2x, N2,
"SType2x_after_operation", matlab);
881 GoodTestCount += GoodTestSubcount;
882 if(verbose || debug) std::cout <<
"TRMV: " << GoodTestSubcount <<
" of " << TRMVTESTS <<
" tests were successful." << std::endl;
883 if(debug) std::cout << std::endl;
891 GoodTestSubcount = 0;
905 M2 = M*std::abs(incx);
906 N2 = N*std::abs(incy);
913 SType1A =
new SType1[LDA * N];
916 SType2A =
new SType2[LDA * N];
921 for(j = 0; j < LDA * N; j++)
926 for(j = 0; j < M2; j++)
931 for(j = 0; j < N2; j++)
938 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
939 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
940 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
941 PrintMatrix(SType1A, M, N, LDA,
"SType1A_before_operation", matlab);
944 PrintMatrix(SType2A, M, N, LDA,
"SType2A_before_operation", matlab);
949 SType1BLAS.
GER(M, N, SType1alpha, SType1x, incx, SType1y, incy, SType1A, LDA);
950 SType2BLAS.
GER(M, N, SType2alpha, SType2x, incx, SType2y, incy, SType2A, LDA);
953 PrintMatrix(SType1A, M, N, LDA,
"SType1A_after_operation", matlab);
954 PrintMatrix(SType2A, M, N, LDA,
"SType2A_after_operation", matlab);
964 GoodTestCount += GoodTestSubcount;
965 if(verbose || debug) std::cout <<
"GER: " << GoodTestSubcount <<
" of " << GERTESTS <<
" tests were successful." << std::endl;
966 if(debug) std::cout << std::endl;
976 GoodTestSubcount = 0;
986 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
991 SType1A =
new SType1[LDA * P];
992 SType2A =
new SType2[LDA * P];
993 for(j = 0; j < LDA * P; j++)
999 PrintMatrix(SType1A, M, P, LDA,
"SType1A", matlab);
1000 PrintMatrix(SType2A, M, P, LDA,
"SType2A", matlab);
1004 SType1A =
new SType1[LDA * M];
1005 SType2A =
new SType2[LDA * M];
1006 for(j = 0; j < LDA * M; j++)
1012 PrintMatrix(SType1A, P, M, LDA,
"SType1A", matlab);
1013 PrintMatrix(SType2A, P, M, LDA,
"SType2A", matlab);
1020 SType1B =
new SType1[LDB * N];
1021 SType2B =
new SType2[LDB * N];
1022 for(j = 0; j < LDB * N; j++)
1028 PrintMatrix(SType1B, P, N, LDB,
"SType1B", matlab);
1029 PrintMatrix(SType2B, P, N, LDB,
"SType2B", matlab);
1033 SType1B =
new SType1[LDB * P];
1034 SType2B =
new SType2[LDB * P];
1035 for(j = 0; j < LDB * P; j++)
1041 PrintMatrix(SType1B, N, P, LDB,
"SType1B", matlab);
1042 PrintMatrix(SType2B, N, P, LDB,
"SType2B", matlab);
1048 SType1C =
new SType1[LDC * N];
1049 SType2C =
new SType2[LDC * N];
1050 for(j = 0; j < LDC * N; j++) {
1056 PrintMatrix(SType1C, M, N, LDC,
"SType1C_before_operation", matlab);
1057 PrintMatrix(SType2C, M, N, LDC,
"SType2C_before_operation", matlab);
1062 SType2alpha =
ConvertType(SType1alpha, convertTo);
1066 SType1BLAS.
GEMM(TRANSA, TRANSB, M, N, P, SType1alpha, SType1A, LDA, SType1B, LDB, SType1beta, SType1C, LDC);
1067 SType2BLAS.
GEMM(TRANSA, TRANSB, M, N, P, SType2alpha, SType2A, LDA, SType2B, LDB, SType2beta, SType2C, LDC);
1070 PrintMatrix(SType1C, M, N, LDC,
"SType1C_after_operation", matlab);
1071 PrintMatrix(SType2C, M, N, LDC,
"SType2C_after_operation", matlab);
1073 GoodTestSubcount +=
CompareMatrices(SType1C, SType2C, M, N, LDC, TOL);
1081 GoodTestCount += GoodTestSubcount;
1082 if(verbose || debug) std::cout <<
"GEMM: " << GoodTestSubcount <<
" of " << GEMMTESTS <<
" tests were successful." << std::endl;
1083 if(debug) std::cout << std::endl;
1091 GoodTestSubcount = 0;
1102 SType1A =
new SType1[LDA * M];
1103 SType2A =
new SType2[LDA * M];
1104 for(j = 0; j < LDA * M; j++) {
1110 SType1A =
new SType1[LDA * N];
1111 SType2A =
new SType2[LDA * N];
1112 for(j = 0; j < LDA * N; j++) {
1120 SType1B =
new SType1[LDB * N];
1121 SType2B =
new SType2[LDB * N];
1122 for(j = 0; j < LDB * N; j++) {
1129 SType1C =
new SType1[LDC * N];
1130 SType2C =
new SType2[LDC * N];
1131 for(j = 0; j < LDC * N; j++) {
1138 SType2alpha =
ConvertType(SType1alpha, convertTo);
1142 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
1143 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
1144 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
1145 std::cout <<
"SType1beta = " << SType1beta << std::endl;
1146 std::cout <<
"SType2beta = " << SType2beta << std::endl;
1148 PrintMatrix(SType1A, M, M, LDA,
"SType1A", matlab);
1149 PrintMatrix(SType2A, M, M, LDA,
"SType2A", matlab);
1151 PrintMatrix(SType1A, N, N, LDA,
"SType1A", matlab);
1152 PrintMatrix(SType2A, N, N, LDA,
"SType2A", matlab);
1154 PrintMatrix(SType1B, M, N, LDB,
"SType1B", matlab);
1155 PrintMatrix(SType1C, M, N, LDC,
"SType1C_before_operation", matlab);
1156 PrintMatrix(SType2B, M, N, LDB,
"SType2B", matlab);
1157 PrintMatrix(SType2C, M, N, LDC,
"SType2C_before_operation", matlab);
1161 SType1BLAS.
SYMM(SIDE, UPLO, M, N, SType1alpha, SType1A, LDA, SType1B, LDB, SType1beta, SType1C, LDC);
1162 SType2BLAS.
SYMM(SIDE, UPLO, M, N, SType2alpha, SType2A, LDA, SType2B, LDB, SType2beta, SType2C, LDC);
1165 PrintMatrix(SType1C, M, N, LDC,
"SType1C_after_operation", matlab);
1166 PrintMatrix(SType2C, M, N, LDC,
"SType2C_after_operation", matlab);
1168 GoodTestSubcount +=
CompareMatrices(SType1C, SType2C, M, N, LDC, TOL);
1177 GoodTestCount += GoodTestSubcount;
1178 if(verbose || debug) std::cout <<
"SYMM: " << GoodTestSubcount <<
" of " << SYMMTESTS <<
" tests were successful." << std::endl;
1179 if(debug) std::cout << std::endl;
1187 GoodTestSubcount = 0;
1196 #ifdef HAVE_TEUCHOS_COMPLEX
1203 SType1A =
new SType1[LDA * K];
1204 SType2A =
new SType2[LDA * K];
1205 for(j = 0; j < LDA * K; j++) {
1211 SType1A =
new SType1[LDA * N];
1212 SType2A =
new SType2[LDA * N];
1213 for(j = 0; j < LDA * N; j++) {
1221 SType1C =
new SType1[LDC * N];
1222 SType2C =
new SType2[LDC * N];
1223 for(j = 0; j < N; j++) {
1228 for(k = 0; k < N; k++)
1233 SType1C[j*LDC+k] = SType1zero;
1235 SType2C[j*LDC+k] =
ConvertType(SType1C[j*LDC+k], convertTo);
1239 for(k = 0; k < N; k++)
1244 SType1C[j*LDC+k] = SType1zero;
1246 SType2C[j*LDC+k] =
ConvertType(SType1C[j*LDC+k], convertTo);
1253 SType2alpha =
ConvertType(SType1alpha, convertTo);
1257 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
1258 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
1259 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
1260 std::cout <<
"SType1beta = " << SType1beta << std::endl;
1261 std::cout <<
"SType2beta = " << SType2beta << std::endl;
1263 PrintMatrix(SType1A, N, K, LDA,
"SType1A", matlab);
1264 PrintMatrix(SType2A, N, K, LDA,
"SType2A", matlab);
1266 PrintMatrix(SType1A, K, N, LDA,
"SType1A", matlab);
1267 PrintMatrix(SType2A, K, N, LDA,
"SType2A", matlab);
1269 PrintMatrix(SType1C, N, N, LDC,
"SType1C_before_operation", matlab);
1270 PrintMatrix(SType2C, N, N, LDC,
"SType2C_before_operation", matlab);
1274 SType1BLAS.
SYRK(UPLO, TRANS, N, K, SType1alpha, SType1A, LDA, SType1beta, SType1C, LDC);
1275 SType2BLAS.
SYRK(UPLO, TRANS, N, K, SType2alpha, SType2A, LDA, SType2beta, SType2C, LDC);
1278 PrintMatrix(SType1C, N, N, LDC,
"SType1C_after_operation", matlab);
1279 PrintMatrix(SType2C, N, N, LDC,
"SType2C_after_operation", matlab);
1281 GoodTestSubcount +=
CompareMatrices(SType1C, SType2C, N, N, LDC, TOL);
1288 GoodTestCount += GoodTestSubcount;
1289 if(verbose || debug) std::cout <<
"SYRK: " << GoodTestSubcount <<
" of " << SYRKTESTS <<
" tests were successful." << std::endl;
1290 if(debug) std::cout << std::endl;
1298 GoodTestSubcount = 0;
1309 SType1B =
new SType1[LDB * N];
1310 SType2B =
new SType2[LDB * N];
1324 SType1A =
new SType1[LDA * M];
1325 SType2A =
new SType2[LDA * M];
1327 for(j = 0; j < M; j++)
1332 for(k = 0; k < M; k++)
1337 SType1A[j*LDA+k] = SType1zero;
1339 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1343 while (SType1A[j*LDA+k] == SType1zero) {
1346 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1348 SType1A[j*LDA+k] = SType1one;
1349 SType2A[j*LDA+k] = SType2one;
1356 for(k = 0; k < M; k++)
1361 SType1A[j*LDA+k] = SType1zero;
1363 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1367 while (SType1A[j*LDA+k] == SType1zero) {
1370 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1372 SType1A[j*LDA+k] = SType1one;
1373 SType2A[j*LDA+k] = SType2one;
1387 SType1A =
new SType1[LDA * N];
1388 SType2A =
new SType2[LDA * N];
1390 for(j = 0; j < N; j++)
1395 for(k = 0; k < N; k++)
1400 SType1A[j*LDA+k] = SType1zero;
1402 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1406 while (SType1A[j*LDA+k] == SType1zero) {
1409 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1411 SType1A[j*LDA+k] = SType1one;
1412 SType2A[j*LDA+k] = SType2one;
1419 for(k = 0; k < N; k++)
1424 SType1A[j*LDA+k] = SType1zero;
1426 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1430 while (SType1A[j*LDA+k] == SType1zero) {
1433 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1435 SType1A[j*LDA+k] = SType1one;
1436 SType2A[j*LDA+k] = SType2one;
1445 for(j = 0; j < N; j++) {
1446 for(k = 0; k < M; k++) {
1448 SType2B[j*LDB+k] =
ConvertType(SType1B[j*LDB+k], convertTo);
1452 SType2alpha =
ConvertType(SType1alpha, convertTo);
1455 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
1456 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
1457 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
1459 PrintMatrix(SType1A, M, M, LDA,
"SType1A", matlab);
1460 PrintMatrix(SType2A, M, M, LDA,
"SType2A", matlab);
1462 PrintMatrix(SType1A, N, N, LDA,
"SType1A", matlab);
1463 PrintMatrix(SType2A, N, N, LDA,
"SType2A", matlab);
1465 PrintMatrix(SType1B, M, N, LDB,
"SType1B_before_operation", matlab);
1466 PrintMatrix(SType2B, M, N, LDB,
"SType2B_before_operation", matlab);
1469 SType1BLAS.
TRMM(SIDE, UPLO, TRANSA, DIAG, M, N, SType1alpha, SType1A, LDA, SType1B, LDB);
1470 SType2BLAS.
TRMM(SIDE, UPLO, TRANSA, DIAG, M, N, SType2alpha, SType2A, LDA, SType2B, LDB);
1473 PrintMatrix(SType1B, M, N, LDB,
"SType1B_after_operation", matlab);
1474 PrintMatrix(SType2B, M, N, LDB,
"SType2B_after_operation", matlab);
1476 GoodTestSubcount +=
CompareMatrices(SType1B, SType2B, M, N, LDB, TOL);
1482 GoodTestCount += GoodTestSubcount;
1483 if(verbose || debug) std::cout <<
"TRMM: " << GoodTestSubcount <<
" of " << TRMMTESTS <<
" tests were successful." << std::endl;
1484 if(debug) std::cout << std::endl;
1492 GoodTestSubcount = 0;
1503 SType1B =
new SType1[LDB * N];
1504 SType2B =
new SType2[LDB * N];
1521 SType1A =
new SType1[LDA * M];
1522 SType2A =
new SType2[LDA * M];
1524 for(j = 0; j < M; j++)
1529 for(k = 0; k < M; k++)
1534 SType1A[j*LDA+k] = SType1zero;
1536 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1540 while (SType1A[j*LDA+k] == SType1zero) {
1543 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1545 SType1A[j*LDA+k] = SType1one;
1546 SType2A[j*LDA+k] = SType2one;
1553 for(k = 0; k < M; k++)
1558 SType1A[j*LDA+k] = SType1zero;
1560 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1564 while (SType1A[j*LDA+k] == SType1zero) {
1567 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1569 SType1A[j*LDA+k] = SType1one;
1570 SType2A[j*LDA+k] = SType2one;
1584 SType1A =
new SType1[LDA * N];
1585 SType2A =
new SType2[LDA * N];
1587 for(j = 0; j < N; j++)
1592 for(k = 0; k < N; k++)
1597 SType1A[j*LDA+k] = SType1zero;
1599 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1603 while (SType1A[j*LDA+k] == SType1zero) {
1606 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1608 SType1A[j*LDA+k] = SType1one;
1609 SType2A[j*LDA+k] = SType2one;
1616 for(k = 0; k < N; k++)
1621 SType1A[j*LDA+k] = SType1zero;
1623 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1627 while (SType1A[j*LDA+k] == SType1zero) {
1630 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1632 SType1A[j*LDA+k] = SType1one;
1633 SType2A[j*LDA+k] = SType2one;
1642 for(j = 0; j < N; j++)
1644 for(k = 0; k < M; k++)
1647 SType2B[j*LDB+k] =
ConvertType(SType1B[j*LDB+k], convertTo);
1652 SType2alpha =
ConvertType(SType1alpha, convertTo);
1656 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
1661 std::cout <<
"M="<<M <<
"\t" <<
"N="<<N <<
"\t" <<
"LDA="<<LDA <<
"\t" <<
"LDB="<<LDB << std::endl;
1662 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
1663 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
1665 PrintMatrix(SType1A, M, M, LDA,
"SType1A", matlab);
1666 PrintMatrix(SType2A, M, M, LDA,
"SType2A", matlab);
1668 PrintMatrix(SType1A, N, N, LDA,
"SType1A", matlab);
1669 PrintMatrix(SType2A, N, N, LDA,
"SType2A", matlab);
1671 PrintMatrix(SType1B, M, N, LDB,
"SType1B_before_operation", matlab);
1672 PrintMatrix(SType2B, M, N, LDB,
"SType2B_before_operation", matlab);
1676 SType1BLAS.
TRSM(SIDE, UPLO, TRANSA, DIAG, M, N, SType1alpha, SType1A, LDA, SType1B, LDB);
1677 SType2BLAS.
TRSM(SIDE, UPLO, TRANSA, DIAG, M, N, SType2alpha, SType2A, LDA, SType2B, LDB);
1681 PrintMatrix(SType1B, M, N, LDB,
"SType1B_after_operation", matlab);
1682 PrintMatrix(SType2B, M, N, LDB,
"SType2B_after_operation", matlab);
1686 std::cout <<
"FAILED TEST!!!!!!" << std::endl;
1687 GoodTestSubcount +=
CompareMatrices(SType1B, SType2B, M, N, LDB, TOL);
1694 GoodTestCount += GoodTestSubcount;
1695 if(verbose || debug) std::cout <<
"TRSM: " << GoodTestSubcount <<
" of " << TRSMTESTS <<
" tests were successful." << std::endl;
1696 if(debug) std::cout << std::endl;
1701 if((((TotalTestCount - 1) - GoodTestCount) != 0) || (verbose) || (debug))
1703 std::cout << GoodTestCount <<
" of " << (TotalTestCount - 1) <<
" total tests were successful." << std::endl;
1706 if ((TotalTestCount-1) == GoodTestCount) {
1707 std::cout <<
"End Result: TEST PASSED" << std::endl;
1711 std::cout <<
"End Result: TEST FAILED" << std::endl;
1712 return (TotalTestCount-GoodTestCount-1);
1715 template<
typename TYPE>
1728 double GetRandom(
double Low,
double High)
1733 template<
typename TYPE>
1736 std::cout << Name <<
" =" << std::endl;
1738 if(Matlab) std::cout <<
"[";
1739 for(i = 0; i < Size; i++)
1741 std::cout << Vector[i] <<
" ";
1743 if(Matlab) std::cout <<
"]";
1746 std::cout << std::endl << std::endl;
1750 std::cout <<
";" << std::endl;
1754 template<
typename TYPE>
1759 std::cout << Name <<
" =" << std::endl;
1761 for(i = 0; i < Rows; i++)
1763 for(j = 0; j < Columns; j++)
1765 std::cout << Matrix[i + (j * LDM)] <<
" ";
1767 std::cout << std::endl;
1769 std::cout << std::endl;
1773 std::cout << Name <<
" = ";
1776 for(i = 0; i < Rows; i++)
1779 for(j = 0; j < Columns; j++)
1781 std::cout << Matrix[i + (j * LDM)] <<
" ";
1785 std::cout <<
"];" << std::endl;
1789 template<
typename TYPE1,
typename TYPE2>
1798 return( temp2 < Tolerance );
1805 template<
typename TYPE1,
typename TYPE2>
1815 for(i = 0; i < Size; i++)
1818 temp =
ConvertType(Vector1[i], convertTo) - Vector2[i];
1826 if (temp3 > Tolerance )
1835 template<
typename TYPE1,
typename TYPE2>
1845 for(j = 0; j < Columns; j++)
1847 for(i = 0; i < Rows; i++)
1850 temp =
ConvertType(Matrix1[j*LDM + i],convertTo) - Matrix2[j*LDM + i];
1859 if (temp3 > Tolerance)
1866 template<
typename TYPE1,
typename TYPE2>
1869 return static_cast<TYPE2
>(T1);
1906 if(r == 1 || r == 2)
void TRSM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, ScalarType *B, const OrdinalType &ldb) const
Solves the matrix equations: op(A)*X=alpha*B or X*op(A)=alpha*B where X and B are m by n matrices...
void GER(const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const x_type *x, const OrdinalType &incx, const y_type *y, const OrdinalType &incy, ScalarType *A, const OrdinalType &lda) const
Performs the rank 1 operation: A <- alpha*x*y'+A.
void AXPY(const OrdinalType &n, const alpha_type alpha, const x_type *x, const OrdinalType &incx, ScalarType *y, const OrdinalType &incy) const
Perform the operation: y <- y+alpha*x.
T magnitudeType
Mandatory typedef for result of magnitude.
void TRMV(EUplo uplo, ETransp trans, EDiag diag, const OrdinalType &n, const A_type *A, const OrdinalType &lda, ScalarType *x, const OrdinalType &incx) const
Performs the matrix-vector operation: x <- A*x or x <- A'*x where A is a unit/non-unit n by n upper/low...
Templated interface class to BLAS routines.
void GEMV(ETransp trans, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const x_type *x, const OrdinalType &incx, const beta_type beta, ScalarType *y, const OrdinalType &incy) const
Performs the matrix-vector operation: y <- alpha*A*x+beta*y or y <- alpha*A'*x+beta*y where A is a gene...
void ROT(const OrdinalType &n, ScalarType *dx, const OrdinalType &incx, ScalarType *dy, const OrdinalType &incy, MagnitudeType *c, ScalarType *s) const
Applies a Givens plane rotation.
Basic wall-clock timer class.
ScalarTraits< ScalarType >::magnitudeType NRM2(const OrdinalType &n, const ScalarType *x, const OrdinalType &incx) const
Compute the 2-norm of the vector x.
OrdinalType IAMAX(const OrdinalType &n, const ScalarType *x, const OrdinalType &incx) const
Return the index of the element of x with the maximum magnitude.
void GEMM(ETransp transa, ETransp transb, const OrdinalType &m, const OrdinalType &n, const OrdinalType &k, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const B_type *B, const OrdinalType &ldb, const beta_type beta, ScalarType *C, const OrdinalType &ldc) const
General matrix-matrix multiply.
void PrintMatrix(TYPE *Matrix, OType Rows, OType Columns, OType LDM, std::string Name, bool Matlab=0)
Initialize, finalize, and query the global MPI session.
TEUCHOSNUMERICS_LIB_DLL_EXPORT const char EDiagChar[]
This structure defines some basic traits for a scalar field type.
ScalarTraits< ScalarType >::magnitudeType ASUM(const OrdinalType &n, const ScalarType *x, const OrdinalType &incx) const
Sum the absolute values of the entries of x.
Teuchos::EUplo RandomUPLO()
void COPY(const OrdinalType &n, const ScalarType *x, const OrdinalType &incx, ScalarType *y, const OrdinalType &incy) const
Copy the vector x to the vector y.
TYPE GetRandom(TYPE, TYPE)
Teuchos::ESide RandomSIDE()
TEUCHOSNUMERICS_LIB_DLL_EXPORT const char EUploChar[]
Teuchos::EDiag RandomDIAG()
ScalarType DOT(const OrdinalType &n, const x_type *x, const OrdinalType &incx, const y_type *y, const OrdinalType &incy) const
Form the dot product of the vectors x and y.
bool CompareVectors(TYPE1 *Vector1, TYPE2 *Vector2, OType Size, TYPE2 Tolerance)
bool CompareScalars(TYPE1 Scalar1, TYPE2 Scalar2, TYPE2 Tolerance)
TEUCHOSNUMERICS_LIB_DLL_EXPORT const char ESideChar[]
std::string Teuchos_Version()
void PrintVector(TYPE *Vector, OType Size, std::string Name, bool Matlab=0)
int main(int argc, char *argv[])
bool CompareMatrices(TYPE1 *Matrix1, TYPE2 *Matrix2, OType Rows, OType Columns, OType LDM, TYPE2 Tolerance)
TYPE2 ConvertType(TYPE1, TYPE2)
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
void SYMM(ESide side, EUplo uplo, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const B_type *B, const OrdinalType &ldb, const beta_type beta, ScalarType *C, const OrdinalType &ldc) const
Performs the matrix-matrix operation: C <- alpha*A*B+beta*C or C <- alpha*B*A+beta*C where A is an m ...
void TRMM(ESide side, EUplo uplo, ETransp transa, EDiag diag, const OrdinalType &m, const OrdinalType &n, const alpha_type alpha, const A_type *A, const OrdinalType &lda, ScalarType *B, const OrdinalType &ldb) const
Performs the matrix-matrix operation: B <- alpha*op(A)*B or B <- alpha*B*op(A) where op(A) is an unit...
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
void SCAL(const OrdinalType &n, const ScalarType &alpha, ScalarType *x, const OrdinalType &incx) const
Scale the vector x by the constant alpha.
void ROTG(ScalarType *da, ScalarType *db, rotg_c_type *c, ScalarType *s) const
Computes a Givens plane rotation.
TEUCHOSNUMERICS_LIB_DLL_EXPORT const char ETranspChar[]
void SYRK(EUplo uplo, ETransp trans, const OrdinalType &n, const OrdinalType &k, const alpha_type alpha, const A_type *A, const OrdinalType &lda, const beta_type beta, ScalarType *C, const OrdinalType &ldc) const
Performs the symmetric rank k operation: C <- alpha*A*A'+beta*C or C <- alpha*A'*A+beta*C, where alpha and beta are scalars, C is an n by n symmetric matrix and A is an n by k matrix in the first case or k by n matrix in the second case.
Teuchos::ETransp RandomTRANS()