ViennaCL - The Vienna Computing Library  1.6.0
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vector_multi_inner_prod.cpp
Go to the documentation of this file.
1 /* =========================================================================
2  Copyright (c) 2010-2014, Institute for Microelectronics,
3  Institute for Analysis and Scientific Computing,
4  TU Wien.
5  Portions of this software are copyright by UChicago Argonne, LLC.
6 
7  -----------------
8  ViennaCL - The Vienna Computing Library
9  -----------------
10 
11  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
12 
13  (A list of authors and contributors can be found in the PDF manual)
14 
15  License: MIT (X11), see file LICENSE in the base directory
16 ============================================================================= */
17 
18 
19 
24 //
25 // *** System
26 //
27 #include <iostream>
28 #include <iomanip>
29 
30 //
31 // *** Boost
32 //
33 #include <boost/numeric/ublas/io.hpp>
34 #include <boost/numeric/ublas/vector.hpp>
35 #include <boost/numeric/ublas/vector_proxy.hpp>
36 
37 //
38 // *** ViennaCL
39 //
40 //#define VIENNACL_DEBUG_ALL
41 #define VIENNACL_WITH_UBLAS 1
42 #include "viennacl/vector.hpp"
48 
49 #include "Random.hpp"
50 
51 using namespace boost::numeric;
52 
53 
54 //
55 // -------------------------------------------------------------
56 //
57 template<typename ScalarType>
59 {
61  if (s1 != s2)
62  return (s1 - s2) / std::max(std::fabs(s1), std::fabs(s2));
63  return 0;
64 }
65 //
66 // -------------------------------------------------------------
67 //
68 template<typename ScalarType>
70 {
72  if (s1 != s2)
73  return (s1 - s2) / std::max(std::fabs(s1), std::fabs(s2));
74  return 0;
75 }
76 //
77 // -------------------------------------------------------------
78 //
79 template<typename ScalarType>
81 {
83  if (s1 != s2)
84  return (s1 - s2) / std::max(std::fabs(s1), std::fabs(s2));
85  return 0;
86 }
87 //
88 // -------------------------------------------------------------
89 //
90 template<typename ScalarType, typename ViennaCLVectorType>
91 ScalarType diff(ublas::vector<ScalarType> const & v1, ViennaCLVectorType const & vcl_vec)
92 {
93  ublas::vector<ScalarType> v2_cpu(vcl_vec.size());
95  viennacl::copy(vcl_vec, v2_cpu);
96 
97  for (unsigned int i=0;i<v1.size(); ++i)
98  {
99  if ( std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 )
100  v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) / std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) );
101  else
102  v2_cpu[i] = 0.0;
103  }
104 
105  return ublas::norm_inf(v2_cpu);
106 }
107 
108 template<typename ScalarType, typename ViennaCLVectorType>
109 ScalarType diff(ublas::vector_slice<ublas::vector<ScalarType> > const & v1, ViennaCLVectorType const & vcl_vec)
110 {
111  ublas::vector<ScalarType> v2_cpu(vcl_vec.size());
113  viennacl::copy(vcl_vec, v2_cpu);
114 
115  for (unsigned int i=0;i<v1.size(); ++i)
116  {
117  if ( std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 )
118  v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) / std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) );
119  else
120  v2_cpu[i] = 0.0;
121  }
122 
123  return ublas::norm_inf(v2_cpu);
124 }
125 
126 
127 template<typename T1, typename T2>
128 int check(T1 const & t1, T2 const & t2, double epsilon)
129 {
130  int retval = EXIT_SUCCESS;
131 
132  double temp = std::fabs(diff(t1, t2));
133  if (temp > epsilon)
134  {
135  std::cout << "# Error! Relative difference: " << temp << std::endl;
136  retval = EXIT_FAILURE;
137  }
138  return retval;
139 }
140 
141 
142 //
143 // -------------------------------------------------------------
144 //
145 template< typename NumericT, typename Epsilon,
146  typename UblasVectorType1, typename UblasVectorType2, typename UblasVectorType3, typename UblasVectorType4,
147  typename ViennaCLVectorType1, typename ViennaCLVectorType2, typename ViennaCLVectorType3, typename ViennaCLVectorType4 >
148 int test(Epsilon const& epsilon,
149  UblasVectorType1 & ublas_v1, UblasVectorType2 & ublas_v2, UblasVectorType3 & ublas_v3, UblasVectorType4 & ublas_v4,
150  ViennaCLVectorType1 & vcl_v1, ViennaCLVectorType2 & vcl_v2, ViennaCLVectorType3 & vcl_v3, ViennaCLVectorType4 & vcl_v4)
151 {
152  int retval = EXIT_SUCCESS;
153 
154  for (std::size_t i=0; i<ublas_v1.size(); ++i)
155  {
156  ublas_v1[i] = NumericT(1.0) + random<NumericT>();
157  ublas_v2[i] = NumericT(1.0) + random<NumericT>();
158  ublas_v3[i] = NumericT(1.0) + random<NumericT>();
159  ublas_v4[i] = NumericT(1.0) + random<NumericT>();
160  }
161 
162  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin()); //resync
163  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
164  viennacl::copy(ublas_v3.begin(), ublas_v3.end(), vcl_v3.begin());
165  viennacl::copy(ublas_v4.begin(), ublas_v4.end(), vcl_v4.begin());
166 
167  std::cout << "Checking for successful copy..." << std::endl;
168  if (check(ublas_v1, vcl_v1, epsilon) != EXIT_SUCCESS)
169  return EXIT_FAILURE;
170  if (check(ublas_v2, vcl_v2, epsilon) != EXIT_SUCCESS)
171  return EXIT_FAILURE;
172  if (check(ublas_v3, vcl_v3, epsilon) != EXIT_SUCCESS)
173  return EXIT_FAILURE;
174  if (check(ublas_v4, vcl_v4, epsilon) != EXIT_SUCCESS)
175  return EXIT_FAILURE;
176 
177  ublas::vector<NumericT> ref_result = ublas::scalar_vector<NumericT>(40, 0.0);
179 
180  std::cout << "Testing inner_prod with two vectors..." << std::endl;
181  ref_result(2) = ublas::inner_prod(ublas_v1, ublas_v1);
182  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v2);
183  viennacl::project(result, viennacl::slice(2, 3, 2)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v1, vcl_v2));
184  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
185  {
186  std::cout << ref_result << std::endl;
187  std::cout << result << std::endl;
188  return EXIT_FAILURE;
189  }
190 
191  ref_result(3) = ublas::inner_prod(ublas_v1, ublas_v3);
192  ref_result(7) = ublas::inner_prod(ublas_v1, ublas_v4);
193  viennacl::project(result, viennacl::slice(3, 4, 2)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v3, vcl_v4));
194  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
195  {
196  std::cout << ref_result << std::endl;
197  std::cout << result << std::endl;
198  return EXIT_FAILURE;
199  }
200 
201 
202  std::cout << "Testing inner_prod with three vectors..." << std::endl;
203  ref_result(1) = ublas::inner_prod(ublas_v1, ublas_v1);
204  ref_result(3) = ublas::inner_prod(ublas_v1, ublas_v2);
205  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v3);
206  viennacl::project(result, viennacl::slice(1, 2, 3)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v1, vcl_v2, vcl_v3));
207  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
208  {
209  std::cout << ref_result << std::endl;
210  std::cout << result << std::endl;
211  return EXIT_FAILURE;
212  }
213 
214  ref_result(2) = ublas::inner_prod(ublas_v1, ublas_v3);
215  ref_result(6) = ublas::inner_prod(ublas_v1, ublas_v2);
216  ref_result(10) = ublas::inner_prod(ublas_v1, ublas_v4);
217  viennacl::project(result, viennacl::slice(2, 4, 3)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v3, vcl_v2, vcl_v4));
218  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
219  {
220  std::cout << ref_result << std::endl;
221  std::cout << result << std::endl;
222  return EXIT_FAILURE;
223  }
224 
225  std::cout << "Testing inner_prod with four vectors..." << std::endl;
226  ref_result(4) = ublas::inner_prod(ublas_v1, ublas_v1);
227  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v2);
228  ref_result(6) = ublas::inner_prod(ublas_v1, ublas_v3);
229  ref_result(7) = ublas::inner_prod(ublas_v1, ublas_v4);
230  viennacl::project(result, viennacl::slice(4, 1, 4)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v1, vcl_v2, vcl_v3, vcl_v4));
231  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
232  {
233  std::cout << ref_result << std::endl;
234  std::cout << result << std::endl;
235  return EXIT_FAILURE;
236  }
237 
238  ref_result(3) = ublas::inner_prod(ublas_v1, ublas_v3);
239  ref_result(6) = ublas::inner_prod(ublas_v1, ublas_v2);
240  ref_result(9) = ublas::inner_prod(ublas_v1, ublas_v4);
241  ref_result(12) = ublas::inner_prod(ublas_v1, ublas_v1);
242  viennacl::project(result, viennacl::slice(3, 3, 4)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v3, vcl_v2, vcl_v4, vcl_v1));
243  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
244  {
245  std::cout << ref_result << std::endl;
246  std::cout << result << std::endl;
247  return EXIT_FAILURE;
248  }
249 
250  std::cout << "Testing inner_prod with five vectors..." << std::endl;
251  ref_result(1) = ublas::inner_prod(ublas_v1, ublas_v1);
252  ref_result(3) = ublas::inner_prod(ublas_v1, ublas_v2);
253  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v3);
254  ref_result(7) = ublas::inner_prod(ublas_v1, ublas_v4);
255  ref_result(9) = ublas::inner_prod(ublas_v1, ublas_v2);
256  viennacl::project(result, viennacl::slice(1, 2, 5)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v1, vcl_v2, vcl_v3, vcl_v4, vcl_v2));
257  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
258  {
259  std::cout << ref_result << std::endl;
260  std::cout << result << std::endl;
261  return EXIT_FAILURE;
262  }
263 
264  ref_result(2) = ublas::inner_prod(ublas_v1, ublas_v3);
265  ref_result(4) = ublas::inner_prod(ublas_v1, ublas_v2);
266  ref_result(6) = ublas::inner_prod(ublas_v1, ublas_v4);
267  ref_result(8) = ublas::inner_prod(ublas_v1, ublas_v1);
268  ref_result(10) = ublas::inner_prod(ublas_v1, ublas_v2);
269  viennacl::project(result, viennacl::slice(2, 2, 5)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v3, vcl_v2, vcl_v4, vcl_v1, vcl_v2));
270  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
271  {
272  std::cout << ref_result << std::endl;
273  std::cout << result << std::endl;
274  return EXIT_FAILURE;
275  }
276 
277 
278  std::cout << "Testing inner_prod with eight vectors..." << std::endl;
279  ref_result(1) = ublas::inner_prod(ublas_v1, ublas_v1);
280  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v2);
281  ref_result(9) = ublas::inner_prod(ublas_v1, ublas_v3);
282  ref_result(13) = ublas::inner_prod(ublas_v1, ublas_v4);
283  ref_result(17) = ublas::inner_prod(ublas_v1, ublas_v3);
284  ref_result(21) = ublas::inner_prod(ublas_v1, ublas_v2);
285  ref_result(25) = ublas::inner_prod(ublas_v1, ublas_v1);
286  ref_result(29) = ublas::inner_prod(ublas_v1, ublas_v2);
287  std::vector<viennacl::vector_base<NumericT> const *> vecs1(8);
288  vecs1[0] = &vcl_v1;
289  vecs1[1] = &vcl_v2;
290  vecs1[2] = &vcl_v3;
291  vecs1[3] = &vcl_v4;
292  vecs1[4] = &vcl_v3;
293  vecs1[5] = &vcl_v2;
294  vecs1[6] = &vcl_v1;
295  vecs1[7] = &vcl_v2;
296  viennacl::vector_tuple<NumericT> tuple1(vecs1);
297  viennacl::project(result, viennacl::slice(1, 4, 8)) = viennacl::linalg::inner_prod(vcl_v1, tuple1);
298  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
299  {
300  std::cout << ref_result << std::endl;
301  std::cout << result << std::endl;
302  return EXIT_FAILURE;
303  }
304 
305  ref_result(3) = ublas::inner_prod(ublas_v1, ublas_v2);
306  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v4);
307  ref_result(7) = ublas::inner_prod(ublas_v1, ublas_v1);
308  ref_result(9) = ublas::inner_prod(ublas_v1, ublas_v2);
309  ref_result(11) = ublas::inner_prod(ublas_v1, ublas_v2);
310  ref_result(13) = ublas::inner_prod(ublas_v1, ublas_v1);
311  ref_result(15) = ublas::inner_prod(ublas_v1, ublas_v4);
312  ref_result(17) = ublas::inner_prod(ublas_v1, ublas_v2);
313  std::vector<viennacl::vector_base<NumericT> const *> vecs2(8);
314  vecs2[0] = &vcl_v2;
315  vecs2[1] = &vcl_v4;
316  vecs2[2] = &vcl_v1;
317  vecs2[3] = &vcl_v2;
318  vecs2[4] = &vcl_v2;
319  vecs2[5] = &vcl_v1;
320  vecs2[6] = &vcl_v4;
321  vecs2[7] = &vcl_v2;
322  viennacl::vector_tuple<NumericT> tuple2(vecs2);
323  viennacl::project(result, viennacl::slice(3, 2, 8)) = viennacl::linalg::inner_prod(vcl_v1, tuple2);
324  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
325  {
326  std::cout << ref_result << std::endl;
327  std::cout << result << std::endl;
328  return EXIT_FAILURE;
329  }
330 
331 
332  // --------------------------------------------------------------------------
333  return retval;
334 }
335 
336 
337 template< typename NumericT, typename Epsilon >
338 int test(Epsilon const& epsilon)
339 {
340  int retval = EXIT_SUCCESS;
341  std::size_t size = 8 * 1337;
342 
343  std::cout << "Running tests for vector of size " << size << std::endl;
344 
345  //
346  // Set up UBLAS objects
347  //
348  ublas::vector<NumericT> ublas_full_vec1(size);
349  ublas::vector<NumericT> ublas_full_vec2(ublas_full_vec1.size());
350 
351  for (std::size_t i=0; i<ublas_full_vec1.size(); ++i)
352  {
353  ublas_full_vec1[i] = NumericT(1.0) + random<NumericT>();
354  ublas_full_vec2[i] = NumericT(1.0) + random<NumericT>();
355  }
356 
357  ublas::slice s1( ublas_full_vec1.size() / 8, 3, ublas_full_vec1.size() / 8);
358  ublas::slice s2(2 * ublas_full_vec2.size() / 8, 1, ublas_full_vec2.size() / 8);
359  ublas::slice s3(4 * ublas_full_vec1.size() / 8, 2, ublas_full_vec1.size() / 8);
360  ublas::slice s4(3 * ublas_full_vec2.size() / 8, 4, ublas_full_vec2.size() / 8);
361  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec1(ublas_full_vec1, s1);
362  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec2(ublas_full_vec2, s2);
363  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec3(ublas_full_vec1, s3);
364  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec4(ublas_full_vec2, s4);
365 
366  //
367  // Set up ViennaCL objects
368  //
369  viennacl::vector<NumericT> vcl_full_vec1(ublas_full_vec1.size());
370  viennacl::vector<NumericT> vcl_full_vec2(ublas_full_vec2.size());
371 
372  viennacl::fast_copy(ublas_full_vec1.begin(), ublas_full_vec1.end(), vcl_full_vec1.begin());
373  viennacl::copy (ublas_full_vec2.begin(), ublas_full_vec2.end(), vcl_full_vec2.begin());
374 
375  viennacl::slice vcl_s1( vcl_full_vec1.size() / 8, 3, vcl_full_vec1.size() / 8);
376  viennacl::slice vcl_s2(2 * vcl_full_vec2.size() / 8, 1, vcl_full_vec2.size() / 8);
377  viennacl::slice vcl_s3(4 * vcl_full_vec1.size() / 8, 2, vcl_full_vec1.size() / 8);
378  viennacl::slice vcl_s4(3 * vcl_full_vec2.size() / 8, 4, vcl_full_vec2.size() / 8);
379  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec1(vcl_full_vec1, vcl_s1);
380  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec2(vcl_full_vec2, vcl_s2);
381  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec3(vcl_full_vec1, vcl_s3);
382  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec4(vcl_full_vec2, vcl_s4);
383 
384  viennacl::vector<NumericT> vcl_short_vec1(vcl_slice_vec1);
385  viennacl::vector<NumericT> vcl_short_vec2 = vcl_slice_vec2;
386  viennacl::vector<NumericT> vcl_short_vec3 = vcl_slice_vec2 + vcl_slice_vec1;
387  viennacl::vector<NumericT> vcl_short_vec4 = vcl_short_vec1 + vcl_slice_vec2;
388 
389  ublas::vector<NumericT> ublas_short_vec1(ublas_slice_vec1);
390  ublas::vector<NumericT> ublas_short_vec2(ublas_slice_vec2);
391  ublas::vector<NumericT> ublas_short_vec3 = ublas_slice_vec2 + ublas_slice_vec1;
392  ublas::vector<NumericT> ublas_short_vec4 = ublas_short_vec1 + ublas_slice_vec2;
393 
394  std::cout << "Testing creation of vectors from slice..." << std::endl;
395  if (check(ublas_short_vec1, vcl_short_vec1, epsilon) != EXIT_SUCCESS)
396  return EXIT_FAILURE;
397  if (check(ublas_short_vec2, vcl_short_vec2, epsilon) != EXIT_SUCCESS)
398  return EXIT_FAILURE;
399  if (check(ublas_short_vec3, vcl_short_vec3, epsilon) != EXIT_SUCCESS)
400  return EXIT_FAILURE;
401  if (check(ublas_short_vec4, vcl_short_vec4, epsilon) != EXIT_SUCCESS)
402  return EXIT_FAILURE;
403 
404 
405  //
406  // Now start running tests for vectors, ranges and slices:
407  //
408 
409  std::cout << " ** [vector|vector|vector|vector] **" << std::endl;
410  retval = test<NumericT>(epsilon,
411  ublas_short_vec1, ublas_short_vec2, ublas_short_vec2, ublas_short_vec2,
412  vcl_short_vec1, vcl_short_vec2, vcl_short_vec3, vcl_short_vec4);
413  if (retval != EXIT_SUCCESS)
414  return EXIT_FAILURE;
415 
416  std::cout << " ** [vector|vector|vector|slice] **" << std::endl;
417  retval = test<NumericT>(epsilon,
418  ublas_short_vec1, ublas_short_vec2, ublas_short_vec2, ublas_slice_vec2,
419  vcl_short_vec1, vcl_short_vec2, vcl_short_vec3, vcl_slice_vec4);
420  if (retval != EXIT_SUCCESS)
421  return EXIT_FAILURE;
422 
423  std::cout << " ** [vector|vector|slice|vector] **" << std::endl;
424  retval = test<NumericT>(epsilon,
425  ublas_short_vec1, ublas_short_vec2, ublas_slice_vec2, ublas_short_vec2,
426  vcl_short_vec1, vcl_short_vec2, vcl_slice_vec3, vcl_short_vec4);
427  if (retval != EXIT_SUCCESS)
428  return EXIT_FAILURE;
429 
430  std::cout << " ** [vector|vector|slice|slice] **" << std::endl;
431  retval = test<NumericT>(epsilon,
432  ublas_short_vec1, ublas_short_vec2, ublas_slice_vec2, ublas_slice_vec2,
433  vcl_short_vec1, vcl_short_vec2, vcl_slice_vec3, vcl_slice_vec4);
434  if (retval != EXIT_SUCCESS)
435  return EXIT_FAILURE;
436 
437  std::cout << " ** [vector|slice|vector|vector] **" << std::endl;
438  retval = test<NumericT>(epsilon,
439  ublas_short_vec1, ublas_slice_vec2, ublas_short_vec2, ublas_short_vec2,
440  vcl_short_vec1, vcl_slice_vec2, vcl_short_vec3, vcl_short_vec4);
441  if (retval != EXIT_SUCCESS)
442  return EXIT_FAILURE;
443 
444  std::cout << " ** [vector|slice|vector|slice] **" << std::endl;
445  retval = test<NumericT>(epsilon,
446  ublas_short_vec1, ublas_slice_vec2, ublas_short_vec2, ublas_slice_vec2,
447  vcl_short_vec1, vcl_slice_vec2, vcl_short_vec3, vcl_slice_vec4);
448  if (retval != EXIT_SUCCESS)
449  return EXIT_FAILURE;
450 
451  std::cout << " ** [vector|slice|slice|vector] **" << std::endl;
452  retval = test<NumericT>(epsilon,
453  ublas_short_vec1, ublas_slice_vec2, ublas_slice_vec2, ublas_short_vec2,
454  vcl_short_vec1, vcl_slice_vec2, vcl_slice_vec3, vcl_short_vec4);
455  if (retval != EXIT_SUCCESS)
456  return EXIT_FAILURE;
457 
458  std::cout << " ** [vector|slice|slice|slice] **" << std::endl;
459  retval = test<NumericT>(epsilon,
460  ublas_short_vec1, ublas_slice_vec2, ublas_slice_vec2, ublas_slice_vec2,
461  vcl_short_vec1, vcl_slice_vec2, vcl_slice_vec3, vcl_slice_vec4);
462  if (retval != EXIT_SUCCESS)
463  return EXIT_FAILURE;
464 
465 
467 
468 
469  std::cout << " ** [slice|vector|vector|vector] **" << std::endl;
470  retval = test<NumericT>(epsilon,
471  ublas_slice_vec1, ublas_short_vec2, ublas_short_vec2, ublas_short_vec2,
472  vcl_slice_vec1, vcl_short_vec2, vcl_short_vec3, vcl_short_vec4);
473  if (retval != EXIT_SUCCESS)
474  return EXIT_FAILURE;
475 
476  std::cout << " ** [slice|vector|vector|slice] **" << std::endl;
477  retval = test<NumericT>(epsilon,
478  ublas_slice_vec1, ublas_short_vec2, ublas_short_vec2, ublas_slice_vec2,
479  vcl_slice_vec1, vcl_short_vec2, vcl_short_vec3, vcl_slice_vec4);
480  if (retval != EXIT_SUCCESS)
481  return EXIT_FAILURE;
482 
483  std::cout << " ** [slice|vector|slice|vector] **" << std::endl;
484  retval = test<NumericT>(epsilon,
485  ublas_slice_vec1, ublas_short_vec2, ublas_slice_vec2, ublas_short_vec2,
486  vcl_slice_vec1, vcl_short_vec2, vcl_slice_vec3, vcl_short_vec4);
487  if (retval != EXIT_SUCCESS)
488  return EXIT_FAILURE;
489 
490  std::cout << " ** [slice|vector|slice|slice] **" << std::endl;
491  retval = test<NumericT>(epsilon,
492  ublas_slice_vec1, ublas_short_vec2, ublas_slice_vec2, ublas_slice_vec2,
493  vcl_slice_vec1, vcl_short_vec2, vcl_slice_vec3, vcl_slice_vec4);
494  if (retval != EXIT_SUCCESS)
495  return EXIT_FAILURE;
496 
497  std::cout << " ** [slice|slice|vector|vector] **" << std::endl;
498  retval = test<NumericT>(epsilon,
499  ublas_slice_vec1, ublas_slice_vec2, ublas_short_vec2, ublas_short_vec2,
500  vcl_slice_vec1, vcl_slice_vec2, vcl_short_vec3, vcl_short_vec4);
501  if (retval != EXIT_SUCCESS)
502  return EXIT_FAILURE;
503 
504  std::cout << " ** [slice|slice|vector|slice] **" << std::endl;
505  retval = test<NumericT>(epsilon,
506  ublas_slice_vec1, ublas_slice_vec2, ublas_short_vec2, ublas_slice_vec2,
507  vcl_slice_vec1, vcl_slice_vec2, vcl_short_vec3, vcl_slice_vec4);
508  if (retval != EXIT_SUCCESS)
509  return EXIT_FAILURE;
510 
511  std::cout << " ** [slice|slice|slice|vector] **" << std::endl;
512  retval = test<NumericT>(epsilon,
513  ublas_slice_vec1, ublas_slice_vec2, ublas_slice_vec2, ublas_short_vec2,
514  vcl_slice_vec1, vcl_slice_vec2, vcl_slice_vec3, vcl_short_vec4);
515  if (retval != EXIT_SUCCESS)
516  return EXIT_FAILURE;
517 
518  std::cout << " ** [slice|slice|slice|slice] **" << std::endl;
519  retval = test<NumericT>(epsilon,
520  ublas_slice_vec1, ublas_slice_vec2, ublas_slice_vec2, ublas_slice_vec2,
521  vcl_slice_vec1, vcl_slice_vec2, vcl_slice_vec3, vcl_slice_vec4);
522  if (retval != EXIT_SUCCESS)
523  return EXIT_FAILURE;
524 
525  return EXIT_SUCCESS;
526 }
527 
528 
529 
530 //
531 // -------------------------------------------------------------
532 //
533 int main()
534 {
535  std::cout << std::endl;
536  std::cout << "----------------------------------------------" << std::endl;
537  std::cout << "----------------------------------------------" << std::endl;
538  std::cout << "## Test :: Vector multiple inner products" << std::endl;
539  std::cout << "----------------------------------------------" << std::endl;
540  std::cout << "----------------------------------------------" << std::endl;
541  std::cout << std::endl;
542 
543  int retval = EXIT_SUCCESS;
544 
545  std::cout << std::endl;
546  std::cout << "----------------------------------------------" << std::endl;
547  std::cout << std::endl;
548  {
549  typedef float NumericT;
550  NumericT epsilon = static_cast<NumericT>(1.0E-4);
551  std::cout << "# Testing setup:" << std::endl;
552  std::cout << " eps: " << epsilon << std::endl;
553  std::cout << " numeric: float" << std::endl;
554  retval = test<NumericT>(epsilon);
555  if ( retval == EXIT_SUCCESS )
556  std::cout << "# Test passed" << std::endl;
557  else
558  return retval;
559  }
560  std::cout << std::endl;
561  std::cout << "----------------------------------------------" << std::endl;
562  std::cout << std::endl;
563 #ifdef VIENNACL_WITH_OPENCL
565 #endif
566  {
567  {
568  typedef double NumericT;
569  NumericT epsilon = 1.0E-12;
570  std::cout << "# Testing setup:" << std::endl;
571  std::cout << " eps: " << epsilon << std::endl;
572  std::cout << " numeric: double" << std::endl;
573  retval = test<NumericT>(epsilon);
574  if ( retval == EXIT_SUCCESS )
575  std::cout << "# Test passed" << std::endl;
576  else
577  return retval;
578  }
579  std::cout << std::endl;
580  std::cout << "----------------------------------------------" << std::endl;
581  std::cout << std::endl;
582  }
583 
584  std::cout << std::endl;
585  std::cout << "------- Test completed --------" << std::endl;
586  std::cout << std::endl;
587 
588 
589  return retval;
590 }
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:226
Generic interface for the l^2-norm. See viennacl/linalg/vector_operations.hpp for implementations...
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
Definition: memory.hpp:54
viennacl::enable_if< viennacl::is_stl< typename viennacl::traits::tag_of< VectorT1 >::type >::value, typename VectorT1::value_type >::type inner_prod(VectorT1 const &v1, VectorT2 const &v2)
Definition: inner_prod.hpp:89
viennacl::scalar< int > s2
viennacl::scalar< float > s1
T max(const T &lhs, const T &rhs)
Maximum.
Definition: util.hpp:59
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context.
Definition: backend.hpp:351
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...
viennacl::vector< float > v1
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
int test(Epsilon const &epsilon, UblasVectorType1 &ublas_v1, UblasVectorType2 &ublas_v2, UblasVectorType3 &ublas_v3, UblasVectorType4 &ublas_v4, ViennaCLVectorType1 &vcl_v1, ViennaCLVectorType2 &vcl_v2, ViennaCLVectorType3 &vcl_v3, ViennaCLVectorType4 &vcl_v4)
Tuple class holding pointers to multiple vectors. Mainly used as a temporary object returned from vie...
Definition: forwards.h:268
Class for representing strided subvectors of a bigger vector x.
Definition: forwards.h:436
bool double_support() const
ViennaCL convenience function: Returns true if the device supports double precision.
Definition: device.hpp:956
matrix_range< MatrixType > project(MatrixType const &A, viennacl::range const &r1, viennacl::range const &r2)
vector_tuple< ScalarT > tie(vector_base< ScalarT > const &v0, vector_base< ScalarT > const &v1)
Definition: vector.hpp:1141
Proxy classes for vectors.
basic_slice slice
Definition: forwards.h:428
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
Definition: vector_def.hpp:87
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) ...
float ScalarType
Definition: fft_1d.cpp:42
ScalarType diff(ScalarType const &s1, ScalarType const &s2)
int check(T1 const &t1, T2 const &t2, double epsilon)
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:428
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
Definition: forwards.h:232
Generic interface for the l^infty-norm. See viennacl/linalg/vector_operations.hpp for implementations...
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)