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);
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...
vcl_size_t size1(MatrixType const &mat)
Generic routine for obtaining the number of rows of a matrix (ViennaCL, uBLAS, etc.)
viennacl::backend::mem_handle handle_type
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.
vandermonde_matrix(vcl_size_t rows, vcl_size_t cols)
Creates the matrix with the given size.
result_of::size_type< MatrixType >::type size2(MatrixType const &mat)
Generic routine for obtaining the number of columns of a matrix (ViennaCL, uBLAS, etc...
handle_type const & handle() const
Returns the OpenCL handle.
A Vandermonde matrix class.
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.)
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'.
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.
Implementations of the OpenCL backend, where all contexts are stored in.
vcl_size_t internal_size() const
Returns the internal size of matrix representtion. Usually required for launching OpenCL kernels only...
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.
vcl_size_t size2() const
Returns the number of columns of the matrix.
Main abstraction class for multiple memory domains. Represents a buffer in either main RAM...
viennacl::vector< NumericT, AlignmentV > & elements()
Returns an internal viennacl::vector, which represents a Vandermonde matrix elements.
viennacl::vector< NumericT, AlignmentV > const & elements() const
vandermonde_matrix()
The default constructor. Does not allocate any memory.
void resize(vcl_size_t sz, bool preserve=true)
Resizes the matrix. Existing entries can be preserved.
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.
vcl_size_t size1() const
Returns the number of rows of the matrix.
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.