1 #ifndef VIENNACL_TOEPLITZ_MATRIX_HPP
2 #define VIENNACL_TOEPLITZ_MATRIX_HPP
40 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
51 viennacl::linalg::kernels::fft<SCALARTYPE, 1>::init();
59 explicit toeplitz_matrix(std::size_t rows, std::size_t cols) : elements_(rows * 2)
61 assert(rows == cols &&
"Toeplitz matrix must be square!");
62 viennacl::linalg::kernels::fft<SCALARTYPE, 1>::init();
72 void resize(
size_t sz,
bool preserve =
true) {
73 elements_.resize(sz * 2, preserve);
93 std::size_t
size1()
const {
return elements_.size() / 2; }
98 std::size_t
size2()
const {
return elements_.size() / 2; }
117 assert(row_index <
size1() && col_index <
size2() &&
"Invalid access");
119 int index =
static_cast<int>(col_index) - static_cast<int>(row_index);
124 (index > 0) index = 2 *
size1() - index;
125 return elements_[index];
154 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
158 assert((size * 2 - 1) == cpu_vec.size() &&
"Size mismatch");
159 std::vector<SCALARTYPE> rvrs(cpu_vec.size());
160 std::copy(cpu_vec.begin(), cpu_vec.end(), rvrs.begin());
161 std::reverse(rvrs.begin(), rvrs.end());
163 std::vector<SCALARTYPE> tmp(size * 2);
164 std::copy(rvrs.begin() + size - 1, rvrs.end(), tmp.begin());
165 std::copy(rvrs.begin(), rvrs.begin() + size - 1, tmp.begin() + size + 1);
176 template <
typename SCALARTYPE,
unsigned int ALIGNMENT>
180 assert((size * 2 - 1) == cpu_vec.size() &&
"Size mismatch");
181 std::vector<SCALARTYPE> tmp(size * 2);
183 std::reverse(tmp.begin(), tmp.end());
185 std::copy(tmp.begin(), tmp.begin() + size - 1, cpu_vec.begin() +
size);
196 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename MATRIXTYPE>
200 assert(size == com_dst.size1() &&
"Size mismatch");
201 assert(size == com_dst.size2() &&
"Size mismatch");
202 std::vector<SCALARTYPE> tmp(tep_src.
size1() * 2 - 1);
205 for(std::size_t i = 0; i <
size; i++)
206 for(std::size_t j = 0; j <
size; j++)
207 com_dst(i, j) = tmp[
static_cast<int>(j) - static_cast<int>(i) +
static_cast<int>(
size) - 1];
216 template <
typename SCALARTYPE,
unsigned int ALIGNMENT,
typename MATRIXTYPE>
220 assert(size == com_src.size1() &&
"Size mismatch");
221 assert(size == com_src.size2() &&
"Size mismatch");
223 std::vector<SCALARTYPE> tmp(2*size - 1);
225 for(
int i = size - 1; i >= 0; i--)
226 tmp[size - i - 1] = com_src(i, 0);
228 for(std::size_t i = 1; i <
size; i++)
229 tmp[size + i - 1] = com_src(0, i);
257 template<
class SCALARTYPE,
unsigned int ALIGNMENT>
258 std::ostream & operator<<(std::ostream & s, toeplitz_matrix<SCALARTYPE, ALIGNMENT>& gpu_matrix)
260 std::size_t
size = gpu_matrix.size1();
261 std::vector<SCALARTYPE> tmp(2*size - 1);
262 copy(gpu_matrix, tmp);
263 s <<
"[" << size <<
"," << size <<
"](";
265 for(std::size_t i = 0; i <
size; i++) {
267 for(std::size_t j = 0; j <
size; j++) {
268 s << tmp[(int)j - (
int)i + (int)size - 1];
270 if(j < (size - 1)) s <<
",";
280 #endif // _VIENNACL_TOEPLITZ_MATRIX_HPP