traits.hpp
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Traits to obtain memory and storage sizes easily from expression templates
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 
31 #ifndef SHARK_LINALG_BLAS_KERNELS_TRAITS_HPP
32 #define SHARK_LINALG_BLAS_KERNELS_TRAITS_HPP
33 
34 #include "../detail/traits.hpp"
35 
36 namespace shark {namespace blas {namespace bindings{ namespace traits {
37 
38 ///////////////Vector Traits//////////////////////////
39 
40 template <typename V>
41 typename V::difference_type stride(vector_expression<V> const&v) {
42  return v().stride();
43 }
44 
45 template <typename V>
46 typename pointer<V>::type storage(vector_expression<V>& v) {
47  return v().storage();
48 }
49 template <typename V>
50 typename pointer<V const>::type storage(vector_expression<V> const& v) {
51  return v().storage();
52 }
53 
54 //////////////////Matrix Traits/////////////////////
55 template <typename M>
56 typename M::difference_type stride1(matrix_expression<M> const& m) {
57  return m().stride1();
58 }
59 template <typename M>
60 typename M::difference_type stride2(matrix_expression<M> const& m) {
61  return m().stride2();
62 }
63 
64 template <typename M>
65 typename pointer<M>::type storage(matrix_expression<M>& m) {
66  return m().storage();
67 }
68 template <typename M>
69 typename pointer<M const>::type storage(matrix_expression<M> const& m) {
70  return m().storage();
71 }
72 
73 template <typename M>
74 typename M::difference_type leading_dimension(matrix_expression<M> const& m) {
75  return M::orientation::index_M(stride1(m),stride2(m));
76 }
77 
78 template<class M1, class M2>
79 bool same_orientation(matrix_expression<M1> const& m1, matrix_expression<M2> const& m2){
80  return boost::is_same<typename M1::orientation,typename M2::orientation>::value;
81 }
82 
83 
84 }}}}
85 #endif