1 #ifndef VIENNACL_VANDERMONDE_MATRIX_HPP
2 #define VIENNACL_VANDERMONDE_MATRIX_HPP
43 template<
class NumericT,
unsigned int AlignmentV>
44 class vandermonde_matrix
64 assert(rows == cols &&
bool(
"Vandermonde matrix must be square in this release!"));
76 elements_.resize(sz, preserve);
83 handle_type
const &
handle()
const {
return elements_.handle(); }
117 return elements_[row_index];
129 assert(row_index <
size1() && col_index <
size2() &&
bool(
"Invalid access"));
131 return pow(elements_[row_index], static_cast<int>(col_index));
147 template<
typename NumericT,
unsigned int AlignmentV>
150 assert(cpu_vec.size() == gpu_mat.size1() && bool(
"Size mismatch"));
151 copy(cpu_vec, gpu_mat.elements());
160 template<
typename NumericT,
unsigned int AlignmentV>
163 assert(cpu_vec.size() == gpu_mat.size1() && bool(
"Size mismatch"));
164 copy(gpu_mat.elements(), cpu_vec);
173 template<
typename NumericT,
unsigned int AlignmentV,
typename MatrixT>
180 std::vector<NumericT> tmp(size);
181 copy(vander_src, tmp);
185 com_dst(i, j) = std::pow(tmp[i], static_cast<int>(j));
195 template<
typename NumericT,
unsigned int AlignmentV,
typename MatrixT>
198 assert( (vander_dst.size1() == 0 || vander_dst.size1() ==
viennacl::traits::size1(com_src)) &&
bool(
"Size mismatch"));
199 assert( (vander_dst.size2() == 0 || vander_dst.size2() ==
viennacl::traits::size2(com_src)) &&
bool(
"Size mismatch"));
202 std::vector<NumericT> tmp(size);
205 tmp[i] = com_src(i, 1);
207 copy(tmp, vander_dst);
224 template<
class NumericT,
unsigned int AlignmentV>
225 std::ostream & operator<<(std::ostream& s, vandermonde_matrix<NumericT, AlignmentV>& gpu_matrix)
228 std::vector<NumericT> tmp(size);
229 copy(gpu_matrix, tmp);
230 s <<
"[" << size <<
"," << size <<
"](\n";
237 s << pow(tmp[i], static_cast<NumericT>(j));
259 template<
typename T,
unsigned int A>
260 struct op_executor<vector_base<T>,
op_assign, vector_expression<const vandermonde_matrix<T, A>, const vector_base<T>, op_prod> >
262 static void apply(vector_base<T> & lhs, vector_expression<
const vandermonde_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
276 template<
typename T,
unsigned int A>
277 struct op_executor<vector_base<T>, op_inplace_add, vector_expression<const vandermonde_matrix<T, A>, const vector_base<T>, op_prod> >
279 static void apply(vector_base<T> & lhs, vector_expression<
const vandermonde_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
287 template<
typename T,
unsigned int A>
288 struct op_executor<vector_base<T>, op_inplace_sub, vector_expression<const vandermonde_matrix<T, A>, const vector_base<T>, op_prod> >
290 static void apply(vector_base<T> & lhs, vector_expression<
const vandermonde_matrix<T, A>,
const vector_base<T>, op_prod>
const & rhs)
300 template<
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
301 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> >
303 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)
311 template<
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
312 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> >
314 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)
324 template<
typename T,
unsigned int A,
typename LHS,
typename RHS,
typename OP>
325 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> >
327 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)
342 #endif // VIENNACL_VANDERMONDE_MATRIX_HPP
This class represents a single scalar value on the GPU and behaves mostly like a built-in scalar type...
vandermonde_matrix(vcl_size_t rows, vcl_size_t cols)
Creates the matrix with the given size.
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows 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...
handle_type const & handle() const
Returns the OpenCL handle.
vcl_size_t size2() const
Returns the number of columns of the matrix.
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::backend::mem_handle handle_type
vcl_size_t size1() const
Returns the number of rows 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...
viennacl::vector< NumericT, AlignmentV > & elements()
Returns an internal viennacl::vector, which represents a Vandermonde matrix elements.
A Vandermonde matrix class.
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
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.)
NumericT operator()(vcl_size_t row_index, vcl_size_t col_index) const
Read access to a element of the matrix.
entry_proxy< NumericT > operator()(vcl_size_t row_index)
Read-write access to a base element of the matrix.
viennacl::vector< NumericT, AlignmentV > const & elements() const
scalar< typename viennacl::tools::CHECK_SCALAR_TEMPLATE_ARGUMENT< NumericT >::ResultType > value_type
void resize(vcl_size_t sz, bool preserve=true)
Resizes the matrix. Existing entries can be preserved.
Implementations of the OpenCL backend, where all contexts are stored in.
vandermonde_matrix()
The default constructor. Does not allocate any memory.
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) ...
All routines related to the Fast Fourier Transform. Experimental.
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
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.
A proxy class for a single element of a vector or matrix. This proxy should not be noticed by end-use...