ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
matrix_int.hpp
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 #define VIENNACL_WITH_UBLAS
19 //#define NDEBUG
20 //#define VIENNACL_BUILD_INFO
21 
22 #include <utility>
23 #include <iostream>
24 #include <fstream>
25 #include <string>
26 #include <cmath>
27 #include <algorithm>
28 #include <cstdio>
29 #include <ctime>
30 
31 #include "viennacl/scalar.hpp"
32 #include "viennacl/matrix.hpp"
33 #include "viennacl/linalg/prod.hpp"
34 /*#include "viennacl/compressed_matrix.hpp"
35 #include "viennacl/linalg/cg.hpp"
36 #include "viennacl/linalg/inner_prod.hpp"
37 #include "viennacl/linalg/ilu.hpp"
38 #include "viennacl/linalg/norm_2.hpp"
39 #include "viennacl/io/matrix_market.hpp"*/
42 
43 #include "boost/numeric/ublas/vector.hpp"
44 #include "boost/numeric/ublas/matrix.hpp"
45 #include "boost/numeric/ublas/matrix_proxy.hpp"
46 #include "boost/numeric/ublas/vector_proxy.hpp"
47 #include "boost/numeric/ublas/io.hpp"
48 
49 template<typename MatrixType, typename VCLMatrixType>
50 bool check_for_equality(MatrixType const & ublas_A, VCLMatrixType const & vcl_A)
51 {
52  typedef typename MatrixType::value_type value_type;
53 
54  boost::numeric::ublas::matrix<value_type> vcl_A_cpu(vcl_A.size1(), vcl_A.size2());
55  viennacl::backend::finish(); //workaround for a bug in APP SDK 2.7 on Trinity APUs (with Catalyst 12.8)
56  viennacl::copy(vcl_A, vcl_A_cpu);
57 
58  for (std::size_t i=0; i<ublas_A.size1(); ++i)
59  {
60  for (std::size_t j=0; j<ublas_A.size2(); ++j)
61  {
62  if (ublas_A(i,j) != vcl_A_cpu(i,j))
63  {
64  std::cout << "Error at index (" << i << ", " << j << "): " << ublas_A(i,j) << " vs " << vcl_A_cpu(i,j) << std::endl;
65  std::cout << std::endl << "TEST failed!" << std::endl;
66  return false;
67  }
68  }
69  }
70 
71  std::cout << "PASSED!" << std::endl;
72  return true;
73 }
74 
75 
76 
77 
78 template<typename UBLASMatrixType,
79  typename ViennaCLMatrixType1, typename ViennaCLMatrixType2, typename ViennaCLMatrixType3>
80 int run_test(UBLASMatrixType & ublas_A, UBLASMatrixType & ublas_B, UBLASMatrixType & ublas_C,
81  ViennaCLMatrixType1 & vcl_A, ViennaCLMatrixType2 & vcl_B, ViennaCLMatrixType3 vcl_C)
82 {
83 
85 
86  cpu_value_type alpha = 3;
87  viennacl::scalar<cpu_value_type> gpu_alpha = alpha;
88 
89  cpu_value_type beta = 2;
90  viennacl::scalar<cpu_value_type> gpu_beta = beta;
91 
92 
93  //
94  // Initializer:
95  //
96  std::cout << "Checking for zero_matrix initializer..." << std::endl;
97  ublas_A = boost::numeric::ublas::zero_matrix<cpu_value_type>(ublas_A.size1(), ublas_A.size2());
98  vcl_A = viennacl::zero_matrix<cpu_value_type>(vcl_A.size1(), vcl_A.size2());
99  if (!check_for_equality(ublas_A, vcl_A))
100  return EXIT_FAILURE;
101 
102  std::cout << "Checking for scalar_matrix initializer..." << std::endl;
103  ublas_A = boost::numeric::ublas::scalar_matrix<cpu_value_type>(ublas_A.size1(), ublas_A.size2(), alpha);
104  vcl_A = viennacl::scalar_matrix<cpu_value_type>(vcl_A.size1(), vcl_A.size2(), alpha);
105  if (!check_for_equality(ublas_A, vcl_A))
106  return EXIT_FAILURE;
107 
108  ublas_A = boost::numeric::ublas::scalar_matrix<cpu_value_type>(ublas_A.size1(), ublas_A.size2(), gpu_beta);
109  vcl_A = viennacl::scalar_matrix<cpu_value_type>( vcl_A.size1(), vcl_A.size2(), gpu_beta);
110  if (!check_for_equality(ublas_A, vcl_A))
111  return EXIT_FAILURE;
112 
113  /*
114  std::cout << "Checking for identity initializer..." << std::endl;
115  ublas_A = boost::numeric::ublas::identity_matrix<cpu_value_type>(ublas_A.size1());
116  vcl_A = viennacl::identity_matrix<cpu_value_type>(vcl_A.size1());
117  if (!check_for_equality(ublas_A, vcl_A))
118  return EXIT_FAILURE; */
119 
120 
121  std::cout << std::endl;
122  //std::cout << "//" << std::endl;
123  //std::cout << "////////// Test: Assignments //////////" << std::endl;
124  //std::cout << "//" << std::endl;
125 
126  if (!check_for_equality(ublas_B, vcl_B))
127  return EXIT_FAILURE;
128 
129  std::cout << "Testing matrix assignment... ";
130  //std::cout << ublas_B(0,0) << " vs. " << vcl_B(0,0) << std::endl;
131  ublas_A = ublas_B;
132  vcl_A = vcl_B;
133  if (!check_for_equality(ublas_A, vcl_A))
134  return EXIT_FAILURE;
135 
136 
137 
138  //std::cout << std::endl;
139  //std::cout << "//" << std::endl;
140  //std::cout << "////////// Test 1: Copy to GPU //////////" << std::endl;
141  //std::cout << "//" << std::endl;
142 
143  ublas_A = ublas_B;
144  viennacl::copy(ublas_B, vcl_A);
145  std::cout << "Testing upper left copy to GPU... ";
146  if (!check_for_equality(ublas_A, vcl_A))
147  return EXIT_FAILURE;
148 
149 
150  ublas_C = ublas_B;
151  viennacl::copy(ublas_B, vcl_C);
152  std::cout << "Testing lower right copy to GPU... ";
153  if (!check_for_equality(ublas_C, vcl_C))
154  return EXIT_FAILURE;
155 
156 
157  //std::cout << std::endl;
158  //std::cout << "//" << std::endl;
159  //std::cout << "////////// Test 2: Copy from GPU //////////" << std::endl;
160  //std::cout << "//" << std::endl;
161 
162  std::cout << "Testing upper left copy to A... ";
163  if (!check_for_equality(ublas_A, vcl_A))
164  return EXIT_FAILURE;
165 
166  std::cout << "Testing lower right copy to C... ";
167  if (!check_for_equality(ublas_C, vcl_C))
168  return EXIT_FAILURE;
169 
170 
171 
172  //std::cout << "//" << std::endl;
173  //std::cout << "////////// Test 3: Addition //////////" << std::endl;
174  //std::cout << "//" << std::endl;
175  viennacl::copy(ublas_C, vcl_C);
176 
177  std::cout << "Inplace add: ";
178  ublas_C += ublas_C;
179  vcl_C += vcl_C;
180 
181  if (!check_for_equality(ublas_C, vcl_C))
182  return EXIT_FAILURE;
183 
184  std::cout << "Scaled inplace add: ";
185  ublas_C += beta * ublas_A;
186  vcl_C += gpu_beta * vcl_A;
187 
188  if (!check_for_equality(ublas_C, vcl_C))
189  return EXIT_FAILURE;
190 
191  std::cout << "Add: ";
192  ublas_C = ublas_A + ublas_B;
193  vcl_C = vcl_A + vcl_B;
194 
195  if (!check_for_equality(ublas_C, vcl_C))
196  return EXIT_FAILURE;
197 
198  std::cout << "Add with flipsign: ";
199  ublas_C = - ublas_A + ublas_B;
200  vcl_C = - vcl_A + vcl_B;
201 
202  if (!check_for_equality(ublas_C, vcl_C))
203  return EXIT_FAILURE;
204 
205 
206  std::cout << "Scaled add (left): ";
207  ublas_C = alpha * ublas_A + ublas_B;
208  vcl_C = alpha * vcl_A + vcl_B;
209 
210  if (!check_for_equality(ublas_C, vcl_C))
211  return EXIT_FAILURE;
212 
213  std::cout << "Scaled add (left): ";
214  vcl_C = gpu_alpha * vcl_A + vcl_B;
215  if (!check_for_equality(ublas_C, vcl_C))
216  return EXIT_FAILURE;
217 
218 
219  std::cout << "Scaled add (right): ";
220  ublas_C = ublas_A + beta * ublas_B;
221  vcl_C = vcl_A + beta * vcl_B;
222 
223  if (!check_for_equality(ublas_C, vcl_C))
224  return EXIT_FAILURE;
225 
226  std::cout << "Scaled add (right): ";
227  vcl_C = vcl_A + gpu_beta * vcl_B;
228  if (!check_for_equality(ublas_C, vcl_C))
229  return EXIT_FAILURE;
230 
231 
232 
233  std::cout << "Scaled add (both): ";
234  ublas_C = alpha * ublas_A + beta * ublas_B;
235  vcl_C = alpha * vcl_A + beta * vcl_B;
236 
237  if (!check_for_equality(ublas_C, vcl_C))
238  return EXIT_FAILURE;
239 
240  std::cout << "Scaled add (both): ";
241  vcl_C = gpu_alpha * vcl_A + gpu_beta * vcl_B;
242  if (!check_for_equality(ublas_C, vcl_C))
243  return EXIT_FAILURE;
244 
245  //std::cout << "//" << std::endl;
246  //std::cout << "////////// Test 4: Subtraction //////////" << std::endl;
247  //std::cout << "//" << std::endl;
248  viennacl::copy(ublas_C, vcl_C);
249 
250  std::cout << "Inplace sub: ";
251  ublas_C -= ublas_B;
252  vcl_C -= vcl_B;
253 
254  if (!check_for_equality(ublas_C, vcl_C))
255  return EXIT_FAILURE;
256 
257  std::cout << "Scaled Inplace sub: ";
258  ublas_C -= alpha * ublas_B;
259  vcl_C -= alpha * vcl_B;
260 
261  if (!check_for_equality(ublas_C, vcl_C))
262  return EXIT_FAILURE;
263 
264 
265 
266 
267  std::cout << "Sub: ";
268  ublas_C = ublas_A - ublas_B;
269  vcl_C = vcl_A - vcl_B;
270 
271  if (!check_for_equality(ublas_C, vcl_C))
272  return EXIT_FAILURE;
273 
274  std::cout << "Scaled sub (left): ";
275  ublas_B = alpha * ublas_A - ublas_C;
276  vcl_B = alpha * vcl_A - vcl_C;
277 
278  if (!check_for_equality(ublas_B, vcl_B))
279  return EXIT_FAILURE;
280 
281  std::cout << "Scaled sub (left): ";
282  vcl_B = gpu_alpha * vcl_A - vcl_C;
283  if (!check_for_equality(ublas_B, vcl_B))
284  return EXIT_FAILURE;
285 
286 
287  std::cout << "Scaled sub (right): ";
288  ublas_B = ublas_A - beta * ublas_C;
289  vcl_B = vcl_A - vcl_C * beta;
290 
291  if (!check_for_equality(ublas_B, vcl_B))
292  return EXIT_FAILURE;
293 
294  std::cout << "Scaled sub (right): ";
295  vcl_B = vcl_A - vcl_C * gpu_beta;
296  if (!check_for_equality(ublas_B, vcl_B))
297  return EXIT_FAILURE;
298 
299 
300  std::cout << "Scaled sub (both): ";
301  ublas_B = alpha * ublas_A - beta * ublas_C;
302  vcl_B = alpha * vcl_A - vcl_C * beta;
303 
304  if (!check_for_equality(ublas_B, vcl_B))
305  return EXIT_FAILURE;
306 
307  std::cout << "Scaled sub (both): ";
308  vcl_B = gpu_alpha * vcl_A - vcl_C * gpu_beta;
309  if (!check_for_equality(ublas_B, vcl_B))
310  return EXIT_FAILURE;
311 
312 
313  std::cout << "Unary operator-: ";
314  ublas_C = - ublas_A;
315  vcl_C = - vcl_A;
316 
317  if (!check_for_equality(ublas_C, vcl_C))
318  return EXIT_FAILURE;
319 
320 
321 
322  //std::cout << "//" << std::endl;
323  //std::cout << "////////// Test 5: Scaling //////////" << std::endl;
324  //std::cout << "//" << std::endl;
325  viennacl::copy(ublas_A, vcl_A);
326 
327  std::cout << "Multiplication with CPU scalar: ";
328  ublas_A *= alpha;
329  vcl_A *= alpha;
330 
331  if (!check_for_equality(ublas_A, vcl_A))
332  return EXIT_FAILURE;
333 
334  std::cout << "Multiplication with GPU scalar: ";
335  ublas_A *= beta;
336  vcl_A *= gpu_beta;
337 
338  if (!check_for_equality(ublas_A, vcl_A))
339  return EXIT_FAILURE;
340 
341 
342  std::cout << "Division with CPU scalar: ";
343  ublas_A /= alpha;
344  vcl_A /= alpha;
345 
346  if (!check_for_equality(ublas_A, vcl_A))
347  return EXIT_FAILURE;
348 
349  std::cout << "Division with GPU scalar: ";
350  ublas_A /= beta;
351  vcl_A /= gpu_beta;
352 
353  if (!check_for_equality(ublas_A, vcl_A))
354  return EXIT_FAILURE;
355 
356 
357 
358  std::cout << "Testing elementwise multiplication..." << std::endl;
359  ublas_B = boost::numeric::ublas::scalar_matrix<cpu_value_type>(ublas_B.size1(), ublas_B.size2(), 2);
360  ublas_A = 3 * ublas_B;
361  viennacl::copy(ublas_A, vcl_A);
362  viennacl::copy(ublas_B, vcl_B);
363  viennacl::copy(ublas_B, vcl_B);
364  ublas_A = boost::numeric::ublas::element_prod(ublas_A, ublas_B);
365  vcl_A = viennacl::linalg::element_prod(vcl_A, vcl_B);
366 
367  if (!check_for_equality(ublas_A, vcl_A))
368  return EXIT_FAILURE;
369 
370  ublas_A += boost::numeric::ublas::element_prod(ublas_A, ublas_B);
371  vcl_A += viennacl::linalg::element_prod(vcl_A, vcl_B);
372 
373  if (!check_for_equality(ublas_A, vcl_A))
374  return EXIT_FAILURE;
375 
376  ublas_A -= boost::numeric::ublas::element_prod(ublas_A, ublas_B);
377  vcl_A -= viennacl::linalg::element_prod(vcl_A, vcl_B);
378 
379  if (!check_for_equality(ublas_A, vcl_A))
380  return EXIT_FAILURE;
381 
383  ublas_A = boost::numeric::ublas::element_prod(ublas_A + ublas_B, ublas_B);
384  vcl_A = viennacl::linalg::element_prod(vcl_A + vcl_B, vcl_B);
385 
386  if (!check_for_equality(ublas_A, vcl_A))
387  return EXIT_FAILURE;
388 
389  ublas_A += boost::numeric::ublas::element_prod(ublas_A + ublas_B, ublas_B);
390  vcl_A += viennacl::linalg::element_prod(vcl_A + vcl_B, vcl_B);
391 
392  if (!check_for_equality(ublas_A, vcl_A))
393  return EXIT_FAILURE;
394 
395  ublas_A -= boost::numeric::ublas::element_prod(ublas_A + ublas_B, ublas_B);
396  vcl_A -= viennacl::linalg::element_prod(vcl_A + vcl_B, vcl_B);
397 
398  if (!check_for_equality(ublas_A, vcl_A))
399  return EXIT_FAILURE;
400 
402  ublas_A = boost::numeric::ublas::element_prod(ublas_A, ublas_B + ublas_A);
403  vcl_A = viennacl::linalg::element_prod(vcl_A, vcl_B + vcl_A);
404 
405  if (!check_for_equality(ublas_A, vcl_A))
406  return EXIT_FAILURE;
407 
408  ublas_A += boost::numeric::ublas::element_prod(ublas_A, ublas_B + ublas_A);
409  vcl_A += viennacl::linalg::element_prod(vcl_A, vcl_B + vcl_A);
410 
411  if (!check_for_equality(ublas_A, vcl_A))
412  return EXIT_FAILURE;
413 
414  ublas_A -= boost::numeric::ublas::element_prod(ublas_A, ublas_B + ublas_A);
415  vcl_A -= viennacl::linalg::element_prod(vcl_A, vcl_B + vcl_A);
416 
417  if (!check_for_equality(ublas_A, vcl_A))
418  return EXIT_FAILURE;
419 
421  ublas_A = boost::numeric::ublas::element_prod(ublas_A + ublas_B, ublas_B + ublas_A);
422  vcl_A = viennacl::linalg::element_prod(vcl_A + vcl_B, vcl_B + vcl_A);
423 
424  if (!check_for_equality(ublas_A, vcl_A))
425  return EXIT_FAILURE;
426 
427  ublas_A += boost::numeric::ublas::element_prod(ublas_A + ublas_B, ublas_B + ublas_A);
428  vcl_A += viennacl::linalg::element_prod(vcl_A + vcl_B, vcl_B + vcl_A);
429 
430  if (!check_for_equality(ublas_A, vcl_A))
431  return EXIT_FAILURE;
432 
433  ublas_A -= boost::numeric::ublas::element_prod(ublas_A + ublas_B, ublas_B + ublas_A);
434  vcl_A -= viennacl::linalg::element_prod(vcl_A + vcl_B, vcl_B + vcl_A);
435 
436  if (!check_for_equality(ublas_A, vcl_A))
437  return EXIT_FAILURE;
438 
439 
440  ublas_B = boost::numeric::ublas::scalar_matrix<cpu_value_type>(ublas_B.size1(), ublas_B.size2(), 2);
441  ublas_A = 3 * ublas_B;
442  viennacl::copy(ublas_A, vcl_A);
443  viennacl::copy(ublas_B, vcl_B);
444  viennacl::copy(ublas_B, vcl_B);
445 
446  ublas_A = boost::numeric::ublas::element_div(ublas_A, ublas_B);
447  vcl_A = viennacl::linalg::element_div(vcl_A, vcl_B);
448 
449  if (!check_for_equality(ublas_A, vcl_A))
450  return EXIT_FAILURE;
451 
452  ublas_A += boost::numeric::ublas::element_div(ublas_A, ublas_B);
453  vcl_A += viennacl::linalg::element_div(vcl_A, vcl_B);
454 
455  if (!check_for_equality(ublas_A, vcl_A))
456  return EXIT_FAILURE;
457 
458  ublas_A -= boost::numeric::ublas::element_div(ublas_A, ublas_B);
459  vcl_A -= viennacl::linalg::element_div(vcl_A, vcl_B);
460 
461  if (!check_for_equality(ublas_A, vcl_A))
462  return EXIT_FAILURE;
463 
465  ublas_A = boost::numeric::ublas::element_div(ublas_A + ublas_B, ublas_B);
466  vcl_A = viennacl::linalg::element_div(vcl_A + vcl_B, vcl_B);
467 
468  if (!check_for_equality(ublas_A, vcl_A))
469  return EXIT_FAILURE;
470 
471  ublas_A += boost::numeric::ublas::element_div(ublas_A + ublas_B, ublas_B);
472  vcl_A += viennacl::linalg::element_div(vcl_A + vcl_B, vcl_B);
473 
474  if (!check_for_equality(ublas_A, vcl_A))
475  return EXIT_FAILURE;
476 
477  ublas_A -= boost::numeric::ublas::element_div(ublas_A + ublas_B, ublas_B);
478  vcl_A -= viennacl::linalg::element_div(vcl_A + vcl_B, vcl_B);
479 
480  if (!check_for_equality(ublas_A, vcl_A))
481  return EXIT_FAILURE;
482 
484  ublas_A = boost::numeric::ublas::element_div(ublas_A, ublas_B + ublas_A);
485  vcl_A = viennacl::linalg::element_div(vcl_A, vcl_B + vcl_A);
486 
487  if (!check_for_equality(ublas_A, vcl_A))
488  return EXIT_FAILURE;
489 
490  ublas_A += boost::numeric::ublas::element_div(ublas_A, ublas_B + ublas_A);
491  vcl_A += viennacl::linalg::element_div(vcl_A, vcl_B + vcl_A);
492 
493  if (!check_for_equality(ublas_A, vcl_A))
494  return EXIT_FAILURE;
495 
496  ublas_A -= boost::numeric::ublas::element_div(ublas_A, ublas_B + ublas_A);
497  vcl_A -= viennacl::linalg::element_div(vcl_A, vcl_B + vcl_A);
498 
499  if (!check_for_equality(ublas_A, vcl_A))
500  return EXIT_FAILURE;
501 
503  ublas_A = boost::numeric::ublas::element_div(ublas_A + ublas_B, ublas_B + ublas_A);
504  vcl_A = viennacl::linalg::element_div(vcl_A + vcl_B, vcl_B + vcl_A);
505 
506  if (!check_for_equality(ublas_A, vcl_A))
507  return EXIT_FAILURE;
508 
509  ublas_A += boost::numeric::ublas::element_div(ublas_A + ublas_B, ublas_B + ublas_A);
510  vcl_A += viennacl::linalg::element_div(vcl_A + vcl_B, vcl_B + vcl_A);
511 
512  if (!check_for_equality(ublas_A, vcl_A))
513  return EXIT_FAILURE;
514 
515  ublas_A -= boost::numeric::ublas::element_div(ublas_A + ublas_B, ublas_B + ublas_A);
516  vcl_A -= viennacl::linalg::element_div(vcl_A + vcl_B, vcl_B + vcl_A);
517 
518  if (!check_for_equality(ublas_A, vcl_A))
519  return EXIT_FAILURE;
520 
521  std::cout << "Testing unary elementwise operations..." << std::endl;
522 
523 #define GENERATE_UNARY_OP_TEST(FUNCNAME) \
524  ublas_B = boost::numeric::ublas::scalar_matrix<cpu_value_type>(ublas_B.size1(), ublas_B.size2(), 1); \
525  ublas_A = 3 * ublas_B; \
526  ublas_C = 2 * ublas_A; \
527  viennacl::copy(ublas_A, vcl_A); \
528  viennacl::copy(ublas_B, vcl_B); \
529  viennacl::copy(ublas_C, vcl_C); \
530  viennacl::copy(ublas_B, vcl_B); \
531  \
532  for (std::size_t i=0; i<ublas_C.size1(); ++i) \
533  for (std::size_t j=0; j<ublas_C.size2(); ++j) \
534  ublas_C(i,j) = std::FUNCNAME(ublas_A(i,j)); \
535  vcl_C = viennacl::linalg::element_##FUNCNAME(vcl_A); \
536  \
537  if (!check_for_equality(ublas_C, vcl_C)) \
538  { \
539  std::cout << "Failure at C = " << #FUNCNAME << "(A)" << std::endl; \
540  return EXIT_FAILURE; \
541  } \
542  \
543  for (std::size_t i=0; i<ublas_C.size1(); ++i) \
544  for (std::size_t j=0; j<ublas_C.size2(); ++j) \
545  ublas_C(i,j) = std::FUNCNAME(ublas_A(i,j) + ublas_B(i,j)); \
546  vcl_C = viennacl::linalg::element_##FUNCNAME(vcl_A + vcl_B); \
547  \
548  if (!check_for_equality(ublas_C, vcl_C)) \
549  { \
550  std::cout << "Failure at C = " << #FUNCNAME << "(A + B)" << std::endl; \
551  return EXIT_FAILURE; \
552  } \
553  \
554  for (std::size_t i=0; i<ublas_C.size1(); ++i) \
555  for (std::size_t j=0; j<ublas_C.size2(); ++j) \
556  ublas_C(i,j) += std::FUNCNAME(ublas_A(i,j)); \
557  vcl_C += viennacl::linalg::element_##FUNCNAME(vcl_A); \
558  \
559  if (!check_for_equality(ublas_C, vcl_C)) \
560  { \
561  std::cout << "Failure at C += " << #FUNCNAME << "(A)" << std::endl; \
562  return EXIT_FAILURE; \
563  } \
564  \
565  for (std::size_t i=0; i<ublas_C.size1(); ++i) \
566  for (std::size_t j=0; j<ublas_C.size2(); ++j) \
567  ublas_C(i,j) += std::FUNCNAME(ublas_A(i,j) + ublas_B(i,j)); \
568  vcl_C += viennacl::linalg::element_##FUNCNAME(vcl_A + vcl_B); \
569  \
570  if (!check_for_equality(ublas_C, vcl_C)) \
571  { \
572  std::cout << "Failure at C += " << #FUNCNAME << "(A + B)" << std::endl; \
573  return EXIT_FAILURE; \
574  } \
575  \
576  for (std::size_t i=0; i<ublas_C.size1(); ++i) \
577  for (std::size_t j=0; j<ublas_C.size2(); ++j) \
578  ublas_C(i,j) -= std::FUNCNAME(ublas_A(i,j)); \
579  vcl_C -= viennacl::linalg::element_##FUNCNAME(vcl_A); \
580  \
581  if (!check_for_equality(ublas_C, vcl_C)) \
582  { \
583  std::cout << "Failure at C -= " << #FUNCNAME << "(A)" << std::endl; \
584  return EXIT_FAILURE; \
585  } \
586  \
587  for (std::size_t i=0; i<ublas_C.size1(); ++i) \
588  for (std::size_t j=0; j<ublas_C.size2(); ++j) \
589  ublas_C(i,j) -= std::FUNCNAME(ublas_A(i,j) + ublas_B(i,j)); \
590  vcl_C -= viennacl::linalg::element_##FUNCNAME(vcl_A + vcl_B); \
591  \
592  if (!check_for_equality(ublas_C, vcl_C)) \
593  { \
594  std::cout << "Failure at C -= " << #FUNCNAME << "(A + B)" << std::endl; \
595  return EXIT_FAILURE; \
596  } \
597  \
598 
600 
601  std::cout << "Complicated expressions: ";
602  //std::cout << "ublas_A: " << ublas_A << std::endl;
603  //std::cout << "ublas_B: " << ublas_B << std::endl;
604  //std::cout << "ublas_C: " << ublas_C << std::endl;
605  ublas_B += alpha * (- ublas_A - beta * ublas_C + ublas_A);
606  vcl_B += gpu_alpha * (- vcl_A - vcl_C * beta + vcl_A);
607 
608  if (!check_for_equality(ublas_B, vcl_B))
609  return EXIT_FAILURE;
610 
611  ublas_B += (- ublas_A - beta * ublas_C + ublas_A * beta) / gpu_alpha;
612  vcl_B += (- vcl_A - vcl_C * beta + gpu_beta * vcl_A) / gpu_alpha;
613 
614  if (!check_for_equality(ublas_B, vcl_B))
615  return EXIT_FAILURE;
616 
617 
618  ublas_B -= alpha * (- ublas_A - beta * ublas_C - ublas_A);
619  vcl_B -= gpu_alpha * (- vcl_A - vcl_C * beta - vcl_A);
620 
621  if (!check_for_equality(ublas_B, vcl_B))
622  return EXIT_FAILURE;
623 
624  ublas_B -= (- ublas_A - beta * ublas_C - ublas_A * beta) / alpha;
625  vcl_B -= (- vcl_A - vcl_C * beta - gpu_beta * vcl_A) / gpu_alpha;
626 
627  if (!check_for_equality(ublas_B, vcl_B))
628  return EXIT_FAILURE;
629 
630  std::cout << std::endl;
631  std::cout << "----------------------------------------------" << std::endl;
632  std::cout << std::endl;
633 
634 
635  return EXIT_SUCCESS;
636 }
637 
638 
639 
640 
641 template<typename T, typename ScalarType>
642 int run_test()
643 {
644  //typedef float ScalarType;
645  typedef boost::numeric::ublas::matrix<ScalarType> MatrixType;
646 
647  typedef viennacl::matrix<ScalarType, T> VCLMatrixType;
648 
649  std::size_t dim_rows = 131;
650  std::size_t dim_cols = 33;
651  //std::size_t dim_rows = 5;
652  //std::size_t dim_cols = 3;
653 
654  //setup ublas objects:
655  MatrixType ublas_A(dim_rows, dim_cols);
656  MatrixType ublas_B(dim_rows, dim_cols);
657  MatrixType ublas_C(dim_rows, dim_cols);
658 
659  for (std::size_t i=0; i<ublas_A.size1(); ++i)
660  for (std::size_t j=0; j<ublas_A.size2(); ++j)
661  {
662  ublas_A(i,j) = ScalarType((i+2) + (j+1)*(i+2));
663  ublas_B(i,j) = ScalarType((j+2) + (j+1)*(j+2));
664  ublas_C(i,j) = ScalarType((i+1) + (i+1)*(i+2));
665  }
666 
667  MatrixType ublas_A_large(4 * dim_rows, 4 * dim_cols);
668  for (std::size_t i=0; i<ublas_A_large.size1(); ++i)
669  for (std::size_t j=0; j<ublas_A_large.size2(); ++j)
670  ublas_A_large(i,j) = ScalarType(i * ublas_A_large.size2() + j);
671 
672  //Setup ViennaCL objects
673  VCLMatrixType vcl_A_full(4 * dim_rows, 4 * dim_cols);
674  VCLMatrixType vcl_B_full(4 * dim_rows, 4 * dim_cols);
675  VCLMatrixType vcl_C_full(4 * dim_rows, 4 * dim_cols);
676 
677  viennacl::copy(ublas_A_large, vcl_A_full);
678  viennacl::copy(ublas_A_large, vcl_B_full);
679  viennacl::copy(ublas_A_large, vcl_C_full);
680 
681  //
682  // Create A
683  //
684  VCLMatrixType vcl_A(dim_rows, dim_cols);
685 
686  viennacl::range vcl_A_r1(2 * dim_rows, 3 * dim_rows);
687  viennacl::range vcl_A_r2(dim_cols, 2 * dim_cols);
688  viennacl::matrix_range<VCLMatrixType> vcl_range_A(vcl_A_full, vcl_A_r1, vcl_A_r2);
689 
690  viennacl::slice vcl_A_s1(2, 3, dim_rows);
691  viennacl::slice vcl_A_s2(2 * dim_cols, 2, dim_cols);
692  viennacl::matrix_slice<VCLMatrixType> vcl_slice_A(vcl_A_full, vcl_A_s1, vcl_A_s2);
693 
694 
695  //
696  // Create B
697  //
698  VCLMatrixType vcl_B(dim_rows, dim_cols);
699 
700  viennacl::range vcl_B_r1(dim_rows, 2 * dim_rows);
701  viennacl::range vcl_B_r2(2 * dim_cols, 3 * dim_cols);
702  viennacl::matrix_range<VCLMatrixType> vcl_range_B(vcl_B_full, vcl_B_r1, vcl_B_r2);
703 
704  viennacl::slice vcl_B_s1(2 * dim_rows, 2, dim_rows);
705  viennacl::slice vcl_B_s2(dim_cols, 3, dim_cols);
706  viennacl::matrix_slice<VCLMatrixType> vcl_slice_B(vcl_B_full, vcl_B_s1, vcl_B_s2);
707 
708 
709  //
710  // Create C
711  //
712  VCLMatrixType vcl_C(dim_rows, dim_cols);
713 
714  viennacl::range vcl_C_r1(2 * dim_rows, 3 * dim_rows);
715  viennacl::range vcl_C_r2(3 * dim_cols, 4 * dim_cols);
716  viennacl::matrix_range<VCLMatrixType> vcl_range_C(vcl_C_full, vcl_C_r1, vcl_C_r2);
717 
718  viennacl::slice vcl_C_s1(dim_rows, 2, dim_rows);
719  viennacl::slice vcl_C_s2(0, 3, dim_cols);
720  viennacl::matrix_slice<VCLMatrixType> vcl_slice_C(vcl_C_full, vcl_C_s1, vcl_C_s2);
721 
722  viennacl::copy(ublas_A, vcl_A);
723  viennacl::copy(ublas_A, vcl_range_A);
724  viennacl::copy(ublas_A, vcl_slice_A);
725 
726  viennacl::copy(ublas_B, vcl_B);
727  viennacl::copy(ublas_B, vcl_range_B);
728  viennacl::copy(ublas_B, vcl_slice_B);
729 
730  viennacl::copy(ublas_C, vcl_C);
731  viennacl::copy(ublas_C, vcl_range_C);
732  viennacl::copy(ublas_C, vcl_slice_C);
733 
734 
735  std::cout << std::endl;
736  std::cout << "//" << std::endl;
737  std::cout << "////////// Test: Copy CTOR //////////" << std::endl;
738  std::cout << "//" << std::endl;
739 
740  {
741  std::cout << "Testing matrix created from range... ";
742  VCLMatrixType vcl_temp = vcl_range_A;
743  if (check_for_equality(ublas_A, vcl_temp))
744  std::cout << "PASSED!" << std::endl;
745  else
746  {
747  std::cout << "ublas_A: " << ublas_A << std::endl;
748  std::cout << "vcl_temp: " << vcl_temp << std::endl;
749  std::cout << "vcl_range_A: " << vcl_range_A << std::endl;
750  std::cout << "vcl_A: " << vcl_A << std::endl;
751  std::cout << std::endl << "TEST failed!" << std::endl;
752  return EXIT_FAILURE;
753  }
754 
755  std::cout << "Testing matrix created from slice... ";
756  VCLMatrixType vcl_temp2 = vcl_range_B;
757  if (check_for_equality(ublas_B, vcl_temp2))
758  std::cout << "PASSED!" << std::endl;
759  else
760  {
761  std::cout << std::endl << "TEST failed!" << std::endl;
762  return EXIT_FAILURE;
763  }
764  }
765 
766  std::cout << "//" << std::endl;
767  std::cout << "////////// Test: Initializer for matrix type //////////" << std::endl;
768  std::cout << "//" << std::endl;
769 
770  {
771  boost::numeric::ublas::matrix<ScalarType> ublas_dummy1 = boost::numeric::ublas::identity_matrix<ScalarType>(ublas_A.size1());
772  boost::numeric::ublas::matrix<ScalarType> ublas_dummy2 = boost::numeric::ublas::scalar_matrix<ScalarType>(ublas_A.size1(), ublas_A.size1(), 3);
773  boost::numeric::ublas::matrix<ScalarType> ublas_dummy3 = boost::numeric::ublas::zero_matrix<ScalarType>(ublas_A.size1(), ublas_A.size1());
774 
776  viennacl::matrix<ScalarType> vcl_dummy2 = viennacl::scalar_matrix<ScalarType>(ublas_A.size1(), ublas_A.size1(), 3);
777  viennacl::matrix<ScalarType> vcl_dummy3 = viennacl::zero_matrix<ScalarType>(ublas_A.size1(), ublas_A.size1());
778 
779  std::cout << "Testing initializer CTOR... ";
780  if ( check_for_equality(ublas_dummy1, vcl_dummy1)
781  && check_for_equality(ublas_dummy2, vcl_dummy2)
782  && check_for_equality(ublas_dummy3, vcl_dummy3)
783  )
784  std::cout << "PASSED!" << std::endl;
785  else
786  {
787  std::cout << std::endl << "TEST failed!" << std::endl;
788  return EXIT_FAILURE;
789  }
790 
791  ublas_dummy1 = boost::numeric::ublas::zero_matrix<ScalarType>(ublas_A.size1(), ublas_A.size1());
792  ublas_dummy2 = boost::numeric::ublas::identity_matrix<ScalarType>(ublas_A.size1());
793  ublas_dummy3 = boost::numeric::ublas::scalar_matrix<ScalarType>(ublas_A.size1(), ublas_A.size1(), 3);
794 
795  vcl_dummy1 = viennacl::zero_matrix<ScalarType>(ublas_A.size1(), ublas_A.size1());
796  vcl_dummy2 = viennacl::identity_matrix<ScalarType>(ublas_A.size1());
797  vcl_dummy3 = viennacl::scalar_matrix<ScalarType>(ublas_A.size1(), ublas_A.size1(), 3);
798 
799  std::cout << "Testing initializer assignment... ";
800  if ( check_for_equality(ublas_dummy1, vcl_dummy1)
801  && check_for_equality(ublas_dummy2, vcl_dummy2)
802  && check_for_equality(ublas_dummy3, vcl_dummy3)
803  )
804  std::cout << "PASSED!" << std::endl;
805  else
806  {
807  std::cout << std::endl << "TEST failed!" << std::endl;
808  return EXIT_FAILURE;
809  }
810  }
811 
812 
813  //
814  // run operation tests:
815  //
816 
818  std::cout << "Testing A=matrix, B=matrix, C=matrix ..." << std::endl;
819  viennacl::copy(ublas_A, vcl_A);
820  viennacl::copy(ublas_B, vcl_B);
821  viennacl::copy(ublas_C, vcl_C);
822  if (run_test(ublas_A, ublas_B, ublas_C,
823  vcl_A, vcl_B, vcl_C) != EXIT_SUCCESS)
824  {
825  return EXIT_FAILURE;
826  }
827 
828  std::cout << "Testing A=matrix, B=matrix, C=range ..." << std::endl;
829  viennacl::copy(ublas_A, vcl_A);
830  viennacl::copy(ublas_B, vcl_B);
831  viennacl::copy(ublas_C, vcl_range_C);
832  if (run_test(ublas_A, ublas_B, ublas_C,
833  vcl_A, vcl_B, vcl_range_C) != EXIT_SUCCESS)
834  {
835  return EXIT_FAILURE;
836  }
837 
838  std::cout << "Testing A=matrix, B=matrix, C=slice ..." << std::endl;
839  viennacl::copy(ublas_A, vcl_A);
840  viennacl::copy(ublas_B, vcl_B);
841  viennacl::copy(ublas_C, vcl_slice_C);
842  if (run_test(ublas_A, ublas_B, ublas_C,
843  vcl_A, vcl_B, vcl_slice_C) != EXIT_SUCCESS)
844  {
845  return EXIT_FAILURE;
846  }
847 
848  std::cout << "Testing A=matrix, B=range, C=matrix ..." << std::endl;
849  viennacl::copy(ublas_A, vcl_A);
850  viennacl::copy(ublas_B, vcl_range_B);
851  viennacl::copy(ublas_C, vcl_C);
852  if (run_test(ublas_A, ublas_B, ublas_C,
853  vcl_A, vcl_range_B, vcl_C) != EXIT_SUCCESS)
854  {
855  return EXIT_FAILURE;
856  }
857 
858  std::cout << "Testing A=matrix, B=range, C=range ..." << std::endl;
859  viennacl::copy(ublas_A, vcl_A);
860  viennacl::copy(ublas_B, vcl_range_B);
861  viennacl::copy(ublas_C, vcl_range_C);
862  if (run_test(ublas_A, ublas_B, ublas_C,
863  vcl_A, vcl_range_B, vcl_range_C) != EXIT_SUCCESS)
864  {
865  return EXIT_FAILURE;
866  }
867 
868  std::cout << "Testing A=matrix, B=range, C=slice ..." << std::endl;
869  viennacl::copy(ublas_A, vcl_A);
870  viennacl::copy(ublas_B, vcl_range_B);
871  viennacl::copy(ublas_C, vcl_slice_C);
872  if (run_test(ublas_A, ublas_B, ublas_C,
873  vcl_A, vcl_range_B, vcl_slice_C) != EXIT_SUCCESS)
874  {
875  return EXIT_FAILURE;
876  }
877 
878 
879  std::cout << "Testing A=matrix, B=slice, C=matrix ..." << std::endl;
880  viennacl::copy(ublas_A, vcl_A);
881  viennacl::copy(ublas_B, vcl_slice_B);
882  viennacl::copy(ublas_C, vcl_C);
883  if (run_test(ublas_A, ublas_B, ublas_C,
884  vcl_A, vcl_slice_B, vcl_C) != EXIT_SUCCESS)
885  {
886  return EXIT_FAILURE;
887  }
888 
889  std::cout << "Testing A=matrix, B=slice, C=range ..." << std::endl;
890  viennacl::copy(ublas_A, vcl_A);
891  viennacl::copy(ublas_B, vcl_slice_B);
892  viennacl::copy(ublas_C, vcl_range_C);
893  if (run_test(ublas_A, ublas_B, ublas_C,
894  vcl_A, vcl_slice_B, vcl_range_C) != EXIT_SUCCESS)
895  {
896  return EXIT_FAILURE;
897  }
898 
899  std::cout << "Testing A=matrix, B=slice, C=slice ..." << std::endl;
900  viennacl::copy(ublas_A, vcl_A);
901  viennacl::copy(ublas_B, vcl_slice_B);
902  viennacl::copy(ublas_C, vcl_slice_C);
903  if (run_test(ublas_A, ublas_B, ublas_C,
904  vcl_A, vcl_slice_B, vcl_slice_C) != EXIT_SUCCESS)
905  {
906  return EXIT_FAILURE;
907  }
908 
909 
910 
912  std::cout << "Testing A=range, B=matrix, C=matrix ..." << std::endl;
913  viennacl::copy(ublas_A, vcl_range_A);
914  viennacl::copy(ublas_B, vcl_B);
915  viennacl::copy(ublas_C, vcl_C);
916  if (run_test(ublas_A, ublas_B, ublas_C,
917  vcl_range_A, vcl_B, vcl_C) != EXIT_SUCCESS)
918  {
919  return EXIT_FAILURE;
920  }
921 
922  std::cout << "Testing A=range, B=matrix, C=range ..." << std::endl;
923  viennacl::copy(ublas_A, vcl_range_A);
924  viennacl::copy(ublas_B, vcl_B);
925  viennacl::copy(ublas_C, vcl_range_C);
926  if (run_test(ublas_A, ublas_B, ublas_C,
927  vcl_range_A, vcl_B, vcl_range_C) != EXIT_SUCCESS)
928  {
929  return EXIT_FAILURE;
930  }
931 
932  std::cout << "Testing A=range, B=matrix, C=slice ..." << std::endl;
933  viennacl::copy(ublas_A, vcl_range_A);
934  viennacl::copy(ublas_B, vcl_B);
935  viennacl::copy(ublas_C, vcl_slice_C);
936  if (run_test(ublas_A, ublas_B, ublas_C,
937  vcl_range_A, vcl_B, vcl_slice_C) != EXIT_SUCCESS)
938  {
939  return EXIT_FAILURE;
940  }
941 
942 
943 
944  std::cout << "Testing A=range, B=range, C=matrix ..." << std::endl;
945  viennacl::copy(ublas_A, vcl_range_A);
946  viennacl::copy(ublas_B, vcl_range_B);
947  viennacl::copy(ublas_C, vcl_C);
948  if (run_test(ublas_A, ublas_B, ublas_C,
949  vcl_range_A, vcl_range_B, vcl_C) != EXIT_SUCCESS)
950  {
951  return EXIT_FAILURE;
952  }
953 
954  std::cout << "Testing A=range, B=range, C=range ..." << std::endl;
955  viennacl::copy(ublas_A, vcl_range_A);
956  viennacl::copy(ublas_B, vcl_range_B);
957  viennacl::copy(ublas_C, vcl_range_C);
958  if (run_test(ublas_A, ublas_B, ublas_C,
959  vcl_range_A, vcl_range_B, vcl_range_C) != EXIT_SUCCESS)
960  {
961  return EXIT_FAILURE;
962  }
963 
964  std::cout << "Testing A=range, B=range, C=slice ..." << std::endl;
965  viennacl::copy(ublas_A, vcl_range_A);
966  viennacl::copy(ublas_B, vcl_range_B);
967  viennacl::copy(ublas_C, vcl_slice_C);
968  if (run_test(ublas_A, ublas_B, ublas_C,
969  vcl_range_A, vcl_range_B, vcl_slice_C) != EXIT_SUCCESS)
970  {
971  return EXIT_FAILURE;
972  }
973 
974 
975 
976  std::cout << "Testing A=range, B=slice, C=matrix ..." << std::endl;
977  viennacl::copy(ublas_A, vcl_range_A);
978  viennacl::copy(ublas_B, vcl_slice_B);
979  viennacl::copy(ublas_C, vcl_C);
980  if (run_test(ublas_A, ublas_B, ublas_C,
981  vcl_range_A, vcl_slice_B, vcl_C) != EXIT_SUCCESS)
982  {
983  return EXIT_FAILURE;
984  }
985 
986  std::cout << "Testing A=range, B=slice, C=range ..." << std::endl;
987  viennacl::copy(ublas_A, vcl_range_A);
988  viennacl::copy(ublas_B, vcl_slice_B);
989  viennacl::copy(ublas_C, vcl_range_C);
990  if (run_test(ublas_A, ublas_B, ublas_C,
991  vcl_range_A, vcl_slice_B, vcl_range_C) != EXIT_SUCCESS)
992  {
993  return EXIT_FAILURE;
994  }
995 
996  std::cout << "Testing A=range, B=slice, C=slice ..." << std::endl;
997  viennacl::copy(ublas_A, vcl_range_A);
998  viennacl::copy(ublas_B, vcl_slice_B);
999  viennacl::copy(ublas_C, vcl_slice_C);
1000  if (run_test(ublas_A, ublas_B, ublas_C,
1001  vcl_range_A, vcl_slice_B, vcl_slice_C) != EXIT_SUCCESS)
1002  {
1003  return EXIT_FAILURE;
1004  }
1005 
1006 
1008  std::cout << "Testing A=slice, B=matrix, C=matrix ..." << std::endl;
1009  viennacl::copy(ublas_A, vcl_slice_A);
1010  viennacl::copy(ublas_B, vcl_B);
1011  viennacl::copy(ublas_C, vcl_C);
1012  if (run_test(ublas_A, ublas_B, ublas_C,
1013  vcl_slice_A, vcl_B, vcl_C) != EXIT_SUCCESS)
1014  {
1015  return EXIT_FAILURE;
1016  }
1017 
1018  std::cout << "Testing A=slice, B=matrix, C=range ..." << std::endl;
1019  viennacl::copy(ublas_A, vcl_slice_A);
1020  viennacl::copy(ublas_B, vcl_B);
1021  viennacl::copy(ublas_C, vcl_range_C);
1022  if (run_test(ublas_A, ublas_B, ublas_C,
1023  vcl_slice_A, vcl_B, vcl_range_C) != EXIT_SUCCESS)
1024  {
1025  return EXIT_FAILURE;
1026  }
1027 
1028  std::cout << "Testing A=slice, B=matrix, C=slice ..." << std::endl;
1029  viennacl::copy(ublas_A, vcl_slice_A);
1030  viennacl::copy(ublas_B, vcl_B);
1031  viennacl::copy(ublas_C, vcl_slice_C);
1032  if (run_test(ublas_A, ublas_B, ublas_C,
1033  vcl_slice_A, vcl_B, vcl_slice_C) != EXIT_SUCCESS)
1034  {
1035  return EXIT_FAILURE;
1036  }
1037 
1038 
1039 
1040  std::cout << "Testing A=slice, B=range, C=matrix ..." << std::endl;
1041  viennacl::copy(ublas_A, vcl_slice_A);
1042  viennacl::copy(ublas_B, vcl_range_B);
1043  viennacl::copy(ublas_C, vcl_C);
1044  if (run_test(ublas_A, ublas_B, ublas_C,
1045  vcl_slice_A, vcl_range_B, vcl_C) != EXIT_SUCCESS)
1046  {
1047  return EXIT_FAILURE;
1048  }
1049 
1050  std::cout << "Testing A=slice, B=range, C=range ..." << std::endl;
1051  viennacl::copy(ublas_A, vcl_slice_A);
1052  viennacl::copy(ublas_B, vcl_range_B);
1053  viennacl::copy(ublas_C, vcl_range_C);
1054  if (run_test(ublas_A, ublas_B, ublas_C,
1055  vcl_slice_A, vcl_range_B, vcl_range_C) != EXIT_SUCCESS)
1056  {
1057  return EXIT_FAILURE;
1058  }
1059 
1060  std::cout << "Testing A=slice, B=range, C=slice ..." << std::endl;
1061  viennacl::copy(ublas_A, vcl_slice_A);
1062  viennacl::copy(ublas_B, vcl_range_B);
1063  viennacl::copy(ublas_C, vcl_slice_C);
1064  if (run_test(ublas_A, ublas_B, ublas_C,
1065  vcl_slice_A, vcl_range_B, vcl_slice_C) != EXIT_SUCCESS)
1066  {
1067  return EXIT_FAILURE;
1068  }
1069 
1070 
1071 
1072  std::cout << "Testing A=slice, B=slice, C=matrix ..." << std::endl;
1073  viennacl::copy(ublas_A, vcl_slice_A);
1074  viennacl::copy(ublas_B, vcl_slice_B);
1075  viennacl::copy(ublas_C, vcl_C);
1076  if (run_test(ublas_A, ublas_B, ublas_C,
1077  vcl_slice_A, vcl_slice_B, vcl_C) != EXIT_SUCCESS)
1078  {
1079  return EXIT_FAILURE;
1080  }
1081 
1082  std::cout << "Testing A=slice, B=slice, C=range ..." << std::endl;
1083  viennacl::copy(ublas_A, vcl_slice_A);
1084  viennacl::copy(ublas_B, vcl_slice_B);
1085  viennacl::copy(ublas_C, vcl_range_C);
1086  if (run_test(ublas_A, ublas_B, ublas_C,
1087  vcl_slice_A, vcl_slice_B, vcl_range_C) != EXIT_SUCCESS)
1088  {
1089  return EXIT_FAILURE;
1090  }
1091 
1092  std::cout << "Testing A=slice, B=slice, C=slice ..." << std::endl;
1093  viennacl::copy(ublas_A, vcl_slice_A);
1094  viennacl::copy(ublas_B, vcl_slice_B);
1095  viennacl::copy(ublas_C, vcl_slice_C);
1096  if (run_test(ublas_A, ublas_B, ublas_C,
1097  vcl_slice_A, vcl_slice_B, vcl_slice_C) != EXIT_SUCCESS)
1098  {
1099  return EXIT_FAILURE;
1100  }
1101 
1102 
1103  return EXIT_SUCCESS;
1104 }
1105 
1106 
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)
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:227
Class for representing strided submatrices of a bigger matrix A.
Definition: forwards.h:443
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:375
Represents a vector consisting of 1 at a given index and zeros otherwise. To be used as an initialize...
Definition: matrix_def.hpp:69
Represents a vector consisting of scalars 's' only, i.e. v[i] = s for all i. To be used as an initial...
Definition: matrix_def.hpp:93
bool check_for_equality(MatrixType const &ublas_A, VCLMatrixType const &vcl_A)
Definition: matrix_int.hpp:50
#define GENERATE_UNARY_OP_TEST(FUNCNAME)
Represents a vector consisting of zeros only. To be used as an initializer for viennacl::vector, vector_range, or vector_slize only.
Definition: matrix_def.hpp:81
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
Definition: result_of.hpp:271
Proxy classes for vectors.
Proxy classes for matrices.
int run_test(UBLASMatrixType &ublas_A, UBLASMatrixType &ublas_B, UBLASMatrixType &ublas_C, ViennaCLMatrixType1 &vcl_A, ViennaCLMatrixType2 &vcl_B, ViennaCLMatrixType3 vcl_C)
Definition: matrix_int.hpp:80
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: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)
Class for representing non-strided submatrices of a bigger matrix A.
Definition: forwards.h:440
A slice class that refers to an interval [start, stop), where 'start' is included, and 'stop' is excluded.
Definition: forwards.h:429
Implementation of the ViennaCL scalar class.