ViennaCL - The Vienna Computing Library: tests/src/matrix_int.hpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

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