1 #ifndef VIENNACL_TOEPLITZ_MATRIX_HPP
2 #define VIENNACL_TOEPLITZ_MATRIX_HPP
41 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
61 assert(rows == cols &&
bool(
"Toeplitz matrix must be square!"));
73 elements_.resize(sz * 2, preserve);
80 handle_type
const &
handle()
const {
return elements_.handle(); }
117 assert(row_index <
size1() && col_index <
size2() &&
bool(
"Invalid access"));
119 long index =
static_cast<long>(col_index) - static_cast<long>(row_index);
124 (index > 0) index = 2 *
static_cast<long>(
size1()) - index;
125 return elements_[index];
136 elements_ += that.elements();
154 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
157 assert( (gpu_mat.size1() == 0 || (gpu_mat.size1() * 2 - 1) == cpu_vec.size()) &&
bool(
"Size mismatch"));
160 std::vector<SCALARTYPE> rvrs(cpu_vec.size());
161 std::copy(cpu_vec.begin(), cpu_vec.end(), rvrs.begin());
162 std::reverse(rvrs.begin(), rvrs.end());
164 std::vector<SCALARTYPE> tmp(size * 2);
165 std::copy(rvrs.begin() + size - 1, rvrs.end(), tmp.begin());
166 std::copy(rvrs.begin(), rvrs.begin() + size - 1, tmp.begin() + size + 1);
168 copy(tmp, gpu_mat.elements());
177 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
180 assert((gpu_mat.size1() * 2 - 1) == cpu_vec.size() && bool(
"Size mismatch"));
183 std::vector<SCALARTYPE> tmp(size * 2);
184 copy(gpu_mat.elements(), tmp);
185 std::reverse(tmp.begin(), tmp.end());
187 std::copy(tmp.begin(), tmp.begin() + size - 1, cpu_vec.begin() +
size);
198 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename MATRIXTYPE>
205 std::vector<SCALARTYPE> tmp(tep_src.size1() * 2 - 1);
210 com_dst(i, j) = tmp[
static_cast<int>(j) - static_cast<int>(i) +
static_cast<int>(
size) - 1];
219 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename MATRIXTYPE>
222 assert( (tep_dst.size1() == 0 || tep_dst.size1() ==
viennacl::traits::size1(com_src)) &&
bool(
"Size mismatch"));
223 assert( (tep_dst.size2() == 0 || tep_dst.size2() ==
viennacl::traits::size2(com_src)) &&
bool(
"Size mismatch"));
227 std::vector<SCALARTYPE> tmp(2*size - 1);
229 for(
long i = static_cast<long>(size) - 1; i >= 0; i--)
230 tmp[size - i - 1] = com_src(i, 0);
233 tmp[size + i - 1] = com_src(0, i);
261 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
262 std::ostream & operator<<(std::ostream & s, toeplitz_matrix<SCALARTYPE, ALIGNMENT>& gpu_matrix)
265 std::vector<SCALARTYPE> tmp(2*size - 1);
266 copy(gpu_matrix, tmp);
267 s <<
"[" << size <<
"," << size <<
"](";
272 s << tmp[static_cast<int>(j) - static_cast<int>(i) +
static_cast<int>(size - 1)];
274 if(j < (size - 1)) s <<
",";
293 template <
typename T,
unsigned int A>
294 struct op_executor<vector_base<T>, op_assign, vector_expression<const toeplitz_matrix<T, A>, const vector_base<T>, op_prod> >
296 static void apply(vector_base<T> & lhs, vector_expression<
const toeplitz_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
310 template <
typename T,
unsigned int A>
311 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const toeplitz_matrix<T, A>, const vector_base<T>, op_prod> >
313 static void apply(vector_base<T> & lhs, vector_expression<
const toeplitz_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
321 template <
typename T,
unsigned int A>
322 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const toeplitz_matrix<T, A>, const vector_base<T>, op_prod> >
324 static void apply(vector_base<T> & lhs, vector_expression<
const toeplitz_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
334 template <
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
335 struct op_executor<vector_base<T>, op_assign, vector_expression<const toeplitz_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
337 static void apply(vector_base<T> & lhs, vector_expression<
const toeplitz_matrix<T, A>,
const vector_expression<const LHS, const RHS, OP>, op_prod>
const & rhs)
345 template <
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
346 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const toeplitz_matrix<T, A>, vector_expression<const LHS, const RHS, OP>, op_prod> >
348 static void apply(vector_base<T> & lhs, vector_expression<
const toeplitz_matrix<T, A>, vector_expression<const LHS, const RHS, OP>, op_prod>
const & rhs)
358 template <
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
359 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const toeplitz_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
361 static void apply(vector_base<T> & lhs, vector_expression<
const toeplitz_matrix<T, A>,
const vector_expression<const LHS, const RHS, OP>, op_prod>
const & rhs)
377 #endif // VIENNACL_TOEPLITZ_MATRIX_HPP
std::size_t vcl_size_t
Definition: forwards.h:58
Implementations of operations using toeplitz_matrix. Experimental.
viennacl::backend::mem_handle handle_type
Definition: toeplitz_matrix.hpp:45
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:172
viennacl::vector< SCALARTYPE, ALIGNMENT > & elements()
Returns an internal viennacl::vector, which represents a Toeplitz matrix elements.
Definition: toeplitz_matrix.hpp:86
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
Definition: size.hpp:216
This file provides the forward declarations for the main types used within ViennaCL.
vcl_size_t size2() const
Returns the number of columns of the matrix.
Definition: toeplitz_matrix.hpp:98
handle_type const & handle() const
Returns the OpenCL handle.
Definition: toeplitz_matrix.hpp:80
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
Definition: size.hpp:245
toeplitz_matrix(vcl_size_t rows, vcl_size_t cols)
Creates the matrix with the given size.
Definition: toeplitz_matrix.hpp:59
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
Definition: size.hpp:144
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
Definition: forwards.h:178
toeplitz_matrix< SCALARTYPE, ALIGNMENT > & operator+=(toeplitz_matrix< SCALARTYPE, ALIGNMENT > &that)
+= operation for Toeplitz matrices
Definition: toeplitz_matrix.hpp:135
A Toeplitz matrix class.
Definition: forwards.h:330
void copy(std::vector< SCALARTYPE > &cpu_vec, circulant_matrix< SCALARTYPE, ALIGNMENT > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
Definition: circulant_matrix.hpp:150
entry_proxy< SCALARTYPE > operator()(vcl_size_t row_index, vcl_size_t col_index)
Read-write access to a single element of the matrix.
Definition: toeplitz_matrix.hpp:115
toeplitz_matrix()
The default constructor. Does not allocate any memory.
Definition: toeplitz_matrix.hpp:52
Implementations of the OpenCL backend, where all contexts are stored in.
void resize(vcl_size_t sz, bool preserve=true)
Resizes the matrix. Existing entries can be preserved.
Definition: toeplitz_matrix.hpp:72
viennacl::vector< SCALARTYPE, ALIGNMENT > const & elements() const
Definition: toeplitz_matrix.hpp:87
A vector class representing a linear memory sequence on the GPU. Inspired by boost::numeric::ublas::v...
Definition: forwards.h:208
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
All routines related to the Fast Fourier Transform. Experimental.
vcl_size_t internal_size() const
Returns the internal size of matrix representtion. Usually required for launching OpenCL kernels only...
Definition: toeplitz_matrix.hpp:105
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:62
void prod_impl(const matrix_base< NumericT, F > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
Definition: matrix_operations.hpp:350
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
void copy(MATRIXTYPE const &com_src, toeplitz_matrix< SCALARTYPE, ALIGNMENT > &tep_dst)
Copies a the matrix-like object to the Toeplitz matrix from the OpenCL device (either GPU or multi-co...
Definition: toeplitz_matrix.hpp:220
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< SCALARTYPE >::ResultType > value_type
Definition: toeplitz_matrix.hpp:46
vcl_size_t size1() const
Returns the number of rows of the matrix.
Definition: toeplitz_matrix.hpp:93