ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
vector_int.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 
23 //
24 // *** System
25 //
26 #include <iostream>
27 #include <iomanip>
28 
29 //
30 // *** Boost
31 //
32 #include <boost/numeric/ublas/io.hpp>
33 #include <boost/numeric/ublas/vector.hpp>
34 #include <boost/numeric/ublas/vector_proxy.hpp>
35 
36 //
37 // *** ViennaCL
38 //
39 //#define VIENNACL_DEBUG_ALL
40 #define VIENNACL_WITH_UBLAS 1
41 #include "viennacl/vector.hpp"
48 #include "viennacl/linalg/sum.hpp"
49 
50 using namespace boost::numeric;
51 
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>
76 {
78  return s1 - s2;
79 }
80 //
81 // -------------------------------------------------------------
82 //
83 template<typename ScalarType, typename VCLVectorType>
84 ScalarType diff(ublas::vector<ScalarType> const & v1, VCLVectorType const & v2)
85 {
86  ublas::vector<ScalarType> v2_cpu(v2.size());
87  viennacl::backend::finish(); //workaround for a bug in APP SDK 2.7 on Trinity APUs (with Catalyst 12.8)
88  viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin());
89 
90  for (unsigned int i=0;i<v1.size(); ++i)
91  {
92  if (v2_cpu[i] != v1[i])
93  return 1;
94  }
95 
96  return 0;
97 }
98 
99 template<typename T1, typename T2>
100 int check(T1 const & t1, T2 const & t2)
101 {
102  int retval = EXIT_SUCCESS;
103 
104  if (diff(t1, t2) != 0)
105  {
106  std::cout << "# Error! Difference: " << std::abs(diff(t1, t2)) << std::endl;
107  retval = EXIT_FAILURE;
108  }
109  return retval;
110 }
111 
112 
113 //
114 // -------------------------------------------------------------
115 //
116 template< typename NumericT, typename UblasVectorType, typename ViennaCLVectorType1, typename ViennaCLVectorType2 >
117 int test(UblasVectorType & ublas_v1, UblasVectorType & ublas_v2,
118  ViennaCLVectorType1 & vcl_v1, ViennaCLVectorType2 & vcl_v2)
119 {
120  int retval = EXIT_SUCCESS;
121 
122  NumericT cpu_result = 42;
123  viennacl::scalar<NumericT> gpu_result = 43;
124 
125  //
126  // Initializer:
127  //
128  std::cout << "Checking for zero_vector initializer..." << std::endl;
129  //ublas_v1 = ublas::zero_vector<NumericT>(ublas_v1.size());
130  for (std::size_t i=0; i<ublas_v1.size(); ++i)
131  ublas_v1[i] = 0;
132  vcl_v1 = viennacl::zero_vector<NumericT>(vcl_v1.size());
133  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
134  return EXIT_FAILURE;
135 
136  std::cout << "Checking for scalar_vector initializer..." << std::endl;
137  //ublas_v1 = ublas::scalar_vector<NumericT>(ublas_v1.size(), cpu_result);
138  for (std::size_t i=0; i<ublas_v1.size(); ++i)
139  ublas_v1[i] = cpu_result;
140  vcl_v1 = viennacl::scalar_vector<NumericT>(vcl_v1.size(), cpu_result);
141  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
142  return EXIT_FAILURE;
143 
144  //ublas_v1 = ublas::scalar_vector<NumericT>(ublas_v1.size(), gpu_result);
145  for (std::size_t i=0; i<ublas_v1.size(); ++i)
146  ublas_v1[i] = cpu_result + 1;
147  vcl_v1 = viennacl::scalar_vector<NumericT>(vcl_v1.size(), gpu_result);
148  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
149  return EXIT_FAILURE;
150 
151  std::cout << "Checking for unit_vector initializer..." << std::endl;
152  //ublas_v1 = ublas::unit_vector<NumericT>(ublas_v1.size(), 5);
153  for (std::size_t i=0; i<ublas_v1.size(); ++i)
154  ublas_v1[i] = (i == 5) ? 1 : 0;
155  vcl_v1 = viennacl::unit_vector<NumericT>(vcl_v1.size(), 5);
156  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
157  return EXIT_FAILURE;
158 
159  for (std::size_t i=0; i<ublas_v1.size(); ++i)
160  {
161  ublas_v1[i] = NumericT(i);
162  ublas_v2[i] = NumericT(i+42);
163  }
164 
165  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin()); //resync
166  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
167 
168  std::cout << "Checking for successful copy..." << std::endl;
169  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
170  return EXIT_FAILURE;
171  if (check(ublas_v2, vcl_v2) != EXIT_SUCCESS)
172  return EXIT_FAILURE;
173 
174  //
175  // Part 1: Norms and inner product
176  //
177 
178  // --------------------------------------------------------------------------
179  std::cout << "Testing inner_prod..." << std::endl;
180  cpu_result = viennacl::linalg::inner_prod(ublas_v1, ublas_v2);
181  NumericT cpu_result2 = viennacl::linalg::inner_prod(vcl_v1, vcl_v2);
182  gpu_result = viennacl::linalg::inner_prod(vcl_v1, vcl_v2);
183 
184  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
185  return EXIT_FAILURE;
186  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
187  return EXIT_FAILURE;
188 
189  cpu_result = inner_prod(ublas_v1 + ublas_v2, ublas_v2 - ublas_v1);
190  NumericT cpu_result3 = viennacl::linalg::inner_prod(vcl_v1 + vcl_v2, vcl_v2 - vcl_v1);
191  gpu_result = viennacl::linalg::inner_prod(vcl_v1 + vcl_v2, vcl_v2 - vcl_v1);
192 
193  if (check(cpu_result, cpu_result3) != EXIT_SUCCESS)
194  return EXIT_FAILURE;
195  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
196  return EXIT_FAILURE;
197 
198  // --------------------------------------------------------------------------
199  std::cout << "Testing norm_1..." << std::endl;
200  cpu_result = ublas::norm_1(ublas_v1);
201  gpu_result = viennacl::linalg::norm_1(vcl_v1);
202 
203  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
204  return EXIT_FAILURE;
205 
206  gpu_result = 2 * cpu_result; //reset
207  gpu_result = ublas::norm_1(ublas_v1);
208  cpu_result = viennacl::linalg::norm_1(vcl_v1);
209 
210  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
211  return EXIT_FAILURE;
212 
213  gpu_result = ublas::norm_1(ublas_v1 + ublas_v2);
214  cpu_result = viennacl::linalg::norm_1(vcl_v1 + vcl_v2);
215 
216  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
217  return EXIT_FAILURE;
218 
219  // --------------------------------------------------------------------------
220  std::cout << "Testing norm_inf..." << std::endl;
221  cpu_result = ublas::norm_inf(ublas_v1);
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  gpu_result = 2 * cpu_result; //reset
228  gpu_result = ublas::norm_inf(ublas_v1);
229  cpu_result = viennacl::linalg::norm_inf(vcl_v1);
230 
231  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
232  return EXIT_FAILURE;
233 
234  gpu_result = ublas::norm_inf(ublas_v1 + ublas_v2);
235  cpu_result = viennacl::linalg::norm_inf(vcl_v1 + vcl_v2);
236 
237  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
238  return EXIT_FAILURE;
239 
240  // --------------------------------------------------------------------------
241  std::cout << "Testing index_norm_inf..." << std::endl;
242  std::size_t cpu_index = ublas::index_norm_inf(ublas_v1);
243  std::size_t gpu_index = viennacl::linalg::index_norm_inf(vcl_v1);
244 
245  if (check(static_cast<NumericT>(cpu_index), static_cast<NumericT>(gpu_index)) != EXIT_SUCCESS)
246  return EXIT_FAILURE;
247  // --------------------------------------------------------------------------
248  cpu_result = ublas_v1[index_norm_inf(ublas_v1)];
249  gpu_result = vcl_v1[viennacl::linalg::index_norm_inf(vcl_v1)];
250 
251  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
252  return EXIT_FAILURE;
253 
254  cpu_result = ublas_v1[index_norm_inf(ublas_v1 + ublas_v2)];
255  gpu_result = vcl_v1[viennacl::linalg::index_norm_inf(vcl_v1 + vcl_v2)];
256 
257  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
258  return EXIT_FAILURE;
259 
260  // --------------------------------------------------------------------------
261  std::cout << "Testing max..." << std::endl;
262  cpu_result = ublas_v1[0];
263  for (std::size_t i=0; i<ublas_v1.size(); ++i)
264  cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i]);
265  gpu_result = viennacl::linalg::max(vcl_v1);
266 
267  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
268  return EXIT_FAILURE;
269 
270  cpu_result = ublas_v1[0];
271  for (std::size_t i=0; i<ublas_v1.size(); ++i)
272  cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i]);
273  gpu_result = cpu_result;
274  cpu_result *= 2; //reset
275  cpu_result = viennacl::linalg::max(vcl_v1);
276 
277  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
278  return EXIT_FAILURE;
279 
280  cpu_result = ublas_v1[0] + ublas_v2[0];
281  for (std::size_t i=0; i<ublas_v1.size(); ++i)
282  cpu_result = std::max<NumericT>(cpu_result, ublas_v1[i] + ublas_v2[i]);
283  gpu_result = cpu_result;
284  cpu_result *= 2; //reset
285  cpu_result = viennacl::linalg::max(vcl_v1 + vcl_v2);
286 
287  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
288  return EXIT_FAILURE;
289 
290 
291  // --------------------------------------------------------------------------
292  std::cout << "Testing min..." << std::endl;
293  cpu_result = ublas_v1[0];
294  for (std::size_t i=0; i<ublas_v1.size(); ++i)
295  cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i]);
296  gpu_result = viennacl::linalg::min(vcl_v1);
297 
298  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
299  return EXIT_FAILURE;
300 
301  cpu_result = ublas_v1[0];
302  for (std::size_t i=0; i<ublas_v1.size(); ++i)
303  cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i]);
304  gpu_result = cpu_result;
305  cpu_result *= 2; //reset
306  cpu_result = viennacl::linalg::min(vcl_v1);
307 
308  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
309  return EXIT_FAILURE;
310 
311  cpu_result = ublas_v1[0] + ublas_v2[0];
312  for (std::size_t i=0; i<ublas_v1.size(); ++i)
313  cpu_result = std::min<NumericT>(cpu_result, ublas_v1[i] + ublas_v2[i]);
314  gpu_result = cpu_result;
315  cpu_result *= 2; //reset
316  cpu_result = viennacl::linalg::min(vcl_v1 + vcl_v2);
317 
318  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
319  return EXIT_FAILURE;
320 
321  // --------------------------------------------------------------------------
322  std::cout << "Testing sum..." << std::endl;
323  cpu_result = 0;
324  for (std::size_t i=0; i<ublas_v1.size(); ++i)
325  cpu_result += ublas_v1[i];
326  cpu_result2 = viennacl::linalg::sum(vcl_v1);
327  gpu_result = viennacl::linalg::sum(vcl_v1);
328 
329  if (check(cpu_result, cpu_result2) != EXIT_SUCCESS)
330  return EXIT_FAILURE;
331  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
332  return EXIT_FAILURE;
333 
334  cpu_result = 0;
335  for (std::size_t i=0; i<ublas_v1.size(); ++i)
336  cpu_result += ublas_v1[i] + ublas_v2[i];
337  cpu_result3 = viennacl::linalg::sum(vcl_v1 + vcl_v2);
338  gpu_result = viennacl::linalg::sum(vcl_v1 + vcl_v2);
339 
340  if (check(cpu_result, cpu_result3) != EXIT_SUCCESS)
341  return EXIT_FAILURE;
342  if (check(cpu_result, gpu_result) != EXIT_SUCCESS)
343  return EXIT_FAILURE;
344 
345 
346  //
347  // Plane rotation and assignments
348  //
349 
350  // --------------------------------------------------------------------------
351 
352  ublas::vector<NumericT> x = ublas_v1;
353  ublas::vector<NumericT> y = ublas_v2;
354  ublas::vector<NumericT> t = ublas_v1;
355  t.assign ( NumericT(1) * x + NumericT(2) * y),
356  y.assign (- NumericT(2) * x + NumericT(1) * y),
357  x.assign (t);
358 
359  viennacl::linalg::plane_rotation(vcl_v1, vcl_v2, NumericT(1), NumericT(2));
360 
361  if (check(x, vcl_v1) != EXIT_SUCCESS)
362  return EXIT_FAILURE;
363  if (check(y, vcl_v2) != EXIT_SUCCESS)
364  return EXIT_FAILURE;
365 
366  // --------------------------------------------------------------------------
367 
368  std::cout << "Testing assignments..." << std::endl;
369  NumericT val = static_cast<NumericT>(1);
370  for (size_t i=0; i < ublas_v1.size(); ++i)
371  ublas_v1(i) = val;
372 
373  for (size_t i=0; i < vcl_v1.size(); ++i)
374  vcl_v1(i) = val;
375 
376  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
377  return EXIT_FAILURE;
378 
379 
380  //
381  // multiplication and division of vectors by scalars
382  //
383  std::cout << "Testing scaling with CPU scalar..." << std::endl;
384  NumericT alpha = static_cast<NumericT>(3);
385  viennacl::scalar<NumericT> gpu_alpha = alpha;
386 
387  ublas_v1 *= alpha;
388  vcl_v1 *= alpha;
389 
390  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
391  return EXIT_FAILURE;
392 
393  std::cout << "Testing scaling with GPU scalar..." << std::endl;
394  ublas_v1 *= alpha;
395  vcl_v1 *= gpu_alpha;
396 
397  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
398  return EXIT_FAILURE;
399 
400  NumericT beta = static_cast<NumericT>(2);
401  viennacl::scalar<NumericT> gpu_beta = beta;
402 
403  std::cout << "Testing shrinking with CPU scalar..." << std::endl;
404  ublas_v1 /= beta;
405  vcl_v1 /= beta;
406 
407  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
408  return EXIT_FAILURE;
409 
410  std::cout << "Testing shrinking with GPU scalar..." << std::endl;
411  ublas_v1 /= beta;
412  vcl_v1 /= gpu_beta;
413 
414  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
415  return EXIT_FAILURE;
416 
417 
418  //
419  // add and inplace_add of vectors
420  //
421  for (size_t i=0; i < ublas_v1.size(); ++i)
422  ublas_v1(i) = NumericT(i);
423  ublas_v2 = 3 * ublas_v1;
424  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin()); //resync
425  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
426 
427  std::cout << "Testing add on vector..." << std::endl;
428 
429  std::cout << "Checking for successful copy..." << std::endl;
430  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
431  return EXIT_FAILURE;
432  if (check(ublas_v2, vcl_v2) != EXIT_SUCCESS)
433  return EXIT_FAILURE;
434 
435  ublas_v1 = ublas_v1 + ublas_v2;
436  vcl_v1 = vcl_v1 + vcl_v2;
437 
438  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
439  return EXIT_FAILURE;
440 
441  std::cout << "Testing add on vector with flipsign..." << std::endl;
442  ublas_v1 = - ublas_v1 + ublas_v2;
443  vcl_v1 = - vcl_v1 + vcl_v2;
444 
445  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
446  return EXIT_FAILURE;
447 
448  std::cout << "Testing inplace-add on vector..." << std::endl;
449  ublas_v1 += ublas_v2;
450  vcl_v1 += vcl_v2;
451 
452  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
453  return EXIT_FAILURE;
454 
455  //
456  // subtract and inplace_subtract of vectors
457  //
458  std::cout << "Testing sub on vector..." << std::endl;
459  ublas_v2 = 3 * ublas_v1;
460  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
461  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
462 
463  ublas_v1 = ublas_v1 - ublas_v2;
464  vcl_v1 = vcl_v1 - vcl_v2;
465 
466  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
467  return EXIT_FAILURE;
468 
469  std::cout << "Testing inplace-sub on vector..." << std::endl;
470  ublas_v1 -= ublas_v2;
471  vcl_v1 -= vcl_v2;
472 
473  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
474  return EXIT_FAILURE;
475 
476 
477 
478  //
479  // multiply-add
480  //
481  std::cout << "Testing multiply-add on vector with CPU scalar (right)..." << std::endl;
482  for (size_t i=0; i < ublas_v1.size(); ++i)
483  ublas_v1(i) = NumericT(i);
484  ublas_v2 = 3 * ublas_v1;
485  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
486  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
487 
488  ublas_v1 = ublas_v1 + alpha * ublas_v2;
489  vcl_v1 = vcl_v1 + alpha * vcl_v2;
490 
491  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
492  return EXIT_FAILURE;
493 
494  std::cout << "Testing multiply-add on vector with CPU scalar (left)..." << std::endl;
495  ublas_v2 = 3 * ublas_v1;
496  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
497  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
498 
499  ublas_v1 = alpha * ublas_v1 + ublas_v2;
500  vcl_v1 = alpha * vcl_v1 + vcl_v2;
501 
502  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
503  return EXIT_FAILURE;
504 
505  std::cout << "Testing multiply-add on vector with CPU scalar (both)..." << std::endl;
506  ublas_v2 = 3 * ublas_v1;
507  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
508  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
509 
510  ublas_v1 = alpha * ublas_v1 + beta * ublas_v2;
511  vcl_v1 = alpha * vcl_v1 + beta * vcl_v2;
512 
513  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
514  return EXIT_FAILURE;
515 
516 
517  std::cout << "Testing inplace multiply-add on vector with CPU scalar..." << std::endl;
518  ublas_v2 = 3 * ublas_v1;
519  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
520  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
521 
522  ublas_v1 += alpha * ublas_v2;
523  vcl_v1 += alpha * vcl_v2;
524 
525  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
526  return EXIT_FAILURE;
527 
528 
529  std::cout << "Testing multiply-add on vector with GPU scalar (right)..." << std::endl;
530  ublas_v2 = 3 * ublas_v1;
531  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
532  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
533 
534  ublas_v1 = ublas_v1 + alpha * ublas_v2;
535  vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
536 
537  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
538  return EXIT_FAILURE;
539 
540  std::cout << "Testing multiply-add on vector with GPU scalar (left)..." << std::endl;
541  ublas_v2 = 3 * ublas_v1;
542  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
543  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
544 
545  ublas_v1 = ublas_v1 + alpha * ublas_v2;
546  vcl_v1 = vcl_v1 + gpu_alpha * vcl_v2;
547 
548  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
549  return EXIT_FAILURE;
550 
551  std::cout << "Testing multiply-add on vector with GPU scalar (both)..." << std::endl;
552  ublas_v2 = 3 * ublas_v1;
553  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
554  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
555 
556  ublas_v1 = alpha * ublas_v1 + beta * ublas_v2;
557  vcl_v1 = gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
558 
559  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
560  return EXIT_FAILURE;
561 
562 
563  std::cout << "Testing inplace multiply-add on vector with GPU scalar (both, adding)..." << std::endl;
564  ublas_v2 = 3 * ublas_v1;
565  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
566  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
567 
568  ublas_v1 += alpha * ublas_v1 + beta * ublas_v2;
569  vcl_v1 += gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
570 
571  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
572  return EXIT_FAILURE;
573 
574  std::cout << "Testing inplace multiply-add on vector with GPU scalar (both, subtracting)..." << std::endl;
575  ublas_v2 = 3 * ublas_v1;
576  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
577  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
578 
579  ublas_v1 += alpha * ublas_v1 - beta * ublas_v2;
580  vcl_v1 += gpu_alpha * vcl_v1 - gpu_beta * vcl_v2;
581 
582  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
583  return EXIT_FAILURE;
584 
585 
586 
587  std::cout << "Testing inplace multiply-add on vector with GPU scalar..." << std::endl;
588  ublas_v2 = 3 * ublas_v1;
589  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
590  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
591 
592  ublas_v1 += alpha * ublas_v2;
593  vcl_v1 += gpu_alpha * vcl_v2;
594 
595  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
596  return EXIT_FAILURE;
597 
598 
599  //
600  // division-add
601  //
602  std::cout << "Testing division-add on vector with CPU scalar (right)..." << std::endl;
603  for (size_t i=0; i < ublas_v1.size(); ++i)
604  ublas_v1(i) = NumericT(i);
605  ublas_v2 = 3 * ublas_v1;
606  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
607  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
608 
609  ublas_v1 = ublas_v1 + ublas_v2 / alpha;
610  vcl_v1 = vcl_v1 + vcl_v2 / alpha;
611 
612  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
613  return EXIT_FAILURE;
614 
615 
616  std::cout << "Testing division-add on vector with CPU scalar (left)..." << std::endl;
617  ublas_v2 = 3 * ublas_v1;
618  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
619  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
620 
621  ublas_v1 = ublas_v1 / alpha + ublas_v2;
622  vcl_v1 = vcl_v1 / alpha + vcl_v2;
623 
624  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
625  return EXIT_FAILURE;
626 
627  std::cout << "Testing division-add on vector with CPU scalar (both)..." << std::endl;
628  ublas_v2 = 3 * ublas_v1;
629  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
630  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
631 
632  ublas_v1 = ublas_v1 / alpha + ublas_v2 / beta;
633  vcl_v1 = vcl_v1 / alpha + vcl_v2 / beta;
634 
635  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
636  return EXIT_FAILURE;
637 
638  std::cout << "Testing division-multiply-add on vector with CPU scalar..." << std::endl;
639  ublas_v2 = 3 * ublas_v1;
640  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
641  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
642 
643  ublas_v1 = ublas_v1 / alpha + ublas_v2 * beta;
644  vcl_v1 = vcl_v1 / alpha + vcl_v2 * beta;
645 
646  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
647  return EXIT_FAILURE;
648 
649 
650  std::cout << "Testing multiply-division-add on vector with CPU scalar..." << std::endl;
651  ublas_v2 = 3 * ublas_v1;
652  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
653  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
654 
655  ublas_v1 = ublas_v1 * alpha + ublas_v2 / beta;
656  vcl_v1 = vcl_v1 * alpha + vcl_v2 / beta;
657 
658  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
659  return EXIT_FAILURE;
660 
661 
662 
663  std::cout << "Testing inplace division-add on vector with CPU scalar..." << std::endl;
664  ublas_v2 = 3 * ublas_v1;
665  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
666  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
667 
668  ublas_v1 += ublas_v2 / alpha;
669  vcl_v1 += vcl_v2 / alpha;
670 
671  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
672  return EXIT_FAILURE;
673 
674 
675  std::cout << "Testing division-add on vector with GPU scalar (right)..." << std::endl;
676  ublas_v2 = 3 * ublas_v1;
677  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
678  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
679 
680  ublas_v1 = ublas_v1 + ublas_v2 / alpha;
681  vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
682 
683  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
684  return EXIT_FAILURE;
685 
686  std::cout << "Testing division-add on vector with GPU scalar (left)..." << std::endl;
687  ublas_v2 = 3 * ublas_v1;
688  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
689  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
690 
691  ublas_v1 = ublas_v1 + ublas_v2 / alpha;
692  vcl_v1 = vcl_v1 + vcl_v2 / gpu_alpha;
693 
694  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
695  return EXIT_FAILURE;
696 
697  std::cout << "Testing division-add on vector with GPU scalar (both)..." << std::endl;
698  ublas_v2 = 3 * ublas_v1;
699  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
700  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
701 
702  ublas_v1 = ublas_v1 / alpha + ublas_v2 / beta;
703  vcl_v1 = vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
704 
705  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
706  return EXIT_FAILURE;
707 
708 
709  std::cout << "Testing inplace division-add on vector with GPU scalar (both, adding)..." << std::endl;
710  ublas_v2 = 3 * ublas_v1;
711  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
712  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
713 
714  ublas_v1 += ublas_v1 / alpha + ublas_v2 / beta;
715  vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
716 
717  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
718  return EXIT_FAILURE;
719 
720  std::cout << "Testing inplace division-add on vector with GPU scalar (both, subtracting)..." << std::endl;
721  ublas_v2 = 3 * ublas_v1;
722  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
723  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
724 
725  ublas_v1 += ublas_v1 / alpha - ublas_v2 / beta;
726  vcl_v1 += vcl_v1 / gpu_alpha - vcl_v2 / gpu_beta;
727 
728  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
729  return EXIT_FAILURE;
730 
731  std::cout << "Testing inplace division-multiply-add on vector with GPU scalar (adding)..." << std::endl;
732  ublas_v2 = 3 * ublas_v1;
733  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
734  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
735 
736  ublas_v1 += ublas_v1 / alpha + ublas_v2 * beta;
737  vcl_v1 += vcl_v1 / gpu_alpha + vcl_v2 * gpu_beta;
738 
739  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
740  return EXIT_FAILURE;
741 
742  std::cout << "Testing inplace multiply-division-add on vector with GPU scalar (subtracting)..." << std::endl;
743  ublas_v2 = 3 * ublas_v1;
744  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
745  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
746 
747  ublas_v1 += ublas_v1 * alpha - ublas_v2 / beta;
748  vcl_v1 += vcl_v1 * gpu_alpha - vcl_v2 / gpu_beta;
749 
750  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
751  return EXIT_FAILURE;
752 
753 
754 
755  std::cout << "Testing inplace division-add on vector with GPU scalar..." << std::endl;
756  ublas_v2 = 3 * ublas_v1;
757  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
758  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
759 
760  ublas_v1 += ublas_v2 * alpha;
761  vcl_v1 += vcl_v2 * gpu_alpha;
762 
763  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
764  return EXIT_FAILURE;
765 
766  //
767  // multiply-subtract
768  //
769  std::cout << "Testing multiply-subtract on vector with CPU scalar (right)..." << std::endl;
770  for (size_t i=0; i < ublas_v1.size(); ++i)
771  ublas_v1(i) = NumericT(i);
772  ublas_v2 = 3 * ublas_v1;
773  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
774  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
775 
776  ublas_v1 = ublas_v1 - alpha * ublas_v2;
777  vcl_v1 = vcl_v1 - alpha * vcl_v2;
778 
779  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
780  return EXIT_FAILURE;
781 
782 
783  std::cout << "Testing multiply-subtract on vector with CPU scalar (left)..." << std::endl;
784  ublas_v2 = 3 * ublas_v1;
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 = alpha * ublas_v1 - ublas_v2;
789  vcl_v1 = alpha * vcl_v1 - vcl_v2;
790 
791  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
792  return EXIT_FAILURE;
793 
794  std::cout << "Testing multiply-subtract on vector with CPU scalar (both)..." << std::endl;
795  ublas_v2 = 3 * ublas_v1;
796  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
797  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
798 
799  ublas_v1 = alpha * ublas_v1 - beta * ublas_v2;
800  vcl_v1 = alpha * vcl_v1 - beta * vcl_v2;
801 
802  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
803  return EXIT_FAILURE;
804 
805 
806  std::cout << "Testing inplace multiply-subtract on vector with CPU scalar..." << std::endl;
807  ublas_v2 = 3 * ublas_v1;
808  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
809  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
810 
811  ublas_v1 -= alpha * ublas_v2;
812  vcl_v1 -= alpha * vcl_v2;
813 
814  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
815  return EXIT_FAILURE;
816 
817 
818  std::cout << "Testing multiply-subtract on vector with GPU scalar (right)..." << std::endl;
819  ublas_v2 = 3 * ublas_v1;
820  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
821  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
822 
823  ublas_v1 = ublas_v1 - alpha * ublas_v2;
824  vcl_v1 = vcl_v1 - gpu_alpha * vcl_v2;
825 
826  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
827  return EXIT_FAILURE;
828 
829  std::cout << "Testing multiply-subtract on vector with GPU scalar (left)..." << std::endl;
830  ublas_v2 = 3 * ublas_v1;
831  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
832  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
833 
834  ublas_v1 = ublas_v1 - alpha * ublas_v2;
835  vcl_v1 = vcl_v1 - gpu_alpha * vcl_v2;
836 
837  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
838  return EXIT_FAILURE;
839 
840  std::cout << "Testing multiply-subtract on vector with GPU scalar (both)..." << std::endl;
841  ublas_v2 = 3 * ublas_v1;
842  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
843  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
844 
845  ublas_v1 = alpha * ublas_v1 - beta * ublas_v2;
846  vcl_v1 = gpu_alpha * vcl_v1 - gpu_beta * vcl_v2;
847 
848  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
849  return EXIT_FAILURE;
850 
851  std::cout << "Testing inplace multiply-subtract on vector with GPU scalar (both, adding)..." << std::endl;
852  ublas_v2 = 3 * ublas_v1;
853  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
854  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
855 
856  ublas_v1 -= alpha * ublas_v1 + beta * ublas_v2;
857  vcl_v1 -= gpu_alpha * vcl_v1 + gpu_beta * vcl_v2;
858 
859  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
860  return EXIT_FAILURE;
861 
862  std::cout << "Testing inplace multiply-subtract on vector with GPU scalar (both, subtracting)..." << std::endl;
863  ublas_v2 = 3 * ublas_v1;
864  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
865  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
866 
867  ublas_v1 -= alpha * ublas_v1 - beta * ublas_v2;
868  vcl_v1 -= gpu_alpha * vcl_v1 - gpu_beta * vcl_v2;
869 
870  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
871  return EXIT_FAILURE;
872 
873 
874  std::cout << "Testing inplace multiply-subtract on vector with GPU scalar..." << std::endl;
875  ublas_v2 = 3 * ublas_v1;
876  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
877  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
878 
879  ublas_v1 -= alpha * ublas_v2;
880  vcl_v1 -= gpu_alpha * vcl_v2;
881 
882  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
883  return EXIT_FAILURE;
884 
885 
886 
887  //
888  // division-subtract
889  //
890  std::cout << "Testing division-subtract on vector with CPU scalar (right)..." << std::endl;
891  for (size_t i=0; i < ublas_v1.size(); ++i)
892  ublas_v1(i) = NumericT(i);
893  ublas_v2 = 3 * ublas_v1;
894  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
895  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
896 
897  ublas_v1 = ublas_v1 - ublas_v2 / alpha;
898  vcl_v1 = vcl_v1 - vcl_v2 / alpha;
899 
900  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
901  return EXIT_FAILURE;
902 
903 
904  std::cout << "Testing division-subtract on vector with CPU scalar (left)..." << std::endl;
905  ublas_v2 = 3 * ublas_v1;
906  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
907  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
908 
909  ublas_v1 = ublas_v1 / alpha - ublas_v2;
910  vcl_v1 = vcl_v1 / alpha - vcl_v2;
911 
912  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
913  return EXIT_FAILURE;
914 
915  std::cout << "Testing division-subtract on vector with CPU scalar (both)..." << std::endl;
916  ublas_v2 = 3 * ublas_v1;
917  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
918  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
919 
920  ublas_v1 = ublas_v1 / alpha - ublas_v2 / alpha;
921  vcl_v1 = vcl_v1 / alpha - vcl_v2 / alpha;
922 
923  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
924  return EXIT_FAILURE;
925 
926 
927  std::cout << "Testing inplace division-subtract on vector with CPU scalar..." << std::endl;
928  ublas_v2 = 3 * ublas_v1;
929  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
930  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
931 
932  ublas_v1 -= ublas_v2 / alpha;
933  vcl_v1 -= vcl_v2 / alpha;
934 
935  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
936  return EXIT_FAILURE;
937 
938  std::cout << "Testing inplace division-subtract on vector with GPU scalar..." << std::endl;
939  ublas_v2 = 3 * ublas_v1;
940  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
941  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
942 
943  ublas_v1 -= ublas_v2 / alpha;
944  vcl_v1 -= vcl_v2 / gpu_alpha;
945 
946  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
947  return EXIT_FAILURE;
948 
949 
950  std::cout << "Testing division-subtract on vector with GPU scalar (right)..." << std::endl;
951  ublas_v2 = 3 * ublas_v1;
952  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
953  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
954 
955  ublas_v1 = ublas_v1 - ublas_v2 / alpha;
956  vcl_v1 = vcl_v1 - vcl_v2 / gpu_alpha;
957 
958  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
959  return EXIT_FAILURE;
960 
961  std::cout << "Testing division-subtract on vector with GPU scalar (left)..." << std::endl;
962  ublas_v2 = 3 * ublas_v1;
963  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
964  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
965 
966  ublas_v1 = ublas_v1 - ublas_v2 / alpha;
967  vcl_v1 = vcl_v1 - vcl_v2 / gpu_alpha;
968 
969  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
970  return EXIT_FAILURE;
971 
972  std::cout << "Testing division-subtract on vector with GPU scalar (both)..." << std::endl;
973  ublas_v2 = 3 * ublas_v1;
974  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
975  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
976 
977  ublas_v1 = ublas_v1 / alpha - ublas_v2 / beta;
978  vcl_v1 = vcl_v1 / gpu_alpha - vcl_v2 / gpu_beta;
979 
980  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
981  return EXIT_FAILURE;
982 
983  std::cout << "Testing inplace division-subtract on vector with GPU scalar (both, adding)..." << std::endl;
984  ublas_v2 = 3 * ublas_v1;
985  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
986  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
987 
988  ublas_v1 -= ublas_v1 / alpha + ublas_v2 / beta;
989  vcl_v1 -= vcl_v1 / gpu_alpha + vcl_v2 / gpu_beta;
990 
991  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
992  return EXIT_FAILURE;
993 
994  std::cout << "Testing inplace division-subtract on vector with GPU scalar (both, subtracting)..." << std::endl;
995  ublas_v2 = 3 * ublas_v1;
996  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
997  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
998 
999  ublas_v1 -= ublas_v1 / alpha - ublas_v2 / beta;
1000  vcl_v1 -= vcl_v1 / gpu_alpha - vcl_v2 / gpu_beta;
1001 
1002  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1003  return EXIT_FAILURE;
1004 
1005  std::cout << "Testing multiply-division-subtract on vector with GPU scalar..." << std::endl;
1006  ublas_v2 = 3 * ublas_v1;
1007  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1008  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1009 
1010  ublas_v1 = ublas_v1 * alpha - ublas_v2 / beta;
1011  vcl_v1 = vcl_v1 * gpu_alpha - vcl_v2 / gpu_beta;
1012 
1013  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1014  return EXIT_FAILURE;
1015 
1016  std::cout << "Testing division-multiply-subtract on vector with GPU scalar..." << std::endl;
1017  ublas_v2 = 3 * ublas_v1;
1018  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1019  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1020 
1021  ublas_v1 = ublas_v1 / alpha - ublas_v2 * beta;
1022  vcl_v1 = vcl_v1 / gpu_alpha - vcl_v2 * gpu_beta;
1023 
1024  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1025  return EXIT_FAILURE;
1026 
1027  std::cout << "Testing inplace multiply-division-subtract on vector with GPU scalar (adding)..." << std::endl;
1028  ublas_v2 = 3 * ublas_v1;
1029  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1030  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1031 
1032  ublas_v1 -= ublas_v1 * alpha + ublas_v2 / beta;
1033  vcl_v1 -= vcl_v1 * gpu_alpha + vcl_v2 / gpu_beta;
1034 
1035  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1036  return EXIT_FAILURE;
1037 
1038  std::cout << "Testing inplace division-multiply-subtract on vector with GPU scalar (adding)..." << std::endl;
1039  ublas_v2 = 3 * ublas_v1;
1040  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1041  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1042 
1043  ublas_v1 -= ublas_v1 / alpha + ublas_v2 * beta;
1044  vcl_v1 -= vcl_v1 / gpu_alpha + vcl_v2 * gpu_beta;
1045 
1046  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1047  return EXIT_FAILURE;
1048 
1049  std::cout << "Testing inplace multiply-division-subtract on vector with GPU scalar (subtracting)..." << std::endl;
1050  ublas_v2 = 3 * ublas_v1;
1051  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1052  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1053 
1054  ublas_v1 -= ublas_v1 * alpha - ublas_v2 / beta;
1055  vcl_v1 -= vcl_v1 * gpu_alpha - vcl_v2 / gpu_beta;
1056 
1057  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1058  return EXIT_FAILURE;
1059 
1060  std::cout << "Testing inplace division-multiply-subtract on vector with GPU scalar (subtracting)..." << std::endl;
1061  ublas_v2 = 3 * ublas_v1;
1062  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1063  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1064 
1065  ublas_v1 -= ublas_v1 / alpha - ublas_v2 * beta;
1066  vcl_v1 -= vcl_v1 / gpu_alpha - vcl_v2 * gpu_beta;
1067 
1068  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1069  return EXIT_FAILURE;
1070 
1071 
1072  std::cout << "Testing inplace division-subtract on vector with GPU scalar..." << std::endl;
1073  ublas_v2 = 3 * ublas_v1;
1074  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1075  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1076 
1077  ublas_v1 -= alpha * ublas_v2;
1078  vcl_v1 -= gpu_alpha * vcl_v2;
1079 
1080  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1081  return EXIT_FAILURE;
1082 
1083 
1084 
1085  //
1086  // More complicated expressions (for ensuring the operator overloads work correctly)
1087  //
1088  for (size_t i=0; i < ublas_v1.size(); ++i)
1089  ublas_v1(i) = NumericT(i);
1090  ublas_v2 = 3 * ublas_v1;
1091  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1092  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1093 
1094  std::cout << "Testing three vector additions..." << std::endl;
1095  ublas_v1 = ublas_v2 + ublas_v1 + ublas_v2;
1096  vcl_v1 = vcl_v2 + vcl_v1 + vcl_v2;
1097 
1098  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1099  return EXIT_FAILURE;
1100 
1101 
1102  ublas_v2 = 3 * ublas_v1;
1103  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1104  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1105 
1106  std::cout << "Testing complicated vector expression with CPU scalar..." << std::endl;
1107  ublas_v1 = beta * (ublas_v1 - alpha * ublas_v2);
1108  vcl_v1 = beta * (vcl_v1 - alpha * vcl_v2);
1109 
1110  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1111  return EXIT_FAILURE;
1112 
1113  std::cout << "Testing complicated vector expression with GPU scalar..." << std::endl;
1114  ublas_v1 = beta * (ublas_v1 - alpha * ublas_v2);
1115  vcl_v1 = gpu_beta * (vcl_v1 - gpu_alpha * vcl_v2);
1116 
1117  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1118  return EXIT_FAILURE;
1119 
1120  // --------------------------------------------------------------------------
1121  ublas_v2 = 3 * ublas_v1;
1122  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1123  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1124 
1125  std::cout << "Testing swap..." << std::endl;
1126  swap(ublas_v1, ublas_v2);
1127  swap(vcl_v1, vcl_v2);
1128 
1129  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1130  return EXIT_FAILURE;
1131 
1132  // --------------------------------------------------------------------------
1133  for (std::size_t i=0; i<ublas_v1.size(); ++i)
1134  {
1135  ublas_v1[i] = NumericT(1.0) + NumericT(i);
1136  ublas_v2[i] = NumericT(5.0) + NumericT(i);
1137  }
1138 
1139  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1140  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1141 
1142  std::cout << "Testing unary operator-..." << std::endl;
1143  ublas_v1 = - ublas_v2;
1144  vcl_v1 = - vcl_v2;
1145 
1146  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1147  return EXIT_FAILURE;
1148 
1149 
1150  std::cout << "Testing elementwise multiplication..." << std::endl;
1151  std::cout << " v1 = element_prod(v1, v2);" << std::endl;
1152  ublas_v1 = ublas::element_prod(ublas_v1, ublas_v2);
1153  vcl_v1 = viennacl::linalg::element_prod(vcl_v1, vcl_v2);
1154 
1155  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1156  return EXIT_FAILURE;
1157 
1158  std::cout << " v1 += element_prod(v1, v2);" << std::endl;
1159  ublas_v1 += ublas::element_prod(ublas_v1, ublas_v2);
1160  vcl_v1 += viennacl::linalg::element_prod(vcl_v1, vcl_v2);
1161 
1162  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1163  return EXIT_FAILURE;
1164 
1165  std::cout << " v1 -= element_prod(v1, v2);" << std::endl;
1166  ublas_v1 -= ublas::element_prod(ublas_v1, ublas_v2);
1167  vcl_v1 -= viennacl::linalg::element_prod(vcl_v1, vcl_v2);
1168 
1169  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1170  return EXIT_FAILURE;
1171 
1173  std::cout << " v1 = element_prod(v1 + v2, v2);" << std::endl;
1174  ublas_v1 = ublas::element_prod(ublas_v1 + ublas_v2, ublas_v2);
1175  vcl_v1 = viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2);
1176 
1177  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1178  return EXIT_FAILURE;
1179 
1180  std::cout << " v1 += element_prod(v1 + v2, v2);" << std::endl;
1181  ublas_v1 += ublas::element_prod(ublas_v1 + ublas_v2, ublas_v2);
1182  vcl_v1 += viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2);
1183 
1184  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1185  return EXIT_FAILURE;
1186 
1187  std::cout << " v1 -= element_prod(v1 + v2, v2);" << std::endl;
1188  ublas_v1 -= ublas::element_prod(ublas_v1 + ublas_v2, ublas_v2);
1189  vcl_v1 -= viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2);
1190 
1191  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1192  return EXIT_FAILURE;
1193 
1195  std::cout << " v1 = element_prod(v1, v2 + v1);" << std::endl;
1196  ublas_v1 = ublas::element_prod(ublas_v1, ublas_v2 + ublas_v1);
1197  vcl_v1 = viennacl::linalg::element_prod(vcl_v1, vcl_v2 + vcl_v1);
1198 
1199  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1200  return EXIT_FAILURE;
1201 
1202  std::cout << " v1 += element_prod(v1, v2 + v1);" << std::endl;
1203  ublas_v1 += ublas::element_prod(ublas_v1, ublas_v2 + ublas_v1);
1204  vcl_v1 += viennacl::linalg::element_prod(vcl_v1, vcl_v2 + vcl_v1);
1205 
1206  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1207  return EXIT_FAILURE;
1208 
1209  std::cout << " v1 -= element_prod(v1, v2 + v1);" << std::endl;
1210  ublas_v1 -= ublas::element_prod(ublas_v1, ublas_v2 + ublas_v1);
1211  vcl_v1 -= viennacl::linalg::element_prod(vcl_v1, vcl_v2 + vcl_v1);
1212 
1213  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1214  return EXIT_FAILURE;
1215 
1217  std::cout << " v1 = element_prod(v1 + v2, v2 + v1);" << std::endl;
1218  ublas_v1 = ublas::element_prod(ublas_v1 + ublas_v2, ublas_v2 + ublas_v1);
1219  vcl_v1 = viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
1220 
1221  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1222  return EXIT_FAILURE;
1223 
1224  std::cout << " v1 += element_prod(v1 + v2, v2 + v1);" << std::endl;
1225  ublas_v1 += ublas::element_prod(ublas_v1 + ublas_v2, ublas_v2 + ublas_v1);
1226  vcl_v1 += viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
1227 
1228  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1229  return EXIT_FAILURE;
1230 
1231  std::cout << " v1 -= element_prod(v1 + v2, v2 + v1);" << std::endl;
1232  ublas_v1 -= ublas::element_prod(ublas_v1 + ublas_v2, ublas_v2 + ublas_v1);
1233  vcl_v1 -= viennacl::linalg::element_prod(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
1234 
1235  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1236  return EXIT_FAILURE;
1237 
1238 
1239  std::cout << "Testing elementwise division..." << std::endl;
1240  for (std::size_t i=0; i<ublas_v1.size(); ++i)
1241  {
1242  ublas_v1[i] = NumericT(1 + i);
1243  ublas_v2[i] = NumericT(5 + i);
1244  }
1245 
1246  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1247  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1248 
1249  ublas_v1 = ublas::element_div(ublas_v1, ublas_v2);
1250  vcl_v1 = viennacl::linalg::element_div(vcl_v1, vcl_v2);
1251 
1252  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1253  return EXIT_FAILURE;
1254 
1255  ublas_v1 += ublas::element_div(ublas_v1, ublas_v2);
1256  vcl_v1 += viennacl::linalg::element_div(vcl_v1, vcl_v2);
1257 
1258  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1259  return EXIT_FAILURE;
1260 
1261  ublas_v1 -= ublas::element_div(ublas_v1, ublas_v2);
1262  vcl_v1 -= viennacl::linalg::element_div(vcl_v1, vcl_v2);
1263 
1264  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1265  return EXIT_FAILURE;
1266 
1268  ublas_v1 = ublas::element_div(ublas_v1 + ublas_v2, ublas_v2);
1269  vcl_v1 = viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2);
1270 
1271  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1272  return EXIT_FAILURE;
1273 
1274  ublas_v1 += ublas::element_div(ublas_v1 + ublas_v2, ublas_v2);
1275  vcl_v1 += viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2);
1276 
1277  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1278  return EXIT_FAILURE;
1279 
1280  ublas_v1 -= ublas::element_div(ublas_v1 + ublas_v2, ublas_v2);
1281  vcl_v1 -= viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2);
1282 
1283  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1284  return EXIT_FAILURE;
1285 
1287  ublas_v1 = ublas::element_div(ublas_v1, ublas_v2 + ublas_v1);
1288  vcl_v1 = viennacl::linalg::element_div(vcl_v1, vcl_v2 + vcl_v1);
1289 
1290  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1291  return EXIT_FAILURE;
1292 
1293  ublas_v1 += ublas::element_div(ublas_v1, ublas_v2 + ublas_v1);
1294  vcl_v1 += viennacl::linalg::element_div(vcl_v1, vcl_v2 + vcl_v1);
1295 
1296  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1297  return EXIT_FAILURE;
1298 
1299  ublas_v1 -= ublas::element_div(ublas_v1, ublas_v2 + ublas_v1);
1300  vcl_v1 -= viennacl::linalg::element_div(vcl_v1, vcl_v2 + vcl_v1);
1301 
1302  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1303  return EXIT_FAILURE;
1304 
1306  ublas_v1 = ublas::element_div(ublas_v1 + ublas_v2, ublas_v2 + ublas_v1);
1307  vcl_v1 = viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
1308 
1309  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1310  return EXIT_FAILURE;
1311 
1312  ublas_v1 += ublas::element_div(ublas_v1 + ublas_v2, ublas_v2 + ublas_v1);
1313  vcl_v1 += viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
1314 
1315  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1316  return EXIT_FAILURE;
1317 
1318  ublas_v1 -= ublas::element_div(ublas_v1 + ublas_v2, ublas_v2 + ublas_v1);
1319  vcl_v1 -= viennacl::linalg::element_div(vcl_v1 + vcl_v2, vcl_v2 + vcl_v1);
1320 
1321  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1322  return EXIT_FAILURE;
1323 
1324  std::cout << "Testing unary elementwise operations..." << std::endl;
1325 
1326 #define GENERATE_UNARY_OP_TEST(FUNCNAME) \
1327  ublas_v2 = 3 * ublas_v1; \
1328  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin()); \
1329  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin()); \
1330  \
1331  for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1332  ublas_v1[i] = std::FUNCNAME(ublas_v2[i]); \
1333  vcl_v1 = viennacl::linalg::element_##FUNCNAME(vcl_v2); \
1334  \
1335  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1336  { \
1337  std::cout << "Failure at v1 = " << #FUNCNAME << "(v2)" << std::endl; \
1338  return EXIT_FAILURE; \
1339  } \
1340  \
1341  for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1342  ublas_v1[i] = std::FUNCNAME(ublas_v1[i] + ublas_v2[i]); \
1343  vcl_v1 = viennacl::linalg::element_##FUNCNAME(vcl_v1 + vcl_v2); \
1344  \
1345  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1346  { \
1347  std::cout << "Failure at v1 = " << #FUNCNAME << "(v1 + v2)" << std::endl; \
1348  return EXIT_FAILURE; \
1349  } \
1350  \
1351  for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1352  ublas_v1[i] += std::FUNCNAME(ublas_v1[i]); \
1353  vcl_v1 += viennacl::linalg::element_##FUNCNAME(vcl_v1); \
1354  \
1355  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1356  { \
1357  std::cout << "Failure at v1 += " << #FUNCNAME << "(v2)" << std::endl; \
1358  return EXIT_FAILURE; \
1359  } \
1360  \
1361  for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1362  ublas_v1[i] += std::FUNCNAME(ublas_v1[i] + ublas_v2[i]); \
1363  vcl_v1 += viennacl::linalg::element_##FUNCNAME(vcl_v1 + vcl_v2); \
1364  \
1365  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1366  { \
1367  std::cout << "Failure at v1 += " << #FUNCNAME << "(v1 + v2)" << std::endl; \
1368  return EXIT_FAILURE; \
1369  } \
1370  \
1371  for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1372  ublas_v1[i] -= std::FUNCNAME(ublas_v2[i]); \
1373  vcl_v1 -= viennacl::linalg::element_##FUNCNAME(vcl_v2); \
1374  \
1375  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1376  { \
1377  std::cout << "Failure at v1 -= " << #FUNCNAME << "(v2)" << std::endl; \
1378  return EXIT_FAILURE; \
1379  } \
1380  \
1381  for (std::size_t i=0; i<ublas_v1.size(); ++i) \
1382  ublas_v1[i] -= std::FUNCNAME(ublas_v1[i] + ublas_v2[i]); \
1383  vcl_v1 -= viennacl::linalg::element_##FUNCNAME(vcl_v1 + vcl_v2); \
1384  \
1385  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS) \
1386  { \
1387  std::cout << "Failure at v1 -= " << #FUNCNAME << "(v1 + v2)" << std::endl; \
1388  return EXIT_FAILURE; \
1389  } \
1390 
1391  //GENERATE_UNARY_OP_TEST(cos);
1392  //GENERATE_UNARY_OP_TEST(cosh);
1393  //GENERATE_UNARY_OP_TEST(exp);
1394  //GENERATE_UNARY_OP_TEST(floor);
1395  //GENERATE_UNARY_OP_TEST(fabs);
1396  //GENERATE_UNARY_OP_TEST(log);
1397  //GENERATE_UNARY_OP_TEST(log10);
1398  //GENERATE_UNARY_OP_TEST(sin);
1399  //GENERATE_UNARY_OP_TEST(sinh);
1400  //GENERATE_UNARY_OP_TEST(fabs);
1402  //GENERATE_UNARY_OP_TEST(sqrt);
1403  //GENERATE_UNARY_OP_TEST(tan);
1404  //GENERATE_UNARY_OP_TEST(tanh);
1405 
1406  std::cout << "Testing lenghty sum of scaled vectors..." << std::endl;
1407  ublas_v2 = 3 * ublas_v1;
1408  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
1409  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
1410 
1411  ublas_v1 = ublas_v2 / alpha + beta * ublas_v1 - alpha * ublas_v2 + beta * ublas_v1 - alpha * ublas_v1;
1412  vcl_v1 = vcl_v2 / gpu_alpha + gpu_beta * vcl_v1 - alpha * vcl_v2 + beta * vcl_v1 - alpha * vcl_v1;
1413 
1414  if (check(ublas_v1, vcl_v1) != EXIT_SUCCESS)
1415  return EXIT_FAILURE;
1416 
1417  // --------------------------------------------------------------------------
1418  return retval;
1419 }
1420 
1421 
1422 template< typename NumericT >
1423 int test()
1424 {
1425  int retval = EXIT_SUCCESS;
1426  std::size_t size = 12345;
1427 
1428  std::cout << "Running tests for vector of size " << size << std::endl;
1429 
1430  //
1431  // Set up UBLAS objects
1432  //
1433  ublas::vector<NumericT> ublas_full_vec(size);
1434  ublas::vector<NumericT> ublas_full_vec2(ublas_full_vec.size());
1435 
1436  for (std::size_t i=0; i<ublas_full_vec.size(); ++i)
1437  {
1438  ublas_full_vec[i] = NumericT(1.0) + NumericT(i);
1439  ublas_full_vec2[i] = NumericT(2.0) + NumericT(i) / NumericT(2);
1440  }
1441 
1442  ublas::range r1( ublas_full_vec.size() / 4, 2 * ublas_full_vec.size() / 4);
1443  ublas::range r2(2 * ublas_full_vec2.size() / 4, 3 * ublas_full_vec2.size() / 4);
1444  ublas::vector_range< ublas::vector<NumericT> > ublas_range_vec(ublas_full_vec, r1);
1445  ublas::vector_range< ublas::vector<NumericT> > ublas_range_vec2(ublas_full_vec2, r2);
1446 
1447  ublas::slice s1( ublas_full_vec.size() / 4, 3, ublas_full_vec.size() / 4);
1448  ublas::slice s2(2 * ublas_full_vec2.size() / 4, 2, ublas_full_vec2.size() / 4);
1449  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec(ublas_full_vec, s1);
1450  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec2(ublas_full_vec2, s2);
1451 
1452  //
1453  // Set up ViennaCL objects
1454  //
1455  viennacl::vector<NumericT> vcl_full_vec(ublas_full_vec.size());
1456  viennacl::vector<NumericT> vcl_full_vec2(ublas_full_vec2.size());
1457 
1458  viennacl::fast_copy(ublas_full_vec.begin(), ublas_full_vec.end(), vcl_full_vec.begin());
1459  viennacl::copy(ublas_full_vec2.begin(), ublas_full_vec2.end(), vcl_full_vec2.begin());
1460 
1461  viennacl::range vcl_r1( vcl_full_vec.size() / 4, 2 * vcl_full_vec.size() / 4);
1462  viennacl::range vcl_r2(2 * vcl_full_vec2.size() / 4, 3 * vcl_full_vec2.size() / 4);
1463  viennacl::vector_range< viennacl::vector<NumericT> > vcl_range_vec(vcl_full_vec, vcl_r1);
1464  viennacl::vector_range< viennacl::vector<NumericT> > vcl_range_vec2(vcl_full_vec2, vcl_r2);
1465 
1466  {
1467  viennacl::vector<NumericT> vcl_short_vec(vcl_range_vec);
1468  viennacl::vector<NumericT> vcl_short_vec2 = vcl_range_vec2;
1469 
1470  ublas::vector<NumericT> ublas_short_vec(ublas_range_vec);
1471  ublas::vector<NumericT> ublas_short_vec2(ublas_range_vec2);
1472 
1473  std::cout << "Testing creation of vectors from range..." << std::endl;
1474  if (check(ublas_short_vec, vcl_short_vec) != EXIT_SUCCESS)
1475  return EXIT_FAILURE;
1476  if (check(ublas_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
1477  return EXIT_FAILURE;
1478  }
1479 
1480  viennacl::slice vcl_s1( vcl_full_vec.size() / 4, 3, vcl_full_vec.size() / 4);
1481  viennacl::slice vcl_s2(2 * vcl_full_vec2.size() / 4, 2, vcl_full_vec2.size() / 4);
1482  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec(vcl_full_vec, vcl_s1);
1483  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec2(vcl_full_vec2, vcl_s2);
1484 
1485  viennacl::vector<NumericT> vcl_short_vec(vcl_slice_vec);
1486  viennacl::vector<NumericT> vcl_short_vec2 = vcl_slice_vec2;
1487 
1488  ublas::vector<NumericT> ublas_short_vec(ublas_slice_vec);
1489  ublas::vector<NumericT> ublas_short_vec2(ublas_slice_vec2);
1490 
1491  std::cout << "Testing creation of vectors from slice..." << std::endl;
1492  if (check(ublas_short_vec, vcl_short_vec) != EXIT_SUCCESS)
1493  return EXIT_FAILURE;
1494  if (check(ublas_short_vec2, vcl_short_vec2) != EXIT_SUCCESS)
1495  return EXIT_FAILURE;
1496 
1497 
1498  //
1499  // Now start running tests for vectors, ranges and slices:
1500  //
1501 
1502  std::cout << " ** vcl_v1 = vector, vcl_v2 = vector **" << std::endl;
1503  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1504  vcl_short_vec, vcl_short_vec2);
1505  if (retval != EXIT_SUCCESS)
1506  return EXIT_FAILURE;
1507 
1508  std::cout << " ** vcl_v1 = vector, vcl_v2 = range **" << std::endl;
1509  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1510  vcl_short_vec, vcl_range_vec2);
1511  if (retval != EXIT_SUCCESS)
1512  return EXIT_FAILURE;
1513 
1514  std::cout << " ** vcl_v1 = vector, vcl_v2 = slice **" << std::endl;
1515  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1516  vcl_short_vec, vcl_slice_vec2);
1517  if (retval != EXIT_SUCCESS)
1518  return EXIT_FAILURE;
1519 
1521 
1522  std::cout << " ** vcl_v1 = range, vcl_v2 = vector **" << std::endl;
1523  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1524  vcl_range_vec, vcl_short_vec2);
1525  if (retval != EXIT_SUCCESS)
1526  return EXIT_FAILURE;
1527 
1528  std::cout << " ** vcl_v1 = range, vcl_v2 = range **" << std::endl;
1529  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1530  vcl_range_vec, vcl_range_vec2);
1531  if (retval != EXIT_SUCCESS)
1532  return EXIT_FAILURE;
1533 
1534  std::cout << " ** vcl_v1 = range, vcl_v2 = slice **" << std::endl;
1535  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1536  vcl_range_vec, vcl_slice_vec2);
1537  if (retval != EXIT_SUCCESS)
1538  return EXIT_FAILURE;
1539 
1541 
1542  std::cout << " ** vcl_v1 = slice, vcl_v2 = vector **" << std::endl;
1543  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1544  vcl_slice_vec, vcl_short_vec2);
1545  if (retval != EXIT_SUCCESS)
1546  return EXIT_FAILURE;
1547 
1548  std::cout << " ** vcl_v1 = slice, vcl_v2 = range **" << std::endl;
1549  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1550  vcl_slice_vec, vcl_range_vec2);
1551  if (retval != EXIT_SUCCESS)
1552  return EXIT_FAILURE;
1553 
1554  std::cout << " ** vcl_v1 = slice, vcl_v2 = slice **" << std::endl;
1555  retval = test<NumericT>(ublas_short_vec, ublas_short_vec2,
1556  vcl_slice_vec, vcl_slice_vec2);
1557  if (retval != EXIT_SUCCESS)
1558  return EXIT_FAILURE;
1559 
1560  return EXIT_SUCCESS;
1561 }
1562 
1563 
1564 
1565 //
1566 // -------------------------------------------------------------
1567 //
1568 int main()
1569 {
1570  std::cout << std::endl;
1571  std::cout << "----------------------------------------------" << std::endl;
1572  std::cout << "----------------------------------------------" << std::endl;
1573  std::cout << "## Test :: Vector with Integer types" << std::endl;
1574  std::cout << "----------------------------------------------" << std::endl;
1575  std::cout << "----------------------------------------------" << std::endl;
1576  std::cout << std::endl;
1577 
1578  int retval = EXIT_SUCCESS;
1579 
1580  std::cout << std::endl;
1581  std::cout << "----------------------------------------------" << std::endl;
1582  std::cout << std::endl;
1583  {
1584  std::cout << "# Testing setup:" << std::endl;
1585  std::cout << " numeric: int" << std::endl;
1586  retval = test<int>();
1587  if ( retval == EXIT_SUCCESS )
1588  std::cout << "# Test passed" << std::endl;
1589  else
1590  return retval;
1591  }
1592  std::cout << std::endl;
1593  std::cout << "----------------------------------------------" << std::endl;
1594  std::cout << std::endl;
1595  {
1596  std::cout << "# Testing setup:" << std::endl;
1597  std::cout << " numeric: long" << std::endl;
1598  retval = test<long>();
1599  if ( retval == EXIT_SUCCESS )
1600  std::cout << "# Test passed" << std::endl;
1601  else
1602  return retval;
1603  }
1604  std::cout << std::endl;
1605  std::cout << "----------------------------------------------" << std::endl;
1606  std::cout << std::endl;
1607 
1608  std::cout << std::endl;
1609  std::cout << "------- Test completed --------" << std::endl;
1610  std::cout << std::endl;
1611 
1612  return retval;
1613 }
int test(UblasVectorType &ublas_v1, UblasVectorType &ublas_v2, ViennaCLVectorType1 &vcl_v1, ViennaCLVectorType2 &vcl_v2)
Definition: vector_int.cpp:117
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
void plane_rotation(vector_base< T > &vec1, vector_base< T > &vec2, T alpha, T beta)
Computes a plane rotation of two vectors.
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...
#define GENERATE_UNARY_OP_TEST(FUNCNAME)
float NumericT
Definition: bisect.cpp:40
basic_range range
Definition: forwards.h:424
int check(T1 const &t1, T2 const &t2)
Definition: vector_int.cpp:100
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
int main()
Class for representing strided subvectors of a bigger vector x.
Definition: forwards.h:437
ScalarType diff(ScalarType const &s1, ScalarType const &s2)
Definition: vector_int.cpp:57
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.
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)