ViennaCL - The Vienna Computing Library  1.6.1
Free open-source GPU-accelerated linear algebra and solver library.
viennacl::scalar< NumericT > Class Template Reference

This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type like float or double. More...

#include <forwards.h>

Public Types

typedef viennacl::backend::mem_handle handle_type
 
typedef vcl_size_t size_type
 
typedef NumericT value_type
 Returns the underlying host scalar type. More...
 

Public Member Functions

 scalar ()
 Creates the scalar object, but does not yet allocate memory. Thus, scalar<> can also be a global variable (if really necessary). More...
 
 scalar (NumericT val, viennacl::context ctx=viennacl::context())
 Allocates the memory for the scalar and sets it to the supplied value. More...
 
template<typename T1 , typename T2 , typename OP >
 scalar (scalar_expression< T1, T2, OP > const &proxy)
 Allocates memory for the scalar and sets it to the result of supplied expression. More...
 
 scalar (const scalar &other)
 Copy constructor. Allocates new memory for the scalar and copies the value of the supplied scalar. More...
 
 operator NumericT () const
 Reads the value of the scalar from the GPU and returns the float or double value. More...
 
self_typeoperator= (entry_proxy< NumericT > const &other)
 Assigns a vector entry. More...
 
self_typeoperator= (scalar< NumericT > const &other)
 Assigns the value from another scalar. More...
 
self_typeoperator= (float cpu_other)
 
self_typeoperator= (double cpu_other)
 
self_typeoperator= (long cpu_other)
 
self_typeoperator= (unsigned long cpu_other)
 
self_typeoperator= (int cpu_other)
 
self_typeoperator= (unsigned int cpu_other)
 
template<typename T1 , typename T2 >
self_typeoperator= (scalar_expression< T1, T2, op_inner_prod > const &proxy)
 Sets the scalar to the result of supplied inner product expression. More...
 
template<typename T1 , typename T2 >
self_typeoperator= (scalar_expression< T1, T2, op_norm_1 > const &proxy)
 Sets the scalar to the result of supplied norm_1 expression. More...
 
template<typename T1 , typename T2 >
self_typeoperator= (scalar_expression< T1, T2, op_norm_2 > const &proxy)
 Sets the scalar to the result of supplied norm_2 expression. More...
 
template<typename T1 , typename T2 >
self_typeoperator= (scalar_expression< T1, T2, op_norm_inf > const &proxy)
 Sets the scalar to the result of supplied norm_inf expression. More...
 
template<typename T1 , typename T2 >
self_typeoperator= (scalar_expression< T1, T2, op_max > const &proxy)
 Sets the scalar to the result of supplied norm_inf expression. More...
 
template<typename T1 , typename T2 >
self_typeoperator= (scalar_expression< T1, T2, op_min > const &proxy)
 Sets the scalar to the result of supplied norm_inf expression. More...
 
template<typename T1 , typename T2 >
self_typeoperator= (scalar_expression< T1, T2, op_norm_frobenius > const &proxy)
 Sets the scalar to the result of supplied norm_frobenius expression. More...
 
template<typename T1 , typename T2 >
self_typeoperator= (scalar_expression< T1, T2, op_flip_sign > const &proxy)
 Sets the scalar to the inverse with respect to addition of the supplied sub-expression. More...
 
self_typeoperator+= (scalar< NumericT > const &other)
 Inplace addition of a ViennaCL scalar. More...
 
self_typeoperator+= (NumericT other)
 Inplace addition of a host scalar (float or double) More...
 
self_typeoperator-= (scalar< NumericT > const &other)
 Inplace subtraction of a ViennaCL scalar. More...
 
self_typeoperator-= (NumericT other)
 Inplace subtraction of a host scalar (float or double) More...
 
self_typeoperator*= (scalar< NumericT > const &other)
 Inplace multiplication with a ViennaCL scalar. More...
 
