Chris@102
|
1 /*
|
Chris@102
|
2 [auto_generated]
|
Chris@102
|
3 boost/numeric/odeint/util/multi_array_adaption.hpp
|
Chris@102
|
4
|
Chris@102
|
5 [begin_description]
|
Chris@102
|
6 tba.
|
Chris@102
|
7 [end_description]
|
Chris@102
|
8
|
Chris@102
|
9 Copyright 2009-2012 Karsten Ahnert
|
Chris@102
|
10 Copyright 2009-2012 Mario Mulansky
|
Chris@102
|
11
|
Chris@102
|
12 Distributed under the Boost Software License, Version 1.0.
|
Chris@102
|
13 (See accompanying file LICENSE_1_0.txt or
|
Chris@102
|
14 copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
15 */
|
Chris@102
|
16
|
Chris@102
|
17
|
Chris@102
|
18 #ifndef BOOST_NUMERIC_ODEINT_UTIL_MULTI_ARRAY_ADAPTION_HPP_DEFINED
|
Chris@102
|
19 #define BOOST_NUMERIC_ODEINT_UTIL_MULTI_ARRAY_ADAPTION_HPP_DEFINED
|
Chris@102
|
20
|
Chris@102
|
21
|
Chris@102
|
22
|
Chris@102
|
23 #include <boost/numeric/odeint/util/is_resizeable.hpp>
|
Chris@102
|
24 #include <boost/numeric/odeint/util/resize.hpp>
|
Chris@102
|
25 #include <boost/numeric/odeint/util/same_size.hpp>
|
Chris@102
|
26
|
Chris@102
|
27 #include <boost/mpl/and.hpp>
|
Chris@102
|
28 #include <boost/mpl/bool.hpp>
|
Chris@102
|
29 #include <boost/multi_array.hpp>
|
Chris@102
|
30
|
Chris@102
|
31
|
Chris@102
|
32 namespace boost {
|
Chris@102
|
33 namespace numeric {
|
Chris@102
|
34 namespace odeint {
|
Chris@102
|
35
|
Chris@102
|
36 template< typename T >
|
Chris@102
|
37 struct is_multi_array
|
Chris@102
|
38 {
|
Chris@102
|
39 typedef boost::false_type type;
|
Chris@102
|
40 const static bool value = type::value;
|
Chris@102
|
41 };
|
Chris@102
|
42
|
Chris@102
|
43 template< typename T >
|
Chris@102
|
44 struct is_resizeable_multi_array
|
Chris@102
|
45 {
|
Chris@102
|
46 typedef boost::false_type type;
|
Chris@102
|
47 const static bool value = type::value;
|
Chris@102
|
48 };
|
Chris@102
|
49
|
Chris@102
|
50
|
Chris@102
|
51
|
Chris@102
|
52 template< typename V , size_t Dim , typename A >
|
Chris@102
|
53 struct is_multi_array< boost::multi_array< V , Dim , A > >
|
Chris@102
|
54 {
|
Chris@102
|
55 typedef boost::true_type type;
|
Chris@102
|
56 const static bool value = type::value;
|
Chris@102
|
57 };
|
Chris@102
|
58
|
Chris@102
|
59 template< typename V , size_t Dim , typename A >
|
Chris@102
|
60 struct is_resizeable_multi_array< boost::multi_array< V , Dim , A > >
|
Chris@102
|
61 {
|
Chris@102
|
62 typedef boost::true_type type;
|
Chris@102
|
63 const static bool value = type::value;
|
Chris@102
|
64 };
|
Chris@102
|
65
|
Chris@102
|
66
|
Chris@102
|
67
|
Chris@102
|
68
|
Chris@102
|
69 template< typename T >
|
Chris@102
|
70 struct is_resizeable_sfinae< T , typename boost::enable_if< typename is_resizeable_multi_array< T >::type >::type >
|
Chris@102
|
71 {
|
Chris@102
|
72 typedef boost::true_type type;
|
Chris@102
|
73 const static bool value = type::value;
|
Chris@102
|
74 };
|
Chris@102
|
75
|
Chris@102
|
76
|
Chris@102
|
77
|
Chris@102
|
78
|
Chris@102
|
79
|
Chris@102
|
80 template< typename T1 , typename T2 >
|
Chris@102
|
81 struct same_size_impl_sfinae< T1 , T2 ,
|
Chris@102
|
82 typename boost::enable_if<
|
Chris@102
|
83 typename boost::mpl::and_<
|
Chris@102
|
84 is_multi_array< T1 > ,
|
Chris@102
|
85 is_multi_array< T2 > ,
|
Chris@102
|
86 boost::mpl::bool_< T1::dimensionality == T2::dimensionality >
|
Chris@102
|
87 >::type
|
Chris@102
|
88 >::type >
|
Chris@102
|
89 {
|
Chris@102
|
90 static bool same_size( T1 const &x1 , T2 const &x2 )
|
Chris@102
|
91 {
|
Chris@102
|
92 for( size_t i=0 ; i<T1::dimensionality ; ++i )
|
Chris@102
|
93 {
|
Chris@102
|
94 if( x1.shape()[i] != x2.shape()[i] ) return false;
|
Chris@102
|
95 if( x1.index_bases()[i] != x2.index_bases()[i] ) return false;
|
Chris@102
|
96 }
|
Chris@102
|
97 return true;
|
Chris@102
|
98 }
|
Chris@102
|
99 };
|
Chris@102
|
100
|
Chris@102
|
101
|
Chris@102
|
102 template< typename T1 , typename T2 >
|
Chris@102
|
103 struct resize_impl_sfinae< T1 , T2 ,
|
Chris@102
|
104 typename boost::enable_if<
|
Chris@102
|
105 typename boost::mpl::and_<
|
Chris@102
|
106 is_resizeable_multi_array< T1 > ,
|
Chris@102
|
107 is_multi_array< T2 > ,
|
Chris@102
|
108 boost::mpl::bool_< T1::dimensionality == T2::dimensionality >
|
Chris@102
|
109 >::type
|
Chris@102
|
110 >::type >
|
Chris@102
|
111 {
|
Chris@102
|
112 static void resize( T1 &x1 , const T2 &x2 )
|
Chris@102
|
113 {
|
Chris@102
|
114 boost::array< int , T1::dimensionality > extents;
|
Chris@102
|
115 for( size_t i=0 ; i<T1::dimensionality ; ++i ) extents[i] = x2.shape()[i];
|
Chris@102
|
116 x1.resize( extents );
|
Chris@102
|
117 boost::array< int , T1::dimensionality > origins;
|
Chris@102
|
118 for( size_t i=0 ; i<T1::dimensionality ; ++i ) origins[i] = x2.index_bases()[i];
|
Chris@102
|
119 x1.reindex( origins );
|
Chris@102
|
120 }
|
Chris@102
|
121 };
|
Chris@102
|
122
|
Chris@102
|
123
|
Chris@102
|
124
|
Chris@102
|
125 } // namespace odeint
|
Chris@102
|
126 } // namespace numeric
|
Chris@102
|
127 } // namespace boost
|
Chris@102
|
128
|
Chris@102
|
129
|
Chris@102
|
130 #endif // BOOST_NUMERIC_ODEINT_UTIL_MULTI_ARRAY_ADAPTION_HPP_DEFINED
|