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
62 template<
typename ScalarType>
67 return (s1 - s2) /
std::max(std::fabs(s1), std::fabs(s2));
71 template<
typename ScalarType,
typename VCLVectorType>
74 ublas::vector<ScalarType> v2_cpu(v2.size());
78 for (
unsigned int i=0;i<v1.size(); ++i)
80 if (
std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 )
81 v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) /
std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) );
89 template<
typename ScalarType,
typename VCLMatrixType>
90 ScalarType diff(ublas::matrix<ScalarType>
const & mat1, VCLMatrixType
const & mat2)
92 ublas::matrix<ScalarType> mat2_cpu(mat2.size1(), mat2.size2());
98 for (
unsigned int i = 0; i < mat2_cpu.size1(); ++i)
100 for (
unsigned int j = 0; j < mat2_cpu.size2(); ++j)
102 act = std::fabs(mat2_cpu(i,j) - mat1(i,j)) /
std::max( std::fabs(mat2_cpu(i, j)), std::fabs(mat1(i,j)) );
114 template<
typename NumericT,
typename Epsilon,
115 typename UblasMatrixType,
typename UblasVectorType,
116 typename VCLMatrixType,
typename VCLVectorType1,
typename VCLVectorType2>
118 UblasMatrixType & ublas_m1, UblasVectorType & ublas_v1, UblasVectorType & ublas_v2, UblasMatrixType & ublas_m2,
119 VCLMatrixType & vcl_m1, VCLVectorType1 & vcl_v1, VCLVectorType2 & vcl_v2, VCLMatrixType & vcl_m2)
121 int retval = EXIT_SUCCESS;
124 ublas_v1 = ublas::scalar_vector<NumericT>(ublas_v1.size(),
NumericT(0.1234));
125 ublas_v2 = ublas::scalar_vector<NumericT>(ublas_v2.size(),
NumericT(0.4321));
131 std::cout <<
"Rank 1 update" << std::endl;
135 if ( std::fabs(
diff(ublas_m1, vcl_m1)) > epsilon )
137 std::cout <<
"# Error at operation: rank 1 update" << std::endl;
138 std::cout <<
" diff: " << std::fabs(
diff(ublas_m1, vcl_m1)) << std::endl;
145 std::cout <<
"Scaled rank 1 update - CPU Scalar" << std::endl;
149 if ( std::fabs(
diff(ublas_m1, vcl_m1)) > epsilon )
151 std::cout <<
"# Error at operation: scaled rank 1 update - CPU Scalar" << std::endl;
152 std::cout <<
" diff: " << std::fabs(
diff(ublas_m1, vcl_m1)) << std::endl;
157 std::cout <<
"Scaled rank 1 update - GPU Scalar" << std::endl;
161 if ( std::fabs(
diff(ublas_m1, vcl_m1)) > epsilon )
163 std::cout <<
"# Error at operation: scaled rank 1 update - GPU Scalar" << std::endl;
164 std::cout <<
" diff: " << std::fabs(
diff(ublas_m1, vcl_m1)) << std::endl;
172 std::cout <<
"Matrix-Vector product" << std::endl;
176 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
178 std::cout <<
"# Error at operation: matrix-vector product" << std::endl;
179 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
180 retval = EXIT_FAILURE;
183 std::cout <<
"Matrix-Vector product with scaled add" << std::endl;
192 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
194 std::cout <<
"# Error at operation: matrix-vector product with scaled additions" << std::endl;
195 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
196 retval = EXIT_FAILURE;
199 std::cout <<
"Matrix-Vector product with matrix expression" << std::endl;
200 ublas_v1 =
ublas::prod(ublas_m1 + ublas_m1, ublas_v2);
203 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
205 std::cout <<
"# Error at operation: matrix-vector product" << std::endl;
206 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
207 retval = EXIT_FAILURE;
210 std::cout <<
"Matrix-Vector product with vector expression" << std::endl;
214 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
216 std::cout <<
"# Error at operation: matrix-vector product" << std::endl;
217 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
218 retval = EXIT_FAILURE;
221 std::cout <<
"Matrix-Vector product with matrix and vector expression" << std::endl;
222 ublas_v1 =
ublas::prod(ublas_m1 + ublas_m1, ublas_v2 + ublas_v2);
225 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
227 std::cout <<
"# Error at operation: matrix-vector product" << std::endl;
228 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
229 retval = EXIT_FAILURE;
236 std::cout <<
"Transposed Matrix-Vector product" << std::endl;
240 if ( std::fabs(
diff(ublas_v2, vcl_v2)) > epsilon )
242 std::cout <<
"# Error at operation: transposed matrix-vector product" << std::endl;
243 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
244 retval = EXIT_FAILURE;
247 std::cout <<
"Transposed Matrix-Vector product with scaled add" << std::endl;
251 if ( std::fabs(
diff(ublas_v2, vcl_v2)) > epsilon )
253 std::cout <<
"# Error at operation: transposed matrix-vector product with scaled additions" << std::endl;
254 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
255 retval = EXIT_FAILURE;
259 std::cout <<
"Row sum with matrix" << std::endl;
260 ublas_v1 =
ublas::prod(ublas_m1, ublas::scalar_vector<NumericT>(ublas_m1.size2(),
NumericT(1)));
263 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
265 std::cout <<
"# Error at operation: row sum" << std::endl;
266 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
267 retval = EXIT_FAILURE;
271 std::cout <<
"Row sum with matrix expression" << std::endl;
272 ublas_v1 =
ublas::prod(ublas_m1 + ublas_m1, ublas::scalar_vector<NumericT>(ublas_m1.size2(),
NumericT(1)));
275 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
277 std::cout <<
"# Error at operation: row sum (with expression)" << std::endl;
278 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
279 retval = EXIT_FAILURE;
283 std::cout <<
"Column sum with matrix" << std::endl;
287 if ( std::fabs(
diff(ublas_v2, vcl_v2)) > epsilon )
289 std::cout <<
"# Error at operation: column sum" << std::endl;
290 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
291 retval = EXIT_FAILURE;
295 std::cout <<
"Column sum with matrix expression" << std::endl;
299 if ( std::fabs(
diff(ublas_v2, vcl_v2)) > epsilon )
301 std::cout <<
"# Error at operation: column sum (with expression)" << std::endl;
302 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
303 retval = EXIT_FAILURE;
311 std::cout <<
"Row extraction from matrix" << std::endl;
312 ublas_v2 =
row(ublas_m1, std::size_t(7));
313 vcl_v2 =
row(vcl_m1, std::size_t(7));
315 if ( std::fabs(
diff(ublas_v2, vcl_v2)) > epsilon )
317 std::cout <<
"# Error at operation: diagonal extraction from matrix" << std::endl;
318 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
319 retval = EXIT_FAILURE;
322 std::cout <<
"Column extraction from matrix" << std::endl;
323 ublas_v1 =
column(ublas_m1, std::size_t(7));
324 vcl_v1 =
column(vcl_m1, std::size_t(7));
326 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
328 std::cout <<
"# Error at operation: diagonal extraction from matrix" << std::endl;
329 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
330 retval = EXIT_FAILURE;
338 UblasMatrixType A = ublas_m2;
340 std::cout <<
"Diagonal extraction from matrix" << std::endl;
341 for (std::size_t i=0; i<ublas_m1.size2(); ++i)
342 ublas_v2[i] = ublas_m1(i + 3, i);
343 vcl_v2 =
diag(vcl_m1, static_cast<int>(-3));
345 if ( std::fabs(
diff(ublas_v2, vcl_v2)) > epsilon )
347 std::cout <<
"# Error at operation: diagonal extraction from matrix" << std::endl;
348 std::cout <<
" diff: " << std::fabs(
diff(ublas_v2, vcl_v2)) << std::endl;
349 retval = EXIT_FAILURE;
352 std::cout <<
"Matrix diagonal assignment from vector" << std::endl;
353 A = ublas::scalar_matrix<NumericT>(A.size1(), A.size2(),
NumericT(0));
354 for (std::size_t i=0; i<ublas_m1.size2(); ++i)
355 A(i + (A.size1() - ublas_m1.size2()), i) = ublas_v2[i];
356 vcl_m2 =
diag(vcl_v2, static_cast<int>(ublas_m1.size2()) - static_cast<int>(A.size1()));
358 if ( std::fabs(
diff(A, vcl_m2)) > epsilon )
360 std::cout <<
"# Error at operation: Matrix assignment from diagonal" << std::endl;
361 std::cout <<
" diff: " << std::fabs(
diff(A, vcl_m2)) << std::endl;
362 retval = EXIT_FAILURE;
371 template<
typename NumericT,
typename Epsilon,
372 typename UblasMatrixType,
typename UblasVectorType,
373 typename VCLMatrixType,
typename VCLVectorType1>
375 UblasMatrixType & ublas_m1, UblasVectorType & ublas_v1,
376 VCLMatrixType & vcl_m1, VCLVectorType1 & vcl_v1)
378 int retval = EXIT_SUCCESS;
388 std::cout <<
"Upper triangular solver" << std::endl;
389 ublas_v1 =
ublas::solve(ublas_m1, ublas_v1, ublas::upper_tag());
391 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
393 std::cout <<
"# Error at operation: upper triangular solver" << std::endl;
394 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
395 retval = EXIT_FAILURE;
399 std::cout <<
"Upper unit triangular solver" << std::endl;
401 ublas_v1 =
ublas::solve(ublas_m1, ublas_v1, ublas::unit_upper_tag());
403 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
405 std::cout <<
"# Error at operation: unit upper triangular solver" << std::endl;
406 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
407 retval = EXIT_FAILURE;
411 std::cout <<
"Lower triangular solver" << std::endl;
413 ublas_v1 =
ublas::solve(ublas_m1, ublas_v1, ublas::lower_tag());
415 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
417 std::cout <<
"# Error at operation: lower triangular solver" << std::endl;
418 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
419 retval = EXIT_FAILURE;
423 std::cout <<
"Lower unit triangular solver" << std::endl;
425 ublas_v1 =
ublas::solve(ublas_m1, ublas_v1, ublas::unit_lower_tag());
427 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
429 std::cout <<
"# Error at operation: unit lower triangular solver" << std::endl;
430 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
431 retval = EXIT_FAILURE;
439 std::cout <<
"Transposed upper triangular solver" << std::endl;
443 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
445 std::cout <<
"# Error at operation: upper triangular solver" << std::endl;
446 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
447 retval = EXIT_FAILURE;
451 std::cout <<
"Transposed unit upper triangular solver" << std::endl;
455 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
457 std::cout <<
"# Error at operation: unit upper triangular solver" << std::endl;
458 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
459 retval = EXIT_FAILURE;
463 std::cout <<
"Transposed lower triangular solver" << std::endl;
467 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
469 std::cout <<
"# Error at operation: lower triangular solver" << std::endl;
470 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
471 retval = EXIT_FAILURE;
475 std::cout <<
"Transposed unit lower triangular solver" << std::endl;
479 if ( std::fabs(
diff(ublas_v1, vcl_v1)) > epsilon )
481 std::cout <<
"# Error at operation: unit lower triangular solver" << std::endl;
482 std::cout <<
" diff: " << std::fabs(
diff(ublas_v1, vcl_v1)) << std::endl;
483 retval = EXIT_FAILURE;
493 template<
typename NumericT,
typename F,
typename Epsilon >
494 int test(Epsilon
const& epsilon)
496 int retval = EXIT_SUCCESS;
500 std::size_t num_rows = 141;
501 std::size_t num_cols = 103;
504 ublas::vector<NumericT> ublas_v1(num_rows);
505 for (std::size_t i = 0; i < ublas_v1.size(); ++i)
506 ublas_v1(i) = randomNumber();
507 ublas::vector<NumericT> ublas_v2 = ublas::scalar_vector<NumericT>(num_cols,
NumericT(3.1415));
510 ublas::matrix<NumericT> ublas_m1(ublas_v1.size(), ublas_v2.size());
512 for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
513 for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
514 ublas_m1(i,j) =
static_cast<NumericT>(0.1) * randomNumber();
517 ublas::matrix<NumericT> ublas_m2(ublas_v1.size(), ublas_v1.size());
519 for (std::size_t i = 0; i < ublas_m2.size1(); ++i)
521 for (std::size_t j = 0; j < ublas_m2.size2(); ++j)
522 ublas_m2(i,j) =
static_cast<NumericT>(-0.1) * randomNumber();
523 ublas_m2(i, i) =
static_cast<NumericT>(2) + randomNumber();
593 std::cout <<
"------------ Testing rank-1-updates and matrix-vector products ------------------" << std::endl;
595 std::cout <<
"* m = full, v1 = full, v2 = full" << std::endl;
596 retval = test_prod_rank1<NumericT>(epsilon,
597 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
598 vcl_m1_native, vcl_v1_native, vcl_v2_native, vcl_m2_native);
599 if (retval == EXIT_FAILURE)
601 std::cout <<
" --- FAILED! ---" << std::endl;
605 std::cout <<
" --- PASSED ---" << std::endl;
608 std::cout <<
"* m = full, v1 = full, v2 = range" << std::endl;
609 retval = test_prod_rank1<NumericT>(epsilon,
610 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
611 vcl_m1_native, vcl_v1_native, vcl_v2_range, vcl_m2_native);
612 if (retval == EXIT_FAILURE)
614 std::cout <<
" --- FAILED! ---" << std::endl;
618 std::cout <<
" --- PASSED ---" << std::endl;
621 std::cout <<
"* m = full, v1 = full, v2 = slice" << std::endl;
622 retval = test_prod_rank1<NumericT>(epsilon,
623 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
624 vcl_m1_native, vcl_v1_native, vcl_v2_slice, vcl_m2_native);
625 if (retval == EXIT_FAILURE)
627 std::cout <<
" --- FAILED! ---" << std::endl;
631 std::cout <<
" --- PASSED ---" << std::endl;
637 std::cout <<
"* m = full, v1 = range, v2 = full" << std::endl;
638 retval = test_prod_rank1<NumericT>(epsilon,
639 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
640 vcl_m1_native, vcl_v1_range, vcl_v2_native, vcl_m2_native);
641 if (retval == EXIT_FAILURE)
643 std::cout <<
" --- FAILED! ---" << std::endl;
647 std::cout <<
" --- PASSED ---" << std::endl;
650 std::cout <<
"* m = full, v1 = range, v2 = range" << std::endl;
651 retval = test_prod_rank1<NumericT>(epsilon,
652 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
653 vcl_m1_native, vcl_v1_range, vcl_v2_range, vcl_m2_native);
654 if (retval == EXIT_FAILURE)
656 std::cout <<
" --- FAILED! ---" << std::endl;
660 std::cout <<
" --- PASSED ---" << std::endl;
663 std::cout <<
"* m = full, v1 = range, v2 = slice" << std::endl;
664 retval = test_prod_rank1<NumericT>(epsilon,
665 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
666 vcl_m1_native, vcl_v1_range, vcl_v2_slice, vcl_m2_native);
667 if (retval == EXIT_FAILURE)
669 std::cout <<
" --- FAILED! ---" << std::endl;
673 std::cout <<
" --- PASSED ---" << std::endl;
679 std::cout <<
"* m = full, v1 = slice, v2 = full" << std::endl;
680 retval = test_prod_rank1<NumericT>(epsilon,
681 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
682 vcl_m1_native, vcl_v1_slice, vcl_v2_native, vcl_m2_native);
683 if (retval == EXIT_FAILURE)
685 std::cout <<
" --- FAILED! ---" << std::endl;
689 std::cout <<
" --- PASSED ---" << std::endl;
692 std::cout <<
"* m = full, v1 = slice, v2 = range" << std::endl;
693 retval = test_prod_rank1<NumericT>(epsilon,
694 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
695 vcl_m1_native, vcl_v1_slice, vcl_v2_range, vcl_m2_native);
696 if (retval == EXIT_FAILURE)
698 std::cout <<
" --- FAILED! ---" << std::endl;
702 std::cout <<
" --- PASSED ---" << std::endl;
705 std::cout <<
"* m = full, v1 = slice, v2 = slice" << std::endl;
706 retval = test_prod_rank1<NumericT>(epsilon,
707 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
708 vcl_m1_native, vcl_v1_slice, vcl_v2_slice, vcl_m2_native);
709 if (retval == EXIT_FAILURE)
711 std::cout <<
" --- FAILED! ---" << std::endl;
715 std::cout <<
" --- PASSED ---" << std::endl;
720 std::cout <<
"* m = range, v1 = full, v2 = full" << std::endl;
721 retval = test_prod_rank1<NumericT>(epsilon,
722 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
723 vcl_m1_range, vcl_v1_native, vcl_v2_native, vcl_m2_range);
724 if (retval == EXIT_FAILURE)
726 std::cout <<
" --- FAILED! ---" << std::endl;
730 std::cout <<
" --- PASSED ---" << std::endl;
733 std::cout <<
"* m = range, v1 = full, v2 = range" << std::endl;
734 retval = test_prod_rank1<NumericT>(epsilon,
735 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
736 vcl_m1_range, vcl_v1_native, vcl_v2_range, vcl_m2_range);
737 if (retval == EXIT_FAILURE)
739 std::cout <<
" --- FAILED! ---" << std::endl;
743 std::cout <<
" --- PASSED ---" << std::endl;
746 std::cout <<
"* m = range, v1 = full, v2 = slice" << std::endl;
747 retval = test_prod_rank1<NumericT>(epsilon,
748 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
749 vcl_m1_range, vcl_v1_native, vcl_v2_slice, vcl_m2_range);
750 if (retval == EXIT_FAILURE)
752 std::cout <<
" --- FAILED! ---" << std::endl;
756 std::cout <<
" --- PASSED ---" << std::endl;
762 std::cout <<
"* m = range, v1 = range, v2 = full" << std::endl;
763 retval = test_prod_rank1<NumericT>(epsilon,
764 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
765 vcl_m1_range, vcl_v1_range, vcl_v2_native, vcl_m2_range);
766 if (retval == EXIT_FAILURE)
768 std::cout <<
" --- FAILED! ---" << std::endl;
772 std::cout <<
" --- PASSED ---" << std::endl;
775 std::cout <<
"* m = range, v1 = range, v2 = range" << std::endl;
776 retval = test_prod_rank1<NumericT>(epsilon,
777 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
778 vcl_m1_range, vcl_v1_range, vcl_v2_range, vcl_m2_range);
779 if (retval == EXIT_FAILURE)
781 std::cout <<
" --- FAILED! ---" << std::endl;
785 std::cout <<
" --- PASSED ---" << std::endl;
788 std::cout <<
"* m = range, v1 = range, v2 = slice" << std::endl;
789 retval = test_prod_rank1<NumericT>(epsilon,
790 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
791 vcl_m1_range, vcl_v1_range, vcl_v2_slice, vcl_m2_range);
792 if (retval == EXIT_FAILURE)
794 std::cout <<
" --- FAILED! ---" << std::endl;
798 std::cout <<
" --- PASSED ---" << std::endl;
804 std::cout <<
"* m = range, v1 = slice, v2 = full" << std::endl;
805 retval = test_prod_rank1<NumericT>(epsilon,
806 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
807 vcl_m1_range, vcl_v1_slice, vcl_v2_native, vcl_m2_range);
808 if (retval == EXIT_FAILURE)
810 std::cout <<
" --- FAILED! ---" << std::endl;
814 std::cout <<
" --- PASSED ---" << std::endl;
817 std::cout <<
"* m = range, v1 = slice, v2 = range" << std::endl;
818 retval = test_prod_rank1<NumericT>(epsilon,
819 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
820 vcl_m1_range, vcl_v1_slice, vcl_v2_range, vcl_m2_range);
821 if (retval == EXIT_FAILURE)
823 std::cout <<
" --- FAILED! ---" << std::endl;
827 std::cout <<
" --- PASSED ---" << std::endl;
830 std::cout <<
"* m = range, v1 = slice, v2 = slice" << std::endl;
831 retval = test_prod_rank1<NumericT>(epsilon,
832 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
833 vcl_m1_range, vcl_v1_slice, vcl_v2_slice, vcl_m2_range);
834 if (retval == EXIT_FAILURE)
836 std::cout <<
" --- FAILED! ---" << std::endl;
840 std::cout <<
" --- PASSED ---" << std::endl;
845 std::cout <<
"* m = slice, v1 = full, v2 = full" << std::endl;
846 retval = test_prod_rank1<NumericT>(epsilon,
847 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
848 vcl_m1_slice, vcl_v1_native, vcl_v2_native, vcl_m2_slice);
849 if (retval == EXIT_FAILURE)
851 std::cout <<
" --- FAILED! ---" << std::endl;
855 std::cout <<
" --- PASSED ---" << std::endl;
858 std::cout <<
"* m = slice, v1 = full, v2 = range" << std::endl;
859 retval = test_prod_rank1<NumericT>(epsilon,
860 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
861 vcl_m1_slice, vcl_v1_native, vcl_v2_range, vcl_m2_slice);
862 if (retval == EXIT_FAILURE)
864 std::cout <<
" --- FAILED! ---" << std::endl;
868 std::cout <<
" --- PASSED ---" << std::endl;
871 std::cout <<
"* m = slice, v1 = full, v2 = slice" << std::endl;
872 retval = test_prod_rank1<NumericT>(epsilon,
873 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
874 vcl_m1_slice, vcl_v1_native, vcl_v2_slice, vcl_m2_slice);
875 if (retval == EXIT_FAILURE)
877 std::cout <<
" --- FAILED! ---" << std::endl;
881 std::cout <<
" --- PASSED ---" << std::endl;
887 std::cout <<
"* m = slice, v1 = range, v2 = full" << std::endl;
888 retval = test_prod_rank1<NumericT>(epsilon,
889 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
890 vcl_m1_slice, vcl_v1_range, vcl_v2_native, vcl_m2_slice);
891 if (retval == EXIT_FAILURE)
893 std::cout <<
" --- FAILED! ---" << std::endl;
897 std::cout <<
" --- PASSED ---" << std::endl;
900 std::cout <<
"* m = slice, v1 = range, v2 = range" << std::endl;
901 retval = test_prod_rank1<NumericT>(epsilon,
902 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
903 vcl_m1_slice, vcl_v1_range, vcl_v2_range, vcl_m2_slice);
904 if (retval == EXIT_FAILURE)
906 std::cout <<
" --- FAILED! ---" << std::endl;
910 std::cout <<
" --- PASSED ---" << std::endl;
913 std::cout <<
"* m = slice, v1 = range, v2 = slice" << std::endl;
914 retval = test_prod_rank1<NumericT>(epsilon,
915 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
916 vcl_m1_slice, vcl_v1_range, vcl_v2_slice, vcl_m2_slice);
917 if (retval == EXIT_FAILURE)
919 std::cout <<
" --- FAILED! ---" << std::endl;
923 std::cout <<
" --- PASSED ---" << std::endl;
929 std::cout <<
"* m = slice, v1 = slice, v2 = full" << std::endl;
930 retval = test_prod_rank1<NumericT>(epsilon,
931 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
932 vcl_m1_slice, vcl_v1_slice, vcl_v2_native, vcl_m2_slice);
933 if (retval == EXIT_FAILURE)
935 std::cout <<
" --- FAILED! ---" << std::endl;
939 std::cout <<
" --- PASSED ---" << std::endl;
942 std::cout <<
"* m = slice, v1 = slice, v2 = range" << std::endl;
943 retval = test_prod_rank1<NumericT>(epsilon,
944 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
945 vcl_m1_slice, vcl_v1_slice, vcl_v2_range, vcl_m2_slice);
946 if (retval == EXIT_FAILURE)
948 std::cout <<
" --- FAILED! ---" << std::endl;
952 std::cout <<
" --- PASSED ---" << std::endl;
955 std::cout <<
"* m = slice, v1 = slice, v2 = slice" << std::endl;
956 retval = test_prod_rank1<NumericT>(epsilon,
957 ublas_m1, ublas_v1, ublas_v2, ublas_m2,
958 vcl_m1_slice, vcl_v1_slice, vcl_v2_slice, vcl_m2_slice);
959 if (retval == EXIT_FAILURE)
961 std::cout <<
" --- FAILED! ---" << std::endl;
965 std::cout <<
" --- PASSED ---" << std::endl;
973 std::cout <<
"------------ Testing triangular solves ------------------" << std::endl;
975 std::cout <<
"* m = full, v1 = full" << std::endl;
976 retval = test_solve<NumericT>(epsilon,
978 vcl_m2_native, vcl_v1_native);
979 if (retval == EXIT_FAILURE)
981 std::cout <<
" --- FAILED! ---" << std::endl;
985 std::cout <<
" --- PASSED ---" << std::endl;
987 std::cout <<
"* m = full, v1 = range" << std::endl;
988 retval = test_solve<NumericT>(epsilon,
990 vcl_m2_native, vcl_v1_range);
991 if (retval == EXIT_FAILURE)
993 std::cout <<
" --- FAILED! ---" << std::endl;
997 std::cout <<
" --- PASSED ---" << std::endl;
999 std::cout <<
"* m = full, v1 = slice" << std::endl;
1000 retval = test_solve<NumericT>(epsilon,
1002 vcl_m2_native, vcl_v1_slice);
1003 if (retval == EXIT_FAILURE)
1005 std::cout <<
" --- FAILED! ---" << std::endl;
1009 std::cout <<
" --- PASSED ---" << std::endl;
1014 std::cout <<
"* m = range, v1 = full" << std::endl;
1015 retval = test_solve<NumericT>(epsilon,
1017 vcl_m2_range, vcl_v1_native);
1018 if (retval == EXIT_FAILURE)
1020 std::cout <<
" --- FAILED! ---" << std::endl;
1024 std::cout <<
" --- PASSED ---" << std::endl;
1026 std::cout <<
"* m = range, v1 = range" << std::endl;
1027 retval = test_solve<NumericT>(epsilon,
1029 vcl_m2_range, vcl_v1_range);
1030 if (retval == EXIT_FAILURE)
1032 std::cout <<
" --- FAILED! ---" << std::endl;
1036 std::cout <<
" --- PASSED ---" << std::endl;
1038 std::cout <<
"* m = range, v1 = slice" << std::endl;
1039 retval = test_solve<NumericT>(epsilon,
1041 vcl_m2_range, vcl_v1_slice);
1042 if (retval == EXIT_FAILURE)
1044 std::cout <<
" --- FAILED! ---" << std::endl;
1048 std::cout <<
" --- PASSED ---" << std::endl;
1052 std::cout <<
"* m = slice, v1 = full" << std::endl;
1053 retval = test_solve<NumericT>(epsilon,
1055 vcl_m2_slice, vcl_v1_native);
1056 if (retval == EXIT_FAILURE)
1058 std::cout <<
" --- FAILED! ---" << std::endl;
1062 std::cout <<
" --- PASSED ---" << std::endl;
1064 std::cout <<
"* m = slice, v1 = range" << std::endl;
1065 retval = test_solve<NumericT>(epsilon,
1067 vcl_m2_slice, vcl_v1_range);
1068 if (retval == EXIT_FAILURE)
1070 std::cout <<
" --- FAILED! ---" << std::endl;
1074 std::cout <<
" --- PASSED ---" << std::endl;
1076 std::cout <<
"* m = slice, v1 = slice" << std::endl;
1077 retval = test_solve<NumericT>(epsilon,
1079 vcl_m2_slice, vcl_v1_slice);
1080 if (retval == EXIT_FAILURE)
1082 std::cout <<
" --- FAILED! ---" << std::endl;
1086 std::cout <<
" --- PASSED ---" << std::endl;
1097 std::cout <<
"Full solver" << std::endl;
1098 unsigned int lu_dim = 100;
1099 ublas::matrix<NumericT> square_matrix(lu_dim, lu_dim);
1100 ublas::vector<NumericT> lu_rhs(lu_dim);
1104 for (std::size_t i=0; i<lu_dim; ++i)
1105 for (std::size_t j=0; j<lu_dim; ++j)
1106 square_matrix(i,j) = -
static_cast<NumericT>(0.5) * randomNumber();
1109 for (std::size_t j=0; j<lu_dim; ++j)
1111 square_matrix(j,j) =
static_cast<NumericT>(20.0) + randomNumber();
1112 lu_rhs(j) = randomNumber();
1128 if ( std::fabs(
diff(lu_rhs, vcl_lu_rhs)) > epsilon )
1130 std::cout <<
"# Error at operation: dense solver" << std::endl;
1131 std::cout <<
" diff: " << std::fabs(
diff(lu_rhs, vcl_lu_rhs)) << std::endl;
1132 retval = EXIT_FAILURE;
1144 std::cout << std::endl;
1145 std::cout <<
"----------------------------------------------" << std::endl;
1146 std::cout <<
"----------------------------------------------" << std::endl;
1147 std::cout <<
"## Test :: Matrix" << std::endl;
1148 std::cout <<
"----------------------------------------------" << std::endl;
1149 std::cout <<
"----------------------------------------------" << std::endl;
1150 std::cout << std::endl;
1152 int retval = EXIT_SUCCESS;
1170 std::cout << std::endl;
1171 std::cout <<
"----------------------------------------------" << std::endl;
1172 std::cout << std::endl;
1175 NumericT epsilon =
NumericT(1.0E-3);
1176 std::cout <<
"# Testing setup:" << std::endl;
1177 std::cout <<
" eps: " << epsilon << std::endl;
1178 std::cout <<
" numeric: float" << std::endl;
1179 std::cout <<
" layout: column-major" << std::endl;
1180 retval = test<NumericT, viennacl::column_major>(epsilon);
1181 if ( retval == EXIT_SUCCESS )
1182 std::cout <<
"# Test passed" << std::endl;
1186 std::cout << std::endl;
1187 std::cout <<
"----------------------------------------------" << std::endl;
1188 std::cout << std::endl;
1191 #ifdef VIENNACL_WITH_OPENCL
1197 NumericT epsilon = 1.0E-11;
1198 std::cout <<
"# Testing setup:" << std::endl;
1199 std::cout <<
" eps: " << epsilon << std::endl;
1200 std::cout <<
" numeric: double" << std::endl;
1201 std::cout <<
" layout: row-major" << std::endl;
1202 retval = test<NumericT, viennacl::row_major>(epsilon);
1203 if ( retval == EXIT_SUCCESS )
1204 std::cout <<
"# Test passed" << std::endl;
1208 std::cout << std::endl;
1209 std::cout <<
"----------------------------------------------" << std::endl;
1210 std::cout << std::endl;
1213 NumericT epsilon = 1.0E-11;
1214 std::cout <<
"# Testing setup:" << std::endl;
1215 std::cout <<
" eps: " << epsilon << std::endl;
1216 std::cout <<
" numeric: double" << std::endl;
1217 std::cout <<
" layout: column-major" << std::endl;
1218 retval = test<NumericT, viennacl::column_major>(epsilon);
1219 if ( retval == EXIT_SUCCESS )
1220 std::cout <<
"# Test passed" << std::endl;
1224 std::cout << std::endl;
1225 std::cout <<
"----------------------------------------------" << std::endl;
1226 std::cout << std::endl;
1229 std::cout << std::endl;
1230 std::cout <<
"------- Test completed --------" << std::endl;
1231 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.
viennacl::vector_expression< const viennacl::matrix_base< NumericT >, const viennacl::matrix_base< NumericT >, viennacl::op_row_sum > row_sum(viennacl::matrix_base< NumericT > const &A)
User interface function for computing the sum of all elements of each row of a matrix.
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.
VectorT solve(MatrixT const &matrix, VectorT const &rhs, bicgstab_tag const &tag, PreconditionerT const &precond)
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.
Stub routines for the summation of elements in a vector, or all elements in either a row or column of...
viennacl::vector< int > v2
void prod(std::vector< std::map< IndexT, NumericT > > const &stl_A, std::vector< std::map< IndexT, NumericT > > const &stl_B, std::vector< std::map< IndexT, NumericT > > &stl_C)
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) ...
A small collection of sequential random number generators.
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.
viennacl::vector_expression< const viennacl::matrix_base< NumericT >, const viennacl::matrix_base< NumericT >, viennacl::op_col_sum > column_sum(viennacl::matrix_base< NumericT > const &A)
User interface function for computing the sum of all elements of each column of a matrix...
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.