00001 #ifndef VIENNACL_LINALG_VANDERMONDE_MATRIX_OPERATIONS_HPP_
00002 #define VIENNACL_LINALG_VANDERMONDE_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
00034 namespace viennacl
00035 {
00036 namespace linalg
00037 {
00038
00039
00040
00048 template<class SCALARTYPE, unsigned int ALIGNMENT, unsigned int VECTOR_ALIGNMENT>
00049 vector_expression<const vandermonde_matrix<SCALARTYPE, ALIGNMENT>,
00050 const vector<SCALARTYPE, VECTOR_ALIGNMENT>,
00051 op_prod > prod_impl(const vandermonde_matrix<SCALARTYPE, ALIGNMENT> & mat,
00052 const vector<SCALARTYPE, VECTOR_ALIGNMENT> & vec)
00053 {
00054 return vector_expression<const vandermonde_matrix<SCALARTYPE, ALIGNMENT>,
00055 const vector<SCALARTYPE, VECTOR_ALIGNMENT>,
00056 op_prod >(mat, vec);
00057 }
00058
00059
00068 template<class SCALARTYPE, unsigned int ALIGNMENT, unsigned int VECTOR_ALIGNMENT>
00069 viennacl::vector_expression<const viennacl::vandermonde_matrix<SCALARTYPE, ALIGNMENT>,
00070 const viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT>,
00071 viennacl::op_prod > prod_impl(const viennacl::vandermonde_matrix<SCALARTYPE, ALIGNMENT> & mat,
00072 const viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> & vec,
00073 size_t NUM_THREADS)
00074 {
00075 return viennacl::vector_expression<const viennacl::vandermonde_matrix<SCALARTYPE, ALIGNMENT>,
00076 const viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT>,
00077 viennacl::op_prod >(mat, vec);
00078 }
00079
00088 template<class SCALARTYPE, unsigned int ALIGNMENT, unsigned int VECTOR_ALIGNMENT>
00089 void prod_impl(const viennacl::vandermonde_matrix<SCALARTYPE, ALIGNMENT> & mat,
00090 const viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> & vec,
00091 viennacl::vector<SCALARTYPE, VECTOR_ALIGNMENT> & result)
00092 {
00093 assert(mat.size1() == result.size());
00094 assert(mat.size2() == vec.size());
00095
00096
00097 viennacl::linalg::kernels::fft<SCALARTYPE, 1>::init();
00098
00099 viennacl::ocl::kernel& kernel = viennacl::ocl::current_context()
00100 .get_program(viennacl::linalg::kernels::fft<SCALARTYPE, 1>::program_name())
00101 .get_kernel("vandermonde_prod");
00102 viennacl::ocl::enqueue(kernel(mat, vec, result, static_cast<cl_uint>(mat.size1())));
00103 }
00104
00105 }
00106
00107
00108
00113 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00114 template <unsigned int MAT_ALIGNMENT>
00115 viennacl::vector<SCALARTYPE, ALIGNMENT> &
00116 viennacl::vector<SCALARTYPE, ALIGNMENT>::operator=(const viennacl::vector_expression< const vandermonde_matrix<SCALARTYPE, MAT_ALIGNMENT>,
00117 const viennacl::vector<SCALARTYPE, ALIGNMENT>,
00118 viennacl::op_prod> & proxy)
00119 {
00120
00121 if (proxy.rhs().handle() == this->handle())
00122 {
00123 viennacl::vector<SCALARTYPE, ALIGNMENT> result(proxy.rhs().size());
00124 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
00125 *this = result;
00126 return *this;
00127 }
00128 else
00129 {
00130 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), *this);
00131 return *this;
00132 }
00133 return *this;
00134 }
00135
00136
00141 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00142 template <unsigned int MAT_ALIGNMENT>
00143 viennacl::vector<SCALARTYPE, ALIGNMENT> &
00144 viennacl::vector<SCALARTYPE, ALIGNMENT>::operator+=(const vector_expression< const vandermonde_matrix<SCALARTYPE, MAT_ALIGNMENT>,
00145 const vector<SCALARTYPE, ALIGNMENT>,
00146 op_prod> & proxy)
00147 {
00148 vector<SCALARTYPE, ALIGNMENT> result(proxy.lhs().size1());
00149 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
00150 *this += result;
00151 return *this;
00152 }
00153
00158 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00159 template <unsigned int MAT_ALIGNMENT>
00160 viennacl::vector<SCALARTYPE, ALIGNMENT> &
00161 viennacl::vector<SCALARTYPE, ALIGNMENT>::operator-=(const vector_expression< const vandermonde_matrix<SCALARTYPE, MAT_ALIGNMENT>,
00162 const vector<SCALARTYPE, ALIGNMENT>,
00163 op_prod> & proxy)
00164 {
00165 vector<SCALARTYPE, ALIGNMENT> result(proxy.get_lhs().size1());
00166 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
00167 *this -= result;
00168 return *this;
00169 }
00170
00171
00172
00177 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00178 template <unsigned int MAT_ALIGNMENT>
00179 viennacl::vector<SCALARTYPE, ALIGNMENT>
00180 viennacl::vector<SCALARTYPE, ALIGNMENT>::operator+(const vector_expression< const vandermonde_matrix<SCALARTYPE, MAT_ALIGNMENT>,
00181 const vector<SCALARTYPE, ALIGNMENT>,
00182 op_prod> & proxy)
00183 {
00184 assert(proxy.get_lhs().size1() == size());
00185 vector<SCALARTYPE, ALIGNMENT> result(size());
00186 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
00187 result += *this;
00188 return result;
00189 }
00190
00195 template <typename SCALARTYPE, unsigned int ALIGNMENT>
00196 template <unsigned int MAT_ALIGNMENT>
00197 viennacl::vector<SCALARTYPE, ALIGNMENT>
00198 viennacl::vector<SCALARTYPE, ALIGNMENT>::operator-(const vector_expression< const vandermonde_matrix<SCALARTYPE, MAT_ALIGNMENT>,
00199 const vector<SCALARTYPE, ALIGNMENT>,
00200 op_prod> & proxy)
00201 {
00202 assert(proxy.get_lhs().size1() == size());
00203 vector<SCALARTYPE, ALIGNMENT> result(size());
00204 viennacl::linalg::prod_impl(proxy.lhs(), proxy.rhs(), result);
00205 result = *this - result;
00206 return result;
00207 }
00208
00209 }
00210
00211
00212 #endif