40 template<
typename NumericT, 
typename MatrixT>
 
   41 int check(std::vector<NumericT> 
const & std_dest,
 
   42           std::size_t 
start1, std::size_t inc1, std::size_t 
size1,
 
   44           MatrixT 
const & vcl_dest)
 
   49   for (std::size_t i=0; i < 
size1; ++i)
 
   51     for (std::size_t j=0; j < 
size2; ++j)
 
   53       NumericT value_std  = std_dest[(i*inc1 + 
start1) * internal_size2 + (j*inc2 + start2)];
 
   54       NumericT value_dest = vcl_dest.row_major() ? tempmat[(i * vcl_dest.stride1() + vcl_dest.start1()) * vcl_dest.internal_size2() + (j * vcl_dest.stride2() + vcl_dest.start2())]
 
   55                                                  : tempmat[(i * vcl_dest.stride1() + vcl_dest.start1())                             + (j * vcl_dest.stride2() + vcl_dest.start2()) * vcl_dest.internal_size1()];
 
   57       if (value_std < value_dest || value_std > value_dest)
 
   59         std::cerr << 
"Failure at row " << i << 
", col " << j << 
": STL value " << value_std << 
", ViennaCL value " << value_dest << std::endl;
 
   72 template<
typename STLVectorT1, 
typename STLVectorT2, 
typename ViennaCLVectorT1, 
typename ViennaCLVectorT2 >
 
   73 int test(STLVectorT1 & std_src,  std::size_t start1_src,  std::size_t inc1_src,  std::size_t size1_src,  std::size_t start2_src,  std::size_t inc2_src,  std::size_t size2_src,  std::size_t internal_size2_src,
 
   74          STLVectorT2 & std_dest, std::size_t start1_dest, std::size_t inc1_dest, std::size_t size1_dest, std::size_t start2_dest, std::size_t inc2_dest, std::size_t size2_dest, std::size_t internal_size2_dest,
 
   75          ViennaCLVectorT1 
const & vcl_src, ViennaCLVectorT2 & vcl_dest)
 
   77   assert(size1_src       == size1_dest       && 
bool(
"Size1 mismatch for STL matrices"));
 
   78   assert(size2_src       == size2_dest       && 
bool(
"Size2 mismatch for STL matrices"));
 
   79   assert(vcl_src.size1() == vcl_dest.size1() && bool(
"Size1 mismatch for ViennaCL matrices"));
 
   80   assert(vcl_src.size2() == vcl_dest.size2() && bool(
"Size2 mismatch for ViennaCL matrices"));
 
   81   assert(size1_src       == vcl_src.size1()  && bool(
"Size1 mismatch for STL and ViennaCL matrices"));
 
   82   assert(size2_src       == vcl_src.size2()  && bool(
"Size2 mismatch for STL and ViennaCL matrices"));
 
   84   typedef typename STLVectorT2::value_type  DestNumericT;
 
   86   for (std::size_t i=0; i<size1_src; ++i)
 
   87     for (std::size_t j=0; j<size2_src; ++j)
 
   88       std_dest[(start1_dest + i * inc1_dest) * internal_size2_dest + (start2_dest + j * inc2_dest)] = static_cast<DestNumericT>(std_src[(start1_src + i * inc1_src) * internal_size2_src + (start2_src + j * inc2_src)]);
 
   92   if (
check(std_dest, start1_dest, inc1_dest, size1_dest, start2_dest, inc2_dest, size2_dest, internal_size2_dest, vcl_dest) != EXIT_SUCCESS)
 
   95   if (vcl_src.row_major())
 
   98     if (
check(std_dest, start1_dest, inc1_dest, size1_dest, start2_dest, inc2_dest, size2_dest, internal_size2_dest, A) != EXIT_SUCCESS)
 
  104     if (
check(std_dest, start1_dest, inc1_dest, size1_dest, start2_dest, inc2_dest, size2_dest, internal_size2_dest, A) != EXIT_SUCCESS)
 
  112 inline std::string 
type_string(
unsigned int)    { 
return "unsigned int"; }
 
  114 inline std::string 
type_string(
unsigned long)   { 
return "unsigned long"; }
 
  119 template<
typename LayoutT, 
typename FromNumericT, 
typename ToNumericT>
 
  122   int retval = EXIT_SUCCESS;
 
  124   std::cout << std::endl;
 
  125   std::cout << 
