Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72742 - in sandbox/odeint/branches/karsten: boost/numeric/odeint/external/gsl boost/numeric/odeint/stepper boost/numeric/odeint/util libs/numeric/odeint/ideas/state_wrapper
From: mario.mulansky_at_[hidden]
Date: 2011-06-24 10:29:34


Author: mariomulansky
Date: 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
New Revision: 72742
URL: http://svn.boost.org/trac/boost/changeset/72742

Log:
deleted adjust_size_callers (default_adjust_size , matrix_vector_adjust_size), vector-matrix resizing is now implemented simply by respective specializations of same_size and adjust_size - see ublas_resize.hpp
Removed:
   sandbox/odeint/branches/karsten/boost/numeric/odeint/util/default_adjust_size.hpp
   sandbox/odeint/branches/karsten/boost/numeric/odeint/util/matrix_vector_adjust_size.hpp
   sandbox/odeint/branches/karsten/boost/numeric/odeint/util/ublas_permutation_matrix_resize.hpp
Text files modified:
   sandbox/odeint/branches/karsten/boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp | 19 ++++++++++++----
   sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/implicit_euler.hpp | 4 --
   sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/rosenbrock4.hpp | 4 --
   sandbox/odeint/branches/karsten/boost/numeric/odeint/util/resize.hpp | 2
   sandbox/odeint/branches/karsten/boost/numeric/odeint/util/size_adjuster.hpp | 26 ++++++++++++++++++----
   sandbox/odeint/branches/karsten/boost/numeric/odeint/util/ublas_resize.hpp | 34 ++++++++++++++++++++++++++++++
   sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp | 45 +++++++++------------------------------
   sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp | 37 --------------------------------
   8 files changed, 84 insertions(+), 87 deletions(-)

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
@@ -21,6 +21,12 @@
 #include <boost/range.hpp>
 #include <boost/iterator/iterator_facade.hpp>
 
+#include <boost/numeric/odeint/util/construct.hpp>
+#include <boost/numeric/odeint/util/destruct.hpp>
+#include <boost/numeric/odeint/util/copy.hpp>
+#include <boost/numeric/odeint/util/resize.hpp>
+#include <boost/numeric/odeint/util/default_adjust_size.hpp>
+
 using namespace std;
 
 
@@ -220,11 +226,14 @@
         return x1.size == x2.size;
 }
 
-template<>
-void adjust_size( const gsl_vector &x1 , gsl_vector &x2 )
-{
- if( !same_size( x1 , x2 ) ) resize( x1 , x2 );
-}
+struct default_adjust_size {
+
+ template<>
+ void adjust_size( const gsl_vector &x1 , gsl_vector &x2 )
+ {
+ if( !same_size( x1 , x2 ) ) resize( x1 , x2 );
+ }
+};
 
 template<>
 void copy( const gsl_vector &from , gsl_vector &to )

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/implicit_euler.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/implicit_euler.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/implicit_euler.hpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
@@ -19,9 +19,7 @@
 #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
 
 #include <boost/numeric/odeint/util/size_adjuster.hpp>
-#include <boost/numeric/odeint/util/matrix_vector_adjust_size.hpp>
 #include <boost/numeric/odeint/util/ublas_resize.hpp>
-#include <boost/numeric/odeint/util/ublas_permutation_matrix_resize.hpp>
 
 #include <boost/numeric/ublas/vector.hpp>
 #include <boost/numeric/ublas/matrix.hpp>
@@ -171,7 +169,7 @@
 
     value_type m_epsilon;
     size_adjuster< state_type , 3 > m_state_adjuster;
- size_adjuster< matrix_type , 1 , matrix_vector_adjust_size > m_matrix_adjuster;
+ size_adjuster< matrix_type , 1 > m_matrix_adjuster;
     size_adjuster< pmatrix_type , 1 > m_pmatrix_adjuster;
     state_type m_dxdt;
     state_type m_x;

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/rosenbrock4.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/rosenbrock4.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/rosenbrock4.hpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
@@ -18,9 +18,7 @@
 #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
 
 #include <boost/numeric/odeint/util/size_adjuster.hpp>
-#include <boost/numeric/odeint/util/matrix_vector_adjust_size.hpp>
 #include <boost/numeric/odeint/util/ublas_resize.hpp>
-#include <boost/numeric/odeint/util/ublas_permutation_matrix_resize.hpp>
 
 #include <boost/numeric/ublas/vector.hpp>
 #include <boost/numeric/ublas/matrix.hpp>
