Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ublastraits.hpp
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2005-07-28
7 
8  Copyright (C) 2007,2009 Université de Grenoble 1
9  Copyright (C) 2005,2006,2009 EPFL
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
30 #ifndef FEELPP_UBLAS_TRAITS_HPP
31 #define FEELPP_UBLAS_TRAITS_HPP 1
32 
33 #if !defined( FEELPP_TRAITS_HPP)
34 #error feel/feelcore/ublas_traits.hpp must not be used directly, use feel/feelcore/traits.hpp instead
35 #endif
36 
37 #include <boost/numeric/ublas/traits.hpp>
38 
39 namespace boost
40 {
41 namespace numeric
42 {
43 namespace ublas
44 {
45 
46 #if defined( FEELPP_HAS_MPFR )
47 template<>
48 struct type_traits<Feel::mp_type>
49 {
50  typedef type_traits<Feel::mp_type> self_type;
51  typedef Feel::mp_type value_type;
52  typedef const value_type &const_reference;
53  typedef value_type &reference;
54  typedef value_type real_type;
55  typedef Feel::mp_type precision_type;
56 
57  static const unsigned plus_complexity = 1;
58  static const unsigned multiplies_complexity = 1;
59 
60  static
61  BOOST_UBLAS_INLINE
62  real_type real ( const_reference t )
63  {
64  return t;
65  }
66  static
67  BOOST_UBLAS_INLINE
68  real_type imag ( const_reference /*t*/ )
69  {
70  return 0;
71  }
72  static
73  BOOST_UBLAS_INLINE
74  value_type conj ( const_reference t )
75  {
76  return t;
77  }
78 
79  static
80  BOOST_UBLAS_INLINE
81  real_type abs ( const_reference t )
82  {
83  return ::abs ( t );
84  }
85 
86  static
87  BOOST_UBLAS_INLINE
88  value_type sqrt ( const_reference t )
89  {
90  return ::sqrt ( t );
91  }
92 
93  static
94  BOOST_UBLAS_INLINE
95  value_type type_sqrt ( const_reference t )
96  {
97  return ::sqrt ( t );
98  }
99 
100  static
101  BOOST_UBLAS_INLINE
102  real_type norm_1 ( const_reference t )
103  {
104  return self_type::abs ( t );
105  }
106  static
107  BOOST_UBLAS_INLINE
108  real_type norm_2 ( const_reference t )
109  {
110  return self_type::abs ( t );
111  }
112  static
113  BOOST_UBLAS_INLINE
114  real_type norm_inf ( const_reference t )
115  {
116  return self_type::abs ( t );
117  }
118 
119  static
120  BOOST_UBLAS_INLINE
121  bool equals ( const_reference t1, const_reference t2 )
122  {
123  return self_type::norm_inf ( t1 - t2 ) < BOOST_UBLAS_TYPE_CHECK_EPSILON *
124  ( std::max ) ( ( std::max ) ( self_type::norm_inf ( t1 ),
125  self_type::norm_inf ( t2 ) ),
126  BOOST_UBLAS_TYPE_CHECK_MIN );
127  }
128 };
129 #endif // FEELPP_HAS_MPFR
130 
131 #if defined ( FEELPP_HAS_QD_REAL )
132 template<>
133 struct type_traits<qd_real>
134 {
135  typedef type_traits<qd_real> self_type;
136  typedef qd_real value_type;
137  typedef const value_type &const_reference;
138  typedef value_type &reference;
139  typedef value_type real_type;
140  typedef qd_real precision_type;
141 
142  static const unsigned plus_complexity = 1;
143  static const unsigned multiplies_complexity = 1;
144 
145  static
146  BOOST_UBLAS_INLINE
147  real_type real ( const_reference t )
148  {
149  return t;
150  }
151  static
152  BOOST_UBLAS_INLINE
153  real_type imag ( const_reference /*t*/ )
154  {
155  return 0;
156  }
157  static
158  BOOST_UBLAS_INLINE
159  value_type conj ( const_reference t )
160  {
161  return t;
162  }
163 
164  static
165  BOOST_UBLAS_INLINE
166  real_type abs ( const_reference t )
167  {
168  return ::abs ( t );
169  }
170 
171  static
172  BOOST_UBLAS_INLINE
173  value_type sqrt ( const_reference t )
174  {
175  return ::sqrt ( t );
176  }
177 
178  static
179  BOOST_UBLAS_INLINE
180  value_type type_sqrt ( const_reference t )
181  {
182  return ::sqrt ( t );
183  }
184 
185  static
186  BOOST_UBLAS_INLINE
187  real_type norm_1 ( const_reference t )
188  {
189  return self_type::abs ( t );
190  }
191  static
192  BOOST_UBLAS_INLINE
193  real_type norm_2 ( const_reference t )
194  {
195  return self_type::abs ( t );
196  }
197  static
198  BOOST_UBLAS_INLINE
199  real_type norm_inf ( const_reference t )
200  {
201  return self_type::abs ( t );
202  }
203 
204  static
205  BOOST_UBLAS_INLINE
206  bool equals ( const_reference t1, const_reference t2 )
207  {
208  return self_type::norm_inf ( t1 - t2 ) < BOOST_UBLAS_TYPE_CHECK_EPSILON *
209  ( std::max ) ( ( std::max ) ( self_type::norm_inf ( t1 ),
210  self_type::norm_inf ( t2 ) ),
211  BOOST_UBLAS_TYPE_CHECK_MIN );
212  }
213 };
214 #endif /* FEELPP_HAS_QD_REAL */
215 #if defined ( FEELPP_HAS_DD_REAL )
216 template<>
217 struct type_traits<dd_real>
218 {
219  typedef type_traits<dd_real> self_type;
220  typedef dd_real value_type;
221  typedef const value_type &const_reference;
222  typedef value_type &reference;
223  typedef value_type real_type;
224  typedef dd_real precision_type;
225 
226  static const unsigned plus_complexity = 1;
227  static const unsigned multiplies_complexity = 1;
228 
229  static
230  BOOST_UBLAS_INLINE
231  real_type real ( const_reference t )
232  {
233  return t;
234  }
235  static
236  BOOST_UBLAS_INLINE
237  real_type imag ( const_reference /*t*/ )
238  {
239  return 0;
240  }
241  static
242  BOOST_UBLAS_INLINE
243  value_type conj ( const_reference t )
244  {
245  return t;
246  }
247 
248  static
249  BOOST_UBLAS_INLINE
250  real_type abs ( const_reference t )
251  {
252  return ::abs ( t );
253  }
254  static
255  BOOST_UBLAS_INLINE
256  value_type sqrt ( const_reference t )
257  {
258  return ::sqrt ( t );
259  }
260 
261  static
262  BOOST_UBLAS_INLINE
263  value_type type_sqrt ( const_reference t )
264  {
265  return ::sqrt ( t );
266  }
267 
268  static
269  BOOST_UBLAS_INLINE
270  real_type norm_1 ( const_reference t )
271  {
272  return self_type::abs ( t );
273  }
274  static
275  BOOST_UBLAS_INLINE
276  real_type norm_2 ( const_reference t )
277  {
278  return self_type::abs ( t );
279  }
280  static
281  BOOST_UBLAS_INLINE
282  real_type norm_inf ( const_reference t )
283  {
284  return self_type::abs ( t );
285  }
286 
287  static
288  BOOST_UBLAS_INLINE
289  bool equals ( const_reference t1, const_reference t2 )
290  {
291  return self_type::norm_inf ( t1 - t2 ) < BOOST_UBLAS_TYPE_CHECK_EPSILON *
292  ( std::max ) ( ( std::max ) ( self_type::norm_inf ( t1 ),
293  self_type::norm_inf ( t2 ) ),
294  BOOST_UBLAS_TYPE_CHECK_MIN );
295  }
296 };
297 #endif /* FEELPP_HAS_DD_REAL */
298 
299 #if defined ( FEELPP_HAS_MP_REAL )
300 template<>
301 struct type_traits<mp_real>
302 {
303  typedef type_traits<mp_real> self_type;
304  typedef mp_real value_type;
305  typedef const value_type &const_reference;
306  typedef value_type &reference;
307  typedef value_type real_type;
308  typedef double precision_type;
309 
310  static const unsigned plus_complexity = 1;
311  static const unsigned multiplies_complexity = 1;
312 
313  static
314  BOOST_UBLAS_INLINE
315  real_type real ( const_reference t )
316  {
317  return t;
318  }
319  static
320  BOOST_UBLAS_INLINE
321  real_type imag ( const_reference /*t*/ )
322  {
323  return 0;
324  }
325  static
326  BOOST_UBLAS_INLINE
327  value_type conj ( const_reference t )
328  {
329  return t;
330  }
331 
332  static
333  BOOST_UBLAS_INLINE
334  real_type abs ( const_reference t )
335  {
336  return ::abs ( t );
337  }
338  static
339  BOOST_UBLAS_INLINE
340  value_type sqrt ( const_reference t )
341  {
342  return ::sqrt ( t );
343  }
344 
345  static
346  BOOST_UBLAS_INLINE
347  value_type type_sqrt ( const_reference t )
348  {
349  return ::sqrt ( t );
350  }
351 
352  static
353  BOOST_UBLAS_INLINE
354  real_type norm_1 ( const_reference t )
355  {
356  return self_type::abs ( t );
357  }
358  static
359  BOOST_UBLAS_INLINE
360  real_type norm_2 ( const_reference t )
361  {
362  return self_type::abs ( t );
363  }
364  static
365  BOOST_UBLAS_INLINE
366  real_type norm_inf ( const_reference t )
367  {
368  return self_type::abs ( t );
369  }
370 
371  static
372  BOOST_UBLAS_INLINE
373  bool equals ( const_reference t1, const_reference t2 )
374  {
375  return self_type::norm_inf ( t1 - t2 ) < BOOST_UBLAS_TYPE_CHECK_EPSILON *
376  ( std::max ) ( ( std::max ) ( self_type::norm_inf ( t1 ),
377  self_type::norm_inf ( t2 ) ),
378  BOOST_UBLAS_TYPE_CHECK_MIN );
379  }
380 };
381 #endif /* FEELPP_HAS_MP_REAL */
382 }
383 }
384 }
385 #endif /* FEELPP_UBLAS_TRAITS_HPP */

Generated on Sun Oct 20 2013 08:25:06 for Feel++ by doxygen 1.8.4