56 template<
typename ScalarType>
 
   60       return (s1 - s2) / 
std::max(fabs(s1), std::fabs(s2));
 
   64 template<
typename ScalarType>
 
   67    std::vector<ScalarType> v2_cpu(v2.
size());
 
   71    for (
unsigned int i=0;i<v1.size(); ++i)
 
   73       if ( 
std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 )
 
   78           v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) / 
std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) );
 
   83       if (v2_cpu[i] > 0.0001)
 
   86         std::cout << 
"Error at entry " << i   << 
": Should: " << v1[i]   << 
" vs. Is: " << v2[i]   << std::endl;
 
   93    for (std::size_t i=0; i<v2_cpu.size(); ++i)
 
   94      norm_inf = std::max<ScalarType>(norm_inf, std::fabs(v2_cpu[i]));
 
  100 template<
typename IndexT, 
typename NumericT, 
typename SparseMatrixT>
 
  101 NumericT diff(std::vector<std::map<IndexT, NumericT> > & cpu_A, SparseMatrixT & vcl_A)
 
  103   typedef typename std::map<IndexT, NumericT>::const_iterator  RowIterator;
 
  105   std::vector<std::map<IndexT, NumericT> > from_gpu(vcl_A.size1());
 
  113   for (std::size_t i=0; i<cpu_A.size(); ++i)
 
  116     for (RowIterator it = cpu_A[i].begin(); it != cpu_A[i].end(); ++it)
 
  121       NumericT val_gpu_A = from_gpu[i][it->first];
 
  125         current_error = std::fabs(val_cpu_A - val_gpu_A) / max_val;
 
  126       if (current_error > error)
 
  127         error = current_error;
 
  133   for (std::size_t i=0; i<from_gpu.size(); ++i)
 
  136     for (RowIterator it = from_gpu[i].begin(); it != from_gpu[i].end(); ++it)
 
  141       NumericT val_cpu_A = cpu_A[i][it->first];
 
  145         current_error = std::fabs(val_cpu_A - val_gpu_A) / max_val;
 
  146       if (current_error > error)
 
  147         error = current_error;
 
  155 template<
typename NumericT, 
typename VCL_MatrixT, 
typename Epsilon, 
typename STLVectorT, 
typename VCLVectorT>
 
  157                                        STLVectorT & result,     STLVectorT 
const & rhs,
 
  158                                        VCLVectorT & vcl_result, VCLVectorT & vcl_rhs)
 
  160   typedef typename std::map<unsigned int, NumericT>::const_iterator    RowIterator;
 
  161     int retval = EXIT_SUCCESS;
 
  163     std::vector<std::map<unsigned int, NumericT> > std_A(5);
 
  170     for (std::size_t i=0; i<5; ++i)
 
  173       for (RowIterator it = std_A[i].begin(); it != std_A[i].end(); ++it)
 
  174         val += it->second * rhs[3 + 2*it->first];
 
  175       result[1 + 3*i] = val;
 
  178     VCL_MatrixT vcl_sparse_matrix2;
 
  187     if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  189       std::cout << 
"# Error at operation: matrix-vector product with strided vectors, part 1" << std::endl;
 
  190       std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  191       retval = EXIT_FAILURE;
 
  201     if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  203       std::cout << 
"# Error at operation: matrix-vector product with strided vectors, part 2" << std::endl;
 
  204       std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  205       retval = EXIT_FAILURE;
 
  212 template< 
typename NumericT, 
typename VCL_MATRIX, 
typename Epsilon >
 
  215    int retval = EXIT_SUCCESS;
 
  217    std::vector<std::map<unsigned int, NumericT> > std_A(5);
 
  218    VCL_MATRIX vcl_matrix;
 
  227    std::vector<std::map<unsigned int, NumericT> > std_B(std_A.size());
 
  230    std::cout << 
"Checking for equality after copy..." << std::endl;
 
  231     if ( std::fabs(
diff(std_A, vcl_matrix)) > epsilon )
 
  233         std::cout << 
