ViennaCL - The Vienna Computing Library  1.5.2
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-2014, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the PDF manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
21 
26 #include <vector>
27 #include <map>
28 
29 #include "viennacl/forwards.h"
30 
31 #ifdef VIENNACL_WITH_UBLAS
32 #include <boost/numeric/ublas/matrix_sparse.hpp>
33 #include <boost/numeric/ublas/matrix.hpp>
34 #include <boost/numeric/ublas/vector.hpp>
35 #endif
36 
37 #ifdef VIENNACL_WITH_EIGEN
38 #include <Eigen/Core>
39 #include <Eigen/Sparse>
40 #endif
41 
42 #ifdef VIENNACL_WITH_MTL4
43 #include <boost/numeric/mtl/mtl.hpp>
44 #endif
45 
46 namespace viennacl
47 {
48 
49  // ----------------------------------------------------
50  // TAGS
51  //
53  struct tag_none {};
55  struct tag_mtl4 {};
57  struct tag_eigen {};
59  struct tag_ublas {};
61  struct tag_stl {};
63  struct tag_viennacl {};
64 
65  namespace traits
66  {
67  // ----------------------------------------------------
68  // GENERIC BASE
69  //
79  template< typename T, typename Active = void >
80  struct tag_of;
81 
83  template < typename Sequence, typename Active >
84  struct tag_of
85  {
86  typedef viennacl::tag_none type;
87  };
88 
89  #ifdef VIENNACL_WITH_MTL4
90  // ----------------------------------------------------
91  // MTL4
92  //
93  template <typename ScalarType>
94  struct tag_of< mtl::dense_vector<ScalarType> >
95  {
96  typedef viennacl::tag_mtl4 type;
97  };
98 
99  template <typename ScalarType>
100  struct tag_of< mtl::compressed2D<ScalarType> >
101  {
102  typedef viennacl::tag_mtl4 type;
103  };
104 
105  template <typename ScalarType, typename T>
106  struct tag_of< mtl::dense2D<ScalarType, T> >
107  {
108  typedef viennacl::tag_mtl4 type;
109  };
110  #endif
111 
112 
113  #ifdef VIENNACL_WITH_EIGEN
114  // ----------------------------------------------------
115  // Eigen
116  //
117  template <>
118  struct tag_of< Eigen::VectorXf >
119  {
120  typedef viennacl::tag_eigen type;
121  };
122 
123  template <>
124  struct tag_of< Eigen::VectorXd >
125  {
126  typedef viennacl::tag_eigen type;
127  };
128 
129  template <>
130  struct tag_of< Eigen::MatrixXf >
131  {
132  typedef viennacl::tag_eigen type;
133  };
134 
135  template <>
136  struct tag_of< Eigen::MatrixXd >
137  {
138  typedef viennacl::tag_eigen type;
139  };
140 
141  template <typename ScalarType, int option>
142  struct tag_of< Eigen::SparseMatrix<ScalarType, option> >
143  {
144  typedef viennacl::tag_eigen type;
145  };
146 
147  #endif
148 
149  #ifdef VIENNACL_WITH_UBLAS
150  // ----------------------------------------------------
151  // UBLAS
152  //
153  template< typename T >
154  struct tag_of< boost::numeric::ublas::vector<T> >
155  {
156  typedef viennacl::tag_ublas type;
157  };
158 
159  template< typename T >
160  struct tag_of< boost::numeric::ublas::matrix<T> >
161  {
162  typedef viennacl::tag_ublas type;
163  };
164 
165  template< typename T1, typename T2 >
166  struct tag_of< boost::numeric::ublas::matrix_unary2<T1,T2> >
167  {
168  typedef viennacl::tag_ublas type;
169  };
170 
171  template< typename T1, typename T2 >
172  struct tag_of< boost::numeric::ublas::compressed_matrix<T1,T2> >
173  {
174  typedef viennacl::tag_ublas type;
175  };
176 
177  #endif
178 
179  // ----------------------------------------------------
180  // STL types
181  //
182 
183  //vector
184  template< typename T, typename A >
185  struct tag_of< std::vector<T, A> >
186  {
187  typedef viennacl::tag_stl type;
188  };
189 
190  //dense matrix
191  template< typename T, typename A >
192  struct tag_of< std::vector<std::vector<T, A>, A> >
193  {
194  typedef viennacl::tag_stl type;
195  };
196 
197  //sparse matrix (vector of maps)
198  template< typename KEY, typename DATA, typename COMPARE, typename AMAP, typename AVEC>
199  struct tag_of< std::vector<std::map<KEY, DATA, COMPARE, AMAP>, AVEC> >
200  {
201  typedef viennacl::tag_stl type;
202  };
203 
204 
205  // ----------------------------------------------------
206  // VIENNACL
207  //
208  template< typename T, unsigned int alignment >
209  struct tag_of< viennacl::vector<T, alignment> >
210  {
211  typedef viennacl::tag_viennacl type;
212  };
213 
214  template< typename T, typename F, unsigned int alignment >
215  struct tag_of< viennacl::matrix<T, F, alignment> >
216  {
217  typedef viennacl::tag_viennacl type;
218  };
219 
220  template< typename T1, typename T2, typename OP >
221  struct tag_of< viennacl::matrix_expression<T1,T2,OP> >
222  {
223  typedef viennacl::tag_viennacl type;
224  };
225 
226  template< typename T >
227  struct tag_of< viennacl::matrix_range<T> >
228  {
229  typedef viennacl::tag_viennacl type;
230  };
231 
232  template< typename T, unsigned int I>
233  struct tag_of< viennacl::compressed_matrix<T,I> >
234  {
235  typedef viennacl::tag_viennacl type;
236  };
237 
238  template< typename T, unsigned int I>
239  struct tag_of< viennacl::coordinate_matrix<T,I> >
240  {
241  typedef viennacl::tag_viennacl type;
242  };
243 
244  template< typename T, unsigned int I>
245  struct tag_of< viennacl::ell_matrix<T,I> >
246  {
247  typedef viennacl::tag_viennacl type;
248  };
249 
250  template< typename T, unsigned int I>
251  struct tag_of< viennacl::hyb_matrix<T,I> >
252  {
253  typedef viennacl::tag_viennacl type;
254  };
255 
256  template< typename T, unsigned int I>
257  struct tag_of< viennacl::circulant_matrix<T,I> >
258  {
259  typedef viennacl::tag_viennacl type;
260  };
261 
262  template< typename T, unsigned int I>
263  struct tag_of< viennacl::hankel_matrix<T,I> >
264  {
265  typedef viennacl::tag_viennacl type;
266  };
267 
268  template< typename T, unsigned int I>
269  struct tag_of< viennacl::toeplitz_matrix<T,I> >
270  {
271  typedef viennacl::tag_viennacl type;
272  };
273 
274  template< typename T, unsigned int I>
275  struct tag_of< viennacl::vandermonde_matrix<T,I> >
276  {
277  typedef viennacl::tag_viennacl type;
278  };
281  // ----------------------------------------------------
282  } // end namespace traits
283 
284 
289  template <typename Tag>
290  struct is_mtl4
291  {
292  enum { value = false };
293  };
294 
296  template <>
297  struct is_mtl4< viennacl::tag_mtl4 >
298  {
299  enum { value = true };
300  };
307  template <typename Tag>
308  struct is_eigen
309  {
310  enum { value = false };
311  };
312 
314  template <>
315  struct is_eigen< viennacl::tag_eigen >
316  {
317  enum { value = true };
318  };
326  template <typename Tag>
327  struct is_ublas
328  {
329  enum { value = false };
330  };
331 
333  template <>
334  struct is_ublas< viennacl::tag_ublas >
335  {
336  enum { value = true };
337  };
344  template <typename Tag>
345  struct is_stl
346  {
347  enum { value = false };
348  };
349 
351  template <>
352  struct is_stl< viennacl::tag_stl >
353  {
354  enum { value = true };
355  };
363  template <typename Tag>
364  struct is_viennacl
365  {
366  enum { value = false };
367  };
368 
370  template <>
371  struct is_viennacl< viennacl::tag_viennacl >
372  {
373  enum { value = true };
374  };
377 } // end namespace viennacl
378 
379 #endif
Meta function which checks whether a tag is tag_mtl4.
Definition: tag_of.hpp:290
Generic base for wrapping other linear algebra packages.
Definition: tag_of.hpp:80
Meta function which checks whether a tag is tag_ublas.
Definition: tag_of.hpp:345
Meta function which checks whether a tag is tag_ublas.
Definition: tag_of.hpp:327
A tag class for identifying 'unknown' types.
Definition: tag_of.hpp:53
Definition: tag_of.hpp:329
Definition: tag_of.hpp:347
Definition: tag_of.hpp:310
This file provides the forward declarations for the main types used within ViennaCL.
A tag class for identifying types from uBLAS.
Definition: tag_of.hpp:59
Meta function which checks whether a tag is tag_viennacl.
Definition: tag_of.hpp:364
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:29
Definition: tag_of.hpp:366
A tag class for identifying types from ViennaCL.
Definition: tag_of.hpp:63
A tag class for identifying types from the C++ STL.
Definition: tag_of.hpp:61
Definition: tag_of.hpp:292
A tag class for identifying types from Eigen.
Definition: tag_of.hpp:57
A tag class for identifying types from MTL4.
Definition: tag_of.hpp:55
Meta function which checks whether a tag is tag_eigen.
Definition: tag_of.hpp:308