multi_array_adaption.hpp 3.4 KB

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