1 #ifndef VIENNACL_TOEPLITZ_MATRIX_HPP
2 #define VIENNACL_TOEPLITZ_MATRIX_HPP
42 template<
class NumericT,
unsigned int AlignmentV>
62 assert(rows == cols &&
bool(
"Toeplitz matrix must be square!"));
75 elements_.resize(sz * 2, preserve);
82 handle_type
const &
handle()
const {
return elements_.handle(); }
119 assert(row_index <
size1() && col_index <
size2() &&
bool(
"Invalid access"));
121 long index =
static_cast<long>(col_index) - static_cast<long>(row_index);
126 (index > 0) index = 2 *
static_cast<long>(
size1()) - index;
139 elements_ += that.elements();
157 template<
typename NumericT,
unsigned int AlignmentV>
160 assert( (gpu_mat.size1() == 0 || (gpu_mat.size1() * 2 - 1) == cpu_vec.size()) &&
bool(
"Size mismatch"));
163 std::vector<NumericT> rvrs(cpu_vec.size());
164 std::copy(cpu_vec.begin(), cpu_vec.end(), rvrs.begin());
167 std::vector<NumericT> tmp(size * 2);
168 typedef typename std::vector<NumericT>::difference_type difference_type;
169 std::copy(rvrs.begin() + difference_type(size) - 1, rvrs.end(), tmp.begin());
170 std::copy(rvrs.begin(), rvrs.begin() + difference_type(size) - 1, tmp.begin() + difference_type(size) + 1);
172 copy(tmp, gpu_mat.elements());
181 template<
typename NumericT,
unsigned int AlignmentV>
184 assert((gpu_mat.size1() * 2 - 1) == cpu_vec.size() && bool(
"Size mismatch"));
187 std::vector<NumericT> tmp(size * 2);
188 copy(gpu_mat.elements(), tmp);
191 typedef typename std::vector<NumericT>::difference_type difference_type;
192 std::copy(tmp.begin(), tmp.begin() + difference_type(size) - 1, cpu_vec.begin() + difference_type(size));
193 std::copy(tmp.begin() + difference_type(size), tmp.end(), cpu_vec.begin());
203 template<
typename NumericT,
unsigned int AlignmentV,
typename MatrixT>
210 std::vector<NumericT> tmp(tep_src.size1() * 2 - 1);
215 com_dst(i, j) = tmp[
static_cast<vcl_size_t>(
static_cast<int>(j) - static_cast<int>(i) +
static_cast<int>(
size) - 1)];
224 template<
typename NumericT,
unsigned int AlignmentV,
typename MatrixT>
227 assert( (tep_dst.size1() == 0 || tep_dst.size1() ==
viennacl::traits::size1(com_src)) &&
bool(
"Size mismatch"));
228 assert( (tep_dst.size2() == 0 || tep_dst.size2() ==
viennacl::traits::size2(com_src)) &&
bool(
"Size mismatch"));
232 std::vector<NumericT> tmp(2*size - 1);
234 for (
long i = static_cast<long>(size) - 1; i >= 0; i--)
235 tmp[size - static_cast<vcl_size_t>(i) - 1] = com_src(static_cast<vcl_size_t>(i), 0);
238 tmp[size + i - 1] = com_src(0, i);
266 template<
class NumericT,
unsigned int AlignmentV>
267 std::ostream & operator<<(std::ostream & s, toeplitz_matrix<NumericT, AlignmentV>& gpu_matrix)
270 std::vector<NumericT> tmp(2*size - 1);
271 copy(gpu_matrix, tmp);
272 s <<
"[" << size <<
"," << size <<
"](";
279 s << tmp[vcl_size_t(static_cast<int>(j) - static_cast<int>(i) +
static_cast<int>(size - 1))];
281 if (j < (size - 1)) s <<
",";
300 template<
typename T,
unsigned int A>
301 struct op_executor<vector_base<T>,
op_assign, vector_expression<const toeplitz_matrix<T, A>, const vector_base<T>, op_prod> >
303 static void apply(vector_base<T> & lhs, vector_expression<
const toeplitz_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
317 template<
typename T,
unsigned int A>
318 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const toeplitz_matrix<T, A>, const vector_base<T>, op_prod> >
320 static void apply(vector_base<T> & lhs, vector_expression<
const toeplitz_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
328 template<
typename T,
unsigned int A>
329 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const toeplitz_matrix<T, A>, const vector_base<T>, op_prod> >
331 static void apply(vector_base<T> & lhs, vector_expression<
const toeplitz_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
341 template<
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
342 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> >
344 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)
352 template<
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
353 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> >
355 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)
365 template<
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
366 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> >
368 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)
384 #endif // VIENNACL_TOEPLITZ_MATRIX_HPP
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Implementations of operations using toeplitz_matrix. Experimental.
handle_type const & handle() const
Returns the OpenCL handle.
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
This file provides the forward declarations for the main types used within ViennaCL.
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
vcl_size_t internal_size() const
Returns the internal size of matrix representtion. Usually required for launching OpenCL kernels only...
toeplitz_matrix< NumericT, AlignmentV > & operator+=(toeplitz_matrix< NumericT, AlignmentV > &that)
+= operation for Toeplitz matrices
toeplitz_matrix()
The default constructor. Does not allocate any memory.
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
void resize(vcl_size_t sz, bool preserve=true)
Resizes the matrix. Existing entries can be preserved.
vcl_size_t size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
vcl_size_t size1() const
Returns the number of rows of the matrix.
viennacl::backend::mem_handle handle_type
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< NumericT >::ResultType > value_type
vcl_size_t size2() const
Returns the number of columns of the matrix.
Implementations of the OpenCL backend, where all contexts are stored in.
void copy(MatrixT const &com_src, toeplitz_matrix< NumericT, AlignmentV > &tep_dst)
Copies a the matrix-like object to the Toeplitz matrix from the OpenCL device (either GPU or multi-co...
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
viennacl::vector< NumericT, AlignmentV > & elements()
Returns an internal viennacl::vector, which represents a Toeplitz matrix elements.
viennacl::vector< NumericT, AlignmentV > const & elements() const
entry_proxy< NumericT > operator()(vcl_size_t row_index, vcl_size_t col_index)
Read-write access to a single element of the matrix.
All routines related to the Fast Fourier Transform. Experimental.
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
void reverse(viennacl::vector_base< NumericT > &in)
Reverse vector to oposite order and save it in input vector.
void prod_impl(const matrix_base< NumericT > &mat, const vector_base< NumericT > &vec, vector_base< NumericT > &result)
Carries out matrix-vector multiplication.
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
toeplitz_matrix(vcl_size_t rows, vcl_size_t cols)
Creates the matrix with the given size.
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...