3 boost/numeric/odeint/util/multi_array_adaption.hpp
9 Copyright 2009-2012 Karsten Ahnert
10 Copyright 2009-2012 Mario Mulansky
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
18 #ifndef BOOST_NUMERIC_ODEINT_UTIL_MULTI_ARRAY_ADAPTION_HPP_DEFINED
19 #define BOOST_NUMERIC_ODEINT_UTIL_MULTI_ARRAY_ADAPTION_HPP_DEFINED
23 #include <boost/numeric/odeint/util/is_resizeable.hpp>
24 #include <boost/numeric/odeint/util/resize.hpp>
25 #include <boost/numeric/odeint/util/same_size.hpp>
27 #include <boost/mpl/and.hpp>
28 #include <boost/mpl/bool.hpp>
29 #include <boost/multi_array.hpp>
36 template< typename T >
39 typedef boost::false_type type;
40 const static bool value = type::value;
43 template< typename T >
44 struct is_resizeable_multi_array
46 typedef boost::false_type type;
47 const static bool value = type::value;
52 template< typename V , size_t Dim , typename A >
53 struct is_multi_array< boost::multi_array< V , Dim , A > >
55 typedef boost::true_type type;
56 const static bool value = type::value;
59 template< typename V , size_t Dim , typename A >
60 struct is_resizeable_multi_array< boost::multi_array< V , Dim , A > >
62 typedef boost::true_type type;
63 const static bool value = type::value;
69 template< typename T >
70 struct is_resizeable_sfinae< T , typename boost::enable_if< typename is_resizeable_multi_array< T >::type >::type >
72 typedef boost::true_type type;
73 const static bool value = type::value;
80 template< typename T1 , typename T2 >
81 struct same_size_impl_sfinae< T1 , T2 ,
82 typename boost::enable_if<
83 typename boost::mpl::and_<
84 is_multi_array< T1 > ,
85 is_multi_array< T2 > ,
86 boost::mpl::bool_< T1::dimensionality == T2::dimensionality >
90 static bool same_size( T1 const &x1 , T2 const &x2 )
92 for( size_t i=0 ; i<T1::dimensionality ; ++i )
94 if( x1.shape()[i] != x2.shape()[i] ) return false;
95 if( x1.index_bases()[i] != x2.index_bases()[i] ) return false;
102 template< typename T1 , typename T2 >
103 struct resize_impl_sfinae< T1 , T2 ,
104 typename boost::enable_if<
105 typename boost::mpl::and_<
106 is_resizeable_multi_array< T1 > ,
107 is_multi_array< T2 > ,
108 boost::mpl::bool_< T1::dimensionality == T2::dimensionality >
112 static void resize( T1 &x1 , const T2 &x2 )
114 boost::array< int , T1::dimensionality > extents;
115 for( size_t i=0 ; i<T1::dimensionality ; ++i ) extents[i] = x2.shape()[i];
116 x1.resize( extents );
117 boost::array< int , T1::dimensionality > origins;
118 for( size_t i=0 ; i<T1::dimensionality ; ++i ) origins[i] = x2.index_bases()[i];
119 x1.reindex( origins );
125 } // namespace odeint
126 } // namespace numeric
130 #endif // BOOST_NUMERIC_ODEINT_UTIL_MULTI_ARRAY_ADAPTION_HPP_DEFINED