1 #ifndef VIENNACL_VANDERMONDE_MATRIX_HPP
2 #define VIENNACL_VANDERMONDE_MATRIX_HPP
41 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
42 class vandermonde_matrix
62 assert(rows == cols &&
bool(
"Vandermonde matrix must be square in this release!"));
73 elements_.resize(sz, preserve);
80 handle_type
const &
handle()
const {
return elements_.handle(); }
114 return elements_[row_index];
126 assert(row_index <
size1() && col_index <
size2() &&
bool(
"Invalid access"));
128 return pow(elements_[row_index], static_cast<int>(col_index));
144 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
147 assert(cpu_vec.size() == gpu_mat.size1() && bool(
"Size mismatch"));
148 copy(cpu_vec, gpu_mat.elements());
157 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
160 assert(cpu_vec.size() == gpu_mat.size1() && bool(
"Size mismatch"));
161 copy(gpu_mat.elements(), cpu_vec);
170 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename MATRIXTYPE>
177 std::vector<SCALARTYPE> tmp(size);
178 copy(vander_src, tmp);
182 com_dst(i, j) = std::pow(tmp[i], static_cast<int>(j));
193 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename MATRIXTYPE>
196 assert( (vander_dst.size1() == 0 || vander_dst.size1() ==
viennacl::traits::size1(com_src)) &&
bool(
"Size mismatch"));
197 assert( (vander_dst.size2() == 0 || vander_dst.size2() ==
viennacl::traits::size2(com_src)) &&
bool(
"Size mismatch"));
200 std::vector<SCALARTYPE> tmp(size);
203 tmp[i] = com_src(i, 1);
205 copy(tmp, vander_dst);
222 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
223 std::ostream & operator<<(std::ostream& s, vandermonde_matrix<SCALARTYPE, ALIGNMENT>& gpu_matrix)
226 std::vector<SCALARTYPE> tmp(size);
227 copy(gpu_matrix, tmp);
228 s <<
"[" << size <<
"," << size <<
"](\n";
233 s << pow(tmp[i], static_cast<SCALARTYPE>(j));
234 if(j < (size - 1)) s <<
",";
254 template <
typename T,
unsigned int A>
255 struct op_executor<vector_base<T>, op_assign, vector_expression<const vandermonde_matrix<T, A>, const vector_base<T>, op_prod> >
257 static void apply(vector_base<T> & lhs, vector_expression<
const vandermonde_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
271 template <
typename T,
unsigned int A>
272 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vandermonde_matrix<T, A>, const vector_base<T>, op_prod> >
274 static void apply(vector_base<T> & lhs, vector_expression<
const vandermonde_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
282 template <
typename T,
unsigned int A>
283 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vandermonde_matrix<T, A>, const vector_base<T>, op_prod> >
285 static void apply(vector_base<T> & lhs, vector_expression<
const vandermonde_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
295 template <
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
296 struct op_executor<vector_base<T>, op_assign, vector_expression<const vandermonde_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
298 static void apply(vector_base<T> & lhs, vector_expression<
const vandermonde_matrix<T, A>,
const vector_expression<const LHS, const RHS, OP>, op_prod>
const & rhs)
306 template <
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
307 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vandermonde_matrix<T, A>, vector_expression<const LHS, const RHS, OP>, op_prod> >
309 static void apply(vector_base<T> & lhs, vector_expression<
const vandermonde_matrix<T, A>, vector_expression<const LHS, const RHS, OP>, op_prod>
const & rhs)
319 template <
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
320 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vandermonde_matrix<T, A>, const vector_expression<const LHS, const RHS, OP>, op_prod> >
322 static void apply(vector_base<T> & lhs, vector_expression<
const vandermonde_matrix<T, A>,
const vector_expression<const LHS, const RHS, OP>, op_prod>
const & rhs)
337 #endif // VIENNACL_VANDERMONDE_MATRIX_HPP
std::size_t vcl_size_t
Definition: forwards.h:58
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< SCALARTYPE >::ResultType > value_type
Definition: vandermonde_matrix.hpp:46
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
Definition: forwards.h:172
SCALARTYPE operator()(vcl_size_t row_index, vcl_size_t col_index) const
Read access to a element of the matrix.
Definition: vandermonde_matrix.hpp:124
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
vcl_size_t internal_size() const
Returns the internal size of matrix representtion. Usually required for launching OpenCL kernels only...
Definition: vandermonde_matrix.hpp:104
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
A Vandermonde matrix class.
Definition: forwards.h:333
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
Implementations of operations using vandermonde_matrix. Experimental.
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
void resize(vcl_size_t sz, bool preserve=true)
Resizes the matrix. Existing entries can be preserved.
Definition: vandermonde_matrix.hpp:72
vcl_size_t size2() const
Returns the number of columns of the matrix.
Definition: vandermonde_matrix.hpp:97
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
vandermonde_matrix()
The default constructor. Does not allocate any memory.
Definition: vandermonde_matrix.hpp:52
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
The vector type with operator-overloads and proxy classes is defined here. Linear algebra operations ...
viennacl::vector< SCALARTYPE, ALIGNMENT > const & elements() const
Definition: vandermonde_matrix.hpp:87
viennacl::backend::mem_handle handle_type
Definition: vandermonde_matrix.hpp:45
All routines related to the Fast Fourier Transform. Experimental.
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
Definition: mem_handle.hpp:62
handle_type const & handle() const
Returns the OpenCL handle.
Definition: vandermonde_matrix.hpp:80
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
vandermonde_matrix(vcl_size_t rows, vcl_size_t cols)
Creates the matrix with the given size.
Definition: vandermonde_matrix.hpp:60
vcl_size_t size1() const
Returns the number of rows of the matrix.
Definition: vandermonde_matrix.hpp:92
viennacl::backend::mem_handle & handle(T &obj)
Returns the generic memory handle of an object. Non-const version.
Definition: handle.hpp:41
viennacl::vector< SCALARTYPE, ALIGNMENT > & elements()
Returns an internal viennacl::vector, which represents a Vandermonde matrix elements.
Definition: vandermonde_matrix.hpp:86
entry_proxy< SCALARTYPE > operator()(vcl_size_t row_index)
Read-write access to a base element of the matrix.
Definition: vandermonde_matrix.hpp:112