29 #ifndef __FEELALG_TRAITS_HPP
30 #define __FEELALG_TRAITS_HPP 1
32 #include <boost/preprocessor/comparison/less.hpp>
33 #include <boost/preprocessor/comparison/equal.hpp>
34 #include <boost/preprocessor/logical/and.hpp>
35 #include <boost/preprocessor/control/if.hpp>
36 #include <boost/preprocessor/list/at.hpp>
37 #include <boost/preprocessor/list/cat.hpp>
38 #include <boost/preprocessor/list/for_each_product.hpp>
39 #include <boost/preprocessor/logical/or.hpp>
40 #include <boost/preprocessor/tuple/to_list.hpp>
41 #include <boost/preprocessor/tuple/eat.hpp>
42 #include <boost/preprocessor/facilities/empty.hpp>
43 #include <boost/preprocessor/punctuation/comma.hpp>
44 #include <boost/preprocessor/facilities/identity.hpp>
45 #include <boost/preprocessor/arithmetic/add.hpp>
46 #include <boost/preprocessor/list/filter.hpp>
48 #include <boost/numeric/ublas/vector.hpp>
49 #include <boost/numeric/ublas/matrix.hpp>
50 #include <boost/numeric/ublas/matrix_sparse.hpp>
53 #include <feel/feelcore/feel.hpp>
54 #include <feel/feelcore/traits.hpp>
62 namespace ublas = boost::numeric::ublas;
78 typedef typename self_type::value_type value_type;
84 # define FEELPP_GLAS_TRAITS_VECTOR_TYPE(T) BOOST_PP_TUPLE_ELEM(5, 0 , T)
85 # define FEELPP_GLAS_TRAITS_VECTOR_ITERATOR(T) BOOST_PP_TUPLE_ELEM(5, 1 , T)
86 # define FEELPP_GLAS_TRAITS_VECTOR_CONST_ITERATOR(T) BOOST_PP_TUPLE_ELEM(5, 2 , T)
87 # define FEELPP_GLAS_TRAITS_VECTOR_SIZE(T) BOOST_PP_TUPLE_ELEM(5, 3 , T)
88 # define FEELPP_GLAS_TRAITS_VECTOR_RESIZE(T) BOOST_PP_TUPLE_ELEM(5, 4 , T)
90 # define FEELPP_GLAS_TRAITS_VECTOR_TYPES \
91 BOOST_PP_TUPLE_TO_LIST( \
94 ( ublas::vector, iterator, const_iterator, size, resize ), \
95 ( std::vector , iterator, const_iterator, size, resize ) \
101 # define FEELPP_GLAS_TRAITS_VECTOR_OP(_, T) \
102 FEELPP_GLAS_TRAITS_VECTOR_OP_CODE T \
105 #define FEELPP_GLAS_TRAITS_VECTOR_OP_CODE(T,V) \
107 struct traits<FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )> > \
109 typedef FEELPP_TRAITS_TYPE( T ) value_type; \
110 typedef FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )> self_type; \
111 typedef self_type::FEELPP_GLAS_TRAITS_VECTOR_ITERATOR( V ) iterator; \
112 typedef self_type::FEELPP_GLAS_TRAITS_VECTOR_CONST_ITERATOR( V ) const_iterator; \
113 typedef vector_tag type_tag; \
114 static const bool is_vector = true; \
115 static const bool is_matrix = false; \
118 traits<FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )> >::const_iterator \
119 begin( FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )> const& t ) \
123 traits<FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )> >::iterator \
124 begin( FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )>& t ) \
128 traits<FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )> >::const_iterator \
129 end( FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )> const& t ) \
133 traits<FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )> >::iterator \
134 end( FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )>& t ) \
139 size_type size( FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )> const& t ) \
141 return t.FEELPP_GLAS_TRAITS_VECTOR_SIZE(V)(); \
144 void resize( FEELPP_GLAS_TRAITS_VECTOR_TYPE( V )<FEELPP_TRAITS_TYPE( T )>& t, size_type newsize ) \
146 return t.FEELPP_GLAS_TRAITS_VECTOR_RESIZE(V)( newsize ); \
154 BOOST_PP_LIST_FOR_EACH_PRODUCT( FEELPP_GLAS_TRAITS_VECTOR_OP, 2, ( FEELPP_TRAITS_TYPES, FEELPP_GLAS_TRAITS_VECTOR_TYPES ) );
160 # define FEELPP_GLAS_TRAITS_MATRIX_TYPE(T) BOOST_PP_TUPLE_ELEM(5, 0 , T)
161 # define FEELPP_GLAS_TRAITS_MATRIX_SIZE1(T) BOOST_PP_TUPLE_ELEM(5, 1 , T)
162 # define FEELPP_GLAS_TRAITS_MATRIX_SIZE2(T) BOOST_PP_TUPLE_ELEM(5, 2 , T)
163 # define FEELPP_GLAS_TRAITS_MATRIX_RESIZE(T) BOOST_PP_TUPLE_ELEM(5, 3 , T)
164 # define FEELPP_GLAS_TRAITS_MATRIX_NNZ(T) BOOST_PP_TUPLE_ELEM(5, 4 , T)
166 #define UBLAS_MATRIX_ROW( T ) ublas::matrix<T, ublas::row_major>
167 #define UBLAS_MATRIX_COL( T ) ublas::matrix<T, ublas::column_major>
168 #define UBLAS_MATRIX_SPARSE_ROW( T ) ublas::compressed_matrix<T, ublas::row_major>
169 #define UBLAS_MATRIX_SPARSE_COL( T ) ublas::compressed_matrix<T, ublas::column_major>
171 # define FEELPP_GLAS_TRAITS_MATRIX_TYPES \
172 BOOST_PP_TUPLE_TO_LIST( \
175 ( UBLAS_MATRIX_ROW , size1, size2, resize, boost::none_t ), \
176 ( UBLAS_MATRIX_COL , size1, size2, resize, boost::none_t ), \
177 ( UBLAS_MATRIX_SPARSE_ROW, size1, size2, resize, nnz ), \
178 ( UBLAS_MATRIX_SPARSE_COL, size1, size2, resize, nnz ) \
184 # define FEELPP_GLAS_TRAITS_MATRIX_OP(_, T) \
185 FEELPP_GLAS_TRAITS_MATRIX_OP_CODE T \
188 #define FEELPP_GLAS_TRAITS_MATRIX_OP_CODE(T,V) \
190 struct traits<FEELPP_GLAS_TRAITS_MATRIX_TYPE( V )( FEELPP_TRAITS_TYPE( T ) ) > \
192 typedef FEELPP_TRAITS_TYPE( T ) value_type; \
193 typedef FEELPP_GLAS_TRAITS_MATRIX_TYPE( V )( FEELPP_TRAITS_TYPE( T ) ) self_type; \
194 typedef matrix_tag type_tag; \
195 static const bool is_vector = false; \
196 static const bool is_matrix = true; \
199 size_type nrows( FEELPP_GLAS_TRAITS_MATRIX_TYPE( V )( FEELPP_TRAITS_TYPE( T ) ) const& t ) \
201 return t.FEELPP_GLAS_TRAITS_MATRIX_SIZE1(V)(); \
204 size_type ncols( FEELPP_GLAS_TRAITS_MATRIX_TYPE( V )( FEELPP_TRAITS_TYPE( T ) ) const& t ) \
206 return t.FEELPP_GLAS_TRAITS_MATRIX_SIZE2(V)(); \
209 void resize( FEELPP_GLAS_TRAITS_MATRIX_TYPE( V )( FEELPP_TRAITS_TYPE( T ) )& t, size_type newsize1, size_type newsize2 ) \
211 return t.FEELPP_GLAS_TRAITS_MATRIX_RESIZE(V)( newsize1, newsize2 ); \
219 BOOST_PP_LIST_FOR_EACH_PRODUCT( FEELPP_GLAS_TRAITS_MATRIX_OP, 2, ( FEELPP_TRAITS_TYPES, FEELPP_GLAS_TRAITS_MATRIX_TYPES ) );