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