"# Error at operation: equality after copy with sparse matrix" << std::endl;
 
  234         std::cout << 
"  diff: " << std::fabs(
diff(std_A, vcl_matrix)) << std::endl;
 
  238    std::cout << 
"Testing resize to larger..." << std::endl;
 
  246    vcl_matrix.resize(10, 10, 
true);
 
  248     if ( std::fabs(
diff(std_A, vcl_matrix)) > epsilon )
 
  250         std::cout << 
"# Error at operation: resize (to larger) with sparse matrix" << std::endl;
 
  251         std::cout << 
"  diff: " << std::fabs(
diff(std_A, vcl_matrix)) << std::endl;
 
  262    std::cout << 
"Testing resize to smaller..." << std::endl;
 
  273    vcl_matrix.resize(7, 7);
 
  276     if ( std::fabs(
diff(std_A, vcl_matrix)) > epsilon )
 
  278         std::cout << 
"# Error at operation: resize (to smaller) with sparse matrix" << std::endl;
 
  279         std::cout << 
"  diff: " << std::fabs(
diff(std_A, vcl_matrix)) << std::endl;
 
  280         retval = EXIT_FAILURE;
 
  283    std::vector<NumericT> std_vec(std_A.size(), 
NumericT(3.1415));
 
  287   std::cout << 
"Testing unit lower triangular solve: compressed_matrix" << std::endl;
 
  290   std::cout << 
"STL..." << std::endl;
 
  292   for (std::size_t i=1; i<std_A.size(); ++i)
 
  293     for (
typename std::map<unsigned int, NumericT>::const_iterator it = std_A[i].begin(); it != std_A[i].end(); ++it)
 
  295       if (it->first < static_cast<unsigned int>(i))
 
  296         std_vec[i] -= it->second * std_vec[it->first];
 
  301   std::cout << 
"ViennaCL..." << std::endl;
 
  304   if ( std::fabs(
diff(std_vec, vcl_vec)) > epsilon )
 
  306       std::cout << 
"# Error at operation: unit lower triangular solve" << std::endl;
 
  307       std::cout << 
"  diff: " << std::fabs(
diff(std_vec, vcl_vec)) << std::endl;
 
  308       retval = EXIT_FAILURE;
 
  317 template< 
typename NumericT, 
typename Epsilon >
 
  318 int test(Epsilon 
const& epsilon)
 
  322   std::cout << 
"Testing resizing of compressed_matrix..." << std::endl;
 
  323   int retval = resize_test<NumericT, viennacl::compressed_matrix<NumericT> >(epsilon);
 
  324   if (retval != EXIT_SUCCESS)
 
  328   std::vector<NumericT> rhs;
 
  329   std::vector<NumericT> result;
 
  330   std::vector<std::map<unsigned int, NumericT> > std_matrix;
 
  334     std::cout << 
"Error reading Matrix file" << std::endl;
 
  339   std::cout << 
"done reading matrix" << std::endl;
 
  342   rhs.resize(std_matrix.size());
 
  343   for (std::size_t i=0; i<rhs.size(); ++i)
 
  345     std_matrix[i][
static_cast<unsigned int>(i)] = 
NumericT(0.5);   
 
  346     rhs[i] = 
NumericT(1) + randomNumber();
 
  350   std::vector<std::map<unsigned int, NumericT> > std_cc_matrix(std_matrix.size());
 
  351   std_cc_matrix[42][199] = 
NumericT(3.1415);
 
  352   std_cc_matrix[31][69] = 
NumericT(2.71);
 
  353   std_cc_matrix[23][32] = 
NumericT(6);
 
  354   std_cc_matrix[177][57] = 
NumericT(4);
 
  355   std_cc_matrix[21][97] = 
NumericT(-4);
 
  356   std_cc_matrix[92][25] = 
NumericT(2);
 
  357   std_cc_matrix[89][62] = 
NumericT(11);
 
  358   std_cc_matrix[ 1][ 7] = 
NumericT(8);
 
  359   std_cc_matrix[85][41] = 
NumericT(13);
 
  360   std_cc_matrix[66][28] = 
