ViennaCL - The Vienna Computing Library: viennacl/linalg/vector_operations.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
vector_operations.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_VECTOR_OPERATIONS_HPP_
2 #define VIENNACL_LINALG_VECTOR_OPERATIONS_HPP_
3
4 /* =========================================================================
5 Copyright (c) 2010-2016, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8 Portions of this software are copyright by UChicago Argonne, LLC.
9
10 -----------------
11 ViennaCL - The Vienna Computing Library
12 -----------------
13
14 Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15
16 (A list of authors and contributors can be found in the manual)
17
18 License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20
25 #include "viennacl/forwards.h"
26 #include "viennacl/range.hpp"
27 #include "viennacl/scalar.hpp"
28 #include "viennacl/tools/tools.hpp"
29 #include "viennacl/meta/predicate.hpp"
30 #include "viennacl/meta/enable_if.hpp"
31 #include "viennacl/traits/size.hpp"
32 #include "viennacl/traits/start.hpp"
33 #include "viennacl/traits/handle.hpp"
34 #include "viennacl/traits/stride.hpp"
35 #include "viennacl/linalg/detail/op_executor.hpp"
36 #include "viennacl/linalg/host_based/vector_operations.hpp"
37
38 #ifdef VIENNACL_WITH_OPENCL
39 #include "viennacl/linalg/opencl/vector_operations.hpp"
40 #endif
41
42 #ifdef VIENNACL_WITH_CUDA
43 #include "viennacl/linalg/cuda/vector_operations.hpp"
44 #endif
45
46 namespace viennacl
47 {
48 namespace linalg
49 {
50 template<typename DestNumericT, typename SrcNumericT>
51 void convert(vector_base<DestNumericT> & dest, vector_base<SrcNumericT> const & src)
52 {
53 assert(viennacl::traits::size(dest) == viennacl::traits::size(src) && bool("Incompatible vector sizes in v1 = v2 (convert): size(v1) != size(v2)"));
54
55 switch (viennacl::traits::handle(dest).get_active_handle_id())
56 {
57 case viennacl::MAIN_MEMORY:
58 viennacl::linalg::host_based::convert(dest, src);
59 break;
60 #ifdef VIENNACL_WITH_OPENCL
61 case viennacl::OPENCL_MEMORY:
62 viennacl::linalg::opencl::convert(dest, src);
63 break;
64 #endif
65 #ifdef VIENNACL_WITH_CUDA
66 case viennacl::CUDA_MEMORY:
67 viennacl::linalg::cuda::convert(dest, src);
68 break;
69 #endif
70 case viennacl::MEMORY_NOT_INITIALIZED:
71 throw memory_exception("not initialised!");
72 default:
73 throw memory_exception("not implemented");
74 }
75 }
76
77 template<typename T, typename ScalarType1>
78 void av(vector_base<T> & vec1,
79 vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
80 {
81 assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 = v2 @ alpha: size(v1) != size(v2)"));
82
83 switch (viennacl::traits::handle(vec1).get_active_handle_id())
84 {
85 case viennacl::MAIN_MEMORY:
86 viennacl::linalg::host_based::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
87 break;
88 #ifdef VIENNACL_WITH_OPENCL
89 case viennacl::OPENCL_MEMORY:
90 viennacl::linalg::opencl::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
91 break;
92 #endif
93 #ifdef VIENNACL_WITH_CUDA
94 case viennacl::CUDA_MEMORY:
95 viennacl::linalg::cuda::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
96 break;
97 #endif
98 case viennacl::MEMORY_NOT_INITIALIZED:
99 throw memory_exception("not initialised!");
100 default:
101 throw memory_exception("not implemented");
102 }
103 }
104
105
106 template<typename T, typename ScalarType1, typename ScalarType2>
107 void avbv(vector_base<T> & vec1,
108 vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
109 vector_base<T> const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
110 {
111 assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 = v2 @ alpha + v3 @ beta: size(v1) != size(v2)"));
112 assert(viennacl::traits::size(vec2) == viennacl::traits::size(vec3) && bool("Incompatible vector sizes in v1 = v2 @ alpha + v3 @ beta: size(v2) != size(v3)"));
113
114 switch (viennacl::traits::handle(vec1).get_active_handle_id())
115 {
116 case viennacl::MAIN_MEMORY:
117 viennacl::linalg::host_based::avbv(vec1,
118 vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
119 vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
120 break;
121 #ifdef VIENNACL_WITH_OPENCL
122 case viennacl::OPENCL_MEMORY:
123 viennacl::linalg::opencl::avbv(vec1,
124 vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
125 vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
126 break;
127 #endif
128 #ifdef VIENNACL_WITH_CUDA
129 case viennacl::CUDA_MEMORY:
130 viennacl::linalg::cuda::avbv(vec1,
131 vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
132 vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
133 break;
134 #endif
135 case viennacl::MEMORY_NOT_INITIALIZED:
136 throw memory_exception("not initialised!");
137 default:
138 throw memory_exception("not implemented");
139 }
140 }
141
142
143 template<typename T, typename ScalarType1, typename ScalarType2>
144 void avbv_v(vector_base<T> & vec1,
145 vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
146 vector_base<T> const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
147 {
148 assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 += v2 @ alpha + v3 @ beta: size(v1) != size(v2)"));
149 assert(viennacl::traits::size(vec2) == viennacl::traits::size(vec3) && bool("Incompatible vector sizes in v1 += v2 @ alpha + v3 @ beta: size(v2) != size(v3)"));
150
151 switch (viennacl::traits::handle(vec1).get_active_handle_id())
152 {
153 case viennacl::MAIN_MEMORY:
154 viennacl::linalg::host_based::avbv_v(vec1,
155 vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
156 vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
157 break;
158 #ifdef VIENNACL_WITH_OPENCL
159 case viennacl::OPENCL_MEMORY:
160 viennacl::linalg::opencl::avbv_v(vec1,
161 vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
162 vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
163 break;
164 #endif
165 #ifdef VIENNACL_WITH_CUDA
166 case viennacl::CUDA_MEMORY:
167 viennacl::linalg::cuda::avbv_v(vec1,
168 vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
169 vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
170 break;
171 #endif
172 case viennacl::MEMORY_NOT_INITIALIZED:
173 throw memory_exception("not initialised!");
174 default:
175 throw memory_exception("not implemented");
176 }
177 }
178
179
186 template<typename T>
187 void vector_assign(vector_base<T> & vec1, const T & alpha, bool up_to_internal_size = false)
188 {
189 switch (viennacl::traits::handle(vec1).get_active_handle_id())
190 {
191 case viennacl::MAIN_MEMORY:
192 viennacl::linalg::host_based::vector_assign(vec1, alpha, up_to_internal_size);
193 break;
194 #ifdef VIENNACL_WITH_OPENCL
195 case viennacl::OPENCL_MEMORY:
196 viennacl::linalg::opencl::vector_assign(vec1, alpha, up_to_internal_size);
197 break;
198 #endif
199 #ifdef VIENNACL_WITH_CUDA
200 case viennacl::CUDA_MEMORY:
201 viennacl::linalg::cuda::vector_assign(vec1, alpha, up_to_internal_size);
202 break;
203 #endif
204 case viennacl::MEMORY_NOT_INITIALIZED:
205 throw memory_exception("not initialised!");
206 default:
207 throw memory_exception("not implemented");
208 }
209 }
210
211
217 template<typename T>
218 void vector_swap(vector_base<T> & vec1, vector_base<T> & vec2)
219 {
220 assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in vector_swap()"));
221
222 switch (viennacl::traits::handle(vec1).get_active_handle_id())
223 {
224 case viennacl::MAIN_MEMORY:
225 viennacl::linalg::host_based::vector_swap(vec1, vec2);
226 break;
227 #ifdef VIENNACL_WITH_OPENCL
228 case viennacl::OPENCL_MEMORY:
229 viennacl::linalg::opencl::vector_swap(vec1, vec2);
230 break;
231 #endif
232 #ifdef VIENNACL_WITH_CUDA
233 case viennacl::CUDA_MEMORY:
234 viennacl::linalg::cuda::vector_swap(vec1, vec2);
235 break;
236 #endif
237 case viennacl::MEMORY_NOT_INITIALIZED:
238 throw memory_exception("not initialised!");
239 default:
240 throw memory_exception("not implemented");
241 }
242 }
243
244
246
247
248
254 template<typename T, typename OP>
255 void element_op(vector_base<T> & vec1,
256 vector_expression<const vector_base<T>, const vector_base<T>, OP> const & proxy)
257 {
258 assert(viennacl::traits::size(vec1) == viennacl::traits::size(proxy) && bool("Incompatible vector sizes in element_op()"));
259
260 switch (viennacl::traits::handle(vec1).get_active_handle_id())
261 {
262 case viennacl::MAIN_MEMORY:
263 viennacl::linalg::host_based::element_op(vec1, proxy);
264 break;
265 #ifdef VIENNACL_WITH_OPENCL
266 case viennacl::OPENCL_MEMORY:
267 viennacl::linalg::opencl::element_op(vec1, proxy);
268 break;
269 #endif
270 #ifdef VIENNACL_WITH_CUDA
271 case viennacl::CUDA_MEMORY:
272 viennacl::linalg::cuda::element_op(vec1, proxy);
273 break;
274 #endif
275 case viennacl::MEMORY_NOT_INITIALIZED:
276 throw memory_exception("not initialised!");
277 default:
278 throw memory_exception("not implemented");
279 }
280 }
281
284 // Helper macro for generating binary element-wise operations such as element_prod(), element_div(), element_pow() without unnecessary code duplication */
285 #define VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(OPNAME) \
286 template<typename T> \
287 viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_binary<op_##OPNAME> > \
288 element_##OPNAME(vector_base<T> const & v1, vector_base<T> const & v2) \
289 { \
290 return viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_binary<op_##OPNAME> >(v1, v2); \
291 } \
292 \
293 template<typename V1, typename V2, typename OP, typename T> \
294 viennacl::vector_expression<const vector_expression<const V1, const V2, OP>, const vector_base<T>, op_element_binary<op_##OPNAME> > \
295 element_##OPNAME(vector_expression<const V1, const V2, OP> const & proxy, vector_base<T> const & v2) \
296 { \
297 return viennacl::vector_expression<const vector_expression<const V1, const V2, OP>, const vector_base<T>, op_element_binary<op_##OPNAME> >(proxy, v2); \
298 } \
299 \
300 template<typename T, typename V2, typename V3, typename OP> \
301 viennacl::vector_expression<const vector_base<T>, const vector_expression<const V2, const V3, OP>, op_element_binary<op_##OPNAME> > \
302 element_##OPNAME(vector_base<T> const & v1, vector_expression<const V2, const V3, OP> const & proxy) \
303 { \
304 return viennacl::vector_expression<const vector_base<T>, const vector_expression<const V2, const V3, OP>, op_element_binary<op_##OPNAME> >(v1, proxy); \
305 } \
306 \
307 template<typename V1, typename V2, typename OP1, \
308 typename V3, typename V4, typename OP2> \
309 viennacl::vector_expression<const vector_expression<const V1, const V2, OP1>, \
310 const vector_expression<const V3, const V4, OP2>, \
311 op_element_binary<op_##OPNAME> > \
312 element_##OPNAME(vector_expression<const V1, const V2, OP1> const & proxy1, \
313 vector_expression<const V3, const V4, OP2> const & proxy2) \
314 {\
315 return viennacl::vector_expression<const vector_expression<const V1, const V2, OP1>, \
316 const vector_expression<const V3, const V4, OP2>, \
317 op_element_binary<op_##OPNAME> >(proxy1, proxy2); \
318 }
319
320 VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(prod) //for element_prod()
321 VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(div) //for element_div()
322 VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(pow) //for element_pow()
323
324 VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(eq)
325 VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(neq)
326 VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(greater)
327 VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(less)
328 VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(geq)
329 VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(leq)
330
331 #undef VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS
332
333 // Helper macro for generating unary element-wise operations such as element_exp(), element_sin(), etc. without unnecessary code duplication */
334 #define VIENNACL_MAKE_UNARY_ELEMENT_OP(funcname) \
335 template<typename T> \
336 viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_unary<op_##funcname> > \
337 element_##funcname(vector_base<T> const & v) \
338 { \
339 return viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_unary<op_##funcname> >(v, v); \
340 } \
341 template<typename LHS, typename RHS, typename OP> \
342 viennacl::vector_expression<const vector_expression<const LHS, const RHS, OP>, \
343 const vector_expression<const LHS, const RHS, OP>, \
344 op_element_unary<op_##funcname> > \
345 element_##funcname(vector_expression<const LHS, const RHS, OP> const & proxy) \
346 { \
347 return viennacl::vector_expression<const vector_expression<const LHS, const RHS, OP>, \
348 const vector_expression<const LHS, const RHS, OP>, \
349 op_element_unary<op_##funcname> >(proxy, proxy); \
350 } \
351
352 VIENNACL_MAKE_UNARY_ELEMENT_OP(abs)
353 VIENNACL_MAKE_UNARY_ELEMENT_OP(acos)
354 VIENNACL_MAKE_UNARY_ELEMENT_OP(asin)
355 VIENNACL_MAKE_UNARY_ELEMENT_OP(atan)
356 VIENNACL_MAKE_UNARY_ELEMENT_OP(ceil)
357 VIENNACL_MAKE_UNARY_ELEMENT_OP(cos)
358 VIENNACL_MAKE_UNARY_ELEMENT_OP(cosh)
359 VIENNACL_MAKE_UNARY_ELEMENT_OP(exp)
360 VIENNACL_MAKE_UNARY_ELEMENT_OP(fabs)
361 VIENNACL_MAKE_UNARY_ELEMENT_OP(floor)
362 VIENNACL_MAKE_UNARY_ELEMENT_OP(log)
363 VIENNACL_MAKE_UNARY_ELEMENT_OP(log10)
364 VIENNACL_MAKE_UNARY_ELEMENT_OP(sin)
365 VIENNACL_MAKE_UNARY_ELEMENT_OP(sinh)
366 VIENNACL_MAKE_UNARY_ELEMENT_OP(sqrt)
367 VIENNACL_MAKE_UNARY_ELEMENT_OP(tan)
368 VIENNACL_MAKE_UNARY_ELEMENT_OP(tanh)
369
370 #undef VIENNACL_MAKE_UNARY_ELEMENT_OP
371
374
376
377 //implementation of inner product:
378 //namespace {
379
386 template<typename T>
387 void inner_prod_impl(vector_base<T> const & vec1,
388 vector_base<T> const & vec2,
389 scalar<T> & result)
390 {
391 assert( vec1.size() == vec2.size() && bool("Size mismatch") );
392
393 switch (viennacl::traits::handle(vec1).get_active_handle_id())
394 {
395 case viennacl::MAIN_MEMORY:
396 viennacl::linalg::host_based::inner_prod_impl(vec1, vec2, result);
397 break;
398 #ifdef VIENNACL_WITH_OPENCL
399 case viennacl::OPENCL_MEMORY:
400 viennacl::linalg::opencl::inner_prod_impl(vec1, vec2, result);
401 break;
402 #endif
403 #ifdef VIENNACL_WITH_CUDA
404 case viennacl::CUDA_MEMORY:
405 viennacl::linalg::cuda::inner_prod_impl(vec1, vec2, result);
406 break;
407 #endif
408 case viennacl::MEMORY_NOT_INITIALIZED:
409 throw memory_exception("not initialised!");
410 default:
411 throw memory_exception("not implemented");
412 }
413 }
414
415 // vector expression on lhs
416 template<typename LHS, typename RHS, typename OP, typename T>
417 void inner_prod_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec1,
418 vector_base<T> const & vec2,
419 scalar<T> & result)
420 {
421 viennacl::vector<T> temp = vec1;
422 inner_prod_impl(temp, vec2, result);
423 }
424
425
426 // vector expression on rhs
427 template<typename T, typename LHS, typename RHS, typename OP>
428 void inner_prod_impl(vector_base<T> const & vec1,
429 viennacl::vector_expression<LHS, RHS, OP> const & vec2,
430 scalar<T> & result)
431 {
432 viennacl::vector<T> temp = vec2;
433 inner_prod_impl(vec1, temp, result);
434 }
435
436
437 // vector expression on lhs and rhs
438 template<typename LHS1, typename RHS1, typename OP1,
439 typename LHS2, typename RHS2, typename OP2, typename T>
440 void inner_prod_impl(viennacl::vector_expression<LHS1, RHS1, OP1> const & vec1,
441 viennacl::vector_expression<LHS2, RHS2, OP2> const & vec2,
442 scalar<T> & result)
443 {
444 viennacl::vector<T> temp1 = vec1;
445 viennacl::vector<T> temp2 = vec2;
446 inner_prod_impl(temp1, temp2, result);
447 }
448
449
450
451
458 template<typename T>
459 void inner_prod_cpu(vector_base<T> const & vec1,
460 vector_base<T> const & vec2,
461 T & result)
462 {
463 assert( vec1.size() == vec2.size() && bool("Size mismatch") );
464
465 switch (viennacl::traits::handle(vec1).get_active_handle_id())
466 {
467 case viennacl::MAIN_MEMORY:
468 viennacl::linalg::host_based::inner_prod_impl(vec1, vec2, result);
469 break;
470 #ifdef VIENNACL_WITH_OPENCL
471 case viennacl::OPENCL_MEMORY:
472 viennacl::linalg::opencl::inner_prod_cpu(vec1, vec2, result);
473 break;
474 #endif
475 #ifdef VIENNACL_WITH_CUDA
476 case viennacl::CUDA_MEMORY:
477 viennacl::linalg::cuda::inner_prod_cpu(vec1, vec2, result);
478 break;
479 #endif
480 case viennacl::MEMORY_NOT_INITIALIZED:
481 throw memory_exception("not initialised!");
482 default:
483 throw memory_exception("not implemented");
484 }
485 }
486
487 // vector expression on lhs
488 template<typename LHS, typename RHS, typename OP, typename T>
489 void inner_prod_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec1,
490 vector_base<T> const & vec2,
491 T & result)
492 {
493 viennacl::vector<T> temp = vec1;
494 inner_prod_cpu(temp, vec2, result);
495 }
496
497
498 // vector expression on rhs
499 template<typename T, typename LHS, typename RHS, typename OP>
500 void inner_prod_cpu(vector_base<T> const & vec1,
501 viennacl::vector_expression<LHS, RHS, OP> const & vec2,
502 T & result)
503 {
504 viennacl::vector<T> temp = vec2;
505 inner_prod_cpu(vec1, temp, result);
506 }
507
508
509 // vector expression on lhs and rhs
510 template<typename LHS1, typename RHS1, typename OP1,
511 typename LHS2, typename RHS2, typename OP2, typename S3>
512 void inner_prod_cpu(viennacl::vector_expression<LHS1, RHS1, OP1> const & vec1,
513 viennacl::vector_expression<LHS2, RHS2, OP2> const & vec2,
514 S3 & result)
515 {
516 viennacl::vector<S3> temp1 = vec1;
517 viennacl::vector<S3> temp2 = vec2;
518 inner_prod_cpu(temp1, temp2, result);
519 }
520
521
522
529 template<typename T>
530 void inner_prod_impl(vector_base<T> const & x,
531 vector_tuple<T> const & y_tuple,
532 vector_base<T> & result)
533 {
534 assert( x.size() == y_tuple.const_at(0).size() && bool("Size mismatch") );
535 assert( result.size() == y_tuple.const_size() && bool("Number of elements does not match result size") );
536
537 switch (viennacl::traits::handle(x).get_active_handle_id())
538 {
539 case viennacl::MAIN_MEMORY:
540 viennacl::linalg::host_based::inner_prod_impl(x, y_tuple, result);
541 break;
542 #ifdef VIENNACL_WITH_OPENCL
543 case viennacl::OPENCL_MEMORY:
544 viennacl::linalg::opencl::inner_prod_impl(x, y_tuple, result);
545 break;
546 #endif
547 #ifdef VIENNACL_WITH_CUDA
548 case viennacl::CUDA_MEMORY:
549 viennacl::linalg::cuda::inner_prod_impl(x, y_tuple, result);
550 break;
551 #endif
552 case viennacl::MEMORY_NOT_INITIALIZED:
553 throw memory_exception("not initialised!");
554 default:
555 throw memory_exception("not implemented");
556 }
557 }
558
559
565 template<typename T>
566 void norm_1_impl(vector_base<T> const & vec,
567 scalar<T> & result)
568 {
569 switch (viennacl::traits::handle(vec).get_active_handle_id())
570 {
571 case viennacl::MAIN_MEMORY:
572 viennacl::linalg::host_based::norm_1_impl(vec, result);
573 break;
574 #ifdef VIENNACL_WITH_OPENCL
575 case viennacl::OPENCL_MEMORY:
576 viennacl::linalg::opencl::norm_1_impl(vec, result);
577 break;
578 #endif
579 #ifdef VIENNACL_WITH_CUDA
580 case viennacl::CUDA_MEMORY:
581 viennacl::linalg::cuda::norm_1_impl(vec, result);
582 break;
583 #endif
584 case viennacl::MEMORY_NOT_INITIALIZED:
585 throw memory_exception("not initialised!");
586 default:
587 throw memory_exception("not implemented");
588 }
589 }
590
591
597 template<typename LHS, typename RHS, typename OP, typename S2>
598 void norm_1_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec,
599 S2 & result)
600 {
601 viennacl::vector<typename viennacl::result_of::cpu_value_type<S2>::type> temp = vec;
602 norm_1_impl(temp, result);
603 }
604
605
606
612 template<typename T>
613 void norm_1_cpu(vector_base<T> const & vec,
614 T & result)
615 {
616 switch (viennacl::traits::handle(vec).get_active_handle_id())
617 {
618 case viennacl::MAIN_MEMORY:
619 viennacl::linalg::host_based::norm_1_impl(vec, result);
620 break;
621 #ifdef VIENNACL_WITH_OPENCL
622 case viennacl::OPENCL_MEMORY:
623 viennacl::linalg::opencl::norm_1_cpu(vec, result);
624 break;
625 #endif
626 #ifdef VIENNACL_WITH_CUDA
627 case viennacl::CUDA_MEMORY:
628 viennacl::linalg::cuda::norm_1_cpu(vec, result);
629 break;
630 #endif
631 case viennacl::MEMORY_NOT_INITIALIZED:
632 throw memory_exception("not initialised!");
633 default:
634 throw memory_exception("not implemented");
635 }
636 }
637
643 template<typename LHS, typename RHS, typename OP, typename S2>
644 void norm_1_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec,
645 S2 & result)
646 {
647 viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
648 norm_1_cpu(temp, result);
649 }
650
651
652
653
659 template<typename T>
660 void norm_2_impl(vector_base<T> const & vec,
661 scalar<T> & result)
662 {
663 switch (viennacl::traits::handle(vec).get_active_handle_id())
664 {
665 case viennacl::MAIN_MEMORY:
666 viennacl::linalg::host_based::norm_2_impl(vec, result);
667 break;
668 #ifdef VIENNACL_WITH_OPENCL
669 case viennacl::OPENCL_MEMORY:
670 viennacl::linalg::opencl::norm_2_impl(vec, result);
671 break;
672 #endif
673 #ifdef VIENNACL_WITH_CUDA
674 case viennacl::CUDA_MEMORY:
675 viennacl::linalg::cuda::norm_2_impl(vec, result);
676 break;
677 #endif
678 case viennacl::MEMORY_NOT_INITIALIZED:
679 throw memory_exception("not initialised!");
680 default:
681 throw memory_exception("not implemented");
682 }
683 }
684
690 template<typename LHS, typename RHS, typename OP, typename T>
691 void norm_2_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec,
692 scalar<T> & result)
693 {
694 viennacl::vector<T> temp = vec;
695 norm_2_impl(temp, result);
696 }
697
698
704 template<typename T>
705 void norm_2_cpu(vector_base<T> const & vec,
706 T & result)
707 {
708 switch (viennacl::traits::handle(vec).get_active_handle_id())
709 {
710 case viennacl::MAIN_MEMORY:
711 viennacl::linalg::host_based::norm_2_impl(vec, result);
712 break;
713 #ifdef VIENNACL_WITH_OPENCL
714 case viennacl::OPENCL_MEMORY:
715 viennacl::linalg::opencl::norm_2_cpu(vec, result);
716 break;
717 #endif
718 #ifdef VIENNACL_WITH_CUDA
719 case viennacl::CUDA_MEMORY:
720 viennacl::linalg::cuda::norm_2_cpu(vec, result);
721 break;
722 #endif
723 case viennacl::MEMORY_NOT_INITIALIZED:
724 throw memory_exception("not initialised!");
725 default:
726 throw memory_exception("not implemented");
727 }
728 }
729
735 template<typename LHS, typename RHS, typename OP, typename S2>
736 void norm_2_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec,
737 S2 & result)
738 {
739 viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
740 norm_2_cpu(temp, result);
741 }
742
743
744
745
751 template<typename T>
752 void norm_inf_impl(vector_base<T> const & vec,
753 scalar<T> & result)
754 {
755 switch (viennacl::traits::handle(vec).get_active_handle_id())
756 {
757 case viennacl::MAIN_MEMORY:
758 viennacl::linalg::host_based::norm_inf_impl(vec, result);
759 break;
760 #ifdef VIENNACL_WITH_OPENCL
761 case viennacl::OPENCL_MEMORY:
762 viennacl::linalg::opencl::norm_inf_impl(vec, result);
763 break;
764 #endif
765 #ifdef VIENNACL_WITH_CUDA
766 case viennacl::CUDA_MEMORY:
767 viennacl::linalg::cuda::norm_inf_impl(vec, result);
768 break;
769 #endif
770 case viennacl::MEMORY_NOT_INITIALIZED:
771 throw memory_exception("not initialised!");
772 default:
773 throw memory_exception("not implemented");
774 }
775 }
776
782 template<typename LHS, typename RHS, typename OP, typename T>
783 void norm_inf_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec,
784 scalar<T> & result)
785 {
786 viennacl::vector<T> temp = vec;
787 norm_inf_impl(temp, result);
788 }
789
790
796 template<typename T>
797 void norm_inf_cpu(vector_base<T> const & vec,
798 T & result)
799 {
800 switch (viennacl::traits::handle(vec).get_active_handle_id())
801 {
802 case viennacl::MAIN_MEMORY:
803 viennacl::linalg::host_based::norm_inf_impl(vec, result);
804 break;
805 #ifdef VIENNACL_WITH_OPENCL
806 case viennacl::OPENCL_MEMORY:
807 viennacl::linalg::opencl::norm_inf_cpu(vec, result);
808 break;
809 #endif
810 #ifdef VIENNACL_WITH_CUDA
811 case viennacl::CUDA_MEMORY:
812 viennacl::linalg::cuda::norm_inf_cpu(vec, result);
813 break;
814 #endif
815 case viennacl::MEMORY_NOT_INITIALIZED:
816 throw memory_exception("not initialised!");
817 default:
818 throw memory_exception("not implemented");
819 }
820 }
821
827 template<typename LHS, typename RHS, typename OP, typename S2>
828 void norm_inf_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec,
829 S2 & result)
830 {
831 viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
832 norm_inf_cpu(temp, result);
833 }
834
835
836 //This function should return a CPU scalar, otherwise statements like
837 // vcl_rhs[index_norm_inf(vcl_rhs)]
838 // are ambiguous
844 template<typename T>
845 vcl_size_t index_norm_inf(vector_base<T> const & vec)
846 {
847 switch (viennacl::traits::handle(vec).get_active_handle_id())
848 {
849 case viennacl::MAIN_MEMORY:
850 return viennacl::linalg::host_based::index_norm_inf(vec);
851 #ifdef VIENNACL_WITH_OPENCL
852 case viennacl::OPENCL_MEMORY:
853 return viennacl::linalg::opencl::index_norm_inf(vec);
854 #endif
855 #ifdef VIENNACL_WITH_CUDA
856 case viennacl::CUDA_MEMORY:
857 return viennacl::linalg::cuda::index_norm_inf(vec);
858 #endif
859 case viennacl::MEMORY_NOT_INITIALIZED:
860 throw memory_exception("not initialised!");
861 default:
862 throw memory_exception("not implemented");
863 }
864 }
865
870 template<typename LHS, typename RHS, typename OP>
871 vcl_size_t index_norm_inf(viennacl::vector_expression<LHS, RHS, OP> const & vec)
872 {
873 viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
874 return index_norm_inf(temp);
875 }
876
878
884 template<typename NumericT>
885 void max_impl(vector_base<NumericT> const & vec, viennacl::scalar<NumericT> & result)
886 {
887 switch (viennacl::traits::handle(vec).get_active_handle_id())
888 {
889 case viennacl::MAIN_MEMORY:
890 viennacl::linalg::host_based::max_impl(vec, result);
891 break;
892 #ifdef VIENNACL_WITH_OPENCL
893 case viennacl::OPENCL_MEMORY:
894 viennacl::linalg::opencl::max_impl(vec, result);
895 break;
896 #endif
897 #ifdef VIENNACL_WITH_CUDA
898 case viennacl::CUDA_MEMORY:
899 viennacl::linalg::cuda::max_impl(vec, result);
900 break;
901 #endif
902 case viennacl::MEMORY_NOT_INITIALIZED:
903 throw memory_exception("not initialised!");
904 default:
905 throw memory_exception("not implemented");
906 }
907 }
908
914 template<typename LHS, typename RHS, typename OP, typename NumericT>
915 void max_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec, viennacl::scalar<NumericT> & result)
916 {
917 viennacl::vector<NumericT> temp = vec;
918 max_impl(temp, result);
919 }
920
921
927 template<typename T>
928 void max_cpu(vector_base<T> const & vec, T & result)
929 {
930 switch (viennacl::traits::handle(vec).get_active_handle_id())
931 {
932 case viennacl::MAIN_MEMORY:
933 viennacl::linalg::host_based::max_impl(vec, result);
934 break;
935 #ifdef VIENNACL_WITH_OPENCL
936 case viennacl::OPENCL_MEMORY:
937 viennacl::linalg::opencl::max_cpu(vec, result);
938 break;
939 #endif
940 #ifdef VIENNACL_WITH_CUDA
941 case viennacl::CUDA_MEMORY:
942 viennacl::linalg::cuda::max_cpu(vec, result);
943 break;
944 #endif
945 case viennacl::MEMORY_NOT_INITIALIZED:
946 throw memory_exception("not initialised!");
947 default:
948 throw memory_exception("not implemented");
949 }
950 }
951
957 template<typename LHS, typename RHS, typename OP, typename S2>
958 void max_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec, S2 & result)
959 {
960 viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
961 max_cpu(temp, result);
962 }
963
965
971 template<typename NumericT>
972 void min_impl(vector_base<NumericT> const & vec, viennacl::scalar<NumericT> & result)
973 {
974 switch (viennacl::traits::handle(vec).get_active_handle_id())
975 {
976 case viennacl::MAIN_MEMORY:
977 viennacl::linalg::host_based::min_impl(vec, result);
978 break;
979 #ifdef VIENNACL_WITH_OPENCL
980 case viennacl::OPENCL_MEMORY:
981 viennacl::linalg::opencl::min_impl(vec, result);
982 break;
983 #endif
984 #ifdef VIENNACL_WITH_CUDA
985 case viennacl::CUDA_MEMORY:
986 viennacl::linalg::cuda::min_impl(vec, result);
987 break;
988 #endif
989 case viennacl::MEMORY_NOT_INITIALIZED:
990 throw memory_exception("not initialised!");
991 default:
992 throw memory_exception("not implemented");
993 }
994 }
995
1001 template<typename LHS, typename RHS, typename OP, typename NumericT>
1002 void min_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec, viennacl::scalar<NumericT> & result)
1003 {
1004 viennacl::vector<NumericT> temp = vec;
1005 min_impl(temp, result);
1006 }
1007
1008
1014 template<typename T>
1015 void min_cpu(vector_base<T> const & vec, T & result)
1016 {
1017 switch (viennacl::traits::handle(vec).get_active_handle_id())
1018 {
1019 case viennacl::MAIN_MEMORY:
1020 viennacl::linalg::host_based::min_impl(vec, result);
1021 break;
1022 #ifdef VIENNACL_WITH_OPENCL
1023 case viennacl::OPENCL_MEMORY:
1024 viennacl::linalg::opencl::min_cpu(vec, result);
1025 break;
1026 #endif
1027 #ifdef VIENNACL_WITH_CUDA
1028 case viennacl::CUDA_MEMORY:
1029 viennacl::linalg::cuda::min_cpu(vec, result);
1030 break;
1031 #endif
1032 case viennacl::MEMORY_NOT_INITIALIZED:
1033 throw memory_exception("not initialised!");
1034 default:
1035 throw memory_exception("not implemented");
1036 }
1037 }
1038
1044 template<typename LHS, typename RHS, typename OP, typename S2>
1045 void min_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec, S2 & result)
1046 {
1047 viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
1048 min_cpu(temp, result);
1049 }
1050
1052
1058 template<typename NumericT>
1059 void sum_impl(vector_base<NumericT> const & vec, viennacl::scalar<NumericT> & result)
1060 {
1061 switch (viennacl::traits::handle(vec).get_active_handle_id())
1062 {
1063 case viennacl::MAIN_MEMORY:
1064 viennacl::linalg::host_based::sum_impl(vec, result);
1065 break;
1066 #ifdef VIENNACL_WITH_OPENCL
1067 case viennacl::OPENCL_MEMORY:
1068 viennacl::linalg::opencl::sum_impl(vec, result);
1069 break;
1070 #endif
1071 #ifdef VIENNACL_WITH_CUDA
1072 case viennacl::CUDA_MEMORY:
1073 viennacl::linalg::cuda::sum_impl(vec, result);
1074 break;
1075 #endif
1076 case viennacl::MEMORY_NOT_INITIALIZED:
1077 throw memory_exception("not initialised!");
1078 default:
1079 throw memory_exception("not implemented");
1080 }
1081 }
1082
1088 template<typename LHS, typename RHS, typename OP, typename NumericT>
1089 void sum_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec, viennacl::scalar<NumericT> & result)
1090 {
1091 viennacl::vector<NumericT> temp = vec;
1092 sum_impl(temp, result);
1093 }
1094
1095
1101 template<typename T>
1102 void sum_cpu(vector_base<T> const & vec, T & result)
1103 {
1104 switch (viennacl::traits::handle(vec).get_active_handle_id())
1105 {
1106 case viennacl::MAIN_MEMORY:
1107 viennacl::linalg::host_based::sum_impl(vec, result);
1108 break;
1109 #ifdef VIENNACL_WITH_OPENCL
1110 case viennacl::OPENCL_MEMORY:
1111 viennacl::linalg::opencl::sum_cpu(vec, result);
1112 break;
1113 #endif
1114 #ifdef VIENNACL_WITH_CUDA
1115 case viennacl::CUDA_MEMORY:
1116 viennacl::linalg::cuda::sum_cpu(vec, result);
1117 break;
1118 #endif
1119 case viennacl::MEMORY_NOT_INITIALIZED:
1120 throw memory_exception("not initialised!");
1121 default:
1122 throw memory_exception("not implemented");
1123 }
1124 }
1125
1131 template<typename LHS, typename RHS, typename OP, typename S2>
1132 void sum_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec, S2 & result)
1133 {
1134 viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
1135 sum_cpu(temp, result);
1136 }
1137
1138
1139
1140
1141
1151 template<typename T>
1152 void plane_rotation(vector_base<T> & vec1,
1153 vector_base<T> & vec2,
1154 T alpha, T beta)
1155 {
1156 switch (viennacl::traits::handle(vec1).get_active_handle_id())
1157 {
1158 case viennacl::MAIN_MEMORY:
1159 viennacl::linalg::host_based::plane_rotation(vec1, vec2, alpha, beta);
1160 break;
1161 #ifdef VIENNACL_WITH_OPENCL
1162 case viennacl::OPENCL_MEMORY:
1163 viennacl::linalg::opencl::plane_rotation(vec1, vec2, alpha, beta);
1164 break;
1165 #endif
1166 #ifdef VIENNACL_WITH_CUDA
1167 case viennacl::CUDA_MEMORY:
1168 viennacl::linalg::cuda::plane_rotation(vec1, vec2, alpha, beta);
1169 break;
1170 #endif
1171 case viennacl::MEMORY_NOT_INITIALIZED:
1172 throw memory_exception("not initialised!");
1173 default:
1174 throw memory_exception("not implemented");
1175 }
1176 }
1177
1189 template<typename NumericT>
1190 void inclusive_scan(vector_base<NumericT> & vec1,
1191 vector_base<NumericT> & vec2)
1192 {
1193 switch (viennacl::traits::handle(vec1).get_active_handle_id())
1194 {
1195 case viennacl::MAIN_MEMORY:
1196 viennacl::linalg::host_based::inclusive_scan(vec1, vec2);
1197 break;
1198 #ifdef VIENNACL_WITH_OPENCL
1199 case viennacl::OPENCL_MEMORY:
1200 viennacl::linalg::opencl::inclusive_scan(vec1, vec2);
1201 break;
1202 #endif
1203
1204 #ifdef VIENNACL_WITH_CUDA
1205 case viennacl::CUDA_MEMORY:
1206 viennacl::linalg::cuda::inclusive_scan(vec1, vec2);
1207 break;
1208 #endif
1209
1210 case viennacl::MEMORY_NOT_INITIALIZED:
1211 throw memory_exception("not initialised!");
1212 default:
1213 throw memory_exception("not implemented");
1214 }
1215 }
1216
1222 template<typename NumericT>
1223 void inclusive_scan(vector_base<NumericT> & vec)
1224 {
1225 inclusive_scan(vec, vec);
1226 }
1227
1239 template<typename NumericT>
1240 void exclusive_scan(vector_base<NumericT> & vec1,
1241 vector_base<NumericT> & vec2)
1242 {
1243 switch (viennacl::traits::handle(vec1).get_active_handle_id())
1244 {
1245 case viennacl::MAIN_MEMORY:
1246 viennacl::linalg::host_based::exclusive_scan(vec1, vec2);
1247 break;
1248 #ifdef VIENNACL_WITH_OPENCL
1249 case viennacl::OPENCL_MEMORY:
1250 viennacl::linalg::opencl::exclusive_scan(vec1, vec2);
1251 break;
1252 #endif
1253
1254 #ifdef VIENNACL_WITH_CUDA
1255 case viennacl::CUDA_MEMORY:
1256 viennacl::linalg::cuda::exclusive_scan(vec1, vec2);
1257 break;
1258 #endif
1259
1260 case viennacl::MEMORY_NOT_INITIALIZED:
1261 throw memory_exception("not initialised!");
1262 default:
1263 throw memory_exception("not implemented");
1264 }
1265 }
1266
1272 template<typename NumericT>
1273 void exclusive_scan(vector_base<NumericT> & vec)
1274 {
1275 exclusive_scan(vec, vec);
1276 }
1277 } //namespace linalg
1278
1279 template<typename T, typename LHS, typename RHS, typename OP>
1280 vector_base<T> & operator += (vector_base<T> & v1, const vector_expression<const LHS, const RHS, OP> & proxy)
1281 {
1282 assert( (viennacl::traits::size(proxy) == v1.size()) && bool("Incompatible vector sizes!"));
1283 assert( (v1.size() > 0) && bool("Vector not yet initialized!") );
1284
1285 linalg::detail::op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, OP> >::apply(v1, proxy);
1286
1287 return v1;
1288 }
1289
1290 template<typename T, typename LHS, typename RHS, typename OP>
1291 vector_base<T> & operator -= (vector_base<T> & v1, const vector_expression<const LHS, const RHS, OP> & proxy)
1292 {
1293 assert( (viennacl::traits::size(proxy) == v1.size()) && bool("Incompatible vector sizes!"));
1294 assert( (v1.size() > 0) && bool("Vector not yet initialized!") );
1295
1296 linalg::detail::op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, OP> >::apply(v1, proxy);
1297
1298 return v1;
1299 }
1300
1301 } //namespace viennacl
1302
1303
1304 #endif
viennacl::linalg::opencl::min_cpu
void min_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the minimum of a vector, where the result is stored on a CPU scalar.
Definition: vector_operations.hpp:1083
viennacl::vector_tuple::const_size
vcl_size_t const_size() const
Definition: vector.hpp:1143
viennacl::linalg::index_norm_inf
vcl_size_t index_norm_inf(vector_base< T > const &vec)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:845
viennacl::linalg::cuda::vector_assign
void vector_assign(vector_base< NumericT > &vec1, ScalarT1 const &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
Definition: vector_operations.hpp:803
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
viennacl::linalg::opencl::avbv
void avbv(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:116
viennacl::linalg::cuda::norm_2_cpu
void norm_2_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the l^2-norm of a vector - implementation.
Definition: vector_operations.hpp:2651
viennacl::linalg::cuda::convert
void convert(matrix_base< DestNumericT > &mat1, matrix_base< SrcNumericT > const &mat2)
Definition: matrix_operations.hpp:57
viennacl::linalg::opencl::norm_2_impl
void norm_2_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^2-norm of a vector - implementation using OpenCL summation at second step...
Definition: vector_operations.hpp:801
viennacl::linalg::host_based::inclusive_scan
void inclusive_scan(vector_base< NumericT > const &vec1, vector_base< NumericT > &vec2)
This function implements an inclusive scan on the host using OpenMP.
Definition: vector_operations.hpp:1161
viennacl::linalg::detail::op_executor
Worker class for decomposing expression templates.
Definition: op_executor.hpp:80
viennacl::linalg::inner_prod_cpu
void inner_prod_cpu(vector_base< T > const &vec1, vector_base< T > const &vec2, T &result)
Computes the inner product of two vectors with the final reduction step on the CPU - dispatcher inter...
Definition: vector_operations.hpp:459
viennacl::linalg::host_based::norm_1_impl
void norm_1_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:648
viennacl::linalg::min_cpu
void min_cpu(vector_base< T > const &vec, T &result)
Computes the minimum of a vector with final reduction on the CPU.
Definition: vector_operations.hpp:1015
viennacl::operator-=
vector< NumericT > operator-=(vector_base< NumericT > &v1, const viennacl::vector_expression< const matrix_base< NumericT >, const vector_base< NumericT >, viennacl::op_prod > &proxy)
Implementation of the operation v1 -= A * v2, where A is a matrix.
Definition: matrix_operations.hpp:1159
vector_operations.hpp
Implementations of NMF operations using OpenCL.
viennacl::memory_exception
Exception class in case of memory errors.
Definition: forwards.h:572
viennacl::linalg::opencl::norm_1_cpu
void norm_1_cpu(vector_base< T > const &vec, T &result)
Computes the l^1-norm of a vector with final reduction on CPU.
Definition: vector_operations.hpp:770
viennacl::linalg::max_cpu
void max_cpu(vector_base< T > const &vec, T &result)
Computes the maximum of a vector with final reduction on the CPU.
Definition: vector_operations.hpp:928
size.hpp
Generic size and resize functionality for different vector and matrix types.
op_executor.hpp
Defines the worker class for decomposing an expression tree into small chunks, which can be processed...
viennacl::linalg::host_based::norm_inf_impl
void norm_inf_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:781
viennacl::linalg::opencl::plane_rotation
void plane_rotation(vector_base< T > &vec1, vector_base< T > &vec2, T alpha, T beta)
Computes a plane rotation of two vectors.
Definition: vector_operations.hpp:1156
viennacl::linalg::host_based::av
void av(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:88
viennacl::linalg::host_based::sum_impl
void sum_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the sum of all elements from the vector.
Definition: vector_operations.hpp:989
start.hpp
Extracts the underlying OpenCL start index handle from a vector, a matrix, an expression etc...
tools.hpp
Various little tools used here and there in ViennaCL.
viennacl::operator+=
vector< NumericT > operator+=(vector_base< NumericT > &v1, const viennacl::vector_expression< const matrix_base< NumericT >, const vector_base< NumericT >, viennacl::op_prod > &proxy)
Implementation of the operation v1 += A * v2, where A is a matrix.
Definition: matrix_operations.hpp:1141
viennacl::linalg::sum_impl
void sum_impl(vector_base< T > const &vec, scalar< T > &result)
viennacl::linalg::plane_rotation
void plane_rotation(vector_base< T > &vec1, vector_base< T > &vec2, T alpha, T beta)
Computes a plane rotation of two vectors.
Definition: vector_operations.hpp:1152
viennacl::linalg::norm_2_cpu
void norm_2_cpu(vector_base< T > const &vec, T &result)
Computes the l^2-norm of a vector with final reduction on the CPU - dispatcher interface.
Definition: vector_operations.hpp:705
viennacl::linalg::cuda::av
void av(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:144
viennacl::linalg::avbv_v
void avbv_v(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:144
viennacl::linalg::opencl::norm_inf_impl
void norm_inf_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:865
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
viennacl::linalg::cuda::max_impl
void max_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the maximum of a vector, both reduction stages run on the GPU.
Definition: vector_operations.hpp:2765
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
stride.hpp
Determines row and column increments for matrices and matrix proxies.
viennacl::linalg::cuda::exclusive_scan
void exclusive_scan(vector_base< NumericT > const &input, vector_base< NumericT > &output)
This function implements an exclusive scan using CUDA.
Definition: vector_operations.hpp:3239
viennacl::linalg::opencl::min_impl
void min_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the minimum of a vector, where the result is stored in an OpenCL buffer. ...
Definition: vector_operations.hpp:1045
viennacl::linalg::cuda::norm_1_cpu
void norm_1_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:2605
viennacl::vector_expression
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:239
viennacl::linalg::element_op
void element_op(matrix_base< T > &A, matrix_expression< const matrix_base< T >, const matrix_base< T >, OP > const &proxy)
Implementation of the element-wise operation A = B .* C and A = B ./ C for matrices (using MATLAB syn...
Definition: matrix_operations.hpp:702
viennacl::linalg::opencl::avbv_v
void avbv_v(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:178
viennacl::linalg::host_based::vector_assign
void vector_assign(vector_base< NumericT > &vec1, const NumericT &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
Definition: vector_operations.hpp:275
viennacl::op_inplace_add
A tag class representing inplace addition.
Definition: forwards.h:83
viennacl::linalg::cuda::max_cpu
void max_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the maximum of a vector, first reduction stage on the GPU, second stage on the CPU...
Definition: vector_operations.hpp:2793
viennacl::linalg::cuda::vector_swap
void vector_swap(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:853
viennacl::linalg::norm_2_impl
void norm_2_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^2-norm of a vector - dispatcher interface.
Definition: vector_operations.hpp:660
viennacl::linalg::host_based::convert
void convert(matrix_base< DestNumericT > &mat1, matrix_base< SrcNumericT > const &mat2)
Definition: matrix_operations.hpp:58
v1
viennacl::vector< float > v1
Definition: global_variables.cpp:60
viennacl::linalg::prod
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Definition: prod.hpp:102
viennacl::linalg::max_impl
void max_impl(vector_base< T > const &vec, scalar< T > &result)
viennacl::linalg::opencl::inner_prod_impl
void inner_prod_impl(vector_base< T > const &vec1, vector_base< T > const &vec2, vector_base< T > &partial_result)
Computes the partial inner product of two vectors - implementation. Library users should call inner_p...
Definition: vector_operations.hpp:388
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::linalg::opencl::sum_impl
void sum_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the sum over all entries of a vector.
Definition: vector_operations.hpp:1122
viennacl::linalg::cuda::inclusive_scan
void inclusive_scan(vector_base< NumericT > const &input, vector_base< NumericT > &output)
This function implements an inclusive scan using CUDA.
Definition: vector_operations.hpp:3226
viennacl::linalg::host_based::norm_2_impl
void norm_2_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the l^2-norm of a vector - implementation.
Definition: vector_operations.hpp:761
viennacl::linalg::opencl::max_impl
void max_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the maximum value of a vector, where the result is stored in an OpenCL buffer.
Definition: vector_operations.hpp:966
viennacl::linalg::inner_prod_impl
void inner_prod_impl(vector_base< T > const &vec1, vector_base< T > const &vec2, scalar< T > &result)
Computes the inner product of two vectors - dispatcher interface.
Definition: vector_operations.hpp:387
viennacl::linalg::opencl::max_cpu
void max_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the maximum value of a vector, where the value is stored in a host value.
Definition: vector_operations.hpp:1004
viennacl::linalg::convert
void convert(matrix_base< DestNumericT > &dest, matrix_base< SrcNumericT > const &src)
Definition: matrix_operations.hpp:54
viennacl::MEMORY_NOT_INITIALIZED
Definition: forwards.h:347
viennacl::linalg::norm_1_cpu
void norm_1_cpu(vector_base< T > const &vec, T &result)
Computes the l^1-norm of a vector with final reduction on the CPU.
Definition: vector_operations.hpp:613
viennacl::CUDA_MEMORY
Definition: forwards.h:350
viennacl::linalg::host_based::index_norm_inf
vcl_size_t index_norm_inf(vector_base< NumericT > const &vec1)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:831
viennacl::linalg::opencl::norm_2_cpu
void norm_2_cpu(vector_base< T > const &vec, T &result)
Computes the l^1-norm of a vector with final reduction on CPU.
Definition: vector_operations.hpp:834
viennacl::vector_tuple
Tuple class holding pointers to multiple vectors. Mainly used as a temporary object returned from vie...
Definition: forwards.h:269
viennacl::linalg::host_based::min_impl
void min_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the minimum of a vector.
Definition: vector_operations.hpp:940
viennacl::linalg::host_based::vector_swap
void vector_swap(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:302
VIENNACL_MAKE_UNARY_ELEMENT_OP
#define VIENNACL_MAKE_UNARY_ELEMENT_OP(funcname)
Definition: matrix_operations.hpp:789
viennacl::linalg::cuda::norm_inf_impl
void norm_inf_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:2679
viennacl::linalg::host_based::element_op
void element_op(matrix_base< NumericT > &A, matrix_expression< const matrix_base< NumericT >, const matrix_base< NumericT >, op_element_binary< OpT > > const &proxy)
Implementation of the element-wise operations A = B .* C and A = B ./ C (using MATLAB syntax) ...
Definition: matrix_operations.hpp:848
viennacl::linalg::cuda::inner_prod_cpu
void inner_prod_cpu(vector_base< NumericT > const &vec1, vector_base< NumericT > const &vec2, NumericT &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(vec1...
Definition: vector_operations.hpp:1771
viennacl::linalg::opencl::av
void av(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:76
viennacl::linalg::vector_swap
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:218
viennacl::linalg::host_based::avbv
void avbv(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &vec3, ScalarT2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:127
viennacl::linalg::norm_inf_impl
void norm_inf_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:752
viennacl::linalg::norm_1_impl
void norm_1_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^1-norm of a vector - dispatcher interface.
Definition: vector_operations.hpp:566
viennacl::linalg::opencl::norm_1_impl
void norm_1_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:737
viennacl::linalg::cuda::sum_cpu
void sum_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the maximum of a vector, first reduction stage on the GPU, second stage on the CPU...
Definition: vector_operations.hpp:2891
viennacl::vector_base
Common base class for dense vectors, vector ranges, and vector slices.
Definition: vector_def.hpp:104
viennacl::linalg::cuda::sum_impl
void sum_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the maximum of a vector, both reduction stages run on the GPU.
Definition: vector_operations.hpp:2874
viennacl::linalg::cuda::avbv_v
void avbv_v(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &vec3, ScalarT2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:735
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::linalg::min_impl
void min_impl(vector_base< T > const &vec, scalar< T > &result)
viennacl::vector
Definition: forwards.h:266
viennacl::linalg::opencl::inclusive_scan
void inclusive_scan(vector_base< NumericT > const &input, vector_base< NumericT > &output)
This function implements an inclusive scan using CUDA.
Definition: vector_operations.hpp:1238
viennacl::linalg::host_based::exclusive_scan
void exclusive_scan(vector_base< NumericT > const &vec1, vector_base< NumericT > &vec2)
This function implements an exclusive scan on the host using OpenMP.
Definition: vector_operations.hpp:1176
viennacl::linalg::cuda::min_cpu
void min_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the maximum of a vector, first reduction stage on the GPU, second stage on the CPU...
Definition: vector_operations.hpp:2847
viennacl::linalg::opencl::element_op
void element_op(matrix_base< T > &A, matrix_expression< const matrix_base< T >, const matrix_base< T >, op_element_binary< OP > > const &proxy)
Implementation of binary element-wise operations A = OP(B,C)
Definition: matrix_operations.hpp:540
viennacl::linalg::cuda::norm_1_impl
void norm_1_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:2587
viennacl::linalg::avbv
void avbv(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:107
viennacl::linalg::inclusive_scan
void inclusive_scan(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2)
This function implements an inclusive scan.
Definition: vector_operations.hpp:1190
viennacl::linalg::cuda::index_norm_inf
vcl_size_t index_norm_inf(vector_base< NumericT > const &vec1)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:2972
predicate.hpp
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
viennacl::linalg::cuda::plane_rotation
void plane_rotation(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2, NumericT alpha, NumericT beta)
Computes a plane rotation of two vectors.
Definition: vector_operations.hpp:3032
viennacl::linalg::host_based::inner_prod_impl
void inner_prod_impl(vector_base< NumericT > const &vec1, vector_base< NumericT > const &vec2, ScalarT &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(vec1...
Definition: vector_operations.hpp:497
viennacl::linalg::opencl::convert
void convert(matrix_base< DestNumericT > &dest, matrix_base< SrcNumericT > const &src)
Definition: matrix_operations.hpp:134
viennacl::MAIN_MEMORY
Definition: forwards.h:348
viennacl::linalg::cuda::min_impl
void min_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the maximum of a vector, both reduction stages run on the GPU.
Definition: vector_operations.hpp:2819
viennacl::op_inplace_sub
A tag class representing inplace subtraction.
Definition: forwards.h:85
viennacl::linalg::host_based::max_impl
void max_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the maximum of a vector.
Definition: vector_operations.hpp:891
viennacl::linalg::sum_cpu
void sum_cpu(vector_base< T > const &vec, T &result)
Computes the sum of a vector with final reduction on the CPU.
Definition: vector_operations.hpp:1102
viennacl::linalg::cuda::element_op
void element_op(matrix_base< NumericT, SizeT > &A, matrix_expression< const matrix_base< NumericT, SizeT >, const matrix_base< NumericT, SizeT >, op_element_binary< OpT > > const &proxy)
Definition: matrix_operations.hpp:548
viennacl::linalg::cuda::inner_prod_impl
void inner_prod_impl(vector_base< NumericT > const &vec1, vector_base< NumericT > const &vec2, ScalarT &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(vec1...
Definition: vector_operations.hpp:1739
viennacl::linalg::opencl::exclusive_scan
void exclusive_scan(vector_base< NumericT > const &input, vector_base< NumericT > &output)
This function implements an exclusive scan using CUDA.
Definition: vector_operations.hpp:1251
viennacl::linalg::cuda::norm_inf_cpu
void norm_inf_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:2699
viennacl::linalg::opencl::index_norm_inf
cl_uint index_norm_inf(vector_base< T > const &vec)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:930
viennacl::vector_base::size
size_type size() const
Returns the length of the vector (cf. std::vector)
Definition: vector_def.hpp:118
viennacl::linalg::av
void av(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:78
viennacl::linalg::opencl::norm_inf_cpu
void norm_inf_cpu(vector_base< T > const &vec, T &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:898
viennacl::vector_tuple::const_at
VectorType const & const_at(vcl_size_t i) const
Definition: vector.hpp:1146
range.hpp
Implementation of a range object for use with proxy objects.
viennacl::linalg::exclusive_scan
void exclusive_scan(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2)
This function implements an exclusive scan.
Definition: vector_operations.hpp:1240
viennacl::linalg::vector_assign
void vector_assign(vector_base< T > &vec1, const T &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
Definition: vector_operations.hpp:187
handle.hpp
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::linalg::opencl::vector_assign
void vector_assign(vector_base< T > &vec1, const T &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
Definition: vector_operations.hpp:246
viennacl::traits::handle
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
viennacl::linalg::opencl::vector_swap
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:272
viennacl::linalg::host_based::plane_rotation
void plane_rotation(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2, NumericT alpha, NumericT beta)
Computes a plane rotation of two vectors.
Definition: vector_operations.hpp:1020
viennacl::linalg::opencl::inner_prod_cpu
void inner_prod_cpu(vector_base< T > const &vec1, vector_base< T > const &vec2, T &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(vec1...
Definition: vector_operations.hpp:669
scalar.hpp
Implementation of the ViennaCL scalar class.
vector_operations.hpp
Implementations of NMF operations using CUDA.
viennacl::linalg::cuda::norm_2_impl
void norm_2_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the l^2-norm of a vector - implementation.
Definition: vector_operations.hpp:2632
viennacl::linalg::host_based::avbv_v
void avbv_v(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &vec3, ScalarT2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:197
viennacl::linalg::norm_inf_cpu
void norm_inf_cpu(vector_base< T > const &vec, T &result)
Computes the supremum-norm of a vector with final reduction on the CPU.
Definition: vector_operations.hpp:797
viennacl::linalg::cuda::avbv
void avbv(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &vec3, ScalarT2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:433
viennacl::linalg::opencl::sum_cpu
void sum_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the sum over all entries of a vector.
Definition: vector_operations.hpp:1137
enable_if.hpp
Simple enable-if variant that uses the SFINAE pattern.
viennacl::backend::mem_handle::get_active_handle_id
memory_types get_active_handle_id() const
Returns an ID for the currently active memory buffer. Other memory buffers might contain old or no da...
Definition: mem_handle.hpp:118
vector_operations.hpp
Implementations of NMF operations using a plain single-threaded or OpenMP-enabled execution on CPU...