ViennaCL - The Vienna Computing Library  1.7.1
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-2016, 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 #include <vector>
30 
31 //
32 // *** ViennaCL
33 //
34 #include "viennacl/vector.hpp"
41 #include "viennacl/linalg/sum.hpp"
42 
43 
44 //
45 // -------------------------------------------------------------
46 //
47 template<typename ScalarType>
49 {
51  return s1 - s2;
52 }
53 //
54 // -------------------------------------------------------------
55 //
56 template<typename ScalarType>
58 {
60  return s1 - s2;
61 }
62 //
63 // -------------------------------------------------------------
64 //
65 template<typename ScalarType>
67 {
69  return s1 - s2;
70 }
71 //
72 // -------------------------------------------------------------
73 //
74 template<typename ScalarType, typename VCLVectorType>
75 ScalarType diff(std::vector<ScalarType> const & v1, VCLVectorType const & v2)
76 {
77  std::vector<ScalarType> v2_cpu(v2.size());
78  viennacl::backend::finish(); //workaround for a bug in APP SDK 2.7 on Trinity APUs (with Catalyst 12.8)
79  viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin());
80 
81  for (unsigned int i=0;i<v1.size(); ++i)
82  {
83  if (v2_cpu[i] != v1[i])
84  return 1;
85  }
86 
87  return 0;
88 }
89 
90 
91 template<typename T1, typename T2>
92 int check(T1 const & t1, T2 const & t2)
93 {
94  int retval = EXIT_SUCCESS;
95 
96  if (diff(t1, t2) != 0)
97  {
98  std::cout << "# Error! Difference: " << diff(t1, t2) << std::endl;
99  retval = EXIT_FAILURE;
100  }
101  return retval;
102 }
103 
104 
105 //
106 // -------------------------------------------------------------
107 //
108 template< typename NumericT, typename STLVectorType, typename ViennaCLVectorType1, typename ViennaCLVectorType2 >
109 int test(STLVectorType & std_v1, STLVectorType & std_v2,
110  ViennaCLVectorType1 & vcl_v1, ViennaCLVectorType2 & vcl_v2)
111 {
112  int retval = EXIT_SUCCESS;
113 
114  NumericT cpu_result = 42;
115  viennacl::scalar<NumericT> gpu_result = 43;
116 
117  //
118  // Initializer:
119  //
120  std::cout << "Checking for zero_vector initializer..." << std::endl;
121  for (std::size_t i=0; i<std_v1.size(); ++i)
122  std_v1[i] = 0;
123  vcl_v1 = viennacl::zero_vector<NumericT>(vcl_v1.size());
124  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
125  return EXIT_FAILURE;
126 
127  std::cout << "Checking for scalar_vector initializer..." << std::endl;
128  for (std::size_t i=0; i<std_v1.size(); ++i)
129  std_v1[i] = cpu_result;
130  vcl_v1 = viennacl::scalar_vector<NumericT>(vcl_v1.size(), cpu_result);
131  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
132  return EXIT_FAILURE;
133 
134  for (std::size_t i=0; i<std_v1.size(); ++i)
135  std_v1[i] = cpu_result + 1;
136  vcl_v1 = viennacl::scalar_vector<NumericT>(vcl_v1.size(), gpu_result);
137  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
138  return EXIT_FAILURE;
139 
140  std::cout << "Checking for unit_vector initializer..." << std::endl;
141  for (std::size_t i=0; i<std_v1.size(); ++i)
142  std_v1[i] = (i == 5) ? 1 : 0;
143  vcl_v1 = viennacl::unit_vector<NumericT>(vcl_v1.size(), 5);
144  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
145  return EXIT_FAILURE;
146 
147  for (std::size_t i=0; i<std_v1.size(); ++i)
148  {
149  std_v1[i] = NumericT(i);
150  std_v2[i] = NumericT(i+42);
151  }
152 
153  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin()); //resync
154  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
155 
156  std::cout << "Checking for successful copy..." << std::endl;
157  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
158  return EXIT_FAILURE;
159  if (check(std_v2, vcl_v2) != EXIT_SUCCESS)
160  return EXIT_FAILURE;
161 
162  //
163  // Part 1: Norms and inner product
164  //
165 
166  // --------------------------------------------------------------------------
167  std::cout << "Testing inner_prod..." << std::endl;
168  cpu_result = 0;
169  for (std::size_t i=0; i<std_v1.size(); ++i)
170  cpu_result += std_v1[i] * std_v2[i];
171  NumericT cpu_result2 = viennacl::linalg::inner_prod(vcl_v1, vcl_v2);
172  gpu_result = viennacl::linalg::inner_prod(vcl_v1, vcl_v2);
173 
174  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
175  return EXIT_FAILURE;
176  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
177  return EXIT_FAILURE;
178 
179  cpu_result = 0;
180  for (std::size_t i=0; i<std_v1.size(); ++i)
181  cpu_result += (std_v1[i] + std_v2[i]) * (2*std_v2[i]);
182  NumericT cpu_result3 = viennacl::linalg::inner_prod(vcl_v1 + vcl_v2, 2*vcl_v2);
183  gpu_result = viennacl::linalg::inner_prod(vcl_v1 + vcl_v2, 2*vcl_v2);
184 
185  if (check(cpu_result, cpu_result3) != EXIT_SUCCESS)
186  return EXIT_FAILURE;
187  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
188  return EXIT_FAILURE;
189 
190  // --------------------------------------------------------------------------
191  std::cout << "Testing norm_1..." << std::endl;
192  cpu_result = 0;
193  for (std::size_t i=0; i<std_v1.size(); ++i) //note: norm_1 broken for unsigned ints on MacOS
194  cpu_result += std_v1[i];
195  gpu_result = viennacl::linalg::norm_1(vcl_v1);
196 
197  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
198  return EXIT_FAILURE;
199 
200  cpu_result2 = 0; //reset
201  for (std::size_t i=0; i<std_v1.size(); ++i) //note: norm_1 broken for unsigned ints on MacOS
202  cpu_result2 += std_v1[i];
203  cpu_result = viennacl::linalg::norm_1(vcl_v1);
204 
205  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
206  return EXIT_FAILURE;
207 
208  cpu_result2 = 0;
209  for (std::size_t i=0; i<std_v1.size(); ++i) //note: norm_1 broken for unsigned ints on MacOS
210  cpu_result2 += std_v1[i] + std_v2[i];
211  cpu_result = viennacl::linalg::norm_1(vcl_v1 + vcl_v2);
212 
213  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
214  return EXIT_FAILURE;
215 
216  // --------------------------------------------------------------------------
217  std::cout << "Testing norm_inf..." << std::endl;
218  cpu_result = 0;
219  for (std::size_t i=0; i<std_v1.size(); ++i)
220  if (std_v1[i] > cpu_result)
221  cpu_result = std_v1[i];
222  gpu_result = viennacl::linalg::norm_inf(vcl_v1);
223 
224  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
225  return EXIT_FAILURE;
226 
227  cpu_result2 = 0;
228  for (std::size_t i=0; i<std_v1.size(); ++i)
229  if (std_v1[i] > cpu_result2)
230  cpu_result2 = std_v1[i];
231  cpu_result = viennacl::linalg::norm_inf(vcl_v1);
232 
233  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
234  return EXIT_FAILURE;
235 
236  cpu_result2 = 0;
237  for (std::size_t i=0; i<std_v1.size(); ++i)
238  if (std_v1[i] + std_v2[i] > cpu_result2)
239  cpu_result2 = std_v1[i] + std_v2[i];
240  cpu_result = viennacl::linalg::norm_inf(vcl_v1 + vcl_v2);
241 
242  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
243  return EXIT_FAILURE;
244 
245  // --------------------------------------------------------------------------
246  std::cout << "Testing index_norm_inf..." << std::endl;
247 
248  std::size_t cpu_index = 0;
249  cpu_result = 0;
250  for (std::size_t i=0; i<std_v1.size(); ++i)
251  if (std_v1[i] > cpu_result)
252  {
253  cpu_result = std_v1[i];
254  cpu_index = i;
255  }
256  std::size_t gpu_index = viennacl::linalg::index_norm_inf(vcl_v1);
257 
258  if (check(static_cast<NumericT>(cpu_index), static_cast<NumericT>(gpu_index)) != EXIT_SUCCESS)
259  return EXIT_FAILURE;
260  // --------------------------------------------------------------------------
261  gpu_result = vcl_v1[viennacl::linalg::index_norm_inf(vcl_v1)];
262 
263  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
264  return EXIT_FAILURE;
265 
266  cpu_index = 0;
267  cpu_result = 0;
268  for (std::size_t i=0; i<std_v1.size(); ++i)
269  if (std_v1[i] + std_v2[i] > cpu_result)
270  {
271  cpu_result = std_v1[i];
272  cpu_index = i;
273  }
274  gpu_result = vcl_v1[viennacl::linalg::index_norm_inf(vcl_v1 + vcl_v2)];
275 
276  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
277  return EXIT_FAILURE;
278 
279  // --------------------------------------------------------------------------
280  std::cout << "Testing max..." << std::endl;
281  cpu_result = std_v1[0];
282  for (std::size_t i=0; i<std_v1.size(); ++i)
283  cpu_result = std::max<NumericT>(cpu_result, std_v1[i]);
284  gpu_result = viennacl::linalg::max(vcl_v1);
285 
286  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
287  return EXIT_FAILURE;
288 
289  cpu_result = std_v1[0];
290  for (std::size_t i=0; i<std_v1.size(); ++i)
291  cpu_result = std::max<NumericT>(cpu_result, std_v1[i]);
292  gpu_result = cpu_result;
293  cpu_result *= 2; //reset
294  cpu_result = viennacl::linalg::max(vcl_v1);
295 
296  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
297  return EXIT_FAILURE;
298 
299  cpu_result = std_v1[0] + std_v2[0];
300  for (std::size_t i=0; i<std_v1.size(); ++i)
301  cpu_result = std::max<NumericT>(cpu_result, std_v1[i] + std_v2[i]);
302  gpu_result = cpu_result;
303  cpu_result *= 2; //reset
304  cpu_result = viennacl::linalg::max(vcl_v1 + vcl_v2);
305 
306  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
307  return EXIT_FAILURE;
308 
309 
310  // --------------------------------------------------------------------------
311  std::cout << "Testing min..." << std::endl;
312  cpu_result = std_v1[0];
313  for (std::size_t i=0; i<std_v1.size(); ++i)
314  cpu_result = std::min<NumericT>(cpu_result, std_v1[i]);
315  gpu_result = viennacl::linalg::min(vcl_v1);
316 
317  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
318  return EXIT_FAILURE;
319 
320  cpu_result = std_v1[0];
321  for (std::size_t i=0; i<std_v1.size(); ++i)
322  cpu_result = std::min<NumericT>(cpu_result, std_v1[i]);
323  gpu_result = cpu_result;
324  cpu_result *= 2; //reset
325  cpu_result = viennacl::linalg::min(vcl_v1);
326 
327  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
328  return EXIT_FAILURE;
329 
330  cpu_result = std_v1[0] + std_v2[0];
331  for (std::size_t i=0; i<std_v1.size(); ++i)
332  cpu_result = std::min<NumericT>(cpu_result, std_v1[i] + std_v2[i]);
333  gpu_result = cpu_result;
334  cpu_result *= 2; //reset
335  cpu_result = viennacl::linalg::min(vcl_v1 + vcl_v2);
336 
337  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
338  return EXIT_FAILURE;
339 
340  // --------------------------------------------------------------------------
341  std::cout << "Testing sum..." << std::endl;
342  cpu_result = 0;
343  for (std::size_t i=0; i<std_v1.size(); ++i)
344  cpu_result += std_v1[i];
345  cpu_result2 = viennacl::linalg::sum(vcl_v1);
346  gpu_result = viennacl::linalg::sum(vcl_v1);
347 
348  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
349  return EXIT_FAILURE;
350  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
351  return EXIT_FAILURE;
352 
353  cpu_result = 0;
354  for (std::size_t i=0; i<std_v1.size(); ++i)
355  cpu_result += std_v1[i] + std_v2[i];
356  cpu_result3 = viennacl::linalg::sum(vcl_v1 + vcl_v2);
357  gpu_result = viennacl::linalg::sum(vcl_v1 + vcl_v2);
358 
359  if (check(cpu_result, cpu_result3) != EXIT_SUCCESS)
360  return EXIT_FAILURE;
361  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
362  return EXIT_FAILURE;
363 
364 
365  // --------------------------------------------------------------------------
366 
367  std::cout << "Testing assignments..." << std::endl;
368  NumericT val = static_cast<NumericT>(1);
369  for (size_t i=0; i < std_v1.size(); ++i)
370  std_v1[i] = val;
371 
372  for (size_t i=0; i < vcl_v1.size(); ++i)
373  vcl_v1(i) = val;
374 
375  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
376  return EXIT_FAILURE;
377 
378 
379  //
380  // multiplication and division of vectors by scalars
381  //
382  std::cout << "Testing scaling with CPU scalar..." << std::endl;
383  NumericT alpha = static_cast<NumericT>(3);
384  viennacl::scalar<NumericT> gpu_alpha = alpha;
385 
386  for (size_t i=0; i<std_v1.size(); ++i)
387  std_v1[i] *= alpha;
388  vcl_v1 *= alpha;
389 
390  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
391  return EXIT_FAILURE;
392 
393  std::cout << "Testing scaling with GPU scalar..." << std::endl;
394  for (size_t i=0; i<std_v1.size(); ++i)
395  std_v1[i] *= alpha;
396  vcl_v1 *= gpu_alpha;
397 
398  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
399  return EXIT_FAILURE;
400 
401  NumericT beta = static_cast<NumericT>(2);
402  viennacl::scalar<NumericT> gpu_beta = beta;
403 
404  std::cout << "Testing shrinking with CPU scalar..." << std::endl;
405  for (size_t i=0; i<std_v1.size(); ++i)
406  std_v1[i] /= beta;
407  vcl_v1 /= beta;
408 
409  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
410  return EXIT_FAILURE;
411 
412  std::cout << "Testing shrinking with GPU scalar..." << std::endl;
413  for (size_t i=0; i<std_v1.size(); ++i)
414  std_v1[i] /= beta;
415  vcl_v1 /= gpu_beta;
416 
417  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
418  return EXIT_FAILURE;
419 
420 
421  //
422  // add and inplace_add of vectors
423  //
424  for (size_t i=0; i<std_v1.size(); ++i)
425  std_v1[i] = NumericT(i);
426  for (size_t i=0; i<std_v1.size(); ++i)
427  std_v2[i] = 3 * std_v1[i];
428  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin()); //resync
429  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
430 
431  std::cout << "Testing add on vector..." << std::endl;
432 
433  std::cout << "Checking for successful copy..." << std::endl;
434  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
435  return EXIT_FAILURE;
436  if (check(std_v2, vcl_v2) != EXIT_SUCCESS)
437  return EXIT_FAILURE;
438 
439  for (size_t i=0; i<std_v1.size(); ++i)
440  std_v1[i] = std_v1[i] + std_v2[i];
441  vcl_v1 = vcl_v1 + vcl_v2;
442 
443  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
444  return EXIT_FAILURE;
445 
446  std::cout << "Testing inplace-add on vector..." << std::endl;
447  for (size_t i=0; i<std_v1.size(); ++i)
448  std_v1[i] += std_v2[i];
449  vcl_v1 += vcl_v2;
450 
451  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
452  return EXIT_FAILURE;
453 
454 
455  //
456  // multiply-add
457  //
458  std::cout << "Testing multiply-add on vector with CPU scalar (right)..." << std::endl;
459  for (size_t i=0; i < std_v1.size(); ++i)
460  std_v1[i] = NumericT(i);
461  for (std::size_t i=0; i<std_v1.size(); ++i)
462  std_v2[i] = 3 * std_v1[i];
463  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
464  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
465 
466  for (std::size_t i=0; i<std_v1.size(); ++i)
467  std_v1[i] = std_v1[i] + alpha * std_v2[i];
468  vcl_v1 = vcl_v1 + alpha * vcl_v2;
469 
470  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
471  return EXIT_FAILURE;
472 
473  std::cout << "Testing multiply-add on vector with CPU scalar (left)..." << std::endl;
474  for (std::size_t i=0; i<std_v1.size(); ++i)
475  std_v2[i] = 3 * std_v1[i];
476  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
477  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
478 
479  for (std::size_t i=0; i<std_v1.size(); ++i)
480  std_v1[i] = alpha * std_v1[i] + std_v2[i];
481  vcl_v1 = alpha * vcl_v1 + vcl_v2;
482 
483  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
484  return EXIT_FAILURE;
485 
486  std::cout << "Testing multiply-add on vector with CPU scalar (both)..." << std::endl;
487  for (std::size_t i=0; i<std_v1.size(); ++i)
488  std_v2[i] = 3 * std_v1[i];
489  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
490  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
491 
492  for (std::size_t i=0; i<std_v1.size(); ++i)
493  std_v1[i] = alpha * std_v1[i] + beta * std_v2[i];
494  vcl_v1 = alpha * vcl_v1 + beta * vcl_v2;
495 
496  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
497  return EXIT_FAILURE;
498 
499 
500  std::cout << "Testing inplace multiply-add on vector with CPU scalar..." << std::endl;
501  for (std::size_t i=0; i<std_v1.size(); ++i)
502  std_v2[i] = 3 * std_v1[i];
503  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
504  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
505 
506  for (std::size_t i=0; i<std_v1.size(); ++i)
507  std_v1[i] += alpha * std_v2[i];
508  vcl_v1 += alpha * vcl_v2;
509 
510  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
511  return EXIT_FAILURE;
512 
513 
514  std::cout << "Testing multiply-add on vector with GPU scalar (right)..." << std::endl;
515  for (std::size_t i=0; i<std_v1.size(); ++i)
516  std_v2[i] = 3 * std_v1[i];
517  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
518  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
519 
520  for (std::size_t i=0; i<std_v1.size(); ++i)
521  std_v1[i] = std_v1[i] + alpha * std_v2[i];
522  vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
523 
524  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
525  return EXIT_FAILURE;
526 
527  std::cout << "Testing multiply-add on vector with GPU scalar (left)..." << std::endl;
528  for (std::size_t i=0; i<std_v1.size(); ++i)
529  std_v2[i] = 3 * std_v1[i];
530  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
531  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
532 
533  for (std::size_t i=0; i<std_v1.size(); ++i)
534  std_v1[i] = std_v1[i] + alpha * std_v2[i];
535  vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
536 
537  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
538  return EXIT_FAILURE;
539 
540  std::cout << "Testing multiply-add on vector with GPU scalar (both)..." << std::endl;
541  for (std::size_t i=0; i<std_v1.size(); ++i)
542  std_v2[i] = 3 * std_v1[i];
543  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
544  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
545 
546  for (std::size_t i=0; i<std_v1.size(); ++i)
547  std_v1[i] = alpha * std_v1[i] + beta * std_v2[i];
548  vcl_v1 = gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
549 
550  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
551  return EXIT_FAILURE;
552 
553 
554  std::cout << "Testing inplace multiply-add on vector with GPU scalar (both, adding)..." << std::endl;
555  for (std::size_t i=0; i<std_v1.size(); ++i)
556  std_v2[i] = 3 * std_v1[i];
557  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
558  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
559 
560  for (std::size_t i=0; i<std_v1.size(); ++i)
561  std_v1[i] += alpha * std_v1[i] + beta * std_v2[i];
562  vcl_v1 += gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
563 
564  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
565  return EXIT_FAILURE;
566 
567 
568  std::cout << "Testing inplace multiply-add on vector with GPU scalar..." << std::endl;
569  for (std::size_t i=0; i<std_v1.size(); ++i)
570  std_v2[i] = 3 * std_v1[i];
571  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
572  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
573 
574  for (std::size_t i=0; i<std_v1.size(); ++i)
575  std_v1[i] += alpha * std_v2[i];
576  vcl_v1 += gpu_alpha * vcl_v2;
577 
578  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
579  return EXIT_FAILURE;
580 
581 
582  //
583  // division-add
584  //
585  std::cout << "Testing division-add on vector with CPU scalar (right)..." << std::endl;
586  for (size_t i=0; i < std_v1.size(); ++i)
587  std_v1[i] = NumericT(i);
588  for (std::size_t i=0; i<std_v1.size(); ++i)
589  std_v2[i] = 3 * std_v1[i];
590  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
591  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
592 
593  for (std::size_t i=0; i<std_v1.size(); ++i)
594  std_v1[i] = std_v1[i] + std_v2[i] / alpha;
595  vcl_v1 = vcl_v1 + vcl_v2 / alpha;
596 
597  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
598  return EXIT_FAILURE;
599 
600 
601  std::cout << "Testing division-add on vector with CPU scalar (left)..." << std::endl;
602  for (std::size_t i=0; i<std_v1.size(); ++i)
603  std_v2[i] = 3 * std_v1[i];
604  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
605  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
606 
607  for (std::size_t i=0; i<std_v1.size(); ++i)
608  std_v1[i] = std_v1[i] / alpha + std_v2[i];
609  vcl_v1 = vcl_v1 / alpha + vcl_v2;
610 
611  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
612  return EXIT_FAILURE;
613 
614  std::cout << "Testing division-add on vector with CPU scalar (both)..." << std::endl;
615  for (std::size_t i=0; i<std_v1.size(); ++i)
616  std_v2[i] = 3 * std_v1[i];
617  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
618  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
619 
620  for (std::size_t i=0; i<std_v1.size(); ++i)
621  std_v1[i] = std_v1[i] / alpha + std_v2[i] / beta;
622  vcl_v1 = vcl_v1 / alpha + vcl_v2 / beta;
623 
624  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
625  return EXIT_FAILURE;
626 
627  std::cout << "Testing division-multiply-add on vector with CPU scalar..." << std::endl;
628  for (std::size_t i=0; i<std_v1.size(); ++i)
629  std_v2[i] = 3 * std_v1[i];
630  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
631  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
632 
633  for (std::size_t i=0; i<std_v1.size(); ++i)
634  std_v1[i] = std_v1[i] / alpha + std_v2[i] * beta;
635  vcl_v1 = vcl_v1 / alpha + vcl_v2 * beta;
636 
637  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
638  return EXIT_FAILURE;
639 
640 
641  std::cout << "Testing multiply-division-add on vector with CPU scalar..." << std::endl;
642  for (std::size_t i=0; i<std_v1.size(); ++i)
643  std_v2[i] = 3 * std_v1[i];
644  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
645  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
646 
647  for (std::size_t i=0; i<std_v1.size(); ++i)
648  std_v1[i] = std_v1[i] * alpha + std_v2[i] / beta;
649  vcl_v1 = vcl_v1 * alpha + vcl_v2 / beta;
650 
651  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
652  return EXIT_FAILURE;
653 
654 
655 
656  std::cout << "Testing inplace division-add on vector with CPU scalar..." << std::endl;
657  for (std::size_t i=0; i<std_v1.size(); ++i)
658  std_v2[i] = 3 * std_v1[i];
659  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
660  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
661 
662  for (std::size_t i=0; i<std_v1.size(); ++i)
663  std_v1[i] += std_v2[i] / alpha;
664  vcl_v1 += vcl_v2 / alpha;
665 
666  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
667  return EXIT_FAILURE;
668 
669 
670  std::cout << "Testing division-add on vector with GPU scalar (right)..." << std::endl;
671  for (std::size_t i=0; i<std_v1.size(); ++i)
672  std_v2[i] = 3 * std_v1[i];
673  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
674  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
675 
676  for (std::size_t i=0; i<std_v1.size(); ++i)
677  std_v1[i] = std_v1[i] + std_v2[i] / alpha;
678  vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
679 
680  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
681  return EXIT_FAILURE;
682 
683  std::cout << "Testing division-add on vector with GPU scalar (left)..." << std::endl;
684  for (std::size_t i=0; i<std_v1.size(); ++i)
685  std_v2[i] = 3 * std_v1[i];
686  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
687  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
688 
689  for (std::size_t i=0; i<std_v1.size(); ++i)
690  std_v1[i] = std_v1[i] + std_v2[i] / alpha;
691  vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
692 
693  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
694  return EXIT_FAILURE;
695 
696  std::cout << "Testing division-add on vector with GPU scalar (both)..." << std::endl;
697  for (std::size_t i=0; i<std_v1.size(); ++i)
698  std_v2[i] = 3 * std_v1[i];
699  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
700  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
701 
702  for (std::size_t i=0; i<std_v1.size(); ++i)
703  std_v1[i] = std_v1[i] / alpha + std_v2[i] / beta;
704  vcl_v1 = vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
705 
706  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
707  return EXIT_FAILURE;
708 
709 
710  std::cout << "Testing inplace division-add on vector with GPU scalar (both, adding)..." << std::endl;
711  for (std::size_t i=0; i<std_v1.size(); ++i)
712  std_v2[i] = 3 * std_v1[i];
713  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
714  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
715 
716  for (std::size_t i=0; i<std_v1.size(); ++i)
717  std_v1[i] += std_v1[i] / alpha + std_v2[i] / beta;
718  vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
719 
720  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
721  return EXIT_FAILURE;
722 
723  std::cout << "Testing inplace division-multiply-add on vector with GPU scalar (adding)..." << std::endl;
724  for (std::size_t i=0; i<std_v1.size(); ++i)
725  std_v2[i] = 3 * std_v1[i];
726  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
727  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
728 
729  for (std::size_t i=0; i<std_v1.size(); ++i)
730  std_v1[i] += std_v1[i] / alpha + std_v2[i] * beta;
731  vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 * gpu_beta;
732 
733  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
734  return EXIT_FAILURE;
735 
736 
737  std::cout << "Testing inplace division-add on vector with GPU scalar..." << std::endl;
738  for (std::size_t i=0; i<std_v1.size(); ++i)
739  std_v2[i] = 3 * std_v1[i];
740  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
741  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
742 
743  for (std::size_t i=0; i<std_v1.size(); ++i)
744  std_v1[i] += std_v2[i] * alpha;
745  vcl_v1 += vcl_v2 * gpu_alpha;
746 
747  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
748  return EXIT_FAILURE;
749 
750  //
751  // More complicated expressions (for ensuring the operator overloads work correctly)
752  //
753  for (size_t i=0; i < std_v1.size(); ++i)
754  std_v1[i] = NumericT(i);
755  for (std::size_t i=0; i<std_v1.size(); ++i)
756  std_v2[i] = 3 * std_v1[i];
757  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
758  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
759 
760  std::cout << "Testing three vector additions..." << std::endl;
761  for (std::size_t i=0; i<std_v1.size(); ++i)
762  std_v1[i] = std_v2[i] + std_v1[i] + std_v2[i];
763  vcl_v1 = vcl_v2 + vcl_v1 + vcl_v2;
764 
765  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
766  return EXIT_FAILURE;
767 
768  // --------------------------------------------------------------------------
769  for (std::size_t i=0; i<std_v1.size(); ++i)
770  std_v2[i] = 3 * std_v1[i];
771  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
772  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
773 
774  std::cout << "Testing swap..." << std::endl;
775  swap(std_v1, std_v2);
776  swap(vcl_v1, vcl_v2);
777 
778  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
779  return EXIT_FAILURE;
780 
781  std::cout << "Testing elementwise multiplication..." << std::endl;
782  std::cout << " v1 = element_prod(v1, v2);" << std::endl;
783  for (std::size_t i=0; i<std_v1.size(); ++i)
784  std_v1[i] = std_v1[i] * std_v2[i];
785  vcl_v1 = viennacl::linalg::element_prod(vcl_v1, vcl_v2);
786 
787  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
788  return EXIT_FAILURE;
789 
790  std::cout << " v1 += element_prod(v1, v2);" << std::endl;
791  for (std::size_t i=0; i<std_v1.size(); ++i)
792  std_v1[i] += std_v1[i] * std_v2[i];
793  vcl_v1 += viennacl::linalg::element_prod(vcl_v1, vcl_v2);
794 
795  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
796  return EXIT_FAILURE;
797 
799  std::cout << " v1 = element_prod(v1 + v2, v2);" << std::endl;
800  for (std::size_t i=0; i<std_v1.size(); ++i)
801  std_v1[i] = (std_v1[i] + std_v2[i]) * std_v2[i];
802  vcl_v1 = viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2);
803 
804  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
805  return EXIT_FAILURE;
806 
807  std::cout << " v1 += element_prod(v1 + v2, v2);" << std::endl;
808  for (std::size_t i=0; i<std_v1.size(); ++i)
809  std_v1[i] += (std_v1[i] + std_v2[i]) * std_v2[i];
810  vcl_v1 += viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2);
811 
812  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
813  return EXIT_FAILURE;
814 
816  std::cout << " v1 = element_prod(v1, v2 + v1);" << std::endl;
817  for (std::size_t i=0; i<std_v1.size(); ++i)
818  std_v1[i] = std_v1[i] * (std_v2[i] + std_v1[i]);
819  vcl_v1 = viennacl::linalg::element_prod(vcl_v1, vcl_v2 + vcl_v1);
820 
821  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
822  return EXIT_FAILURE;
823 
824  std::cout << " v1 += element_prod(v1, v2 + v1);" << std::endl;
825  for (std::size_t i=0; i<std_v1.size(); ++i)
826  std_v1[i] += std_v1[i] * (std_v2[i] + std_v1[i]);
827  vcl_v1 += viennacl::linalg::element_prod(vcl_v1, vcl_v2 + vcl_v1);
828 
829  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
830  return EXIT_FAILURE;
831 
833  std::cout << " v1 = element_prod(v1 + v2, v2 + v1);" << std::endl;
834  for (std::size_t i=0; i<std_v1.size(); ++i)
835  std_v1[i] = (std_v1[i] + std_v2[i]) * (std_v2[i] + std_v1[i]);
836  vcl_v1 = viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
837 
838  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
839  return EXIT_FAILURE;
840 
841  std::cout << " v1 += element_prod(v1 + v2, v2 + v1);" << std::endl;
842  for (std::size_t i=0; i<std_v1.size(); ++i)
843  std_v1[i] += (std_v1[i] + std_v2[i]) * (std_v2[i] + std_v1[i]);
844  vcl_v1 += viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
845 
846  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
847  return EXIT_FAILURE;
848 
849 
850  std::cout << "Testing elementwise division..." << std::endl;
851  for (std::size_t i=0; i<std_v1.size(); ++i)
852  {
853  std_v1[i] = NumericT(1 + i);
854  std_v2[i] = NumericT(5 + i);
855  }
856 
857  viennacl::copy(std_v1.begin(), std_v1.end(), vcl_v1.begin());
858  viennacl::copy(std_v2.begin(), std_v2.end(), vcl_v2.begin());
859 
860  for (std::size_t i=0; i<std_v1.size(); ++i)
861  std_v1[i] = std_v1[i] / std_v2[i];
862  vcl_v1 = viennacl::linalg::element_div(vcl_v1, vcl_v2);
863 
864  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
865  return EXIT_FAILURE;
866 
867  for (std::size_t i=0; i<std_v1.size(); ++i)
868  std_v1[i] += std_v1[i] / std_v2[i];
869  vcl_v1 += viennacl::linalg::element_div(vcl_v1, vcl_v2);
870 
871  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
872  return EXIT_FAILURE;
873 
875  for (std::size_t i=0; i<std_v1.size(); ++i)
876  std_v1[i] = (std_v1[i] + std_v2[i]) / std_v2[i];
877  vcl_v1 = viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2);
878 
879  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
880  return EXIT_FAILURE;
881 
882  for (std::size_t i=0; i<std_v1.size(); ++i)
883  std_v1[i] += (std_v1[i] + std_v2[i]) / std_v2[i];
884  vcl_v1 += viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2);
885 
886  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
887  return EXIT_FAILURE;
888 
890  for (std::size_t i=0; i<std_v1.size(); ++i)
891  std_v1[i] = std_v1[i] / (std_v2[i] + std_v1[i]);
892  vcl_v1 = viennacl::linalg::element_div(vcl_v1, vcl_v2 + vcl_v1);
893 
894  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
895  return EXIT_FAILURE;
896 
897  for (std::size_t i=0; i<std_v1.size(); ++i)
898  std_v1[i] += std_v1[i] / (std_v2[i] + std_v1[i]);
899  vcl_v1 += viennacl::linalg::element_div(vcl_v1, vcl_v2 + vcl_v1);
900 
901  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
902  return EXIT_FAILURE;
903 
905  for (std::size_t i=0; i<std_v1.size(); ++i)
906  std_v1[i] = (std_v1[i] + std_v2[i]) / (std_v2[i] + std_v1[i]);
907  vcl_v1 = viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
908 
909  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
910  return EXIT_FAILURE;
911 
912  for (std::size_t i=0; i<std_v1.size(); ++i)
913  std_v1[i] += (std_v1[i] + std_v2[i]) / (std_v2[i] + std_v1[i]);
914  vcl_v1 += viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
915 
916  if (check(std_v1, vcl_v1) != EXIT_SUCCESS)
917  return EXIT_FAILURE;
918 
919  // --------------------------------------------------------------------------
920  return retval;
921 }
922 
923 
924 template< typename NumericT >
925 int test()
926 {
927  int retval = EXIT_SUCCESS;
928  std::size_t size = 12345;
929 
930  std::cout << "Running tests for vector of size " << size << std::endl;
931 
932  //
933  // Set up STL objects
934  //
935  std::vector<NumericT> std_full_vec(size);
936  std::vector<NumericT> std_full_vec2(std_full_vec.size());
937 
938  for (std::size_t i=0; i<std_full_vec.size(); ++i)
939  {
940  std_full_vec[i] = NumericT(1.0) + NumericT(i);
941  std_full_vec2[i] = NumericT(2.0) + NumericT(i) / NumericT(2);
942  }
943 
944  std::vector<NumericT> std_range_vec (2 * std_full_vec.size() / 4 - std_full_vec.size() / 4);
945  std::vector<NumericT> std_range_vec2(2 * std_full_vec.size() / 4 - std_full_vec.size() / 4);
946 
947  for (std::size_t i=0; i<std_range_vec.size(); ++i)
948  std_range_vec[i] = std_full_vec[i + std_full_vec.size() / 4];
949  for (std::size_t i=0; i<std_range_vec2.size(); ++i)
950  std_range_vec2[i] = std_full_vec2[i + 2 * std_full_vec2.size() / 4];
951 
952  std::vector<NumericT> std_slice_vec (std_full_vec.size() / 4);
953  std::vector<NumericT> std_slice_vec2(std_full_vec.size() / 4);
954 
955  for (std::size_t i=0; i<std_slice_vec.size(); ++i)
956  std_slice_vec[i] = std_full_vec[3*i + std_full_vec.size() / 4];
957  for (std::size_t i=0; i<std_slice_vec2.size(); ++i)
958  std_slice_vec2[i] = std_full_vec2[2*i + 2 * std_full_vec2.size() / 4];
959 
960  //
961  // Set up ViennaCL objects
962  //
963  viennacl::vector<NumericT> vcl_full_vec(std_full_vec.size());
964  viennacl::vector<NumericT> vcl_full_vec2(std_full_vec2.size());
965 
966  viennacl::fast_copy(std_full_vec.begin(), std_full_vec.end(), vcl_full_vec.begin());
967  viennacl::copy(std_full_vec2.begin(), std_full_vec2.end(), vcl_full_vec2.begin());
968 
969  viennacl::range vcl_r1( vcl_full_vec.size() / 4, 2 * vcl_full_vec.size() / 4);
970  viennacl::range vcl_r2(2 * vcl_full_vec2.size() / 4, 3 * vcl_full_vec2.size() / 4);
971  viennacl::vector_range< viennacl::vector<NumericT> > vcl_range_vec(vcl_full_vec, vcl_r1);
972  viennacl::vector_range< viennacl::vector<NumericT> > vcl_range_vec2(vcl_full_vec2, vcl_r2);
973 
974  {
975  viennacl::vector<NumericT> vcl_short_vec(vcl_range_vec);
976  viennacl::vector<NumericT> vcl_short_vec2 = vcl_range_vec2;
977 
978  std::vector<NumericT> std_short_vec(std_range_vec);
979  std::vector<NumericT> std_short_vec2(std_range_vec2);
980 
981  std::cout << "Testing creation of vectors from range..." << std::endl;
982  if (check(std_short_vec, vcl_short_vec) != EXIT_SUCCESS)
983  return EXIT_FAILURE;
984  if (check(std_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
985  return EXIT_FAILURE;
986  }
987 
988  viennacl::slice vcl_s1( vcl_full_vec.size() / 4, 3, vcl_full_vec.size() / 4);
989  viennacl::slice vcl_s2(2 * vcl_full_vec2.size() / 4, 2, vcl_full_vec2.size() / 4);
990  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec(vcl_full_vec, vcl_s1);
991  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec2(vcl_full_vec2, vcl_s2);
992 
993  viennacl::vector<NumericT> vcl_short_vec(vcl_slice_vec);
994  viennacl::vector<NumericT> vcl_short_vec2 = vcl_slice_vec2;
995 
996  std::vector<NumericT> std_short_vec(std_slice_vec);
997  std::vector<NumericT> std_short_vec2(std_slice_vec2);
998 
999  std::cout << "Testing creation of vectors from slice..." << std::endl;
1000  if (check(std_short_vec, vcl_short_vec) != EXIT_SUCCESS)
1001  return EXIT_FAILURE;
1002  if (check(std_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
1003  return EXIT_FAILURE;
1004 
1005 
1006  //
1007  // Now start running tests for vectors, ranges and slices:
1008  //
1009 
1010  std::cout << " ** vcl_v1 = vector, vcl_v2 = vector **" << std::endl;
1011  retval = test<NumericT>(std_short_vec, std_short_vec2,
1012  vcl_short_vec, vcl_short_vec2);
1013  if (retval != EXIT_SUCCESS)
1014  return EXIT_FAILURE;
1015 
1016  std::cout << " ** vcl_v1 = vector, vcl_v2 = range **" << std::endl;
1017  retval = test<NumericT>(std_short_vec, std_short_vec2,
1018  vcl_short_vec, vcl_range_vec2);
1019  if (retval != EXIT_SUCCESS)
1020  return EXIT_FAILURE;
1021 
1022  std::cout << " ** vcl_v1 = vector, vcl_v2 = slice **" << std::endl;
1023  retval = test<NumericT>(std_short_vec, std_short_vec2,
1024  vcl_short_vec, vcl_slice_vec2);
1025  if (retval != EXIT_SUCCESS)
1026  return EXIT_FAILURE;
1027 
1029 
1030  std::cout << " ** vcl_v1 = range, vcl_v2 = vector **" << std::endl;
1031  retval = test<NumericT>(std_short_vec, std_short_vec2,
1032  vcl_range_vec, vcl_short_vec2);
1033  if (retval != EXIT_SUCCESS)
1034  return EXIT_FAILURE;
1035 
1036  std::cout << " ** vcl_v1 = range, vcl_v2 = range **" << std::endl;
1037  retval = test<NumericT>(std_short_vec, std_short_vec2,
1038  vcl_range_vec, vcl_range_vec2);
1039  if (retval != EXIT_SUCCESS)
1040  return EXIT_FAILURE;
1041 
1042  std::cout << " ** vcl_v1 = range, vcl_v2 = slice **" << std::endl;
1043  retval = test<NumericT>(std_short_vec, std_short_vec2,
1044  vcl_range_vec, vcl_slice_vec2);
1045  if (retval != EXIT_SUCCESS)
1046  return EXIT_FAILURE;
1047 
1049 
1050  std::cout << " ** vcl_v1 = slice, vcl_v2 = vector **" << std::endl;
1051  retval = test<NumericT>(std_short_vec, std_short_vec2,
1052  vcl_slice_vec, vcl_short_vec2);
1053  if (retval != EXIT_SUCCESS)
1054  return EXIT_FAILURE;
1055 
1056  std::cout << " ** vcl_v1 = slice, vcl_v2 = range **" << std::endl;
1057  retval = test<NumericT>(std_short_vec, std_short_vec2,
1058  vcl_slice_vec, vcl_range_vec2);
1059  if (retval != EXIT_SUCCESS)
1060  return EXIT_FAILURE;
1061 
1062  std::cout << " ** vcl_v1 = slice, vcl_v2 = slice **" << std::endl;
1063  retval = test<NumericT>(std_short_vec, std_short_vec2,
1064  vcl_slice_vec, vcl_slice_vec2);
1065  if (retval != EXIT_SUCCESS)
1066  return EXIT_FAILURE;
1067 
1068  return EXIT_SUCCESS;
1069 }
1070 
1071 
1072 
1073 //
1074 // -------------------------------------------------------------
1075 //
1076 int main()
1077 {
1078  std::cout << std::endl;
1079  std::cout << "----------------------------------------------" << std::endl;
1080  std::cout << "----------------------------------------------" << std::endl;
1081  std::cout << "## Test :: Vector with Integer types" << std::endl;
1082  std::cout << "----------------------------------------------" << std::endl;
1083  std::cout << "----------------------------------------------" << std::endl;
1084  std::cout << std::endl;
1085 
1086  int retval = EXIT_SUCCESS;
1087 
1088  std::cout << std::endl;
1089  std::cout << "----------------------------------------------" << std::endl;
1090  std::cout << std::endl;
1091  {
1092  std::cout << "# Testing setup:" << std::endl;
1093  std::cout << " numeric: unsigned int" << std::endl;
1094  retval = test<unsigned int>();
1095  if ( retval == EXIT_SUCCESS )
1096  std::cout << "# Test passed" << std::endl;
1097  else
1098  return retval;
1099  }
1100  std::cout << std::endl;
1101  std::cout << "----------------------------------------------" << std::endl;
1102  std::cout << std::endl;
1103  {
1104  std::cout << "# Testing setup:" << std::endl;
1105  std::cout << " numeric: long" << std::endl;
1106  retval = test<unsigned long>();
1107  if ( retval == EXIT_SUCCESS )
1108  std::cout << "# Test passed" << std::endl;
1109  else
1110  return retval;
1111  }
1112  std::cout << std::endl;
1113  std::cout << "----------------------------------------------" << std::endl;
1114  std::cout << std::endl;
1115 
1116  std::cout << std::endl;
1117  std::cout << "------- Test completed --------" << std::endl;
1118  std::cout << std::endl;
1119 
1120  return retval;
1121 }
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:227
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
viennacl::scalar_expression< const viennacl::vector_base< NumericT >, const viennacl::vector_base< NumericT >, viennacl::op_sum > sum(viennacl::vector_base< NumericT > const &x)
User interface function for computing the sum of all elements of a vector.
Definition: sum.hpp:45
int check(T1 const &t1, T2 const &t2)
Definition: vector_uint.cpp:92
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:100
viennacl::scalar< int > s2
viennacl::scalar< float > s1
Generic interface for the computation of inner products. See viennacl/linalg/vector_operations.hpp for implementations.
int test(STLVectorType &std_v1, STLVectorType &std_v2, ViennaCLVectorType1 &vcl_v1, ViennaCLVectorType2 &vcl_v2)
Generic interface for the l^1-norm. See viennacl/linalg/vector_operations.hpp for implementations...
float NumericT
Definition: bisect.cpp:40
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:239
Class for representing non-strided subvectors of a bigger vector x.
Definition: forwards.h:434
Class for representing strided subvectors of a bigger vector x.
Definition: forwards.h:437
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:48
Represents a vector consisting of 1 at a given index and zeros otherwise.
Definition: vector_def.hpp:76
Stub routines for the summation of elements in a vector, or all elements in either a row or column of...
viennacl::vector< int > v2
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:424
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:429
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
Definition: forwards.h:233
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)