ViennaCL - The Vienna Computing Library  1.5.2
scalar.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_SCALAR_HPP_
2 #define VIENNACL_SCALAR_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 <iostream>
26 
27 #include "viennacl/forwards.h"
32 
33 #ifdef VIENNACL_WITH_OPENCL
34 #include "viennacl/ocl/backend.hpp"
35 #endif
36 
37 namespace viennacl
38 {
46  template <typename LHS, typename RHS, typename OP>
47  class scalar_expression
48  {
49  typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
50  public:
52 
53  scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
54 
56  LHS & lhs() const { return lhs_; }
58  RHS & rhs() const { return rhs_; }
59 
61  operator ScalarType () const
62  {
64  temp = *this;
65  return temp;
66  }
67 
68  private:
69  LHS & lhs_;
70  RHS & rhs_;
71  };
72 
73 
81  template <typename LHS, typename RHS>
83  {
84  //typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
85  public:
87 
88  scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
89 
91  LHS & lhs() const { return lhs_; }
93  RHS & rhs() const { return rhs_; }
94 
96  operator ScalarType () const
97  {
98  ScalarType result;
99  viennacl::linalg::inner_prod_cpu(lhs_, rhs_, result);
100  return result;
101  }
102 
103  private:
104  LHS & lhs_;
105  RHS & rhs_;
106  };
107 
108 
114  template <typename LHS, typename RHS>
115  class scalar_expression<LHS, RHS, op_norm_1>
116  {
117  //typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
118  public:
120 
121  scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
122 
124  LHS & lhs() const { return lhs_; }
126  RHS & rhs() const { return rhs_; }
127 
129  operator ScalarType () const
130  {
131  ScalarType result;
132  viennacl::linalg::norm_1_cpu(lhs_, result);
133  return result;
134  }
135 
136  private:
137  LHS & lhs_;
138  RHS & rhs_;
139  };
140 
146  template <typename LHS, typename RHS>
147  class scalar_expression<LHS, RHS, op_norm_2>
148  {
149  //typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
150  public:
152 
153  scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
154 
156  LHS & lhs() const { return lhs_; }
158  RHS & rhs() const { return rhs_; }
159 
161  operator ScalarType () const
162  {
163  ScalarType result;
164  viennacl::linalg::norm_2_cpu(lhs_, result);
165  return result;
166  }
167 
168  private:
169  LHS & lhs_;
170  RHS & rhs_;
171  };
172 
173 
179  template <typename LHS, typename RHS>
181  {
182  //typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
183  public:
185 
186  scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
187 
189  LHS & lhs() const { return lhs_; }
191  RHS & rhs() const { return rhs_; }
192 
194  operator ScalarType () const
195  {
196  ScalarType result;
197  viennacl::linalg::norm_inf_cpu(lhs_, result);
198  return result;
199  }
200 
201  private:
202  LHS & lhs_;
203  RHS & rhs_;
204  };
205 
211  template <typename LHS, typename RHS>
213  {
214  //typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
215  public:
217 
218  scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
219 
221  LHS & lhs() const { return lhs_; }
223  RHS & rhs() const { return rhs_; }
224 
226  operator ScalarType () const
227  {
228  ScalarType result;
230  return result;
231  }
232 
233  private:
234  LHS & lhs_;
235  RHS & rhs_;
236  };
237 
238 
239 
240 
248  template<class SCALARTYPE>
249  class scalar
250  {
251  typedef scalar<SCALARTYPE> self_type;
252  public:
255 
257  typedef SCALARTYPE value_type;
258 
260  scalar() {}
261 
263  scalar(SCALARTYPE val, viennacl::context ctx = viennacl::context())
264  {
265  viennacl::backend::memory_create(val_, sizeof(SCALARTYPE), ctx, &val);
266  }
267 
268 #ifdef VIENNACL_WITH_OPENCL
269 
274  explicit scalar(cl_mem mem, size_type /*size*/)
275  {
277  val_.opencl_handle() = mem;
278  val_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the vector object is destroyed.
279  }
280 #endif
281 
283  template <typename T1, typename T2, typename OP>
285  {
286  val_.switch_active_handle_id(viennacl::traits::handle(proxy.lhs()).get_active_handle_id());
287  viennacl::backend::memory_create(val_, sizeof(SCALARTYPE), viennacl::traits::context(proxy));
288  *this = proxy;
289  }
290 
291  //copy constructor
293  scalar(const scalar & other)
294  {
295  if (other.handle().get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED)
296  {
297  //copy value:
298  val_.switch_active_handle_id(other.handle().get_active_handle_id());
299  viennacl::backend::memory_create(val_, sizeof(SCALARTYPE), viennacl::traits::context(other));
300  viennacl::backend::memory_copy(other.handle(), val_, 0, 0, sizeof(SCALARTYPE));
301  }
302  }
303 
305  operator SCALARTYPE() const
306  {
307  // make sure the scalar contains reasonable data:
308  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized, cannot read!"));
309 
310  SCALARTYPE tmp;
311  viennacl::backend::memory_read(val_, 0, sizeof(SCALARTYPE), &tmp);
312  return tmp;
313  }
314 
317  {
318  init_if_necessary(viennacl::traits::context(other));
319  viennacl::backend::memory_copy(other.handle(), val_, other.index() * sizeof(SCALARTYPE), 0, sizeof(SCALARTYPE));
320  return *this;
321  }
322 
325  {
326  init_if_necessary(viennacl::traits::context(other));
327  viennacl::backend::memory_copy(other.handle(), val_, 0, 0, sizeof(SCALARTYPE));
328  return *this;
329  }
330 
331  self_type & operator= (float cpu_other)
332  {
333  init_if_necessary(viennacl::context());
334 
335  //copy value:
336  SCALARTYPE value = static_cast<SCALARTYPE>(cpu_other);
337  viennacl::backend::memory_write(val_, 0, sizeof(SCALARTYPE), &value);
338  return *this;
339  }
340 
341  self_type & operator= (double cpu_other)
342  {
343  init_if_necessary(viennacl::context());
344 
345  SCALARTYPE value = static_cast<SCALARTYPE>(cpu_other);
346  viennacl::backend::memory_write(val_, 0, sizeof(SCALARTYPE), &value);
347  return *this;
348  }
349 
350  self_type & operator= (long cpu_other)
351  {
352  init_if_necessary(viennacl::context());
353 
354  SCALARTYPE value = static_cast<SCALARTYPE>(cpu_other);
355  viennacl::backend::memory_write(val_, 0, sizeof(SCALARTYPE), &value);
356  return *this;
357  }
358 
359  self_type & operator= (unsigned long cpu_other)
360  {
361  init_if_necessary(viennacl::context());
362 
363  SCALARTYPE value = static_cast<SCALARTYPE>(cpu_other);
364  viennacl::backend::memory_write(val_, 0, sizeof(SCALARTYPE), &value);
365  return *this;
366  }
367 
368  self_type & operator= (int cpu_other)
369  {
370  init_if_necessary(viennacl::context());
371 
372  SCALARTYPE value = static_cast<SCALARTYPE>(cpu_other);
373  viennacl::backend::memory_write(val_, 0, sizeof(SCALARTYPE), &value);
374  return *this;
375  }
376 
377  self_type & operator= (unsigned int cpu_other)
378  {
379  init_if_necessary(viennacl::context());
380 
381  SCALARTYPE value = static_cast<SCALARTYPE>(cpu_other);
382  viennacl::backend::memory_write(val_, 0, sizeof(SCALARTYPE), &value);
383  return *this;
384  }
385 
387  template <typename T1, typename T2>
389  {
390  init_if_necessary(viennacl::traits::context(proxy));
391 
392  viennacl::linalg::inner_prod_impl(proxy.lhs(), proxy.rhs(), *this);
393  return *this;
394  }
395 
397  template <typename T1, typename T2>
399  {
400  init_if_necessary(viennacl::traits::context(proxy));
401 
402  viennacl::linalg::norm_1_impl(proxy.lhs(), *this);
403  return *this;
404  }
405 
407  template <typename T1, typename T2>
409  {
410  init_if_necessary(viennacl::traits::context(proxy));
411 
412  viennacl::linalg::norm_2_impl(proxy.lhs(), *this);
413  return *this;
414  }
415 
417  template <typename T1, typename T2>
419  {
420  init_if_necessary(viennacl::traits::context(proxy));
421 
422  viennacl::linalg::norm_inf_impl(proxy.lhs(), *this);
423  return *this;
424  }
425 
427  template <typename T1, typename T2>
429  {
430  init_if_necessary(viennacl::traits::context(proxy));
431 
432  viennacl::linalg::norm_frobenius_impl(proxy.lhs(), *this);
433  return *this;
434  }
435 
437  template <typename T1, typename T2>
439  {
440  init_if_necessary(viennacl::traits::context(proxy));
441 
442  viennacl::linalg::as(*this, proxy.lhs(), SCALARTYPE(-1.0), 1, false, true);
443  return *this;
444  }
445 
446 
449  {
450  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
451 
452  viennacl::linalg::asbs(*this, // s1 =
453  *this, SCALARTYPE(1.0), 1, false, false, // s1 * 1.0
454  other, SCALARTYPE(1.0), 1, false, false); // + s2 * 1.0
455  return *this;
456  }
458  self_type & operator += (SCALARTYPE other)
459  {
460  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
461 
462  viennacl::linalg::asbs(*this, // s1 =
463  *this, SCALARTYPE(1.0), 1, false, false, // s1 * 1.0
464  other, SCALARTYPE(1.0), 1, false, false); // + s2 * 1.0
465  return *this;
466  }
467 
468 
471  {
472  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
473 
474  viennacl::linalg::asbs(*this, // s1 =
475  *this, SCALARTYPE(1.0), 1, false, false, // s1 * 1.0
476  other, SCALARTYPE(-1.0), 1, false, false); // + s2 * (-1.0)
477  return *this;
478  }
480  self_type & operator -= (SCALARTYPE other)
481  {
482  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
483 
484  viennacl::linalg::asbs(*this, // s1 =
485  *this, SCALARTYPE(1.0), 1, false, false, // s1 * 1.0
486  other, SCALARTYPE(-1.0), 1, false, false); // + s2 * (-1.0)
487  return *this;
488  }
489 
490 
493  {
494  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
495 
496  viennacl::linalg::as(*this, // s1 =
497  *this, other, 1, false, false); // s1 * s2
498  return *this;
499  }
501  self_type & operator *= (SCALARTYPE other)
502  {
503  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
504 
505  viennacl::linalg::as(*this, // s1 =
506  *this, other, 1, false, false); // s1 * s2
507  return *this;
508  }
509 
510 
512 
514  {
515  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
516 
517  viennacl::linalg::as(*this, // s1 =
518  *this, other, 1, true, false); // s1 / s2
519  return *this;
520  }
522  self_type & operator /= (SCALARTYPE other)
523  {
524  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
525 
526  viennacl::linalg::as(*this, // s1 =
527  *this, other, 1, true, false); // s1 / s2
528  return *this;
529  }
530 
531 
533 
535  {
536  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
537 
538  self_type result = 0;
539 
540  viennacl::linalg::asbs(result, // result =
541  *this, SCALARTYPE(1.0), 1, false, false, // *this * 1.0
542  other, SCALARTYPE(1.0), 1, false, false); // + other * 1.0
543 
544  return result;
545  }
547  template <typename T1, typename T2, typename OP>
549  {
550  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
551 
552  self_type result = proxy;
553 
554  viennacl::linalg::asbs(result, // result =
555  *this, SCALARTYPE(1.0), 1, false, false, // *this * 1.0
556  result, SCALARTYPE(1.0), 1, false, false); // + result * 1.0
557 
558  return result;
559  }
561  self_type operator + (SCALARTYPE other)
562  {
563  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
564 
565  self_type result = 0;
566 
567  viennacl::linalg::asbs(result, // result =
568  *this, SCALARTYPE(1.0), 1, false, false, // *this * 1.0
569  other, SCALARTYPE(1.0), 1, false, false); // + other * 1.0
570 
571  return result;
572  }
573 
574 
576 
579  {
581  }
582 
583 
586  {
587  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
588 
589  self_type result = 0;
590 
591  viennacl::linalg::asbs(result, // result =
592  *this, SCALARTYPE(1.0), 1, false, false, // *this * 1.0
593  other, SCALARTYPE(-1.0), 1, false, false); // + other * (-1.0)
594 
595  return result;
596  }
598  template <typename T1, typename T2, typename OP>
600  {
601  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
602 
603  self_type result = proxy;
604 
605  viennacl::linalg::asbs(result, // result =
606  *this, SCALARTYPE(1.0), 1 , false, false, // *this * 1.0
607  result, SCALARTYPE(-1.0), 1, false, false); // + result * (-1.0)
608 
609  return result;
610  }
612  scalar<SCALARTYPE> operator - (SCALARTYPE other) const
613  {
614  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
615 
616  self_type result = 0;
617 
618  viennacl::linalg::asbs(result, // result =
619  *this, SCALARTYPE(1.0), 1, false, false, // *this * 1.0
620  other, SCALARTYPE(-1.0), 1, false, false); // + other * (-1.0)
621 
622  return result;
623  }
624 
626 
628  {
629  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
630 
631  scalar<SCALARTYPE> result = 0;
632 
633  viennacl::linalg::as(result, // result =
634  *this, other, 1, false, false); // *this * other
635 
636  return result;
637  }
639  template <typename T1, typename T2, typename OP>
641  {
642  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
643 
644  self_type result = proxy;
645 
646  viennacl::linalg::as(result, // result =
647  *this, result, 1, false, false); // *this * proxy
648 
649  return result;
650  }
652  self_type operator * (SCALARTYPE other) const
653  {
654  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
655 
656  scalar<SCALARTYPE> result = 0;
657 
658  viennacl::linalg::as(result, // result =
659  *this, other, 1, false, false); // *this * other
660 
661  return result;
662  }
663 
665 
667  {
668  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
669 
670  self_type result = 0;
671 
672  viennacl::linalg::as(result, // result =
673  *this, other, 1, true, false); // *this / other
674 
675  return result;
676  }
678  template <typename T1, typename T2, typename OP>
680  {
681  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
682 
683  self_type result = proxy;
684 
685  viennacl::linalg::as(result, // result =
686  *this, result, 1, true, false); // *this / proxy
687 
688  return result;
689  }
691  self_type operator / (SCALARTYPE other) const
692  {
693  assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
694 
695  self_type result = 0;
696 
697  viennacl::linalg::as(result, // result =
698  *this, other, 1, true, false); // *this / other
699 
700  return result;
701  }
702 
704  handle_type & handle() { return val_; }
705 
707  const handle_type & handle() const { return val_; }
708 
709  private:
710 
711  void init_if_necessary(viennacl::context ctx)
712  {
714  {
715  viennacl::backend::memory_create(val_, sizeof(SCALARTYPE), ctx);
716  }
717  }
718 
719  handle_type val_;
720  };
721 
722 
723  //stream operators:
725  template<class SCALARTYPE>
726  std::ostream & operator<<(std::ostream & s, const scalar<SCALARTYPE> & val)
727  {
728  SCALARTYPE temp = val;
729  s << temp;
730  return s;
731  }
732 
734  template<class SCALARTYPE>
735  std::istream & operator>>(std::istream & s, const scalar<SCALARTYPE> & val)
736  {
737  SCALARTYPE temp;
738  s >> temp;
739  val = temp;
740  return s;
741  }
742 
743 } //namespace viennacl
744 
745 #endif
viennacl::enable_if< viennacl::is_scalar< S1 >::value &&viennacl::is_scalar< S2 >::value &&viennacl::is_any_scalar< ScalarType1 >::value >::type as(S1 &s1, S2 const &s2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Interface for the generic operation s1 = s2 @ alpha, where s1 and s2 are GPU scalars, @ denotes multiplication or division, and alpha is either a GPU or a CPU scalar.
Definition: scalar_operations.hpp:65
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:218
scalar(SCALARTYPE val, viennacl::context ctx=viennacl::context())
Allocates the memory for the scalar and sets it to the supplied value.
Definition: scalar.hpp:263
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:216
std::size_t vcl_size_t
Definition: forwards.h:58
void memory_write(mem_handle &dst_buffer, vcl_size_t dst_offset, vcl_size_t bytes_to_write, const void *ptr, bool async=false)
Writes data from main RAM identified by 'ptr' to the buffer identified by 'dst_buffer'.
Definition: memory.hpp:220
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:172
Definition: forwards.h:478
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:184
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:153
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:156
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:119
Implementations of scalar operations.
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
self_type & operator-=(scalar< SCALARTYPE > const &other)
Inplace subtraction of a ViennaCL scalar.
Definition: scalar.hpp:470
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:186
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:88
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:56
This file provides the forward declarations for the main types used within ViennaCL.
void memory_read(mem_handle const &src_buffer, vcl_size_t src_offset, vcl_size_t bytes_to_read, void *ptr, bool async=false)
Reads data from a buffer back to main RAM.
Definition: memory.hpp:261
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:53
A proxy for scalar expressions (e.g. from inner vector products)
Definition: forwards.h:175
std::istream & operator>>(std::istream &s, const scalar< SCALARTYPE > &val)
Allows to directly read a value of a scalar from an input stream.
Definition: scalar.hpp:735
scalar_expression< const self_type, const self_type, op_flip_sign > operator-() const
Sign flip of the scalar. Does not evaluate immediately, but instead returns an expression template ob...
Definition: scalar.hpp:578
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:191
const handle_type & handle() const
Returns the memory handle, const version.
Definition: scalar.hpp:707
self_type & operator/=(scalar< SCALARTYPE > const &other)
Inplace division with a ViennaCL scalar.
Definition: scalar.hpp:513
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
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
scalar()
Creates the scalar object, but does not yet allocate memory. Thus, scalar<> can also be a global vari...
Definition: scalar.hpp:260
handle_type & handle()
Returns the memory handle, non-const version.
Definition: scalar.hpp:704
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:189
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
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:93
self_type operator*(scalar< SCALARTYPE > const &other) const
Multiplication of two ViennaCL scalars.
Definition: scalar.hpp:627
void norm_frobenius_cpu(matrix_base< T, F > const &vec, T &result)
Computes the Frobenius norm of a vector with final reduction on the CPU.
Definition: matrix_operations.hpp:325
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
vcl_size_t index() const
Returns the index of the represented element.
Definition: entry_proxy.hpp:137
vcl_size_t size_type
Definition: scalar.hpp:254
scalar(scalar_expression< T1, T2, OP > const &proxy)
Allocates memory for the scalar and sets it to the result of supplied expression. ...
Definition: scalar.hpp:284
self_type operator+(scalar< SCALARTYPE > const &other)
Addition of two ViennaCL scalars.
Definition: scalar.hpp:534
SCALARTYPE value_type
Returns the underlying host scalar type.
Definition: scalar.hpp:257
self_type & operator=(entry_proxy< SCALARTYPE > const &other)
Assigns a vector entry.
Definition: scalar.hpp:316
viennacl::enable_if< viennacl::is_scalar< S1 >::value &&viennacl::is_scalar< S2 >::value &&viennacl::is_scalar< S3 >::value &&viennacl::is_any_scalar< ScalarType1 >::value &&viennacl::is_any_scalar< ScalarType2 >::value >::type asbs(S1 &s1, S2 const &s2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, S3 const &s3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Interface for the generic operation s1 = s2 @ alpha + s3 @ beta, where s1, s2 and s3 are GPU scalars...
Definition: scalar_operations.hpp:114
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
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:124
Implementations of the OpenCL backend, where all contexts are stored in.
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:221
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:223
handle_type const & handle() const
Returns the memory viennacl::ocl::handle.
Definition: entry_proxy.hpp:141
viennacl::backend::mem_handle handle_type
Definition: scalar.hpp:253
A tag class representing the 1-norm of a vector.
Definition: forwards.h:153
void memory_copy(mem_handle const &src_buffer, mem_handle &dst_buffer, vcl_size_t src_offset, vcl_size_t dst_offset, vcl_size_t bytes_to_copy)
Copies 'bytes_to_copy' bytes from address 'src_buffer + src_offset' to memory starting at address 'ds...
Definition: memory.hpp:140
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:41
self_type operator/(scalar< SCALARTYPE > const &other) const
Division of two ViennaCL scalars.
Definition: scalar.hpp:666
scalar(const scalar &other)
Copy constructor. Allocates new memory for the scalar and copies the value of the supplied scalar...
Definition: scalar.hpp:293
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
Definition: result_of.hpp:276
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
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:58
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:86
viennacl::result_of::cpu_value_type< DummyType >::type ScalarType
Definition: scalar.hpp:51
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
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:62
self_type & operator*=(scalar< SCALARTYPE > const &other)
Inplace multiplication with a ViennaCL scalar.
Definition: scalar.hpp:492
A tag class representing the Frobenius-norm of a matrix.
Definition: forwards.h:162
void memory_create(mem_handle &handle, vcl_size_t size_in_bytes, viennacl::context const &ctx, const void *host_ptr=NULL)
Creates an array of the specified size. If the second argument is provided, the buffer is initialized...
Definition: memory.hpp:87
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:158
void norm_frobenius_impl(matrix_base< T, F > const &vec, scalar< T > &result)
Computes the Frobenius norm of a matrix - dispatcher interface.
Definition: matrix_operations.hpp:311
void switch_active_handle_id(memory_types new_id)
Switches the currently active handle. If no support for that backend is provided, an exception is thr...
Definition: mem_handle.hpp:94
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
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:151
A tag class representing inner products of two vectors.
Definition: forwards.h:150
self_type & operator+=(scalar< SCALARTYPE > const &other)
Inplace addition of a ViennaCL scalar.
Definition: scalar.hpp:448
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
Definition: forwards.h:178
A tag class representing the inf-norm of a vector.
Definition: forwards.h:159
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:91
A tag class representing the 2-norm of a vector.
Definition: forwards.h:156
A collection of compile time type deductions.
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
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:126
Main interface routines for memory management.
void norm_inf_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:716
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:121