SHOGUN  4.0.0
Dot.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2014 Soumyajit De
4  * Written (w) 2014 Khaled Nasr
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * The views and conclusions contained in the software and documentation are those
28  * of the authors and should not be interpreted as representing official policies,
29  * either expressed or implied, of the Shogun Development Team.
30  */
31 
32 #ifndef DOT_IMPL_H_
33 #define DOT_IMPL_H_
34 
35 #include <shogun/lib/config.h>
36 #include <shogun/lib/SGVector.h>
37 
38 #ifdef HAVE_EIGEN3
40 #endif // HAVE_EIGEN3
41 
42 #ifdef HAVE_VIENNACL
43 #include <shogun/lib/GPUVector.h>
44 #include <viennacl/linalg/inner_prod.hpp>
45 #endif // HAVE_VIENNACL
46 
47 namespace shogun
48 {
49 
50 namespace linalg
51 {
52 
56 namespace implementation
57 {
58 
64 template <enum Backend, class Vector>
65 struct dot
66 {
68  typedef typename Vector::Scalar T;
69 
78  static T compute(Vector a, Vector b);
79 };
80 
81 #ifdef HAVE_EIGEN3
82 
85 template <> template <class Vector>
86 struct dot<Backend::EIGEN3, Vector>
87 {
88  typedef typename Vector::Scalar T;
89 
99  {
100  typedef Eigen::Matrix<T, Eigen::Dynamic, 1> VectorXt;
101  Eigen::Map<VectorXt> vec_a = a;
102  Eigen::Map<VectorXt> vec_b = b;
103  return vec_a.dot(vec_b);
104  }
105 };
106 #endif // HAVE_EIGEN3
107 
108 #ifdef HAVE_VIENNACL
109 
112 template <> template <class Vector>
113 struct dot<Backend::VIENNACL, Vector>
114 {
115  typedef typename Vector::Scalar T;
116 
125  static T compute(shogun::CGPUVector<T> a, shogun::CGPUVector<T> b)
126  {
127  return viennacl::linalg::inner_prod(a.vcl_vector(), b.vcl_vector());
128  }
129 };
130 #endif // HAVE_VIENNACL
131 
132 }
133 
134 }
135 
136 }
137 #endif // DOT_IMPL_H_
Vector::Scalar dot(Vector a, Vector b)
Definition: Redux.h:56
Generic class dot which provides a static compute method. This class is specialized for different typ...
Definition: Dot.h:65
static T compute(shogun::SGVector< T > a, shogun::SGVector< T > b)
Definition: Dot.h:98
shogun vector
Definition: Parameter.h:28
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
static T compute(Vector a, Vector b)

SHOGUN Machine Learning Toolbox - Documentation