39 template<
typename NumericT, 
typename VectorT>
 
   40 int check(std::vector<NumericT> 
const & std_dest, std::size_t start_dest, std::size_t inc_dest, std::size_t size_dest,
 
   41           VectorT 
const & vcl_dest)
 
   43   std::vector<NumericT> tempvec(vcl_dest.size());
 
   46   for (std::size_t i=0; i < size_dest; ++i)
 
   48     if (   std_dest[start_dest + i * inc_dest] < tempvec[i]
 
   49         || std_dest[start_dest + i * inc_dest] > tempvec[i])
 
   51       std::cerr << 
"Failure at index " << i << 
": STL value " << std_dest[start_dest + i * inc_dest] << 
", ViennaCL value " << tempvec[i] << std::endl;
 
   63 template<
typename STLVectorT1, 
typename STLVectorT2, 
typename ViennaCLVectorT1, 
typename ViennaCLVectorT2 >
 
   64 int test(STLVectorT1 & std_src,  std::size_t start_src,  std::size_t inc_src,  std::size_t size_src,
 
   65          STLVectorT2 & std_dest, std::size_t start_dest, std::size_t inc_dest, std::size_t size_dest,
 
   66          ViennaCLVectorT1 
const & vcl_src, ViennaCLVectorT2 & vcl_dest)
 
   68   assert(size_src       == size_dest       && 
bool(
"Size mismatch for STL vectors"));
 
   69   assert(vcl_src.size() == vcl_dest.size() && bool(
"Size mismatch for ViennaCL vectors"));
 
   70   assert(size_src       == vcl_src.size()  && bool(
"Size mismatch for STL and ViennaCL vectors"));
 
   72   typedef typename STLVectorT2::value_type  DestNumericT;
 
   74   for (std::size_t i=0; i<size_src; ++i)
 
   75     std_dest[start_dest + i * inc_dest] = static_cast<DestNumericT>(std_src[start_src + i * inc_src]);
 
   79   if (
check(std_dest, start_dest, inc_dest, size_dest, vcl_dest) != EXIT_SUCCESS)
 
   83   if (
check(std_dest, start_dest, inc_dest, size_dest, x) != EXIT_SUCCESS)
 
   90 inline std::string 
type_string(
unsigned int)    { 
return "unsigned int"; }
 
   92 inline std::string 
type_string(
unsigned long)   { 
return "unsigned long"; }
 
   97 template<
typename FromNumericT, 
typename ToNumericT>
 
  100   int retval = EXIT_SUCCESS;
 
  102   std::cout << std::endl;
 
  103   std::cout << 
"-----------------------------------------------" << std::endl;
 
  104   std::cout << std::endl;
 
  105   std::cout << 
"Conversion test from " << 
type_string(FromNumericT()) << 
" to " << 
type_string(ToNumericT()) << std::endl;
 
  106   std::cout << std::endl;
 
  108   std::size_t full_size  = 12345;
 
  109   std::size_t small_size = full_size / 4;
 
  113   std::vector<FromNumericT> std_src(full_size);
 
  114   std::vector<ToNumericT>   std_dest(std_src.size());
 
  116   for (std::size_t i=0; i<std_src.size(); ++i)
 
  117     std_src[i]  = FromNumericT(1.0) + FromNumericT(i);
 
  128   viennacl::copy(std_src.begin(), std_src.begin() + 
typename std::vector<FromNumericT>::difference_type(small_size), vcl_src_small.
begin());
 
  131   std::size_t r1_start = 1 +     vcl_src.size() / 4;
 
  132   std::size_t r1_stop  = 1 + 2 * vcl_src.size() / 4;
 
  135   std::size_t r2_start = 2 * vcl_src.size() / 4;
 
  136   std::size_t r2_stop  = 3 * vcl_src.size() / 4;
 
  144   std::size_t s1_start = 1 + vcl_src.size() / 5;
 
  145   std::size_t s1_inc   = 3;
 
  146   std::size_t s1_size  = vcl_src.size() / 4;
 
  149   std::size_t s2_start = 2 * vcl_dest.size() / 5;
 
  150   std::size_t s2_inc   = 2;
 
  151   std::size_t s2_size  = vcl_dest.size() / 4;
 
  161   std::cout << 
