00001 #ifndef VIENNACL_LINALG_TOEPLITZ_MATRIX_OPERATIONS_HPP_
00002 #define VIENNACL_LINALG_TOEPLITZ_MATRIX_OPERATIONS_HPP_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00024 #include "viennacl/forwards.h"
00025 #include "viennacl/ocl/device.hpp"
00026 #include "viennacl/ocl/handle.hpp"
00027 #include "viennacl/ocl/kernel.hpp"
00028 #include "viennacl/scalar.hpp"
00029 #include "viennacl/vector.hpp"
00030 #include "viennacl/tools/tools.hpp"
00031 #include "viennacl/fft.hpp"
00032
00033 namespace viennacl
00034 {
00035 namespace linalg
00036 {
00037
00038
00039
00047 template<class SCALARTYPE, unsigned int ALIGNMENT, unsigned int VECTOR_ALIGNMENT>
00048 vector_expression<const toeplitz_matrix<SCALARTYPE, ALIGNMENT>,
00049 const vector<SCALARTYPE, VECTOR_ALIGNMENT>,
00050 op_prod > prod_impl(const toeplitz_matrix<SCALARTYPE, ALIGNMENT> & mat,
00051 const vector<SCALARTYPE, VECTOR_ALIGNMENT> & vec)
00052 {
00053 return vector_expression<const toeplitz_matrix<SCALARTYPE, ALIGNMENT>,
00054 const vector<SCALARTYPE, VECTOR_ALIGNMENT>,
00055 op_prod >(mat, vec);
00056 }
00057
00058
00067 template<class SCALARTYPE, unsigned int ALIGNMENT, unsigned int VECTOR_ALIGNMENT>
00068 viennacl::vector_expression<const viennacl::toeplitz_matrix<SCALARTYPE, ALIGNMENT>,
00069 const viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT>,
00070 viennacl::op_prod > prod_impl(const viennacl::toeplitz_matrix<SCALARTYPE, ALIGNMENT> & mat,
00071 const viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> & vec,
00072 size_t NUM_THREADS)
00073 {
00074 return viennacl::vector_expression<const viennacl::toeplitz_matrix<SCALARTYPE, ALIGNMENT>,
00075 const viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT>,
00076 viennacl::op_prod >(mat, vec);
00077 }
00078
00087 template<class SCALARTYPE, unsigned int ALIGNMENT, unsigned int VECTOR_ALIGNMENT>
00088 void prod_impl(const viennacl::toeplitz_matrix<SCALARTYPE, ALIGNMENT> & mat,
00089 const viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> & vec,
00090 viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> & result)
00091 {
00092 assert(mat.size1() == result.size());
00093 assert(mat.size2() == vec.size());
00094
00095 viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> tep(mat.elements().size() * 2);
00096 viennacl::detail::fft::real_to_complex(mat.elements(), tep, mat.elements().size());
00097
00098 viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> tmp(vec.size() * 4);
00099 viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> tmp2(vec.size() * 4);
00100
00101 tmp.clear();
00102 copy(vec, tmp);
00103 viennacl::detail::fft::real_to_complex(tmp, tmp2, vec.size() * 2);
00104 viennacl::linalg::convolve(tep, tmp2, tmp);
00105 viennacl::detail::fft::complex_to_real(tmp, tmp2, vec.size() * 2);
00106 copy(tmp2.begin(), tmp2.begin() + vec.size(), result.begin());
00107 }
00108
00109 }
00110
00111
00112
00117 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00118 template <unsigned int MAT_ALIGNMENT>
00119 viennacl::vector<SCALARTYPE, ALIGNMENT> &
00120 viennacl::vector<SCALARTYPE, ALIGNMENT>::operator=(const viennacl::vector_expression< const toeplitz_matrix<SCALARTYPE, MAT_ALIGNMENT>,
00121 const viennacl::vector<SCALARTYPE, ALIGNMENT>,
00122 viennacl::op_prod> & proxy)
00123 {
00124
00125 if (proxy.rhs().handle() == this->handle())
00126 {
00127 viennacl::vector<SCALARTYPE, ALIGNMENT> result(proxy.rhs().size());
00128 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
00129 *this = result;
00130 return *this;
00131 }
00132 else
00133 {
00134 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), *this);
00135 return *this;
00136 }
00137 return *this;
00138 }
00139
00140
00145 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00146 template <unsigned int MAT_ALIGNMENT>
00147 viennacl::vector<SCALARTYPE, ALIGNMENT> &
00148 viennacl::vector<SCALARTYPE, ALIGNMENT>::operator+=(const vector_expression< const toeplitz_matrix<SCALARTYPE, MAT_ALIGNMENT>,
00149 const vector<SCALARTYPE, ALIGNMENT>,
00150 op_prod> & proxy)
00151 {
00152 vector<SCALARTYPE, ALIGNMENT> result(proxy.lhs().size1());
00153 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
00154 *this += result;
00155 return *this;
00156 }
00157
00162 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00163 template <unsigned int MAT_ALIGNMENT>
00164 viennacl::vector<SCALARTYPE, ALIGNMENT> &
00165 viennacl::vector<SCALARTYPE, ALIGNMENT>::operator-=(const vector_expression< const toeplitz_matrix<SCALARTYPE, MAT_ALIGNMENT>,
00166 const vector<SCALARTYPE, ALIGNMENT>,
00167 op_prod> & proxy)
00168 {
00169 vector<SCALARTYPE, ALIGNMENT> result(proxy.get_lhs().size1());
00170 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
00171 *this -= result;
00172 return *this;
00173 }
00174
00175
00176
00181 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00182 template <unsigned int MAT_ALIGNMENT>
00183 viennacl::vector<SCALARTYPE, ALIGNMENT>
00184 viennacl::vector<SCALARTYPE, ALIGNMENT>::operator+(const vector_expression< const toeplitz_matrix<SCALARTYPE, MAT_ALIGNMENT>,
00185 const vector<SCALARTYPE, ALIGNMENT>,
00186 op_prod> & proxy)
00187 {
00188 assert(proxy.get_lhs().size1() == size());
00189 vector<SCALARTYPE, ALIGNMENT> result(size());
00190 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
00191 result += *this;
00192 return result;
00193 }
00194
00199 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00200 template <unsigned int MAT_ALIGNMENT>
00201 viennacl::vector<SCALARTYPE, ALIGNMENT>
00202 viennacl::vector<SCALARTYPE, ALIGNMENT>::operator-(const vector_expression< const toeplitz_matrix<SCALARTYPE, MAT_ALIGNMENT>,
00203 const vector<SCALARTYPE, ALIGNMENT>,
00204 op_prod> & proxy)
00205 {
00206 assert(proxy.get_lhs().size1() == size());
00207 vector<SCALARTYPE, ALIGNMENT> result(size());
00208 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
00209 result = *this - result;
00210 return result;
00211 }
00212
00213 }
00214
00215
00216 #endif