NumericT(8);
 
  361   std_cc_matrix[21][74] = 
NumericT(-2);
 
  380   viennacl::copy(adapted_std_cc_matrix, vcl_compressed_compressed_matrix);
 
  384   std::cout << 
"Testing products: STL" << std::endl;
 
  387   std::cout << 
"Testing products: compressed_matrix" << std::endl;
 
  390   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  392     std::cout << 
"# Error at operation: matrix-vector product with compressed_matrix" << std::endl;
 
  393     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  397   std::cout << 
"Testing products: compressed_matrix, strided vectors" << std::endl;
 
  398   retval = strided_matrix_vector_product_test<NumericT, viennacl::compressed_matrix<NumericT> >(epsilon, result, rhs, vcl_result, vcl_rhs);
 
  399   if (retval != EXIT_SUCCESS)
 
  404   for (std::size_t i=0; i<result.size(); ++i) result[i] += rhs[i];
 
  405   vcl_result = vcl_rhs;
 
  408   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  410     std::cout << 
"# Error at operation: matrix-vector product with compressed_matrix (+=)" << std::endl;
 
  411     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  417   for (std::size_t i=0; i<result.size(); ++i) result[i] = rhs[i] - result[i];
 
  418   vcl_result = vcl_rhs;
 
  421   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  423     std::cout << 
"# Error at operation: matrix-vector product with compressed_matrix (-=)" << std::endl;
 
  424     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  432   std::cout << 
"Testing unit upper triangular solve: compressed_matrix" << std::endl;
 
  436   for (std::size_t i2=0; i2<std_matrix.size(); ++i2)
 
  438     std::size_t 
row = std_matrix.size() - i2 - 1;
 
  439     for (
typename std::map<unsigned int, NumericT>::const_iterator it = std_matrix[row].begin(); it != std_matrix[
row].end(); ++it)
 
  441       if (it->first > static_cast<unsigned int>(row))
 
  442         result[row] -= it->second * result[it->first];
 
  450   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  452     std::cout << 
"# Error at operation: unit upper triangular solve with compressed_matrix" << std::endl;
 
  453     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  459   std::cout << 
"Testing upper triangular solve: compressed_matrix" << std::endl;
 
  463   for (std::size_t i2=0; i2<std_matrix.size(); ++i2)
 
  465     std::size_t 
row = std_matrix.size() - i2 - 1;
 
  467     for (
typename std::map<unsigned int, NumericT>::const_iterator it = std_matrix[row].begin(); it != std_matrix[
row].end(); ++it)
 
  469       if (it->first > static_cast<unsigned int>(row))
 
  470         result[row] -= it->second * result[it->first];
 
  471       else if (it->first == static_cast<unsigned int>(row))
 
  481   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  483     std::cout << 
"# Error at operation: upper triangular solve with compressed_matrix" << std::endl;
 
  484     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  490   std::cout << 
"Testing unit lower triangular solve: compressed_matrix" << std::endl;
 
  494   for (std::size_t i=1; i<std_matrix.size(); ++i)
 
  495     for (
typename std::map<unsigned int, NumericT>::const_iterator it = std_matrix[i].begin(); it != std_matrix[i].end(); ++it)
 
  497       if (it->first < static_cast<unsigned int>(i))
 
  498         result[i] -= it->second * result[it->first];
 
  505   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  507     std::cout << 
"# Error at operation: unit lower triangular solve with compressed_matrix" << std::endl;
 
  508     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  513   std::cout << 
"Testing lower triangular solve: compressed_matrix" << std::endl;
 
  517   for (std::size_t i=0; i<std_matrix.size(); ++i)
 
  520     for (
typename std::map<unsigned int, NumericT>::const_iterator it = std_matrix[i].begin(); it != std_matrix[i].end(); ++it)
 
  522       if (it->first < static_cast<unsigned int>(i))
 
  523         result[i] -= it->second * result[it->first];
 
  524       else if (it->first == static_cast<unsigned int>(i))
 
  534   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  536     std::cout << 
