ViennaCL - The Vienna Computing Library  1.2.0
toeplitz_matrix_operations.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_TOEPLITZ_MATRIX_OPERATIONS_HPP_
2 #define VIENNACL_LINALG_TOEPLITZ_MATRIX_OPERATIONS_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2011, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8 
9  -----------------
10  ViennaCL - The Vienna Computing Library
11  -----------------
12 
13  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
14 
15  (A list of authors and contributors can be found in the PDF manual)
16 
17  License: MIT (X11), see file LICENSE in the base directory
18 ============================================================================= */
19 
24 #include "viennacl/forwards.h"
25 #include "viennacl/ocl/device.hpp"
26 #include "viennacl/ocl/handle.hpp"
27 #include "viennacl/ocl/kernel.hpp"
28 #include "viennacl/scalar.hpp"
29 #include "viennacl/vector.hpp"
30 #include "viennacl/tools/tools.hpp"
31 #include "viennacl/fft.hpp"
32 
33 namespace viennacl
34 {
35  namespace linalg
36  {
37 
38 
39  // A * x
47  template<class SCALARTYPE, unsigned int ALIGNMENT, unsigned int VECTOR_ALIGNMENT>
48  vector_expression<const toeplitz_matrix<SCALARTYPE, ALIGNMENT>,
49  const vector<SCALARTYPE, VECTOR_ALIGNMENT>,
52  {
55  op_prod >(mat, vec);
56  }
57 
58  // A * x
67  template<class SCALARTYPE, unsigned int ALIGNMENT, unsigned int VECTOR_ALIGNMENT>
72  size_t NUM_THREADS)
73  {
76  viennacl::op_prod >(mat, vec);
77  }
78 
87  template<class SCALARTYPE, unsigned int ALIGNMENT, unsigned int VECTOR_ALIGNMENT>
91  {
92  assert(mat.size1() == result.size());
93  assert(mat.size2() == vec.size());
94 
96  viennacl::detail::fft::real_to_complex(mat.elements(), tep, mat.elements().size());
97 
100 
101  tmp.clear();
102  copy(vec, tmp);
103  viennacl::detail::fft::real_to_complex(tmp, tmp2, vec.size() * 2);
104  viennacl::linalg::convolve(tep, tmp2, tmp);
105  viennacl::detail::fft::complex_to_real(tmp, tmp2, vec.size() * 2);
106  copy(tmp2.begin(), tmp2.begin() + vec.size(), result.begin());
107  }
108 
109  } //namespace linalg
110 
111 
112 
117  template <typename SCALARTYPE, unsigned int ALIGNMENT>
118  template <unsigned int MAT_ALIGNMENT>
122  viennacl::op_prod> & proxy)
123  {
124  // check for the special case x = A * x
125  if (proxy.rhs().handle() == this->handle())
126  {
127  viennacl::vector<SCALARTYPE, ALIGNMENT> result(proxy.rhs().size());
128  viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
129  *this = result;
130  return *this;
131  }
132  else
133  {
134  viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), *this);
135  return *this;
136  }
137  return *this;
138  }
139 
140  //v += A * x
145  template <typename SCALARTYPE, unsigned int ALIGNMENT>
146  template <unsigned int MAT_ALIGNMENT>
150  op_prod> & proxy)
151  {
152  vector<SCALARTYPE, ALIGNMENT> result(proxy.lhs().size1());
153  viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
154  *this += result;
155  return *this;
156  }
157 
162  template <typename SCALARTYPE, unsigned int ALIGNMENT>
163  template <unsigned int MAT_ALIGNMENT>
167  op_prod> & proxy)
168  {
169  vector<SCALARTYPE, ALIGNMENT> result(proxy.get_lhs().size1());
170  viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
171  *this -= result;
172  return *this;
173  }
174 
175 
176  //free functions:
181  template <typename SCALARTYPE, unsigned int ALIGNMENT>
182  template <unsigned int MAT_ALIGNMENT>
186  op_prod> & proxy)
187  {
188  assert(proxy.get_lhs().size1() == size());
190  viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
191  result += *this;
192  return result;
193  }
194 
199  template <typename SCALARTYPE, unsigned int ALIGNMENT>
200  template <unsigned int MAT_ALIGNMENT>
204  op_prod> & proxy)
205  {
206  assert(proxy.get_lhs().size1() == size());
208  viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
209  result = *this - result;
210  return result;
211  }
212 
213 } //namespace viennacl
214 
215 
216 #endif