All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scalar.hpp
Go to the documentation of this file.
#ifndef VIENNACL_SCALAR_HPP_
#define VIENNACL_SCALAR_HPP_
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <iostream>
#include "viennacl/forwards.h"
#include "viennacl/backend/memory.hpp"
#include "viennacl/meta/result_of.hpp"
#include "viennacl/linalg/scalar_operations.hpp"
#include "viennacl/traits/handle.hpp"
#ifdef VIENNACL_WITH_OPENCL
#include "viennacl/ocl/backend.hpp"
#endif
namespace viennacl
{
template<typename LHS, typename RHS, typename OP>
class scalar_expression
{
typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
public:
typedef typename viennacl::result_of::cpu_value_type<DummyType>::type ScalarType;
scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
LHS & lhs() const { return lhs_; }
RHS & rhs() const { return rhs_; }
operator ScalarType () const
{
viennacl::scalar<ScalarType> temp;
temp = *this;
return temp;
}
private:
LHS & lhs_;
RHS & rhs_;
};
template<typename LHS, typename RHS>
class scalar_expression<LHS, RHS, op_inner_prod>
{
//typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
public:
typedef typename viennacl::result_of::cpu_value_type<LHS>::type ScalarType;
scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
LHS & lhs() const { return lhs_; }
RHS & rhs() const { return rhs_; }
operator ScalarType () const
{
ScalarType result;
viennacl::linalg::inner_prod_cpu(lhs_, rhs_, result);
return result;
}
private:
LHS & lhs_;
RHS & rhs_;
};
template<typename LHS, typename RHS>
class scalar_expression<LHS, RHS, op_norm_1>
{
//typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
public:
typedef typename viennacl::result_of::cpu_value_type<LHS>::type ScalarType;
scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
LHS & lhs() const { return lhs_; }
RHS & rhs() const { return rhs_; }
operator ScalarType () const
{
ScalarType result;
viennacl::linalg::norm_1_cpu(lhs_, result);
return result;
}
private:
LHS & lhs_;
RHS & rhs_;
};
template<typename LHS, typename RHS>
class scalar_expression<LHS, RHS, op_norm_2>
{
//typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
public:
typedef typename viennacl::result_of::cpu_value_type<LHS>::type ScalarType;
scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
LHS & lhs() const { return lhs_; }
RHS & rhs() const { return rhs_; }
operator ScalarType () const
{
ScalarType result;
viennacl::linalg::norm_2_cpu(lhs_, result);
return result;
}
private:
LHS & lhs_;
RHS & rhs_;
};
template<typename LHS, typename RHS>
class scalar_expression<LHS, RHS, op_norm_inf>
{
//typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
public:
typedef typename viennacl::result_of::cpu_value_type<LHS>::type ScalarType;
scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
LHS & lhs() const { return lhs_; }
RHS & rhs() const { return rhs_; }
operator ScalarType () const
{
ScalarType result;
viennacl::linalg::norm_inf_cpu(lhs_, result);
return result;
}
private:
LHS & lhs_;
RHS & rhs_;
};
template<typename LHS, typename RHS>
class scalar_expression<LHS, RHS, op_max>
{
//typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
public:
typedef typename viennacl::result_of::cpu_value_type<LHS>::type ScalarType;
scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
LHS & lhs() const { return lhs_; }
RHS & rhs() const { return rhs_; }
operator ScalarType () const
{
ScalarType result;
viennacl::linalg::max_cpu(lhs_, result);
return result;
}
private:
LHS & lhs_;
RHS & rhs_;
};
template<typename LHS, typename RHS>
class scalar_expression<LHS, RHS, op_min>
{
//typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
public:
typedef typename viennacl::result_of::cpu_value_type<LHS>::type ScalarType;
scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
LHS & lhs() const { return lhs_; }
RHS & rhs() const { return rhs_; }
operator ScalarType () const
{
ScalarType result;
viennacl::linalg::min_cpu(lhs_, result);
return result;
}
private:
LHS & lhs_;
RHS & rhs_;
};
template<typename LHS, typename RHS>
class scalar_expression<LHS, RHS, op_sum>
{
//typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
public:
typedef typename viennacl::result_of::cpu_value_type<LHS>::type ScalarType;
scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
LHS & lhs() const { return lhs_; }
RHS & rhs() const { return rhs_; }
operator ScalarType () const
{
ScalarType result;
viennacl::linalg::sum_cpu(lhs_, result);
return result;
}
private:
LHS & lhs_;
RHS & rhs_;
};
template<typename LHS, typename RHS>
class scalar_expression<LHS, RHS, op_norm_frobenius>
{
//typedef typename LHS::value_type DummyType; //Visual C++ 2005 does not allow to write LHS::value_type::value_type
public:
typedef typename viennacl::result_of::cpu_value_type<LHS>::type ScalarType;
scalar_expression(LHS & lhs, RHS & rhs) : lhs_(lhs), rhs_(rhs) {}
LHS & lhs() const { return lhs_; }
RHS & rhs() const { return rhs_; }
operator ScalarType () const
{
ScalarType result;
viennacl::linalg::norm_frobenius_cpu(lhs_, result);
return result;
}
private:
LHS & lhs_;
RHS & rhs_;
};
template<class NumericT>
class scalar
{
typedef scalar<NumericT> self_type;
public:
typedef viennacl::backend::mem_handle handle_type;
typedef vcl_size_t size_type;
typedef NumericT value_type;
scalar() {}
scalar(NumericT val, viennacl::context ctx = viennacl::context())
{
viennacl::backend::memory_create(val_, sizeof(NumericT), ctx, &val);
}
#ifdef VIENNACL_WITH_OPENCL
explicit scalar(cl_mem mem, size_type /*size*/)
{
val_.switch_active_handle_id(viennacl::OPENCL_MEMORY);
val_.opencl_handle() = mem;
val_.opencl_handle().inc(); //prevents that the user-provided memory is deleted once the vector object is destroyed.
}
#endif
template<typename T1, typename T2, typename OP>
scalar(scalar_expression<T1, T2, OP> const & proxy)
{
val_.switch_active_handle_id(viennacl::traits::handle(proxy.lhs()).get_active_handle_id());
viennacl::backend::memory_create(val_, sizeof(NumericT), viennacl::traits::context(proxy));
*this = proxy;
}
//copy constructor
scalar(const scalar & other)
{
if (other.handle().get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED)
{
//copy value:
val_.switch_active_handle_id(other.handle().get_active_handle_id());
viennacl::backend::memory_create(val_, sizeof(NumericT), viennacl::traits::context(other));
viennacl::backend::memory_copy(other.handle(), val_, 0, 0, sizeof(NumericT));
}
}
operator NumericT() const
{
// make sure the scalar contains reasonable data:
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized, cannot read!"));
NumericT tmp;
viennacl::backend::memory_read(val_, 0, sizeof(NumericT), &tmp);
return tmp;
}
self_type & operator= (entry_proxy<NumericT> const & other)
{
init_if_necessary(viennacl::traits::context(other));
viennacl::backend::memory_copy(other.handle(), val_, other.index() * sizeof(NumericT), 0, sizeof(NumericT));
return *this;
}
self_type & operator= (scalar<NumericT> const & other)
{
init_if_necessary(viennacl::traits::context(other));
viennacl::backend::memory_copy(other.handle(), val_, 0, 0, sizeof(NumericT));
return *this;
}
self_type & operator= (float cpu_other)
{
init_if_necessary(viennacl::context());
//copy value:
NumericT value = static_cast<NumericT>(cpu_other);
viennacl::backend::memory_write(val_, 0, sizeof(NumericT), &value);
return *this;
}
self_type & operator= (double cpu_other)
{
init_if_necessary(viennacl::context());
NumericT value = static_cast<NumericT>(cpu_other);
viennacl::backend::memory_write(val_, 0, sizeof(NumericT), &value);
return *this;
}
self_type & operator= (long cpu_other)
{
init_if_necessary(viennacl::context());
NumericT value = static_cast<NumericT>(cpu_other);
viennacl::backend::memory_write(val_, 0, sizeof(NumericT), &value);
return *this;
}
self_type & operator= (unsigned long cpu_other)
{
init_if_necessary(viennacl::context());
NumericT value = static_cast<NumericT>(cpu_other);
viennacl::backend::memory_write(val_, 0, sizeof(NumericT), &value);
return *this;
}
self_type & operator= (int cpu_other)
{
init_if_necessary(viennacl::context());
NumericT value = static_cast<NumericT>(cpu_other);
viennacl::backend::memory_write(val_, 0, sizeof(NumericT), &value);
return *this;
}
self_type & operator= (unsigned int cpu_other)
{
init_if_necessary(viennacl::context());
NumericT value = static_cast<NumericT>(cpu_other);
viennacl::backend::memory_write(val_, 0, sizeof(NumericT), &value);
return *this;
}
template<typename T1, typename T2>
self_type & operator= (scalar_expression<T1, T2, op_inner_prod> const & proxy)
{
init_if_necessary(viennacl::traits::context(proxy));
viennacl::linalg::inner_prod_impl(proxy.lhs(), proxy.rhs(), *this);
return *this;
}
template<typename T1, typename T2>
self_type & operator= (scalar_expression<T1, T2, op_norm_1> const & proxy)
{
init_if_necessary(viennacl::traits::context(proxy));
viennacl::linalg::norm_1_impl(proxy.lhs(), *this);
return *this;
}
template<typename T1, typename T2>
self_type & operator= (scalar_expression<T1, T2, op_norm_2> const & proxy)
{
init_if_necessary(viennacl::traits::context(proxy));
viennacl::linalg::norm_2_impl(proxy.lhs(), *this);
return *this;
}
template<typename T1, typename T2>
self_type & operator= (scalar_expression<T1, T2, op_norm_inf> const & proxy)
{
init_if_necessary(viennacl::traits::context(proxy));
viennacl::linalg::norm_inf_impl(proxy.lhs(), *this);
return *this;
}
template<typename T1, typename T2>
self_type & operator= (scalar_expression<T1, T2, op_max> const & proxy)
{
init_if_necessary(viennacl::traits::context(proxy));
viennacl::linalg::max_impl(proxy.lhs(), *this);
return *this;
}
template<typename T1, typename T2>
self_type & operator= (scalar_expression<T1, T2, op_min> const & proxy)
{
init_if_necessary(viennacl::traits::context(proxy));
viennacl::linalg::min_impl(proxy.lhs(), *this);
return *this;
}
template<typename T1, typename T2>
self_type & operator= (scalar_expression<T1, T2, op_sum> const & proxy)
{
init_if_necessary(viennacl::traits::context(proxy));
viennacl::linalg::sum_impl(proxy.lhs(), *this);
return *this;
}
template<typename T1, typename T2>
self_type & operator= (scalar_expression<T1, T2, op_norm_frobenius> const & proxy)
{
init_if_necessary(viennacl::traits::context(proxy));
viennacl::linalg::norm_frobenius_impl(proxy.lhs(), *this);
return *this;
}
template<typename T1, typename T2>
self_type & operator= (scalar_expression<T1, T2, op_flip_sign> const & proxy)
{
init_if_necessary(viennacl::traits::context(proxy));
viennacl::linalg::as(*this, proxy.lhs(), NumericT(-1.0), 1, false, true);
return *this;
}
self_type & operator += (scalar<NumericT> const & other)
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
viennacl::linalg::asbs(*this, // s1 =
*this, NumericT(1.0), 1, false, false, // s1 * 1.0
other, NumericT(1.0), 1, false, false); // + s2 * 1.0
return *this;
}
self_type & operator += (NumericT other)
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
viennacl::linalg::asbs(*this, // s1 =
*this, NumericT(1.0), 1, false, false, // s1 * 1.0
other, NumericT(1.0), 1, false, false); // + s2 * 1.0
return *this;
}
self_type & operator -= (scalar<NumericT> const & other)
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
viennacl::linalg::asbs(*this, // s1 =
*this, NumericT(1.0), 1, false, false, // s1 * 1.0
other, NumericT(-1.0), 1, false, false); // + s2 * (-1.0)
return *this;
}
self_type & operator -= (NumericT other)
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
viennacl::linalg::asbs(*this, // s1 =
*this, NumericT(1.0), 1, false, false, // s1 * 1.0
other, NumericT(-1.0), 1, false, false); // + s2 * (-1.0)
return *this;
}
self_type & operator *= (scalar<NumericT> const & other)
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
viennacl::linalg::as(*this, // s1 =
*this, other, 1, false, false); // s1 * s2
return *this;
}
self_type & operator *= (NumericT other)
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
viennacl::linalg::as(*this, // s1 =
*this, other, 1, false, false); // s1 * s2
return *this;
}
self_type & operator /= (scalar<NumericT> const & other)
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
viennacl::linalg::as(*this, // s1 =
*this, other, 1, true, false); // s1 / s2
return *this;
}
self_type & operator /= (NumericT other)
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
viennacl::linalg::as(*this, // s1 =
*this, other, 1, true, false); // s1 / s2
return *this;
}
self_type operator + (scalar<NumericT> const & other)
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
self_type result = 0;
viennacl::linalg::asbs(result, // result =
*this, NumericT(1.0), 1, false, false, // *this * 1.0
other, NumericT(1.0), 1, false, false); // + other * 1.0
return result;
}
template<typename T1, typename T2, typename OP>
self_type operator + (scalar_expression<T1, T2, OP> const & proxy) const
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
self_type result = proxy;
viennacl::linalg::asbs(result, // result =
*this, NumericT(1.0), 1, false, false, // *this * 1.0
result, NumericT(1.0), 1, false, false); // + result * 1.0
return result;
}
self_type operator + (NumericT other)
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
self_type result = 0;
viennacl::linalg::asbs(result, // result =
*this, NumericT(1.0), 1, false, false, // *this * 1.0
other, NumericT(1.0), 1, false, false); // + other * 1.0
return result;
}
scalar_expression<const self_type, const self_type, op_flip_sign> operator-() const
{
return scalar_expression<const self_type, const self_type, op_flip_sign>(*this, *this);
}
self_type operator - (scalar<NumericT> const & other) const
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
self_type result = 0;
viennacl::linalg::asbs(result, // result =
*this, NumericT(1.0), 1, false, false, // *this * 1.0
other, NumericT(-1.0), 1, false, false); // + other * (-1.0)
return result;
}
template<typename T1, typename T2, typename OP>
self_type operator - (scalar_expression<T1, T2, OP> const & proxy) const
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
self_type result = proxy;
viennacl::linalg::asbs(result, // result =
*this, NumericT(1.0), 1 , false, false, // *this * 1.0
result, NumericT(-1.0), 1, false, false); // + result * (-1.0)
return result;
}
scalar<NumericT> operator - (NumericT other) const
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
self_type result = 0;
viennacl::linalg::asbs(result, // result =
*this, NumericT(1.0), 1, false, false, // *this * 1.0
other, NumericT(-1.0), 1, false, false); // + other * (-1.0)
return result;
}
self_type operator * (scalar<NumericT> const & other) const
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
scalar<NumericT> result = 0;
viennacl::linalg::as(result, // result =
*this, other, 1, false, false); // *this * other
return result;
}
template<typename T1, typename T2, typename OP>
self_type operator * (scalar_expression<T1, T2, OP> const & proxy) const
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
self_type result = proxy;
viennacl::linalg::as(result, // result =
*this, result, 1, false, false); // *this * proxy
return result;
}
self_type operator * (NumericT other) const
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
scalar<NumericT> result = 0;
viennacl::linalg::as(result, // result =
*this, other, 1, false, false); // *this * other
return result;
}
self_type operator / (scalar<NumericT> const & other) const
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
self_type result = 0;
viennacl::linalg::as(result, // result =
*this, other, 1, true, false); // *this / other
return result;
}
template<typename T1, typename T2, typename OP>
self_type operator / (scalar_expression<T1, T2, OP> const & proxy) const
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
self_type result = proxy;
viennacl::linalg::as(result, // result =
*this, result, 1, true, false); // *this / proxy
return result;
}
self_type operator / (NumericT other) const
{
assert( val_.get_active_handle_id() != viennacl::MEMORY_NOT_INITIALIZED && bool("Scalar not initialized!"));
self_type result = 0;
viennacl::linalg::as(result, // result =
*this, other, 1, true, false); // *this / other
return result;
}
handle_type & handle() { return val_; }
const handle_type & handle() const { return val_; }
private:
void init_if_necessary(viennacl::context ctx)
{
if (val_.get_active_handle_id() == viennacl::MEMORY_NOT_INITIALIZED)
{
viennacl::backend::memory_create(val_, sizeof(NumericT), ctx);
}
}
handle_type val_;
};
//stream operators:
template<class NumericT>
std::ostream & operator<<(std::ostream & s, const scalar<NumericT> & val)
{
NumericT temp = val;
s << temp;
return s;
}
template<class NumericT>
std::istream & operator>>(std::istream & s, const scalar<NumericT> & val)
{
NumericT temp;
s >> temp;
val = temp;
return s;
}
} //namespace viennacl
#endif
viennacl::linalg::norm_frobenius_cpu
void norm_frobenius_cpu(matrix_base< T > const &vec, T &result)
Computes the Frobenius norm of a vector with final reduction on the CPU.
Definition: matrix_operations.hpp:399
viennacl::linalg::as
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
viennacl::scalar_expression< LHS, RHS, op_inner_prod >::scalar_expression
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:88
viennacl::backend::memory_write
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
viennacl::scalar
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:227
viennacl::linalg::inner_prod_cpu
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:459
viennacl::op_sum
A tag class representing the summation of a vector.
Definition: forwards.h:116
viennacl::linalg::min_cpu
void min_cpu(vector_base< T > const &vec, T &result)
Computes the minimum of a vector with final reduction on the CPU.
Definition: vector_operations.hpp:1015
viennacl::scalar_expression< LHS, RHS, op_norm_frobenius >::scalar_expression
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:316
viennacl::scalar::scalar
scalar()
Creates the scalar object, but does not yet allocate memory. Thus, scalar<> can also be a global vari...
Definition: scalar.hpp:358
viennacl::scalar::scalar
scalar(NumericT val, viennacl::context ctx=viennacl::context())
Allocates the memory for the scalar and sets it to the supplied value.
Definition: scalar.hpp:361
viennacl::scalar::operator-
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:707
viennacl::linalg::max_cpu
void max_cpu(vector_base< T > const &vec, T &result)
Computes the maximum of a vector with final reduction on the CPU.
Definition: vector_operations.hpp:928
viennacl::scalar::handle
handle_type & handle()
Returns the memory handle, non-const version.
Definition: scalar.hpp:833
viennacl::scalar_expression::scalar_expression
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:53
scalar_operations.hpp
Implementations of scalar operations.
viennacl::scalar::scalar
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:382
viennacl::linalg::sum_impl
void sum_impl(vector_base< T > const &vec, scalar< T > &result)
viennacl::scalar::operator/=
self_type & operator/=(scalar< NumericT > const &other)
Inplace division with a ViennaCL scalar.
Definition: scalar.hpp:642
viennacl::linalg::norm_2_cpu
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:705
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
viennacl::scalar_expression< LHS, RHS, op_norm_1 >::ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:119
viennacl::scalar::operator*
self_type operator*(scalar< NumericT > const &other) const
Multiplication of two ViennaCL scalars.
Definition: scalar.hpp:756
viennacl::scalar::size_type
vcl_size_t size_type
Definition: scalar.hpp:352
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::scalar_expression< LHS, RHS, op_norm_frobenius >::rhs
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:321
viennacl::backend::memory_read
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
viennacl::scalar::operator-=
self_type & operator-=(scalar< NumericT > const &other)
Inplace subtraction of a ViennaCL scalar.
Definition: scalar.hpp:599
viennacl::scalar_expression
A proxy for scalar expressions (e.g. from inner vector products)
Definition: forwards.h:230
viennacl::scalar::value_type
NumericT value_type
Returns the underlying host scalar type.
Definition: scalar.hpp:355
viennacl::op_max
A tag class representing the maximum of a vector.
Definition: forwards.h:210
viennacl::scalar_expression< LHS, RHS, op_min >::scalar_expression
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:251
NumericT
float NumericT
Definition: bisect.cpp:40
viennacl::scalar_expression< LHS, RHS, op_max >::rhs
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:223
viennacl::context
Represents a generic 'context' similar to an OpenCL context, but is backend-agnostic and thus also su...
Definition: context.hpp:39
viennacl::scalar_expression< LHS, RHS, op_max >::ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:216
viennacl::scalar_expression< LHS, RHS, op_min >::ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:249
viennacl::linalg::norm_2_impl
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:660
viennacl::scalar_expression< LHS, RHS, op_norm_2 >::rhs
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:158
viennacl::linalg::norm_frobenius_impl
void norm_frobenius_impl(matrix_base< T > const &vec, scalar< T > &result)
Computes the Frobenius norm of a matrix - dispatcher interface.
Definition: matrix_operations.hpp:369
viennacl::scalar_expression< LHS, RHS, op_norm_inf >::scalar_expression
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:186
viennacl::linalg::max_impl
void max_impl(vector_base< T > const &vec, scalar< T > &result)
viennacl::entry_proxy::index
vcl_size_t index() const
Returns the index of the represented element.
Definition: entry_proxy.hpp:138
viennacl::scalar_expression< LHS, RHS, op_sum >::scalar_expression
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:283
viennacl::scalar::scalar
scalar(const scalar &other)
Copy constructor. Allocates new memory for the scalar and copies the value of the supplied scalar...
Definition: scalar.hpp:391
viennacl::scalar_expression< LHS, RHS, op_norm_2 >::ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:151
viennacl::linalg::inner_prod_impl
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:387
viennacl::scalar::operator/
self_type operator/(scalar< NumericT > const &other) const
Division of two ViennaCL scalars.
Definition: scalar.hpp:795
viennacl::scalar::operator+=
self_type & operator+=(scalar< NumericT > const &other)
Inplace addition of a ViennaCL scalar.
Definition: scalar.hpp:577
viennacl::scalar_expression< LHS, RHS, op_inner_prod >::lhs
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:91
viennacl::scalar::operator=
self_type & operator=(entry_proxy< NumericT > const &other)
Assigns a vector entry.
Definition: scalar.hpp:414
viennacl::scalar_expression< LHS, RHS, op_norm_2 >::scalar_expression
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:153
viennacl::MEMORY_NOT_INITIALIZED
Definition: forwards.h:347
viennacl::linalg::norm_1_cpu
void norm_1_cpu(vector_base< T > const &vec, T &result)
Computes the l^1-norm of a vector with final reduction on the CPU.
Definition: vector_operations.hpp:613
viennacl::scalar_expression< LHS, RHS, op_max >::lhs
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:221
viennacl::scalar_expression< LHS, RHS, op_norm_inf >::ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:184
viennacl::scalar_expression< LHS, RHS, op_norm_frobenius >::ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:314
viennacl::scalar::handle
const handle_type & handle() const
Returns the memory handle, const version.
Definition: scalar.hpp:836
viennacl::operator>>
std::istream & operator>>(std::istream &s, const scalar< NumericT > &val)
Allows to directly read a value of a scalar from an input stream.
Definition: scalar.hpp:864
viennacl::linalg::norm_inf_impl
void norm_inf_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:752
viennacl::linalg::norm_1_impl
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:566
viennacl::scalar_expression< LHS, RHS, op_inner_prod >::rhs
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:93
viennacl::scalar::operator*=
self_type & operator*=(scalar< NumericT > const &other)
Inplace multiplication with a ViennaCL scalar.
Definition: scalar.hpp:621
viennacl::scalar_expression< LHS, RHS, op_norm_frobenius >::lhs
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:319
viennacl::scalar_expression::ScalarType
viennacl::result_of::cpu_value_type< DummyType >::type ScalarType
Definition: scalar.hpp:51
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::linalg::min_impl
void min_impl(vector_base< T > const &vec, scalar< T > &result)
viennacl::linalg::asbs
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
viennacl::scalar_expression< LHS, RHS, op_norm_2 >::lhs
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:156
viennacl::op_min
A tag class representing the minimum of a vector.
Definition: forwards.h:213
viennacl::result_of::cpu_value_type::type
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
Definition: result_of.hpp:271
backend.hpp
Implementations of the OpenCL backend, where all contexts are stored in.
viennacl::scalar_expression< LHS, RHS, op_min >::lhs
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:254
viennacl::scalar_expression< LHS, RHS, op_norm_inf >::rhs
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:191
viennacl::entry_proxy::handle
handle_type const & handle() const
Returns the memory viennacl::ocl::handle.
Definition: entry_proxy.hpp:142
viennacl::backend::mem_handle::switch_active_handle_id
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:121
viennacl::op_norm_1
A tag class representing the 1-norm of a vector.
Definition: forwards.h:201
viennacl::backend::memory_copy
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::scalar::operator+
self_type operator+(scalar< NumericT > const &other)
Addition of two ViennaCL scalars.
Definition: scalar.hpp:663
viennacl::traits::context
viennacl::context context(T const &t)
Returns an ID for the currently active memory domain of an object.
Definition: context.hpp:40
viennacl::linalg::sum_cpu
void sum_cpu(vector_base< T > const &vec, T &result)
Computes the sum of a vector with final reduction on the CPU.
Definition: vector_operations.hpp:1102
viennacl::scalar_expression< LHS, RHS, op_norm_1 >::lhs
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:124
viennacl::scalar_expression::lhs
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:56
viennacl::scalar::handle_type
viennacl::backend::mem_handle handle_type
Definition: scalar.hpp:351
viennacl::backend::mem_handle
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:89
viennacl::scalar_expression< LHS, RHS, op_norm_1 >::scalar_expression
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:121
viennacl::op_norm_frobenius
A tag class representing the Frobenius-norm of a matrix.
Definition: forwards.h:217
viennacl::backend::memory_create
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
viennacl::scalar_expression< LHS, RHS, op_inner_prod >::ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:86
viennacl::scalar_expression< LHS, RHS, op_sum >::ScalarType
viennacl::result_of::cpu_value_type< LHS >::type ScalarType
Definition: scalar.hpp:281
handle.hpp
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::traits::handle
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
viennacl::op_inner_prod
A tag class representing inner products of two vectors.
Definition: forwards.h:198
viennacl::scalar_expression< LHS, RHS, op_norm_1 >::rhs
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:126
viennacl::entry_proxy
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
Definition: forwards.h:233
viennacl::op_norm_inf
A tag class representing the inf-norm of a vector.
Definition: forwards.h:207
viennacl::scalar_expression< LHS, RHS, op_norm_inf >::lhs
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:189
viennacl::scalar_expression::rhs
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:58
viennacl::scalar_expression< LHS, RHS, op_sum >::rhs
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:288
viennacl::op_norm_2
A tag class representing the 2-norm of a vector.
Definition: forwards.h:204
viennacl::linalg::norm_inf_cpu
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:797
result_of.hpp
A collection of compile time type deductions.
viennacl::scalar_expression< LHS, RHS, op_sum >::lhs
LHS & lhs() const
Returns the left hand side operand.
Definition: scalar.hpp:286
memory.hpp
Main interface routines for memory management.
viennacl::scalar_expression< LHS, RHS, op_max >::scalar_expression
scalar_expression(LHS &lhs, RHS &rhs)
Definition: scalar.hpp:218
viennacl::scalar_expression< LHS, RHS, op_min >::rhs
RHS & rhs() const
Returns the left hand side operand.
Definition: scalar.hpp:256
viennacl::backend::mem_handle::get_active_handle_id
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