"# Error at operation: lower triangular solve with compressed_matrix" << std::endl;
 
  537     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  546   std::vector<std::map<unsigned int, NumericT> > std_matrix_trans(std_matrix.size());
 
  549   for (std::size_t i=0; i<std_matrix.size(); ++i)
 
  550     for (
typename std::map<unsigned int, NumericT>::const_iterator it  = std_matrix[i].begin(); it != std_matrix[i].end(); ++it)
 
  551       std_matrix_trans[i][it->first] = it->second;
 
  553   std::cout << 
"Testing transposed unit upper triangular solve: compressed_matrix" << std::endl;
 
  555   viennacl::copy(result, vcl_result);
 
  557   for (std::size_t i2=0; i2<std_matrix_trans.size(); ++i2)
 
  559     std::size_t 
row = std_matrix_trans.size() - i2 - 1;
 
  560     for (
typename std::map<unsigned int, NumericT>::const_iterator it = std_matrix_trans[row].begin(); it != std_matrix_trans[
row].end(); ++it)
 
  562       if (it->first > static_cast<unsigned int>(row))
 
  563         result[row] -= it->second * result[it->first];
 
  570   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  572     std::cout << 
"# Error at operation: unit upper triangular solve with compressed_matrix" << std::endl;
 
  573     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  579   std::cout << 
"Testing transposed upper triangular solve: compressed_matrix" << std::endl;
 
  583   for (std::size_t i2=0; i2<std_matrix_trans.size(); ++i2)
 
  585     std::size_t 
row = std_matrix_trans.size() - i2 - 1;
 
  587     for (
typename std::map<unsigned int, NumericT>::const_iterator it = std_matrix_trans[row].begin(); it != std_matrix_trans[
row].end(); ++it)
 
  589       if (it->first > static_cast<unsigned int>(row))
 
  590         result[row] -= it->second * result[it->first];
 
  591       else if (it->first == static_cast<unsigned int>(row))
 
  600   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  602     std::cout << 
"# Error at operation: upper triangular solve with compressed_matrix" << std::endl;
 
  603     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  609   std::cout << 
"Testing transposed unit lower triangular solve: compressed_matrix" << std::endl;
 
  613   for (std::size_t i=1; i<std_matrix_trans.size(); ++i)
 
  614     for (
typename std::map<unsigned int, NumericT>::const_iterator it = std_matrix_trans[i].begin(); it != std_matrix_trans[i].end(); ++it)
 
  616       if (it->first < static_cast<unsigned int>(i))
 
  617         result[i] -= it->second * result[it->first];
 
  623   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  625     std::cout << 
"# Error at operation: unit lower triangular solve with compressed_matrix" << std::endl;
 
  626     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  632   std::cout << 
"Testing transposed lower triangular solve: compressed_matrix" << std::endl;
 
  636   for (std::size_t i=0; i<std_matrix_trans.size(); ++i)
 
  639     for (
typename std::map<unsigned int, NumericT>::const_iterator it = std_matrix_trans[i].begin(); it != std_matrix_trans[i].end(); ++it)
 
  641       if (it->first < static_cast<unsigned int>(i))
 
  642         result[i] -= it->second * result[it->first];
 
  643       else if (it->first == static_cast<unsigned int>(i))
 
  652   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  654     std::cout << 
"# Error at operation: lower triangular solve with compressed_matrix" << std::endl;
 
  655     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  665   std::cout << 
"Testing products: compressed_compressed_matrix" << std::endl;
 
  669   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  671     std::cout << 
"# Error at operation: matrix-vector product with compressed_compressed_matrix (=)" << std::endl;
 
  672     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  677     std::vector<std::map<unsigned int, NumericT> > temp(vcl_compressed_compressed_matrix.size1());
 
  683     if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  685       std::cout << 
"# Error at operation: matrix-vector product with compressed_compressed_matrix (after copy back)" << std::endl;
 
  686       std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  694   for (std::size_t i=0; i<result.size(); ++i) result[i] += rhs[i];
 
  695   vcl_result = vcl_rhs;
 
  698   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  700     std::cout << 
