ViennaCL - The Vienna Computing Library  1.7.0
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 max 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 min expression. More...
 
template<typename T1 , typename T2 >
self_typeoperator= (scalar_expression< T1, T2, op_sum > const &proxy)
 Sets the scalar to the result of supplied sum 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< NumericToperator- (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 227 of file forwards.h.

Member Typedef Documentation

Definition at line 351 of file scalar.hpp.

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

Definition at line 352 of file scalar.hpp.

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

Returns the underlying host scalar type.

Definition at line 355 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 358 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 361 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 382 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 391 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 833 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 836 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 403 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 756 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 769 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 781 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 621 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 630 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 663 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 677 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 690 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 577 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 587 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 707 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 714 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 728 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 741 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 599 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 609 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 795 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 808 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 820 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 642 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 651 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 414 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 422 of file scalar.hpp.

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

Definition at line 429 of file scalar.hpp.

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

Definition at line 439 of file scalar.hpp.

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

Definition at line 448 of file scalar.hpp.

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

Definition at line 457 of file scalar.hpp.

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

Definition at line 466 of file scalar.hpp.

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

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_inner_prod > const &  proxy)
inline

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

Definition at line 486 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 496 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 506 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 516 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 max expression.

Definition at line 526 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 min expression.

Definition at line 536 of file scalar.hpp.

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

Sets the scalar to the result of supplied sum expression.

Definition at line 546 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 557 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 567 of file scalar.hpp.


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