1 #ifndef VIENNACL_CIRCULANT_MATRIX_HPP
2 #define VIENNACL_CIRCULANT_MATRIX_HPP
40 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
61 assert(rows == cols &&
bool(
"Circulant matrix must be square!"));
73 elements_.resize(sz, preserve);
80 handle_type
const &
handle()
const {
return elements_.handle(); }
115 long index =
static_cast<long>(row_index) - static_cast<long>(col_index);
117 assert(row_index <
size1() && col_index <
size2() &&
bool(
"Invalid access"));
120 index +=
static_cast<long>(
size1());
121 return elements_[index];
149 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
152 assert( (gpu_mat.
size1() == 0 || cpu_vec.size() == gpu_mat.
size1()) &&
bool(
"Size mismatch"));
162 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
165 assert(cpu_vec.size() == gpu_mat.
size1() && bool(
"Size mismatch"));
175 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename MATRIXTYPE>
180 std::vector<SCALARTYPE> tmp(size);
185 long index =
static_cast<long>(i) - static_cast<long>(j);
187 index =
static_cast<long>(size + index);
188 com_dst(i, j) = tmp[index];
199 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename MATRIXTYPE>
207 std::vector<SCALARTYPE> tmp(size);
237 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
238 std::ostream & operator<<(std::ostream& s, circulant_matrix<SCALARTYPE, ALIGNMENT>& gpu_matrix)
241 std::vector<SCALARTYPE> tmp(size);
242 copy(gpu_matrix, tmp);
243 s <<
"[" << size <<
"," << size <<
"](";
248 long index =
static_cast<long>(i) - static_cast<long>(j);
249 if(index < 0) index =
static_cast<long>(
size) + index;
252 if(j < (size - 1)) s <<
",";
271 template <
typename T,
unsigned int A>
272 struct op_executor<vector_base<T>, op_assign, vector_expression<const circulant_matrix<T, A>, const vector_base<T>, op_prod> >
274 static void apply(vector_base<T> & lhs, vector_expression<
const circulant_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
288 template <
typename T,
unsigned int A>
289 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const circulant_matrix<T, A>, const vector_base<T>, op_prod> >
291 static void apply(vector_base<T> & lhs, vector_expression<
const circulant_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
299 template <
typename T,
unsigned int A>
300 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const circulant_matrix<T, A>, const vector_base<T>, op_prod> >
302 static void apply(vector_base<T> & lhs, vector_expression<
const circulant_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
312 template <
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
313 struct op_executor<vector_base<T>, op_assign, vector_expression<const circulant_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
315 static void apply(vector_base<T> & lhs, vector_expression<
const circulant_matrix<T, A>,
const vector_expression<const LHS, const RHS, OP>, op_prod>
const & rhs)
323 template <
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
324 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const circulant_matrix<T, A>, vector_expression<const LHS, const RHS, OP>, op_prod> >
326 static void apply(vector_base<T> & lhs, vector_expression<
const circulant_matrix<T, A>, vector_expression<const LHS, const RHS, OP>, op_prod>
const & rhs)
336 template <
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
337 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const circulant_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
339 static void apply(vector_base<T> & lhs, vector_expression<
const circulant_matrix<T, A>,
const vector_expression<const LHS, const RHS, OP>, op_prod>
const & rhs)
354 #endif // VIENNACL_CIRCULANT_MATRIX_HPP
std::size_t vcl_size_t
Definition: forwards.h:58
circulant_matrix< SCALARTYPE, ALIGNMENT > & operator+=(circulant_matrix< SCALARTYPE, ALIGNMENT > &that)
+= operation for circulant matrices
Definition: circulant_matrix.hpp:130
Implementations of operations using circulant_matrix. Experimental.
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< SCALARTYPE >::ResultType > value_type
Definition: circulant_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
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: circulant_matrix.hpp:113
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
handle_type const & handle() const
Returns the OpenCL handle.
Definition: circulant_matrix.hpp:80
viennacl::backend::mem_handle handle_type
Definition: circulant_matrix.hpp:44
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...
Definition: size.hpp:245
circulant_matrix()
The default constructor. Does not allocate any memory.
Definition: circulant_matrix.hpp:51
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
viennacl::vector< SCALARTYPE, ALIGNMENT > & elements()
Returns an internal viennacl::vector, which represents a circulant matrix elements.
Definition: circulant_matrix.hpp:86
circulant_matrix(vcl_size_t rows, vcl_size_t cols)
Creates the matrix with the given size.
Definition: circulant_matrix.hpp:59
viennacl::vector< SCALARTYPE, ALIGNMENT > const & elements() const
Definition: circulant_matrix.hpp:87
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
Implementations of the OpenCL backend, where all contexts are stored in.
A vector class representing a linear memory sequence on the GPU. Inspired by boost::numeric::ublas::v...
Definition: forwards.h:208
vcl_size_t size2() const
Returns the number of columns of the matrix.
Definition: circulant_matrix.hpp:97
vcl_size_t internal_size() const
Returns the internal size of matrix representtion. Usually required for launching OpenCL kernels only...
Definition: circulant_matrix.hpp:104
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 size1() const
Returns the number of rows of the matrix.
Definition: circulant_matrix.hpp:92
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:62
A Circulant matrix class.
Definition: circulant_matrix.hpp:41
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 resize(vcl_size_t sz, bool preserve=true)
Resizes the matrix. Existing entries can be preserved.
Definition: circulant_matrix.hpp:71