@@ -284,7 +282,7 @@
 private:
 
         size_adjuster< state_type , 11 > m_state_adjuster;
- size_adjuster< matrix_type , 1 , matrix_vector_adjust_size > m_matrix_adjuster;
+ size_adjuster< matrix_type , 1 > m_matrix_adjuster;
     size_adjuster< pmatrix_type , 1 > m_pmatrix_adjuster;
 
         matrix_type m_jac;

Deleted: sandbox/odeint/branches/karsten/boost/numeric/odeint/util/default_adjust_size.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/util/default_adjust_size.hpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
+++ (empty file)
@@ -1,51 +0,0 @@
-/*
- * adjust_size.hpp
- *
- * Created on: Jan 30, 2011
- * Author: karsten
- */
-
-#ifndef BOOST_NUMERIC_ODEINT_UTIL_ADJUST_SIZE_HPP_
-#define BOOST_NUMERIC_ODEINT_UTIL_ADJUST_SIZE_HPP_
-
-#include <boost/numeric/odeint/util/same_size.hpp>
-#include <boost/numeric/odeint/util/resize.hpp>
-
-namespace boost {
-namespace numeric {
-namespace odeint {
-
-
-
-/*
- *
- * We need this interface in order to call matrix by vector resizing,
- * i.e. mat.resize( vec.size() , vec.size() )
- *
- * See implicit_euler.hpp for usage
- */
-struct default_adjust_size
-{
- template< class Container1 , class Container2 >
- static bool adjust_size( const Container1 &x1 , Container2 &x2 )
- {
- if( !same_size( x1 , x2 ) )
- {
- resize( x1 , x2 );
- return true;
- }
- else
- {
- return false;
- }
- }
-};
-
-
-
-} // namespace odeint
-} // namespace numeric
-} // namespace boost
-
-
-#endif /* BOOST_NUMERIC_ODEINT_UTIL_ADJUST_SIZE_HPP_ */

Deleted: sandbox/odeint/branches/karsten/boost/numeric/odeint/util/matrix_vector_adjust_size.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/util/matrix_vector_adjust_size.hpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
+++ (empty file)
@@ -1,35 +0,0 @@
-/*
- * matrix_vector_adjuster.hpp
- *
- * Created on: Jan 31, 2011
- * Author: karsten
- */
-
-#ifndef BOOST_NUMERIC_ODEINT_UTIL_MATRIX_VECTOR_ADJUST_SIZE_HPP_
-#define BOOST_NUMERIC_ODEINT_UTIL_MATRIX_VECTOR_ADJUST_SIZE_HPP_
-
-
-namespace boost {
-namespace numeric {
-namespace odeint {
-
-struct matrix_vector_adjust_size
-{
- template< class Vector , class Matrix >
- static bool adjust_size( const Vector &v , Matrix &m )
- {
- if( ( m.size1() != v.size() ) || ( m.size2() != v.size() ) )
- {
- m.resize( v.size() , v.size() );
- return true;
- }
- return false;
- }
-};
-
-} // namespace odeint
-} // namespace numeric
-} // namespace boost
-
-
-#endif /* BOOST_NUMERIC_ODEINT_UTIL_MATRIX_VECTOR_ADJUSTER_HPP_ */

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/util/resize.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/util/resize.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/util/resize.hpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
@@ -9,6 +9,7 @@
 #define BOOST_NUMERIC_ODEINT_UTIL_RESIZE_HPP_
 
 #include <boost/range/size.hpp>
+#include <boost/numeric/odeint/util/same_size.hpp>
 
 namespace boost {
 namespace numeric {
@@ -35,7 +36,6 @@
 }
 
 
-
 } // namespace odeint
 } // namespace numeric
 } // namespace boost

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/util/size_adjuster.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/util/size_adjuster.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/util/size_adjuster.hpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
@@ -19,7 +19,8 @@
 #include <boost/array.hpp>
 
 #include <boost/numeric/odeint/util/is_resizeable.hpp>
