SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 #include <shogun/io/SGIO.h>
38 
40 
41 #ifdef HAVE_VIENNACL
42 #include <shogun/lib/GPUVector.h>
43 #include <viennacl/linalg/inner_prod.hpp>
44 #endif // HAVE_VIENNACL
45 
46 namespace shogun
47 {
48 
49 namespace linalg
50 {
51 
55 namespace implementation
56 {
57 
63 template <enum Backend, class Vector>
64 struct dot
65 {
67  typedef typename Vector::Scalar T;
68 
77  static T compute(Vector a, Vector b);
78 };
79 
83 template <class Vector>
84 struct dot<Backend::EIGEN3, Vector>
85 {
87  typedef typename Vector::Scalar T;
88 
98  {
99  typedef Eigen::Matrix<T, Eigen::Dynamic, 1> VectorXt;
100  Eigen::Map<VectorXt> vec_a = a;
101  Eigen::Map<VectorXt> vec_b = b;
102  return vec_a.dot(vec_b);
103  }
104 };
105 
106 #ifdef HAVE_VIENNACL
107 
110 template <class Vector>
111 struct dot<Backend::VIENNACL, Vector>
112 {
114  typedef typename Vector::Scalar T;
115 
124  static T compute(shogun::CGPUVector<T> a, shogun::CGPUVector<T> b)
125  {
126  return viennacl::linalg::inner_prod(a.vcl_vector(), b.vcl_vector());
127  }
128 };
129 #endif // HAVE_VIENNACL
130 
131 }
132 
133 }
134 
135 }
136 #endif // DOT_IMPL_H_
Vector::Scalar dot(Vector a, Vector b)
Definition: Redux.h:58
Generic class dot which provides a static compute method. This class is specialized for different typ...
Definition: Dot.h:64
static T compute(shogun::SGVector< T > a, shogun::SGVector< T > b)
Definition: Dot.h:97
shogun vector
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