36 #include <boost/numeric/ublas/io.hpp>
37 #include <boost/numeric/ublas/triangular.hpp>
38 #include <boost/numeric/ublas/matrix_sparse.hpp>
39 #include <boost/numeric/ublas/matrix.hpp>
40 #include <boost/numeric/ublas/matrix_proxy.hpp>
41 #include <boost/numeric/ublas/lu.hpp>
42 #include <boost/numeric/ublas/io.hpp>
43 #include <boost/numeric/ublas/operation_sparse.hpp>
44 #include <boost/numeric/ublas/vector_proxy.hpp>
50 #define VIENNACL_WITH_UBLAS 1
75 template<
typename ScalarType>
79 return (s1 - s2) /
std::max(fabs(s1), std::fabs(s2));
83 template<
typename ScalarType>
86 ublas::vector<ScalarType> v2_cpu(v2.
size());
90 for (
unsigned int i=0;i<v1.size(); ++i)
92 if (
std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 )
97 v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) /
std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) );
102 if (v2_cpu[i] > 0.0001)
105 std::cout <<
"Error at entry " << i <<
": Should: " << v1[i] <<
" vs. Is: " << v2[i] << std::endl;
115 template<
typename ScalarType,
typename VCL_MATRIX>
116 ScalarType diff(ublas::compressed_matrix<ScalarType> & cpu_matrix, VCL_MATRIX & gpu_matrix)
118 typedef ublas::compressed_matrix<ScalarType> CPU_MATRIX;
119 CPU_MATRIX from_gpu(gpu_matrix.size1(), gpu_matrix.size2());
128 for (
typename CPU_MATRIX::const_iterator1 row_it = cpu_matrix.begin1();
129 row_it != cpu_matrix.end1();
133 for (
typename CPU_MATRIX::const_iterator2 col_it = row_it.begin();
134 col_it != row_it.end();
140 if (
std::max( std::fabs(cpu_matrix(col_it.index1(), col_it.index2())),
141 std::fabs(from_gpu(col_it.index1(), col_it.index2())) ) > 0 )
142 current_error = std::fabs(cpu_matrix(col_it.index1(), col_it.index2()) - from_gpu(col_it.index1(), col_it.index2()))
143 /
std::max( std::fabs(cpu_matrix(col_it.index1(), col_it.index2())),
144 std::fabs(from_gpu(col_it.index1(), col_it.index2())) );
145 if (current_error > error)
146 error = current_error;
152 for (
typename CPU_MATRIX::const_iterator1 row_it = from_gpu.begin1();
153 row_it != from_gpu.end1();
157 for (
typename CPU_MATRIX::const_iterator2 col_it = row_it.begin();
158 col_it != row_it.end();
164 if (
std::max( std::fabs(cpu_matrix(col_it.index1(), col_it.index2())),
165 std::fabs(from_gpu(col_it.index1(), col_it.index2())) ) > 0 )
166 current_error = std::fabs(cpu_matrix(col_it.index1(), col_it.index2()) - from_gpu(col_it.index1(), col_it.index2()))
167 /
std::max( std::fabs(cpu_matrix(col_it.index1(), col_it.index2())),
168 std::fabs(from_gpu(col_it.index1(), col_it.index2())) );
169 if (current_error > error)
170 error = current_error;
178 template<
typename NumericT,
typename VCL_MatrixT,
typename Epsilon,
typename UblasVectorT,
typename VCLVectorT>
180 UblasVectorT & result, UblasVectorT
const & rhs,
181 VCLVectorT & vcl_result, VCLVectorT & vcl_rhs)
183 int retval = EXIT_SUCCESS;
185 ublas::compressed_matrix<NumericT> ublas_matrix2(5, 4);
186 ublas_matrix2(0, 0) = NumericT(2.0); ublas_matrix2(0, 2) = NumericT(-1.0);
187 ublas_matrix2(1, 0) = NumericT(3.0); ublas_matrix2(1, 2) = NumericT(-5.0);
188 ublas_matrix2(2, 1) = NumericT(5.0); ublas_matrix2(2, 2) = NumericT(-2.0);
189 ublas_matrix2(3, 2) = NumericT(1.0); ublas_matrix2(3, 3) = NumericT(-6.0);
190 ublas_matrix2(4, 1) = NumericT(7.0); ublas_matrix2(4, 2) = NumericT(-5.0);
193 VCL_MatrixT vcl_sparse_matrix2;
202 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
204 std::cout <<
"# Error at operation: matrix-vector product with stided vectors, part 1" << std::endl;
205 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
206 retval = EXIT_FAILURE;
208 vcl_result(1) = NumericT(1.0);
209 vcl_result(4) = NumericT(1.0);
210 vcl_result(7) = NumericT(1.0);
211 vcl_result(10) = NumericT(1.0);
212 vcl_result(13) = NumericT(1.0);
216 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
218 std::cout <<
"# Error at operation: matrix-vector product with strided vectors, part 2" << std::endl;
219 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
220 retval = EXIT_FAILURE;
227 template<
typename NumericT,
typename VCL_MATRIX,
typename Epsilon >
230 int retval = EXIT_SUCCESS;
232 ublas::compressed_matrix<NumericT> ublas_matrix(5,5);
233 VCL_MATRIX vcl_matrix;
235 ublas_matrix(0,0) = NumericT(10.0); ublas_matrix(0, 1) = NumericT(0.1); ublas_matrix(0, 2) = NumericT(0.2); ublas_matrix(0, 3) = NumericT(0.3); ublas_matrix(0, 4) = NumericT(0.4);
236 ublas_matrix(1,0) = NumericT(1.0); ublas_matrix(1, 1) = NumericT(1.1); ublas_matrix(1, 2) = NumericT(1.2); ublas_matrix(1, 3) = NumericT(1.3); ublas_matrix(1, 4) = NumericT(1.4);
237 ublas_matrix(2,0) = NumericT(2.0); ublas_matrix(2, 1) = NumericT(2.1); ublas_matrix(2, 2) = NumericT(2.2); ublas_matrix(2, 3) = NumericT(2.3); ublas_matrix(2, 4) = NumericT(2.4);
238 ublas_matrix(3,0) = NumericT(3.0); ublas_matrix(3, 1) = NumericT(3.1); ublas_matrix(3, 2) = NumericT(3.2); ublas_matrix(3, 3) = NumericT(3.3); ublas_matrix(3, 4) = NumericT(3.4);
239 ublas_matrix(4,0) = NumericT(4.0); ublas_matrix(4, 1) = NumericT(4.1); ublas_matrix(4, 2) = NumericT(4.2); ublas_matrix(4, 3) = NumericT(4.3); ublas_matrix(4, 4) = NumericT(4.4);
242 ublas::compressed_matrix<NumericT> other_matrix(ublas_matrix.size1(), ublas_matrix.size2());
245 std::cout <<
"Checking for equality after copy..." << std::endl;
246 if ( std::fabs(
diff(ublas_matrix, vcl_matrix)) > epsilon )
248 std::cout <<
"# Error at operation: equality after copy with sparse matrix" << std::endl;
249 std::cout <<
" diff: " << std::fabs(
diff(ublas_matrix, vcl_matrix)) << std::endl;
253 std::cout <<
"Testing resize to larger..." << std::endl;
254 ublas_matrix.resize(10, 10,
false);
255 ublas_matrix(0,0) = NumericT(10.0); ublas_matrix(0, 1) = NumericT(0.1); ublas_matrix(0, 2) = NumericT(0.2); ublas_matrix(0, 3) = NumericT(0.3); ublas_matrix(0, 4) = NumericT(0.4);
256 ublas_matrix(1,0) = NumericT( 1.0); ublas_matrix(1, 1) = NumericT(1.1); ublas_matrix(1, 2) = NumericT(1.2); ublas_matrix(1, 3) = NumericT(1.3); ublas_matrix(1, 4) = NumericT(1.4);
257 ublas_matrix(2,0) = NumericT( 2.0); ublas_matrix(2, 1) = NumericT(2.1); ublas_matrix(2, 2) = NumericT(2.2); ublas_matrix(2, 3) = NumericT(2.3); ublas_matrix(2, 4) = NumericT(2.4);
258 ublas_matrix(3,0) = NumericT( 3.0); ublas_matrix(3, 1) = NumericT(3.1); ublas_matrix(3, 2) = NumericT(3.2); ublas_matrix(3, 3) = NumericT(3.3); ublas_matrix(3, 4) = NumericT(3.4);
259 ublas_matrix(4,0) = NumericT( 4.0); ublas_matrix(4, 1) = NumericT(4.1); ublas_matrix(4, 2) = NumericT(4.2); ublas_matrix(4, 3) = NumericT(4.3); ublas_matrix(4, 4) = NumericT(4.4);
262 vcl_matrix.resize(10, 10,
true);
264 if ( std::fabs(
diff(ublas_matrix, vcl_matrix)) > epsilon )
266 std::cout <<
"# Error at operation: resize (to larger) with sparse matrix" << std::endl;
267 std::cout <<
" diff: " << std::fabs(
diff(ublas_matrix, vcl_matrix)) << std::endl;
271 ublas_matrix(5,5) = NumericT(5.5); ublas_matrix(5, 6) = NumericT(5.6); ublas_matrix(5, 7) = NumericT(5.7); ublas_matrix(5, 8) = NumericT(5.8); ublas_matrix(5, 9) = NumericT(5.9);
272 ublas_matrix(6,5) = NumericT(6.5); ublas_matrix(6, 6) = NumericT(6.6); ublas_matrix(6, 7) = NumericT(6.7); ublas_matrix(6, 8) = NumericT(6.8); ublas_matrix(6, 9) = NumericT(6.9);
273 ublas_matrix(7,5) = NumericT(7.5); ublas_matrix(7, 6) = NumericT(7.6); ublas_matrix(7, 7) = NumericT(7.7); ublas_matrix(7, 8) = NumericT(7.8); ublas_matrix(7, 9) = NumericT(7.9);
274 ublas_matrix(8,5) = NumericT(8.5); ublas_matrix(8, 6) = NumericT(8.6); ublas_matrix(8, 7) = NumericT(8.7); ublas_matrix(8, 8) = NumericT(8.8); ublas_matrix(8, 9) = NumericT(8.9);
275 ublas_matrix(9,5) = NumericT(9.5); ublas_matrix(9, 6) = NumericT(9.6); ublas_matrix(9, 7) = NumericT(9.7); ublas_matrix(9, 8) = NumericT(9.8); ublas_matrix(9, 9) = NumericT(9.9);
278 std::cout <<
"Testing resize to smaller..." << std::endl;
279 ublas_matrix.resize(7, 7,
false);
280 ublas_matrix(0,0) = NumericT(10.0); ublas_matrix(0, 1) = NumericT(0.1); ublas_matrix(0, 2) = NumericT(0.2); ublas_matrix(0, 3) = NumericT(0.3); ublas_matrix(0, 4) = NumericT(0.4);
281 ublas_matrix(1,0) = NumericT( 1.0); ublas_matrix(1, 1) = NumericT(1.1); ublas_matrix(1, 2) = NumericT(1.2); ublas_matrix(1, 3) = NumericT(1.3); ublas_matrix(1, 4) = NumericT(1.4);
282 ublas_matrix(2,0) = NumericT( 2.0); ublas_matrix(2, 1) = NumericT(2.1); ublas_matrix(2, 2) = NumericT(2.2); ublas_matrix(2, 3) = NumericT(2.3); ublas_matrix(2, 4) = NumericT(2.4);
283 ublas_matrix(3,0) = NumericT( 3.0); ublas_matrix(3, 1) = NumericT(3.1); ublas_matrix(3, 2) = NumericT(3.2); ublas_matrix(3, 3) = NumericT(3.3); ublas_matrix(3, 4) = NumericT(3.4);
284 ublas_matrix(4,0) = NumericT( 4.0); ublas_matrix(4, 1) = NumericT(4.1); ublas_matrix(4, 2) = NumericT(4.2); ublas_matrix(4, 3) = NumericT(4.3); ublas_matrix(4, 4) = NumericT(4.4);
285 ublas_matrix(5,5) = NumericT( 5.5); ublas_matrix(5, 6) = NumericT(5.6); ublas_matrix(5, 7) = NumericT(5.7); ublas_matrix(5, 8) = NumericT(5.8); ublas_matrix(5, 9) = NumericT(5.9);
286 ublas_matrix(6,5) = NumericT( 6.5); ublas_matrix(6, 6) = NumericT(6.6); ublas_matrix(6, 7) = NumericT(6.7); ublas_matrix(6, 8) = NumericT(6.8); ublas_matrix(6, 9) = NumericT(6.9);
288 vcl_matrix.resize(7, 7);
291 if ( std::fabs(
diff(ublas_matrix, vcl_matrix)) > epsilon )
293 std::cout <<
"# Error at operation: resize (to smaller) with sparse matrix" << std::endl;
294 std::cout <<
" diff: " << std::fabs(
diff(ublas_matrix, vcl_matrix)) << std::endl;
295 retval = EXIT_FAILURE;
298 ublas::vector<NumericT> ublas_vec = ublas::scalar_vector<NumericT>(ublas_matrix.size1(), NumericT(3.1415));
302 std::cout <<
"Testing transposed unit lower triangular solve: compressed_matrix" << std::endl;
304 std::cout <<
"matrix: " << ublas_matrix << std::endl;
305 std::cout <<
"vector: " << ublas_vec << std::endl;
306 std::cout <<
"ViennaCL matrix size: " << vcl_matrix.size1() <<
" x " << vcl_matrix.size2() << std::endl;
308 std::cout <<
"ublas..." << std::endl;
310 std::cout <<
"ViennaCL..." << std::endl;
365 for (std::size_t i=0; i<ublas_vec.size(); ++i)
367 std::cout << ublas_vec[i] <<
" vs. " << vcl_vec[i] << std::endl;
393 template<
typename NumericT,
typename Epsilon >
394 int test(Epsilon
const& epsilon)
396 std::cout <<
"Testing resizing of compressed_matrix..." << std::endl;
397 int retval = resize_test<NumericT, viennacl::compressed_matrix<NumericT> >(epsilon);
398 if (retval != EXIT_SUCCESS)
400 std::cout <<
"Testing resizing of coordinate_matrix..." << std::endl;
407 ublas::vector<NumericT> rhs;
408 ublas::vector<NumericT> result;
409 ublas::compressed_matrix<NumericT> ublas_matrix;
413 std::cout <<
"Error reading Matrix file" << std::endl;
418 std::cout <<
"done reading matrix" << std::endl;
421 rhs.resize(ublas_matrix.size2());
422 for (std::size_t i=0; i<rhs.size(); ++i)
424 ublas_matrix(i,i) = NumericT(0.5);
425 rhs[i] = NumericT(1) + random<NumericT>();
429 ublas::compressed_matrix<NumericT> ublas_cc_matrix(ublas_matrix.size1(), ublas_matrix.size2());
430 ublas_cc_matrix(42,199) = NumericT(3.1415);
431 ublas_cc_matrix(31, 69) = NumericT(2.71);
432 ublas_cc_matrix(23, 32) = NumericT(6);
433 ublas_cc_matrix(177,57) = NumericT(4);
434 ublas_cc_matrix(21, 97) = NumericT(-4);
435 ublas_cc_matrix(92, 25) = NumericT(2);
436 ublas_cc_matrix(89, 62) = NumericT(11);
437 ublas_cc_matrix(1, 7) = NumericT(8);
438 ublas_cc_matrix(85, 41) = NumericT(13);
439 ublas_cc_matrix(66, 28) = NumericT(8);
440 ublas_cc_matrix(21, 74) = NumericT(-2);
458 viennacl::copy(ublas_cc_matrix, vcl_compressed_compressed_matrix);
462 std::cout <<
"Testing products: ublas" << std::endl;
465 std::cout <<
"Testing products: compressed_matrix" << std::endl;
468 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
470 std::cout <<
"# Error at operation: matrix-vector product with compressed_matrix" << std::endl;
471 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
472 retval = EXIT_FAILURE;
475 std::cout <<
"Testing products: compressed_matrix, strided vectors" << std::endl;
476 retval = strided_matrix_vector_product_test<NumericT, viennacl::compressed_matrix<NumericT> >(epsilon, result, rhs, vcl_result, vcl_rhs);
477 if (retval != EXIT_SUCCESS)
483 ublas::compressed_matrix<NumericT> ublas_matrix_trans(ublas_matrix.size2(), ublas_matrix.size1(), ublas_matrix.nnz());
486 for (
typename ublas::compressed_matrix<NumericT>::iterator1 row_it = ublas_matrix.begin1();
487 row_it != ublas_matrix.end1();
490 for (
typename ublas::compressed_matrix<NumericT>::iterator2 col_it = row_it.begin();
491 col_it != row_it.end();
494 ublas_matrix_trans(col_it.index1(), col_it.index2()) = *col_it;
499 std::cout <<
"Testing unit upper triangular solve: compressed_matrix" << std::endl;
505 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
507 std::cout <<
"# Error at operation: unit upper triangular solve with compressed_matrix" << std::endl;
508 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
509 retval = EXIT_FAILURE;
512 std::cout <<
"Testing upper triangular solve: compressed_matrix" << std::endl;
518 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
520 std::cout <<
"# Error at operation: upper triangular solve with compressed_matrix" << std::endl;
521 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
522 retval = EXIT_FAILURE;
525 std::cout <<
"Testing unit lower triangular solve: compressed_matrix" << std::endl;
559 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
561 std::cout <<
"# Error at operation: unit lower triangular solve with compressed_matrix" << std::endl;
562 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
563 retval = EXIT_FAILURE;
567 std::cout <<
"Testing lower triangular solve: compressed_matrix" << std::endl;
598 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
600 std::cout <<
"# Error at operation: lower triangular solve with compressed_matrix" << std::endl;
601 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
602 retval = EXIT_FAILURE;
623 std::cout <<
"Testing transposed unit upper triangular solve: compressed_matrix" << std::endl;
629 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
631 std::cout <<
"# Error at operation: unit upper triangular solve with compressed_matrix" << std::endl;
632 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
633 retval = EXIT_FAILURE;
636 std::cout <<
"Testing transposed upper triangular solve: compressed_matrix" << std::endl;
642 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
644 std::cout <<
"# Error at operation: upper triangular solve with compressed_matrix" << std::endl;
645 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
646 retval = EXIT_FAILURE;
650 std::cout <<
"Testing transposed unit lower triangular solve: compressed_matrix" << std::endl;
656 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
658 std::cout <<
"# Error at operation: unit lower triangular solve with compressed_matrix" << std::endl;
659 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
660 retval = EXIT_FAILURE;
663 std::cout <<
"Testing transposed lower triangular solve: compressed_matrix" << std::endl;
669 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
671 std::cout <<
"# Error at operation: lower triangular solve with compressed_matrix" << std::endl;
672 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
673 retval = EXIT_FAILURE;
676 std::cout <<
"Testing products: compressed_compressed_matrix" << std::endl;
680 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
682 std::cout <<
"# Error at operation: matrix-vector product with compressed_compressed_matrix" << std::endl;
683 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
684 retval = EXIT_FAILURE;
688 ublas::compressed_matrix<NumericT> temp(vcl_compressed_compressed_matrix.size1(), vcl_compressed_compressed_matrix.size2());
694 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
696 std::cout <<
"# Error at operation: matrix-vector product with compressed_compressed_matrix (after copy back)" << std::endl;
697 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
698 retval = EXIT_FAILURE;
706 std::cout <<
"Testing products: coordinate_matrix" << std::endl;
710 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
712 std::cout <<
"# Error at operation: matrix-vector product with coordinate_matrix" << std::endl;
713 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
714 retval = EXIT_FAILURE;
717 std::cout <<
"Testing products: coordinate_matrix, strided vectors" << std::endl;
719 retval = strided_matrix_vector_product_test<NumericT, viennacl::coordinate_matrix<NumericT> >(epsilon, result, rhs, vcl_result, vcl_rhs);
720 if (retval != EXIT_SUCCESS)
726 ublas_matrix.clear();
730 std::cout <<
"Testing products: ell_matrix" << std::endl;
739 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
741 std::cout <<
"# Error at operation: matrix-vector product with ell_matrix" << std::endl;
742 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
743 retval = EXIT_FAILURE;
746 std::cout <<
"Testing products: ell_matrix, strided vectors" << std::endl;
747 retval = strided_matrix_vector_product_test<NumericT, viennacl::ell_matrix<NumericT> >(epsilon, result, rhs, vcl_result, vcl_rhs);
748 if (retval != EXIT_SUCCESS)
757 std::cout <<
"Testing products: sliced_ell_matrix" << std::endl;
762 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
764 std::cout <<
"# Error at operation: matrix-vector product with sliced_ell_matrix" << std::endl;
765 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
766 retval = EXIT_FAILURE;
769 std::cout <<
"Testing products: sliced_ell_matrix, strided vectors" << std::endl;
770 retval = strided_matrix_vector_product_test<NumericT, viennacl::sliced_ell_matrix<NumericT> >(epsilon, result, rhs, vcl_result, vcl_rhs);
771 if (retval != EXIT_SUCCESS)
777 ublas_matrix.clear();
781 std::cout <<
"Testing products: hyb_matrix" << std::endl;
790 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
792 std::cout <<
"# Error at operation: matrix-vector product with hyb_matrix" << std::endl;
793 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
794 retval = EXIT_FAILURE;
797 std::cout <<
"Testing products: hyb_matrix, strided vectors" << std::endl;
798 retval = strided_matrix_vector_product_test<NumericT, viennacl::hyb_matrix<NumericT> >(epsilon, result, rhs, vcl_result, vcl_rhs);
799 if (retval != EXIT_SUCCESS)
805 NumericT alpha =
static_cast<NumericT
>(2.786);
806 NumericT beta =
static_cast<NumericT
>(1.432);
807 copy(rhs.begin(), rhs.end(), vcl_rhs.begin());
808 copy(result.begin(), result.end(), vcl_result.begin());
809 copy(result.begin(), result.end(), vcl_result2.begin());
811 std::cout <<
"Testing scaled additions of products and vectors" << std::endl;
815 if ( std::fabs(
diff(result, vcl_result2)) > epsilon )
817 std::cout <<
"# Error at operation: matrix-vector product (compressed_matrix) with scaled additions" << std::endl;
818 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result2)) << std::endl;
819 retval = EXIT_FAILURE;
826 if ( std::fabs(
diff(result, vcl_result2)) > epsilon )
828 std::cout <<
"# Error at operation: matrix-vector product (coordinate_matrix) with scaled additions" << std::endl;
829 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result2)) << std::endl;
830 retval = EXIT_FAILURE;
836 if ( std::fabs(
diff(result, vcl_result2)) > epsilon )
838 std::cout <<
"# Error at operation: matrix-vector product (ell_matrix) with scaled additions" << std::endl;
839 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result2)) << std::endl;
840 retval = EXIT_FAILURE;
846 if ( std::fabs(
diff(result, vcl_result2)) > epsilon )
848 std::cout <<
"# Error at operation: matrix-vector product (hyb_matrix) with scaled additions" << std::endl;
849 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result2)) << std::endl;
850 retval = EXIT_FAILURE;
854 ublas_matrix.clear();
856 std::cout <<
"Testing products after clear(): compressed_matrix" << std::endl;
857 vcl_compressed_matrix.clear();
858 result = ublas::scalar_vector<NumericT>(result.size(), NumericT(1));
862 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
864 std::cout <<
"# Error at operation: matrix-vector product with compressed_matrix" << std::endl;
865 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
866 retval = EXIT_FAILURE;
869 std::cout <<
"Testing products after clear(): compressed_compressed_matrix" << std::endl;
870 vcl_compressed_compressed_matrix.clear();
871 result = ublas::scalar_vector<NumericT>(result.size(), NumericT(1));
875 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
877 std::cout <<
"# Error at operation: matrix-vector product with compressed_compressed_matrix" << std::endl;
878 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
879 retval = EXIT_FAILURE;
882 std::cout <<
"Testing products after clear(): coordinate_matrix" << std::endl;
883 vcl_coordinate_matrix.clear();
884 result = ublas::scalar_vector<NumericT>(result.size(), NumericT(1));
888 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
890 std::cout <<
"# Error at operation: matrix-vector product with coordinate_matrix" << std::endl;
891 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
892 retval = EXIT_FAILURE;
895 std::cout <<
"Testing products after clear(): ell_matrix" << std::endl;
896 vcl_ell_matrix.
clear();
897 result = ublas::scalar_vector<NumericT>(result.size(), NumericT(1));
901 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
903 std::cout <<
"# Error at operation: matrix-vector product with ell_matrix" << std::endl;
904 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
905 retval = EXIT_FAILURE;
908 std::cout <<
"Testing products after clear(): hyb_matrix" << std::endl;
909 vcl_hyb_matrix.
clear();
910 result = ublas::scalar_vector<NumericT>(result.size(), NumericT(1));
914 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
916 std::cout <<
"# Error at operation: matrix-vector product with hyb_matrix" << std::endl;
917 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
918 retval = EXIT_FAILURE;
921 std::cout <<
"Testing products after clear(): sliced_ell_matrix" << std::endl;
922 vcl_sliced_ell_matrix.
clear();
923 result = ublas::scalar_vector<NumericT>(result.size(), NumericT(1));
927 if ( std::fabs(
diff(result, vcl_result)) > epsilon )
929 std::cout <<
"# Error at operation: matrix-vector product with sliced_ell_matrix" << std::endl;
930 std::cout <<
" diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
931 retval = EXIT_FAILURE;
943 std::cout << std::endl;
944 std::cout <<
"----------------------------------------------" << std::endl;
945 std::cout <<
"----------------------------------------------" << std::endl;
946 std::cout <<
"## Test :: Sparse Matrices" << std::endl;
947 std::cout <<
"----------------------------------------------" << std::endl;
948 std::cout <<
"----------------------------------------------" << std::endl;
949 std::cout << std::endl;
951 int retval = EXIT_SUCCESS;
953 std::cout << std::endl;
954 std::cout <<
"----------------------------------------------" << std::endl;
955 std::cout << std::endl;
957 typedef float NumericT;
958 NumericT epsilon =
static_cast<NumericT
>(1E-4);
959 std::cout <<
"# Testing setup:" << std::endl;
960 std::cout <<
" eps: " << epsilon << std::endl;
961 std::cout <<
" numeric: float" << std::endl;
962 retval = test<NumericT>(epsilon);
963 if ( retval == EXIT_SUCCESS )
964 std::cout <<
"# Test passed" << std::endl;
968 std::cout << std::endl;
969 std::cout <<
"----------------------------------------------" << std::endl;
970 std::cout << std::endl;
972 #ifdef VIENNACL_WITH_OPENCL
977 typedef double NumericT;
978 NumericT epsilon = 1.0E-12;
979 std::cout <<
"# Testing setup:" << std::endl;
980 std::cout <<
" eps: " << epsilon << std::endl;
981 std::cout <<
" numeric: double" << std::endl;
982 retval = test<NumericT>(epsilon);
983 if ( retval == EXIT_SUCCESS )
984 std::cout <<
"# Test passed" << std::endl;
988 std::cout << std::endl;
989 std::cout <<
"----------------------------------------------" << std::endl;
990 std::cout << std::endl;
992 #ifdef VIENNACL_WITH_OPENCL
994 std::cout <<
"No double precision support, skipping test..." << std::endl;
998 std::cout << std::endl;
999 std::cout <<
"------- Test completed --------" << std::endl;
1000 std::cout << std::endl;
Sparse matrix class using a hybrid format composed of the ELL and CSR format for storing the nonzeros...
void clear()
Resets all entries in the matrix back to zero without changing the matrix size. Resets the sparsity p...
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...
void inplace_solve(const matrix_base< NumericT > &A, matrix_base< NumericT > &B, SolverTagT)
Direct inplace solver for triangular systems with multiple right hand sides, i.e. A \ B (MATLAB notat...
A reader and writer for the matrix market format is implemented here.
ScalarType diff(ScalarType &s1, viennacl::scalar< ScalarType > &s2)
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...
int test(Epsilon const &epsilon)
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...
A tag class representing a lower triangular matrix.
void clear()
Resets all entries in the matrix back to zero without changing the matrix size. Resets the sparsity p...
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.
Implementation of the coordinate_matrix class.
viennacl::vector< float > v1
Implementation of the hyb_matrix class.
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Sparse matrix class using the ELLPACK format for storing the nonzeros.
iterator begin()
Returns an iterator pointing to the beginning of the vector (STL like)
Implementations of incomplete factorization preconditioners. Convenience header file.
A tag class representing an upper triangular matrix.
Sparse matrix class using the sliced ELLPACK with parameters C, .
Implementation of the compressed_matrix class.
A sparse square matrix in compressed sparse rows format optimized for the case that only a few rows c...
Implementation of the sliced_ell_matrix class.
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
matrix_range< MatrixType > project(MatrixType const &A, viennacl::range const &r1, viennacl::range const &r2)
Implementation of the ell_matrix class.
void prod(const MatrixT1 &A, bool transposed_A, const MatrixT2 &B, bool transposed_B, MatrixT3 &C, ScalarT alpha, ScalarT beta)
Proxy classes for vectors.
Implementation of the compressed_compressed_matrix class (CSR format with a relatively small number o...
void clear()
Resets all entries to zero. Does not change the size of the vector.
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)
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 strided_matrix_vector_product_test(Epsilon epsilon, UblasVectorT &result, UblasVectorT const &rhs, VCLVectorT &vcl_result, VCLVectorT &vcl_rhs)
size_type size() const
Returns the length of the vector (cf. std::vector)
A tag class representing a lower triangular matrix with unit diagonal.
long read_matrix_market_file(MatrixT &mat, const char *file, long index_base=1)
Reads a sparse matrix from a file (MatrixMarket format)
iterator end()
Returns an iterator pointing to the end of the vector (STL like)
Common routines used within ILU-type preconditioners.
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 resize_test(Epsilon const &epsilon)
A tag class representing an upper triangular matrix with unit diagonal.
A sparse square matrix, where entries are stored as triplets (i,j, val), where i and j are the row an...