"# Error at operation: matrix-vector product with compressed_compressed_matrix (+=)" << std::endl;
 
  701     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  707   for (std::size_t i=0; i<result.size(); ++i) result[i] = rhs[i] - result[i];
 
  708   vcl_result = vcl_rhs;
 
  711   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  713     std::cout << 
"# Error at operation: matrix-vector product with compressed_compressed_matrix (-=)" << std::endl;
 
  714     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  724   std::cout << 
"Testing products: coordinate_matrix" << std::endl;
 
  728   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  730     std::cout << 
"# Error at operation: matrix-vector product with coordinate_matrix" << std::endl;
 
  731     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  735   std::cout << 
"Testing products: coordinate_matrix, strided vectors" << std::endl;
 
  737   retval = strided_matrix_vector_product_test<NumericT, viennacl::coordinate_matrix<NumericT> >(epsilon, result, rhs, vcl_result, vcl_rhs);
 
  738   if (retval != EXIT_SUCCESS)
 
  743   for (std::size_t i=0; i<result.size(); ++i) result[i] += rhs[i];
 
  744   vcl_result = vcl_rhs;
 
  747   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  749     std::cout << 
"# Error at operation: matrix-vector product with coordinate_matrix (+=)" << std::endl;
 
  750     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  756   for (std::size_t i=0; i<result.size(); ++i) result[i] = rhs[i] - result[i];
 
  757   vcl_result = vcl_rhs;
 
  760   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  762     std::cout << 
"# Error at operation: matrix-vector product with coordinate_matrix (-=)" << std::endl;
 
  763     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  778   std::cout << 
"Testing products: ell_matrix" << std::endl;
 
  787   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  789     std::cout << 
"# Error at operation: matrix-vector product with ell_matrix" << std::endl;
 
  790     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  794   std::cout << 
"Testing products: ell_matrix, strided vectors" << std::endl;
 
  795   retval = strided_matrix_vector_product_test<NumericT, viennacl::ell_matrix<NumericT> >(epsilon, result, rhs, vcl_result, vcl_rhs);
 
  796   if (retval != EXIT_SUCCESS)
 
  801   for (std::size_t i=0; i<result.size(); ++i) result[i] += rhs[i];
 
  802   vcl_result = vcl_rhs;
 
  805   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  807     std::cout << 
"# Error at operation: matrix-vector product with ell_matrix (+=)" << std::endl;
 
  808     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  814   for (std::size_t i=0; i<result.size(); ++i) result[i] = rhs[i] - result[i];
 
  815   vcl_result = vcl_rhs;
 
  818   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  820     std::cout << 
"# Error at operation: matrix-vector product with ell_matrix (-=)" << std::endl;
 
  821     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  833   std::cout << 
"Testing products: sliced_ell_matrix" << std::endl;
 
  838   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  840     std::cout << 
"# Error at operation: matrix-vector product with sliced_ell_matrix" << std::endl;
 
  841     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  845   std::cout << 
"Testing products: sliced_ell_matrix, strided vectors" << std::endl;
 
  846   retval = strided_matrix_vector_product_test<NumericT, viennacl::sliced_ell_matrix<NumericT> >(epsilon, result, rhs, vcl_result, vcl_rhs);
 
  847   if (retval != EXIT_SUCCESS)
 
  852   for (std::size_t i=0; i<result.size(); ++i) result[i] += rhs[i];
 
  853   vcl_result = vcl_rhs;
 
  856   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  858     std::cout << 
"# Error at operation: matrix-vector product with sliced_ell_matrix (+=)" << std::endl;
 
  859     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  865   for (std::size_t i=0; i<result.size(); ++i) result[i] = rhs[i] - result[i];
 
  866   vcl_result = vcl_rhs;
 
  869   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  871     std::cout << 
"# Error at operation: matrix-vector product with sliced_ell_matrix (-=)" << std::endl;
 
  872     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  887   std::cout << 