"-----------------------------------------------" << std::endl;
 
  126   std::cout << std::endl;
 
  127   std::cout << 
"Conversion test from " << 
type_string(FromNumericT()) << 
" to " << 
type_string(ToNumericT()) << std::endl;
 
  128   std::cout << std::endl;
 
  130   std::size_t full_size1  = 578;
 
  131   std::size_t small_size1 = full_size1 / 4;
 
  133   std::size_t full_size2  = 687;
 
  134   std::size_t small_size2 = full_size2 / 4;
 
  139   std::vector<FromNumericT>               std_src(full_size1 * full_size2);
 
  140   std::vector<std::vector<FromNumericT> > std_src2(full_size1, std::vector<FromNumericT>(full_size2));
 
  141   std::vector<std::vector<FromNumericT> > std_src_small(small_size1, std::vector<FromNumericT>(small_size2));
 
  142   std::vector<ToNumericT> std_dest(std_src.size());
 
  144   for (std::size_t i=0; i<full_size1; ++i)
 
  145     for (std::size_t j=0; j<full_size2; ++j)
 
  147       std_src[i * full_size2 + j]  = FromNumericT(1.0) + FromNumericT(i) + FromNumericT(j);
 
  148       std_src2[i][j]  = FromNumericT(1.0) + FromNumericT(i) + FromNumericT(j);
 
  149       if (i < small_size1 && j < small_size2)
 
  150         std_src_small[i][j]  = FromNumericT(1.0) + FromNumericT(i) + FromNumericT(j);
 
  165   std::size_t r11_start = 1 + full_size1 / 4;
 
  166   std::size_t r11_stop  = r11_start + small_size1;
 
  169   std::size_t r12_start = 2 * full_size1 / 4;
 
  170   std::size_t r12_stop  = r12_start + small_size1;
 
  173   std::size_t r21_start = 2 * full_size2 / 4;
 
  174   std::size_t r21_stop  = r21_start + small_size2;
 
  177   std::size_t r22_start = 1 + full_size2 / 4;
 
  178   std::size_t r22_stop  = r22_start + small_size2;
 
  186   std::size_t s11_start = 1 + full_size1 / 5;
 
  187   std::size_t s11_inc   = 3;
 
  188   std::size_t s11_size  = small_size1;
 
  191   std::size_t s12_start = 2 * full_size1 / 5;
 
  192   std::size_t s12_inc   = 2;
 
  193   std::size_t s12_size  = small_size1;
 
  196   std::size_t s21_start = 1 + full_size2 / 5;
 
  197   std::size_t s21_inc   = 3;
 
  198   std::size_t s21_size  = small_size2;
 
  201   std::size_t s22_start = 2 * full_size2 / 5;
 
  202   std::size_t s22_inc   = 2;
 
  203   std::size_t s22_size  = small_size2;
 
  213   std::cout << 
" ** vcl_src = matrix, vcl_dest = matrix **" << std::endl;
 
  214   retval = 
