All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
scalar_operations.hpp
Go to the documentation of this file.
#ifndef VIENNACL_LINALG_HOST_BASED_SCALAR_OPERATIONS_HPP_
#define VIENNACL_LINALG_HOST_BASED_SCALAR_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/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/stride.hpp"
#include "viennacl/linalg/host_based/common.hpp"
namespace viennacl
{
namespace linalg
{
namespace host_based
{
template<typename ScalarT1,
typename ScalarT2, typename FactorT>
typename 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 /*len_alpha*/, bool reciprocal_alpha, bool flip_sign_alpha)
{
typedef typename viennacl::result_of::cpu_value_type<ScalarT1>::type value_type;
value_type * data_s1 = detail::extract_raw_pointer<value_type>(s1);
value_type const * data_s2 = detail::extract_raw_pointer<value_type>(s2);
value_type data_alpha = alpha;
if (flip_sign_alpha)
data_alpha = -data_alpha;
if (reciprocal_alpha)
data_alpha = static_cast<value_type>(1) / data_alpha;
*data_s1 = *data_s2 * data_alpha;
}
template<typename ScalarT1,
typename ScalarT2, typename FactorT2,
typename ScalarT3, typename FactorT3>
typename 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 /*len_alpha*/, bool reciprocal_alpha, bool flip_sign_alpha,
ScalarT3 const & s3, FactorT3 const & beta, vcl_size_t /*len_beta*/, bool reciprocal_beta, bool flip_sign_beta)
{
typedef typename viennacl::result_of::cpu_value_type<ScalarT1>::type value_type;
value_type * data_s1 = detail::extract_raw_pointer<value_type>(s1);
value_type const * data_s2 = detail::extract_raw_pointer<value_type>(s2);
value_type const * data_s3 = detail::extract_raw_pointer<value_type>(s3);
value_type data_alpha = alpha;
if (flip_sign_alpha)
data_alpha = -data_alpha;
if (reciprocal_alpha)
data_alpha = static_cast<value_type>(1) / data_alpha;
value_type data_beta = beta;
if (flip_sign_beta)
data_beta = -data_beta;
if (reciprocal_beta)
data_beta = static_cast<value_type>(1) / data_beta;
*data_s1 = *data_s2 * data_alpha + *data_s3 * data_beta;
}
template<typename ScalarT1,
typename ScalarT2, typename FactorT2,
typename ScalarT3, typename FactorT3>
typename 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 /*len_alpha*/, bool reciprocal_alpha, bool flip_sign_alpha,
ScalarT3 const & s3, FactorT3 const & beta, vcl_size_t /*len_beta*/, bool reciprocal_beta, bool flip_sign_beta)
{
typedef typename viennacl::result_of::cpu_value_type<ScalarT1>::type value_type;
value_type * data_s1 = detail::extract_raw_pointer<value_type>(s1);
value_type const * data_s2 = detail::extract_raw_pointer<value_type>(s2);
value_type const * data_s3 = detail::extract_raw_pointer<value_type>(s3);
value_type data_alpha = alpha;
if (flip_sign_alpha)
data_alpha = -data_alpha;
if (reciprocal_alpha)
data_alpha = static_cast<value_type>(1) / data_alpha;
value_type data_beta = beta;
if (flip_sign_beta)
data_beta = -data_beta;
if (reciprocal_beta)
data_beta = static_cast<value_type>(1) / data_beta;
*data_s1 += *data_s2 * data_alpha + *data_s3 * data_beta;
}
template<typename ScalarT1, typename ScalarT2>
typename viennacl::enable_if< viennacl::is_scalar<ScalarT1>::value
&& viennacl::is_scalar<ScalarT2>::value
>::type
swap(ScalarT1 & s1, ScalarT2 & s2)
{
typedef typename viennacl::result_of::cpu_value_type<ScalarT1>::type value_type;
value_type * data_s1 = detail::extract_raw_pointer<value_type>(s1);
value_type * data_s2 = detail::extract_raw_pointer<value_type>(s2);
value_type temp = *data_s2;
*data_s2 = *data_s1;
*data_s1 = temp;
}
} //namespace host_based
} //namespace linalg
} //namespace viennacl
#endif
viennacl::enable_if
Simple enable-if variant that uses the SFINAE pattern.
Definition: enable_if.hpp:30
size.hpp
Generic size and resize functionality for different vector and matrix types.
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::linalg::host_based::swap
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.
Definition: scalar_operations.hpp:143
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.
s2
viennacl::scalar< int > s2
Definition: global_variables.cpp:58
s1
viennacl::scalar< float > s1
Definition: global_variables.cpp:57
viennacl::is_any_scalar
Helper struct for checking whether the provided type represents a scalar (either host, from ViennaCL, or a flip-sign proxy)
Definition: forwards.h:469
viennacl::linalg::host_based::asbs
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)
Definition: scalar_operations.hpp:73
viennacl::linalg::host_based::as
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)
Definition: scalar_operations.hpp:46
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
common.hpp
Common routines for single-threaded or OpenMP-enabled execution on CPU.
viennacl::result_of::cpu_value_type::type
T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type
Definition: result_of.hpp:271
predicate.hpp
All the predicates used within ViennaCL. Checks for expressions to be vectors, etc.
viennacl::is_scalar
Helper struct for checking whether a type is a viennacl::scalar<>
Definition: forwards.h:455
enable_if.hpp
Simple enable-if variant that uses the SFINAE pattern.
viennacl::linalg::host_based::asbs_s
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)
Definition: scalar_operations.hpp:108