dot.hpp
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief dot-product of vectors
5  *
6  * \author O. Krause
7  * \date 2013
8  *
9  *
10  * \par Copyright 1995-2015 Shark Development Team
11  *
12  * <BR><HR>
13  * This file is part of Shark.
14  * <http://image.diku.dk/shark/>
15  *
16  * Shark is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU Lesser General Public License as published
18  * by the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * Shark is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public License
27  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
28  *
29  */
30 #ifndef SHARK_LINALG_BLAS_KERNELS_DOT_HPP
31 #define SHARK_LINALG_BLAS_KERNELS_DOT_HPP
32 
33 #include "default/dot.hpp"
34 
35 //~ #ifdef SHARK_USE_CBLAS
36 //~ #include "cblas/dot.hpp" // not faster in many cases, the compiler optimizes quite well.
37 //~ #else
38 // if no bindings are included, we have to provide the default has_optimized_dot
39 // otherwise the binding will take care of this
40 namespace shark { namespace blas { namespace bindings{
41 template<class V1, class V2,class result_type>
42 struct has_optimized_dot
43 : public boost::mpl::false_{};
44 }}}
45 //~ #endif
46 
47 namespace shark { namespace blas {namespace kernels{
48 
49 ///\brief Well known dot-product r=<e1,e2>=sum_i e1_i*e2_i.
50 ///
51 /// If bindings are included and the vector combination allows for a specific binding
52 /// to be applied, the binding is called automatically from {binding}/dot.h
53 /// otherwise default/dot.h is used which is fully implemented for all dense/sparse combinations.
54 /// if a combination is optimized, bindings::has_optimized_dot<E1,E2,R>::type evaluates to boost::mpl::true_
55 /// The kernels themselves are implemented in blas::bindings::dot.
56 template<class E1, class E2,class result_type>
57 void dot(
58  vector_expression<E1> const& e1,
59  vector_expression<E2> const& e2,
60  result_type& result
61 ) {
62  SIZE_CHECK(e1().size() == e2().size());
63 
65  e1, e2,result,
66  typename bindings::has_optimized_dot<E1,E2,result_type>::type()
67  );
68 }
69 
70 }}}
71 #endif