self_typeoperator*= (NumericT other)
 Inplace multiplication with a host scalar (float or double) More...
 
self_typeoperator/= (scalar< NumericT > const &other)
 Inplace division with a ViennaCL scalar. More...
 
self_typeoperator/= (NumericT other)
 Inplace division with a host scalar (float or double) More...
 
self_type operator+ (scalar< NumericT > const &other)
 Addition of two ViennaCL scalars. More...
 
template<typename T1 , typename T2 , typename OP >
self_type operator+ (scalar_expression< T1, T2, OP > const &proxy) const
 Addition of a ViennaCL scalar with a scalar expression. More...
 
self_type operator+ (NumericT other)
 Addition of a ViennaCL scalar with a host scalar (float, double) More...
 
scalar_expression< const self_type, const self_type, op_flip_signoperator- () const
 Sign flip of the scalar. Does not evaluate immediately, but instead returns an expression template object. More...
 
self_type operator- (scalar< NumericT > const &other) const
 Subtraction of two ViennaCL scalars. More...
 
template<typename T1 , typename T2 , typename OP >
self_type operator- (scalar_expression< T1, T2, OP > const &proxy) const
 Subtraction of a ViennaCL scalar from a scalar expression. More...
 
scalar< NumericT > operator- (NumericT other) const
 Subtraction of a host scalar (float, double) from a ViennaCL scalar. More...
 
self_type operator* (scalar< NumericT > const &other) const
 Multiplication of two ViennaCL scalars. More...
 
template<typename T1 , typename T2 , typename OP >
self_type operator* (scalar_expression< T1, T2, OP > const &proxy) const
 Multiplication of a ViennaCL scalar with a scalar expression. More...
 
self_type operator* (NumericT other) const
 Multiplication of a host scalar (float, double) with a ViennaCL scalar. More...
 
self_type operator/ (scalar< NumericT > const &other) const
 Division of two ViennaCL scalars. More...
 
template<typename T1 , typename T2 , typename OP >
self_type operator/ (scalar_expression< T1, T2, OP > const &proxy) const
 Division of a ViennaCL scalar by a scalar expression. More...
 
self_type operator/ (NumericT other) const
 Division of a ViennaCL scalar by a host scalar (float, double) More...
 
handle_typehandle ()
 Returns the memory handle, non-const version. More...
 
const handle_typehandle () const
 Returns the memory handle, const version. More...
 

Detailed Description

template<class NumericT>
class viennacl::scalar< NumericT >

This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type like float or double.

Since every read and write operation requires a CPU->GPU or GPU->CPU transfer, this type should be used with care. The advantage of this type is that the GPU command queue can be filled without blocking read operations.

Template Parameters
NumericTEither float or double. Checked at compile time.
Examples:
blas1.cpp, blas2.cpp, and custom-context.cpp.

Definition at line 226 of file forwards.h.

Member Typedef Documentation

template<class NumericT>
typedef viennacl::backend::mem_handle viennacl::scalar< NumericT >::handle_type

Definition at line 320 of file scalar.hpp.

template<class NumericT>
typedef vcl_size_t viennacl::scalar< NumericT >::size_type

Definition at line 321 of file scalar.hpp.

template<class NumericT>
typedef NumericT viennacl::scalar< NumericT >::value_type

Returns the underlying host scalar type.

Definition at line 324 of file scalar.hpp.

Constructor & Destructor Documentation

template<class NumericT>
viennacl::scalar< NumericT >::scalar ( )
inline

Creates the scalar object, but does not yet allocate memory. Thus, scalar<> can also be a global variable (if really necessary).

Definition at line 327 of file scalar.hpp.

template<class NumericT>
viennacl::scalar< NumericT >::scalar ( NumericT  val,
viennacl::context  ctx = viennacl::context() 
)
inline

Allocates the memory for the scalar and sets it to the supplied value.

