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
matrix_vector_int.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 
23 //
24 // *** System
25 //
26 #include <iostream>
27 
28 //
29 // *** Boost
30 //
31 #include <boost/numeric/ublas/io.hpp>
32 #include <boost/numeric/ublas/triangular.hpp>
33 #include <boost/numeric/ublas/matrix_sparse.hpp>
34 #include <boost/numeric/ublas/matrix.hpp>
35 #include <boost/numeric/ublas/matrix_proxy.hpp>
36 #include <boost/numeric/ublas/lu.hpp>
37 #include <boost/numeric/ublas/io.hpp>
38 
39 //
40 // *** ViennaCL
41 //
42 //#define VIENNACL_DEBUG_ALL
43 #define VIENNACL_WITH_UBLAS 1
44 #include "viennacl/scalar.hpp"
45 #include "viennacl/matrix.hpp"
46 #include "viennacl/vector.hpp"
47 #include "viennacl/linalg/prod.hpp"
50 #include "viennacl/linalg/lu.hpp"
52 
53 //
54 // -------------------------------------------------------------
55 //
56 using namespace boost::numeric;
57 //
58 // -------------------------------------------------------------
59 //
60 template<typename ScalarType>
62 {
64  if (s1 != s2)
65  return 1;
66  return 0;
67 }
68 
69 template<typename ScalarType, typename VCLVectorType>
70 ScalarType diff(ublas::vector<ScalarType> const & v1, VCLVectorType const & v2)
71 {
72  ublas::vector<ScalarType> v2_cpu(v2.size());
73  viennacl::backend::finish(); //workaround for a bug in APP SDK 2.7 on Trinity APUs (with Catalyst 12.8)
74  viennacl::copy(v2.begin(), v2.end(), v2_cpu.begin());
75 
76  for (unsigned int i=0;i<v1.size(); ++i)
77  {
78  if (v2_cpu[i] != v1[i])
79  return 1;
80  }
81 
82  return 0;
83 }
84 
85 template<typename ScalarType, typename VCLMatrixType>
86 ScalarType diff(ublas::matrix<ScalarType> const & mat1, VCLMatrixType const & mat2)
87 {
88  ublas::matrix<ScalarType> mat2_cpu(mat2.size1(), mat2.size2());
89  viennacl::backend::finish(); //workaround for a bug in APP SDK 2.7 on Trinity APUs (with Catalyst 12.8)
90  viennacl::copy(mat2, mat2_cpu);
91 
92  for (unsigned int i = 0; i < mat2_cpu.size1(); ++i)
93  {
94  for (unsigned int j = 0; j < mat2_cpu.size2(); ++j)
95  {
96  if (mat2_cpu(i,j) != mat1(i,j))
97  return 1;
98  }
99  }
100  //std::cout << ret << std::endl;
101  return 0;
102 }
103 //
104 // -------------------------------------------------------------
105 //
106 
107 template<typename NumericT,
108  typename UblasMatrixType, typename UblasVectorType,
109  typename VCLMatrixType, typename VCLVectorType1, typename VCLVectorType2>
110 int test_prod_rank1(UblasMatrixType & ublas_m1, UblasVectorType & ublas_v1, UblasVectorType & ublas_v2,
111  VCLMatrixType & vcl_m1, VCLVectorType1 & vcl_v1, VCLVectorType2 & vcl_v2)
112 {
113  int retval = EXIT_SUCCESS;
114 
115  // sync data:
116  ublas_v1 = ublas::scalar_vector<NumericT>(ublas_v1.size(), NumericT(2));
117  ublas_v2 = ublas::scalar_vector<NumericT>(ublas_v2.size(), NumericT(3));
118  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
119  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
120  viennacl::copy(ublas_m1, vcl_m1);
121 
122  // --------------------------------------------------------------------------
123  std::cout << "Rank 1 update" << std::endl;
124 
125  ublas_m1 += ublas::outer_prod(ublas_v1, ublas_v2);
126  vcl_m1 += viennacl::linalg::outer_prod(vcl_v1, vcl_v2);
127  if ( diff(ublas_m1, vcl_m1) != 0 )
128  {
129  std::cout << "# Error at operation: rank 1 update" << std::endl;
130  std::cout << " diff: " << diff(ublas_m1, vcl_m1) << std::endl;
131  return EXIT_FAILURE;
132  }
133 
134 
135 
136  // --------------------------------------------------------------------------
137  std::cout << "Scaled rank 1 update - CPU Scalar" << std::endl;
138  ublas_m1 += NumericT(4) * ublas::outer_prod(ublas_v1, ublas_v2);
139  vcl_m1 += NumericT(2) * viennacl::linalg::outer_prod(vcl_v1, vcl_v2);
140  vcl_m1 += viennacl::linalg::outer_prod(vcl_v1, vcl_v2) * NumericT(2); //check proper compilation
141  if ( diff(ublas_m1, vcl_m1) != 0 )
142  {
143  std::cout << "# Error at operation: scaled rank 1 update - CPU Scalar" << std::endl;
144  std::cout << " diff: " << diff(ublas_m1, vcl_m1) << std::endl;
145  return EXIT_FAILURE;
146  }
147 
148  // --------------------------------------------------------------------------
149  std::cout << "Scaled rank 1 update - GPU Scalar" << std::endl;
150  ublas_m1 += NumericT(4) * ublas::outer_prod(ublas_v1, ublas_v2);
151  vcl_m1 += viennacl::scalar<NumericT>(2) * viennacl::linalg::outer_prod(vcl_v1, vcl_v2);
152  vcl_m1 += viennacl::linalg::outer_prod(vcl_v1, vcl_v2) * viennacl::scalar<NumericT>(2); //check proper compilation
153  if ( diff(ublas_m1, vcl_m1) != 0 )
154  {
155  std::cout << "# Error at operation: scaled rank 1 update - GPU Scalar" << std::endl;
156  std::cout << " diff: " << diff(ublas_m1, vcl_m1) << std::endl;
157  return EXIT_FAILURE;
158  }
159 
160  //reset vcl_matrix:
161  viennacl::copy(ublas_m1, vcl_m1);
162 
163  // --------------------------------------------------------------------------
164  std::cout << "Matrix-Vector product" << std::endl;
165  ublas_v1 = viennacl::linalg::prod(ublas_m1, ublas_v2);
166  vcl_v1 = viennacl::linalg::prod(vcl_m1, vcl_v2);
167 
168  if ( diff(ublas_v1, vcl_v1) != 0 )
169  {
170  std::cout << "# Error at operation: matrix-vector product" << std::endl;
171  std::cout << " diff: " << diff(ublas_v1, vcl_v1) << std::endl;
172  retval = EXIT_FAILURE;
173  }
174  // --------------------------------------------------------------------------
175  std::cout << "Matrix-Vector product with scaled add" << std::endl;
176  NumericT alpha = static_cast<NumericT>(2);
177  NumericT beta = static_cast<NumericT>(3);
178  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
179  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
180 
181  ublas_v1 = alpha * viennacl::linalg::prod(ublas_m1, ublas_v2) + beta * ublas_v1;
182  vcl_v1 = alpha * viennacl::linalg::prod(vcl_m1, vcl_v2) + beta * vcl_v1;
183 
184  if ( diff(ublas_v1, vcl_v1) != 0 )
185  {
186  std::cout << "# Error at operation: matrix-vector product with scaled additions" << std::endl;
187  std::cout << " diff: " << diff(ublas_v1, vcl_v1) << std::endl;
188  retval = EXIT_FAILURE;
189  }
190  // --------------------------------------------------------------------------
191 
192  viennacl::copy(ublas_v1.begin(), ublas_v1.end(), vcl_v1.begin());
193  viennacl::copy(ublas_v2.begin(), ublas_v2.end(), vcl_v2.begin());
194 
195  std::cout << "Transposed Matrix-Vector product" << std::endl;
196  ublas_v2 = alpha * viennacl::linalg::prod(trans(ublas_m1), ublas_v1);
197  vcl_v2 = alpha * viennacl::linalg::prod(trans(vcl_m1), vcl_v1);
198 
199  if ( diff(ublas_v2, vcl_v2) != 0 )
200  {
201  std::cout << "# Error at operation: transposed matrix-vector product" << std::endl;
202  std::cout << " diff: " << diff(ublas_v2, vcl_v2) << std::endl;
203  retval = EXIT_FAILURE;
204  }
205 
206  std::cout << "Transposed Matrix-Vector product with scaled add" << std::endl;
207  ublas_v2 = alpha * viennacl::linalg::prod(trans(ublas_m1), ublas_v1) + beta * ublas_v2;
208  vcl_v2 = alpha * viennacl::linalg::prod(trans(vcl_m1), vcl_v1) + beta * vcl_v2;
209 
210  if ( diff(ublas_v2, vcl_v2) != 0 )
211  {
212  std::cout << "# Error at operation: transposed matrix-vector product with scaled additions" << std::endl;
213  std::cout << " diff: " << diff(ublas_v2, vcl_v2) << std::endl;
214  retval = EXIT_FAILURE;
215  }
216  // --------------------------------------------------------------------------
217 
218  return retval;
219 }
220 
221 
222 //
223 // -------------------------------------------------------------
224 //
225 template< typename NumericT, typename F>
226 int test()
227 {
228  int retval = EXIT_SUCCESS;
229 
230  std::size_t num_rows = 141;
231  std::size_t num_cols = 103;
232 
233  // --------------------------------------------------------------------------
234  ublas::vector<NumericT> ublas_v1(num_rows);
235  for (std::size_t i = 0; i < ublas_v1.size(); ++i)
236  ublas_v1(i) = NumericT(i);
237  ublas::vector<NumericT> ublas_v2 = ublas::scalar_vector<NumericT>(num_cols, NumericT(3));
238 
239 
240  ublas::matrix<NumericT> ublas_m1(ublas_v1.size(), ublas_v2.size());
241  ublas::matrix<NumericT> ublas_m2(ublas_v1.size(), ublas_v1.size());
242 
243 
244  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
245  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
246  ublas_m1(i,j) = NumericT(i+j);
247 
248 
249  for (std::size_t i = 0; i < ublas_m2.size1(); ++i)
250  for (std::size_t j = 0; j < ublas_m2.size2(); ++j)
251  ublas_m2(i,j) = NumericT(j - i*j + i);
252 
253 
254  viennacl::vector<NumericT> vcl_v1_native(ublas_v1.size());
255  viennacl::vector<NumericT> vcl_v1_large(4 * ublas_v1.size());
256  viennacl::vector_range< viennacl::vector<NumericT> > vcl_v1_range(vcl_v1_large, viennacl::range(3, ublas_v1.size() + 3));
257  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_v1_slice(vcl_v1_large, viennacl::slice(2, 3, ublas_v1.size()));
258 
259  viennacl::vector<NumericT> vcl_v2_native(ublas_v2.size());
260  viennacl::vector<NumericT> vcl_v2_large(4 * ublas_v2.size());
261  viennacl::vector_range< viennacl::vector<NumericT> > vcl_v2_range(vcl_v2_large, viennacl::range(8, ublas_v2.size() + 8));
262  viennacl::vector_slice< viennacl::vector<NumericT> > vcl_v2_slice(vcl_v2_large, viennacl::slice(6, 2, ublas_v2.size()));
263 
264  viennacl::matrix<NumericT, F> vcl_m1_native(ublas_m1.size1(), ublas_m1.size2());
265  viennacl::matrix<NumericT, F> vcl_m1_large(4 * ublas_m1.size1(), 4 * ublas_m1.size2());
266  viennacl::matrix_range< viennacl::matrix<NumericT, F> > vcl_m1_range(vcl_m1_large,
267  viennacl::range(8, ublas_m1.size1() + 8),
268  viennacl::range(ublas_m1.size2(), 2 * ublas_m1.size2()) );
269  viennacl::matrix_slice< viennacl::matrix<NumericT, F> > vcl_m1_slice(vcl_m1_large,
270  viennacl::slice(6, 2, ublas_m1.size1()),
271  viennacl::slice(ublas_m1.size2(), 2, ublas_m1.size2()) );
272 
273  viennacl::matrix<NumericT, F> vcl_m2_native(ublas_m2.size1(), ublas_m2.size2());
274  viennacl::matrix<NumericT, F> vcl_m2_large(4 * ublas_m2.size1(), 4 * ublas_m2.size2());
275  viennacl::matrix_range< viennacl::matrix<NumericT, F> > vcl_m2_range(vcl_m2_large,
276  viennacl::range(8, ublas_m2.size1() + 8),
277  viennacl::range(ublas_m2.size2(), 2 * ublas_m2.size2()) );
278  viennacl::matrix_slice< viennacl::matrix<NumericT, F> > vcl_m2_slice(vcl_m2_large,
279  viennacl::slice(6, 2, ublas_m2.size1()),
280  viennacl::slice(ublas_m2.size2(), 2, ublas_m2.size2()) );
281 
282 
283  //
284  // Run a bunch of tests for rank-1-updates, matrix-vector products
285  //
286  std::cout << "------------ Testing rank-1-updates and matrix-vector products ------------------" << std::endl;
287 
288  std::cout << "* m = full, v1 = full, v2 = full" << std::endl;
289  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
290  vcl_m1_native, vcl_v1_native, vcl_v2_native);
291  if (retval == EXIT_FAILURE)
292  {
293  std::cout << " --- FAILED! ---" << std::endl;
294  return retval;
295  }
296  else
297  std::cout << " --- PASSED ---" << std::endl;
298 
299  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
300  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
301  ublas_m1(i,j) = NumericT(i+j);
302 
303  std::cout << "* m = full, v1 = full, v2 = range" << std::endl;
304  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
305  vcl_m1_native, vcl_v1_native, vcl_v2_range);
306  if (retval == EXIT_FAILURE)
307  {
308  std::cout << " --- FAILED! ---" << std::endl;
309  return retval;
310  }
311  else
312  std::cout << " --- PASSED ---" << std::endl;
313 
314 
315  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
316  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
317  ublas_m1(i,j) = NumericT(i+j);
318 
319  std::cout << "* m = full, v1 = full, v2 = slice" << std::endl;
320  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
321  vcl_m1_native, vcl_v1_native, vcl_v2_slice);
322  if (retval == EXIT_FAILURE)
323  {
324  std::cout << " --- FAILED! ---" << std::endl;
325  return retval;
326  }
327  else
328  std::cout << " --- PASSED ---" << std::endl;
329 
330 
331  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
332  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
333  ublas_m1(i,j) = NumericT(i+j);
334 
335  // v1 = range
336 
337 
338  std::cout << "* m = full, v1 = range, v2 = full" << std::endl;
339  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
340  vcl_m1_native, vcl_v1_range, vcl_v2_native);
341  if (retval == EXIT_FAILURE)
342  {
343  std::cout << " --- FAILED! ---" << std::endl;
344  return retval;
345  }
346  else
347  std::cout << " --- PASSED ---" << std::endl;
348 
349 
350  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
351  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
352  ublas_m1(i,j) = NumericT(i+j);
353 
354  std::cout << "* m = full, v1 = range, v2 = range" << std::endl;
355  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
356  vcl_m1_native, vcl_v1_range, vcl_v2_range);
357  if (retval == EXIT_FAILURE)
358  {
359  std::cout << " --- FAILED! ---" << std::endl;
360  return retval;
361  }
362  else
363  std::cout << " --- PASSED ---" << std::endl;
364 
365 
366  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
367  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
368  ublas_m1(i,j) = NumericT(i+j);
369 
370  std::cout << "* m = full, v1 = range, v2 = slice" << std::endl;
371  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
372  vcl_m1_native, vcl_v1_range, vcl_v2_slice);
373  if (retval == EXIT_FAILURE)
374  {
375  std::cout << " --- FAILED! ---" << std::endl;
376  return retval;
377  }
378  else
379  std::cout << " --- PASSED ---" << std::endl;
380 
381 
382  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
383  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
384  ublas_m1(i,j) = NumericT(i+j);
385 
386 
387  // v1 = slice
388 
389  std::cout << "* m = full, v1 = slice, v2 = full" << std::endl;
390  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
391  vcl_m1_native, vcl_v1_slice, vcl_v2_native);
392  if (retval == EXIT_FAILURE)
393  {
394  std::cout << " --- FAILED! ---" << std::endl;
395  return retval;
396  }
397  else
398  std::cout << " --- PASSED ---" << std::endl;
399 
400 
401  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
402  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
403  ublas_m1(i,j) = NumericT(i+j);
404 
405  std::cout << "* m = full, v1 = slice, v2 = range" << std::endl;
406  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
407  vcl_m1_native, vcl_v1_slice, vcl_v2_range);
408  if (retval == EXIT_FAILURE)
409  {
410  std::cout << " --- FAILED! ---" << std::endl;
411  return retval;
412  }
413  else
414  std::cout << " --- PASSED ---" << std::endl;
415 
416 
417  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
418  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
419  ublas_m1(i,j) = NumericT(i+j);
420 
421  std::cout << "* m = full, v1 = slice, v2 = slice" << std::endl;
422  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
423  vcl_m1_native, vcl_v1_slice, vcl_v2_slice);
424  if (retval == EXIT_FAILURE)
425  {
426  std::cout << " --- FAILED! ---" << std::endl;
427  return retval;
428  }
429  else
430  std::cout << " --- PASSED ---" << std::endl;
431 
432 
433  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
434  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
435  ublas_m1(i,j) = NumericT(i+j);
436 
438 
439  std::cout << "* m = range, v1 = full, v2 = full" << std::endl;
440  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
441  vcl_m1_range, vcl_v1_native, vcl_v2_native);
442  if (retval == EXIT_FAILURE)
443  {
444  std::cout << " --- FAILED! ---" << std::endl;
445  return retval;
446  }
447  else
448  std::cout << " --- PASSED ---" << std::endl;
449 
450 
451  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
452  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
453  ublas_m1(i,j) = NumericT(i+j);
454 
455  std::cout << "* m = range, v1 = full, v2 = range" << std::endl;
456  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
457  vcl_m1_range, vcl_v1_native, vcl_v2_range);
458  if (retval == EXIT_FAILURE)
459  {
460  std::cout << " --- FAILED! ---" << std::endl;
461  return retval;
462  }
463  else
464  std::cout << " --- PASSED ---" << std::endl;
465 
466 
467  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
468  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
469  ublas_m1(i,j) = NumericT(i+j);
470 
471  std::cout << "* m = range, v1 = full, v2 = slice" << std::endl;
472  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
473  vcl_m1_range, vcl_v1_native, vcl_v2_slice);
474  if (retval == EXIT_FAILURE)
475  {
476  std::cout << " --- FAILED! ---" << std::endl;
477  return retval;
478  }
479  else
480  std::cout << " --- PASSED ---" << std::endl;
481 
482 
483  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
484  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
485  ublas_m1(i,j) = NumericT(i+j);
486 
487  // v1 = range
488 
489 
490  std::cout << "* m = range, v1 = range, v2 = full" << std::endl;
491  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
492  vcl_m1_range, vcl_v1_range, vcl_v2_native);
493  if (retval == EXIT_FAILURE)
494  {
495  std::cout << " --- FAILED! ---" << std::endl;
496  return retval;
497  }
498  else
499  std::cout << " --- PASSED ---" << std::endl;
500 
501 
502  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
503  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
504  ublas_m1(i,j) = NumericT(i+j);
505 
506  std::cout << "* m = range, v1 = range, v2 = range" << std::endl;
507  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
508  vcl_m1_range, vcl_v1_range, vcl_v2_range);
509  if (retval == EXIT_FAILURE)
510  {
511  std::cout << " --- FAILED! ---" << std::endl;
512  return retval;
513  }
514  else
515  std::cout << " --- PASSED ---" << std::endl;
516 
517 
518  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
519  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
520  ublas_m1(i,j) = NumericT(i+j);
521 
522  std::cout << "* m = range, v1 = range, v2 = slice" << std::endl;
523  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
524  vcl_m1_range, vcl_v1_range, vcl_v2_slice);
525  if (retval == EXIT_FAILURE)
526  {
527  std::cout << " --- FAILED! ---" << std::endl;
528  return retval;
529  }
530  else
531  std::cout << " --- PASSED ---" << std::endl;
532 
533 
534  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
535  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
536  ublas_m1(i,j) = NumericT(i+j);
537 
538 
539  // v1 = slice
540 
541  std::cout << "* m = range, v1 = slice, v2 = full" << std::endl;
542  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
543  vcl_m1_range, vcl_v1_slice, vcl_v2_native);
544  if (retval == EXIT_FAILURE)
545  {
546  std::cout << " --- FAILED! ---" << std::endl;
547  return retval;
548  }
549  else
550  std::cout << " --- PASSED ---" << std::endl;
551 
552 
553  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
554  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
555  ublas_m1(i,j) = NumericT(i+j);
556 
557  std::cout << "* m = range, v1 = slice, v2 = range" << std::endl;
558  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
559  vcl_m1_range, vcl_v1_slice, vcl_v2_range);
560  if (retval == EXIT_FAILURE)
561  {
562  std::cout << " --- FAILED! ---" << std::endl;
563  return retval;
564  }
565  else
566  std::cout << " --- PASSED ---" << std::endl;
567 
568 
569  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
570  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
571  ublas_m1(i,j) = NumericT(i+j);
572 
573  std::cout << "* m = range, v1 = slice, v2 = slice" << std::endl;
574  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
575  vcl_m1_range, vcl_v1_slice, vcl_v2_slice);
576  if (retval == EXIT_FAILURE)
577  {
578  std::cout << " --- FAILED! ---" << std::endl;
579  return retval;
580  }
581  else
582  std::cout << " --- PASSED ---" << std::endl;
583 
584 
585  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
586  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
587  ublas_m1(i,j) = NumericT(i+j);
588 
590 
591  std::cout << "* m = slice, v1 = full, v2 = full" << std::endl;
592  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
593  vcl_m1_slice, vcl_v1_native, vcl_v2_native);
594  if (retval == EXIT_FAILURE)
595  {
596  std::cout << " --- FAILED! ---" << std::endl;
597  return retval;
598  }
599  else
600  std::cout << " --- PASSED ---" << std::endl;
601 
602 
603  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
604  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
605  ublas_m1(i,j) = NumericT(i+j);
606 
607  std::cout << "* m = slice, v1 = full, v2 = range" << std::endl;
608  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
609  vcl_m1_slice, vcl_v1_native, vcl_v2_range);
610  if (retval == EXIT_FAILURE)
611  {
612  std::cout << " --- FAILED! ---" << std::endl;
613  return retval;
614  }
615  else
616  std::cout << " --- PASSED ---" << std::endl;
617 
618 
619  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
620  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
621  ublas_m1(i,j) = NumericT(i+j);
622 
623  std::cout << "* m = slice, v1 = full, v2 = slice" << std::endl;
624  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
625  vcl_m1_slice, vcl_v1_native, vcl_v2_slice);
626  if (retval == EXIT_FAILURE)
627  {
628  std::cout << " --- FAILED! ---" << std::endl;
629  return retval;
630  }
631  else
632  std::cout << " --- PASSED ---" << std::endl;
633 
634 
635  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
636  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
637  ublas_m1(i,j) = NumericT(i+j);
638 
639  // v1 = range
640 
641 
642  std::cout << "* m = slice, v1 = range, v2 = full" << std::endl;
643  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
644  vcl_m1_slice, vcl_v1_range, vcl_v2_native);
645  if (retval == EXIT_FAILURE)
646  {
647  std::cout << " --- FAILED! ---" << std::endl;
648  return retval;
649  }
650  else
651  std::cout << " --- PASSED ---" << std::endl;
652 
653 
654  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
655  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
656  ublas_m1(i,j) = NumericT(i+j);
657 
658  std::cout << "* m = slice, v1 = range, v2 = range" << std::endl;
659  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
660  vcl_m1_slice, vcl_v1_range, vcl_v2_range);
661  if (retval == EXIT_FAILURE)
662  {
663  std::cout << " --- FAILED! ---" << std::endl;
664  return retval;
665  }
666  else
667  std::cout << " --- PASSED ---" << std::endl;
668 
669 
670  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
671  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
672  ublas_m1(i,j) = NumericT(i+j);
673 
674  std::cout << "* m = slice, v1 = range, v2 = slice" << std::endl;
675  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
676  vcl_m1_slice, vcl_v1_range, vcl_v2_slice);
677  if (retval == EXIT_FAILURE)
678  {
679  std::cout << " --- FAILED! ---" << std::endl;
680  return retval;
681  }
682  else
683  std::cout << " --- PASSED ---" << std::endl;
684 
685 
686 
687  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
688  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
689  ublas_m1(i,j) = NumericT(i+j);
690 
691  // v1 = slice
692 
693  std::cout << "* m = slice, v1 = slice, v2 = full" << std::endl;
694  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
695  vcl_m1_slice, vcl_v1_slice, vcl_v2_native);
696  if (retval == EXIT_FAILURE)
697  {
698  std::cout << " --- FAILED! ---" << std::endl;
699  return retval;
700  }
701  else
702  std::cout << " --- PASSED ---" << std::endl;
703 
704  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
705  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
706  ublas_m1(i,j) = NumericT(i+j);
707 
708 
709  std::cout << "* m = slice, v1 = slice, v2 = range" << std::endl;
710  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
711  vcl_m1_slice, vcl_v1_slice, vcl_v2_range);
712  if (retval == EXIT_FAILURE)
713  {
714  std::cout << " --- FAILED! ---" << std::endl;
715  return retval;
716  }
717  else
718  std::cout << " --- PASSED ---" << std::endl;
719 
720 
721  for (std::size_t i = 0; i < ublas_m1.size1(); ++i)
722  for (std::size_t j = 0; j < ublas_m1.size2(); ++j)
723  ublas_m1(i,j) = NumericT(i+j);
724 
725  std::cout << "* m = slice, v1 = slice, v2 = slice" << std::endl;
726  retval = test_prod_rank1<NumericT>(ublas_m1, ublas_v1, ublas_v2,
727  vcl_m1_slice, vcl_v1_slice, vcl_v2_slice);
728  if (retval == EXIT_FAILURE)
729  {
730  std::cout << " --- FAILED! ---" << std::endl;
731  return retval;
732  }
733  else
734  std::cout << " --- PASSED ---" << std::endl;
735 
736 
737  return retval;
738 }
739 //
740 // -------------------------------------------------------------
741 //
742 int main()
743 {
744  std::cout << std::endl;
745  std::cout << "----------------------------------------------" << std::endl;
746  std::cout << "----------------------------------------------" << std::endl;
747  std::cout << "## Test :: Matrix" << std::endl;
748  std::cout << "----------------------------------------------" << std::endl;
749  std::cout << "----------------------------------------------" << std::endl;
750  std::cout << std::endl;
751 
752  int retval = EXIT_SUCCESS;
753 
754  std::cout << std::endl;
755  std::cout << "----------------------------------------------" << std::endl;
756  std::cout << std::endl;
757  {
758  typedef int NumericT;
759  std::cout << "# Testing setup:" << std::endl;
760  std::cout << " numeric: int" << std::endl;
761  std::cout << " layout: row-major" << std::endl;
762  retval = test<NumericT, viennacl::row_major>();
763  if ( retval == EXIT_SUCCESS )
764  std::cout << "# Test passed" << std::endl;
765  else
766  return retval;
767  }
768  std::cout << std::endl;
769  std::cout << "----------------------------------------------" << std::endl;
770  std::cout << std::endl;
771  {
772  typedef int NumericT;
773  std::cout << "# Testing setup:" << std::endl;
774  std::cout << " numeric: int" << std::endl;
775  std::cout << " layout: column-major" << std::endl;
776  retval = test<NumericT, viennacl::column_major>();
777  if ( retval == EXIT_SUCCESS )
778  std::cout << "# Test passed" << std::endl;
779  else
780  return retval;
781  }
782  std::cout << std::endl;
783  std::cout << "----------------------------------------------" << std::endl;
784  std::cout << std::endl;
785 
786 
787 #ifdef VIENNACL_WITH_OPENCL
789 #endif
790  {
791  {
792  typedef long NumericT;
793  std::cout << "# Testing setup:" << std::endl;
794  std::cout << " numeric: double" << std::endl;
795  std::cout << " layout: row-major" << std::endl;
796  retval = test<NumericT, viennacl::row_major>();
797  if ( retval == EXIT_SUCCESS )
798  std::cout << "# Test passed" << std::endl;
799  else
800  return retval;
801  }
802  std::cout << std::endl;
803  std::cout << "----------------------------------------------" << std::endl;
804  std::cout << std::endl;
805  {
806  typedef long NumericT;
807  std::cout << "# Testing setup:" << std::endl;
808  std::cout << " numeric: double" << std::endl;
809  std::cout << " layout: column-major" << std::endl;
810  retval = test<NumericT, viennacl::column_major>();
811  if ( retval == EXIT_SUCCESS )
812  std::cout << "# Test passed" << std::endl;
813  else
814  return retval;
815  }
816  std::cout << std::endl;
817  std::cout << "----------------------------------------------" << std::endl;
818  std::cout << std::endl;
819  }
820 
821  std::cout << std::endl;
822  std::cout << "------- Test completed --------" << std::endl;
823  std::cout << std::endl;
824 
825 
826  return retval;
827 }
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...
int test_prod_rank1(UblasMatrixType &ublas_m1, UblasVectorType &ublas_v1, UblasVectorType &ublas_v2, VCLMatrixType &vcl_m1, VCLVectorType1 &vcl_v1, VCLVectorType2 &vcl_v2)
Class for representing strided submatrices of a bigger matrix A.
Definition: forwards.h:442
void trans(matrix_expression< const matrix_base< NumericT, SizeT, DistanceT >, const matrix_base< NumericT, SizeT, DistanceT >, op_trans > const &proxy, matrix_base< NumericT > &temp_trans)
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Implementation of the dense matrix class.
void finish()
Synchronizes the execution. finish() will only return after all compute kernels (CUDA, OpenCL) have completed.
Definition: memory.hpp:54
A dense matrix class.
Definition: forwards.h:374
viennacl::scalar< int > s2
viennacl::scalar< float > s1
viennacl::ocl::device const & current_device()
Convenience function for returning the active device in the current context.
Definition: backend.hpp:351
int test()
viennacl::vector< float > v1
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Definition: prod.hpp:91
Class for representing non-strided subvectors of a bigger vector x.
Definition: forwards.h:433
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
ScalarType diff(ScalarType &s1, viennacl::scalar< ScalarType > &s2)
Implementations of LU factorization for row-major and column-major dense matrices.
Implementations of dense direct solvers are found here.
viennacl::matrix_expression< const vector_base< NumericT >, const vector_base< NumericT >, op_prod > outer_prod(const vector_base< NumericT > &vec1, const vector_base< NumericT > &vec2)
Returns a proxy class for the operation mat += vec1 * vec2^T, i.e. a rank 1 update.
viennacl::vector< int > v2
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
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 range class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:423
float ScalarType
Definition: fft_1d.cpp:42
int main()
Class for representing non-strided submatrices of a bigger matrix A.
Definition: forwards.h:439
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:428
Implementation of the ViennaCL scalar class.