ViennaCL - The Vienna Computing Library  1.2.0
result_of.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_META_RESULT_OF_HPP_
2 #define VIENNACL_META_RESULT_OF_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 
24 #include <string>
25 #include <fstream>
26 #include <sstream>
27 #include "viennacl/forwards.h"
28 
29 
30 #ifdef VIENNACL_HAVE_UBLAS
31 #include <boost/numeric/ublas/matrix_sparse.hpp>
32 #include <boost/numeric/ublas/matrix.hpp>
33 #endif
34 
35 #ifdef VIENNACL_HAVE_EIGEN
36 #include <Eigen/Core>
37 #include <Eigen/Sparse>
38 #endif
39 
40 #ifdef VIENNACL_HAVE_MTL4
41 #include <boost/numeric/mtl/mtl.hpp>
42 #endif
43 
44 #include <vector>
45 #include <map>
46 
47 namespace viennacl
48 {
49  namespace result_of
50  {
51  //
52  // Retrieve size_type
53  //
54  template <typename T>
55  struct size_type
56  {
57  typedef typename T::size_type type;
58  };
59 
60  #ifdef VIENNACL_HAVE_EIGEN
61  template <class T, int a, int b, int c, int d, int e>
62  struct size_type< Eigen::Matrix<T, a, b, c, d, e> >
63  {
64  typedef std::size_t type;
65  };
66 
67  template <>
68  struct size_type<Eigen::VectorXf>
69  {
70  typedef std::size_t type;
71  };
72 
73  template <>
74  struct size_type<Eigen::VectorXd>
75  {
76  typedef std::size_t type;
77  };
78 
79  template <typename T, int options>
80  struct size_type<Eigen::SparseMatrix<T, options> >
81  {
82  typedef std::size_t type;
83  };
84  #endif
85 
86  //
87  // Retrieve value_type:
88  //
89  template <typename T>
90  struct value_type
91  {
92  typedef typename T::value_type type;
93  };
94 
95  //
96  // Retrieve cpu value_type:
97  //
98  template <typename T>
100  {
101  typedef typename T::ERROR_CANNOT_DEDUCE_CPU_SCALAR_TYPE_FOR_T type;
102  };
103 
104  template <>
105  struct cpu_value_type<float>
106  {
107  typedef float type;
108  };
109 
110  template <>
111  struct cpu_value_type<double>
112  {
113  typedef double type;
114  };
115 
116  template <typename T>
117  struct cpu_value_type<viennacl::scalar<T> >
118  {
119  typedef T type;
120  };
121 
122  template <typename T, unsigned int ALIGNMENT>
123  struct cpu_value_type<viennacl::vector<T, ALIGNMENT> >
124  {
125  typedef T type;
126  };
127 
128  template <typename T>
129  struct cpu_value_type<viennacl::vector_range<T> >
130  {
131  typedef typename cpu_value_type<T>::type type;
132  };
133 
134  template <typename T1, typename T2, typename OP>
135  struct cpu_value_type<viennacl::vector_expression<T1, T2, OP> >
136  {
137  typedef typename cpu_value_type<T1>::type type;
138  };
139 
140 
141 
142  template <typename T, typename F, unsigned int ALIGNMENT>
143  struct cpu_value_type<viennacl::matrix<T, F, ALIGNMENT> >
144  {
145  typedef T type;
146  };
147 
148  template <typename T>
149  struct cpu_value_type<viennacl::matrix_range<T> >
150  {
151  typedef typename cpu_value_type<T>::type type;
152  };
153 
154  template <typename T1, typename T2, typename OP>
155  struct cpu_value_type<viennacl::matrix_expression<T1, T2, OP> >
156  {
157  typedef typename cpu_value_type<T1>::type type;
158  };
159 
160 
161  #ifdef VIENNACL_HAVE_EIGEN
162  template <>
163  struct value_type<Eigen::MatrixXf>
164  {
165  typedef Eigen::MatrixXf::RealScalar type;
166  };
167 
168  template <>
169  struct value_type<Eigen::MatrixXd>
170  {
171  typedef Eigen::MatrixXd::RealScalar type;
172  };
173 
174  template <typename ScalarType, int option>
175  struct value_type<Eigen::SparseMatrix<ScalarType, option> >
176  {
177  typedef ScalarType type;
178  };
179 
180  template <>
181  struct value_type<Eigen::VectorXf>
182  {
183  typedef Eigen::VectorXf::RealScalar type;
184  };
185 
186  template <>
187  struct value_type<Eigen::VectorXd>
188  {
189  typedef Eigen::VectorXd::RealScalar type;
190  };
191 
192  #endif
193 
194 
195 
196  template <typename T>
198  {
199  typedef T & type;
200  };
201 
202  template <>
204  {
205  typedef float type;
206  };
207 
208  template <>
210  {
211  typedef double type;
212  };
213 
214 
215  } //namespace result_of
216 } //namespace viennacl
217 
218 
219 #endif