66 #ifdef HAVE_TEUCHOS_COMPLEX
67 #define SType1 std::complex<float>
73 #ifdef HAVE_TEUCHOS_COMPLEX
74 #define SType2 std::complex<double>
80 #define OType long int
111 template<
typename TYPE>
122 template<
typename TYPE>
123 void PrintVector(TYPE* Vector,
OType Size, std::string Name,
bool Matlab = 0);
125 template<
typename TYPE>
128 template<
typename TYPE1,
typename TYPE2>
131 template<
typename TYPE1,
typename TYPE2>
134 template<
typename TYPE1,
typename TYPE2>
139 template<
typename TYPE1,
typename TYPE2>
148 int main(
int argc,
char *argv[])
154 bool InvalidCmdLineArgs = 0;
156 for(i = 1; i < argc; i++)
158 if(argv[i][0] ==
'-')
169 InvalidCmdLineArgs = 1;
179 InvalidCmdLineArgs = 1;
189 InvalidCmdLineArgs = 1;
193 InvalidCmdLineArgs = 1;
202 if(InvalidCmdLineArgs || (argc > 4))
204 std::cout <<
"Invalid command line arguments detected. Use the following flags:" << std::endl
205 <<
"\t -v enables verbose mode (reports number of failed/successful tests)" << std::endl
206 <<
"\t -d enables debug mode (same as verbose with output of each test, not recommended for large numbers of tests)" << std::endl
207 <<
"\t -m enables matlab-style output; only has an effect if debug mode is enabled" << std::endl;
222 SType1 SType1alpha, SType1beta;
228 SType2 SType2alpha, SType2beta;
229 SType1 SType1ASUMresult, SType1DOTresult, SType1NRM2result, SType1SINresult;
230 SType2 SType2ASUMresult, SType2DOTresult, SType2NRM2result, SType2SINresult;
231 MType1 SType1COSresult;
232 MType2 SType2COSresult;
234 OType SType1IAMAXresult;
235 OType SType2IAMAXresult;
236 OType TotalTestCount = 1, GoodTestSubcount, GoodTestCount = 0, M, M2, N, N2, P, K, LDA, LDB, LDC, Mx, My;
245 std::srand(time(NULL));
252 GoodTestSubcount = 0;
262 SType2SINresult =
ConvertType(SType1SINresult, convertTo);
266 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
267 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
268 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
269 std::cout <<
"SType1beta = " << SType1beta << std::endl;
270 std::cout <<
"SType2beta = " << SType2beta << std::endl;
273 SType1BLAS.
ROTG(&SType1alpha, &SType1beta, &SType1COSresult, &SType1SINresult);
274 SType2BLAS.
ROTG(&SType2alpha, &SType2beta, &SType2COSresult, &SType2SINresult);
277 std::cout <<
"SType1 ROTG COS result: " << SType1COSresult << std::endl;
278 std::cout <<
"SType2 ROTG COS result: " << SType2COSresult << std::endl;
279 std::cout <<
"SType1 ROTG SIN result: " << SType1SINresult << std::endl;
280 std::cout <<
"SType2 ROTG SIN result: " << SType2SINresult << std::endl;
282 GoodTestSubcount += (
CompareScalars(SType1COSresult, SType2COSresult, TOL) &&
285 GoodTestCount += GoodTestSubcount;
286 if(verbose || debug) std::cout <<
"ROTG: " << GoodTestSubcount <<
" of " << ROTGTESTS <<
" tests were successful." << std::endl;
287 if(debug) std::cout << std::endl;
297 GoodTestSubcount = 0;
302 if (incx == 0) incx = 1;
303 if (incy == 0) incy = 1;
305 Mx = M*std::abs(incx);
306 My = M*std::abs(incy);
307 if (Mx == 0) { Mx = 1; }
308 if (My == 0) { My = 1; }
313 for(j = 0; j < Mx; j++)
318 for(j = 0; j < My; j++)
329 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
330 std::cout <<
"c1 = " << c1 <<
", s1 = " << s1 << std::endl;
331 std::cout <<
"c2 = " << c2 <<
", s2 = " << s2 << std::endl;
332 std::cout <<
"incx = " << incx <<
", incy = " << incy << std::endl;
334 PrintVector(SType1y, My,
"SType1y_before_operation", matlab);
336 PrintVector(SType2y, My,
"SType2y_before_operation", matlab);
339 SType1BLAS.
ROT(M, SType1x, incx, SType1y, incy, &c1, &s1);
340 SType2BLAS.
ROT(M, SType2x, incx, SType2y, incy, &c2, &s2);
343 PrintVector(SType1y, My,
"SType1y_after_operation", matlab);
344 PrintVector(SType2y, My,
"SType2y_after_operation", matlab);
346 GoodTestSubcount += (
CompareVectors(SType1x, SType2x, Mx, TOL) &&
353 GoodTestCount += GoodTestSubcount;
354 if(verbose || debug) std::cout <<
"ROT: " << GoodTestSubcount <<
" of " << ROTTESTS <<
" tests were successful." << std::endl;
355 if(debug) std::cout << std::endl;
363 GoodTestSubcount = 0;
372 for(j = 0; j < M2; j++)
379 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
384 SType1ASUMresult = SType1BLAS.
ASUM(M, SType1x, incx);
385 SType2ASUMresult = SType2BLAS.
ASUM(M, SType2x, incx);
388 std::cout <<
"SType1 ASUM result: " << SType1ASUMresult << std::endl;
389 std::cout <<
"SType2 ASUM result: " << SType2ASUMresult << std::endl;
391 GoodTestSubcount +=
CompareScalars(SType1ASUMresult, SType2ASUMresult, TOL);
395 GoodTestCount += GoodTestSubcount;
396 if(verbose || debug) std::cout <<
"ASUM: " << GoodTestSubcount <<
" of " << ASUMTESTS <<
" tests were successful." << std::endl;
397 if(debug) std::cout << std::endl;
406 GoodTestSubcount = 0;
412 Mx = M*std::abs(incx);
413 My = M*std::abs(incy);
414 if (Mx == 0) { Mx = 1; }
415 if (My == 0) { My = 1; }
420 for(j = 0; j < Mx; j++)
425 for(j = 0; j < My; j++)
434 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
435 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
436 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
438 PrintVector(SType1y, My,
"SType1y_before_operation", matlab);
440 PrintVector(SType2y, My,
"SType2y_before_operation", matlab);
443 SType1BLAS.
AXPY(M, SType1alpha, SType1x, incx, SType1y, incy);
444 SType2BLAS.
AXPY(M, SType2alpha, SType2x, incx, SType2y, incy);
447 PrintVector(SType1y, My,
"SType1y_after_operation", matlab);
448 PrintVector(SType2y, My,
"SType2y_after_operation", matlab);
456 GoodTestCount += GoodTestSubcount;
457 if(verbose || debug) std::cout <<
"AXPY: " << GoodTestSubcount <<
" of " << AXPYTESTS <<
" tests were successful." << std::endl;
458 if(debug) std::cout << std::endl;
466 GoodTestSubcount = 0;
472 Mx = M*std::abs(incx);
473 My = M*std::abs(incy);
474 if (Mx == 0) { Mx = 1; }
475 if (My == 0) { My = 1; }
480 for(j = 0; j < Mx; j++)
485 for(j = 0; j < My; j++)
492 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
494 PrintVector(SType1y, My,
"SType1y_before_operation", matlab);
496 PrintVector(SType2y, My,
"SType2y_before_operation", matlab);
499 SType1BLAS.
COPY(M, SType1x, incx, SType1y, incy);
500 SType2BLAS.
COPY(M, SType2x, incx, SType2y, incy);
503 PrintVector(SType1y, My,
"SType1y_after_operation", matlab);
504 PrintVector(SType2y, My,
"SType2y_after_operation", matlab);
512 GoodTestCount += GoodTestSubcount;
if(verbose || debug) std::cout <<
"COPY: " << GoodTestSubcount <<
" of " << COPYTESTS <<
" tests were successful." << std::endl;
513 if(debug) std::cout << std::endl;
521 GoodTestSubcount = 0;
527 Mx = M*std::abs(incx);
528 My = M*std::abs(incy);
529 if (Mx == 0) { Mx = 1; }
530 if (My == 0) { My = 1; }
535 for(j = 0; j < Mx; j++)
540 for(j = 0; j < My; j++)
547 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
554 SType1DOTresult = SType1BLAS.
DOT(M, SType1x, incx, SType1y, incy);
555 SType2DOTresult = SType2BLAS.
DOT(M, SType2x, incx, SType2y, incy);
558 std::cout <<
"SType1 DOT result: " << SType1DOTresult << std::endl;
559 std::cout <<
"SType2 DOT result: " << SType2DOTresult << std::endl;
561 GoodTestSubcount +=
CompareScalars(SType1DOTresult, SType2DOTresult, TOL);
567 GoodTestCount += GoodTestSubcount;
568 if(verbose || debug) std::cout <<
"DOT: " << GoodTestSubcount <<
" of " << DOTTESTS <<
" tests were successful." << std::endl;
569 if(debug) std::cout << std::endl;
577 GoodTestSubcount = 0;
585 for(j = 0; j < M2; j++)
592 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
597 SType1NRM2result = SType1BLAS.
NRM2(M, SType1x, incx);
598 SType2NRM2result = SType2BLAS.
NRM2(M, SType2x, incx);
601 std::cout <<
"SType1 NRM2 result: " << SType1NRM2result << std::endl;
602 std::cout <<
"SType2 NRM2 result: " << SType2NRM2result << std::endl;
604 GoodTestSubcount +=
CompareScalars(SType1NRM2result, SType2NRM2result, TOL);
608 GoodTestCount += GoodTestSubcount;
if(verbose || debug) std::cout <<
"NRM2: " << GoodTestSubcount <<
" of " << NRM2TESTS <<
" tests were successful." << std::endl;
609 if(debug) std::cout << std::endl;
617 GoodTestSubcount = 0;
628 for(j = 0; j < M2; j++)
637 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
638 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
639 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
640 PrintVector(SType1x, M2,
"SType1x_before_operation", matlab);
641 PrintVector(SType2x, M2,
"SType2x_before_operation", matlab);
644 SType1BLAS.
SCAL(M, SType1alpha, SType1x, incx);
645 SType2BLAS.
SCAL(M, SType2alpha, SType2x, incx);
648 PrintVector(SType1x, M2,
"SType1x_after_operation", matlab);
649 PrintVector(SType2x, M2,
"SType2x_after_operation", matlab);
655 GoodTestCount += GoodTestSubcount;
656 if(verbose || debug) std::cout <<
"SCAL: " << GoodTestSubcount <<
" of " << SCALTESTS <<
" tests were successful." << std::endl;
657 if(debug) std::cout << std::endl;
665 GoodTestSubcount = 0;
673 for(j = 0; j < M2; j++)
680 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
685 SType1IAMAXresult = SType1BLAS.
IAMAX(M, SType1x, incx);
686 SType2IAMAXresult = SType2BLAS.
IAMAX(M, SType2x, incx);
689 std::cout <<
"SType1 IAMAX result: " << SType1IAMAXresult << std::endl;
690 std::cout <<
"SType2 IAMAX result: " << SType2IAMAXresult << std::endl;
692 GoodTestSubcount += (SType1IAMAXresult == SType2IAMAXresult);
696 GoodTestCount += GoodTestSubcount;
697 if(verbose || debug) std::cout <<
"IAMAX: " << GoodTestSubcount <<
" of " << IAMAXTESTS <<
" tests were successful." << std::endl;
698 if(debug) std::cout << std::endl;
708 GoodTestSubcount = 0;
726 M2 = M*std::abs(incy);
727 N2 = N*std::abs(incx);
729 M2 = N*std::abs(incy);
730 N2 = M*std::abs(incx);
743 SType1A =
new SType1[LDA * N];
746 SType2A =
new SType2[LDA * N];
750 for(j = 0; j < LDA * N; j++)
755 for(j = 0; j < N2; j++)
760 for(j = 0; j < M2; j++)
767 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
768 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
769 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
770 std::cout <<
"SType1beta = " << SType1beta << std::endl;
771 std::cout <<
"SType2beta = " << SType2beta << std::endl;
772 PrintMatrix(SType1A, M, N, LDA,
"SType1A", matlab);
774 PrintVector(SType1y, M2,
"SType1y_before_operation", matlab);
775 PrintMatrix(SType2A, M, N, LDA,
"SType2A", matlab);
777 PrintVector(SType2y, M2,
"SType2y_before_operation", matlab);
780 SType1BLAS.
GEMV(TRANS, M, N, SType1alpha, SType1A, LDA, SType1x, incx, SType1beta, SType1y, incy);
781 SType2BLAS.
GEMV(TRANS, M, N, SType2alpha, SType2A, LDA, SType2x, incx, SType2beta, SType2y, incy);
784 PrintVector(SType1y, M2,
"SType1y_after_operation", matlab);
785 PrintVector(SType2y, M2,
"SType2y_after_operation", matlab);
795 GoodTestCount += GoodTestSubcount;
796 if(verbose || debug) std::cout <<
"GEMV: " << GoodTestSubcount <<
" of " << GEMVTESTS <<
" tests were successful." << std::endl;
797 if(debug) std::cout << std::endl;
805 GoodTestSubcount = 0;
821 N2 = N*std::abs(incx);
825 for(j = 0; j < N2; j++)
835 SType1A =
new SType1[LDA * N];
836 SType2A =
new SType2[LDA * N];
838 for(j = 0; j < N; j++)
843 for(k = 0; k < N; k++)
848 SType1A[j*LDA+k] = SType1zero;
850 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
854 while (SType1A[j*LDA+k] == SType1zero) {
857 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
859 SType1A[j*LDA+k] = SType1one;
860 SType2A[j*LDA+k] = SType2one;
867 for(k = 0; k < N; k++)
872 SType1A[j*LDA+k] = SType1zero;
874 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
878 while (SType1A[j*LDA+k] == SType1zero) {
881 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
883 SType1A[j*LDA+k] = SType1one;
884 SType2A[j*LDA+k] = SType2one;
893 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
895 PrintVector(SType1x, N2,
"SType1x_before_operation", matlab);
896 PrintMatrix(SType2A, N, N, LDA,
"SType2A", matlab);
897 PrintVector(SType2x, N2,
"SType2x_before_operation", matlab);
900 SType1BLAS.
TRMV(UPLO, TRANSA, DIAG, N, SType1A, LDA, SType1x, incx);
901 SType2BLAS.
TRMV(UPLO, TRANSA, DIAG, N, SType2A, LDA, SType2x, incx);
904 PrintVector(SType1x, N2,
"SType1x_after_operation", matlab);
905 PrintVector(SType2x, N2,
"SType2x_after_operation", matlab);
913 GoodTestCount += GoodTestSubcount;
914 if(verbose || debug) std::cout <<
"TRMV: " << GoodTestSubcount <<
" of " << TRMVTESTS <<
" tests were successful." << std::endl;
915 if(debug) std::cout << std::endl;
923 GoodTestSubcount = 0;
937 M2 = M*std::abs(incx);
938 N2 = N*std::abs(incy);
945 SType1A =
new SType1[LDA * N];
948 SType2A =
new SType2[LDA * N];
953 for(j = 0; j < LDA * N; j++)
958 for(j = 0; j < M2; j++)
963 for(j = 0; j < N2; j++)
970 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
971 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
972 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
973 PrintMatrix(SType1A, M, N, LDA,
"SType1A_before_operation", matlab);
976 PrintMatrix(SType2A, M, N, LDA,
"SType2A_before_operation", matlab);
981 SType1BLAS.
GER(M, N, SType1alpha, SType1x, incx, SType1y, incy, SType1A, LDA);
982 SType2BLAS.
GER(M, N, SType2alpha, SType2x, incx, SType2y, incy, SType2A, LDA);
985 PrintMatrix(SType1A, M, N, LDA,
"SType1A_after_operation", matlab);
986 PrintMatrix(SType2A, M, N, LDA,
"SType2A_after_operation", matlab);
996 GoodTestCount += GoodTestSubcount;
997 if(verbose || debug) std::cout <<
"GER: " << GoodTestSubcount <<
" of " << GERTESTS <<
" tests were successful." << std::endl;
998 if(debug) std::cout << std::endl;
1008 GoodTestSubcount = 0;
1018 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
1023 SType1A =
new SType1[LDA * P];
1024 SType2A =
new SType2[LDA * P];
1025 for(j = 0; j < LDA * P; j++)
1031 PrintMatrix(SType1A, M, P, LDA,
"SType1A", matlab);
1032 PrintMatrix(SType2A, M, P, LDA,
"SType2A", matlab);
1036 SType1A =
new SType1[LDA * M];
1037 SType2A =
new SType2[LDA * M];
1038 for(j = 0; j < LDA * M; j++)
1044 PrintMatrix(SType1A, P, M, LDA,
"SType1A", matlab);
1045 PrintMatrix(SType2A, P, M, LDA,
"SType2A", matlab);
1052 SType1B =
new SType1[LDB * N];
1053 SType2B =
new SType2[LDB * N];
1054 for(j = 0; j < LDB * N; j++)
1060 PrintMatrix(SType1B, P, N, LDB,
"SType1B", matlab);
1061 PrintMatrix(SType2B, P, N, LDB,
"SType2B", matlab);
1065 SType1B =
new SType1[LDB * P];
1066 SType2B =
new SType2[LDB * P];
1067 for(j = 0; j < LDB * P; j++)
1073 PrintMatrix(SType1B, N, P, LDB,
"SType1B", matlab);
1074 PrintMatrix(SType2B, N, P, LDB,
"SType2B", matlab);
1080 SType1C =
new SType1[LDC * N];
1081 SType2C =
new SType2[LDC * N];
1082 for(j = 0; j < LDC * N; j++) {
1088 PrintMatrix(SType1C, M, N, LDC,
"SType1C_before_operation", matlab);
1089 PrintMatrix(SType2C, M, N, LDC,
"SType2C_before_operation", matlab);
1094 SType2alpha =
ConvertType(SType1alpha, convertTo);
1098 SType1BLAS.
GEMM(TRANSA, TRANSB, M, N, P, SType1alpha, SType1A, LDA, SType1B, LDB, SType1beta, SType1C, LDC);
1099 SType2BLAS.
GEMM(TRANSA, TRANSB, M, N, P, SType2alpha, SType2A, LDA, SType2B, LDB, SType2beta, SType2C, LDC);
1102 PrintMatrix(SType1C, M, N, LDC,
"SType1C_after_operation", matlab);
1103 PrintMatrix(SType2C, M, N, LDC,
"SType2C_after_operation", matlab);
1105 GoodTestSubcount +=
CompareMatrices(SType1C, SType2C, M, N, LDC, TOL);
1113 GoodTestCount += GoodTestSubcount;
1114 if(verbose || debug) std::cout <<
"GEMM: " << GoodTestSubcount <<
" of " << GEMMTESTS <<
" tests were successful." << std::endl;
1115 if(debug) std::cout << std::endl;
1123 GoodTestSubcount = 0;
1134 SType1A =
new SType1[LDA * M];
1135 SType2A =
new SType2[LDA * M];
1136 for(j = 0; j < LDA * M; j++) {
1142 SType1A =
new SType1[LDA * N];
1143 SType2A =
new SType2[LDA * N];
1144 for(j = 0; j < LDA * N; j++) {
1152 SType1B =
new SType1[LDB * N];
1153 SType2B =
new SType2[LDB * N];
1154 for(j = 0; j < LDB * N; j++) {
1161 SType1C =
new SType1[LDC * N];
1162 SType2C =
new SType2[LDC * N];
1163 for(j = 0; j < LDC * N; j++) {
1170 SType2alpha =
ConvertType(SType1alpha, convertTo);
1174 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
1175 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
1176 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
1177 std::cout <<
"SType1beta = " << SType1beta << std::endl;
1178 std::cout <<
"SType2beta = " << SType2beta << std::endl;
1180 PrintMatrix(SType1A, M, M, LDA,
"SType1A", matlab);
1181 PrintMatrix(SType2A, M, M, LDA,
"SType2A", matlab);
1183 PrintMatrix(SType1A, N, N, LDA,
"SType1A", matlab);
1184 PrintMatrix(SType2A, N, N, LDA,
"SType2A", matlab);
1186 PrintMatrix(SType1B, M, N, LDB,
"SType1B", matlab);
1187 PrintMatrix(SType1C, M, N, LDC,
"SType1C_before_operation", matlab);
1188 PrintMatrix(SType2B, M, N, LDB,
"SType2B", matlab);
1189 PrintMatrix(SType2C, M, N, LDC,
"SType2C_before_operation", matlab);
1193 SType1BLAS.
SYMM(SIDE, UPLO, M, N, SType1alpha, SType1A, LDA, SType1B, LDB, SType1beta, SType1C, LDC);
1194 SType2BLAS.
SYMM(SIDE, UPLO, M, N, SType2alpha, SType2A, LDA, SType2B, LDB, SType2beta, SType2C, LDC);
1197 PrintMatrix(SType1C, M, N, LDC,
"SType1C_after_operation", matlab);
1198 PrintMatrix(SType2C, M, N, LDC,
"SType2C_after_operation", matlab);
1200 GoodTestSubcount +=
CompareMatrices(SType1C, SType2C, M, N, LDC, TOL);
1209 GoodTestCount += GoodTestSubcount;
1210 if(verbose || debug) std::cout <<
"SYMM: " << GoodTestSubcount <<
" of " << SYMMTESTS <<
" tests were successful." << std::endl;
1211 if(debug) std::cout << std::endl;
1219 GoodTestSubcount = 0;
1228 #ifdef HAVE_TEUCHOS_COMPLEX
1235 SType1A =
new SType1[LDA * K];
1236 SType2A =
new SType2[LDA * K];
1237 for(j = 0; j < LDA * K; j++) {
1243 SType1A =
new SType1[LDA * N];
1244 SType2A =
new SType2[LDA * N];
1245 for(j = 0; j < LDA * N; j++) {
1253 SType1C =
new SType1[LDC * N];
1254 SType2C =
new SType2[LDC * N];
1255 for(j = 0; j < N; j++) {
1260 for(k = 0; k < N; k++)
1265 SType1C[j*LDC+k] = SType1zero;
1267 SType2C[j*LDC+k] =
ConvertType(SType1C[j*LDC+k], convertTo);
1271 for(k = 0; k < N; k++)
1276 SType1C[j*LDC+k] = SType1zero;
1278 SType2C[j*LDC+k] =
ConvertType(SType1C[j*LDC+k], convertTo);
1285 SType2alpha =
ConvertType(SType1alpha, convertTo);
1289 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
1290 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
1291 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
1292 std::cout <<
"SType1beta = " << SType1beta << std::endl;
1293 std::cout <<
"SType2beta = " << SType2beta << std::endl;
1295 PrintMatrix(SType1A, N, K, LDA,
"SType1A", matlab);
1296 PrintMatrix(SType2A, N, K, LDA,
"SType2A", matlab);
1298 PrintMatrix(SType1A, K, N, LDA,
"SType1A", matlab);
1299 PrintMatrix(SType2A, K, N, LDA,
"SType2A", matlab);
1301 PrintMatrix(SType1C, N, N, LDC,
"SType1C_before_operation", matlab);
1302 PrintMatrix(SType2C, N, N, LDC,
"SType2C_before_operation", matlab);
1306 SType1BLAS.
SYRK(UPLO, TRANS, N, K, SType1alpha, SType1A, LDA, SType1beta, SType1C, LDC);
1307 SType2BLAS.
SYRK(UPLO, TRANS, N, K, SType2alpha, SType2A, LDA, SType2beta, SType2C, LDC);
1310 PrintMatrix(SType1C, N, N, LDC,
"SType1C_after_operation", matlab);
1311 PrintMatrix(SType2C, N, N, LDC,
"SType2C_after_operation", matlab);
1313 GoodTestSubcount +=
CompareMatrices(SType1C, SType2C, N, N, LDC, TOL);
1320 GoodTestCount += GoodTestSubcount;
1321 if(verbose || debug) std::cout <<
"SYRK: " << GoodTestSubcount <<
" of " << SYRKTESTS <<
" tests were successful." << std::endl;
1322 if(debug) std::cout << std::endl;
1330 GoodTestSubcount = 0;
1341 SType1B =
new SType1[LDB * N];
1342 SType2B =
new SType2[LDB * N];
1356 SType1A =
new SType1[LDA * M];
1357 SType2A =
new SType2[LDA * M];
1359 for(j = 0; j < M; j++)
1364 for(k = 0; k < M; k++)
1369 SType1A[j*LDA+k] = SType1zero;
1371 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1375 while (SType1A[j*LDA+k] == SType1zero) {
1378 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1380 SType1A[j*LDA+k] = SType1one;
1381 SType2A[j*LDA+k] = SType2one;
1388 for(k = 0; k < M; k++)
1393 SType1A[j*LDA+k] = SType1zero;
1395 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1399 while (SType1A[j*LDA+k] == SType1zero) {
1402 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1404 SType1A[j*LDA+k] = SType1one;
1405 SType2A[j*LDA+k] = SType2one;
1419 SType1A =
new SType1[LDA * N];
1420 SType2A =
new SType2[LDA * N];
1422 for(j = 0; j < N; j++)
1427 for(k = 0; k < N; k++)
1432 SType1A[j*LDA+k] = SType1zero;
1434 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1438 while (SType1A[j*LDA+k] == SType1zero) {
1441 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1443 SType1A[j*LDA+k] = SType1one;
1444 SType2A[j*LDA+k] = SType2one;
1451 for(k = 0; k < N; k++)
1456 SType1A[j*LDA+k] = SType1zero;
1458 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1462 while (SType1A[j*LDA+k] == SType1zero) {
1465 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1467 SType1A[j*LDA+k] = SType1one;
1468 SType2A[j*LDA+k] = SType2one;
1477 for(j = 0; j < N; j++) {
1478 for(k = 0; k < M; k++) {
1480 SType2B[j*LDB+k] =
ConvertType(SType1B[j*LDB+k], convertTo);
1484 SType2alpha =
ConvertType(SType1alpha, convertTo);
1487 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
1488 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
1489 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
1491 PrintMatrix(SType1A, M, M, LDA,
"SType1A", matlab);
1492 PrintMatrix(SType2A, M, M, LDA,
"SType2A", matlab);
1494 PrintMatrix(SType1A, N, N, LDA,
"SType1A", matlab);
1495 PrintMatrix(SType2A, N, N, LDA,
"SType2A", matlab);
1497 PrintMatrix(SType1B, M, N, LDB,
"SType1B_before_operation", matlab);
1498 PrintMatrix(SType2B, M, N, LDB,
"SType2B_before_operation", matlab);
1501 SType1BLAS.
TRMM(SIDE, UPLO, TRANSA, DIAG, M, N, SType1alpha, SType1A, LDA, SType1B, LDB);
1502 SType2BLAS.
TRMM(SIDE, UPLO, TRANSA, DIAG, M, N, SType2alpha, SType2A, LDA, SType2B, LDB);
1505 PrintMatrix(SType1B, M, N, LDB,
"SType1B_after_operation", matlab);
1506 PrintMatrix(SType2B, M, N, LDB,
"SType2B_after_operation", matlab);
1508 GoodTestSubcount +=
CompareMatrices(SType1B, SType2B, M, N, LDB, TOL);
1514 GoodTestCount += GoodTestSubcount;
1515 if(verbose || debug) std::cout <<
"TRMM: " << GoodTestSubcount <<
" of " << TRMMTESTS <<
" tests were successful." << std::endl;
1516 if(debug) std::cout << std::endl;
1524 GoodTestSubcount = 0;
1535 SType1B =
new SType1[LDB * N];
1536 SType2B =
new SType2[LDB * N];
1553 SType1A =
new SType1[LDA * M];
1554 SType2A =
new SType2[LDA * M];
1556 for(j = 0; j < M; j++)
1561 for(k = 0; k < M; k++)
1566 SType1A[j*LDA+k] = SType1zero;
1568 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1572 while (SType1A[j*LDA+k] == SType1zero) {
1575 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1577 SType1A[j*LDA+k] = SType1one;
1578 SType2A[j*LDA+k] = SType2one;
1585 for(k = 0; k < M; k++)
1590 SType1A[j*LDA+k] = SType1zero;
1592 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1596 while (SType1A[j*LDA+k] == SType1zero) {
1599 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1601 SType1A[j*LDA+k] = SType1one;
1602 SType2A[j*LDA+k] = SType2one;
1616 SType1A =
new SType1[LDA * N];
1617 SType2A =
new SType2[LDA * N];
1619 for(j = 0; j < N; j++)
1624 for(k = 0; k < N; k++)
1629 SType1A[j*LDA+k] = SType1zero;
1631 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1635 while (SType1A[j*LDA+k] == SType1zero) {
1638 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1640 SType1A[j*LDA+k] = SType1one;
1641 SType2A[j*LDA+k] = SType2one;
1648 for(k = 0; k < N; k++)
1653 SType1A[j*LDA+k] = SType1zero;
1655 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1659 while (SType1A[j*LDA+k] == SType1zero) {
1662 SType2A[j*LDA+k] =
ConvertType(SType1A[j*LDA+k], convertTo);
1664 SType1A[j*LDA+k] = SType1one;
1665 SType2A[j*LDA+k] = SType2one;
1674 for(j = 0; j < N; j++)
1676 for(k = 0; k < M; k++)
1679 SType2B[j*LDB+k] =
ConvertType(SType1B[j*LDB+k], convertTo);
1684 SType2alpha =
ConvertType(SType1alpha, convertTo);
1688 std::cout <<
"Test #" << TotalTestCount <<
" --" << std::endl;
1693 std::cout <<
"M="<<M <<
"\t" <<
"N="<<N <<
"\t" <<
"LDA="<<LDA <<
"\t" <<
"LDB="<<LDB << std::endl;
1694 std::cout <<
"SType1alpha = " << SType1alpha << std::endl;
1695 std::cout <<
"SType2alpha = " << SType2alpha << std::endl;
1697 PrintMatrix(SType1A, M, M, LDA,
"SType1A", matlab);
1698 PrintMatrix(SType2A, M, M, LDA,
"SType2A", matlab);
1700 PrintMatrix(SType1A, N, N, LDA,
"SType1A", matlab);
1701 PrintMatrix(SType2A, N, N, LDA,
"SType2A", matlab);
1703 PrintMatrix(SType1B, M, N, LDB,
"SType1B_before_operation", matlab);
1704 PrintMatrix(SType2B, M, N, LDB,
"SType2B_before_operation", matlab);
1708 SType1BLAS.
TRSM(SIDE, UPLO, TRANSA, DIAG, M, N, SType1alpha, SType1A, LDA, SType1B, LDB);
1709 SType2BLAS.
TRSM(SIDE, UPLO, TRANSA, DIAG, M, N, SType2alpha, SType2A, LDA, SType2B, LDB);
1713 PrintMatrix(SType1B, M, N, LDB,
"SType1B_after_operation", matlab);
1714 PrintMatrix(SType2B, M, N, LDB,
"SType2B_after_operation", matlab);
1718 std::cout <<
"FAILED TEST!!!!!!" << std::endl;
1719 GoodTestSubcount +=
CompareMatrices(SType1B, SType2B, M, N, LDB, TOL);
1726 GoodTestCount += GoodTestSubcount;
1727 if(verbose || debug) std::cout <<
"TRSM: " << GoodTestSubcount <<
" of " << TRSMTESTS <<
" tests were successful." << std::endl;
1728 if(debug) std::cout << std::endl;
1733 if((((TotalTestCount - 1) - GoodTestCount) != 0) || (verbose) || (debug))
1735 std::cout << GoodTestCount <<
" of " << (TotalTestCount - 1) <<
" total tests were successful." << std::endl;
1738 if ((TotalTestCount-1) == GoodTestCount) {
1739 std::cout <<
"End Result: TEST PASSED" << std::endl;
1743 std::cout <<
"End Result: TEST FAILED" << std::endl;
1744 return (TotalTestCount-GoodTestCount-1);
1747 template<
typename TYPE>
1760 double GetRandom(
double Low,
double High)
1765 template<
typename TYPE>
1768 std::cout << Name <<
" =" << std::endl;
1770 if(Matlab) std::cout <<
"[";
1771 for(i = 0; i < Size; i++)
1773 std::cout << Vector[i] <<
" ";
1775 if(Matlab) std::cout <<
"]";
1778 std::cout << std::endl << std::endl;
1782 std::cout <<
";" << std::endl;
1786 template<
typename TYPE>
1791 std::cout << Name <<
" =" << std::endl;
1793 for(i = 0; i < Rows; i++)
1795 for(j = 0; j < Columns; j++)
1797 std::cout << Matrix[i + (j * LDM)] <<
" ";
1799 std::cout << std::endl;
1801 std::cout << std::endl;
1805 std::cout << Name <<
" = ";
1808 for(i = 0; i < Rows; i++)
1811 for(j = 0; j < Columns; j++)
1813 std::cout << Matrix[i + (j * LDM)] <<
" ";
1817 std::cout <<
"];" << std::endl;
1821 template<
typename TYPE1,
typename TYPE2>
1830 return( temp2 < Tolerance );
1837 template<
typename TYPE1,
typename TYPE2>
1847 for(i = 0; i < Size; i++)
1850 temp =
ConvertType(Vector1[i], convertTo) - Vector2[i];
1858 if (temp3 > Tolerance )
1867 template<
typename TYPE1,
typename TYPE2>
1877 for(j = 0; j < Columns; j++)
1879 for(i = 0; i < Rows; i++)
1882 temp =
ConvertType(Matrix1[j*LDM + i],convertTo) - Matrix2[j*LDM + i];
1891 if (temp3 > Tolerance)
1898 template<
typename TYPE1,
typename TYPE2>
1901 return static_cast<TYPE2
>(T1);
1938 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.
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()