ViennaCL - The Vienna Computing Library  1.5.1
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-2014, 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 PDF manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
25 #include "viennacl/forwards.h"
26 #include "viennacl/scalar.hpp"
27 #include "viennacl/tools/tools.hpp"
30 #include "viennacl/traits/size.hpp"
35 
36 #ifdef VIENNACL_WITH_OPENCL
38 #endif
39 
40 #ifdef VIENNACL_WITH_CUDA
42 #endif
43 
44 namespace viennacl
45 {
46  namespace linalg
47  {
48  template <typename T, typename ScalarType1>
49  void av(vector_base<T> & vec1,
50  vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
51  {
52  assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 = v2 @ alpha: size(v1) != size(v2)"));
53 
54  switch (viennacl::traits::handle(vec1).get_active_handle_id())
55  {
57  viennacl::linalg::host_based::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
58  break;
59 #ifdef VIENNACL_WITH_OPENCL
61  viennacl::linalg::opencl::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
62  break;
63 #endif
64 #ifdef VIENNACL_WITH_CUDA
66  viennacl::linalg::cuda::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
67  break;
68 #endif
70  throw memory_exception("not initialised!");
71  default:
72  throw memory_exception("not implemented");
73  }
74  }
75 
76 
77  template <typename T, typename ScalarType1, typename ScalarType2>
78  void avbv(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  vector_base<T> const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
81  {
82  assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 = v2 @ alpha + v3 @ beta: size(v1) != size(v2)"));
83  assert(viennacl::traits::size(vec2) == viennacl::traits::size(vec3) && bool("Incompatible vector sizes in v1 = v2 @ alpha + v3 @ beta: size(v2) != size(v3)"));
84 
85  switch (viennacl::traits::handle(vec1).get_active_handle_id())
86  {
89  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
90  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
91  break;
92 #ifdef VIENNACL_WITH_OPENCL
95  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
96  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
97  break;
98 #endif
99 #ifdef VIENNACL_WITH_CUDA
102  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
103  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
104  break;
105 #endif
107  throw memory_exception("not initialised!");
108  default:
109  throw memory_exception("not implemented");
110  }
111  }
112 
113 
114  template <typename T, typename ScalarType1, typename ScalarType2>
115  void avbv_v(vector_base<T> & vec1,
116  vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
117  vector_base<T> const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
118  {
119  assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 += v2 @ alpha + v3 @ beta: size(v1) != size(v2)"));
120  assert(viennacl::traits::size(vec2) == viennacl::traits::size(vec3) && bool("Incompatible vector sizes in v1 += v2 @ alpha + v3 @ beta: size(v2) != size(v3)"));
121 
122  switch (viennacl::traits::handle(vec1).get_active_handle_id())
123  {
126  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
127  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
128  break;
129 #ifdef VIENNACL_WITH_OPENCL
132  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
133  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
134  break;
135 #endif
136 #ifdef VIENNACL_WITH_CUDA
139  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
140  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
141  break;
142 #endif
144  throw memory_exception("not initialised!");
145  default:
146  throw memory_exception("not implemented");
147  }
148  }
149 
150 
157  template <typename T>
158  void vector_assign(vector_base<T> & vec1, const T & alpha, bool up_to_internal_size = false)
159  {
160  switch (viennacl::traits::handle(vec1).get_active_handle_id())
161  {
163  viennacl::linalg::host_based::vector_assign(vec1, alpha, up_to_internal_size);
164  break;
165 #ifdef VIENNACL_WITH_OPENCL
167  viennacl::linalg::opencl::vector_assign(vec1, alpha, up_to_internal_size);
168  break;
169 #endif
170 #ifdef VIENNACL_WITH_CUDA
172  viennacl::linalg::cuda::vector_assign(vec1, alpha, up_to_internal_size);
173  break;
174 #endif
176  throw memory_exception("not initialised!");
177  default:
178  throw memory_exception("not implemented");
179  }
180  }
181 
182 
188  template <typename T>
190  {
191  assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in vector_swap()"));
192 
193  switch (viennacl::traits::handle(vec1).get_active_handle_id())
194  {
197  break;
198 #ifdef VIENNACL_WITH_OPENCL
201  break;
202 #endif
203 #ifdef VIENNACL_WITH_CUDA
206  break;
207 #endif
209  throw memory_exception("not initialised!");
210  default:
211  throw memory_exception("not implemented");
212  }
213  }
214 
215 
217 
218 
219 
225  template <typename T, typename OP>
227  vector_expression<const vector_base<T>, const vector_base<T>, OP> const & proxy)
228  {
229  assert(viennacl::traits::size(vec1) == viennacl::traits::size(proxy) && bool("Incompatible vector sizes in element_op()"));
230 
231  switch (viennacl::traits::handle(vec1).get_active_handle_id())
232  {
235  break;
236 #ifdef VIENNACL_WITH_OPENCL
239  break;
240 #endif
241 #ifdef VIENNACL_WITH_CUDA
244  break;
245 #endif
247  throw memory_exception("not initialised!");
248  default:
249  throw memory_exception("not implemented");
250  }
251  }
252 
255 // Helper macro for generating binary element-wise operations such as element_prod(), element_div(), element_pow() without unnecessary code duplication */
256 #define VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(OPNAME) \
257  template <typename T> \
258  viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_binary<op_##OPNAME> > \
259  element_##OPNAME(vector_base<T> const & v1, vector_base<T> const & v2) \
260  { \
261  return viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_binary<op_##OPNAME> >(v1, v2); \
262  } \
263 \
264  template <typename V1, typename V2, typename OP, typename T> \
265  viennacl::vector_expression<const vector_expression<const V1, const V2, OP>, const vector_base<T>, op_element_binary<op_##OPNAME> > \
266  element_##OPNAME(vector_expression<const V1, const V2, OP> const & proxy, vector_base<T> const & v2) \
267  { \
268  return viennacl::vector_expression<const vector_expression<const V1, const V2, OP>, const vector_base<T>, op_element_binary<op_##OPNAME> >(proxy, v2); \
269  } \
270 \
271  template <typename T, typename V2, typename V3, typename OP> \
272  viennacl::vector_expression<const vector_base<T>, const vector_expression<const V2, const V3, OP>, op_element_binary<op_##OPNAME> > \
273  element_##OPNAME(vector_base<T> const & v1, vector_expression<const V2, const V3, OP> const & proxy) \
274  { \
275  return viennacl::vector_expression<const vector_base<T>, const vector_expression<const V2, const V3, OP>, op_element_binary<op_##OPNAME> >(v1, proxy); \
276  } \
277 \
278  template <typename V1, typename V2, typename OP1, \
279  typename V3, typename V4, typename OP2> \
280  viennacl::vector_expression<const vector_expression<const V1, const V2, OP1>, \
281  const vector_expression<const V3, const V4, OP2>, \
282  op_element_binary<op_##OPNAME> > \
283  element_##OPNAME(vector_expression<const V1, const V2, OP1> const & proxy1, \
284  vector_expression<const V3, const V4, OP2> const & proxy2) \
285  {\
286  return viennacl::vector_expression<const vector_expression<const V1, const V2, OP1>, \
287  const vector_expression<const V3, const V4, OP2>, \
288  op_element_binary<op_##OPNAME> >(proxy1, proxy2); \
289  }
290 
291  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(prod) //for element_prod()
292  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(div) //for element_div()
293  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(pow) //for element_pow()
294 
295 #undef VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS
296 
297 // Helper macro for generating unary element-wise operations such as element_exp(), element_sin(), etc. without unnecessary code duplication */
298 #define VIENNACL_MAKE_UNARY_ELEMENT_OP(funcname) \
299  template <typename T> \
300  viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_unary<op_##funcname> > \
301  element_##funcname(vector_base<T> const & v) \
302  { \
303  return viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_unary<op_##funcname> >(v, v); \
304  } \
305  template <typename LHS, typename RHS, typename OP> \
306  viennacl::vector_expression<const vector_expression<const LHS, const RHS, OP>, \
307  const vector_expression<const LHS, const RHS, OP>, \
308  op_element_unary<op_##funcname> > \
309  element_##funcname(vector_expression<const LHS, const RHS, OP> const & proxy) \
310  { \
311  return viennacl::vector_expression<const vector_expression<const LHS, const RHS, OP>, \
312  const vector_expression<const LHS, const RHS, OP>, \
313  op_element_unary<op_##funcname> >(proxy, proxy); \
314  } \
315 
333 
334 #undef VIENNACL_MAKE_UNARY_ELEMENT_OP
335 
338 
340 
341  //implementation of inner product:
342  //namespace {
343 
350  template <typename T>
351  void inner_prod_impl(vector_base<T> const & vec1,
352  vector_base<T> const & vec2,
353  scalar<T> & result)
354  {
355  assert( vec1.size() == vec2.size() && bool("Size mismatch") );
356 
358  {
361  break;
362 #ifdef VIENNACL_WITH_OPENCL
364  viennacl::linalg::opencl::inner_prod_impl(vec1, vec2, result);
365  break;
366 #endif
367 #ifdef VIENNACL_WITH_CUDA
369  viennacl::linalg::cuda::inner_prod_impl(vec1, vec2, result);
370  break;
371 #endif
373  throw memory_exception("not initialised!");
374  default:
375  throw memory_exception("not implemented");
376  }
377  }
378 
379  // vector expression on lhs
380  template <typename LHS, typename RHS, typename OP, typename T>
382  vector_base<T> const & vec2,
383  scalar<T> & result)
384  {
385  viennacl::vector<T> temp = vec1;
386  inner_prod_impl(temp, vec2, result);
387  }
388 
389 
390  // vector expression on rhs
391  template <typename T, typename LHS, typename RHS, typename OP>
392  void inner_prod_impl(vector_base<T> const & vec1,
394  scalar<T> & result)
395  {
396  viennacl::vector<T> temp = vec2;
397  inner_prod_impl(vec1, temp, result);
398  }
399 
400 
401  // vector expression on lhs and rhs
402  template <typename LHS1, typename RHS1, typename OP1,
403  typename LHS2, typename RHS2, typename OP2, typename T>
406  scalar<T> & result)
407  {
408  viennacl::vector<T> temp1 = vec1;
409  viennacl::vector<T> temp2 = vec2;
410  inner_prod_impl(temp1, temp2, result);
411  }
412 
413 
414 
415 
422  template <typename T>
423  void inner_prod_cpu(vector_base<T> const & vec1,
424  vector_base<T> const & vec2,
425  T & result)
426  {
427  assert( vec1.size() == vec2.size() && bool("Size mismatch") );
428 
430  {
433  break;
434 #ifdef VIENNACL_WITH_OPENCL
436  viennacl::linalg::opencl::inner_prod_cpu(vec1, vec2, result);
437  break;
438 #endif
439 #ifdef VIENNACL_WITH_CUDA
441  viennacl::linalg::cuda::inner_prod_cpu(vec1, vec2, result);
442  break;
443 #endif
445  throw memory_exception("not initialised!");
446  default:
447  throw memory_exception("not implemented");
448  }
449  }
450 
451  // vector expression on lhs
452  template <typename LHS, typename RHS, typename OP, typename T>
454  vector_base<T> const & vec2,
455  T & result)
456  {
457  viennacl::vector<T> temp = vec1;
458  inner_prod_cpu(temp, vec2, result);
459  }
460 
461 
462  // vector expression on rhs
463  template <typename T, typename LHS, typename RHS, typename OP>
464  void inner_prod_cpu(vector_base<T> const & vec1,
466  T & result)
467  {
468  viennacl::vector<T> temp = vec2;
469  inner_prod_cpu(vec1, temp, result);
470  }
471 
472 
473  // vector expression on lhs and rhs
474  template <typename LHS1, typename RHS1, typename OP1,
475  typename LHS2, typename RHS2, typename OP2, typename S3>
478  S3 & result)
479  {
480  viennacl::vector<S3> temp1 = vec1;
481  viennacl::vector<S3> temp2 = vec2;
482  inner_prod_cpu(temp1, temp2, result);
483  }
484 
485 
486 
493  template <typename T>
495  vector_tuple<T> const & y_tuple,
496  vector_base<T> & result)
497  {
498  assert( x.size() == y_tuple.const_at(0).size() && bool("Size mismatch") );
499  assert( result.size() == y_tuple.const_size() && bool("Number of elements does not match result size") );
500 
502  {
505  break;
506 #ifdef VIENNACL_WITH_OPENCL
508  viennacl::linalg::opencl::inner_prod_impl(x, y_tuple, result);
509  break;
510 #endif
511 #ifdef VIENNACL_WITH_CUDA
513  viennacl::linalg::cuda::inner_prod_impl(x, y_tuple, result);
514  break;
515 #endif
517  throw memory_exception("not initialised!");
518  default:
519  throw memory_exception("not implemented");
520  }
521  }
522 
523 
529  template <typename T>
530  void norm_1_impl(vector_base<T> const & vec,
531  scalar<T> & result)
532  {
533  switch (viennacl::traits::handle(vec).get_active_handle_id())
534  {
537  break;
538 #ifdef VIENNACL_WITH_OPENCL
541  break;
542 #endif
543 #ifdef VIENNACL_WITH_CUDA
546  break;
547 #endif
549  throw memory_exception("not initialised!");
550  default:
551  throw memory_exception("not implemented");
552  }
553  }
554 
555 
561  template <typename LHS, typename RHS, typename OP, typename S2>
563  S2 & result)
564  {
566  norm_1_impl(temp, result);
567  }
568 
569 
570 
576  template <typename T>
577  void norm_1_cpu(vector_base<T> const & vec,
578  T & result)
579  {
580  switch (viennacl::traits::handle(vec).get_active_handle_id())
581  {
584  break;
585 #ifdef VIENNACL_WITH_OPENCL
588  break;
589 #endif
590 #ifdef VIENNACL_WITH_CUDA
593  break;
594 #endif
596  throw memory_exception("not initialised!");
597  default:
598  throw memory_exception("not implemented");
599  }
600  }
601 
607  template <typename LHS, typename RHS, typename OP, typename S2>
609  S2 & result)
610  {
612  norm_1_cpu(temp, result);
613  }
614 
615 
616 
617 
623  template <typename T>
624  void norm_2_impl(vector_base<T> const & vec,
625  scalar<T> & result)
626  {
627  switch (viennacl::traits::handle(vec).get_active_handle_id())
628  {
631  break;
632 #ifdef VIENNACL_WITH_OPENCL
635  break;
636 #endif
637 #ifdef VIENNACL_WITH_CUDA
640  break;
641 #endif
643  throw memory_exception("not initialised!");
644  default:
645  throw memory_exception("not implemented");
646  }
647  }
648 
654  template <typename LHS, typename RHS, typename OP, typename T>
656  scalar<T> & result)
657  {
658  viennacl::vector<T> temp = vec;
659  norm_2_impl(temp, result);
660  }
661 
662 
668  template <typename T>
669  void norm_2_cpu(vector_base<T> const & vec,
670  T & result)
671  {
672  switch (viennacl::traits::handle(vec).get_active_handle_id())
673  {
676  break;
677 #ifdef VIENNACL_WITH_OPENCL
680  break;
681 #endif
682 #ifdef VIENNACL_WITH_CUDA
685  break;
686 #endif
688  throw memory_exception("not initialised!");
689  default:
690  throw memory_exception("not implemented");
691  }
692  }
693 
699  template <typename LHS, typename RHS, typename OP, typename S2>
701  S2 & result)
702  {
704  norm_2_cpu(temp, result);
705  }
706 
707 
708 
709 
715  template <typename T>
716  void norm_inf_impl(vector_base<T> const & vec,
717  scalar<T> & result)
718  {
719  switch (viennacl::traits::handle(vec).get_active_handle_id())
720  {
723  break;
724 #ifdef VIENNACL_WITH_OPENCL
727  break;
728 #endif
729 #ifdef VIENNACL_WITH_CUDA
732  break;
733 #endif
735  throw memory_exception("not initialised!");
736  default:
737  throw memory_exception("not implemented");
738  }
739  }
740 
746  template <typename LHS, typename RHS, typename OP, typename T>
748  scalar<T> & result)
749  {
750  viennacl::vector<T> temp = vec;
751  norm_inf_impl(temp, result);
752  }
753 
754 
760  template <typename T>
761  void norm_inf_cpu(vector_base<T> const & vec,
762  T & result)
763  {
764  switch (viennacl::traits::handle(vec).get_active_handle_id())
765  {
768  break;
769 #ifdef VIENNACL_WITH_OPENCL
772  break;
773 #endif
774 #ifdef VIENNACL_WITH_CUDA
777  break;
778 #endif
780  throw memory_exception("not initialised!");
781  default:
782  throw memory_exception("not implemented");
783  }
784  }
785 
791  template <typename LHS, typename RHS, typename OP, typename S2>
793  S2 & result)
794  {
796  norm_inf_cpu(temp, result);
797  }
798 
799 
800  //This function should return a CPU scalar, otherwise statements like
801  // vcl_rhs[index_norm_inf(vcl_rhs)]
802  // are ambiguous
808  template <typename T>
810  {
811  switch (viennacl::traits::handle(vec).get_active_handle_id())
812  {
815 #ifdef VIENNACL_WITH_OPENCL
818 #endif
819 #ifdef VIENNACL_WITH_CUDA
822 #endif
824  throw memory_exception("not initialised!");
825  default:
826  throw memory_exception("not implemented");
827  }
828  }
829 
834  template <typename LHS, typename RHS, typename OP>
836  {
838  return index_norm_inf(temp);
839  }
840 
841 
851  template <typename T>
853  vector_base<T> & vec2,
854  T alpha, T beta)
855  {
856  switch (viennacl::traits::handle(vec1).get_active_handle_id())
857  {
859  viennacl::linalg::host_based::plane_rotation(vec1, vec2, alpha, beta);
860  break;
861 #ifdef VIENNACL_WITH_OPENCL
863  viennacl::linalg::opencl::plane_rotation(vec1, vec2, alpha, beta);
864  break;
865 #endif
866 #ifdef VIENNACL_WITH_CUDA
868  viennacl::linalg::cuda::plane_rotation(vec1, vec2, alpha, beta);
869  break;
870 #endif
872  throw memory_exception("not initialised!");
873  default:
874  throw memory_exception("not implemented");
875  }
876  }
877 
878  } //namespace linalg
879 } //namespace viennacl
880 
881 
882 #endif
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:253
VectorType const & const_at(vcl_size_t i) const
Definition: vector.hpp:1196
void avbv_v(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:175
std::size_t vcl_size_t
Definition: forwards.h:58
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:172
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:95
size_type size() const
Returns the length of the vector (cf. std::vector)
Definition: vector.hpp:859
Definition: forwards.h:478
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:776
void av(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:66
Implementations of vector operations using OpenCL.
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:809
Exception class in case of memory errors.
Definition: forwards.h:485
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:745
Generic size and resize functionality for different vector and matrix types.
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:945
void inner_prod_impl(vector_base< T > const &vec1, vector_base< T > const &vec2, S3 &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(vec1...
Definition: vector_operations.hpp:383
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:351
Extracts the underlying OpenCL start index handle from a vector, a matrix, an expression etc...
Various little tools used here and there in ViennaCL.
void norm_2_cpu(vector_base< T > const &vec1, T &result)
Computes the l^2-norm of a vector - implementation.
Definition: vector_operations.hpp:2561
void element_op(matrix_base< NumericT, F > &A, matrix_expression< const matrix_base< NumericT, F >, const matrix_base< NumericT, F >, op_element_binary< OP > > const &proxy)
Implementation of the element-wise operations A = B .* C and A = B ./ C (using MATLAB syntax) ...
Definition: matrix_operations.hpp:604
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:852
void inner_prod_impl(vector_base< T > const &vec1, vector_base< T > const &vec2, S3 &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(vec1...
Definition: vector_operations.hpp:1736
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:115
void norm_inf_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:841
This file provides the forward declarations for the main types used within ViennaCL.
Determines row and column increments for matrices and matrix proxies.
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:827
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:181
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:157
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:2758
Definition: forwards.h:481
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:407
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:118
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:709
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:91
vcl_size_t index_norm_inf(vector_base< T > const &vec1)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:543
void vector_assign(vector_base< T > &vec1, const S1 &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
Definition: vector_operations.hpp:777
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Definition: prod.hpp:91
void element_op(matrix_base< T, F > &A, matrix_expression< const matrix_base< T, F >, const matrix_base< T, F >, op_element_binary< OP > > const &proxy)
Definition: matrix_operations.hpp:489
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:360
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
Definition: forwards.h:480
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:530
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:810
Tuple class holding pointers to multiple vectors. Mainly used as a temporary object returned from vie...
Definition: forwards.h:211
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:582
#define VIENNACL_MAKE_UNARY_ELEMENT_OP(funcname)
Definition: matrix_operations.hpp:678
void norm_1_cpu(vector_base< T > const &vec1, T &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:2515
void element_op(matrix_base< T, F > &A, matrix_expression< const matrix_base< T, F >, const matrix_base< T, F >, op_element_binary< OP > > const &proxy)
Implementation of binary element-wise operations A = OP(B,C)
Definition: matrix_operations.hpp:460
vcl_size_t index_norm_inf(vector_base< T > const &vec1)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:2698
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:55
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:189
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:761
void norm_1_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:711
Common base class for dense vectors, vector ranges, and vector slices.
Definition: forwards.h:205
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:280
void element_op(matrix_base< T, F > &A, matrix_expression< const matrix_base< T, F >, const matrix_base< T, F >, 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:598
A vector class representing a linear memory sequence on the GPU. Inspired by boost::numeric::ublas::v...
Definition: forwards.h:208
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:669
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:78
void norm_inf_impl(vector_base< T > const &vec1, scalar< T > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:2589
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
void avbv(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:105
void norm_1_impl(vector_base< T > const &vec1, scalar< T > &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:2497
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:423
void norm_2_impl(vector_base< T > const &vec1, scalar< T > &result)
Computes the l^2-norm of a vector - implementation.
Definition: vector_operations.hpp:2542
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:907
Definition: forwards.h:479
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:49
void norm_inf_cpu(vector_base< T > const &vec, T &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:875
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:1768
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:624
void norm_1_impl(vector_base< T > const &vec1, S2 &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:454
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:158
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
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:225
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:251
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:643
Implementation of the ViennaCL scalar class.
Implementations of vector operations using a plain single-threaded execution on 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:577
void norm_inf_cpu(vector_base< T > const &vec1, T &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:2609
void norm_inf_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:716
Simple enable-if variant that uses the SFINAE pattern.
void norm_2_impl(vector_base< T > const &vec1, S2 &result)
Computes the l^2-norm of a vector - implementation.
Definition: vector_operations.hpp:482
void norm_inf_impl(vector_base< T > const &vec1, S2 &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:514
vcl_size_t const_size() const
Definition: vector.hpp:1193
Implementations of vector operations using a plain single-threaded or OpenMP-enabled execution on CPU...