ViennaCL - The Vienna Computing Library  1.5.0
viennacl/meta/tag_of.hpp
Go to the documentation of this file.
00001 #ifndef VIENNACL_META_TAGOF_HPP_
00002 #define VIENNACL_META_TAGOF_HPP_
00003 
00004 /* =========================================================================
00005    Copyright (c) 2010-2013, Institute for Microelectronics,
00006                             Institute for Analysis and Scientific Computing,
00007                             TU Wien.
00008    Portions of this software are copyright by UChicago Argonne, LLC.
00009 
00010                             -----------------
00011                   ViennaCL - The Vienna Computing Library
00012                             -----------------
00013 
00014    Project Head:    Karl Rupp                   rupp@iue.tuwien.ac.at
00015 
00016    (A list of authors and contributors can be found in the PDF manual)
00017 
00018    License:         MIT (X11), see file LICENSE in the base directory
00019 ============================================================================= */
00020 
00021 
00026 #include <vector>
00027 #include <map>
00028 
00029 #include "viennacl/forwards.h"
00030 
00031 #ifdef VIENNACL_WITH_UBLAS
00032 #include <boost/numeric/ublas/matrix_sparse.hpp>
00033 #include <boost/numeric/ublas/matrix.hpp>
00034 #include <boost/numeric/ublas/vector.hpp>
00035 #endif
00036 
00037 #ifdef VIENNACL_WITH_EIGEN
00038 #include <Eigen/Core>
00039 #include <Eigen/Sparse>
00040 #endif
00041 
00042 #ifdef VIENNACL_WITH_MTL4
00043 #include <boost/numeric/mtl/mtl.hpp>
00044 #endif
00045 
00046 namespace viennacl
00047 {
00048 
00049   // ----------------------------------------------------
00050   // TAGS
00051   //
00053   struct tag_none     {};
00055   struct tag_mtl4     {};
00057   struct tag_eigen    {};
00059   struct tag_ublas    {};
00061   struct tag_stl      {};
00063   struct tag_viennacl {};
00064 
00065   namespace traits
00066   {
00067     // ----------------------------------------------------
00068     // GENERIC BASE
00069     //
00079     template< typename T, typename Active = void >
00080     struct tag_of;
00081 
00083     template < typename Sequence, typename Active >
00084     struct tag_of
00085     {
00086       typedef viennacl::tag_none  type;
00087     };
00088 
00089     #ifdef VIENNACL_WITH_MTL4
00090     // ----------------------------------------------------
00091     // MTL4
00092     //
00093     template <typename ScalarType>
00094     struct tag_of< mtl::dense_vector<ScalarType> >
00095     {
00096       typedef viennacl::tag_mtl4  type;
00097     };
00098 
00099     template <typename ScalarType>
00100     struct tag_of< mtl::compressed2D<ScalarType> >
00101     {
00102       typedef viennacl::tag_mtl4  type;
00103     };
00104 
00105     template <typename ScalarType, typename T>
00106     struct tag_of< mtl::dense2D<ScalarType, T> >
00107     {
00108       typedef viennacl::tag_mtl4  type;
00109     };
00110     #endif
00111 
00112 
00113     #ifdef VIENNACL_WITH_EIGEN
00114     // ----------------------------------------------------
00115     // Eigen
00116     //
00117     template <>
00118     struct tag_of< Eigen::VectorXf >
00119     {
00120       typedef viennacl::tag_eigen  type;
00121     };
00122 
00123     template <>
00124     struct tag_of< Eigen::VectorXd >
00125     {
00126       typedef viennacl::tag_eigen  type;
00127     };
00128 
00129     template <>
00130     struct tag_of< Eigen::MatrixXf >
00131     {
00132       typedef viennacl::tag_eigen  type;
00133     };
00134 
00135     template <>
00136     struct tag_of< Eigen::MatrixXd >
00137     {
00138       typedef viennacl::tag_eigen  type;
00139     };
00140 
00141     template <typename ScalarType, int option>
00142     struct tag_of< Eigen::SparseMatrix<ScalarType, option> >
00143     {
00144       typedef viennacl::tag_eigen  type;
00145     };
00146 
00147     #endif
00148 
00149     #ifdef VIENNACL_WITH_UBLAS
00150     // ----------------------------------------------------
00151     // UBLAS
00152     //
00153     template< typename T >
00154     struct tag_of< boost::numeric::ublas::vector<T> >
00155     {
00156       typedef viennacl::tag_ublas  type;
00157     };
00158 
00159     template< typename T >
00160     struct tag_of< boost::numeric::ublas::matrix<T> >
00161     {
00162       typedef viennacl::tag_ublas  type;
00163     };
00164 
00165     template< typename T1, typename T2 >
00166     struct tag_of< boost::numeric::ublas::matrix_unary2<T1,T2> >
00167     {
00168       typedef viennacl::tag_ublas  type;
00169     };
00170 
00171     template< typename T1, typename T2 >
00172     struct tag_of< boost::numeric::ublas::compressed_matrix<T1,T2> >
00173     {
00174       typedef viennacl::tag_ublas  type;
00175     };
00176 
00177     #endif
00178 
00179     // ----------------------------------------------------
00180     // STL types
00181     //
00182 
00183     //vector
00184     template< typename T, typename A >
00185     struct tag_of< std::vector<T, A> >
00186     {
00187       typedef viennacl::tag_stl  type;
00188     };
00189 
00190     //dense matrix
00191     template< typename T, typename A >
00192     struct tag_of< std::vector<std::vector<T, A>, A> >
00193     {
00194       typedef viennacl::tag_stl  type;
00195     };
00196 
00197     //sparse matrix (vector of maps)
00198     template< typename KEY, typename DATA, typename COMPARE, typename AMAP, typename AVEC>
00199     struct tag_of< std::vector<std::map<KEY, DATA, COMPARE, AMAP>, AVEC> >
00200     {
00201       typedef viennacl::tag_stl  type;
00202     };
00203 
00204 
00205     // ----------------------------------------------------
00206     // VIENNACL
00207     //
00208     template< typename T, unsigned int alignment >
00209     struct tag_of< viennacl::vector<T, alignment> >
00210     {
00211       typedef viennacl::tag_viennacl  type;
00212     };
00213 
00214     template< typename T, typename F, unsigned int alignment >
00215     struct tag_of< viennacl::matrix<T, F, alignment> >
00216     {
00217       typedef viennacl::tag_viennacl  type;
00218     };
00219 
00220     template< typename T1, typename T2, typename OP >
00221     struct tag_of< viennacl::matrix_expression<T1,T2,OP> >
00222     {
00223       typedef viennacl::tag_viennacl  type;
00224     };
00225 
00226     template< typename T >
00227     struct tag_of< viennacl::matrix_range<T> >
00228     {
00229       typedef viennacl::tag_viennacl  type;
00230     };
00231 
00232     template< typename T, unsigned int I>
00233     struct tag_of< viennacl::compressed_matrix<T,I> >
00234     {
00235       typedef viennacl::tag_viennacl  type;
00236     };
00237 
00238     template< typename T, unsigned int I>
00239     struct tag_of< viennacl::coordinate_matrix<T,I> >
00240     {
00241       typedef viennacl::tag_viennacl  type;
00242     };
00243 
00244     template< typename T, unsigned int I>
00245     struct tag_of< viennacl::ell_matrix<T,I> >
00246     {
00247       typedef viennacl::tag_viennacl  type;
00248     };
00249 
00250     template< typename T, unsigned int I>
00251     struct tag_of< viennacl::hyb_matrix<T,I> >
00252     {
00253       typedef viennacl::tag_viennacl  type;
00254     };
00255 
00256     template< typename T, unsigned int I>
00257     struct tag_of< viennacl::circulant_matrix<T,I> >
00258     {
00259       typedef viennacl::tag_viennacl  type;
00260     };
00261 
00262     template< typename T, unsigned int I>
00263     struct tag_of< viennacl::hankel_matrix<T,I> >
00264     {
00265       typedef viennacl::tag_viennacl  type;
00266     };
00267 
00268     template< typename T, unsigned int I>
00269     struct tag_of< viennacl::toeplitz_matrix<T,I> >
00270     {
00271       typedef viennacl::tag_viennacl  type;
00272     };
00273 
00274     template< typename T, unsigned int I>
00275     struct tag_of< viennacl::vandermonde_matrix<T,I> >
00276     {
00277       typedef viennacl::tag_viennacl  type;
00278     };
00281     // ----------------------------------------------------
00282   } // end namespace traits
00283 
00284 
00289   template <typename Tag>
00290   struct is_mtl4
00291   {
00292      enum { value = false };
00293   };
00294 
00296   template <>
00297   struct is_mtl4< viennacl::tag_mtl4 >
00298   {
00299      enum { value = true };
00300   };
00307   template <typename Tag>
00308   struct is_eigen
00309   {
00310      enum { value = false };
00311   };
00312 
00314   template <>
00315   struct is_eigen< viennacl::tag_eigen >
00316   {
00317      enum { value = true };
00318   };
00326   template <typename Tag>
00327   struct is_ublas
00328   {
00329      enum { value = false };
00330   };
00331 
00333   template <>
00334   struct is_ublas< viennacl::tag_ublas >
00335   {
00336      enum { value = true };
00337   };
00344   template <typename Tag>
00345   struct is_stl
00346   {
00347      enum { value = false };
00348   };
00349 
00351   template <>
00352   struct is_stl< viennacl::tag_stl >
00353   {
00354      enum { value = true };
00355   };
00363   template <typename Tag>
00364   struct is_viennacl
00365   {
00366      enum { value = false };
00367   };
00368 
00370   template <>
00371   struct is_viennacl< viennacl::tag_viennacl >
00372   {
00373      enum { value = true };
00374   };
00377 } // end namespace viennacl
00378 
00379 #endif