1 #ifndef VIENNACL_CIRCULANT_MATRIX_HPP
2 #define VIENNACL_CIRCULANT_MATRIX_HPP
40 template<
class NumericT,
unsigned int AlignmentV>
61 assert(rows == cols &&
bool(
"Circulant matrix must be square!"));
73 elements_.
resize(sz, preserve);
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_[
static_cast<vcl_size_t>(index)];
149 template<
typename NumericT,
unsigned int AlignmentV>
152 assert( (gpu_mat.
size1() == 0 || cpu_vec.size() == gpu_mat.
size1()) &&
bool(
"Size mismatch"));
162 template<
typename NumericT,
unsigned int AlignmentV>
165 assert(cpu_vec.size() == gpu_mat.
size1() && bool(
"Size mismatch"));
175 template<
typename NumericT,
unsigned int AlignmentV,
typename MatrixT>
181 std::vector<NumericT> tmp(size);
188 long index =
static_cast<long>(i) - static_cast<long>(j);
190 index +=
static_cast<long>(
size);
191 com_dst(i, j) = tmp[
static_cast<vcl_size_t>(index)];
202 template<
typename NumericT,
unsigned int AlignmentV,
typename MatrixT>
210 std::vector<NumericT> tmp(size);
240 template<
class NumericT,
unsigned int AlignmentV>
241 std::ostream & operator<<(std::ostream& s, circulant_matrix<NumericT, AlignmentV>& gpu_matrix)
244 std::vector<NumericT> tmp(size);
245 copy(gpu_matrix, tmp);
246 s <<
"[" << size <<
"," << size <<
"](";
253 long index =
static_cast<long>(i) - static_cast<long>(j);
254 if (index < 0) index =
static_cast<long>(
size) + index;
257 if (j < (size - 1)) s <<
",";
276 template<
typename T,
unsigned int A>
277 struct op_executor<vector_base<T>,
op_assign, vector_expression<const circulant_matrix<T, A>, const vector_base<T>, op_prod> >
279 static void apply(vector_base<T> & lhs, vector_expression<
const circulant_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
293 template<
typename T,
unsigned int A>
294 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const circulant_matrix<T, A>, const vector_base<T>, op_prod> >
296 static void apply(vector_base<T> & lhs, vector_expression<
const circulant_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
304 template<
typename T,
unsigned int A>
305 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const circulant_matrix<T, A>, const vector_base<T>, op_prod> >
307 static void apply(vector_base<T> & lhs, vector_expression<
const circulant_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
317 template<
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
318 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> >
320 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)
328 template<
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
329 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> >
331 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)
341 template<
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
342 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> >
344 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)
359 #endif // VIENNACL_CIRCULANT_MATRIX_HPP
viennacl::vector< NumericT, AlignmentV > const & elements() const
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
viennacl::vector< NumericT, AlignmentV > & elements()
Returns an internal viennacl::vector, which represents a circulant matrix elements.
Implementations of operations using circulant_matrix. Experimental.
viennacl::backend::mem_handle handle_type
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< NumericT >::ResultType > value_type
This file provides the forward declarations for the main types used within ViennaCL.
void resize(vcl_size_t sz, bool preserve=true)
Resizes the matrix. Existing entries can be preserved.
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 size(VectorType const &vec)
Generic routine for obtaining the size of a vector (ViennaCL, uBLAS, etc.)
vcl_size_t internal_size() const
Returns the internal size of matrix representtion. Usually required for launching OpenCL kernels only...
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'.
entry_proxy< NumericT > operator()(vcl_size_t row_index, vcl_size_t col_index)
Read-write access to a single element of the matrix.
circulant_matrix()
The default constructor. Does not allocate any memory.
Implementations of the OpenCL backend, where all contexts are stored in.
handle_type const & handle() const
Returns the OpenCL handle.
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...
A Circulant matrix class.
circulant_matrix(vcl_size_t rows, vcl_size_t cols)
Creates the matrix with the given size.
vcl_size_t size2() const
Returns the number of columns of the matrix.
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.
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...
const handle_type & handle() const
Returns the memory handle.
circulant_matrix< NumericT, AlignmentV > & operator+=(circulant_matrix< NumericT, AlignmentV > &that)
+= operation for circulant matrices