-#include <boost/numeric/odeint/util/default_adjust_size.hpp>
+#include <boost/numeric/odeint/util/resize.hpp>
+//#include <boost/numeric/odeint/util/default_adjust_size.hpp>
 
 
 namespace boost {
@@ -42,14 +43,13 @@
 /*
  * Adjust size functionality with policies and resizeability
  */
-template< class Container , size_t Dim , class AdjustSizeCaller = default_adjust_size >
+template< class Container , size_t Dim >
 class size_adjuster : boost::noncopyable
 {
 public:
 
         typedef Container container_type;
         static const size_t dim = Dim;
- typedef AdjustSizeCaller adjust_size_caller;
 
         size_adjuster() : m_is_initialized( false ) , m_states()
         {
@@ -99,11 +99,12 @@
         template< class State >
         bool adjust_size_by_resizeability( const State &x , boost::true_type )
         {
+ bool resized = false;
                 for( size_t i=0 ; i<dim ; ++i )
                 {
- adjust_size_caller::adjust_size( x , *(m_states[i]) );
+ resized |= adjust_size_impl( x , *(m_states[i]) );
                 }
- return ( dim > 0 );
+ return resized;
         }
 
         template< class State >
@@ -112,6 +113,21 @@
             return false;
         }
 
+ /* adjust size implementation - resizes only if sizes aren't equal */
+ template< class Container1 , class Container2 >
+ static bool adjust_size_impl( const Container1 &x1 , Container2 &x2 )
+ {
+ if( !same_size( x1 , x2 ) )
+ {
+ resize( x1 , x2 );
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
 
 private :
 

Deleted: sandbox/odeint/branches/karsten/boost/numeric/odeint/util/ublas_permutation_matrix_resize.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/util/ublas_permutation_matrix_resize.hpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
+++ (empty file)
@@ -1,33 +0,0 @@
-/*
- * ublas_permutation_matrix_resize.hpp
- *
- * Created on: Jan 31, 2011
- * Author: karsten
- */
-
-#ifndef BOOST_NUMERIC_ODEINT_UTIL_UBLAS_PERMUTATION_MATRIX_RESIZE_HPP_
-#define BOOST_NUMERIC_ODEINT_UTIL_UBLAS_PERMUTATION_MATRIX_RESIZE_HPP_
-
-#include <boost/type_traits/integral_constant.hpp>
-#include <boost/numeric/ublas/lu.hpp>
-
-namespace boost {
-namespace numeric {
-namespace odeint {
-
-
-template< class T , class A >
-struct is_resizeable< boost::numeric::ublas::permutation_matrix< T , A > >
-{
- struct type : public boost::true_type { };
- const static bool value = type::value;
-};
-
-
-
-} // namespace odeint
-} // namespace numeric
-} // namespace boost
-
-
-#endif /* BOOST_NUMERIC_ODEINT_UTIL_UBLAS_PERMUTATION_MATRIX_RESIZE_HPP_ */

Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/util/ublas_resize.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/util/ublas_resize.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/util/ublas_resize.hpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
@@ -14,6 +14,7 @@
 
 #include <boost/numeric/ublas/vector.hpp>
 #include <boost/numeric/ublas/matrix.hpp>
+#include <boost/numeric/ublas/lu.hpp>
 
 #include <boost/type_traits/integral_constant.hpp> //for true_type and false_type
 
@@ -51,6 +52,10 @@
         }
 };
 
+
+/*
+ * specialization for vector-matrix resizing
+ */
 template< class T , class L , class A >
 struct same_size_impl< boost::numeric::ublas::matrix< T , L , A > , boost::numeric::ublas::matrix< T , L , A > >
 {
@@ -61,7 +66,36 @@
 };
 
 
+template< class T_V , class A_V , class T_M , class L_M , class A_M >
+struct resize_impl< boost::numeric::ublas::vector< T_V , A_V > , boost::numeric::ublas::matrix< T_M , L_M , A_M > >
+{
+ static void resize( const boost::numeric::ublas::vector< T_V , A_V > &x1 ,
+ boost::numeric::ublas::matrix< T_M , L_M , A_M > &x2 )
+ {
+ x2.resize( x1.size() , x1.size() );
+ }
+};
+
+template< class T_V , class A_V , class T_M , class L_M , class A_M >
+struct same_size_impl< boost::numeric::ublas::vector< T_V , A_V > , boost::numeric::ublas::matrix< T_M , L_M , A_M > >
+{
+ static bool same_size( const boost::numeric::ublas::vector< T_V , A_V > &x1 ,
+ const boost::numeric::ublas::matrix< T_M , L_M , A_M > &x2 )
+ {
+ return ( ( x1.size() == x2.size1() ) && ( x1.size() == x2.size2() ) );
+ }
+};
+
+/*
+ * specialization for boost::numeric::ublas::permutation_matrix
+ */
 
+template< class T , class A >
+struct is_resizeable< boost::numeric::ublas::permutation_matrix< T , A > >
+{
+ struct type : public boost::true_type { };
+ const static bool value = type::value;
+};
 
 
 } // namespace odeint

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/explicit_euler.hpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
@@ -2,46 +2,22 @@
 
 #include <boost/range.hpp>
 
-#include <boost/numeric/odeint/algebra/detail/for_each.hpp>
+#include <boost/numeric/odeint/algebra/range_algebra.hpp>
 #include <boost/numeric/odeint/algebra/default_operations.hpp>
+#include <boost/numeric/odeint/util/size_adjuster.hpp>
 
 template< class V >
 struct state_wrapper
 {
     typedef typename V::value_type value_type;
 
- V &m_v;
- V m_v_;
+ V m_v;
 
- state_wrapper( V &v ) : m_v( v ) { }
+ state_wrapper() : m_v() { }
 
- state_wrapper() : m_v( m_v_ ) { }
-
- typename boost::range_iterator<V>::type begin()
- { return boost::begin( m_v ); }
-
- typename boost::range_iterator<V>::type end()
- { return boost::end( m_v ); }
-
- void resize( V &v )
- {
- m_v.resize( boost::size( v ) );
- }
-
- bool same_size( V &v )
- { return ( boost::size( m_v ) == boost::size( v ) ); }
 };
 
 
-struct range_algebra
-{
- template< class S1 , class S2 , class S3 , class Op >
- static void for_each3( S1 &s1 , S2 &s2 , S3 &s3 , Op op )
- {
- boost::numeric::odeint::detail::for_each3( s1.begin() , s1.end() , s2.begin() , s3.begin() , op );
- }
-};
-
 template< typename StateType >
 class explicit_euler {
 
@@ -52,21 +28,22 @@
     typedef StateType state_type;
     typedef state_wrapper< state_type > wrapped_state_type;
 
- explicit_euler() { };
+ explicit_euler() : m_dxdt()
+ {
+ m_size_adjuster.register_state( 0 , m_dxdt.m_v );
+ };
 
     template< class System , class StateInOut >
     void do_step( System system , StateInOut &inout , const time_type &t , const time_type &dt )
     {
- state_wrapper< StateInOut > x( inout );
-
- if( !m_dxdt.same_size( inout ) )
- m_dxdt.resize( inout );
+ m_size_adjuster.adjust_size( inout );
 
         system( inout , m_dxdt.m_v , t );
 
- range_algebra::for_each3( x , x , m_dxdt , typename boost::numeric::odeint::default_operations::template scale_sum2< value_type , time_type >( 1.0 , dt ) );
+ boost::numeric::odeint::range_algebra::for_each3( inout , inout , m_dxdt.m_v , typename boost::numeric::odeint::default_operations::template scale_sum2< value_type , time_type >( 1.0 , dt ) );
     }
 
 private:
+ boost::numeric::odeint::size_adjuster< state_type , 1 > m_size_adjuster;
     wrapped_state_type m_dxdt;
 };

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp 2011-06-24 10:29:32 EDT (Fri, 24 Jun 2011)
@@ -2,6 +2,7 @@
 #include <gsl/gsl_vector.h>
 
 #include "explicit_euler.hpp"
+#include <boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp>
 
 using namespace std;
 
@@ -25,10 +26,6 @@
 
     state_type m_v;
 
- state_wrapper( state_type &v ) : m_v( v ) {
- cout << m_v->size << endl;
- }
-
     state_wrapper( )
     {
         m_v->owner = 0;
@@ -38,38 +35,6 @@
         m_v->block = 0;
     }
 
- double* begin()
- { return m_v->data; }
-
- double* end()
- { return m_v->data + m_v->size; }
-
- void resize( state_type &v )
- {
- cout << v->size << " " << m_v->owner << " " << v->owner << endl;
-
- if( m_v->owner != 0 )
- {
- gsl_block_free( m_v->block );
- }
- m_v->size = 0;
-
- cout << v->size << endl;
-
- if( v->size == 0 ) return;
-
- gsl_block *block = gsl_block_alloc( v->size );
- if( block == 0 ) throw std::bad_alloc( );
-
- m_v->data = block->data ;
- m_v->size = v->size;
- m_v->stride = 1;
- m_v->block = block;
- m_v->owner = 1;
- }
-
- bool same_size( state_type &v )
- { return ( m_v->size == v->size ); }
 };
 
 int main() {


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk