All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vector_operations.hpp
Go to the documentation of this file.
#ifndef VIENNACL_LINALG_VECTOR_OPERATIONS_HPP_
#define VIENNACL_LINALG_VECTOR_OPERATIONS_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 "viennacl/forwards.h"
#include "viennacl/range.hpp"
#include "viennacl/scalar.hpp"
#include "viennacl/tools/tools.hpp"
#include "viennacl/meta/predicate.hpp"
#include "viennacl/meta/enable_if.hpp"
#include "viennacl/traits/size.hpp"
#include "viennacl/traits/start.hpp"
#include "viennacl/traits/handle.hpp"
#include "viennacl/traits/stride.hpp"
#include "viennacl/linalg/detail/op_executor.hpp"
#include "viennacl/linalg/host_based/vector_operations.hpp"
#ifdef VIENNACL_WITH_OPENCL
#include "viennacl/linalg/opencl/vector_operations.hpp"
#endif
#ifdef VIENNACL_WITH_CUDA
#include "viennacl/linalg/cuda/vector_operations.hpp"
#endif
namespace viennacl
{
namespace linalg
{
template<typename DestNumericT, typename SrcNumericT>
void convert(vector_base<DestNumericT> & dest, vector_base<SrcNumericT> const & src)
{
assert(viennacl::traits::size(dest) == viennacl::traits::size(src) && bool("Incompatible vector sizes in v1 = v2 (convert): size(v1) != size(v2)"));
switch (viennacl::traits::handle(dest).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::convert(dest, src);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::convert(dest, src);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::convert(dest, src);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename T, typename ScalarType1>
void av(vector_base<T> & vec1,
vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
{
assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 = v2 @ alpha: size(v1) != size(v2)"));
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::av(vec1, vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename T, typename ScalarType1, typename ScalarType2>
void avbv(vector_base<T> & vec1,
vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
vector_base<T> const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
{
assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 = v2 @ alpha + v3 @ beta: size(v1) != size(v2)"));
assert(viennacl::traits::size(vec2) == viennacl::traits::size(vec3) && bool("Incompatible vector sizes in v1 = v2 @ alpha + v3 @ beta: size(v2) != size(v3)"));
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::avbv(vec1,
vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::avbv(vec1,
vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::avbv(vec1,
vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename T, typename ScalarType1, typename ScalarType2>
void avbv_v(vector_base<T> & vec1,
vector_base<T> const & vec2, ScalarType1 const & alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha,
vector_base<T> const & vec3, ScalarType2 const & beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
{
assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in v1 += v2 @ alpha + v3 @ beta: size(v1) != size(v2)"));
assert(viennacl::traits::size(vec2) == viennacl::traits::size(vec3) && bool("Incompatible vector sizes in v1 += v2 @ alpha + v3 @ beta: size(v2) != size(v3)"));
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::avbv_v(vec1,
vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::avbv_v(vec1,
vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::avbv_v(vec1,
vec2, alpha, len_alpha, reciprocal_alpha, flip_sign_alpha,
vec3, beta, len_beta, reciprocal_beta, flip_sign_beta);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename T>
void vector_assign(vector_base<T> & vec1, const T & alpha, bool up_to_internal_size = false)
{
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::vector_assign(vec1, alpha, up_to_internal_size);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::vector_assign(vec1, alpha, up_to_internal_size);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::vector_assign(vec1, alpha, up_to_internal_size);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename T>
void vector_swap(vector_base<T> & vec1, vector_base<T> & vec2)
{
assert(viennacl::traits::size(vec1) == viennacl::traits::size(vec2) && bool("Incompatible vector sizes in vector_swap()"));
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::vector_swap(vec1, vec2);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::vector_swap(vec1, vec2);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::vector_swap(vec1, vec2);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename T, typename OP>
void element_op(vector_base<T> & vec1,
vector_expression<const vector_base<T>, const vector_base<T>, OP> const & proxy)
{
assert(viennacl::traits::size(vec1) == viennacl::traits::size(proxy) && bool("Incompatible vector sizes in element_op()"));
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::element_op(vec1, proxy);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::element_op(vec1, proxy);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::element_op(vec1, proxy);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
// Helper macro for generating binary element-wise operations such as element_prod(), element_div(), element_pow() without unnecessary code duplication */
#define VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(OPNAME) \
template<typename T> \
viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_binary<op_##OPNAME> > \
element_##OPNAME(vector_base<T> const & v1, vector_base<T> const & v2) \
{ \
return viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_binary<op_##OPNAME> >(v1, v2); \
} \
\
template<typename V1, typename V2, typename OP, typename T> \
viennacl::vector_expression<const vector_expression<const V1, const V2, OP>, const vector_base<T>, op_element_binary<op_##OPNAME> > \
element_##OPNAME(vector_expression<const V1, const V2, OP> const & proxy, vector_base<T> const & v2) \
{ \
return viennacl::vector_expression<const vector_expression<const V1, const V2, OP>, const vector_base<T>, op_element_binary<op_##OPNAME> >(proxy, v2); \
} \
\
template<typename T, typename V2, typename V3, typename OP> \
viennacl::vector_expression<const vector_base<T>, const vector_expression<const V2, const V3, OP>, op_element_binary<op_##OPNAME> > \
element_##OPNAME(vector_base<T> const & v1, vector_expression<const V2, const V3, OP> const & proxy) \
{ \
return viennacl::vector_expression<const vector_base<T>, const vector_expression<const V2, const V3, OP>, op_element_binary<op_##OPNAME> >(v1, proxy); \
} \
\
template<typename V1, typename V2, typename OP1, \
typename V3, typename V4, typename OP2> \
viennacl::vector_expression<const vector_expression<const V1, const V2, OP1>, \
const vector_expression<const V3, const V4, OP2>, \
op_element_binary<op_##OPNAME> > \
element_##OPNAME(vector_expression<const V1, const V2, OP1> const & proxy1, \
vector_expression<const V3, const V4, OP2> const & proxy2) \
{\
return viennacl::vector_expression<const vector_expression<const V1, const V2, OP1>, \
const vector_expression<const V3, const V4, OP2>, \
op_element_binary<op_##OPNAME> >(proxy1, proxy2); \
}
VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(prod) //for element_prod()
VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(div) //for element_div()
VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(pow) //for element_pow()
VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(eq)
VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(neq)
VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(greater)
VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(less)
VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(geq)
VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS(leq)
#undef VIENNACL_GENERATE_BINARY_ELEMENTOPERATION_OVERLOADS
// Helper macro for generating unary element-wise operations such as element_exp(), element_sin(), etc. without unnecessary code duplication */
#define VIENNACL_MAKE_UNARY_ELEMENT_OP(funcname) \
template<typename T> \
viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_unary<op_##funcname> > \
element_##funcname(vector_base<T> const & v) \
{ \
return viennacl::vector_expression<const vector_base<T>, const vector_base<T>, op_element_unary<op_##funcname> >(v, v); \
} \
template<typename LHS, typename RHS, typename OP> \
viennacl::vector_expression<const vector_expression<const LHS, const RHS, OP>, \
const vector_expression<const LHS, const RHS, OP>, \
op_element_unary<op_##funcname> > \
element_##funcname(vector_expression<const LHS, const RHS, OP> const & proxy) \
{ \
return viennacl::vector_expression<const vector_expression<const LHS, const RHS, OP>, \
const vector_expression<const LHS, const RHS, OP>, \
op_element_unary<op_##funcname> >(proxy, proxy); \
} \
VIENNACL_MAKE_UNARY_ELEMENT_OP(abs)
VIENNACL_MAKE_UNARY_ELEMENT_OP(acos)
VIENNACL_MAKE_UNARY_ELEMENT_OP(asin)
VIENNACL_MAKE_UNARY_ELEMENT_OP(atan)
VIENNACL_MAKE_UNARY_ELEMENT_OP(ceil)
VIENNACL_MAKE_UNARY_ELEMENT_OP(cos)
VIENNACL_MAKE_UNARY_ELEMENT_OP(cosh)
VIENNACL_MAKE_UNARY_ELEMENT_OP(exp)
VIENNACL_MAKE_UNARY_ELEMENT_OP(fabs)
VIENNACL_MAKE_UNARY_ELEMENT_OP(floor)
VIENNACL_MAKE_UNARY_ELEMENT_OP(log)
VIENNACL_MAKE_UNARY_ELEMENT_OP(log10)
VIENNACL_MAKE_UNARY_ELEMENT_OP(sin)
VIENNACL_MAKE_UNARY_ELEMENT_OP(sinh)
VIENNACL_MAKE_UNARY_ELEMENT_OP(sqrt)
VIENNACL_MAKE_UNARY_ELEMENT_OP(tan)
VIENNACL_MAKE_UNARY_ELEMENT_OP(tanh)
#undef VIENNACL_MAKE_UNARY_ELEMENT_OP
//implementation of inner product:
//namespace {
template<typename T>
void inner_prod_impl(vector_base<T> const & vec1,
vector_base<T> const & vec2,
scalar<T> & result)
{
assert( vec1.size() == vec2.size() && bool("Size mismatch") );
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::inner_prod_impl(vec1, vec2, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::inner_prod_impl(vec1, vec2, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::inner_prod_impl(vec1, vec2, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
// vector expression on lhs
template<typename LHS, typename RHS, typename OP, typename T>
void inner_prod_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec1,
vector_base<T> const & vec2,
scalar<T> & result)
{
viennacl::vector<T> temp = vec1;
inner_prod_impl(temp, vec2, result);
}
// vector expression on rhs
template<typename T, typename LHS, typename RHS, typename OP>
void inner_prod_impl(vector_base<T> const & vec1,
viennacl::vector_expression<LHS, RHS, OP> const & vec2,
scalar<T> & result)
{
viennacl::vector<T> temp = vec2;
inner_prod_impl(vec1, temp, result);
}
// vector expression on lhs and rhs
template<typename LHS1, typename RHS1, typename OP1,
typename LHS2, typename RHS2, typename OP2, typename T>
void inner_prod_impl(viennacl::vector_expression<LHS1, RHS1, OP1> const & vec1,
viennacl::vector_expression<LHS2, RHS2, OP2> const & vec2,
scalar<T> & result)
{
viennacl::vector<T> temp1 = vec1;
viennacl::vector<T> temp2 = vec2;
inner_prod_impl(temp1, temp2, result);
}
template<typename T>
void inner_prod_cpu(vector_base<T> const & vec1,
vector_base<T> const & vec2,
T & result)
{
assert( vec1.size() == vec2.size() && bool("Size mismatch") );
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::inner_prod_impl(vec1, vec2, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::inner_prod_cpu(vec1, vec2, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::inner_prod_cpu(vec1, vec2, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
// vector expression on lhs
template<typename LHS, typename RHS, typename OP, typename T>
void inner_prod_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec1,
vector_base<T> const & vec2,
T & result)
{
viennacl::vector<T> temp = vec1;
inner_prod_cpu(temp, vec2, result);
}
// vector expression on rhs
template<typename T, typename LHS, typename RHS, typename OP>
void inner_prod_cpu(vector_base<T> const & vec1,
viennacl::vector_expression<LHS, RHS, OP> const & vec2,
T & result)
{
viennacl::vector<T> temp = vec2;
inner_prod_cpu(vec1, temp, result);
}
// vector expression on lhs and rhs
template<typename LHS1, typename RHS1, typename OP1,
typename LHS2, typename RHS2, typename OP2, typename S3>
void inner_prod_cpu(viennacl::vector_expression<LHS1, RHS1, OP1> const & vec1,
viennacl::vector_expression<LHS2, RHS2, OP2> const & vec2,
S3 & result)
{
viennacl::vector<S3> temp1 = vec1;
viennacl::vector<S3> temp2 = vec2;
inner_prod_cpu(temp1, temp2, result);
}
template<typename T>
void inner_prod_impl(vector_base<T> const & x,
vector_tuple<T> const & y_tuple,
vector_base<T> & result)
{
assert( x.size() == y_tuple.const_at(0).size() && bool("Size mismatch") );
assert( result.size() == y_tuple.const_size() && bool("Number of elements does not match result size") );
switch (viennacl::traits::handle(x).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::inner_prod_impl(x, y_tuple, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::inner_prod_impl(x, y_tuple, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::inner_prod_impl(x, y_tuple, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename T>
void norm_1_impl(vector_base<T> const & vec,
scalar<T> & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::norm_1_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::norm_1_impl(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::norm_1_impl(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename S2>
void norm_1_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec,
S2 & result)
{
viennacl::vector<typename viennacl::result_of::cpu_value_type<S2>::type> temp = vec;
norm_1_impl(temp, result);
}
template<typename T>
void norm_1_cpu(vector_base<T> const & vec,
T & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::norm_1_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::norm_1_cpu(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::norm_1_cpu(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename S2>
void norm_1_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec,
S2 & result)
{
viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
norm_1_cpu(temp, result);
}
template<typename T>
void norm_2_impl(vector_base<T> const & vec,
scalar<T> & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::norm_2_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::norm_2_impl(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::norm_2_impl(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename T>
void norm_2_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec,
scalar<T> & result)
{
viennacl::vector<T> temp = vec;
norm_2_impl(temp, result);
}
template<typename T>
void norm_2_cpu(vector_base<T> const & vec,
T & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::norm_2_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::norm_2_cpu(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::norm_2_cpu(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename S2>
void norm_2_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec,
S2 & result)
{
viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
norm_2_cpu(temp, result);
}
template<typename T>
void norm_inf_impl(vector_base<T> const & vec,
scalar<T> & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::norm_inf_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::norm_inf_impl(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::norm_inf_impl(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename T>
void norm_inf_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec,
scalar<T> & result)
{
viennacl::vector<T> temp = vec;
norm_inf_impl(temp, result);
}
template<typename T>
void norm_inf_cpu(vector_base<T> const & vec,
T & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::norm_inf_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::norm_inf_cpu(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::norm_inf_cpu(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename S2>
void norm_inf_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec,
S2 & result)
{
viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
norm_inf_cpu(temp, result);
}
//This function should return a CPU scalar, otherwise statements like
// vcl_rhs[index_norm_inf(vcl_rhs)]
// are ambiguous
template<typename T>
vcl_size_t index_norm_inf(vector_base<T> const & vec)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
return viennacl::linalg::host_based::index_norm_inf(vec);
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
return viennacl::linalg::opencl::index_norm_inf(vec);
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
return viennacl::linalg::cuda::index_norm_inf(vec);
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP>
vcl_size_t index_norm_inf(viennacl::vector_expression<LHS, RHS, OP> const & vec)
{
viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
return index_norm_inf(temp);
}
template<typename NumericT>
void max_impl(vector_base<NumericT> const & vec, viennacl::scalar<NumericT> & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::max_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::max_impl(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::max_impl(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename NumericT>
void max_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec, viennacl::scalar<NumericT> & result)
{
viennacl::vector<NumericT> temp = vec;
max_impl(temp, result);
}
template<typename T>
void max_cpu(vector_base<T> const & vec, T & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::max_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::max_cpu(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::max_cpu(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename S2>
void max_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec, S2 & result)
{
viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
max_cpu(temp, result);
}
template<typename NumericT>
void min_impl(vector_base<NumericT> const & vec, viennacl::scalar<NumericT> & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::min_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::min_impl(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::min_impl(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename NumericT>
void min_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec, viennacl::scalar<NumericT> & result)
{
viennacl::vector<NumericT> temp = vec;
min_impl(temp, result);
}
template<typename T>
void min_cpu(vector_base<T> const & vec, T & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::min_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::min_cpu(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::min_cpu(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename S2>
void min_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec, S2 & result)
{
viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
min_cpu(temp, result);
}
template<typename NumericT>
void sum_impl(vector_base<NumericT> const & vec, viennacl::scalar<NumericT> & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::sum_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::sum_impl(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::sum_impl(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename NumericT>
void sum_impl(viennacl::vector_expression<LHS, RHS, OP> const & vec, viennacl::scalar<NumericT> & result)
{
viennacl::vector<NumericT> temp = vec;
sum_impl(temp, result);
}
template<typename T>
void sum_cpu(vector_base<T> const & vec, T & result)
{
switch (viennacl::traits::handle(vec).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::sum_impl(vec, result);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::sum_cpu(vec, result);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::sum_cpu(vec, result);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename LHS, typename RHS, typename OP, typename S2>
void sum_cpu(viennacl::vector_expression<LHS, RHS, OP> const & vec, S2 & result)
{
viennacl::vector<typename viennacl::result_of::cpu_value_type<LHS>::type> temp = vec;
sum_cpu(temp, result);
}
template<typename T>
void plane_rotation(vector_base<T> & vec1,
vector_base<T> & vec2,
T alpha, T beta)
{
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::plane_rotation(vec1, vec2, alpha, beta);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::plane_rotation(vec1, vec2, alpha, beta);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::plane_rotation(vec1, vec2, alpha, beta);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename NumericT>
void inclusive_scan(vector_base<NumericT> & vec1,
vector_base<NumericT> & vec2)
{
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::inclusive_scan(vec1, vec2);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::inclusive_scan(vec1, vec2);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::inclusive_scan(vec1, vec2);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename NumericT>
void inclusive_scan(vector_base<NumericT> & vec)
{
inclusive_scan(vec, vec);
}
template<typename NumericT>
void exclusive_scan(vector_base<NumericT> & vec1,
vector_base<NumericT> & vec2)
{
switch (viennacl::traits::handle(vec1).get_active_handle_id())
{
case viennacl::MAIN_MEMORY:
viennacl::linalg::host_based::exclusive_scan(vec1, vec2);
break;
#ifdef VIENNACL_WITH_OPENCL
case viennacl::OPENCL_MEMORY:
viennacl::linalg::opencl::exclusive_scan(vec1, vec2);
break;
#endif
#ifdef VIENNACL_WITH_CUDA
case viennacl::CUDA_MEMORY:
viennacl::linalg::cuda::exclusive_scan(vec1, vec2);
break;
#endif
case viennacl::MEMORY_NOT_INITIALIZED:
throw memory_exception("not initialised!");
default:
throw memory_exception("not implemented");
}
}
template<typename NumericT>
void exclusive_scan(vector_base<NumericT> & vec)
{
exclusive_scan(vec, vec);
}
} //namespace linalg
template<typename T, typename LHS, typename RHS, typename OP>
vector_base<T> & operator += (vector_base<T> & v1, const vector_expression<const LHS, const RHS, OP> & proxy)
{
assert( (viennacl::traits::size(proxy) == v1.size()) && bool("Incompatible vector sizes!"));
assert( (v1.size() > 0) && bool("Vector not yet initialized!") );
linalg::detail::op_executor<vector_base<T>, op_inplace_add, vector_expression<const LHS, const RHS, OP> >::apply(v1, proxy);
return v1;
}
template<typename T, typename LHS, typename RHS, typename OP>
vector_base<T> & operator -= (vector_base<T> & v1, const vector_expression<const LHS, const RHS, OP> & proxy)
{
assert( (viennacl::traits::size(proxy) == v1.size()) && bool("Incompatible vector sizes!"));
assert( (v1.size() > 0) && bool("Vector not yet initialized!") );
linalg::detail::op_executor<vector_base<T>, op_inplace_sub, vector_expression<const LHS, const RHS, OP> >::apply(v1, proxy);
return v1;
}
} //namespace viennacl
#endif
viennacl::linalg::opencl::min_cpu
void min_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the minimum of a vector, where the result is stored on a CPU scalar.
Definition: vector_operations.hpp:1083
viennacl::vector_tuple::const_size
vcl_size_t const_size() const
Definition: vector.hpp:1143
viennacl::linalg::index_norm_inf
vcl_size_t index_norm_inf(vector_base< T > const &vec)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:845
viennacl::linalg::cuda::vector_assign
void vector_assign(vector_base< NumericT > &vec1, ScalarT1 const &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
Definition: vector_operations.hpp:803
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::opencl::avbv
void avbv(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:116
viennacl::linalg::cuda::norm_2_cpu
void norm_2_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the l^2-norm of a vector - implementation.
Definition: vector_operations.hpp:2651
viennacl::linalg::cuda::convert
void convert(matrix_base< DestNumericT > &mat1, matrix_base< SrcNumericT > const &mat2)
Definition: matrix_operations.hpp:57
viennacl::linalg::opencl::norm_2_impl
void norm_2_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^2-norm of a vector - implementation using OpenCL summation at second step...
Definition: vector_operations.hpp:801
viennacl::linalg::host_based::inclusive_scan
void inclusive_scan(vector_base< NumericT > const &vec1, vector_base< NumericT > &vec2)
This function implements an inclusive scan on the host using OpenMP.
Definition: vector_operations.hpp:1161
viennacl::linalg::detail::op_executor
Worker class for decomposing expression templates.
Definition: op_executor.hpp:80
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::linalg::host_based::norm_1_impl
void norm_1_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:648
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::operator-=
vector< NumericT > operator-=(vector_base< NumericT > &v1, const viennacl::vector_expression< const matrix_base< NumericT >, const vector_base< NumericT >, viennacl::op_prod > &proxy)
Implementation of the operation v1 -= A * v2, where A is a matrix.
Definition: matrix_operations.hpp:1159
vector_operations.hpp
Implementations of NMF operations using OpenCL.
viennacl::memory_exception
Exception class in case of memory errors.
Definition: forwards.h:572
viennacl::linalg::opencl::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 CPU.
Definition: vector_operations.hpp:770
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
size.hpp
Generic size and resize functionality for different vector and matrix types.
op_executor.hpp
Defines the worker class for decomposing an expression tree into small chunks, which can be processed...
viennacl::linalg::host_based::norm_inf_impl
void norm_inf_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:781
viennacl::linalg::opencl::plane_rotation
void plane_rotation(vector_base< T > &vec1, vector_base< T > &vec2, T alpha, T beta)
Computes a plane rotation of two vectors.
Definition: vector_operations.hpp:1156
viennacl::linalg::host_based::av
void av(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:88
viennacl::linalg::host_based::sum_impl
void sum_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the sum of all elements from the vector.
Definition: vector_operations.hpp:989
start.hpp
Extracts the underlying OpenCL start index handle from a vector, a matrix, an expression etc...
tools.hpp
Various little tools used here and there in ViennaCL.
viennacl::operator+=
vector< NumericT > operator+=(vector_base< NumericT > &v1, const viennacl::vector_expression< const matrix_base< NumericT >, const vector_base< NumericT >, viennacl::op_prod > &proxy)
Implementation of the operation v1 += A * v2, where A is a matrix.
Definition: matrix_operations.hpp:1141
viennacl::linalg::sum_impl
void sum_impl(vector_base< T > const &vec, scalar< T > &result)
viennacl::linalg::plane_rotation
void plane_rotation(vector_base< T > &vec1, vector_base< T > &vec2, T alpha, T beta)
Computes a plane rotation of two vectors.
Definition: vector_operations.hpp:1152
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::linalg::cuda::av
void av(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:144
viennacl::linalg::avbv_v
void avbv_v(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:144
viennacl::linalg::opencl::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:865
viennacl::OPENCL_MEMORY
Definition: forwards.h:349
viennacl::linalg::cuda::max_impl
void max_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the maximum of a vector, both reduction stages run on the GPU.
Definition: vector_operations.hpp:2765
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
stride.hpp
Determines row and column increments for matrices and matrix proxies.
viennacl::linalg::cuda::exclusive_scan
void exclusive_scan(vector_base< NumericT > const &input, vector_base< NumericT > &output)
This function implements an exclusive scan using CUDA.
Definition: vector_operations.hpp:3239
viennacl::linalg::opencl::min_impl
void min_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the minimum of a vector, where the result is stored in an OpenCL buffer. ...
Definition: vector_operations.hpp:1045
viennacl::linalg::cuda::norm_1_cpu
void norm_1_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:2605
viennacl::vector_expression
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:239
viennacl::linalg::element_op
void element_op(matrix_base< T > &A, matrix_expression< const matrix_base< T >, const matrix_base< T >, OP > const &proxy)
Implementation of the element-wise operation A = B .* C and A = B ./ C for matrices (using MATLAB syn...
Definition: matrix_operations.hpp:702
viennacl::linalg::opencl::avbv_v
void avbv_v(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:178
viennacl::linalg::host_based::vector_assign
void vector_assign(vector_base< NumericT > &vec1, const NumericT &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
Definition: vector_operations.hpp:275
viennacl::op_inplace_add
A tag class representing inplace addition.
Definition: forwards.h:83
viennacl::linalg::cuda::max_cpu
void max_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the maximum of a vector, first reduction stage on the GPU, second stage on the CPU...
Definition: vector_operations.hpp:2793
viennacl::linalg::cuda::vector_swap
void vector_swap(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:853
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::linalg::host_based::convert
void convert(matrix_base< DestNumericT > &mat1, matrix_base< SrcNumericT > const &mat2)
Definition: matrix_operations.hpp:58
v1
viennacl::vector< float > v1
Definition: global_variables.cpp:60
viennacl::linalg::prod
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
Definition: prod.hpp:102
viennacl::linalg::max_impl
void max_impl(vector_base< T > const &vec, scalar< T > &result)
viennacl::linalg::opencl::inner_prod_impl
void inner_prod_impl(vector_base< T > const &vec1, vector_base< T > const &vec2, vector_base< T > &partial_result)
Computes the partial inner product of two vectors - implementation. Library users should call inner_p...
Definition: vector_operations.hpp:388
viennacl::traits::size
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:239
viennacl::linalg::opencl::sum_impl
void sum_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the sum over all entries of a vector.
Definition: vector_operations.hpp:1122
viennacl::linalg::cuda::inclusive_scan
void inclusive_scan(vector_base< NumericT > const &input, vector_base< NumericT > &output)
This function implements an inclusive scan using CUDA.
Definition: vector_operations.hpp:3226
viennacl::linalg::host_based::norm_2_impl
void norm_2_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the l^2-norm of a vector - implementation.
Definition: vector_operations.hpp:761
viennacl::linalg::opencl::max_impl
void max_impl(vector_base< NumericT > const &x, scalar< NumericT > &result)
Computes the maximum value of a vector, where the result is stored in an OpenCL buffer.
Definition: vector_operations.hpp:966
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::linalg::opencl::max_cpu
void max_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the maximum value of a vector, where the value is stored in a host value.
Definition: vector_operations.hpp:1004
viennacl::linalg::convert
void convert(matrix_base< DestNumericT > &dest, matrix_base< SrcNumericT > const &src)
Definition: matrix_operations.hpp:54
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::CUDA_MEMORY
Definition: forwards.h:350
viennacl::linalg::host_based::index_norm_inf
vcl_size_t index_norm_inf(vector_base< NumericT > const &vec1)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:831
viennacl::linalg::opencl::norm_2_cpu
void norm_2_cpu(vector_base< T > const &vec, T &result)
Computes the l^1-norm of a vector with final reduction on CPU.
Definition: vector_operations.hpp:834
viennacl::vector_tuple
Tuple class holding pointers to multiple vectors. Mainly used as a temporary object returned from vie...
Definition: forwards.h:269
viennacl::linalg::host_based::min_impl
void min_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the minimum of a vector.
Definition: vector_operations.hpp:940
viennacl::linalg::host_based::vector_swap
void vector_swap(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:302
VIENNACL_MAKE_UNARY_ELEMENT_OP
#define VIENNACL_MAKE_UNARY_ELEMENT_OP(funcname)
Definition: matrix_operations.hpp:789
viennacl::linalg::cuda::norm_inf_impl
void norm_inf_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:2679
viennacl::linalg::host_based::element_op
void element_op(matrix_base< NumericT > &A, matrix_expression< const matrix_base< NumericT >, const matrix_base< NumericT >, op_element_binary< OpT > > const &proxy)
Implementation of the element-wise operations A = B .* C and A = B ./ C (using MATLAB syntax) ...
Definition: matrix_operations.hpp:848
viennacl::linalg::cuda::inner_prod_cpu
void inner_prod_cpu(vector_base< NumericT > const &vec1, vector_base< NumericT > const &vec2, NumericT &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(vec1...
Definition: vector_operations.hpp:1771
viennacl::linalg::opencl::av
void av(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:76
viennacl::linalg::vector_swap
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:218
viennacl::linalg::host_based::avbv
void avbv(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &vec3, ScalarT2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:127
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::linalg::opencl::norm_1_impl
void norm_1_impl(vector_base< T > const &vec, scalar< T > &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:737
viennacl::linalg::cuda::sum_cpu
void sum_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the maximum of a vector, first reduction stage on the GPU, second stage on the CPU...
Definition: vector_operations.hpp:2891
viennacl::vector_base
Common base class for dense vectors, vector ranges, and vector slices.
Definition: vector_def.hpp:104
viennacl::linalg::cuda::sum_impl
void sum_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the maximum of a vector, both reduction stages run on the GPU.
Definition: vector_operations.hpp:2874
viennacl::linalg::cuda::avbv_v
void avbv_v(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &vec3, ScalarT2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:735
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::vector
Definition: forwards.h:266
viennacl::linalg::opencl::inclusive_scan
void inclusive_scan(vector_base< NumericT > const &input, vector_base< NumericT > &output)
This function implements an inclusive scan using CUDA.
Definition: vector_operations.hpp:1238
viennacl::linalg::host_based::exclusive_scan
void exclusive_scan(vector_base< NumericT > const &vec1, vector_base< NumericT > &vec2)
This function implements an exclusive scan on the host using OpenMP.
Definition: vector_operations.hpp:1176
viennacl::linalg::cuda::min_cpu
void min_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the maximum of a vector, first reduction stage on the GPU, second stage on the CPU...
Definition: vector_operations.hpp:2847
viennacl::linalg::opencl::element_op
void element_op(matrix_base< T > &A, matrix_expression< const matrix_base< T >, const matrix_base< T >, op_element_binary< OP > > const &proxy)
Implementation of binary element-wise operations A = OP(B,C)
Definition: matrix_operations.hpp:540
viennacl::linalg::cuda::norm_1_impl
void norm_1_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the l^1-norm of a vector.
Definition: vector_operations.hpp:2587
viennacl::linalg::avbv
void avbv(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< T > const &vec3, ScalarType2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:107
viennacl::linalg::inclusive_scan
void inclusive_scan(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2)
This function implements an inclusive scan.
Definition: vector_operations.hpp:1190
viennacl::linalg::cuda::index_norm_inf
vcl_size_t index_norm_inf(vector_base< NumericT > const &vec1)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:2972
predicate.hpp
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
viennacl::linalg::cuda::plane_rotation
void plane_rotation(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2, NumericT alpha, NumericT beta)
Computes a plane rotation of two vectors.
Definition: vector_operations.hpp:3032
viennacl::linalg::host_based::inner_prod_impl
void inner_prod_impl(vector_base< NumericT > const &vec1, vector_base< NumericT > const &vec2, ScalarT &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(vec1...
Definition: vector_operations.hpp:497
viennacl::linalg::opencl::convert
void convert(matrix_base< DestNumericT > &dest, matrix_base< SrcNumericT > const &src)
Definition: matrix_operations.hpp:134
viennacl::MAIN_MEMORY
Definition: forwards.h:348
viennacl::linalg::cuda::min_impl
void min_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the maximum of a vector, both reduction stages run on the GPU.
Definition: vector_operations.hpp:2819
viennacl::op_inplace_sub
A tag class representing inplace subtraction.
Definition: forwards.h:85
viennacl::linalg::host_based::max_impl
void max_impl(vector_base< NumericT > const &vec1, ScalarT &result)
Computes the maximum of a vector.
Definition: vector_operations.hpp:891
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::linalg::cuda::element_op
void element_op(matrix_base< NumericT, SizeT > &A, matrix_expression< const matrix_base< NumericT, SizeT >, const matrix_base< NumericT, SizeT >, op_element_binary< OpT > > const &proxy)
Definition: matrix_operations.hpp:548
viennacl::linalg::cuda::inner_prod_impl
void inner_prod_impl(vector_base< NumericT > const &vec1, vector_base< NumericT > const &vec2, ScalarT &result)
Computes the inner product of two vectors - implementation. Library users should call inner_prod(vec1...
Definition: vector_operations.hpp:1739
viennacl::linalg::opencl::exclusive_scan
void exclusive_scan(vector_base< NumericT > const &input, vector_base< NumericT > &output)
This function implements an exclusive scan using CUDA.
Definition: vector_operations.hpp:1251
viennacl::linalg::cuda::norm_inf_cpu
void norm_inf_cpu(vector_base< NumericT > const &vec1, NumericT &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:2699
viennacl::linalg::opencl::index_norm_inf
cl_uint index_norm_inf(vector_base< T > const &vec)
Computes the index of the first entry that is equal to the supremum-norm in modulus.
Definition: vector_operations.hpp:930
viennacl::vector_base::size
size_type size() const
Returns the length of the vector (cf. std::vector)
Definition: vector_def.hpp:118
viennacl::linalg::av
void av(vector_base< T > &vec1, vector_base< T > const &vec2, ScalarType1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha)
Definition: vector_operations.hpp:78
viennacl::linalg::opencl::norm_inf_cpu
void norm_inf_cpu(vector_base< T > const &vec, T &result)
Computes the supremum-norm of a vector.
Definition: vector_operations.hpp:898
viennacl::vector_tuple::const_at
VectorType const & const_at(vcl_size_t i) const
Definition: vector.hpp:1146
range.hpp
Implementation of a range object for use with proxy objects.
viennacl::linalg::exclusive_scan
void exclusive_scan(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2)
This function implements an exclusive scan.
Definition: vector_operations.hpp:1240
viennacl::linalg::vector_assign
void vector_assign(vector_base< T > &vec1, const T &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
Definition: vector_operations.hpp:187
handle.hpp
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::linalg::opencl::vector_assign
void vector_assign(vector_base< T > &vec1, const T &alpha, bool up_to_internal_size=false)
Assign a constant value to a vector (-range/-slice)
Definition: vector_operations.hpp:246
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::linalg::opencl::vector_swap
void vector_swap(vector_base< T > &vec1, vector_base< T > &vec2)
Swaps the contents of two vectors, data is copied.
Definition: vector_operations.hpp:272
viennacl::linalg::host_based::plane_rotation
void plane_rotation(vector_base< NumericT > &vec1, vector_base< NumericT > &vec2, NumericT alpha, NumericT beta)
Computes a plane rotation of two vectors.
Definition: vector_operations.hpp:1020
viennacl::linalg::opencl::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 - implementation. Library users should call inner_prod(vec1...
Definition: vector_operations.hpp:669
scalar.hpp
Implementation of the ViennaCL scalar class.
vector_operations.hpp
Implementations of NMF operations using CUDA.
viennacl::linalg::cuda::norm_2_impl
void norm_2_impl(vector_base< NumericT > const &vec1, scalar< NumericT > &result)
Computes the l^2-norm of a vector - implementation.
Definition: vector_operations.hpp:2632
viennacl::linalg::host_based::avbv_v
void avbv_v(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &vec3, ScalarT2 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:197
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
viennacl::linalg::cuda::avbv
void avbv(vector_base< NumericT > &vec1, vector_base< NumericT > const &vec2, ScalarT1 const &alpha, vcl_size_t len_alpha, bool reciprocal_alpha, bool flip_sign_alpha, vector_base< NumericT > const &vec3, ScalarT2 const &beta, vcl_size_t len_beta, bool reciprocal_beta, bool flip_sign_beta)
Definition: vector_operations.hpp:433
viennacl::linalg::opencl::sum_cpu
void sum_cpu(vector_base< NumericT > const &x, NumericT &result)
Computes the sum over all entries of a vector.
Definition: vector_operations.hpp:1137
enable_if.hpp
Simple enable-if variant that uses the SFINAE pattern.
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
vector_operations.hpp
Implementations of NMF operations using a plain single-threaded or OpenMP-enabled execution on CPU...