All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
common.hpp
Go to the documentation of this file.
#ifndef VIENNACL_LINALG_HOST_BASED_COMMON_HPP_
#define VIENNACL_LINALG_HOST_BASED_COMMON_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/traits/handle.hpp"
namespace viennacl
{
namespace linalg
{
namespace host_based
{
namespace detail
{
template<typename ResultT, typename VectorT>
ResultT * extract_raw_pointer(VectorT & vec)
{
return reinterpret_cast<ResultT *>(viennacl::traits::ram_handle(vec).get());
}
template<typename ResultT, typename VectorT>
ResultT const * extract_raw_pointer(VectorT const & vec)
{
return reinterpret_cast<ResultT const *>(viennacl::traits::ram_handle(vec).get());
}
template<typename NumericT>
class vector_array_wrapper
{
public:
typedef NumericT value_type;
vector_array_wrapper(value_type * A,
vcl_size_t start,
vcl_size_t inc)
: A_(A),
start_(start),
inc_(inc) {}
value_type & operator()(vcl_size_t i) { return A_[i * inc_ + start_]; }
private:
value_type * A_;
vcl_size_t start_;
vcl_size_t inc_;
};
template<typename NumericT, typename LayoutT, bool is_transposed>
class matrix_array_wrapper
{
public:
typedef NumericT value_type;
matrix_array_wrapper(value_type * A,
vcl_size_t start1, vcl_size_t start2,
vcl_size_t inc1, vcl_size_t inc2,
vcl_size_t internal_size1, vcl_size_t internal_size2)
: A_(A),
start1_(start1), start2_(start2),
inc1_(inc1), inc2_(inc2),
internal_size1_(internal_size1), internal_size2_(internal_size2) {}
value_type & operator()(vcl_size_t i, vcl_size_t j)
{
return A_[LayoutT::mem_index(i * inc1_ + start1_,
j * inc2_ + start2_,
internal_size1_, internal_size2_)];
}
// convenience overloads to address signed index types for OpenMP:
value_type & operator()(vcl_size_t i, long j) { return operator()(i, static_cast<vcl_size_t>(j)); }
value_type & operator()(long i, vcl_size_t j) { return operator()(static_cast<vcl_size_t>(i), j); }
value_type & operator()(long i, long j) { return operator()(static_cast<vcl_size_t>(i), static_cast<vcl_size_t>(j)); }
private:
value_type * A_;
vcl_size_t start1_, start2_;
vcl_size_t inc1_, inc2_;
vcl_size_t internal_size1_, internal_size2_;
};
template<typename NumericT, typename LayoutT>
class matrix_array_wrapper<NumericT, LayoutT, true>
{
public:
typedef NumericT value_type;
matrix_array_wrapper(value_type * A,
vcl_size_t start1, vcl_size_t start2,
vcl_size_t inc1, vcl_size_t inc2,
vcl_size_t internal_size1, vcl_size_t internal_size2)
: A_(A),
start1_(start1), start2_(start2),
inc1_(inc1), inc2_(inc2),
internal_size1_(internal_size1), internal_size2_(internal_size2) {}
value_type & operator()(vcl_size_t i, vcl_size_t j)
{
//swapping row and column indices here
return A_[LayoutT::mem_index(j * inc1_ + start1_,
i * inc2_ + start2_,
internal_size1_, internal_size2_)];
}
// convenience overloads to address signed index types for OpenMP:
value_type & operator()(vcl_size_t i, long j) { return operator()(i, static_cast<vcl_size_t>(j)); }
value_type & operator()(long i, vcl_size_t j) { return operator()(static_cast<vcl_size_t>(i), j); }
value_type & operator()(long i, long j) { return operator()(static_cast<vcl_size_t>(i), static_cast<vcl_size_t>(j)); }
private:
value_type * A_;
vcl_size_t start1_, start2_;
vcl_size_t inc1_, inc2_;
vcl_size_t internal_size1_, internal_size2_;
};
} //namespace detail
} //namespace host_based
} //namespace linalg
} //namespace viennacl
#endif
viennacl::linalg::host_based::detail::matrix_array_wrapper::operator()
value_type & operator()(vcl_size_t i, vcl_size_t j)
Definition: common.hpp:87
viennacl::linalg::host_based::detail::vector_array_wrapper::value_type
NumericT value_type
Definition: common.hpp:53
viennacl::linalg::host_based::detail::vector_array_wrapper
Helper class for accessing a strided subvector of a larger vector.
Definition: common.hpp:50
viennacl::linalg::host_based::detail::matrix_array_wrapper::operator()
value_type & operator()(long i, long j)
Definition: common.hpp:97
viennacl::linalg::host_based::detail::matrix_array_wrapper::value_type
NumericT value_type
Definition: common.hpp:76
viennacl::linalg::host_based::detail::matrix_array_wrapper::operator()
value_type & operator()(vcl_size_t i, long j)
Definition: common.hpp:95
viennacl::traits::internal_size1
vcl_size_t internal_size1(matrix_base< NumericT > const &mat)
Helper routine for obtaining the internal number of entries per row of a ViennaCL matrix...
Definition: size.hpp:386
viennacl::linalg::host_based::detail::matrix_array_wrapper::operator()
value_type & operator()(long i, vcl_size_t j)
Definition: common.hpp:96
viennacl::traits::internal_size2
vcl_size_t internal_size2(matrix_base< NumericT > const &mat)
Helper routine for obtaining the internal number of entries per column of a ViennaCL matrix...
Definition: size.hpp:394
viennacl::traits::start1
result_of::size_type< T >::type start1(T const &obj)
Definition: start.hpp:65
NumericT
float NumericT
Definition: bisect.cpp:40
viennacl::linalg::host_based::detail::matrix_array_wrapper::matrix_array_wrapper
matrix_array_wrapper(value_type *A, vcl_size_t start1, vcl_size_t start2, vcl_size_t inc1, vcl_size_t inc2, vcl_size_t internal_size1, vcl_size_t internal_size2)
Definition: common.hpp:78
viennacl::traits::start2
result_of::size_type< T >::type start2(T const &obj)
Definition: start.hpp:84
viennacl::linalg::host_based::detail::matrix_array_wrapper
Helper array for accessing a strided submatrix embedded in a larger matrix.
Definition: common.hpp:73
viennacl::traits::start
result_of::size_type< T >::type start(T const &obj)
Definition: start.hpp:44
viennacl::linalg::host_based::detail::vector_array_wrapper::vector_array_wrapper
vector_array_wrapper(value_type *A, vcl_size_t start, vcl_size_t inc)
Definition: common.hpp:55
viennacl::linalg::host_based::detail::vector_array_wrapper::operator()
value_type & operator()(vcl_size_t i)
Definition: common.hpp:62
viennacl::linalg::host_based::detail::extract_raw_pointer
ResultT * extract_raw_pointer(VectorT &vec)
Definition: common.hpp:37
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::tools::shared_ptr::get
T * get() const
Definition: shared_ptr.hpp:101
handle.hpp
Extracts the underlying OpenCL handle from a vector, a matrix, an expression etc. ...
viennacl::traits::ram_handle
viennacl::backend::mem_handle::ram_handle_type & ram_handle(T &obj)
Generic helper routine for extracting the RAM handle of a ViennaCL object. Non-const version...
Definition: handle.hpp:138