"Testing products: hyb_matrix" << std::endl;
 
  896   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  898     std::cout << 
"# Error at operation: matrix-vector product with hyb_matrix" << std::endl;
 
  899     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  903   std::cout << 
"Testing products: hyb_matrix, strided vectors" << std::endl;
 
  904   retval = strided_matrix_vector_product_test<NumericT, viennacl::hyb_matrix<NumericT> >(epsilon, result, rhs, vcl_result, vcl_rhs);
 
  905   if (retval != EXIT_SUCCESS)
 
  910   for (std::size_t i=0; i<result.size(); ++i) result[i] += rhs[i];
 
  911   vcl_result = vcl_rhs;
 
  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;
 
  923   for (std::size_t i=0; i<result.size(); ++i) result[i] = rhs[i] - result[i];
 
  924   vcl_result = vcl_rhs;
 
  927   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  929     std::cout << 
"# Error at operation: matrix-vector product with hyb_matrix (-=)" << std::endl;
 
  930     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
  939   copy(rhs.begin(), rhs.end(), vcl_rhs.begin());
 
  940   copy(result.begin(), result.end(), vcl_result.begin());
 
  941   copy(result.begin(), result.end(), vcl_result2.begin());
 
  943   std::cout << 
"Testing scaled additions of products and vectors" << std::endl;
 
  944   std::vector<NumericT> result2(result);
 
  946   for (std::size_t i=0; i<result.size(); ++i)
 
  947     result[i] = alpha * result2[i] + beta * result[i];
 
  950   if ( std::fabs(
diff(result, vcl_result2)) > epsilon )
 
  952     std::cout << 
"# Error at operation: matrix-vector product (compressed_matrix) with scaled additions" << std::endl;
 
  953     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result2)) << std::endl;
 
  961   if ( std::fabs(
diff(result, vcl_result2)) > epsilon )
 
  963     std::cout << 
"# Error at operation: matrix-vector product (coordinate_matrix) with scaled additions" << std::endl;
 
  964     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result2)) << std::endl;
 
  971   if ( std::fabs(
diff(result, vcl_result2)) > epsilon )
 
  973     std::cout << 
"# Error at operation: matrix-vector product (ell_matrix) with scaled additions" << std::endl;
 
  974     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result2)) << std::endl;
 
  981   if ( std::fabs(
diff(result, vcl_result2)) > epsilon )
 
  983     std::cout << 
"# Error at operation: matrix-vector product (hyb_matrix) with scaled additions" << std::endl;
 
  984     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result2)) << std::endl;
 
  991   std::cout << 
"Testing products after clear(): compressed_matrix" << std::endl;
 
  992   vcl_compressed_matrix.clear();
 
  993   result     = std::vector<NumericT>(result.size(), 
NumericT(1));
 
  997   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
  999     std::cout << 
"# Error at operation: matrix-vector product with compressed_matrix" << std::endl;
 
 1000     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
 1001     return EXIT_FAILURE;
 
 1004   std::cout << 
"Testing products after clear(): compressed_compressed_matrix" << std::endl;
 
 1005   vcl_compressed_compressed_matrix.clear();
 
 1006   result     = std::vector<NumericT>(result.size(), 
NumericT(1));
 
 1010   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
 1012     std::cout << 
"# Error at operation: matrix-vector product with compressed_compressed_matrix" << std::endl;
 
 1013     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
 1014     return EXIT_FAILURE;
 
 1017   std::cout << 
"Testing products after clear(): coordinate_matrix" << std::endl;
 
 1018   vcl_coordinate_matrix.clear();
 
 1019   result     = std::vector<NumericT>(result.size(), 
NumericT(1));
 
 1023   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
 1025     std::cout << 
"# Error at operation: matrix-vector product with coordinate_matrix" << std::endl;
 
 1026     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
 1027     return EXIT_FAILURE;
 
 1030   std::cout << 
"Testing products after clear(): ell_matrix" << std::endl;
 
 1031   vcl_ell_matrix.
clear();
 
 1032   result     = std::vector<NumericT>(result.size(), 
NumericT(1));
 
 1036   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
 1038     std::cout << 
