ViennaCL - The Vienna Computing Library  1.6.2
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vector_uint.cpp
Go to the documentation of this file.
1 /* =========================================================================
2  Copyright (c) 2010-2014, Institute for Microelectronics,
3  Institute for Analysis and Scientific Computing,
4  TU Wien.
5  Portions of this software are copyright by UChicago Argonne, LLC.
6 
7  -----------------
8  ViennaCL - The Vienna Computing Library
9  -----------------
10 
11  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
12 
13  (A list of authors and contributors can be found in the PDF manual)
14 
15  License: MIT (X11), see file LICENSE in the base directory
16 ============================================================================= */
17 
18 
19 
24 //
25 // *** System
26 //
27 #include <iostream>
28 #include <iomanip>
29 
30 //
31 // *** Boost
32 //
33 #include <boost/numeric/ublas/io.hpp>
34 #include <boost/numeric/ublas/vector.hpp>
35 #include <boost/numeric/ublas/vector_proxy.hpp>
36 
37 //
38 // *** ViennaCL
39 //
40 //#define VIENNACL_DEBUG_ALL
41 #define VIENNACL_WITH_UBLAS 1
42 #include "viennacl/vector.hpp"
49 
50 #include "Random.hpp"
51 
52 using namespace boost::numeric;
53 
54 
55 //
56 // -------------------------------------------------------------
57 //
58 template<typename ScalarType>
60 {
62  return s1 - s2;
63 }
64 //
65 // -------------------------------------------------------------
66 //
67 template<typename ScalarType>
69 {
71  return s1 - s2;
72 }
73 //
74 // -------------------------------------------------------------
75 //
76 template<typename ScalarType>
78 {
80  return s1 - s2;
81 }
82 //
83 // -------------------------------------------------------------
84 //
85 template<typename ScalarType, typename VCLVectorType>
86 ScalarType diff(ublas::vector<ScalarType> const & v1, VCLVectorType const & v2)
87 {
88  ublas::vector<ScalarType> v2_cpu(v2.size());
89  viennacl::backend::finish(); //workaround for a bug in APP SDK 2.7 on Trinity APUs (with Catalyst 12.8)
90  viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin());
91 
92  for (unsigned int i=0;i<v1.size(); ++i)
93  {
94  if (v2_cpu[i] != v1[i])
95  return 1;
96  }
97 
98  return 0;
99 }
100 
101 
102 template<typename T1, typename T2>
103 int check(T1 const & t1, T2 const & t2)
104 {
105  int retval = EXIT_SUCCESS;
106 
107  if (diff(t1, t2) != 0)
108  {
109  std::cout << "# Error! Difference: " << diff(t1, t2) << std::endl;
110  retval = EXIT_FAILURE;
111  }
112  return retval;
113 }
114 
115 
116 //
117 // -------------------------------------------------------------
118 //
119 template< typename NumericT, typename UblasVectorType, typename ViennaCLVectorType1, typename ViennaCLVectorType2 >
120 int test(UblasVectorType & ublas_v1, UblasVectorType & ublas_v2,
121  ViennaCLVectorType1 & vcl_v1, ViennaCLVectorType2 & vcl_v2)
122 {
123  int retval = EXIT_SUCCESS;
124 
125  NumericT cpu_result = 42;
126  viennacl::scalar<NumericT> gpu_result = 43;
127 
128  //
129  // Initializer:
130  //
131  std::cout << "Checking for zero_vector initializer..." << std::endl;
132  //ublas_v1 = ublas::zero_vector<NumericT>(ublas_v1.size());
133  for (std::size_t i=0; i<ublas_v1.size(); ++i)
134  ublas_v1[i] = 0;
135  vcl_v1 = viennacl::zero_vector<NumericT>(vcl_v1.size());
136  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
137  return EXIT_FAILURE;
138 
139  std::cout << "Checking for scalar_vector initializer..." << std::endl;
140  //ublas_v1 = ublas::scalar_vector<NumericT>(ublas_v1.size(), cpu_result);
141  for (std::size_t i=0; i<ublas_v1.size(); ++i)
142  ublas_v1[i] = cpu_result;
143  vcl_v1 = viennacl::scalar_vector<NumericT>(vcl_v1.size(), cpu_result);
144  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
145  return EXIT_FAILURE;
146 
147  //ublas_v1 = ublas::scalar_vector<NumericT>(ublas_v1.size(), gpu_result);
148  for (std::size_t i=0; i<ublas_v1.size(); ++i)
149  ublas_v1[i] = cpu_result + 1;
150  vcl_v1 = viennacl::scalar_vector<NumericT>(vcl_v1.size(), gpu_result);
151  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
152  return EXIT_FAILURE;
153 
154  std::cout << "Checking for unit_vector initializer..." << std::endl;
155  //ublas_v1 = ublas::unit_vector<NumericT>(ublas_v1.size(), 5);
156  for (std::size_t i=0; i<ublas_v1.size(); ++i)
157  ublas_v1[i] = (i == 5) ? 1 : 0;
158  vcl_v1 = viennacl::unit_vector<NumericT>(vcl_v1.size(), 5);
159  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
160  return EXIT_FAILURE;
161 
162  for (std::size_t i=0; i<ublas_v1.size(); ++i)
163  {
164  ublas_v1[i] = NumericT(i);
165  ublas_v2[i] = NumericT(i+42);
166  }
167 
168  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin()); //resync
169  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
170 
171  std::cout << "Checking for successful copy..." << std::endl;
172  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
173  return EXIT_FAILURE;
174  if (check(ublas_v2, vcl_v2) != EXIT_SUCCESS)
175  return EXIT_FAILURE;
176 
177  //
178  // Part 1: Norms and inner product
179  //
180 
181  // --------------------------------------------------------------------------
182  std::cout << "Testing inner_prod..." << std::endl;
183  cpu_result = viennacl::linalg::inner_prod(ublas_v1, ublas_v2);
184  NumericT cpu_result2 = viennacl::linalg::inner_prod(vcl_v1, vcl_v2);
185  gpu_result = viennacl::linalg::inner_prod(vcl_v1, vcl_v2);
186 
187  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
188  return EXIT_FAILURE;
189  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
190  return EXIT_FAILURE;
191 
192  cpu_result = inner_prod(ublas_v1 + ublas_v2, 2*ublas_v2);
193  NumericT cpu_result3 = viennacl::linalg::inner_prod(vcl_v1 + vcl_v2, 2*vcl_v2);
194  gpu_result = viennacl::linalg::inner_prod(vcl_v1 + vcl_v2, 2*vcl_v2);
195 
196  if (check(cpu_result, cpu_result3) != EXIT_SUCCESS)
197  return EXIT_FAILURE;
198  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
199  return EXIT_FAILURE;
200 
201  // --------------------------------------------------------------------------
202  std::cout << "Testing norm_1..." << std::endl;
203  cpu_result = 0;
204  for (std::size_t i=0; i<ublas_v1.size(); ++i) //note: norm_1 broken for unsigned ints on MacOS
205  cpu_result += ublas_v1[i];
206  gpu_result = viennacl::linalg::norm_1(vcl_v1);
207 
208  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
209  return EXIT_FAILURE;
210 
211  cpu_result2 = 0; //reset
212  for (std::size_t i=0; i<ublas_v1.size(); ++i) //note: norm_1 broken for unsigned ints on MacOS
213  cpu_result2 += ublas_v1[i];
214  cpu_result = viennacl::linalg::norm_1(vcl_v1);
215 
216  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
217  return EXIT_FAILURE;
218 
219  cpu_result2 = 0;
220  for (std::size_t i=0; i<ublas_v1.size(); ++i) //note: norm_1 broken for unsigned ints on MacOS
221  cpu_result2 += ublas_v1[i] + ublas_v2[i];
222  cpu_result = viennacl::linalg::norm_1(vcl_v1 + vcl_v2);
223 
224  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
225  return EXIT_FAILURE;
226 
227  // --------------------------------------------------------------------------
228  std::cout << "Testing norm_inf..." << std::endl;
229  cpu_result = 0;
230  for (std::size_t i=0; i<ublas_v1.size(); ++i)
231  if (ublas_v1[i] > cpu_result)
232  cpu_result = ublas_v1[i];
233  gpu_result = viennacl::linalg::norm_inf(vcl_v1);
234 
235  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
236  return EXIT_FAILURE;
237 
238  cpu_result2 = 0;
239  for (std::size_t i=0; i<ublas_v1.size(); ++i)
240  if (ublas_v1[i] > cpu_result2)
241  cpu_result2 = ublas_v1[i];
242  cpu_result = viennacl::linalg::norm_inf(vcl_v1);
243 
244  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
245  return EXIT_FAILURE;
246 
247  cpu_result2 = 0;
248  for (std::size_t i=0; i<ublas_v1.size(); ++i)
249  if (ublas_v1[i] + ublas_v2[i] > cpu_result2)
250  cpu_result2 = ublas_v1[i] + ublas_v2[i];
251  cpu_result = viennacl::linalg::norm_inf(vcl_v1 + vcl_v2);
252 
253  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
254  return EXIT_FAILURE;
255 
256  // --------------------------------------------------------------------------
257  std::cout << "Testing index_norm_inf..." << std::endl;
258 
259  std::size_t cpu_index = 0;
260  cpu_result = 0;
261  for (std::size_t i=0; i<ublas_v1.size(); ++i)
262  if (ublas_v1[i] > cpu_result)
263  {
264  cpu_result = ublas_v1[i];
265  cpu_index = i;
266  }
267  std::size_t gpu_index = viennacl::linalg::index_norm_inf(vcl_v1);
268 
269  if (check(static_cast<NumericT>(cpu_index), static_cast<NumericT>(gpu_index)) != EXIT_SUCCESS)
270  return EXIT_FAILURE;
271  // --------------------------------------------------------------------------
272  gpu_result = vcl_v1[viennacl::linalg::index_norm_inf(vcl_v1)];
273 
274  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
275  return EXIT_FAILURE;
276 
277  cpu_index = 0;
278  cpu_result = 0;
279  for (std::size_t i=0; i<ublas_v1.size(); ++i)
280  if (ublas_v1[i] + ublas_v2[i] > cpu_result)
281  {
282  cpu_result = ublas_v1[i];
283  cpu_index = i;
284  }
285  gpu_result = vcl_v1[viennacl::linalg::index_norm_inf(vcl_v1 + vcl_v2)];
286 
287  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
288  return EXIT_FAILURE;
289 
290  // --------------------------------------------------------------------------
291  std::cout << "Testing max..." << std::endl;
292  cpu_result = ublas_v1[0];
293  for (std::size_t i=0; i<ublas_v1.size(); ++i)
294  cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i]);
295  gpu_result = viennacl::linalg::max(vcl_v1);
296 
297  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
298  return EXIT_FAILURE;
299 
300  cpu_result = ublas_v1[0];
301  for (std::size_t i=0; i<ublas_v1.size(); ++i)
302  cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i]);
303  gpu_result = cpu_result;
304  cpu_result *= 2; //reset
305  cpu_result = viennacl::linalg::max(vcl_v1);
306 
307  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
308  return EXIT_FAILURE;
309 
310  cpu_result = ublas_v1[0] + ublas_v2[0];
311  for (std::size_t i=0; i<ublas_v1.size(); ++i)
312  cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i] + ublas_v2[i]);
313  gpu_result = cpu_result;
314  cpu_result *= 2; //reset
315  cpu_result = viennacl::linalg::max(vcl_v1 + vcl_v2);
316 
317  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
318  return EXIT_FAILURE;
319 
320 
321  // --------------------------------------------------------------------------
322  std::cout << "Testing min..." << std::endl;
323  cpu_result = ublas_v1[0];
324  for (std::size_t i=0; i<ublas_v1.size(); ++i)
325  cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i]);
326  gpu_result = viennacl::linalg::min(vcl_v1);
327 
328  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
329  return EXIT_FAILURE;
330 
331  cpu_result = ublas_v1[0];
332  for (std::size_t i=0; i<ublas_v1.size(); ++i)
333  cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i]);
334  gpu_result = cpu_result;
335  cpu_result *= 2; //reset
336  cpu_result = viennacl::linalg::min(vcl_v1);
337 
338  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
339  return EXIT_FAILURE;
340 
341  cpu_result = ublas_v1[0] + ublas_v2[0];
342  for (std::size_t i=0; i<ublas_v1.size(); ++i)
343  cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i] + ublas_v2[i]);
344  gpu_result = cpu_result;
345  cpu_result *= 2; //reset
346  cpu_result = viennacl::linalg::min(vcl_v1 + vcl_v2);
347 
348  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
349  return EXIT_FAILURE;
350 
351 
352 
353  // --------------------------------------------------------------------------
354 
355  std::cout << "Testing assignments..." << std::endl;
356  NumericT val = static_cast<NumericT>(1);
357  for (size_t i=0; i < ublas_v1.size(); ++i)
358  ublas_v1(i) = val;
359 
360  for (size_t i=0; i < vcl_v1.size(); ++i)
361  vcl_v1(i) = val;
362 
363  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
364  return EXIT_FAILURE;
365 
366 
367  //
368  // multiplication and division of vectors by scalars
369  //
370  std::cout << "Testing scaling with CPU scalar..." << std::endl;
371  NumericT alpha = static_cast<NumericT>(3);
372  viennacl::scalar<NumericT> gpu_alpha = alpha;
373 
374  ublas_v1 *= alpha;
375  vcl_v1 *= alpha;
376 
377  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
378  return EXIT_FAILURE;
379 
380  std::cout << "Testing scaling with GPU scalar..." << std::endl;
381  ublas_v1 *= alpha;
382  vcl_v1 *= gpu_alpha;
383 
384  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
385  return EXIT_FAILURE;
386 
387  NumericT beta = static_cast<NumericT>(2);
388  viennacl::scalar<NumericT> gpu_beta = beta;
389 
390  std::cout << "Testing shrinking with CPU scalar..." << std::endl;
391  ublas_v1 /= beta;
392  vcl_v1 /= beta;
393 
394  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
395  return EXIT_FAILURE;
396 
397  std::cout << "Testing shrinking with GPU scalar..." << std::endl;
398  ublas_v1 /= beta;
399  vcl_v1 /= gpu_beta;
400 
401  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
402  return EXIT_FAILURE;
403 
404 
405  //
406  // add and inplace_add of vectors
407  //
408  for (size_t i=0; i < ublas_v1.size(); ++i)
409  ublas_v1(i) = NumericT(i);
410  ublas_v2 = 3 * ublas_v1;
411  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin()); //resync
412  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
413 
414  std::cout << "Testing add on vector..." << std::endl;
415 
416  std::cout << "Checking for successful copy..." << std::endl;
417  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
418  return EXIT_FAILURE;
419  if (check(ublas_v2, vcl_v2) != EXIT_SUCCESS)
420  return EXIT_FAILURE;
421 
422  ublas_v1 = ublas_v1 + ublas_v2;
423  vcl_v1 = vcl_v1 + vcl_v2;
424 
425  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
426  return EXIT_FAILURE;
427 
428  std::cout << "Testing inplace-add on vector..." << std::endl;
429  ublas_v1 += ublas_v2;
430  vcl_v1 += vcl_v2;
431 
432  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
433  return EXIT_FAILURE;
434 
435 
436  //
437  // multiply-add
438  //
439  std::cout << "Testing multiply-add on vector with CPU scalar (right)..." << std::endl;
440  for (size_t i=0; i < ublas_v1.size(); ++i)
441  ublas_v1(i) = NumericT(i);
442  ublas_v2 = 3 * ublas_v1;
443  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
444  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
445 
446  ublas_v1 = ublas_v1 + alpha * ublas_v2;
447  vcl_v1 = vcl_v1 + alpha * vcl_v2;
448 
449  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
450  return EXIT_FAILURE;
451 
452  std::cout << "Testing multiply-add on vector with CPU scalar (left)..." << std::endl;
453  ublas_v2 = 3 * ublas_v1;
454  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
455  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
456 
457  ublas_v1 = alpha * ublas_v1 + ublas_v2;
458  vcl_v1 = alpha * vcl_v1 + vcl_v2;
459 
460  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
461  return EXIT_FAILURE;
462 
463  std::cout << "Testing multiply-add on vector with CPU scalar (both)..." << std::endl;
464  ublas_v2 = 3 * ublas_v1;
465  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
466  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
467 
468  ublas_v1 = alpha * ublas_v1 + beta * ublas_v2;
469  vcl_v1 = alpha * vcl_v1 + beta * vcl_v2;
470 
471  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
472  return EXIT_FAILURE;
473 
474 
475  std::cout << "Testing inplace multiply-add on vector with CPU scalar..." << std::endl;
476  ublas_v2 = 3 * ublas_v1;
477  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
478  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
479 
480  ublas_v1 += alpha * ublas_v2;
481  vcl_v1 += alpha * vcl_v2;
482 
483  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
484  return EXIT_FAILURE;
485 
486 
487  std::cout << "Testing multiply-add on vector with GPU scalar (right)..." << std::endl;
488  ublas_v2 = 3 * ublas_v1;
489  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
490  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
491 
492  ublas_v1 = ublas_v1 + alpha * ublas_v2;
493  vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
494 
495  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
496  return EXIT_FAILURE;
497 
498  std::cout << "Testing multiply-add on vector with GPU scalar (left)..." << std::endl;
499  ublas_v2 = 3 * ublas_v1;
500  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
501  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
502 
503  ublas_v1 = ublas_v1 + alpha * ublas_v2;
504  vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
505 
506  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
507  return EXIT_FAILURE;
508 
509  std::cout << "Testing multiply-add on vector with GPU scalar (both)..." << std::endl;
510  ublas_v2 = 3 * ublas_v1;
511  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
512  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
513 
514  ublas_v1 = alpha * ublas_v1 + beta * ublas_v2;
515  vcl_v1 = gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
516 
517  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
518  return EXIT_FAILURE;
519 
520 
521  std::cout << "Testing inplace multiply-add on vector with GPU scalar (both, adding)..." << std::endl;
522  ublas_v2 = 3 * ublas_v1;
523  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
524  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
525 
526  ublas_v1 += alpha * ublas_v1 + beta * ublas_v2;
527  vcl_v1 += gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
528 
529  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
530  return EXIT_FAILURE;
531 
532 
533  std::cout << "Testing inplace multiply-add on vector with GPU scalar..." << std::endl;
534  ublas_v2 = 3 * ublas_v1;
535  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
536  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
537 
538  ublas_v1 += alpha * ublas_v2;
539  vcl_v1 += gpu_alpha * vcl_v2;
540 
541  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
542  return EXIT_FAILURE;
543 
544 
545  //
546  // division-add
547  //
548  std::cout << "Testing division-add on vector with CPU scalar (right)..." << std::endl;
549  for (size_t i=0; i < ublas_v1.size(); ++i)
550  ublas_v1(i) = NumericT(i);
551  ublas_v2 = 3 * ublas_v1;
552  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
553  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
554 
555  ublas_v1 = ublas_v1 + ublas_v2 / alpha;
556  vcl_v1 = vcl_v1 + vcl_v2 / alpha;
557 
558  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
559  return EXIT_FAILURE;
560 
561 
562  std::cout << "Testing division-add on vector with CPU scalar (left)..." << std::endl;
563  ublas_v2 = 3 * ublas_v1;
564  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
565  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
566 
567  ublas_v1 = ublas_v1 / alpha + ublas_v2;
568  vcl_v1 = vcl_v1 / alpha + vcl_v2;
569 
570  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
571  return EXIT_FAILURE;
572 
573  std::cout << "Testing division-add on vector with CPU scalar (both)..." << std::endl;
574  ublas_v2 = 3 * ublas_v1;
575  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
576  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
577 
578  ublas_v1 = ublas_v1 / alpha + ublas_v2 / beta;
579  vcl_v1 = vcl_v1 / alpha + vcl_v2 / beta;
580 
581  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
582  return EXIT_FAILURE;
583 
584  std::cout << "Testing division-multiply-add on vector with CPU scalar..." << std::endl;
585  ublas_v2 = 3 * ublas_v1;
586  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
587  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
588 
589  ublas_v1 = ublas_v1 / alpha + ublas_v2 * beta;
590  vcl_v1 = vcl_v1 / alpha + vcl_v2 * beta;
591 
592  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
593  return EXIT_FAILURE;
594 
595 
596  std::cout << "Testing multiply-division-add on vector with CPU scalar..." << std::endl;
597  ublas_v2 = 3 * ublas_v1;
598  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
599  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
600 
601  ublas_v1 = ublas_v1 * alpha + ublas_v2 / beta;
602  vcl_v1 = vcl_v1 * alpha + vcl_v2 / beta;
603 
604  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
605  return EXIT_FAILURE;
606 
607 
608 
609  std::cout << "Testing inplace division-add on vector with CPU scalar..." << std::endl;
610  ublas_v2 = 3 * ublas_v1;
611  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
612  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
613 
614  ublas_v1 += ublas_v2 / alpha;
615  vcl_v1 += vcl_v2 / alpha;
616 
617  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
618  return EXIT_FAILURE;
619 
620 
621  std::cout << "Testing division-add on vector with GPU scalar (right)..." << std::endl;
622  ublas_v2 = 3 * ublas_v1;
623  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
624  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
625 
626  ublas_v1 = ublas_v1 + ublas_v2 / alpha;
627  vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
628 
629  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
630  return EXIT_FAILURE;
631 
632  std::cout << "Testing division-add on vector with GPU scalar (left)..." << std::endl;
633  ublas_v2 = 3 * ublas_v1;
634  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
635  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
636 
637  ublas_v1 = ublas_v1 + ublas_v2 / alpha;
638  vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
639 
640  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
641  return EXIT_FAILURE;
642 
643  std::cout << "Testing division-add on vector with GPU scalar (both)..." << std::endl;
644  ublas_v2 = 3 * ublas_v1;
645  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
646  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
647 
648  ublas_v1 = ublas_v1 / alpha + ublas_v2 / beta;
649  vcl_v1 = vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
650 
651  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
652  return EXIT_FAILURE;
653 
654 
655  std::cout << "Testing inplace division-add on vector with GPU scalar (both, adding)..." << std::endl;
656  ublas_v2 = 3 * ublas_v1;
657  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
658  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
659 
660  ublas_v1 += ublas_v1 / alpha + ublas_v2 / beta;
661  vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
662 
663  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
664  return EXIT_FAILURE;
665 
666  std::cout << "Testing inplace division-multiply-add on vector with GPU scalar (adding)..." << std::endl;
667  ublas_v2 = 3 * ublas_v1;
668  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
669  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
670 
671  ublas_v1 += ublas_v1 / alpha + ublas_v2 * beta;
672  vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 * gpu_beta;
673 
674  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
675  return EXIT_FAILURE;
676 
677 
678  std::cout << "Testing inplace division-add on vector with GPU scalar..." << std::endl;
679  ublas_v2 = 3 * ublas_v1;
680  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
681  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
682 
683  ublas_v1 += ublas_v2 * alpha;
684  vcl_v1 += vcl_v2 * gpu_alpha;
685 
686  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
687  return EXIT_FAILURE;
688 
689  //
690  // More complicated expressions (for ensuring the operator overloads work correctly)
691  //
692  for (size_t i=0; i < ublas_v1.size(); ++i)
693  ublas_v1(i) = NumericT(i);
694  ublas_v2 = 3 * ublas_v1;
695  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
696  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
697 
698  std::cout << "Testing three vector additions..." << std::endl;
699  ublas_v1 = ublas_v2 + ublas_v1 + ublas_v2;
700  vcl_v1 = vcl_v2 + vcl_v1 + vcl_v2;
701 
702  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
703  return EXIT_FAILURE;
704 
705  // --------------------------------------------------------------------------
706  ublas_v2 = 3 * ublas_v1;
707  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
708  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
709 
710  std::cout << "Testing swap..." << std::endl;
711  swap(ublas_v1, ublas_v2);
712  swap(vcl_v1, vcl_v2);
713 
714  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
715  return EXIT_FAILURE;
716 
717  std::cout << "Testing elementwise multiplication..." << std::endl;
718  std::cout << " v1 = element_prod(v1, v2);" << std::endl;
719  ublas_v1 = ublas::element_prod(ublas_v1, ublas_v2);
720  vcl_v1 = viennacl::linalg::element_prod(vcl_v1, vcl_v2);
721 
722  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
723  return EXIT_FAILURE;
724 
725  std::cout << " v1 += element_prod(v1, v2);" << std::endl;
726  ublas_v1 += ublas::element_prod(ublas_v1, ublas_v2);
727  vcl_v1 += viennacl::linalg::element_prod(vcl_v1, vcl_v2);
728 
729  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
730  return EXIT_FAILURE;
731 
733  std::cout << " v1 = element_prod(v1 + v2, v2);" << std::endl;
734  ublas_v1 = ublas::element_prod(ublas_v1 + ublas_v2, ublas_v2);
735  vcl_v1 = viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2);
736 
737  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
738  return EXIT_FAILURE;
739 
740  std::cout << " v1 += element_prod(v1 + v2, v2);" << std::endl;
741  ublas_v1 += ublas::element_prod(ublas_v1 + ublas_v2, ublas_v2);
742  vcl_v1 += viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2);
743 
744  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
745  return EXIT_FAILURE;
746 
748  std::cout << " v1 = element_prod(v1, v2 + v1);" << std::endl;
749  ublas_v1 = ublas::element_prod(ublas_v1, ublas_v2 + ublas_v1);
750  vcl_v1 = viennacl::linalg::element_prod(vcl_v1, vcl_v2 + vcl_v1);
751 
752  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
753  return EXIT_FAILURE;
754 
755  std::cout << " v1 += element_prod(v1, v2 + v1);" << std::endl;
756  ublas_v1 += ublas::element_prod(ublas_v1, ublas_v2 + ublas_v1);
757  vcl_v1 += viennacl::linalg::element_prod(vcl_v1, vcl_v2 + vcl_v1);
758 
759  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
760  return EXIT_FAILURE;
761 
763  std::cout << " v1 = element_prod(v1 + v2, v2 + v1);" << std::endl;
764  ublas_v1 = ublas::element_prod(ublas_v1 + ublas_v2, ublas_v2 + ublas_v1);
765  vcl_v1 = viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
766 
767  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
768  return EXIT_FAILURE;
769 
770  std::cout << " v1 += element_prod(v1 + v2, v2 + v1);" << std::endl;
771  ublas_v1 += ublas::element_prod(ublas_v1 + ublas_v2, ublas_v2 + ublas_v1);
772  vcl_v1 += viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
773 
774  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
775  return EXIT_FAILURE;
776 
777 
778  std::cout << "Testing elementwise division..." << std::endl;
779  for (std::size_t i=0; i<ublas_v1.size(); ++i)
780  {
781  ublas_v1[i] = NumericT(1 + i);
782  ublas_v2[i] = NumericT(5 + i);
783  }
784 
785  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
786  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
787 
788  ublas_v1 = ublas::element_div(ublas_v1, ublas_v2);
789  vcl_v1 = viennacl::linalg::element_div(vcl_v1, vcl_v2);
790 
791  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
792  return EXIT_FAILURE;
793 
794  ublas_v1 += ublas::element_div(ublas_v1, ublas_v2);
795  vcl_v1 += viennacl::linalg::element_div(vcl_v1, vcl_v2);
796 
797  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
798  return EXIT_FAILURE;
799 
801  ublas_v1 = ublas::element_div(ublas_v1 + ublas_v2, ublas_v2);
802  vcl_v1 = viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2);
803 
804  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
805  return EXIT_FAILURE;
806 
807  ublas_v1 += ublas::element_div(ublas_v1 + ublas_v2, ublas_v2);
808  vcl_v1 += viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2);
809 
810  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
811  return EXIT_FAILURE;
812 
814  ublas_v1 = ublas::element_div(ublas_v1, ublas_v2 + ublas_v1);
815  vcl_v1 = viennacl::linalg::element_div(vcl_v1, vcl_v2 + vcl_v1);
816 
817  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
818  return EXIT_FAILURE;
819 
820  ublas_v1 += ublas::element_div(ublas_v1, ublas_v2 + ublas_v1);
821  vcl_v1 += viennacl::linalg::element_div(vcl_v1, vcl_v2 + vcl_v1);
822 
823  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
824  return EXIT_FAILURE;
825 
827  ublas_v1 = ublas::element_div(ublas_v1 + ublas_v2, ublas_v2 + ublas_v1);
828  vcl_v1 = viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
829 
830  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
831  return EXIT_FAILURE;
832 
833  ublas_v1 += ublas::element_div(ublas_v1 + ublas_v2, ublas_v2 + ublas_v1);
834  vcl_v1 += viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
835 
836  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
837  return EXIT_FAILURE;
838 
839  // --------------------------------------------------------------------------
840  return retval;
841 }
842 
843 
844 template< typename NumericT >
845 int test()
846 {
847  int retval = EXIT_SUCCESS;
848  std::size_t size = 12345;
849 
850  std::cout << "Running tests for vector of size " << size << std::endl;
851 
852  //
853  // Set up UBLAS objects
854  //
855  ublas::vector<NumericT> ublas_full_vec(size);
856  ublas::vector<NumericT> ublas_full_vec2(ublas_full_vec.size());
857 
858  for (std::size_t i=0; i<ublas_full_vec.size(); ++i)
859  {
860  ublas_full_vec[i] = NumericT(1.0) + NumericT(i);
861  ublas_full_vec2[i] = NumericT(2.0) + NumericT(i) / NumericT(2);
862  }
863 
864  ublas::range r1( ublas_full_vec.size() / 4, 2 * ublas_full_vec.size() / 4);
865  ublas::range r2(2 * ublas_full_vec2.size() / 4, 3 * ublas_full_vec2.size() / 4);
866  ublas::vector_range< ublas::vector<NumericT> > ublas_range_vec(ublas_full_vec, r1);
867  ublas::vector_range< ublas::vector<NumericT> > ublas_range_vec2(ublas_full_vec2, r2);
868 
869  ublas::slice s1( ublas_full_vec.size() / 4, 3, ublas_full_vec.size() / 4);
870  ublas::slice s2(2 * ublas_full_vec2.size() / 4, 2, ublas_full_vec2.size() / 4);
871  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec(ublas_full_vec, s1);
872  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec2(ublas_full_vec2, s2);
873 
874  //
875  // Set up ViennaCL objects
876  //
877  viennacl::vector<NumericT> vcl_full_vec(ublas_full_vec.size());
878  viennacl::vector<NumericT> vcl_full_vec2(ublas_full_vec2.size());
879 
880  viennacl::fast_copy(ublas_full_vec.begin(), ublas_full_vec.end(), vcl_full_vec.begin());
881  viennacl::copy(ublas_full_vec2.begin(), ublas_full_vec2.end(), vcl_full_vec2.begin());
882 
883  viennacl::range vcl_r1( vcl_full_vec.size() / 4, 2 * vcl_full_vec.size() / 4);
884  viennacl::range vcl_r2(2 * vcl_full_vec2.size() / 4, 3 * vcl_full_vec2.size() / 4);
885  viennacl::vector_range< viennacl::vector<NumericT> > vcl_range_vec(vcl_full_vec, vcl_r1);
886  viennacl::vector_range< viennacl::vector<NumericT> > vcl_range_vec2(vcl_full_vec2, vcl_r2);
887 
888  {
889  viennacl::vector<NumericT> vcl_short_vec(vcl_range_vec);
890  viennacl::vector<NumericT> vcl_short_vec2 = vcl_range_vec2;
891 
892  ublas::vector<NumericT> ublas_short_vec(ublas_range_vec);
893  ublas::vector<NumericT> ublas_short_vec2(ublas_range_vec2);
894 
895  std::cout << "Testing creation of vectors from range..." << std::endl;
896  if (check(ublas_short_vec, vcl_short_vec) != EXIT_SUCCESS)
897  return EXIT_FAILURE;
898  if (check(ublas_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
899  return EXIT_FAILURE;
900  }
901 
902  viennacl::slice vcl_s1( vcl_full_vec.size() / 4, 3, vcl_full_vec.size() / 4);
903  viennacl::slice vcl_s2(2 * vcl_full_vec2.size() / 4, 2, vcl_full_vec2.size() / 4);
904  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec(vcl_full_vec, vcl_s1);
905  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec2(vcl_full_vec2, vcl_s2);
906 
907  viennacl::vector<NumericT> vcl_short_vec(vcl_slice_vec);
908  viennacl::vector<NumericT> vcl_short_vec2 = vcl_slice_vec2;
909 
910  ublas::vector<NumericT> ublas_short_vec(ublas_slice_vec);
911  ublas::vector<NumericT> ublas_short_vec2(ublas_slice_vec2);
912 
913  std::cout << "Testing creation of vectors from slice..." << std::endl;
914  if (check(ublas_short_vec, vcl_short_vec) != EXIT_SUCCESS)
915  return EXIT_FAILURE;
916  if (check(ublas_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
917  return EXIT_FAILURE;
918 
919 
920  //
921  // Now start running tests for vectors, ranges and slices:
922  //
923 
924  std::cout << " ** vcl_v1 = vector, vcl_v2 = vector **" << std::endl;
925  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
926  vcl_short_vec, vcl_short_vec2);
927  if (retval != EXIT_SUCCESS)
928  return EXIT_FAILURE;
929 
930  std::cout << " ** vcl_v1 = vector, vcl_v2 = range **" << std::endl;
931  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
932  vcl_short_vec, vcl_range_vec2);
933  if (retval != EXIT_SUCCESS)
934  return EXIT_FAILURE;
935 
936  std::cout << " ** vcl_v1 = vector, vcl_v2 = slice **" << std::endl;
937  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
938  vcl_short_vec, vcl_slice_vec2);
939  if (retval != EXIT_SUCCESS)
940  return EXIT_FAILURE;
941 
943 
944  std::cout << " ** vcl_v1 = range, vcl_v2 = vector **" << std::endl;
945  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
946  vcl_range_vec, vcl_short_vec2);
947  if (retval != EXIT_SUCCESS)
948  return EXIT_FAILURE;
949 
950  std::cout << " ** vcl_v1 = range, vcl_v2 = range **" << std::endl;
951  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
952  vcl_range_vec, vcl_range_vec2);
953  if (retval != EXIT_SUCCESS)
954  return EXIT_FAILURE;
955 
956  std::cout << " ** vcl_v1 = range, vcl_v2 = slice **" << std::endl;
957  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
958  vcl_range_vec, vcl_slice_vec2);
959  if (retval != EXIT_SUCCESS)
960  return EXIT_FAILURE;
961 
963 
964  std::cout << " ** vcl_v1 = slice, vcl_v2 = vector **" << std::endl;
965  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
966  vcl_slice_vec, vcl_short_vec2);
967  if (retval != EXIT_SUCCESS)
968  return EXIT_FAILURE;
969 
970  std::cout << " ** vcl_v1 = slice, vcl_v2 = range **" << std::endl;
971  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
972  vcl_slice_vec, vcl_range_vec2);
973  if (retval != EXIT_SUCCESS)
974  return EXIT_FAILURE;
975 
976  std::cout << " ** vcl_v1 = slice, vcl_v2 = slice **" << std::endl;
977  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
978  vcl_slice_vec, vcl_slice_vec2);
979  if (retval != EXIT_SUCCESS)
980  return EXIT_FAILURE;
981 
982  return EXIT_SUCCESS;
983 }
984 
985 
986 
987 //
988 // -------------------------------------------------------------
989 //
990 int main()
991 {
992  std::cout << std::endl;
993  std::cout << "----------------------------------------------" << std::endl;
994  std::cout << "----------------------------------------------" << std::endl;
995  std::cout << "## Test :: Vector with Integer types" << std::endl;
996  std::cout << "----------------------------------------------" << std::endl;
997  std::cout << "----------------------------------------------" << std::endl;
998  std::cout << std::endl;
999 
1000  int retval = EXIT_SUCCESS;
1001 
1002  std::cout << std::endl;
1003  std::cout << "----------------------------------------------" << std::endl;
1004  std::cout << std::endl;
1005  {
1006  std::cout << "# Testing setup:" << std::endl;
1007  std::cout << " numeric: unsigned int" << std::endl;
1008  retval = test<unsigned int>();
1009  if ( retval == EXIT_SUCCESS )
1010  std::cout << "# Test passed" << std::endl;
1011  else
1012  return retval;
1013  }
1014  std::cout << std::endl;
1015  std::cout << "----------------------------------------------" << std::endl;
1016  std::cout << std::endl;
1017  {
1018  std::cout << "# Testing setup:" << std::endl;
1019  std::cout << " numeric: long" << std::endl;
1020  retval = test<unsigned long>();
1021  if ( retval == EXIT_SUCCESS )
1022  std::cout << "# Test passed" << std::endl;
1023  else
1024  return retval;
1025  }
1026  std::cout << std::endl;
1027  std::cout << "----------------------------------------------" << std::endl;
1028  std::cout << std::endl;
1029 
1030  std::cout << std::endl;
1031  std::cout << "------- Test completed --------" << std::endl;
1032  std::cout << std::endl;
1033 
1034  return retval;
1035 }
int test(UblasVectorType &ublas_v1, UblasVectorType &ublas_v2, ViennaCLVectorType1 &vcl_v1, ViennaCLVectorType2 &vcl_v2)
viennacl::vector_expression< const vector_base< T >, const vector_base< T >, op_element_binary< op_div > > element_div(vector_base< T > const &v1, vector_base< T > const &v2)
vcl_size_t index_norm_inf(vector_base< T > const &vec)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:226
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
int check(T1 const &t1, T2 const &t2)
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
Definition: memory.hpp:54
viennacl::enable_if< viennacl::is_stl< typename viennacl::traits::tag_of< VectorT1 >::type >::value, typename VectorT1::value_type >::type inner_prod(VectorT1 const &v1, VectorT2 const &v2)
Definition: inner_prod.hpp:89
viennacl::scalar< int > s2
viennacl::scalar< float > s1
Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
Generic interface for the l^1-norm. See viennacl/linalg/vector_operations.hpp for implementations...
basic_range range
Definition: forwards.h:423
viennacl::vector< float > v1
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
Class for representing non-strided subvectors of a bigger vector x.
Definition: forwards.h:433
Class for representing strided subvectors of a bigger vector x.
Definition: forwards.h:436
Proxy classes for vectors.
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value >::type swap(ScalarT1 &s1, ScalarT2 &s2)
Swaps the contents of two scalars, data is copied.
int main()
ScalarType diff(ScalarType const &s1, ScalarType const &s2)
Definition: vector_uint.cpp:59
Represents a vector consisting of 1 at a given index and zeros otherwise.
Definition: vector_def.hpp:76
viennacl::vector< int > v2
basic_slice slice
Definition: forwards.h:428
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
Definition: vector_def.hpp:87
NumericT max(std::vector< NumericT > const &v1)
Definition: maxmin.hpp:47
T norm_inf(std::vector< T, A > const &v1)
Definition: norm_inf.hpp:60
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) ...
T norm_1(std::vector< T, A > const &v1)
Definition: norm_1.hpp:61
A range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:423
float ScalarType
Definition: fft_1d.cpp:42
viennacl::vector_expression< const vector_base< T >, const vector_base< T >, op_element_binary< op_prod > > element_prod(vector_base< T > const &v1, vector_base< T > const &v2)
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:428
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
Definition: forwards.h:232
Generic interface for the l^infty-norm. See viennacl/linalg/vector_operations.hpp for implementations...
NumericT min(std::vector< NumericT > const &v1)
Definition: maxmin.hpp:91
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)