31 #ifndef ELEMENTWISESQUARE_IMPL_H_
32 #define ELEMENTWISESQUARE_IMPL_H_
55 namespace implementation
63 template <enum Backend,
class Matrix>
73 static Matrix
compute(Matrix m);
88 template <
class Matrix>
92 typedef typename Matrix::Scalar
T;
139 r = m.array().template square();
153 Eigen::Block< Eigen::Map<MatrixXt> > m = map.block(
154 b.m_row_begin, b.m_col_begin,
155 b.m_row_size, b.m_col_size);
157 r = m.array().template square();
166 template <
class Matrix>
167 struct elementwise_square<Backend::VIENNACL,Matrix>
170 typedef typename Matrix::Scalar T;
173 typedef CGPUMatrix<T> ReturnType;
182 static CGPUMatrix<T>
compute(CGPUMatrix<T> m)
184 CGPUMatrix<T> result(m.num_rows, m.num_cols);
196 static CGPUMatrix<T>
compute(Block<CGPUMatrix<T> > b)
198 SG_SERROR(
"The operation elementwise_square() on a matrix block is currently not supported\n");
199 return CGPUMatrix<T>();
208 static void compute(CGPUMatrix<T> mat, CGPUMatrix<T> result)
210 const std::string operation =
"return element*element;";
212 std::string kernel_name =
"elementwise_square_" + ocl::get_type_string<T>();
213 viennacl::ocl::kernel& kernel =
214 ocl::generate_single_arg_elementwise_kernel<T>(kernel_name, operation);
216 kernel.global_work_size(0, ocl::align_to_multiple_1d(mat.num_rows*mat.num_cols));
218 viennacl::ocl::enqueue(kernel(mat.vcl_matrix(),
219 cl_int(mat.num_rows*mat.num_cols), cl_int(mat.offset),
220 result.vcl_matrix(), cl_int(result.offset)));
229 static void compute(Block<SGMatrix<T> > b, SGMatrix<T> result)
231 SG_SERROR(
"The operation elementwise_square() on a matrix block is currently not supported\n");
235 #endif // HAVE_VIENNACL
242 #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)