31 #ifndef ELEMENTWISESQUARE_IMPL_H_
32 #define ELEMENTWISESQUARE_IMPL_H_
57 namespace implementation
65 template <enum Backend,
class Matrix>
75 static Matrix
compute(Matrix m);
91 template <
class Matrix>
95 typedef typename Matrix::Scalar
T;
142 r = m.array().template square();
156 Eigen::Block< Eigen::Map<MatrixXt> > m = map.block(
157 b.m_row_begin, b.m_col_begin,
158 b.m_row_size, b.m_col_size);
160 r = m.array().template square();
164 #endif // HAVE_EIGEN3
170 template <
class Matrix>
171 struct elementwise_square<Backend::VIENNACL,Matrix>
174 typedef typename Matrix::Scalar T;
177 typedef CGPUMatrix<T> ReturnType;
186 static CGPUMatrix<T>
compute(CGPUMatrix<T> m)
188 CGPUMatrix<T> result(m.num_rows, m.num_cols);
200 static CGPUMatrix<T>
compute(Block<CGPUMatrix<T> > b)
202 SG_SERROR(
"The operation elementwise_square() on a matrix block is currently not supported\n");
203 return CGPUMatrix<T>();
212 static void compute(CGPUMatrix<T> mat, CGPUMatrix<T> result)
214 const std::string operation =
"return element*element;";
216 std::string kernel_name =
"elementwise_square_" + ocl::get_type_string<T>();
217 viennacl::ocl::kernel& kernel =
218 ocl::generate_single_arg_elementwise_kernel<T>(kernel_name, operation);
220 kernel.global_work_size(0, ocl::align_to_multiple_1d(mat.num_rows*mat.num_cols));
222 viennacl::ocl::enqueue(kernel(mat.vcl_matrix(),
223 cl_int(mat.num_rows*mat.num_cols), cl_int(mat.offset),
224 result.vcl_matrix(), cl_int(result.offset)));
233 static void compute(Block<SGMatrix<T> > b, SGMatrix<T> result)
235 SG_SERROR(
"The operation elementwise_square() on a matrix block is currently not supported\n");
239 #endif // HAVE_VIENNACL
246 #endif // ELEMENTWISESQUARE_IMPL_H_
Generic class square which provides a static compute method. This class is specialized for different ...
static SGMatrix< T > compute(SGMatrix< T > m)
Generic class Block which wraps a matrix class and contains block specific information, providing a uniform way to deal with matrix blocks for all supported backend matrices.
all of classes and functions are contained in the shogun namespace
static void compute(Block< SGMatrix< T > > b, SGMatrix< T > result)
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > MatrixXt
static void compute(SGMatrix< T > mat, SGMatrix< T > result)
static SGMatrix< T > compute(Block< SGMatrix< T > > b)
static Matrix compute(Matrix m)