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 <>
template <
class Matrix>
94 typedef typename Matrix::Scalar
T;
138 r = m.array().template square();
152 Eigen::Block< Eigen::Map<MatrixXt> > m = map.block(
153 b.m_row_begin, b.m_col_begin,
154 b.m_row_size, b.m_col_size);
156 r = m.array().template square();
160 #endif // HAVE_EIGEN3
166 template <>
template <
class Matrix>
169 typedef typename Matrix::Scalar T;
170 typedef CGPUMatrix<T> ReturnType;
180 static CGPUMatrix<T>
compute(CGPUMatrix<T> m)
182 CGPUMatrix<T> result(m.num_rows, m.num_cols);
194 static CGPUMatrix<T>
compute(Block<CGPUMatrix<T> > b)
196 SG_SERROR(
"The operation elementwise_square() on a matrix block is currently not supported\n");
197 return CGPUMatrix<T>();
206 static void compute(CGPUMatrix<T> mat, CGPUMatrix<T> result)
208 const std::string operation =
"return element*element;";
210 std::string kernel_name =
"elementwise_square_" + ocl::get_type_string<T>();
211 viennacl::ocl::kernel& kernel =
212 ocl::generate_single_arg_elementwise_kernel<T>(kernel_name, operation);
214 kernel.global_work_size(0, ocl::align_to_multiple_1d(mat.num_rows*mat.num_cols));
216 viennacl::ocl::enqueue(kernel(mat.vcl_matrix(),
217 cl_int(mat.num_rows*mat.num_cols), cl_int(mat.offset),
218 result.vcl_matrix(), cl_int(result.offset)));
227 static void compute(Block<SGMatrix<T> > b, SGMatrix<T> result)
229 SG_SERROR(
"The operation elementwise_square() on a matrix block is currently not supported\n");
233 #endif // HAVE_VIENNACL
240 #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.
implementation::elementwise_square< backend, Matrix >::ReturnType elementwise_square(Matrix m)
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)