SHOGUN  4.0.0
ElementwiseProduct.h
浏览该文件的文档.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2014 Khaled Nasr
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are those
27  * of the authors and should not be interpreted as representing official policies,
28  * either expressed or implied, of the Shogun Development Team.
29  */
30 
31 #ifndef ELEMENTWISE_PRODUCT_IMPL_H_
32 #define ELEMENTWISE_PRODUCT_IMPL_H_
33 
34 #include <shogun/lib/config.h>
35 #include <shogun/lib/SGMatrix.h>
36 
37 #ifdef HAVE_EIGEN3
39 #endif // HAVE_EIGEN3
40 
41 #ifdef HAVE_VIENNACL
42 #include <shogun/lib/GPUMatrix.h>
43 #include <viennacl/linalg/matrix_operations.hpp>
44 #endif // HAVE_VIENNACL
45 
46 namespace shogun
47 {
48 
49 namespace linalg
50 {
51 
52 namespace implementation
53 {
54 
58 template <enum Backend, class Matrix>
60 {
62  typedef typename Matrix::Scalar T;
63 
65  static void compute(Matrix A, Matrix B, Matrix C);
66 };
67 
68 #ifdef HAVE_EIGEN3
69 
71 template <> template <class Matrix>
72 struct elementwise_product<Backend::EIGEN3, Matrix>
73 {
74  typedef typename Matrix::Scalar T;
77 
80  {
81  Eigen::Map<MatrixXt> A_eig = A;
82  Eigen::Map<MatrixXt> B_eig = B;
83  Eigen::Map<MatrixXt> C_eig = C;
84 
85  C_eig = A_eig.array() * B_eig.array();
86  }
87 };
88 #endif // HAVE_EIGEN3
89 
90 #ifdef HAVE_VIENNACL
91 
93 template <> template <class Matrix>
94 struct elementwise_product<Backend::VIENNACL, Matrix>
95 {
96  typedef typename Matrix::Scalar T;
97 
99  static void compute(CGPUMatrix<T> A, CGPUMatrix<T> B, CGPUMatrix<T> C)
100  {
101  C.vcl_matrix() = viennacl::linalg::element_prod(A.vcl_matrix(), B.vcl_matrix());
102  }
103 };
104 
105 #endif // HAVE_VIENNACL
106 
107 }
108 
109 }
110 
111 }
112 #endif // ELEMENTWISE_PRODUCT_IMPL_H_
static void compute(Matrix A, Matrix B, Matrix C)
void elementwise_product(Matrix A, Matrix B, Matrix C)
Definition: Core.h:90
shogun matrix
Definition: Parameter.h:26
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
static void compute(SGMatrix< T > A, SGMatrix< T > B, SGMatrix< T > C)

SHOGUN 机器学习工具包 - 项目文档