Definition at line 330 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 , typename OP >
viennacl::scalar< NumericT >::scalar ( scalar_expression< T1, T2, OP > const &  proxy)
inline

Allocates memory for the scalar and sets it to the result of supplied expression.

Definition at line 351 of file scalar.hpp.

template<class NumericT>
viennacl::scalar< NumericT >::scalar ( const scalar< NumericT > &  other)
inline

Copy constructor. Allocates new memory for the scalar and copies the value of the supplied scalar.

Definition at line 360 of file scalar.hpp.

Member Function Documentation

template<class NumericT>
handle_type& viennacl::scalar< NumericT >::handle ( )
inline

Returns the memory handle, non-const version.

Definition at line 792 of file scalar.hpp.

template<class NumericT>
const handle_type& viennacl::scalar< NumericT >::handle ( ) const
inline

Returns the memory handle, const version.

Definition at line 795 of file scalar.hpp.

template<class NumericT>
viennacl::scalar< NumericT >::operator NumericT ( ) const
inline

Reads the value of the scalar from the GPU and returns the float or double value.

Definition at line 372 of file scalar.hpp.

template<class NumericT>
self_type viennacl::scalar< NumericT >::operator* ( scalar< NumericT > const &  other) const
inline

Multiplication of two ViennaCL scalars.

Definition at line 715 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 , typename OP >
self_type viennacl::scalar< NumericT >::operator* ( scalar_expression< T1, T2, OP > const &  proxy) const
inline

Multiplication of a ViennaCL scalar with a scalar expression.

Definition at line 728 of file scalar.hpp.

template<class NumericT>
self_type viennacl::scalar< NumericT >::operator* ( NumericT  other) const
inline

Multiplication of a host scalar (float, double) with a ViennaCL scalar.

Definition at line 740 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator*= ( scalar< NumericT > const &  other)
inline

Inplace multiplication with a ViennaCL scalar.

Definition at line 580 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator*= ( NumericT  other)
inline

Inplace multiplication with a host scalar (float or double)

Definition at line 589 of file scalar.hpp.

template<class NumericT>
self_type viennacl::scalar< NumericT >::operator+ ( scalar< NumericT > const &  other)
inline

Addition of two ViennaCL scalars.

Definition at line 622 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 , typename OP >
self_type viennacl::scalar< NumericT >::operator+ ( scalar_expression< T1, T2, OP > const &  proxy) const
inline

Addition of a ViennaCL scalar with a scalar expression.

Definition at line 636 of file scalar.hpp.

template<class NumericT>
self_type viennacl::scalar< NumericT >::operator+ ( NumericT  other)
inline

Addition of a ViennaCL scalar with a host scalar (float, double)

Definition at line 649 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator+= ( scalar< NumericT > const &  other)
inline

Inplace addition of a ViennaCL scalar.

Definition at line 536 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator+= ( NumericT  other)
inline

Inplace addition of a host scalar (float or double)

Definition at line 546 of file scalar.hpp.

template<class NumericT>
scalar_expression<const self_type, const self_type, op_flip_sign> viennacl::scalar< NumericT >::operator- ( ) const
inline

Sign flip of the scalar. Does not evaluate immediately, but instead returns an expression template object.

Definition at line 666 of file scalar.hpp.

template<class NumericT>
self_type viennacl::scalar< NumericT >::operator- ( scalar< NumericT > const &  other) const
inline

Subtraction of two ViennaCL scalars.

Definition at line 673 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 , typename OP >
self_type viennacl::scalar< NumericT >::operator- ( scalar_expression< T1, T2, OP > const &  proxy) const
inline

Subtraction of a ViennaCL scalar from a scalar expression.

Definition at line 687 of file scalar.hpp.

template<class NumericT>
scalar<NumericT> viennacl::scalar< NumericT >::operator- ( NumericT  other) const
inline

Subtraction of a host scalar (float, double) from a ViennaCL scalar.

