31 #include <boost/numeric/ublas/io.hpp>
32 #include <boost/numeric/ublas/triangular.hpp>
33 #include <boost/numeric/ublas/matrix_sparse.hpp>
34 #include <boost/numeric/ublas/matrix.hpp>
35 #include <boost/numeric/ublas/matrix_proxy.hpp>
36 #include <boost/numeric/ublas/lu.hpp>
37 #include <boost/numeric/ublas/io.hpp>
38 #include <boost/numeric/ublas/vector_proxy.hpp>
44 #define VIENNACL_WITH_UBLAS 1
61 template<
typename ScalarType>
66 return (s1 - s2) /
std::max(std::fabs(s1), std::fabs(s2));
70 template<
typename ScalarType,
typename VCLVectorType>
73 ublas::vector<ScalarType> v2_cpu(v2.size());
77 for (
unsigned int i=0;i<v1.size(); ++i)
79 if (
std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 )
80 v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) /
std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) );
88 template<
typename ScalarType,
typename VCLMatrixType>
89 ScalarType diff(ublas::matrix<ScalarType>
const & mat1, VCLMatrixType
const & mat2)
91 ublas::matrix<ScalarType> mat2_cpu(mat2.size1(), mat2.size2());
97 for (
unsigned int i = 0; i < mat2_cpu.size1(); ++i)
99 for (
unsigned int j = 0; j < mat2_cpu.size2(); ++j)
101 act = std::fabs(mat2_cpu(i,j) - mat1(i,j)) /
std::max( std::fabs(mat2_cpu(i, j)), std::fabs(mat1(i,j)) );
113 template<
typename NumericT,
typename Epsilon,
114 typename UblasMatrixType,
typename UblasVectorType,
115 typename VCLMatrixType,
typename VCLVectorType1,
typename VCLVectorType2>
117 UblasMatrixType & ublas_m1, UblasVectorType & ublas_v1, UblasVectorType & ublas_v2, UblasMatrixType & ublas_m2,
118 VCLMatrixType & vcl_m1, VCLVectorType1 & vcl_v1, VCLVectorType2 & vcl_v2, VCLMatrixType & vcl_m2)
120 int retval = EXIT_SUCCESS;
123 ublas_v1 = ublas::scalar_vector<NumericT>(ublas_v1.size(), NumericT(0.1234));
124 ublas_v2 = ublas::scalar_vector<NumericT>(ublas_v2.size(), NumericT(0.4321));
130 std::cout <<
"Rank 1 update" << std::endl;
134 if ( std::fabs(
diff(ublas_m1, vcl_m1)) > epsilon )
136 std::cout <<
"# Error at operation: rank 1 update" << std::endl;
137 std::cout <<
" diff: " << std::fabs(
diff(ublas_m1, vcl_m1)) << std::endl;
144 std::cout <<
"Scaled rank 1 update - CPU Scalar" << std::endl;
148 if ( std::fabs(
diff(ublas_m1, vcl_m1)) > epsilon )
150 std::cout <<
"# Error at operation: scaled rank 1 update - CPU Scalar" << std::endl;
151 std::cout <<
" diff: " << std::fabs(
diff(ublas_m1, vcl_m1)) << std::endl;
156 std::cout <<
"Scaled rank 1 update - GPU Scalar" << std::endl;
160 if ( std::fabs(
diff(ublas_m1, vcl_m1)) > epsilon )
162 std::cout <<
"# Error at operation: scaled rank 1 update - GPU Scalar" << std::endl;
163 std::cout <<
" diff: " << std::fabs(
diff(ublas_m1, vcl_m1)) << std::endl;
171 std::cout <<
"Matrix-Vector product" << std::endl;
175 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
177 std::cout <<
"# Error at operation: matrix-vector product" << std::endl;
178 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
179 retval = EXIT_FAILURE;
182 std::cout <<
"Matrix-Vector product with scaled add" << std::endl;
183 NumericT alpha =
static_cast<NumericT
>(2.786);
184 NumericT beta =
static_cast<NumericT
>(1.432);
191 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
193 std::cout <<
"# Error at operation: matrix-vector product with scaled additions" << std::endl;
194 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
195 retval = EXIT_FAILURE;
202 std::cout <<
"Transposed Matrix-Vector product" << std::endl;
206 if ( std::fabs(
diff(ublas_v2, vcl_v2)) > epsilon )
208 std::cout <<
"# Error at operation: transposed matrix-vector product" << std::endl;
209 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
210 retval = EXIT_FAILURE;
213 std::cout <<
"Transposed Matrix-Vector product with scaled add" << std::endl;
217 if ( std::fabs(
diff(ublas_v2, vcl_v2)) > epsilon )
219 std::cout <<
"# Error at operation: transposed matrix-vector product with scaled additions" << std::endl;
220 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
221 retval = EXIT_FAILURE;
228 std::cout <<
"Row extraction from matrix" << std::endl;
229 ublas_v2 =
row(ublas_m1, std::size_t(7));
230 vcl_v2 =
row(vcl_m1, std::size_t(7));
232 if ( std::fabs(
diff(ublas_v2, vcl_v2)) > epsilon )
234 std::cout <<
"# Error at operation: diagonal extraction from matrix" << std::endl;
235 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
236 retval = EXIT_FAILURE;
239 std::cout <<
"Column extraction from matrix" << std::endl;
240 ublas_v1 =
column(ublas_m1, std::size_t(7));
241 vcl_v1 =
column(vcl_m1, std::size_t(7));
243 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
245 std::cout <<
"# Error at operation: diagonal extraction from matrix" << std::endl;
246 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
247 retval = EXIT_FAILURE;
255 UblasMatrixType A = ublas_m2;
257 std::cout <<
"Diagonal extraction from matrix" << std::endl;
258 for (std::size_t i=0; i<ublas_m1.size2(); ++i)
259 ublas_v2[i] = ublas_m1(i + 3, i);
260 vcl_v2 =
diag(vcl_m1, static_cast<int>(-3));
262 if ( std::fabs(
diff(ublas_v2, vcl_v2)) > epsilon )
264 std::cout <<
"# Error at operation: diagonal extraction from matrix" << std::endl;
265 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
266 retval = EXIT_FAILURE;
269 std::cout <<
"Matrix diagonal assignment from vector" << std::endl;
270 A = ublas::scalar_matrix<NumericT>(A.size1(), A.size2(), NumericT(0));
271 for (std::size_t i=0; i<ublas_m1.size2(); ++i)
272 A(i + (A.size1() - ublas_m1.size2()), i) = ublas_v2[i];
273 vcl_m2 =
diag(vcl_v2, static_cast<int>(ublas_m1.size2()) - static_cast<int>(A.size1()));
275 if ( std::fabs(
diff(A, vcl_m2)) > epsilon )
277 std::cout <<
"# Error at operation: Matrix assignment from diagonal" << std::endl;
278 std::cout <<
" diff: " << std::fabs(
diff(A, vcl_m2)) << std::endl;
279 retval = EXIT_FAILURE;
288 template<
typename NumericT,
typename Epsilon,
289 typename UblasMatrixType,
typename UblasVectorType,
290 typename VCLMatrixType,
typename VCLVectorType1>
292 UblasMatrixType & ublas_m1, UblasVectorType & ublas_v1,
293 VCLMatrixType & vcl_m1, VCLVectorType1 & vcl_v1)
295 int retval = EXIT_SUCCESS;
305 std::cout <<
"Upper triangular solver" << std::endl;
306 ublas_v1 =
ublas::solve(ublas_m1, ublas_v1, ublas::upper_tag());
308 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
310 std::cout <<
"# Error at operation: upper triangular solver" << std::endl;
311 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
312 retval = EXIT_FAILURE;
316 std::cout <<
"Upper unit triangular solver" << std::endl;
318 ublas_v1 =
ublas::solve(ublas_m1, ublas_v1, ublas::unit_upper_tag());
320 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
322 std::cout <<
"# Error at operation: unit upper triangular solver" << std::endl;
323 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
324 retval = EXIT_FAILURE;
328 std::cout <<
"Lower triangular solver" << std::endl;
330 ublas_v1 =
ublas::solve(ublas_m1, ublas_v1, ublas::lower_tag());
332 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
334 std::cout <<
"# Error at operation: lower triangular solver" << std::endl;
335 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
336 retval = EXIT_FAILURE;
340 std::cout <<
"Lower unit triangular solver" << std::endl;
342 ublas_v1 =
ublas::solve(ublas_m1, ublas_v1, ublas::unit_lower_tag());
344 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
346 std::cout <<
"# Error at operation: unit lower triangular solver" << std::endl;
347 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
348 retval = EXIT_FAILURE;
356 std::cout <<
"Transposed upper triangular solver" << std::endl;
360 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
362 std::cout <<
"# Error at operation: upper triangular solver" << std::endl;
363 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
364 retval = EXIT_FAILURE;
368 std::cout <<
"Transposed unit upper triangular solver" << std::endl;
372 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
374 std::cout <<
"# Error at operation: unit upper triangular solver" << std::endl;
375 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
376 retval = EXIT_FAILURE;
380 std::cout <<
"Transposed lower triangular solver" << std::endl;
384 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
386 std::cout <<
"# Error at operation: lower triangular solver" << std::endl;
387 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
388 retval = EXIT_FAILURE;
392 std::cout <<
"Transposed unit lower triangular solver" << std::endl;
396 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
398 std::cout <<
"# Error at operation: unit lower triangular solver" << std::endl;
399 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
400 retval = EXIT_FAILURE;
410 template<
typename NumericT,
typename F,
typename Epsilon >
411 int test(Epsilon
const& epsilon)
413 int retval = EXIT_SUCCESS;
415 std::size_t num_rows = 141;
416 std::size_t num_cols = 103;
419 ublas::vector<NumericT> ublas_v1(num_rows);
420 for (std::size_t i = 0; i < ublas_v1.size(); ++i)
421 ublas_v1(i) = random<NumericT>();
422 ublas::vector<NumericT> ublas_v2 = ublas::scalar_vector<NumericT>(num_cols, NumericT(3.1415));
425 ublas::matrix<NumericT> ublas_m1(ublas_v1.size(), ublas_v2.size());
427 for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
428 for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
429 ublas_m1(i,j) =
static_cast<NumericT
>(0.1) * random<NumericT>();
432 ublas::matrix<NumericT> ublas_m2(ublas_v1.size(), ublas_v1.size());
434 for (std::size_t i = 0; i < ublas_m2.size1(); ++i)
436 for (std::size_t j = 0; j < ublas_m2.size2(); ++j)
437 ublas_m2(i,j) =
static_cast<NumericT
>(-0.1) * random<NumericT>();
438 ublas_m2(i, i) =
static_cast<NumericT
>(2) + random<NumericT>();
508 std::cout <<
"------------ Testing rank-1-updates and matrix-vector products ------------------" << std::endl;
510 std::cout <<
"* m = full, v1 = full, v2 = full" << std::endl;
511 retval = test_prod_rank1<NumericT>(epsilon,
512 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
513 vcl_m1_native, vcl_v1_native, vcl_v2_native, vcl_m2_native);
514 if (retval == EXIT_FAILURE)
516 std::cout <<
" --- FAILED! ---" << std::endl;
520 std::cout <<
" --- PASSED ---" << std::endl;
523 std::cout <<
"* m = full, v1 = full, v2 = range" << std::endl;
524 retval = test_prod_rank1<NumericT>(epsilon,
525 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
526 vcl_m1_native, vcl_v1_native, vcl_v2_range, vcl_m2_native);
527 if (retval == EXIT_FAILURE)
529 std::cout <<
" --- FAILED! ---" << std::endl;
533 std::cout <<
" --- PASSED ---" << std::endl;
536 std::cout <<
"* m = full, v1 = full, v2 = slice" << std::endl;
537 retval = test_prod_rank1<NumericT>(epsilon,
538 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
539 vcl_m1_native, vcl_v1_native, vcl_v2_slice, vcl_m2_native);
540 if (retval == EXIT_FAILURE)
542 std::cout <<
" --- FAILED! ---" << std::endl;
546 std::cout <<
" --- PASSED ---" << std::endl;
552 std::cout <<
"* m = full, v1 = range, v2 = full" << std::endl;
553 retval = test_prod_rank1<NumericT>(epsilon,
554 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
555 vcl_m1_native, vcl_v1_range, vcl_v2_native, vcl_m2_native);
556 if (retval == EXIT_FAILURE)
558 std::cout <<
" --- FAILED! ---" << std::endl;
562 std::cout <<
" --- PASSED ---" << std::endl;
565 std::cout <<
"* m = full, v1 = range, v2 = range" << std::endl;
566 retval = test_prod_rank1<NumericT>(epsilon,
567 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
568 vcl_m1_native, vcl_v1_range, vcl_v2_range, vcl_m2_native);
569 if (retval == EXIT_FAILURE)
571 std::cout <<
" --- FAILED! ---" << std::endl;
575 std::cout <<
" --- PASSED ---" << std::endl;
578 std::cout <<
"* m = full, v1 = range, v2 = slice" << std::endl;
579 retval = test_prod_rank1<NumericT>(epsilon,
580 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
581 vcl_m1_native, vcl_v1_range, vcl_v2_slice, vcl_m2_native);
582 if (retval == EXIT_FAILURE)
584 std::cout <<
" --- FAILED! ---" << std::endl;
588 std::cout <<
" --- PASSED ---" << std::endl;
594 std::cout <<
"* m = full, v1 = slice, v2 = full" << std::endl;
595 retval = test_prod_rank1<NumericT>(epsilon,
596 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
597 vcl_m1_native, vcl_v1_slice, vcl_v2_native, vcl_m2_native);
598 if (retval == EXIT_FAILURE)
600 std::cout <<
" --- FAILED! ---" << std::endl;
604 std::cout <<
" --- PASSED ---" << std::endl;
607 std::cout <<
"* m = full, v1 = slice, v2 = range" << std::endl;
608 retval = test_prod_rank1<NumericT>(epsilon,
609 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
610 vcl_m1_native, vcl_v1_slice, vcl_v2_range, vcl_m2_native);
611 if (retval == EXIT_FAILURE)
613 std::cout <<
" --- FAILED! ---" << std::endl;
617 std::cout <<
" --- PASSED ---" << std::endl;
620 std::cout <<
"* m = full, v1 = slice, v2 = slice" << std::endl;
621 retval = test_prod_rank1<NumericT>(epsilon,
622 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
623 vcl_m1_native, vcl_v1_slice, vcl_v2_slice, vcl_m2_native);
624 if (retval == EXIT_FAILURE)
626 std::cout <<
" --- FAILED! ---" << std::endl;
630 std::cout <<
" --- PASSED ---" << std::endl;
635 std::cout <<
"* m = range, v1 = full, v2 = full" << std::endl;
636 retval = test_prod_rank1<NumericT>(epsilon,
637 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
638 vcl_m1_range, vcl_v1_native, vcl_v2_native, vcl_m2_range);
639 if (retval == EXIT_FAILURE)
641 std::cout <<
" --- FAILED! ---" << std::endl;
645 std::cout <<
" --- PASSED ---" << std::endl;
648 std::cout <<
"* m = range, v1 = full, v2 = range" << std::endl;
649 retval = test_prod_rank1<NumericT>(epsilon,
650 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
651 vcl_m1_range, vcl_v1_native, vcl_v2_range, vcl_m2_range);
652 if (retval == EXIT_FAILURE)
654 std::cout <<
" --- FAILED! ---" << std::endl;
658 std::cout <<
" --- PASSED ---" << std::endl;
661 std::cout <<
"* m = range, v1 = full, v2 = slice" << std::endl;
662 retval = test_prod_rank1<NumericT>(epsilon,
663 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
664 vcl_m1_range, vcl_v1_native, vcl_v2_slice, vcl_m2_range);
665 if (retval == EXIT_FAILURE)
667 std::cout <<
" --- FAILED! ---" << std::endl;
671 std::cout <<
" --- PASSED ---" << std::endl;
677 std::cout <<
"* m = range, v1 = range, v2 = full" << std::endl;
678 retval = test_prod_rank1<NumericT>(epsilon,
679 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
680 vcl_m1_range, vcl_v1_range, vcl_v2_native, vcl_m2_range);
681 if (retval == EXIT_FAILURE)
683 std::cout <<
" --- FAILED! ---" << std::endl;
687 std::cout <<
" --- PASSED ---" << std::endl;
690 std::cout <<
"* m = range, v1 = range, v2 = range" << std::endl;
691 retval = test_prod_rank1<NumericT>(epsilon,
692 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
693 vcl_m1_range, vcl_v1_range, vcl_v2_range, vcl_m2_range);
694 if (retval == EXIT_FAILURE)
696 std::cout <<
" --- FAILED! ---" << std::endl;
700 std::cout <<
" --- PASSED ---" << std::endl;
703 std::cout <<
"* m = range, v1 = range, v2 = slice" << std::endl;
704 retval = test_prod_rank1<NumericT>(epsilon,
705 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
706 vcl_m1_range, vcl_v1_range, vcl_v2_slice, vcl_m2_range);
707 if (retval == EXIT_FAILURE)
709 std::cout <<
" --- FAILED! ---" << std::endl;
713 std::cout <<
" --- PASSED ---" << std::endl;
719 std::cout <<
"* m = range, v1 = slice, v2 = full" << std::endl;
720 retval = test_prod_rank1<NumericT>(epsilon,
721 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
722 vcl_m1_range, vcl_v1_slice, vcl_v2_native, vcl_m2_range);
723 if (retval == EXIT_FAILURE)
725 std::cout <<
" --- FAILED! ---" << std::endl;
729 std::cout <<
" --- PASSED ---" << std::endl;
732 std::cout <<
"* m = range, v1 = slice, v2 = range" << std::endl;
733 retval = test_prod_rank1<NumericT>(epsilon,
734 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
735 vcl_m1_range, vcl_v1_slice, vcl_v2_range, vcl_m2_range);
736 if (retval == EXIT_FAILURE)
738 std::cout <<
" --- FAILED! ---" << std::endl;
742 std::cout <<
" --- PASSED ---" << std::endl;
745 std::cout <<
"* m = range, v1 = slice, v2 = slice" << std::endl;
746 retval = test_prod_rank1<NumericT>(epsilon,
747 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
748 vcl_m1_range, vcl_v1_slice, vcl_v2_slice, vcl_m2_range);
749 if (retval == EXIT_FAILURE)
751 std::cout <<
" --- FAILED! ---" << std::endl;
755 std::cout <<
" --- PASSED ---" << std::endl;
760 std::cout <<
"* m = slice, v1 = full, v2 = full" << std::endl;
761 retval = test_prod_rank1<NumericT>(epsilon,
762 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
763 vcl_m1_slice, vcl_v1_native, vcl_v2_native, vcl_m2_slice);
764 if (retval == EXIT_FAILURE)
766 std::cout <<
" --- FAILED! ---" << std::endl;
770 std::cout <<
" --- PASSED ---" << std::endl;
773 std::cout <<
"* m = slice, v1 = full, v2 = range" << std::endl;
774 retval = test_prod_rank1<NumericT>(epsilon,
775 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
776 vcl_m1_slice, vcl_v1_native, vcl_v2_range, vcl_m2_slice);
777 if (retval == EXIT_FAILURE)
779 std::cout <<
" --- FAILED! ---" << std::endl;
783 std::cout <<
" --- PASSED ---" << std::endl;
786 std::cout <<
"* m = slice, v1 = full, v2 = slice" << std::endl;
787 retval = test_prod_rank1<NumericT>(epsilon,
788 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
789 vcl_m1_slice, vcl_v1_native, vcl_v2_slice, vcl_m2_slice);
790 if (retval == EXIT_FAILURE)
792 std::cout <<
" --- FAILED! ---" << std::endl;
796 std::cout <<
" --- PASSED ---" << std::endl;
802 std::cout <<
"* m = slice, v1 = range, v2 = full" << std::endl;
803 retval = test_prod_rank1<NumericT>(epsilon,
804 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
805 vcl_m1_slice, vcl_v1_range, vcl_v2_native, vcl_m2_slice);
806 if (retval == EXIT_FAILURE)
808 std::cout <<
" --- FAILED! ---" << std::endl;
812 std::cout <<
" --- PASSED ---" << std::endl;
815 std::cout <<
"* m = slice, v1 = range, v2 = range" << std::endl;
816 retval = test_prod_rank1<NumericT>(epsilon,
817 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
818 vcl_m1_slice, vcl_v1_range, vcl_v2_range, vcl_m2_slice);
819 if (retval == EXIT_FAILURE)
821 std::cout <<
" --- FAILED! ---" << std::endl;
825 std::cout <<
" --- PASSED ---" << std::endl;
828 std::cout <<
"* m = slice, v1 = range, v2 = slice" << std::endl;
829 retval = test_prod_rank1<NumericT>(epsilon,
830 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
831 vcl_m1_slice, vcl_v1_range, vcl_v2_slice, vcl_m2_slice);
832 if (retval == EXIT_FAILURE)
834 std::cout <<
" --- FAILED! ---" << std::endl;
838 std::cout <<
" --- PASSED ---" << std::endl;
844 std::cout <<
"* m = slice, v1 = slice, v2 = full" << std::endl;
845 retval = test_prod_rank1<NumericT>(epsilon,
846 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
847 vcl_m1_slice, vcl_v1_slice, vcl_v2_native, vcl_m2_slice);
848 if (retval == EXIT_FAILURE)
850 std::cout <<
" --- FAILED! ---" << std::endl;
854 std::cout <<
" --- PASSED ---" << std::endl;
857 std::cout <<
"* m = slice, v1 = slice, v2 = range" << std::endl;
858 retval = test_prod_rank1<NumericT>(epsilon,
859 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
860 vcl_m1_slice, vcl_v1_slice, vcl_v2_range, vcl_m2_slice);
861 if (retval == EXIT_FAILURE)
863 std::cout <<
" --- FAILED! ---" << std::endl;
867 std::cout <<
" --- PASSED ---" << std::endl;
870 std::cout <<
"* m = slice, v1 = slice, v2 = slice" << std::endl;
871 retval = test_prod_rank1<NumericT>(epsilon,
872 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
873 vcl_m1_slice, vcl_v1_slice, vcl_v2_slice, vcl_m2_slice);
874 if (retval == EXIT_FAILURE)
876 std::cout <<
" --- FAILED! ---" << std::endl;
880 std::cout <<
" --- PASSED ---" << std::endl;
888 std::cout <<
"------------ Testing triangular solves ------------------" << std::endl;
890 std::cout <<
"* m = full, v1 = full" << std::endl;
891 retval = test_solve<NumericT>(epsilon,
893 vcl_m2_native, vcl_v1_native);
894 if (retval == EXIT_FAILURE)
896 std::cout <<
" --- FAILED! ---" << std::endl;
900 std::cout <<
" --- PASSED ---" << std::endl;
902 std::cout <<
"* m = full, v1 = range" << std::endl;
903 retval = test_solve<NumericT>(epsilon,
905 vcl_m2_native, vcl_v1_range);
906 if (retval == EXIT_FAILURE)
908 std::cout <<
" --- FAILED! ---" << std::endl;
912 std::cout <<
" --- PASSED ---" << std::endl;
914 std::cout <<
"* m = full, v1 = slice" << std::endl;
915 retval = test_solve<NumericT>(epsilon,
917 vcl_m2_native, vcl_v1_slice);
918 if (retval == EXIT_FAILURE)
920 std::cout <<
" --- FAILED! ---" << std::endl;
924 std::cout <<
" --- PASSED ---" << std::endl;
929 std::cout <<
"* m = range, v1 = full" << std::endl;
930 retval = test_solve<NumericT>(epsilon,
932 vcl_m2_range, vcl_v1_native);
933 if (retval == EXIT_FAILURE)
935 std::cout <<
" --- FAILED! ---" << std::endl;
939 std::cout <<
" --- PASSED ---" << std::endl;
941 std::cout <<
"* m = range, v1 = range" << std::endl;
942 retval = test_solve<NumericT>(epsilon,
944 vcl_m2_range, vcl_v1_range);
945 if (retval == EXIT_FAILURE)
947 std::cout <<
" --- FAILED! ---" << std::endl;
951 std::cout <<
" --- PASSED ---" << std::endl;
953 std::cout <<
"* m = range, v1 = slice" << std::endl;
954 retval = test_solve<NumericT>(epsilon,
956 vcl_m2_range, vcl_v1_slice);
957 if (retval == EXIT_FAILURE)
959 std::cout <<
" --- FAILED! ---" << std::endl;
963 std::cout <<
" --- PASSED ---" << std::endl;
967 std::cout <<
"* m = slice, v1 = full" << std::endl;
968 retval = test_solve<NumericT>(epsilon,
970 vcl_m2_slice, vcl_v1_native);
971 if (retval == EXIT_FAILURE)
973 std::cout <<
" --- FAILED! ---" << std::endl;
977 std::cout <<
" --- PASSED ---" << std::endl;
979 std::cout <<
"* m = slice, v1 = range" << std::endl;
980 retval = test_solve<NumericT>(epsilon,
982 vcl_m2_slice, vcl_v1_range);
983 if (retval == EXIT_FAILURE)
985 std::cout <<
" --- FAILED! ---" << std::endl;
989 std::cout <<
" --- PASSED ---" << std::endl;
991 std::cout <<
"* m = slice, v1 = slice" << std::endl;
992 retval = test_solve<NumericT>(epsilon,
994 vcl_m2_slice, vcl_v1_slice);
995 if (retval == EXIT_FAILURE)
997 std::cout <<
" --- FAILED! ---" << std::endl;
1001 std::cout <<
" --- PASSED ---" << std::endl;
1012 std::cout <<
"Full solver" << std::endl;
1013 unsigned int lu_dim = 100;
1014 ublas::matrix<NumericT> square_matrix(lu_dim, lu_dim);
1015 ublas::vector<NumericT> lu_rhs(lu_dim);
1019 for (std::size_t i=0; i<lu_dim; ++i)
1020 for (std::size_t j=0; j<lu_dim; ++j)
1021 square_matrix(i,j) = -
static_cast<NumericT
>(0.5) * random<NumericT>();
1024 for (std::size_t j=0; j<lu_dim; ++j)
1026 square_matrix(j,j) =
static_cast<NumericT
>(20.0) + random<NumericT>();
1027 lu_rhs(j) = random<NumericT>();
1043 if ( std::fabs(
diff(lu_rhs, vcl_lu_rhs)) > epsilon )
1045 std::cout <<
"# Error at operation: dense solver" << std::endl;
1046 std::cout <<
" diff: " << std::fabs(
diff(lu_rhs, vcl_lu_rhs)) << std::endl;
1047 retval = EXIT_FAILURE;
1059 std::cout << std::endl;
1060 std::cout <<
"----------------------------------------------" << std::endl;
1061 std::cout <<
"----------------------------------------------" << std::endl;
1062 std::cout <<
"## Test :: Matrix" << std::endl;
1063 std::cout <<
"----------------------------------------------" << std::endl;
1064 std::cout <<
"----------------------------------------------" << std::endl;
1065 std::cout << std::endl;
1067 int retval = EXIT_SUCCESS;
1085 std::cout << std::endl;
1086 std::cout <<
"----------------------------------------------" << std::endl;
1087 std::cout << std::endl;
1089 typedef float NumericT;
1090 NumericT epsilon = NumericT(1.0E-3);
1091 std::cout <<
"# Testing setup:" << std::endl;
1092 std::cout <<
" eps: " << epsilon << std::endl;
1093 std::cout <<
" numeric: float" << std::endl;
1094 std::cout <<
" layout: column-major" << std::endl;
1095 retval = test<NumericT, viennacl::column_major>(epsilon);
1096 if ( retval == EXIT_SUCCESS )
1097 std::cout <<
"# Test passed" << std::endl;
1101 std::cout << std::endl;
1102 std::cout <<
"----------------------------------------------" << std::endl;
1103 std::cout << std::endl;
1106 #ifdef VIENNACL_WITH_OPENCL
1111 typedef double NumericT;
1112 NumericT epsilon = 1.0E-11;
1113 std::cout <<
"# Testing setup:" << std::endl;
1114 std::cout <<
" eps: " << epsilon << std::endl;
1115 std::cout <<
" numeric: double" << std::endl;
1116 std::cout <<
" layout: row-major" << std::endl;
1117 retval = test<NumericT, viennacl::row_major>(epsilon);
1118 if ( retval == EXIT_SUCCESS )
1119 std::cout <<
"# Test passed" << std::endl;
1123 std::cout << std::endl;
1124 std::cout <<
"----------------------------------------------" << std::endl;
1125 std::cout << std::endl;
1127 typedef double NumericT;
1128 NumericT epsilon = 1.0E-11;
1129 std::cout <<
"# Testing setup:" << std::endl;
1130 std::cout <<
" eps: " << epsilon << std::endl;
1131 std::cout <<
" numeric: double" << std::endl;
1132 std::cout <<
" layout: column-major" << std::endl;
1133 retval = test<NumericT, viennacl::column_major>(epsilon);
1134 if ( retval == EXIT_SUCCESS )
1135 std::cout <<
"# Test passed" << std::endl;
1139 std::cout << std::endl;
1140 std::cout <<
"----------------------------------------------" << std::endl;
1141 std::cout << std::endl;
1144 std::cout << std::endl;
1145 std::cout <<
"------- Test completed --------" << std::endl;
1146 std::cout << std::endl;
void inplace_solve(matrix_base< NumericT > const &A, matrix_base< NumericT > &B, SolverTagT tag)
Direct inplace solver for triangular systems with multiple right hand sides, i.e. A \ B (MATLAB notat...
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
Class for representing strided submatrices of a bigger matrix A.
void trans(matrix_expression< const matrix_base< NumericT, SizeT, DistanceT >, const matrix_base< NumericT, SizeT, DistanceT >, op_trans > const &proxy, matrix_base< NumericT > &temp_trans)
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
void lu_substitute(matrix< NumericT, F1, AlignmentV1 > const &A, matrix< NumericT, F2, AlignmentV2 > &B)
LU substitution for the system LU = rhs.
A tag class representing a lower triangular matrix.
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
viennacl::scalar< int > s2
viennacl::scalar< float > s1
T max(const T &lhs, const T &rhs)
Maximum.
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context.
viennacl::vector< float > v1
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Class for representing non-strided subvectors of a bigger vector x.
A tag class representing an upper triangular matrix.
Class for representing strided subvectors of a bigger vector x.
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
vector_expression< const matrix_base< NumericT >, const int, op_matrix_diag > diag(const matrix_base< NumericT > &A, int k=0)
Implementations of LU factorization for row-major and column-major dense matrices.
Implementations of dense direct solvers are found here.
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_row > row(const matrix_base< NumericT, F > &A, unsigned int i)
viennacl::matrix_expression< const vector_base< NumericT >, const vector_base< NumericT >, op_prod > outer_prod(const vector_base< NumericT > &vec1, const vector_base< NumericT > &vec2)
Returns a proxy class for the operation mat += vec1 * vec2^T, i.e. a rank 1 update.
viennacl::vector< int > v2
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
T norm_inf(std::vector< T, A > const &v1)
int test_solve(Epsilon const &epsilon, UblasMatrixType &ublas_m1, UblasVectorType &ublas_v1, VCLMatrixType &vcl_m1, VCLVectorType1 &vcl_v1)
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
int test_prod_rank1(Epsilon const &epsilon, UblasMatrixType &ublas_m1, UblasVectorType &ublas_v1, UblasVectorType &ublas_v2, UblasMatrixType &ublas_m2, VCLMatrixType &vcl_m1, VCLVectorType1 &vcl_v1, VCLVectorType2 &vcl_v2, VCLMatrixType &vcl_m2)
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
A tag class representing a lower triangular matrix with unit diagonal.
ScalarType diff(ScalarType &s1, viennacl::scalar< ScalarType > &s2)
Class for representing non-strided submatrices of a bigger matrix A.
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_column > column(const matrix_base< NumericT, F > &A, unsigned int j)
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Implementation of the ViennaCL scalar class.
int test(Epsilon const &epsilon)
void lu_factorize(matrix< NumericT, viennacl::row_major > &A)
LU factorization of a row-major dense matrix.
A tag class representing an upper triangular matrix with unit diagonal.
viennacl::vector< NumericT > solve(MatrixT const &A, viennacl::vector_base< NumericT > const &rhs, bicgstab_tag const &tag, viennacl::linalg::no_precond)
Implementation of a pipelined stabilized Bi-conjugate gradient solver.