1 #ifndef VIENNACL_LINALG_HOST_BASED_SCALAR_OPERATIONS_HPP_
2 #define VIENNACL_LINALG_HOST_BASED_SCALAR_OPERATIONS_HPP_
40 template<
typename ScalarT1,
41 typename ScalarT2,
typename FactorT>
47 ScalarT2
const &
s2, FactorT
const & alpha,
vcl_size_t ,
bool reciprocal_alpha,
bool flip_sign_alpha)
51 value_type * data_s1 = detail::extract_raw_pointer<value_type>(
s1);
52 value_type
const * data_s2 = detail::extract_raw_pointer<value_type>(
s2);
54 value_type data_alpha = alpha;
56 data_alpha = -data_alpha;
58 data_alpha =
static_cast<value_type
>(1) / data_alpha;
60 *data_s1 = *data_s2 * data_alpha;
64 template<
typename ScalarT1,
65 typename ScalarT2,
typename FactorT2,
66 typename ScalarT3,
typename FactorT3>
74 ScalarT2
const &
s2, FactorT2
const & alpha,
vcl_size_t ,
bool reciprocal_alpha,
bool flip_sign_alpha,
75 ScalarT3
const & s3, FactorT3
const & beta,
vcl_size_t ,
bool reciprocal_beta,
bool flip_sign_beta)
79 value_type * data_s1 = detail::extract_raw_pointer<value_type>(
s1);
80 value_type
const * data_s2 = detail::extract_raw_pointer<value_type>(
s2);
81 value_type
const * data_s3 = detail::extract_raw_pointer<value_type>(s3);
83 value_type data_alpha = alpha;
85 data_alpha = -data_alpha;
87 data_alpha =
static_cast<value_type
>(1) / data_alpha;
89 value_type data_beta = beta;
91 data_beta = -data_beta;
93 data_beta =
static_cast<value_type
>(1) / data_beta;
95 *data_s1 = *data_s2 * data_alpha + *data_s3 * data_beta;
99 template<
typename ScalarT1,
100 typename ScalarT2,
typename FactorT2,
101 typename ScalarT3,
typename FactorT3>
109 ScalarT2
const &
s2, FactorT2
const & alpha,
vcl_size_t ,
bool reciprocal_alpha,
bool flip_sign_alpha,
110 ScalarT3
const & s3, FactorT3
const & beta,
vcl_size_t ,
bool reciprocal_beta,
bool flip_sign_beta)
114 value_type * data_s1 = detail::extract_raw_pointer<value_type>(
s1);
115 value_type
const * data_s2 = detail::extract_raw_pointer<value_type>(
s2);
116 value_type
const * data_s3 = detail::extract_raw_pointer<value_type>(s3);
118 value_type data_alpha = alpha;
120 data_alpha = -data_alpha;
121 if (reciprocal_alpha)
122 data_alpha =
static_cast<value_type
>(1) / data_alpha;
124 value_type data_beta = beta;
126 data_beta = -data_beta;
128 data_beta =
static_cast<value_type
>(1) / data_beta;
130 *data_s1 += *data_s2 * data_alpha + *data_s3 * data_beta;
139 template<
typename ScalarT1,
typename ScalarT2>
147 value_type * data_s1 = detail::extract_raw_pointer<value_type>(
s1);
148 value_type * data_s2 = detail::extract_raw_pointer<value_type>(
s2);
150 value_type temp = *data_s2;
Simple enable-if variant that uses the SFINAE pattern.
Generic size and resize functionality for different vector and matrix types.
Extracts the underlying OpenCL start index handle from a vector, a matrix, an expression etc...
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value >::type swap(ScalarT1 &s1, ScalarT2 &s2)
Swaps the contents of two scalars, data is copied.
This file provides the forward declarations for the main types used within ViennaCL.
Determines row and column increments for matrices and matrix proxies.
viennacl::scalar< int > s2
viennacl::scalar< float > s1
Helper struct for checking whether the provided type represents a scalar (either host, from ViennaCL, or a flip-sign proxy)
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_scalar< ScalarT3 >::value &&viennacl::is_any_scalar< FactorT2 >::value &&viennacl::is_any_scalar< FactorT3 >::value >::type asbs(ScalarT1 &s1, ScalarT2 const &s2, FactorT2 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, ScalarT3 const &s3, FactorT3 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_any_scalar< FactorT >::value >::type as(ScalarT1 &s1, ScalarT2 const &s2, FactorT const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha)
Common routines for single-threaded or OpenMP-enabled execution on CPU.
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
Helper struct for checking whether a type is a viennacl::scalar<>
Simple enable-if variant that uses the SFINAE pattern.
viennacl::enable_if< viennacl::is_scalar< ScalarT1 >::value &&viennacl::is_scalar< ScalarT2 >::value &&viennacl::is_scalar< ScalarT3 >::value &&viennacl::is_any_scalar< FactorT2 >::value &&viennacl::is_any_scalar< FactorT3 >::value >::type asbs_s(ScalarT1 &s1, ScalarT2 const &s2, FactorT2 const &alpha, vcl_size_t, bool reciprocal_alpha, bool flip_sign_alpha, ScalarT3 const &s3, FactorT3 const &beta, vcl_size_t, bool reciprocal_beta, bool flip_sign_beta)