ViennaCL - The Vienna Computing Library  1.6.0
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/range.hpp"
27 #include "viennacl/scalar.hpp"
28 #include "viennacl/tools/tools.hpp"
31 #include "viennacl/traits/size.hpp"
36 
37 #ifdef VIENNACL_WITH_OPENCL
39 #endif
40 
41 #ifdef VIENNACL_WITH_CUDA
43 #endif
44 
45 namespace viennacl
46 {
47  namespace linalg
48  {
49  template<typename T, typename ScalarType1>
50  void av(vector_base<T> & vec1,
51  vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
52  {
53  assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 = v2 @ alpha: size(v1) != size(v2)"));
54 
55  switch (viennacl::traits::handle(vec1).get_active_handle_id())
56  {
58  viennacl::linalg::host_based::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
59  break;
60 #ifdef VIENNACL_WITH_OPENCL
62  viennacl::linalg::opencl::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
63  break;
64 #endif
65 #ifdef VIENNACL_WITH_CUDA
67  viennacl::linalg::cuda::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
68  break;
69 #endif
71  throw memory_exception("not initialised!");
72  default:
73  throw memory_exception("not implemented");
74  }
75  }
76 
77 
78  template<typename T, typename ScalarType1, typename ScalarType2>
79  void avbv(vector_base<T> & vec1,
80  vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
81  vector_base<T> const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
82  {
83  assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 = v2 @ alpha + v3 @ beta: size(v1) != size(v2)"));
84  assert(viennacl::traits::size(vec2) == viennacl::traits::size(vec3) && bool("Incompatible vector sizes in v1 = v2 @ alpha + v3 @ beta: size(v2) != size(v3)"));
85 
86  switch (viennacl::traits::handle(vec1).get_active_handle_id())
87  {
90  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
91  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
92  break;
93 #ifdef VIENNACL_WITH_OPENCL
96  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
97  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
98  break;
99 #endif
100 #ifdef VIENNACL_WITH_CUDA
103  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
104  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
105  break;
106 #endif
108  throw memory_exception("not initialised!");
109  default:
110  throw memory_exception("not implemented");
111  }
112  }
113 
114 
115  template<typename T, typename ScalarType1, typename ScalarType2>
116  void avbv_v(vector_base<T> & vec1,
117  vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
118  vector_base<T> const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
119  {
120  assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 += v2 @ alpha + v3 @ beta: size(v1) != size(v2)"));
121  assert(viennacl::traits::size(vec2) == viennacl::traits::size(vec3) && bool("Incompatible vector sizes in v1 += v2 @ alpha + v3 @ beta: size(v2) != size(v3)"));
122 
123  switch (viennacl::traits::handle(vec1).get_active_handle_id())
124  {
127  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
128  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
129  break;
130 #ifdef VIENNACL_WITH_OPENCL
133  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
134  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
135  break;
136 #endif
137 #ifdef VIENNACL_WITH_CUDA
140  vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
141  vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
142  break;
143 #endif
145  throw memory_exception("not initialised!");
146  default:
147  throw memory_exception("not implemented");
148  }
149  }
150 
151 
158  template<typename T>
159  void vector_assign(vector_base<T> & vec1, const T & alpha, bool up_to_internal_size = false)
160  {
161  switch (viennacl::traits::handle(vec1).get_active_handle_id())
162  {
164  viennacl::linalg::host_based::vector_assign(vec1, alpha, up_to_internal_size);
165  break;
166 #ifdef VIENNACL_WITH_OPENCL
168  viennacl::linalg::opencl::vector_assign(vec1, alpha, up_to_internal_size);
169  break;
170 #endif
171 #ifdef VIENNACL_WITH_CUDA
173  viennacl::linalg::cuda::vector_assign(vec1, alpha, up_to_internal_size);
174  break;
175 #endif
177  throw memory_exception("not initialised!");
178  default:
179  throw memory_exception("not implemented");
180  }
181  }
182 
183 
189  template<typename T>
191  {
192  assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in vector_swap()"));
193 
194  switch (viennacl::traits::handle(vec1).get_active_handle_id())
195  {
198  break;
199 #ifdef VIENNACL_WITH_OPENCL
202  break;
203 #endif
204 #ifdef VIENNACL_WITH_CUDA
207  break;
208 #endif
210  throw memory_exception("not initialised!");
211  default:
212  throw memory_exception("not implemented");
213  }
214  }
215 
216 
218 
219 
220 
226  template<typename T, typename OP>
228  vector_expression<const vector_base<T>, const vector_base<T>, OP> const & proxy)
229  {
230  assert(viennacl::traits::size(vec1) == viennacl::traits::size(proxy) && bool("Incompatible vector sizes in element_op()"));
231 
232  switch (viennacl::traits::handle(vec1).get_active_handle_id())
233  {
236  break;
237 #ifdef VIENNACL_WITH_OPENCL
240  break;
241 #endif
242 #ifdef VIENNACL_WITH_CUDA
245  break;
246 #endif
248  throw memory_exception("not initialised!");
249  default:
250  throw memory_exception("not implemented");
251  }
252  }
253 
256 // Helper macro for generating binary element-wise operations such as element_prod(), element_div(), element_pow() without unnecessary code duplication */
257 #define VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(OPNAME) \
258  template<typename T> \
259  viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_binary<op_##OPNAME> > \
260  element_##OPNAME(vector_base<T> const & v1, vector_base<T> const & v2) \
261  { \
262  return viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_binary<op_##OPNAME> >(v1, v2); \
263  } \
264 \
265  template<typename V1, typename V2, typename OP, typename T> \
266  viennacl::vector_expression<const vector_expression<const V1, const V2, OP>, const vector_base<T>, op_element_binary<op_##OPNAME> > \
267  element_##OPNAME(vector_expression<const V1, const V2, OP> const & proxy, vector_base<T> const & v2) \
268  { \
269  return viennacl::vector_expression<const vector_expression<const V1, const V2, OP>, const vector_base<T>, op_element_binary<op_##OPNAME> >(proxy, v2); \
270  } \
271 \
272  template<typename T, typename V2, typename V3, typename OP> \
273  viennacl::vector_expression<const vector_base<T>, const vector_expression<const V2, const V3, OP>, op_element_binary<op_##OPNAME> > \
274  element_##OPNAME(vector_base<T> const & v1, vector_expression<const V2, const V3, OP> const & proxy) \
275  { \
276  return viennacl::vector_expression<const vector_base<T>, const vector_expression<const V2, const V3, OP>, op_element_binary<op_##OPNAME> >(v1, proxy); \
277  } \
278 \
279  template<typename V1, typename V2, typename OP1, \
280  typename V3, typename V4, typename OP2> \
281  viennacl::vector_expression<const vector_expression<const V1, const V2, OP1>, \
282  const vector_expression<const V3, const V4, OP2>, \
283  op_element_binary<op_##OPNAME> > \
284  element_##OPNAME(vector_expression<const V1, const V2, OP1> const & proxy1, \
285  vector_expression<const V3, const V4, OP2> const & proxy2) \
286  {\
287  return viennacl::vector_expression<const vector_expression<const V1, const V2, OP1>, \
288  const vector_expression<const V3, const V4, OP2>, \
289  op_element_binary<op_##OPNAME> >(proxy1, proxy2); \
290  }
291 
292  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(prod) //for element_prod()
293  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(div) //for element_div()
294  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(pow) //for element_pow()
295 
296  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(eq)
297  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(neq)
298  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(greater)
299  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(less)
300  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(geq)
301  VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(leq)
302 
303 #undef VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS
304 
305 // Helper macro for generating unary element-wise operations such as element_exp(), element_sin(), etc. without unnecessary code duplication */
306 #define VIENNACL_MAKE_UNARY_ELEMENT_OP(funcname) \
307  template<typename T> \
308  viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_unary<op_##funcname> > \
309  element_##funcname(vector_base<T> const & v) \
310  { \
311  return viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_unary<op_##funcname> >(v, v); \
312  } \
313  template<typename LHS, typename RHS, typename OP> \
314  viennacl::vector_expression<const vector_expression<const LHS, const RHS, OP>, \
315  const vector_expression<const LHS, const RHS, OP>, \
316  op_element_unary<op_##funcname> > \
317  element_##funcname(vector_expression<const LHS, const RHS, OP> const & proxy) \
318  { \
319  return viennacl::vector_expression<const vector_expression<const LHS, const RHS, OP>, \
320  const vector_expression<const LHS, const RHS, OP>, \
321  op_element_unary<op_##funcname> >(proxy, proxy); \
322  } \
323 
341 
342 #undef VIENNACL_MAKE_UNARY_ELEMENT_OP
343 
346 
348 
349  //implementation of inner product:
350  //namespace {
351 
358  template<typename T>
359  void inner_prod_impl(vector_base<T> const & vec1,
360  vector_base<T> const & vec2,
361  scalar<T> & result)
362  {
363  assert( vec1.size() == vec2.size() && bool("Size mismatch") );
364 
366  {
369  break;
370 #ifdef VIENNACL_WITH_OPENCL
372  viennacl::linalg::opencl::inner_prod_impl(vec1, vec2, result);
373  break;
374 #endif
375 #ifdef VIENNACL_WITH_CUDA
377  viennacl::linalg::cuda::inner_prod_impl(vec1, vec2, result);
378  break;
379 #endif
381  throw memory_exception("not initialised!");
382  default:
383  throw memory_exception("not implemented");
384  }
385  }
386 
387  // vector expression on lhs
388  template<typename LHS, typename RHS, typename OP, typename T>
390  vector_base<T> const & vec2,
391  scalar<T> & result)
392  {
393  viennacl::vector<T> temp = vec1;
394  inner_prod_impl(temp, vec2, result);
395  }
396 
397 
398  // vector expression on rhs
399  template<typename T, typename LHS, typename RHS, typename OP>
400  void inner_prod_impl(vector_base<T> const & vec1,
402  scalar<T> & result)
403  {
404  viennacl::vector<T> temp = vec2;
405  inner_prod_impl(vec1, temp, result);
406  }
407 
408 
409  // vector expression on lhs and rhs
410  template<typename LHS1, typename RHS1, typename OP1,
411  typename LHS2, typename RHS2, typename OP2, typename T>
414  scalar<T> & result)
415  {
416  viennacl::vector<T> temp1 = vec1;
417  viennacl::vector<T> temp2 = vec2;
418  inner_prod_impl(temp1, temp2, result);
419  }
420 
421 
422 
423 
430  template<typename T>
431  void inner_prod_cpu(vector_base<T> const & vec1,
432  vector_base<T> const & vec2,
433  T & result)
434  {
435  assert( vec1.size() == vec2.size() && bool("Size mismatch") );
436 
438  {
441  break;
442 #ifdef VIENNACL_WITH_OPENCL
444  viennacl::linalg::opencl::inner_prod_cpu(vec1, vec2, result);
445  break;
446 #endif
447 #ifdef VIENNACL_WITH_CUDA
449  viennacl::linalg::cuda::inner_prod_cpu(vec1, vec2, result);
450  break;
451 #endif
453  throw memory_exception("not initialised!");
454  default:
455  throw memory_exception("not implemented");
456  }
457  }
458 
459  // vector expression on lhs
460  template<typename LHS, typename RHS, typename OP, typename T>
462  vector_base<T> const & vec2,
463  T & result)
464  {
465  viennacl::vector<T> temp = vec1;
466  inner_prod_cpu(temp, vec2, result);
467  }
468 
469 
470  // vector expression on rhs
471  template<typename T, typename LHS, typename RHS, typename OP>
472  void inner_prod_cpu(vector_base<T> const & vec1,
474  T & result)
475  {
476  viennacl::vector<T> temp = vec2;
477  inner_prod_cpu(vec1, temp, result);
478  }
479 
480 
481  // vector expression on lhs and rhs
482  template<typename LHS1, typename RHS1, typename OP1,
483  typename LHS2, typename RHS2, typename OP2, typename S3>
486  S3 & result)
487  {
488  viennacl::vector<S3> temp1 = vec1;
489  viennacl::vector<S3> temp2 = vec2;
490  inner_prod_cpu(temp1, temp2, result);
491  }
492 
493 
494 
501  template<typename T>
503  vector_tuple<T> const & y_tuple,
504  vector_base<T> & result)
505  {
506  assert( x.size() == y_tuple.const_at(0).size() && bool("Size mismatch") );
507  assert( result.size() == y_tuple.const_size() && bool("Number of elements does not match result size") );
508 
510  {
513  break;
514 #ifdef VIENNACL_WITH_OPENCL
516  viennacl::linalg::opencl::inner_prod_impl(x, y_tuple, result);
517  break;
518 #endif
519 #ifdef VIENNACL_WITH_CUDA
521  viennacl::linalg::cuda::inner_prod_impl(x, y_tuple, result);
522  break;
523 #endif
525  throw memory_exception("not initialised!");
526  default:
527  throw memory_exception("not implemented");
528  }
529  }
530 
531 
537  template<typename T>
538  void norm_1_impl(vector_base<T> const & vec,
539  scalar<T> & result)
540  {
541  switch (viennacl::traits::handle(vec).get_active_handle_id())
542  {
545  break;
546 #ifdef VIENNACL_WITH_OPENCL
549  break;
550 #endif
551 #ifdef VIENNACL_WITH_CUDA
554  break;
555 #endif
557  throw memory_exception("not initialised!");
558  default:
559  throw memory_exception("not implemented");
560  }
561  }
562 
563 
569  template<typename LHS, typename RHS, typename OP, typename S2>
571  S2 & result)
572  {
574  norm_1_impl(temp, result);
575  }
576 
577 
578 
584  template<typename T>
585  void norm_1_cpu(vector_base<T> const & vec,
586  T & result)
587  {
588  switch (viennacl::traits::handle(vec).get_active_handle_id())
589  {
592  break;
593 #ifdef VIENNACL_WITH_OPENCL
596  break;
597 #endif
598 #ifdef VIENNACL_WITH_CUDA
601  break;
602 #endif
604  throw memory_exception("not initialised!");
605  default:
606  throw memory_exception("not implemented");
607  }
608  }
609 
615  template<typename LHS, typename RHS, typename OP, typename S2>
617  S2 & result)
618  {
620  norm_1_cpu(temp, result);
621  }
622 
623 
624 
625 
631  template<typename T>
632  void norm_2_impl(vector_base<T> const & vec,
633  scalar<T> & result)
634  {
635  switch (viennacl::traits::handle(vec).get_active_handle_id())
636  {
639  break;
640 #ifdef VIENNACL_WITH_OPENCL
643  break;
644 #endif
645 #ifdef VIENNACL_WITH_CUDA
648  break;
649 #endif
651  throw memory_exception("not initialised!");
652  default:
653  throw memory_exception("not implemented");
654  }
655  }
656 
662  template<typename LHS, typename RHS, typename OP, typename T>
664  scalar<T> & result)
665  {
666  viennacl::vector<T> temp = vec;
667  norm_2_impl(temp, result);
668  }
669 
670 
676  template<typename T>
677  void norm_2_cpu(vector_base<T> const & vec,
678  T & result)
679  {
680  switch (viennacl::traits::handle(vec).get_active_handle_id())
681  {
684  break;
685 #ifdef VIENNACL_WITH_OPENCL
688  break;
689 #endif
690 #ifdef VIENNACL_WITH_CUDA
693  break;
694 #endif
696  throw memory_exception("not initialised!");
697  default:
698  throw memory_exception("not implemented");
699  }
700  }
701 
707  template<typename LHS, typename RHS, typename OP, typename S2>
709  S2 & result)
710  {
712  norm_2_cpu(temp, result);
713  }
714 
715 
716 
717 
723  template<typename T>
724  void norm_inf_impl(vector_base<T> const & vec,
725  scalar<T> & result)
726  {
727  switch (viennacl::traits::handle(vec).get_active_handle_id())
728  {
731  break;
732 #ifdef VIENNACL_WITH_OPENCL
735  break;
736 #endif
737 #ifdef VIENNACL_WITH_CUDA
740  break;
741 #endif
743  throw memory_exception("not initialised!");
744  default:
745  throw memory_exception("not implemented");
746  }
747  }
748 
754  template<typename LHS, typename RHS, typename OP, typename T>
756  scalar<T> & result)
757  {
758  viennacl::vector<T> temp = vec;
759  norm_inf_impl(temp, result);
760  }
761 
762 
768  template<typename T>
769  void norm_inf_cpu(vector_base<T> const & vec,
770  T & result)
771  {
772  switch (viennacl::traits::handle(vec).get_active_handle_id())
773  {
776  break;
777 #ifdef VIENNACL_WITH_OPENCL
780  break;
781 #endif
782 #ifdef VIENNACL_WITH_CUDA
785  break;
786 #endif
788  throw memory_exception("not initialised!");
789  default:
790  throw memory_exception("not implemented");
791  }
792  }
793 
799  template<typename LHS, typename RHS, typename OP, typename S2>
801  S2 & result)
802  {
804  norm_inf_cpu(temp, result);
805  }
806 
807 
808  //This function should return a CPU scalar, otherwise statements like
809  // vcl_rhs[index_norm_inf(vcl_rhs)]
810  // are ambiguous
816  template<typename T>
818  {
819  switch (viennacl::traits::handle(vec).get_active_handle_id())
820  {
823 #ifdef VIENNACL_WITH_OPENCL
826 #endif
827 #ifdef VIENNACL_WITH_CUDA
830 #endif
832  throw memory_exception("not initialised!");
833  default:
834  throw memory_exception("not implemented");
835  }
836  }
837 
842  template<typename LHS, typename RHS, typename OP>
844  {
846  return index_norm_inf(temp);
847  }
848 
849 
855  template<typename NumericT>
857  {
858  switch (viennacl::traits::handle(vec).get_active_handle_id())
859  {
862  break;
863 #ifdef VIENNACL_WITH_OPENCL
866  break;
867 #endif
868 #ifdef VIENNACL_WITH_CUDA
871  break;
872 #endif
874  throw memory_exception("not initialised!");
875  default:
876  throw memory_exception("not implemented");
877  }
878  }
879 
885  template<typename LHS, typename RHS, typename OP, typename NumericT>
887  {
888  viennacl::vector<NumericT> temp = vec;
889  max_impl(temp, result);
890  }
891 
892 
898  template<typename T>
899  void max_cpu(vector_base<T> const & vec, T & result)
900  {
901  switch (viennacl::traits::handle(vec).get_active_handle_id())
902  {
905  break;
906 #ifdef VIENNACL_WITH_OPENCL
909  break;
910 #endif
911 #ifdef VIENNACL_WITH_CUDA
913  viennacl::linalg::cuda::max_cpu(vec, result);
914  break;
915 #endif
917  throw memory_exception("not initialised!");
918  default:
919  throw memory_exception("not implemented");
920  }
921  }
922 
928  template<typename LHS, typename RHS, typename OP, typename S2>
929  void max_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec, S2 & result)
930  {
932  max_cpu(temp, result);
933  }
934 
935 
941  template<typename NumericT>
943  {
944  switch (viennacl::traits::handle(vec).get_active_handle_id())
945  {
948  break;
949 #ifdef VIENNACL_WITH_OPENCL
952  break;
953 #endif
954 #ifdef VIENNACL_WITH_CUDA
957  break;
958 #endif
960  throw memory_exception("not initialised!");
961  default:
962  throw memory_exception("not implemented");
963  }
964  }
965 
971  template<typename LHS, typename RHS, typename OP, typename NumericT>
973  {
974  viennacl::vector<NumericT> temp = vec;
975  min_impl(temp, result);
976  }
977 
978 
984  template<typename T>
985  void min_cpu(vector_base<T> const & vec, T & result)
986  {
987  switch (viennacl::traits::handle(vec).get_active_handle_id())
988  {
991  break;
992 #ifdef VIENNACL_WITH_OPENCL
995  break;
996 #endif
997 #ifdef VIENNACL_WITH_CUDA
999  viennacl::linalg::cuda::min_cpu(vec, result);
1000  break;
1001 #endif
1003  throw memory_exception("not initialised!");
1004  default:
1005  throw memory_exception("not implemented");
1006  }
1007  }
1008 
1014  template<typename LHS, typename RHS, typename OP, typename S2>
1016  {
1018  min_cpu(temp, result);
1019  }
1020 
1021 
1022 
1032  template<typename T>
1034  vector_base<T> & vec2,
1035  T alpha, T beta)
1036  {
1037  switch (viennacl::traits::handle(vec1).get_active_handle_id())
1038  {
1039  case viennacl::MAIN_MEMORY:
1040  viennacl::linalg::host_based::plane_rotation(vec1, vec2, alpha, beta);
1041  break;
1042 #ifdef VIENNACL_WITH_OPENCL
1044  viennacl::linalg::opencl::plane_rotation(vec1, vec2, alpha, beta);
1045  break;
1046 #endif
1047 #ifdef VIENNACL_WITH_CUDA
1048  case viennacl::CUDA_MEMORY:
1049  viennacl::linalg::cuda::plane_rotation(vec1, vec2, alpha, beta);
1050  break;
1051 #endif
1053  throw memory_exception("not initialised!");
1054  default:
1055  throw memory_exception("not implemented");
1056  }
1057  }
1058 
1059  } //namespace linalg
1060 
1061  template<typename T, typename LHS, typename RHS, typename OP>
1063  {
1064  assert( (viennacl::traits::size(proxy) == v1.size()) && bool("Incompatible vector sizes!"));
1065  assert( (v1.size() > 0) && bool("Vector not yet initialized!") );
1066 
1068 
1069  return v1;
1070  }
1071 
1072  template<typename T, typename LHS, typename RHS, typename OP>
1074  {
1075  assert( (viennacl::traits::size(proxy) == v1.size()) && bool("Incompatible vector sizes!"));
1076  assert( (v1.size() > 0) && bool("Vector not yet initialized!") );
1077 
1079 
1080  return v1;
1081  }
1082 
1083 } //namespace viennacl
1084 
1085 
1086 #endif
void min_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the supremum-norm of a vector.
void norm_2_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the l^1-norm of a vector with final reduction on CPU.
vcl_size_t const_size() const
Definition: vector.hpp:1129
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.
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)
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:226
void norm_2_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the l^2-norm of a vector - implementation.
void norm_1_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the l^1-norm of a vector with final reduction on CPU.
Worker class for decomposing expression templates.
Definition: op_executor.hpp:80
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...
void norm_1_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the l^1-norm of a vector.
void min_cpu(vector_base< T > const &vec, T &result)
Computes the minimum of a vector with final reduction on the CPU.
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.
Implementations of NMF operations using OpenCL.
void inner_prod_cpu(vector_base< NumericT > const &x, vector_base< NumericT > const &y, NumericT &result)
Exception class in case of memory errors.
Definition: forwards.h:571
void max_cpu(vector_base< T > const &vec, T &result)
Computes the maximum of a vector with final reduction on the CPU.
Generic size and resize functionality for different vector and matrix types.
void norm_inf_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the supremum-norm of a vector.
void plane_rotation(vector_base< NumericT > &x, vector_base< NumericT > &y, NumericT alpha, NumericT beta)
Computes a plane rotation of two vectors.
void norm_inf_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the supremum-norm of a vector.
void av(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha)
Extracts the underlying OpenCL start index handle from a vector, a matrix, an expression etc...
Various little tools used here and there in ViennaCL.
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.
void plane_rotation(vector_base< T > &vec1, vector_base< T > &vec2, T alpha, T beta)
Computes a plane rotation of two vectors.
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.
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)
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)
cl_uint index_norm_inf(vector_base< NumericT > const &x)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
void norm_1_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the l^1-norm of a vector.
void avbv_v(vector_base< NumericT > &x, vector_base< NumericT > const &y, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &z, ScalarT2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
void max_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the maximum of a vector, both reduction stages run on the GPU.
This file provides the forward declarations for the main types used within ViennaCL.
Determines row and column increments for matrices and matrix proxies.
void min_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the minimum of a vector.
void norm_1_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the l^1-norm of a vector.
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:238
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...
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)
A tag class representing inplace addition.
Definition: forwards.h:82
void vector_assign(vector_base< NumericT > &x, const NumericT &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
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...
void vector_swap(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2)
Swaps the contents of two vectors, data is copied.
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 binary element-wise operations A = OP(B,C)
void norm_2_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^2-norm of a vector - dispatcher interface.
viennacl::vector< float > v1
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Definition: prod.hpp:91
void max_impl(vector_base< T > const &vec, scalar< T > &result)
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
void norm_2_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the l^2-norm of a vector - implementation.
void max_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the maximum of a vector.
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.
void max_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the supremum-norm of a vector.
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.
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.
Tuple class holding pointers to multiple vectors. Mainly used as a temporary object returned from vie...
Definition: forwards.h:268
void min_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the maximum of a vector.
void norm_2_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the l^2-norm of a vector - implementation using OpenCL summation at second step...
void vector_swap(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2)
Swaps the contents of two vectors, data is copied.
#define VIENNACL_MAKE_UNARY_ELEMENT_OP(funcname)
void inner_prod_impl(vector_base< NumericT > const &x, vector_base< NumericT > const &y, scalar< NumericT > &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(x...
void norm_inf_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the supremum-norm of a vector.
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) ...
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...
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
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)
void norm_inf_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the supremum-norm of a vector.
void norm_1_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^1-norm of a vector - dispatcher interface.
Common base class for dense vectors, vector ranges, and vector slices.
Definition: vector_def.hpp:104
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)
std::size_t vcl_size_t
Definition: forwards.h:74
void min_impl(vector_base< T > const &vec, scalar< T > &result)
void norm_inf_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the supremum-norm of a vector.
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...
void norm_1_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the l^1-norm of a vector.
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)
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.
void vector_swap(vector_base< NumericT > &x, vector_base< NumericT > &y)
Swaps the contents of two vectors, data is copied.
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
void plane_rotation(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2, NumericT alpha, NumericT beta)
Computes a plane rotation of two vectors.
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...
void min_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the maximum of a vector, both reduction stages run on the GPU.
A tag class representing inplace subtraction.
Definition: forwards.h:84
void max_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the maximum of a vector.
void av(vector_base< NumericT > &x, vector_base< NumericT > const &y, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha)
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)
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...
void norm_inf_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the supremum-norm of a vector.
size_type size() const
Returns the length of the vector (cf. std::vector)
Definition: vector_def.hpp:118
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)
void avbv(vector_base< NumericT > &x, vector_base< NumericT > const &y, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &z, ScalarT2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
VectorType const & const_at(vcl_size_t i) const
Definition: vector.hpp:1132
Implementation of a range object for use with proxy objects.
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)
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
void plane_rotation(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2, NumericT alpha, NumericT beta)
Computes a plane rotation of two vectors.
Implementation of the ViennaCL scalar class.
Implementations of NMF operations using CUDA.
void norm_2_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the l^2-norm of a vector - implementation.
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)
void norm_inf_cpu(vector_base< T > const &vec, T &result)
Computes the supremum-norm of a vector with final reduction on the CPU.
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)
Simple enable-if variant that uses the SFINAE pattern.
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
Implementations of NMF operations using a plain single-threaded or OpenMP-enabled execution on CPU...