Go to the documentation of this file.00001 #ifndef VIENNACL_HANKEL_MATRIX_HPP
00002 #define VIENNACL_HANKEL_MATRIX_HPP
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00025 #include "viennacl/forwards.h"
00026 #include "viennacl/vector.hpp"
00027 #include "viennacl/ocl/context.hpp"
00028
00029 #include "viennacl/toeplitz_matrix.hpp"
00030 #include "viennacl/fft.hpp"
00031
00032 #include "viennacl/linalg/hankel_matrix_operations.hpp"
00033
00034 namespace viennacl {
00040 template<class SCALARTYPE, unsigned int ALIGNMENT>
00041 class hankel_matrix
00042 {
00043 public:
00048 explicit hankel_matrix()
00049 {
00050 viennacl::linalg::kernels::fft<SCALARTYPE, 1>::init();
00051 }
00052
00059 explicit hankel_matrix(std::size_t rows, std::size_t cols) : elements_(rows, cols)
00060 {
00061 assert(rows == cols && "Hankel matrix must be square!");
00062 viennacl::linalg::kernels::fft<SCALARTYPE, 1>::init();
00063 }
00064
00071 void resize(size_t sz, bool preserve = true)
00072 {
00073 elements_.resize(sz, preserve);
00074 }
00075
00080 viennacl::ocl::handle<cl_mem> handle() const { return elements_.handle(); }
00081
00086 toeplitz_matrix<SCALARTYPE, ALIGNMENT> & elements() { return elements_; }
00087 toeplitz_matrix<SCALARTYPE, ALIGNMENT> const & elements() const { return elements_; }
00088
00092 std::size_t size1() const { return elements_.size1(); }
00093
00097 std::size_t size2() const { return elements_.size2(); }
00098
00104 std::size_t internal_size() const { return elements_.internal_size(); }
00105
00113 entry_proxy<SCALARTYPE> operator()(unsigned int row_index, unsigned int col_index)
00114 {
00115 assert(row_index < size1() && col_index < size2() && "Invalid access");
00116
00117 return elements_(size1() - row_index - 1, col_index);
00118 }
00119
00126 hankel_matrix<SCALARTYPE, ALIGNMENT>& operator +=(hankel_matrix<SCALARTYPE, ALIGNMENT>& that)
00127 {
00128 elements_ += that.elements();
00129 return *this;
00130 }
00131
00132 private:
00133 hankel_matrix(hankel_matrix const & t) {}
00134 hankel_matrix & operator=(hankel_matrix const & t) {}
00135
00136 toeplitz_matrix<SCALARTYPE, ALIGNMENT> elements_;
00137 };
00138
00145 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00146 void copy(std::vector<SCALARTYPE> const & cpu_vec, hankel_matrix<SCALARTYPE, ALIGNMENT> & gpu_mat)
00147 {
00148 assert((gpu_mat.size1() * 2 - 1) == cpu_vec.size() && "Size mismatch");
00149
00150 copy(cpu_vec, gpu_mat.elements());
00151 }
00152
00159 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00160 void copy(hankel_matrix<SCALARTYPE, ALIGNMENT> const & gpu_mat, std::vector<SCALARTYPE> & cpu_vec)
00161 {
00162 assert((gpu_mat.size1() * 2 - 1) == cpu_vec.size() && "Size mismatch");
00163
00164 copy(gpu_mat.elements(), cpu_vec);
00165 }
00166
00173 template <typename SCALARTYPE, unsigned int ALIGNMENT, typename MATRIXTYPE>
00174 void copy(hankel_matrix<SCALARTYPE, ALIGNMENT> const & han_src, MATRIXTYPE& com_dst)
00175 {
00176 std::size_t size = han_src.size1();
00177 assert(size == com_dst.size1() && "Size mismatch");
00178 assert(size == com_dst.size2() && "Size mismatch");
00179 std::vector<SCALARTYPE> tmp(size * 2 - 1);
00180 copy(han_src, tmp);
00181
00182 for (std::size_t i = 0; i < size; i++)
00183 for (std::size_t j = 0; j < size; j++)
00184 com_dst(i, j) = tmp[i + j];
00185 }
00186
00193 template <typename SCALARTYPE, unsigned int ALIGNMENT, typename MATRIXTYPE>
00194 void copy(MATRIXTYPE const & com_src, hankel_matrix<SCALARTYPE, ALIGNMENT>& han_dst)
00195 {
00196 std::size_t size = han_dst.size1();
00197 assert(size == com_src.size1() && "Size mismatch");
00198 assert(size == com_src.size2() && "Size mismatch");
00199
00200 std::vector<SCALARTYPE> tmp(2*size - 1);
00201
00202 for (std::size_t i = 0; i < size; i++)
00203 tmp[i] = com_src(0, i);
00204
00205 for (std::size_t i = 1; i < size; i++)
00206 tmp[size + i - 1] = com_src(size - 1, i);
00207
00208 viennacl::copy(tmp, han_dst);
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 template<class SCALARTYPE, unsigned int ALIGNMENT>
00221 std::ostream & operator<<(std::ostream & s, hankel_matrix<SCALARTYPE, ALIGNMENT>& gpu_matrix)
00222 {
00223 std::size_t size = gpu_matrix.size1();
00224 std::vector<SCALARTYPE> tmp(2*size - 1);
00225 copy(gpu_matrix, tmp);
00226 s << "[" << size << "," << size << "](";
00227
00228 for(std::size_t i = 0; i < size; i++) {
00229 s << "(";
00230 for(std::size_t j = 0; j < size; j++) {
00231 s << tmp[i + j];
00232
00233 if(j < (size - 1)) s << ",";
00234 }
00235 s << ")";
00236 }
00237 s << ")";
00238 return s;
00239 }
00240 }
00241 #endif // _VIENNACL_HANKEL_MATRIX_HPP