Definition at line 700 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator-= ( scalar< NumericT > const &  other)
inline

Inplace subtraction of a ViennaCL scalar.

Definition at line 558 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator-= ( NumericT  other)
inline

Inplace subtraction of a host scalar (float or double)

Definition at line 568 of file scalar.hpp.

template<class NumericT>
self_type viennacl::scalar< NumericT >::operator/ ( scalar< NumericT > const &  other) const
inline

Division of two ViennaCL scalars.

Definition at line 754 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 , typename OP >
self_type viennacl::scalar< NumericT >::operator/ ( scalar_expression< T1, T2, OP > const &  proxy) const
inline

Division of a ViennaCL scalar by a scalar expression.

Definition at line 767 of file scalar.hpp.

template<class NumericT>
self_type viennacl::scalar< NumericT >::operator/ ( NumericT  other) const
inline

Division of a ViennaCL scalar by a host scalar (float, double)

Definition at line 779 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator/= ( scalar< NumericT > const &  other)
inline

Inplace division with a ViennaCL scalar.

Definition at line 601 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator/= ( NumericT  other)
inline

Inplace division with a host scalar (float or double)

Definition at line 610 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator= ( entry_proxy< NumericT > const &  other)
inline

Assigns a vector entry.

Definition at line 383 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator= ( scalar< NumericT > const &  other)
inline

Assigns the value from another scalar.

Definition at line 391 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator= ( float  cpu_other)
inline

Definition at line 398 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator= ( double  cpu_other)
inline

Definition at line 408 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator= ( long  cpu_other)
inline

Definition at line 417 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator= ( unsigned long  cpu_other)
inline

Definition at line 426 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator= ( int  cpu_other)
inline

Definition at line 435 of file scalar.hpp.

template<class NumericT>
self_type& viennacl::scalar< NumericT >::operator= ( unsigned int  cpu_other)
inline

Definition at line 444 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 >
self_type& viennacl::scalar< NumericT >::operator= ( scalar_expression< T1, T2, op_inner_prod > const &  proxy)
inline

Sets the scalar to the result of supplied inner product expression.

Definition at line 455 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 >
self_type& viennacl::scalar< NumericT >::operator= ( scalar_expression< T1, T2, op_norm_1 > const &  proxy)
inline

Sets the scalar to the result of supplied norm_1 expression.

Definition at line 465 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 >
self_type& viennacl::scalar< NumericT >::operator= ( scalar_expression< T1, T2, op_norm_2 > const &  proxy)
inline

Sets the scalar to the result of supplied norm_2 expression.

Definition at line 475 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 >
self_type& viennacl::scalar< NumericT >::operator= ( scalar_expression< T1, T2, op_norm_inf > const &  proxy)
inline

Sets the scalar to the result of supplied norm_inf expression.

Definition at line 485 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 >
self_type& viennacl::scalar< NumericT >::operator= ( scalar_expression< T1, T2, op_max > const &  proxy)
inline

Sets the scalar to the result of supplied norm_inf expression.

Definition at line 495 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 >
self_type& viennacl::scalar< NumericT >::operator= ( scalar_expression< T1, T2, op_min > const &  proxy)
inline

Sets the scalar to the result of supplied norm_inf expression.

Definition at line 505 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 >
self_type& viennacl::scalar< NumericT >::operator= ( scalar_expression< T1, T2, op_norm_frobenius > const &  proxy)
inline

Sets the scalar to the result of supplied norm_frobenius expression.

Definition at line 516 of file scalar.hpp.

template<class NumericT>
template<typename T1 , typename T2 >
self_type& viennacl::scalar< NumericT >::operator= ( scalar_expression< T1, T2, op_flip_sign > const &  proxy)
inline

Sets the scalar to the inverse with respect to addition of the supplied sub-expression.

Definition at line 526 of file scalar.hpp.


The documentation for this class was generated from the following files: