ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
vector_multi_inner_prod.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 
50 using namespace boost::numeric;
51 
52 
53 //
54 // -------------------------------------------------------------
55 //
56 template<typename ScalarType>
58 {
60  if (s1 != s2)
61  return (s1 - s2) / std::max(std::fabs(s1), std::fabs(s2));
62  return 0;
63 }
64 //
65 // -------------------------------------------------------------
66 //
67 template<typename ScalarType>
69 {
71  if (s1 != s2)
72  return (s1 - s2) / std::max(std::fabs(s1), std::fabs(s2));
73  return 0;
74 }
75 //
76 // -------------------------------------------------------------
77 //
78 template<typename ScalarType>
80 {
82  if (s1 != s2)
83  return (s1 - s2) / std::max(std::fabs(s1), std::fabs(s2));
84  return 0;
85 }
86 //
87 // -------------------------------------------------------------
88 //
89 template<typename ScalarType, typename ViennaCLVectorType>
90 ScalarType diff(ublas::vector<ScalarType> const & v1, ViennaCLVectorType const & vcl_vec)
91 {
92  ublas::vector<ScalarType> v2_cpu(vcl_vec.size());
94  viennacl::copy(vcl_vec, v2_cpu);
95 
96  for (unsigned int i=0;i<v1.size(); ++i)
97  {
98  if ( std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 )
99  v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) / std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) );
100  else
101  v2_cpu[i] = 0.0;
102  }
103 
104  return ublas::norm_inf(v2_cpu);
105 }
106 
107 template<typename ScalarType, typename ViennaCLVectorType>
108 ScalarType diff(ublas::vector_slice<ublas::vector<ScalarType> > const & v1, ViennaCLVectorType const & vcl_vec)
109 {
110  ublas::vector<ScalarType> v2_cpu(vcl_vec.size());
112  viennacl::copy(vcl_vec, v2_cpu);
113 
114  for (unsigned int i=0;i<v1.size(); ++i)
115  {
116  if ( std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) ) > 0 )
117  v2_cpu[i] = std::fabs(v2_cpu[i] - v1[i]) / std::max( std::fabs(v2_cpu[i]), std::fabs(v1[i]) );
118  else
119  v2_cpu[i] = 0.0;
120  }
121 
122  return ublas::norm_inf(v2_cpu);
123 }
124 
125 
126 template<typename T1, typename T2>
127 int check(T1 const & t1, T2 const & t2, double epsilon)
128 {
129  int retval = EXIT_SUCCESS;
130 
131  double temp = std::fabs(diff(t1, t2));
132  if (temp > epsilon)
133  {
134  std::cout << "# Error! Relative difference: " << temp << std::endl;
135  retval = EXIT_FAILURE;
136  }
137  return retval;
138 }
139 
140 
141 //
142 // -------------------------------------------------------------
143 //
144 template< typename NumericT, typename Epsilon,
145  typename UblasVectorType1, typename UblasVectorType2, typename UblasVectorType3, typename UblasVectorType4,
146  typename ViennaCLVectorType1, typename ViennaCLVectorType2, typename ViennaCLVectorType3, typename ViennaCLVectorType4 >
147 int test(Epsilon const& epsilon,
148  UblasVectorType1 & ublas_v1, UblasVectorType2 & ublas_v2, UblasVectorType3 & ublas_v3, UblasVectorType4 & ublas_v4,
149  ViennaCLVectorType1 & vcl_v1, ViennaCLVectorType2 & vcl_v2, ViennaCLVectorType3 & vcl_v3, ViennaCLVectorType4 & vcl_v4)
150 {
151  int retval = EXIT_SUCCESS;
152 
154 
155  for (std::size_t i=0; i<ublas_v1.size(); ++i)
156  {
157  ublas_v1[i] = NumericT(1.0) + randomNumber();
158  ublas_v2[i] = NumericT(1.0) + randomNumber();
159  ublas_v3[i] = NumericT(1.0) + randomNumber();
160  ublas_v4[i] = NumericT(1.0) + randomNumber();
161  }
162 
163  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin()); //resync
164  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
165  viennacl::copy(ublas_v3.begin(), ublas_v3.end(), vcl_v3.begin());
166  viennacl::copy(ublas_v4.begin(), ublas_v4.end(), vcl_v4.begin());
167 
168  std::cout << "Checking for successful copy..." << std::endl;
169  if (check(ublas_v1, vcl_v1, epsilon) != EXIT_SUCCESS)
170  return EXIT_FAILURE;
171  if (check(ublas_v2, vcl_v2, epsilon) != EXIT_SUCCESS)
172  return EXIT_FAILURE;
173  if (check(ublas_v3, vcl_v3, epsilon) != EXIT_SUCCESS)
174  return EXIT_FAILURE;
175  if (check(ublas_v4, vcl_v4, epsilon) != EXIT_SUCCESS)
176  return EXIT_FAILURE;
177 
178  ublas::vector<NumericT> ref_result = ublas::scalar_vector<NumericT>(40, 0.0);
180 
181  std::cout << "Testing inner_prod with two vectors..." << std::endl;
182  ref_result(2) = ublas::inner_prod(ublas_v1, ublas_v1);
183  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v2);
184  viennacl::project(result, viennacl::slice(2, 3, 2)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v1, vcl_v2));
185  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
186  {
187  std::cout << ref_result << std::endl;
188  std::cout << result << std::endl;
189  return EXIT_FAILURE;
190  }
191 
192  ref_result(3) = ublas::inner_prod(ublas_v1, ublas_v3);
193  ref_result(7) = ublas::inner_prod(ublas_v1, ublas_v4);
194  viennacl::project(result, viennacl::slice(3, 4, 2)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v3, vcl_v4));
195  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
196  {
197  std::cout << ref_result << std::endl;
198  std::cout << result << std::endl;
199  return EXIT_FAILURE;
200  }
201 
202 
203  std::cout << "Testing inner_prod with three vectors..." << std::endl;
204  ref_result(1) = ublas::inner_prod(ublas_v1, ublas_v1);
205  ref_result(3) = ublas::inner_prod(ublas_v1, ublas_v2);
206  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v3);
207  viennacl::project(result, viennacl::slice(1, 2, 3)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v1, vcl_v2, vcl_v3));
208  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
209  {
210  std::cout << ref_result << std::endl;
211  std::cout << result << std::endl;
212  return EXIT_FAILURE;
213  }
214 
215  ref_result(2) = ublas::inner_prod(ublas_v1, ublas_v3);
216  ref_result(6) = ublas::inner_prod(ublas_v1, ublas_v2);
217  ref_result(10) = ublas::inner_prod(ublas_v1, ublas_v4);
218  viennacl::project(result, viennacl::slice(2, 4, 3)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v3, vcl_v2, vcl_v4));
219  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
220  {
221  std::cout << ref_result << std::endl;
222  std::cout << result << std::endl;
223  return EXIT_FAILURE;
224  }
225 
226  std::cout << "Testing inner_prod with four vectors..." << std::endl;
227  ref_result(4) = ublas::inner_prod(ublas_v1, ublas_v1);
228  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v2);
229  ref_result(6) = ublas::inner_prod(ublas_v1, ublas_v3);
230  ref_result(7) = ublas::inner_prod(ublas_v1, ublas_v4);
231  viennacl::project(result, viennacl::slice(4, 1, 4)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v1, vcl_v2, vcl_v3, vcl_v4));
232  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
233  {
234  std::cout << ref_result << std::endl;
235  std::cout << result << std::endl;
236  return EXIT_FAILURE;
237  }
238 
239  ref_result(3) = ublas::inner_prod(ublas_v1, ublas_v3);
240  ref_result(6) = ublas::inner_prod(ublas_v1, ublas_v2);
241  ref_result(9) = ublas::inner_prod(ublas_v1, ublas_v4);
242  ref_result(12) = ublas::inner_prod(ublas_v1, ublas_v1);
243  viennacl::project(result, viennacl::slice(3, 3, 4)) = viennacl::linalg::inner_prod(vcl_v1, viennacl::tie(vcl_v3, vcl_v2, vcl_v4, vcl_v1));
244  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
245  {
246  std::cout << ref_result << std::endl;
247  std::cout << result << std::endl;
248  return EXIT_FAILURE;
249  }
250 
251  std::cout << "Testing inner_prod with five vectors..." << std::endl;
252  ref_result(1) = ublas::inner_prod(ublas_v1, ublas_v1);
253  ref_result(3) = ublas::inner_prod(ublas_v1, ublas_v2);
254  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v3);
255  ref_result(7) = ublas::inner_prod(ublas_v1, ublas_v4);
256  ref_result(9) = ublas::inner_prod(ublas_v1, ublas_v2);
257  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));
258  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
259  {
260  std::cout << ref_result << std::endl;
261  std::cout << result << std::endl;
262  return EXIT_FAILURE;
263  }
264 
265  ref_result(2) = ublas::inner_prod(ublas_v1, ublas_v3);
266  ref_result(4) = ublas::inner_prod(ublas_v1, ublas_v2);
267  ref_result(6) = ublas::inner_prod(ublas_v1, ublas_v4);
268  ref_result(8) = ublas::inner_prod(ublas_v1, ublas_v1);
269  ref_result(10) = ublas::inner_prod(ublas_v1, ublas_v2);
270  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));
271  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
272  {
273  std::cout << ref_result << std::endl;
274  std::cout << result << std::endl;
275  return EXIT_FAILURE;
276  }
277 
278 
279  std::cout << "Testing inner_prod with eight vectors..." << std::endl;
280  ref_result(1) = ublas::inner_prod(ublas_v1, ublas_v1);
281  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v2);
282  ref_result(9) = ublas::inner_prod(ublas_v1, ublas_v3);
283  ref_result(13) = ublas::inner_prod(ublas_v1, ublas_v4);
284  ref_result(17) = ublas::inner_prod(ublas_v1, ublas_v3);
285  ref_result(21) = ublas::inner_prod(ublas_v1, ublas_v2);
286  ref_result(25) = ublas::inner_prod(ublas_v1, ublas_v1);
287  ref_result(29) = ublas::inner_prod(ublas_v1, ublas_v2);
288  std::vector<viennacl::vector_base<NumericT> const *> vecs1(8);
289  vecs1[0] = &vcl_v1;
290  vecs1[1] = &vcl_v2;
291  vecs1[2] = &vcl_v3;
292  vecs1[3] = &vcl_v4;
293  vecs1[4] = &vcl_v3;
294  vecs1[5] = &vcl_v2;
295  vecs1[6] = &vcl_v1;
296  vecs1[7] = &vcl_v2;
297  viennacl::vector_tuple<NumericT> tuple1(vecs1);
298  viennacl::project(result, viennacl::slice(1, 4, 8)) = viennacl::linalg::inner_prod(vcl_v1, tuple1);
299  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
300  {
301  std::cout << ref_result << std::endl;
302  std::cout << result << std::endl;
303  return EXIT_FAILURE;
304  }
305 
306  ref_result(3) = ublas::inner_prod(ublas_v1, ublas_v2);
307  ref_result(5) = ublas::inner_prod(ublas_v1, ublas_v4);
308  ref_result(7) = ublas::inner_prod(ublas_v1, ublas_v1);
309  ref_result(9) = ublas::inner_prod(ublas_v1, ublas_v2);
310  ref_result(11) = ublas::inner_prod(ublas_v1, ublas_v2);
311  ref_result(13) = ublas::inner_prod(ublas_v1, ublas_v1);
312  ref_result(15) = ublas::inner_prod(ublas_v1, ublas_v4);
313  ref_result(17) = ublas::inner_prod(ublas_v1, ublas_v2);
314  std::vector<viennacl::vector_base<NumericT> const *> vecs2(8);
315  vecs2[0] = &vcl_v2;
316  vecs2[1] = &vcl_v4;
317  vecs2[2] = &vcl_v1;
318  vecs2[3] = &vcl_v2;
319  vecs2[4] = &vcl_v2;
320  vecs2[5] = &vcl_v1;
321  vecs2[6] = &vcl_v4;
322  vecs2[7] = &vcl_v2;
323  viennacl::vector_tuple<NumericT> tuple2(vecs2);
324  viennacl::project(result, viennacl::slice(3, 2, 8)) = viennacl::linalg::inner_prod(vcl_v1, tuple2);
325  if (check(ref_result, result, epsilon) != EXIT_SUCCESS)
326  {
327  std::cout << ref_result << std::endl;
328  std::cout << result << std::endl;
329  return EXIT_FAILURE;
330  }
331 
332 
333  // --------------------------------------------------------------------------
334  return retval;
335 }
336 
337 
338 template< typename NumericT, typename Epsilon >
339 int test(Epsilon const& epsilon)
340 {
342 
343  int retval = EXIT_SUCCESS;
344  std::size_t size = 8 * 1337;
345 
346  std::cout << "Running tests for vector of size " << size << std::endl;
347 
348  //
349  // Set up UBLAS objects
350  //
351  ublas::vector<NumericT> ublas_full_vec1(size);
352  ublas::vector<NumericT> ublas_full_vec2(ublas_full_vec1.size());
353 
354  for (std::size_t i=0; i<ublas_full_vec1.size(); ++i)
355  {
356  ublas_full_vec1[i] = NumericT(1.0) + randomNumber();
357  ublas_full_vec2[i] = NumericT(1.0) + randomNumber();
358  }
359 
360  ublas::slice s1( ublas_full_vec1.size() / 8, 3, ublas_full_vec1.size() / 8);
361  ublas::slice s2(2 * ublas_full_vec2.size() / 8, 1, ublas_full_vec2.size() / 8);
362  ublas::slice s3(4 * ublas_full_vec1.size() / 8, 2, ublas_full_vec1.size() / 8);
363  ublas::slice s4(3 * ublas_full_vec2.size() / 8, 4, ublas_full_vec2.size() / 8);
364  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec1(ublas_full_vec1, s1);
365  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec2(ublas_full_vec2, s2);
366  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec3(ublas_full_vec1, s3);
367  ublas::vector_slice< ublas::vector<NumericT> > ublas_slice_vec4(ublas_full_vec2, s4);
368 
369  //
370  // Set up ViennaCL objects
371  //
372  viennacl::vector<NumericT> vcl_full_vec1(ublas_full_vec1.size());
373  viennacl::vector<NumericT> vcl_full_vec2(ublas_full_vec2.size());
374 
375  viennacl::fast_copy(ublas_full_vec1.begin(), ublas_full_vec1.end(), vcl_full_vec1.begin());
376  viennacl::copy (ublas_full_vec2.begin(), ublas_full_vec2.end(), vcl_full_vec2.begin());
377 
378  viennacl::slice vcl_s1( vcl_full_vec1.size() / 8, 3, vcl_full_vec1.size() / 8);
379  viennacl::slice vcl_s2(2 * vcl_full_vec2.size() / 8, 1, vcl_full_vec2.size() / 8);
380  viennacl::slice vcl_s3(4 * vcl_full_vec1.size() / 8, 2, vcl_full_vec1.size() / 8);
381  viennacl::slice vcl_s4(3 * vcl_full_vec2.size() / 8, 4, vcl_full_vec2.size() / 8);
382  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec1(vcl_full_vec1, vcl_s1);
383  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec2(vcl_full_vec2, vcl_s2);
384  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec3(vcl_full_vec1, vcl_s3);
385  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_slice_vec4(vcl_full_vec2, vcl_s4);
386 
387  viennacl::vector<NumericT> vcl_short_vec1(vcl_slice_vec1);
388  viennacl::vector<NumericT> vcl_short_vec2 = vcl_slice_vec2;
389  viennacl::vector<NumericT> vcl_short_vec3 = vcl_slice_vec2 + vcl_slice_vec1;
390  viennacl::vector<NumericT> vcl_short_vec4 = vcl_short_vec1 + vcl_slice_vec2;
391 
392  ublas::vector<NumericT> ublas_short_vec1(ublas_slice_vec1);
393  ublas::vector<NumericT> ublas_short_vec2(ublas_slice_vec2);
394  ublas::vector<NumericT> ublas_short_vec3 = ublas_slice_vec2 + ublas_slice_vec1;
395  ublas::vector<NumericT> ublas_short_vec4 = ublas_short_vec1 + ublas_slice_vec2;
396 
397  std::cout << "Testing creation of vectors from slice..." << std::endl;
398  if (check(ublas_short_vec1, vcl_short_vec1, epsilon) != EXIT_SUCCESS)
399  return EXIT_FAILURE;
400  if (check(ublas_short_vec2, vcl_short_vec2, epsilon) != EXIT_SUCCESS)
401  return EXIT_FAILURE;
402  if (check(ublas_short_vec3, vcl_short_vec3, epsilon) != EXIT_SUCCESS)
403  return EXIT_FAILURE;
404  if (check(ublas_short_vec4, vcl_short_vec4, epsilon) != EXIT_SUCCESS)
405  return EXIT_FAILURE;
406 
407 
408  //
409  // Now start running tests for vectors, ranges and slices:
410  //
411 
412  std::cout << " ** [vector|vector|vector|vector] **" << std::endl;
413  retval = test<NumericT>(epsilon,
414  ublas_short_vec1, ublas_short_vec2, ublas_short_vec2, ublas_short_vec2,
415  vcl_short_vec1, vcl_short_vec2, vcl_short_vec3, vcl_short_vec4);
416  if (retval != EXIT_SUCCESS)
417  return EXIT_FAILURE;
418 
419  std::cout << " ** [vector|vector|vector|slice] **" << std::endl;
420  retval = test<NumericT>(epsilon,
421  ublas_short_vec1, ublas_short_vec2, ublas_short_vec2, ublas_slice_vec2,
422  vcl_short_vec1, vcl_short_vec2, vcl_short_vec3, vcl_slice_vec4);
423  if (retval != EXIT_SUCCESS)
424  return EXIT_FAILURE;
425 
426  std::cout << " ** [vector|vector|slice|vector] **" << std::endl;
427  retval = test<NumericT>(epsilon,
428  ublas_short_vec1, ublas_short_vec2, ublas_slice_vec2, ublas_short_vec2,
429  vcl_short_vec1, vcl_short_vec2, vcl_slice_vec3, vcl_short_vec4);
430  if (retval != EXIT_SUCCESS)
431  return EXIT_FAILURE;
432 
433  std::cout << " ** [vector|vector|slice|slice] **" << std::endl;
434  retval = test<NumericT>(epsilon,
435  ublas_short_vec1, ublas_short_vec2, ublas_slice_vec2, ublas_slice_vec2,
436  vcl_short_vec1, vcl_short_vec2, vcl_slice_vec3, vcl_slice_vec4);
437  if (retval != EXIT_SUCCESS)
438  return EXIT_FAILURE;
439 
440  std::cout << " ** [vector|slice|vector|vector] **" << std::endl;
441  retval = test<NumericT>(epsilon,
442  ublas_short_vec1, ublas_slice_vec2, ublas_short_vec2, ublas_short_vec2,
443  vcl_short_vec1, vcl_slice_vec2, vcl_short_vec3, vcl_short_vec4);
444  if (retval != EXIT_SUCCESS)
445  return EXIT_FAILURE;
446 
447  std::cout << " ** [vector|slice|vector|slice] **" << std::endl;
448  retval = test<NumericT>(epsilon,
449  ublas_short_vec1, ublas_slice_vec2, ublas_short_vec2, ublas_slice_vec2,
450  vcl_short_vec1, vcl_slice_vec2, vcl_short_vec3, vcl_slice_vec4);
451  if (retval != EXIT_SUCCESS)
452  return EXIT_FAILURE;
453 
454  std::cout << " ** [vector|slice|slice|vector] **" << std::endl;
455  retval = test<NumericT>(epsilon,
456  ublas_short_vec1, ublas_slice_vec2, ublas_slice_vec2, ublas_short_vec2,
457  vcl_short_vec1, vcl_slice_vec2, vcl_slice_vec3, vcl_short_vec4);
458  if (retval != EXIT_SUCCESS)
459  return EXIT_FAILURE;
460 
461  std::cout << " ** [vector|slice|slice|slice] **" << std::endl;
462  retval = test<NumericT>(epsilon,
463  ublas_short_vec1, ublas_slice_vec2, ublas_slice_vec2, ublas_slice_vec2,
464  vcl_short_vec1, vcl_slice_vec2, vcl_slice_vec3, vcl_slice_vec4);
465  if (retval != EXIT_SUCCESS)
466  return EXIT_FAILURE;
467 
468 
470 
471 
472  std::cout << " ** [slice|vector|vector|vector] **" << std::endl;
473  retval = test<NumericT>(epsilon,
474  ublas_slice_vec1, ublas_short_vec2, ublas_short_vec2, ublas_short_vec2,
475  vcl_slice_vec1, vcl_short_vec2, vcl_short_vec3, vcl_short_vec4);
476  if (retval != EXIT_SUCCESS)
477  return EXIT_FAILURE;
478 
479  std::cout << " ** [slice|vector|vector|slice] **" << std::endl;
480  retval = test<NumericT>(epsilon,
481  ublas_slice_vec1, ublas_short_vec2, ublas_short_vec2, ublas_slice_vec2,
482  vcl_slice_vec1, vcl_short_vec2, vcl_short_vec3, vcl_slice_vec4);
483  if (retval != EXIT_SUCCESS)
484  return EXIT_FAILURE;
485 
486  std::cout << " ** [slice|vector|slice|vector] **" << std::endl;
487  retval = test<NumericT>(epsilon,
488  ublas_slice_vec1, ublas_short_vec2, ublas_slice_vec2, ublas_short_vec2,
489  vcl_slice_vec1, vcl_short_vec2, vcl_slice_vec3, vcl_short_vec4);
490  if (retval != EXIT_SUCCESS)
491  return EXIT_FAILURE;
492 
493  std::cout << " ** [slice|vector|slice|slice] **" << std::endl;
494  retval = test<NumericT>(epsilon,
495  ublas_slice_vec1, ublas_short_vec2, ublas_slice_vec2, ublas_slice_vec2,
496  vcl_slice_vec1, vcl_short_vec2, vcl_slice_vec3, vcl_slice_vec4);
497  if (retval != EXIT_SUCCESS)
498  return EXIT_FAILURE;
499 
500  std::cout << " ** [slice|slice|vector|vector] **" << std::endl;
501  retval = test<NumericT>(epsilon,
502  ublas_slice_vec1, ublas_slice_vec2, ublas_short_vec2, ublas_short_vec2,
503  vcl_slice_vec1, vcl_slice_vec2, vcl_short_vec3, vcl_short_vec4);
504  if (retval != EXIT_SUCCESS)
505  return EXIT_FAILURE;
506 
507  std::cout << " ** [slice|slice|vector|slice] **" << std::endl;
508  retval = test<NumericT>(epsilon,
509  ublas_slice_vec1, ublas_slice_vec2, ublas_short_vec2, ublas_slice_vec2,
510  vcl_slice_vec1, vcl_slice_vec2, vcl_short_vec3, vcl_slice_vec4);
511  if (retval != EXIT_SUCCESS)
512  return EXIT_FAILURE;
513 
514  std::cout << " ** [slice|slice|slice|vector] **" << std::endl;
515  retval = test<NumericT>(epsilon,
516  ublas_slice_vec1, ublas_slice_vec2, ublas_slice_vec2, ublas_short_vec2,
517  vcl_slice_vec1, vcl_slice_vec2, vcl_slice_vec3, vcl_short_vec4);
518  if (retval != EXIT_SUCCESS)
519  return EXIT_FAILURE;
520 
521  std::cout << " ** [slice|slice|slice|slice] **" << std::endl;
522  retval = test<NumericT>(epsilon,
523  ublas_slice_vec1, ublas_slice_vec2, ublas_slice_vec2, ublas_slice_vec2,
524  vcl_slice_vec1, vcl_slice_vec2, vcl_slice_vec3, vcl_slice_vec4);
525  if (retval != EXIT_SUCCESS)
526  return EXIT_FAILURE;
527 
528  return EXIT_SUCCESS;
529 }
530 
531 
532 
533 //
534 // -------------------------------------------------------------
535 //
536 int main()
537 {
538  std::cout << std::endl;
539  std::cout << "----------------------------------------------" << std::endl;
540  std::cout << "----------------------------------------------" << std::endl;
541  std::cout << "## Test :: Vector multiple inner products" << std::endl;
542  std::cout << "----------------------------------------------" << std::endl;
543  std::cout << "----------------------------------------------" << std::endl;
544  std::cout << std::endl;
545 
546  int retval = EXIT_SUCCESS;
547 
548  std::cout << std::endl;
549  std::cout << "----------------------------------------------" << std::endl;
550  std::cout << std::endl;
551  {
552  typedef float NumericT;
553  NumericT epsilon = static_cast<NumericT>(1.0E-4);
554  std::cout << "# Testing setup:" << std::endl;
555  std::cout << " eps: " << epsilon << std::endl;
556  std::cout << " numeric: float" << std::endl;
557  retval = test<NumericT>(epsilon);
558  if ( retval == EXIT_SUCCESS )
559  std::cout << "# Test passed" << std::endl;
560  else
561  return retval;
562  }
563  std::cout << std::endl;
564  std::cout << "----------------------------------------------" << std::endl;
565  std::cout << std::endl;
566 #ifdef VIENNACL_WITH_OPENCL
568 #endif
569  {
570  {
571  typedef double NumericT;
572  NumericT epsilon = 1.0E-12;
573  std::cout << "# Testing setup:" << std::endl;
574  std::cout << " eps: " << epsilon << std::endl;
575  std::cout << " numeric: double" << std::endl;
576  retval = test<NumericT>(epsilon);
577  if ( retval == EXIT_SUCCESS )
578  std::cout << "# Test passed" << std::endl;
579  else
580  return retval;
581  }
582  std::cout << std::endl;
583  std::cout << "----------------------------------------------" << std::endl;
584  std::cout << std::endl;
585  }
586 
587  std::cout << std::endl;
588  std::cout << "------- Test completed --------" << std::endl;
589  std::cout << std::endl;
590 
591 
592  return retval;
593 }
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...
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
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...
float NumericT
Definition: bisect.cpp:40
viennacl::vector< float > v1
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:235
Random number generator for returning uniformly distributed values in the closed interval [0...
Definition: random.hpp:44
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:269
Class for representing strided subvectors of a bigger vector x.
Definition: forwards.h:437
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:1155
Proxy classes for vectors.
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
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) ...
A small collection of sequential random number generators.
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: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...
void fast_copy(const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_begin, const const_vector_iterator< SCALARTYPE, ALIGNMENT > &gpu_end, CPU_ITERATOR cpu_begin)