test(std_src,  0, 1, full_size1, 0, 1, full_size2, full_size2,
 
  215                 std_dest, 0, 1, full_size1, 0, 1, full_size2, full_size2,
 
  217   if (retval != EXIT_SUCCESS)
 
  220   std::cout << 
" ** vcl_src = matrix, vcl_dest = range **" << std::endl;
 
  221   retval = 
test(std_src,          0, 1, small_size1,                  0, 1,          small_size2, full_size2,
 
  222                 std_dest, r12_start, 1, r12_stop - r12_start, r22_start, 1, r22_stop - r22_start, full_size2,
 
  223                 vcl_src_small, vcl_range_dest);
 
  224   if (retval != EXIT_SUCCESS)
 
  227   std::cout << 
" ** vcl_src = matrix, vcl_dest = slice **" << std::endl;
 
  228   retval = 
test(std_src,          0,       1, small_size1,         0,       1, small_size2, full_size2,
 
  229                 std_dest, s12_start, s12_inc,    s12_size, s22_start, s22_inc,    s22_size, full_size2,
 
  230                 vcl_src_small, vcl_slice_dest);
 
  231   if (retval != EXIT_SUCCESS)
 
  236   std::cout << 
" ** vcl_src = range, vcl_dest = matrix **" << std::endl;
 
  237   retval = 
test(std_src,  r11_start, 1, r11_stop - r11_start, r21_start, 1, r21_stop - r21_start, full_size2,
 
  238                 std_dest,         0, 1,          small_size1,         0, 1,          small_size2, full_size2,
 
  239                 vcl_range_src, vcl_dest_small);
 
  240   if (retval != EXIT_SUCCESS)
 
  243   std::cout << 
" ** vcl_src = range, vcl_dest = range **" << std::endl;
 
  244   retval = 
test(std_src,  r11_start, 1, r11_stop - r11_start, r21_start, 1, r21_stop - r21_start, full_size2,
 
  245                 std_dest, r12_start, 1, r12_stop - r12_start, r22_start, 1, r22_stop - r22_start, full_size2,
 
  246                 vcl_range_src, vcl_range_dest);
 
  247   if (retval != EXIT_SUCCESS)
 
  250   std::cout << 
" ** vcl_src = range, vcl_dest = slice **" << std::endl;
 
  251   retval = 
test(std_src,  r11_start,       1, r11_stop - r11_start, r21_start,       1, r21_stop - r21_start, full_size2,
 
  252                 std_dest, s12_start, s12_inc,             s12_size, s22_start, s22_inc,             s22_size, full_size2,
 
  253                 vcl_range_src, vcl_slice_dest);
 
  254   if (retval != EXIT_SUCCESS)
 
  259   std::cout << 
" ** vcl_src = slice, vcl_dest = matrix **" << std::endl;
 
  260   retval = 
test(std_src,  s11_start, s11_inc,    s11_size, s21_start, s21_inc,    s21_size, full_size2,
 
  261                 std_dest,         0,       1, small_size1,         0,       1, small_size2, full_size2,
 
  262                 vcl_slice_src, vcl_dest_small);
 
  263   if (retval != EXIT_SUCCESS)
 
  266   std::cout << 
" ** vcl_src = slice, vcl_dest = range **" << std::endl;
 
  267   retval = 
test(std_src,  s11_start, s11_inc,             s11_size, s21_start, s21_inc,             s21_size, full_size2,
 
  268                 std_dest, r12_start,       1, r12_stop - r12_start, r22_start,       1, r22_stop - r22_start, full_size2,
 
  269                 vcl_slice_src, vcl_range_dest);
 
  270   if (retval != EXIT_SUCCESS)
 
  273   std::cout << 
" ** vcl_src = slice, vcl_dest = slice **" << std::endl;
 
  274   retval = 
test(std_src,  s11_start, s11_inc, s11_size, s21_start, s21_inc, s21_size, full_size2,
 
  275                 std_dest, s12_start, s12_inc, s12_size, s22_start, s22_inc, s22_size, full_size2,
 
  276                 vcl_slice_src, vcl_slice_dest);
 
  277   if (retval != EXIT_SUCCESS)
 
  284 template<
typename FromNumericT, 
typename ToNumericT>
 
  287   int retval = test<viennacl::row_major, FromNumericT, ToNumericT>();
 
  288   if (retval == EXIT_SUCCESS)
 
  290     retval = test<viennacl::column_major, FromNumericT, ToNumericT>();
 
  291     if (retval != EXIT_SUCCESS)
 
  292       std::cerr << 
"Test failed for column-major!" << std::endl;
 
  295     std::cerr << 
"Test failed for row-major!" << std::endl;
 
  305   std::cout << std::endl;
 
  306   std::cout << 
"----------------------------------------------" << std::endl;
 
  307   std::cout << 
"----------------------------------------------" << std::endl;
 
  308   std::cout << 
"## Test :: Type conversion test for matrices  " << std::endl;
 
  309   std::cout << 
"----------------------------------------------" << std::endl;
 
  310   std::cout << 
"----------------------------------------------" << std::endl;
 
  311   std::cout << std::endl;
 
  313   int retval = EXIT_SUCCESS;
 
  318   retval = test<int, int>();
 
  319   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  322   retval = test<int, unsigned int>();
 
  323   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  326   retval = test<int, long>();
 
  327   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  330   retval = test<int, unsigned long>();
 
  331   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  334   retval = test<int, float>();
 
  335   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  338   retval = test<int, unsigned long>();
 
  339   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  342 #ifdef VIENNACL_WITH_OPENCL 
  346     retval = test<int, double>();
 
  347     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  355   retval = test<unsigned int, int>();
 
  356   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  359   retval = test<unsigned int, unsigned int>();
 
  360   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  363   retval = test<unsigned int, long>();
 
  364   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  367   retval = test<unsigned int, unsigned long>();
 
  368   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  371   retval = test<unsigned int, float>();
 
  372   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  375   retval = test<unsigned int, unsigned long>();
 
  376   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  379 #ifdef VIENNACL_WITH_OPENCL 
  383     retval = test<unsigned int, double>();
 
  384     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  392   retval = test<long, int>();
 
  393   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  396   retval = test<long, unsigned int>();
 
  397   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  400   retval = test<long, long>();
 
  401   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  404   retval = test<long, unsigned long>();
 
  405   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  408   retval = test<long, float>();
 
  409   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  412   retval = test<long, unsigned long>();
 
  413   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  416 #ifdef VIENNACL_WITH_OPENCL 
  420     retval = test<long, double>();
 
  421     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  429   retval = test<unsigned long, int>();
 
  430   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  433   retval = test<unsigned long, unsigned int>();
 
  434   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  437   retval = test<unsigned long, long>();
 
  438   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  441   retval = test<unsigned long, unsigned long>();
 
  442   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  445   retval = test<unsigned long, float>();
 
  446   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  449   retval = test<unsigned long, unsigned long>();
 
  450   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  453 #ifdef VIENNACL_WITH_OPENCL 
  457     retval = test<unsigned long, double>();
 
  458     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  465   retval = test<float, int>();
 
  466   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  469   retval = test<float, unsigned int>();
 
  470   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  473   retval = test<float, long>();
 
  474   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  477   retval = test<float, unsigned long>();
 
  478   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  481   retval = test<float, float>();
 
  482   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  485   retval = test<float, unsigned long>();
 
  486   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  489 #ifdef VIENNACL_WITH_OPENCL 
  493     retval = test<float, double>();
 
  494     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  501 #ifdef VIENNACL_WITH_OPENCL 
  505     retval = test<double, int>();
 
  506     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  509     retval = test<double, unsigned int>();
 
  510     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  513     retval = test<double, long>();
 
  514     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  517     retval = test<double, unsigned long>();
 
  518     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  521     retval = test<double, float>();
 
  522     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  525     retval = test<double, unsigned long>();
 
  526     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  529     retval = test<double, double>();
 
  530     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  535   std::cout << std::endl;
 
  536   std::cout << 
"------- Test completed --------" << std::endl;
 
  537   std::cout << std::endl;
 
Helper class implementing an array on the host. Default case: No conversion necessary. 
Class for representing strided submatrices of a bigger matrix A. 
Implementation of the dense matrix class. 
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.) 
int check(std::vector< NumericT > const &std_dest, std::size_t start1, std::size_t inc1, std::size_t size1, std::size_t start2, std::size_t inc2, std::size_t size2, std::size_t internal_size2, MatrixT const &vcl_dest)
vcl_size_t internal_size2(matrix_base< NumericT > const &mat)
Helper routine for obtaining the internal number of entries per column of a ViennaCL matrix...
std::string type_string(unsigned int)
result_of::size_type< T >::type start1(T const &obj)
void memory_read(mem_handle const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_read, void *ptr, bool async=false)
Reads data from a buffer back to main RAM. 
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context. 
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
result_of::size_type< T >::type start2(T const &obj)
int test(STLVectorT1 &std_src, std::size_t start1_src, std::size_t inc1_src, std::size_t size1_src, std::size_t start2_src, std::size_t inc2_src, std::size_t size2_src, std::size_t internal_size2_src, STLVectorT2 &std_dest, std::size_t start1_dest, std::size_t inc1_dest, std::size_t size1_dest, std::size_t start2_dest, std::size_t inc2_dest, std::size_t size2_dest, std::size_t internal_size2_dest, ViennaCLVectorT1 const &vcl_src, ViennaCLVectorT2 &vcl_dest)
bool double_support() const 
ViennaCL convenience function: Returns true if the device supports double precision. 
Proxy classes for matrices. 
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 range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded. 
Class for representing non-strided submatrices of a bigger matrix A. 
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded. 
Main interface routines for memory management.