So-Bogus
A c++ sparse block matrix library aimed at Second Order cone problems
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ScalarBindings.hpp
1 /*
2  * This file is part of bogus, a C++ sparse block matrix library.
3  *
4  * Copyright 2013 Gilles Daviet <gdaviet@gmail.com>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
10 
11 #ifndef BOGUS_BLOCK_SCALAR_BINDGINS
12 #define BOGUS_BLOCK_SCALAR_BINDGINS
13 
14 #include "Expressions.hpp"
15 #include <cmath>
16 #include <cstdlib>
17 
18 #define BOGUS_BLOCK_SCALAR_TYPES \
19  BOGUS_PROCESS_SCALAR( double ) \
20  BOGUS_PROCESS_SCALAR( float ) \
21  BOGUS_PROCESS_SCALAR( int ) \
22  BOGUS_PROCESS_SCALAR( char ) \
23 
24 namespace bogus {
25 
26 #define BOGUS_PROCESS_SCALAR( Scalar ) \
27  inline bool is_zero( Scalar s, Scalar precision ) { return std::abs( s ) <= precision ; } \
28  inline void set_zero( Scalar &s ) { s = 0 ; } \
29  inline void set_identity( Scalar &s ) { s = 1 ; } \
30  inline void resize( Scalar &, int ,int ) { } \
31  inline const Scalar* data_pointer( const Scalar &s ) { return &s ; }
32 BOGUS_BLOCK_SCALAR_TYPES
33 #undef BOGUS_PROCESS_SCALAR
34 
35 #define BOGUS_PROCESS_SCALAR( Scalar ) \
36 BOGUS_BLOCK_SCALAR_TYPES
37 #undef BOGUS_PROCESS_SCALAR
38 
39 #define BOGUS_PROCESS_SCALAR( Scalar_ ) \
40  template< > struct BlockTraits< Scalar_ > { \
41  typedef Scalar_ Scalar ; \
42  typedef Scalar_ TransposeStorageType ; \
43  enum { RowsAtCompileTime = 1, ColsAtCompileTime = 1, \
44  is_row_major = 0, uses_plain_array_storage = 1, \
45  is_self_transpose = 1 } ; \
46  } ;
47 BOGUS_BLOCK_SCALAR_TYPES
48 #undef BOGUS_PROCESS_SCALAR
49 
50 }
51 
52 
53 #endif