ViennaCL - The Vienna Computing Library  1.6.2
Free open-source GPU-accelerated linear algebra and solver library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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, typename I>
251  struct tag_of< viennacl::sliced_ell_matrix<T,I> >
252  {
253  typedef viennacl::tag_viennacl type;
254  };
255 
256 
257  template< typename T, unsigned int I>
258  struct tag_of< viennacl::hyb_matrix<T,I> >
259  {
260  typedef viennacl::tag_viennacl type;
261  };
262 
263  template< typename T, unsigned int I>
264  struct tag_of< viennacl::circulant_matrix<T,I> >
265  {
266  typedef viennacl::tag_viennacl type;
267  };
268 
269  template< typename T, unsigned int I>
270  struct tag_of< viennacl::hankel_matrix<T,I> >
271  {
272  typedef viennacl::tag_viennacl type;
273  };
274 
275  template< typename T, unsigned int I>
276  struct tag_of< viennacl::toeplitz_matrix<T,I> >
277  {
278  typedef viennacl::tag_viennacl type;
279  };
280 
281  template< typename T, unsigned int I>
282  struct tag_of< viennacl::vandermonde_matrix<T,I> >
283  {
284  typedef viennacl::tag_viennacl type;
285  };
288  // ----------------------------------------------------
289 } // end namespace traits
290 
291 
296 template<typename Tag>
297 struct is_mtl4
298 {
299  enum { value = false };
300 };
301 
303 template<>
304 struct is_mtl4< viennacl::tag_mtl4 >
305 {
306  enum { value = true };
307 };
314 template<typename Tag>
315 struct is_eigen
316 {
317  enum { value = false };
318 };
319 
321 template<>
322 struct is_eigen< viennacl::tag_eigen >
323 {
324  enum { value = true };
325 };
333 template<typename Tag>
334 struct is_ublas
335 {
336  enum { value = false };
337 };
338 
340 template<>
341 struct is_ublas< viennacl::tag_ublas >
342 {
343  enum { value = true };
344 };
351 template<typename Tag>
352 struct is_stl
353 {
354  enum { value = false };
355 };
356 
358 template<>
359 struct is_stl< viennacl::tag_stl >
360 {
361  enum { value = true };
362 };
370 template<typename Tag>
372 {
373  enum { value = false };
374 };
375 
377 template<>
378 struct is_viennacl< viennacl::tag_viennacl >
379 {
380  enum { value = true };
381 };
384 } // end namespace viennacl
385 
386 #endif
Meta function which checks whether a tag is tag_mtl4.
Definition: tag_of.hpp:297
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:352
Meta function which checks whether a tag is tag_ublas.
Definition: tag_of.hpp:334
A tag class for identifying 'unknown' types.
Definition: tag_of.hpp:53
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:371
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
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:315