" ** vcl_src = vector, vcl_dest = vector **" << std::endl;
 
  162   retval = 
test(std_src,  0, 1, std_src.size(),
 
  163                 std_dest, 0, 1, std_dest.size(),
 
  165   if (retval != EXIT_SUCCESS)
 
  168   std::cout << 
" ** vcl_src = vector, vcl_dest = range **" << std::endl;
 
  169   retval = 
test(std_src,  0, 1, small_size,
 
  170                 std_dest, r2_start, 1, r2_stop - r2_start,
 
  171                 vcl_src_small, vcl_range_dest);
 
  172   if (retval != EXIT_SUCCESS)
 
  175   std::cout << 
" ** vcl_src = vector, vcl_dest = slice **" << std::endl;
 
  176   retval = 
test(std_src,  0, 1, small_size,
 
  177                 std_dest, s2_start, s2_inc, s2_size,
 
  178                 vcl_src_small, vcl_slice_dest);
 
  179   if (retval != EXIT_SUCCESS)
 
  184   std::cout << 
" ** vcl_src = range, vcl_dest = vector **" << std::endl;
 
  185   retval = 
test(std_src,  r1_start, 1, r1_stop - r1_start,
 
  186                 std_dest, 0, 1, small_size,
 
  187                 vcl_range_src, vcl_dest_small);
 
  188   if (retval != EXIT_SUCCESS)
 
  191   std::cout << 
" ** vcl_src = range, vcl_dest = range **" << std::endl;
 
  192   retval = 
test(std_src,  r1_start, 1, r1_stop - r1_start,
 
  193                 std_dest, r2_start, 1, r2_stop - r2_start,
 
  194                 vcl_range_src, vcl_range_dest);
 
  195   if (retval != EXIT_SUCCESS)
 
  198   std::cout << 
" ** vcl_src = range, vcl_dest = slice **" << std::endl;
 
  199   retval = 
test(std_src,  r1_start, 1, r1_stop - r1_start,
 
  200                 std_dest, s2_start, s2_inc, s2_size,
 
  201                 vcl_range_src, vcl_slice_dest);
 
  202   if (retval != EXIT_SUCCESS)
 
  207   std::cout << 
" ** vcl_src = slice, vcl_dest = vector **" << std::endl;
 
  208   retval = 
test(std_src,  s1_start, s1_inc, s1_size,
 
  209                 std_dest, 0, 1, small_size,
 
  210                 vcl_slice_src, vcl_dest_small);
 
  211   if (retval != EXIT_SUCCESS)
 
  214   std::cout << 
" ** vcl_src = slice, vcl_dest = range **" << std::endl;
 
  215   retval = 
test(std_src,  s1_start, s1_inc, s1_size,
 
  216                 std_dest, r2_start, 1, r2_stop - r2_start,
 
  217                 vcl_slice_src, vcl_range_dest);
 
  218   if (retval != EXIT_SUCCESS)
 
  221   std::cout << 
" ** vcl_src = slice, vcl_dest = slice **" << std::endl;
 
  222   retval = 
test(std_src,  s1_start, s1_inc, s1_size,
 
  223                 std_dest, s2_start, s2_inc, s2_size,
 
  224                 vcl_slice_src, vcl_slice_dest);
 
  225   if (retval != EXIT_SUCCESS)
 
  238   std::cout << std::endl;
 
  239   std::cout << 
"----------------------------------------------" << std::endl;
 
  240   std::cout << 
"----------------------------------------------" << std::endl;
 
  241   std::cout << 
"## Test :: Type conversion test for vectors   " << std::endl;
 
  242   std::cout << 
"----------------------------------------------" << std::endl;
 
  243   std::cout << 
"----------------------------------------------" << std::endl;
 
  244   std::cout << std::endl;
 
  246   int retval = EXIT_SUCCESS;
 
  251   retval = test<int, int>();
 
  252   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  255   retval = test<int, unsigned int>();
 
  256   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  259   retval = test<int, long>();
 
  260   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  263   retval = test<int, unsigned long>();
 
  264   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  267   retval = test<int, float>();
 
  268   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  271   retval = test<int, unsigned long>();
 
  272   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  275 #ifdef VIENNACL_WITH_OPENCL 
  279     retval = test<int, double>();
 
  280     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  288   retval = test<unsigned int, int>();
 
  289   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  292   retval = test<unsigned int, unsigned int>();
 
  293   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  296   retval = test<unsigned int, long>();
 
  297   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  300   retval = test<unsigned int, unsigned long>();
 
  301   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  304   retval = test<unsigned int, float>();
 
  305   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  308   retval = test<unsigned int, unsigned long>();
 
  309   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  312 #ifdef VIENNACL_WITH_OPENCL 
  316     retval = test<unsigned int, double>();
 
  317     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  325   retval = test<long, int>();
 
  326   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  329   retval = test<long, unsigned int>();
 
  330   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  333   retval = test<long, long>();
 
  334   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  337   retval = test<long, unsigned long>();
 
  338   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  341   retval = test<long, float>();
 
  342   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  345   retval = test<long, unsigned long>();
 
  346   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  349 #ifdef VIENNACL_WITH_OPENCL 
  353     retval = test<long, double>();
 
  354     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  362   retval = test<unsigned long, int>();
 
  363   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  366   retval = test<unsigned long, unsigned int>();
 
  367   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  370   retval = test<unsigned long, long>();
 
  371   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  374   retval = test<unsigned long, unsigned long>();
 
  375   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  378   retval = test<unsigned long, float>();
 
  379   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  382   retval = test<unsigned long, unsigned long>();
 
  383   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  386 #ifdef VIENNACL_WITH_OPENCL 
  390     retval = test<unsigned long, double>();
 
  391     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  398   retval = test<float, int>();
 
  399   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  402   retval = test<float, unsigned int>();
 
  403   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  406   retval = test<float, long>();
 
  407   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  410   retval = test<float, unsigned long>();
 
  411   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  414   retval = test<float, float>();
 
  415   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  418   retval = test<float, unsigned long>();
 
  419   if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  422 #ifdef VIENNACL_WITH_OPENCL 
  426     retval = test<float, double>();
 
  427     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  434 #ifdef VIENNACL_WITH_OPENCL 
  438     retval = test<double, int>();
 
  439     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  442     retval = test<double, unsigned int>();
 
  443     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  446     retval = test<double, long>();
 
  447     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  450     retval = test<double, unsigned long>();
 
  451     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  454     retval = test<double, float>();
 
  455     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  458     retval = test<double, unsigned long>();
 
  459     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  462     retval = test<double, double>();
 
  463     if ( retval == EXIT_SUCCESS ) std::cout << 
"# Test passed" << std::endl;
 
  468   std::cout << std::endl;
 
  469   std::cout << 
"------- Test completed --------" << std::endl;
 
  470   std::cout << std::endl;
 
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context. 
Class for representing non-strided subvectors of a bigger vector x. 
iterator begin()
Returns an iterator pointing to the beginning of the vector (STL like) 
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. 
Proxy classes for vectors. 
int check(std::vector< NumericT > const &std_dest, std::size_t start_dest, std::size_t inc_dest, std::size_t size_dest, VectorT const &vcl_dest)
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
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. 
std::string type_string(unsigned int)
int test(STLVectorT1 &std_src, std::size_t start_src, std::size_t inc_src, std::size_t size_src, STLVectorT2 &std_dest, std::size_t start_dest, std::size_t inc_dest, std::size_t size_dest, ViennaCLVectorT1 const &vcl_src, ViennaCLVectorT2 &vcl_dest)
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.