ViennaCL - The Vienna Computing Library  1.2.0
tag_of.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_META_TAGOF_HPP_
2 #define VIENNACL_META_TAGOF_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2011, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8 
9  -----------------
10  ViennaCL - The Vienna Computing Library
11  -----------------
12 
13  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
14 
15  (A list of authors and contributors can be found in the PDF manual)
16 
17  License: MIT (X11), see file LICENSE in the base directory
18 ============================================================================= */
19 
20 
25 #ifdef VIENNACL_HAVE_UBLAS
26 #include <boost/numeric/ublas/matrix_sparse.hpp>
27 #include <boost/numeric/ublas/matrix.hpp>
28 #include <boost/numeric/ublas/vector.hpp>
29 #endif
30 
31 #ifdef VIENNACL_HAVE_EIGEN
32 #include <Eigen/Core>
33 #include <Eigen/Sparse>
34 #endif
35 
36 #ifdef VIENNACL_HAVE_MTL4
37 #include <boost/numeric/mtl/mtl.hpp>
38 #endif
39 
40 namespace viennacl
41 {
42 
43  // ----------------------------------------------------
44  // TAGS
45  //
46  struct tag_none {};
47  struct tag_mtl4 {};
48  struct tag_eigen {};
49  struct tag_ublas {};
50  struct tag_stl {};
51  struct tag_viennacl {};
52 
53  namespace traits
54  {
55  // ----------------------------------------------------
56  // GENERIC BASE
57  //
67  template< typename T, typename Active = void >
68  struct tag_of;
69 
70  template < typename Sequence, typename Active >
71  struct tag_of
72  {
74  };
75 
76  #ifdef VIENNACL_HAVE_MTL4
77  // ----------------------------------------------------
78  // MTL4
79  //
80  template <typename ScalarType>
81  struct tag_of< mtl::dense_vector<ScalarType> >
82  {
83  typedef viennacl::tag_mtl4 type;
84  };
85 
86  template <typename ScalarType>
87  struct tag_of< mtl::compressed2D<ScalarType> >
88  {
89  typedef viennacl::tag_mtl4 type;
90  };
91 
92  template <typename ScalarType, typename T>
93  struct tag_of< mtl::dense2D<ScalarType, T> >
94  {
95  typedef viennacl::tag_mtl4 type;
96  };
97  #endif
98 
99 
100  #ifdef VIENNACL_HAVE_EIGEN
101  // ----------------------------------------------------
102  // Eigen
103  //
104  template <>
105  struct tag_of< Eigen::VectorXf >
106  {
107  typedef viennacl::tag_eigen type;
108  };
109 
110  template <>
111  struct tag_of< Eigen::VectorXd >
112  {
113  typedef viennacl::tag_eigen type;
114  };
115 
116  template <>
117  struct tag_of< Eigen::MatrixXf >
118  {
119  typedef viennacl::tag_eigen type;
120  };
121 
122  template <>
123  struct tag_of< Eigen::MatrixXd >
124  {
125  typedef viennacl::tag_eigen type;
126  };
127 
128  template <typename ScalarType, int option>
129  struct tag_of< Eigen::SparseMatrix<ScalarType, option> >
130  {
131  typedef viennacl::tag_eigen type;
132  };
133 
134  #endif
135 
136  #ifdef VIENNACL_HAVE_UBLAS
137  // ----------------------------------------------------
138  // UBLAS
139  //
140  template< typename T >
141  struct tag_of< boost::numeric::ublas::vector<T> >
142  {
143  typedef viennacl::tag_ublas type;
144  };
145 
146  template< typename T >
147  struct tag_of< boost::numeric::ublas::matrix<T> >
148  {
149  typedef viennacl::tag_ublas type;
150  };
151 
152  template< typename T1, typename T2 >
153  struct tag_of< boost::numeric::ublas::matrix_unary2<T1,T2> >
154  {
155  typedef viennacl::tag_ublas type;
156  };
157 
158  template< typename T1, typename T2 >
159  struct tag_of< boost::numeric::ublas::compressed_matrix<T1,T2> >
160  {
161  typedef viennacl::tag_ublas type;
162  };
163 
164  #endif
165 
166  // ----------------------------------------------------
167  // STL types
168  //
169 
170  //vector
171  template< typename T, typename A >
172  struct tag_of< std::vector<T, A> >
173  {
175  };
176 
177  //dense matrix
178  template< typename T, typename A >
179  struct tag_of< std::vector<std::vector<T, A>, A> >
180  {
182  };
183 
184  //sparse matrix (vector of maps)
185  template< typename KEY, typename DATA, typename COMPARE, typename AMAP, typename AVEC>
186  struct tag_of< std::vector<std::map<KEY, DATA, COMPARE, AMAP>, AVEC> >
187  {
189  };
190 
191 
192  // ----------------------------------------------------
193  // VIENNACL
194  //
195  template< typename T, unsigned int alignment >
196  struct tag_of< viennacl::vector<T, alignment> >
197  {
199  };
200 
201  template< typename T, typename F, unsigned int alignment >
202  struct tag_of< viennacl::matrix<T, F, alignment> >
203  {
205  };
206 
207  template< typename T1, typename T2, typename OP >
208  struct tag_of< viennacl::matrix_expression<T1,T2,OP> >
209  {
211  };
212 
213  template< typename T >
214  struct tag_of< viennacl::matrix_range<T> >
215  {
217  };
218 
219  template< typename T, unsigned int I>
220  struct tag_of< viennacl::compressed_matrix<T,I> >
221  {
223  };
224 
225  template< typename T, unsigned int I>
226  struct tag_of< viennacl::coordinate_matrix<T,I> >
227  {
229  };
230 
231  template< typename T, unsigned int I>
232  struct tag_of< viennacl::circulant_matrix<T,I> >
233  {
235  };
236 
237  template< typename T, unsigned int I>
238  struct tag_of< viennacl::hankel_matrix<T,I> >
239  {
241  };
242 
243  template< typename T, unsigned int I>
244  struct tag_of< viennacl::toeplitz_matrix<T,I> >
245  {
247  };
248 
249  template< typename T, unsigned int I>
250  struct tag_of< viennacl::vandermonde_matrix<T,I> >
251  {
253  };
254 
255 
256  // ----------------------------------------------------
257  } // end namespace traits
258 
259 
264  template <typename Tag>
265  struct is_mtl4
266  {
267  enum { value = false };
268  };
269 
270  template <>
271  struct is_mtl4< viennacl::tag_mtl4 >
272  {
273  enum { value = true };
274  };
275 
280  template <typename Tag>
281  struct is_eigen
282  {
283  enum { value = false };
284  };
285 
286  template <>
287  struct is_eigen< viennacl::tag_eigen >
288  {
289  enum { value = true };
290  };
291 
292 
297  template <typename Tag>
298  struct is_ublas
299  {
300  enum { value = false };
301  };
302 
303  template <>
304  struct is_ublas< viennacl::tag_ublas >
305  {
306  enum { value = true };
307  };
308 
313  template <typename Tag>
314  struct is_stl
315  {
316  enum { value = false };
317  };
318 
319  template <>
320  struct is_stl< viennacl::tag_stl >
321  {
322  enum { value = true };
323  };
324 
325 
330  template <typename Tag>
331  struct is_viennacl
332  {
333  enum { value = false };
334  };
335 
336  template <>
337  struct is_viennacl< viennacl::tag_viennacl >
338  {
339  enum { value = true };
340  };
341 
342 } // end namespace viennacl
343 
344 #endif