multi_array_adaption.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include <type_traits>
  22. namespace boost {
  23. namespace numeric {
  24. namespace odeint {
  25. template< typename T >
  26. struct is_multi_array
  27. {
  28. typedef std::false_type type;
  29. const static bool value = type::value;
  30. };
  31. template< typename T >
  32. struct is_resizeable_multi_array
  33. {
  34. typedef std::false_type type;
  35. const static bool value = type::value;
  36. };
  37. template< typename V , size_t Dim , typename A >
  38. struct is_multi_array< boost::multi_array< V , Dim , A > >
  39. {
  40. typedef std::true_type type;
  41. const static bool value = type::value;
  42. };
  43. template< typename V , size_t Dim , typename A >
  44. struct is_resizeable_multi_array< boost::multi_array< V , Dim , A > >
  45. {
  46. typedef std::true_type type;
  47. const static bool value = type::value;
  48. };
  49. template< typename T >
  50. struct is_resizeable_sfinae< T , typename boost::enable_if< typename is_resizeable_multi_array< T >::type >::type >
  51. {
  52. typedef std::true_type type;
  53. const static bool value = type::value;
  54. };
  55. template< typename T1 , typename T2 >
  56. struct same_size_impl_sfinae< T1 , T2 ,
  57. typename boost::enable_if<
  58. typename boost::mpl::and_<
  59. is_multi_array< T1 > ,
  60. is_multi_array< T2 > ,
  61. boost::mpl::bool_< T1::dimensionality == T2::dimensionality >
  62. >::type
  63. >::type >
  64. {
  65. static bool same_size( T1 const &x1 , T2 const &x2 )
  66. {
  67. for( size_t i=0 ; i<T1::dimensionality ; ++i )
  68. {
  69. if( x1.shape()[i] != x2.shape()[i] ) return false;
  70. if( x1.index_bases()[i] != x2.index_bases()[i] ) return false;
  71. }
  72. return true;
  73. }
  74. };
  75. template< typename T1 , typename T2 >
  76. struct resize_impl_sfinae< T1 , T2 ,
  77. typename boost::enable_if<
  78. typename boost::mpl::and_<
  79. is_resizeable_multi_array< T1 > ,
  80. is_multi_array< T2 > ,
  81. boost::mpl::bool_< T1::dimensionality == T2::dimensionality >
  82. >::type
  83. >::type >
  84. {
  85. static void resize( T1 &x1 , const T2 &x2 )
  86. {
  87. std::array< int , T1::dimensionality > extents;
  88. for( size_t i=0 ; i<T1::dimensionality ; ++i ) extents[i] = x2.shape()[i];
  89. x1.resize( extents );
  90. std::array< int , T1::dimensionality > origins;
  91. for( size_t i=0 ; i<T1::dimensionality ; ++i ) origins[i] = x2.index_bases()[i];
  92. x1.reindex( origins );
  93. }
  94. };
  95. } // namespace odeint
  96. } // namespace numeric
  97. } // namespace boost
  98. #endif // BOOST_NUMERIC_ODEINT_UTIL_MULTI_ARRAY_ADAPTION_HPP_DEFINED