"# Error at operation: matrix-vector product with ell_matrix" << std::endl;
 
 1039     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
 1040     return EXIT_FAILURE;
 
 1043   std::cout << 
"Testing products after clear(): hyb_matrix" << std::endl;
 
 1044   vcl_hyb_matrix.
clear();
 
 1045   result     = std::vector<NumericT>(result.size(), 
NumericT(1));
 
 1049   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
 1051     std::cout << 
"# Error at operation: matrix-vector product with hyb_matrix" << std::endl;
 
 1052     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
 1053     return EXIT_FAILURE;
 
 1056   std::cout << 
"Testing products after clear(): sliced_ell_matrix" << std::endl;
 
 1057   vcl_sliced_ell_matrix.
clear();
 
 1058   result     = std::vector<NumericT>(result.size(), 
NumericT(1));
 
 1062   if ( std::fabs(
diff(result, vcl_result)) > epsilon )
 
 1064     std::cout << 
"# Error at operation: matrix-vector product with sliced_ell_matrix" << std::endl;
 
 1065     std::cout << 
"  diff: " << std::fabs(
diff(result, vcl_result)) << std::endl;
 
 1066     return EXIT_FAILURE;
 
 1078   std::cout << std::endl;
 
 1079   std::cout << 
"----------------------------------------------" << std::endl;
 
 1080   std::cout << 
"----------------------------------------------" << std::endl;
 
 1081   std::cout << 
"## Test :: Sparse Matrices" << std::endl;
 
 1082   std::cout << 
"----------------------------------------------" << std::endl;
 
 1083   std::cout << 
"----------------------------------------------" << std::endl;
 
 1084   std::cout << std::endl;
 
 1086   int retval = EXIT_SUCCESS;
 
 1088   std::cout << std::endl;
 
 1089   std::cout << 
"----------------------------------------------" << std::endl;
 
 1090   std::cout << std::endl;
 
 1093     NumericT epsilon = 
static_cast<NumericT
>(1E-4);
 
 1094     std::cout << 
"# Testing setup:" << std::endl;
 
 1095     std::cout << 
"  eps:     " << epsilon << std::endl;
 
 1096     std::cout << 
"  numeric: float" << std::endl;
 
 1097     retval = test<NumericT>(epsilon);
 
 1098     if ( retval == EXIT_SUCCESS )
 
 1099         std::cout << 
"# Test passed" << std::endl;
 
 1103   std::cout << std::endl;
 
 1104   std::cout << 
"----------------------------------------------" << std::endl;
 
 1105   std::cout << std::endl;
 
 1107 #ifdef VIENNACL_WITH_OPENCL 
 1113       NumericT epsilon = 1.0E-12;
 
 1114       std::cout << 
"# Testing setup:" << std::endl;
 
 1115       std::cout << 
"  eps:     " << epsilon << std::endl;
 
 1116       std::cout << 
"  numeric: double" << std::endl;
 
 1117       retval = test<NumericT>(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 #ifdef VIENNACL_WITH_OPENCL 
 1129     std::cout << 
"No double precision support, skipping test..." << std::endl;
 
 1133   std::cout << std::endl;
 
 1134   std::cout << 
"------- Test completed --------" << std::endl;
 
 1135   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(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. 
int strided_matrix_vector_product_test(Epsilon epsilon, STLVectorT &result, STLVectorT const &rhs, VCLVectorT &vcl_result, VCLVectorT &vcl_rhs)
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)
std::vector< std::vector< NumericT > > trans(std::vector< std::vector< NumericT > > const &A)
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
void clear()
Resets all entries in the matrix back to zero without changing the matrix size. Resets the sparsity p...
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. 
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. 
vector_expression< const matrix_base< NumericT >, const int, op_matrix_diag > diag(const matrix_base< NumericT > &A, int k=0)
Proxy classes for vectors. 
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_row > row(const matrix_base< NumericT, F > &A, unsigned int i)
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) ...
A small collection of sequential random number generators. 
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...