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);
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;
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);
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);
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>
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
toeplitz_matrix(vcl_size_t rows, vcl_size_t cols)
Creates the matrix with the given size.
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< NumericT >::ResultType > value_type
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.
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.
vcl_size_t size2() const
Returns the number of columns of the matrix.
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
entry_proxy< NumericT > operator()(vcl_size_t row_index, vcl_size_t col_index)
Read-write access to a single element of the matrix.
viennacl::backend::mem_handle handle_type
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
viennacl::vector< NumericT, AlignmentV > const & elements() const
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.
void resize(size_type new_size, bool preserve=true)
Resizes the allocated memory for the vector. Pads the memory to be a multiple of 'AlignmentV'.
toeplitz_matrix()
The default constructor. Does not allocate any memory.
handle_type const & handle() const
Returns the OpenCL handle.
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) ...
size_type size() const
Returns the length of the vector (cf. std::vector)
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.
size_type internal_size() const
Returns the internal length of the vector, which is given by size() plus the extra memory due to padd...
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
viennacl::vector< NumericT, AlignmentV > & elements()
Returns an internal viennacl::vector, which represents a Toeplitz matrix elements.
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
void resize(vcl_size_t sz, bool preserve=true)
Resizes the matrix. Existing entries can be preserved.
const handle_type & handle() const
Returns the memory handle.