|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64005 - in sandbox/odeint/branches/karsten: boost/numeric/odeint/algebra libs/numeric/odeint/test
From: karsten.ahnert_at_[hidden]
Date: 2010-07-14 02:41:43
Author: karsten
Date: 2010-07-14 02:41:39 EDT (Wed, 14 Jul 2010)
New Revision: 64005
URL: http://svn.boost.org/trac/boost/changeset/64005
Log:
small changes in algebra
Added:
sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/gsl_vector_adaptor.hpp (contents, props changed)
- copied, changed from r63841, /sandbox/odeint/branches/karsten/libs/numeric/odeint/test/gsl_vector_adaptor.hpp
Removed:
sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/tr1_array_resize.hpp
sandbox/odeint/branches/karsten/libs/numeric/odeint/test/gsl_vector_adaptor.hpp
Text files modified:
sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/gsl_vector_adaptor.hpp | 156 +++++++++++++++++++++++++++++++++-----
sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/standard_resize.hpp | 29 +++++++
sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_stepper_concepts.cpp | 159 ++++++---------------------------------
3 files changed, 185 insertions(+), 159 deletions(-)
Copied: sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/gsl_vector_adaptor.hpp (from r63841, /sandbox/odeint/branches/karsten/libs/numeric/odeint/test/gsl_vector_adaptor.hpp)
==============================================================================
--- /sandbox/odeint/branches/karsten/libs/numeric/odeint/test/gsl_vector_adaptor.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/gsl_vector_adaptor.hpp 2010-07-14 02:41:39 EDT (Wed, 14 Jul 2010)
@@ -10,37 +10,147 @@
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
-#ifndef GSL_VECTOR_ADAPTOR_HPP_INCLUDED
-#define GSL_VECTOR_ADAPTOR_HPP_INCLUDED
+#ifndef BOOST_NUMERIC_ODEINT_GSL_VECTOR_ADAPTOR_HPP_INCLUDED
+#define BOOST_NUMERIC_ODEINT_GSL_VECTOR_ADAPTOR_HPP_INCLUDED
#include <gsl/gsl_vector.h>
-
#include <boost/range.hpp>
-namespace boost
+#include <boost/iterator/iterator_facade.hpp>
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+
+class const_gsl_vector_iterator;
+
+/*
+ * defines an iterator for gsl_vector
+ */
+class gsl_vector_iterator : public boost::iterator_facade< gsl_vector_iterator , double , boost::random_access_traversal_tag >
+{
+public :
+
+ gsl_vector_iterator( void ): m_p(0) , m_stride( 0 ) { }
+ explicit gsl_vector_iterator( gsl_vector &p ) : m_p( p.data ) , m_stride( p.stride ) { }
+ gsl_vector_iterator( gsl_vector_iterator &p ) : m_p( p.m_p ) , m_stride( p.m_stride ) { }
+
+private :
+
+ friend class boost::iterator_core_access;
+ friend class const_gsl_vector_iterator;
+
+ void increment( void ) { m_p += m_stride; }
+ void decrement( void ) { m_p -= m_stride; }
+ void advance( ptrdiff_t n ) { m_p += n*m_stride; }
+ bool equal( const gsl_vector_iterator &other ) const { return this->m_p == other.m_p; }
+ bool equal( const const_gsl_vector_iterator &other ) const;
+ double& dereference( void ) const { return *m_p; }
+
+ double *m_p;
+ size_t m_stride;
+};
+
+/*
+ * defines an iterator for gsl_vector
+ */
+class const_gsl_vector_iterator : public boost::iterator_facade< const_gsl_vector_iterator , double , boost::random_access_traversal_tag >
+{
+public :
+
+ const_gsl_vector_iterator( void ): m_p(0) , m_stride( 0 ) { }
+ explicit const_gsl_vector_iterator( const gsl_vector &p ) : m_p( p.data ) , m_stride( p.stride ) { }
+ const_gsl_vector_iterator( const const_gsl_vector_iterator &p ) : m_p( p.m_p ) , m_stride( p.m_stride ) { }
+ const_gsl_vector_iterator( const gsl_vector_iterator &p ) : m_p( p.m_p ) , m_stride( p.m_stride ) { }
+
+private :
+
+ friend class boost::iterator_core_access;
+ friend class gsl_vector_iterator;
+
+ void increment( void ) { m_p += m_stride; }
+ void decrement( void ) { m_p -= m_stride; }
+ void advance( ptrdiff_t n ) { m_p += n*m_stride; }
+ bool equal( const const_gsl_vector_iterator &other ) const { return this->m_p == other.m_p; }
+ bool equal( const gsl_vector_iterator &other ) const { return this->m_p == other.m_p; }
+ const double& dereference( void ) const { return *m_p; }
+
+ const double *m_p;
+ size_t m_stride;
+};
+
+bool gsl_vector_iterator::equal( const const_gsl_vector_iterator &other ) const { return this->m_p == other.m_p; }
+
+
+} // namespace odeint
+} // namespace numeric
+} // namespace boost
+
+
+namespace boost {
+
+
+
+/*
+ * specialization of range_iterator for gsl_vector_iterator
+ */
+template<>
+struct range_iterator< gsl_vector >
+{
+ typedef boost::numeric::odeint::gsl_vector_iterator type;
+};
+
+/*
+ * specialization of range_iterator for const_gsl_vector_iterator
+ */
+template<>
+struct range_iterator< const gsl_vector >
{
- // ToDo define gsl_vector_iterator which increments x by stride
+ typedef boost::numeric::odeint::const_gsl_vector_iterator type;
+};
+
+
+/*
+ * specialization of begin for gsl_vector
+ */
+template<>
+range_iterator< gsl_vector >::type begin( gsl_vector &r )
+{
+ return boost::numeric::odeint::gsl_vector_iterator( r );
+}
- template<>
- struct range_iterator< gsl_vector >
- {
- typedef double* type;
- };
-
- template<>
- range_iterator< gsl_vector >::type begin( gsl_vector &r )
- {
- return r.data;
- }
-
- template<>
- range_iterator< gsl_vector >::type end( gsl_vector &r )
- {
- return r.data + r.size;
- }
+/*
+ * specialization of begin for const gsl_vector
+ */
+template<>
+range_iterator< const gsl_vector >::type begin( const gsl_vector &r )
+{
+ return boost::numeric::odeint::const_gsl_vector_iterator( r );
+}
+/*
+ * specialization of end for gsl_vector
+ */
+template<>
+range_iterator< gsl_vector >::type end( gsl_vector &r )
+{
+ return boost::numeric::odeint::gsl_vector_iterator( r ) + r.size * r.stride ;
+}
+/*
+ * specialization of end for const gsl_vector
+ */
+template<>
+range_iterator< const gsl_vector >::type end( const gsl_vector &r )
+{
+ return boost::numeric::odeint::const_gsl_vector_iterator( r ) + r.size * r.stride ;
}
-#endif // GSL_VECTOR_ADAPTOR_HPP_INCLUDED
+
+} // namespace boost
+
+
+
+#endif // BOOST_NUMERIC_ODEINT_GSL_VECTOR_ADAPTOR_HPP_INCLUDED
Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/standard_resize.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/standard_resize.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/standard_resize.hpp 2010-07-14 02:41:39 EDT (Wed, 14 Jul 2010)
@@ -13,15 +13,42 @@
#ifndef BOOST_BOOST_NUMERIC_ODEINT_STANDARD_RESIZE_HPP_INCLUDED
#define BOOST_BOOST_NUMERIC_ODEINT_STANDARD_RESIZE_HPP_INCLUDED
+#include <vector>
+#include <list>
+
namespace boost {
namespace numeric {
namespace odeint {
-// ToDo : make default false and
+
+/*
+ * by default any type is not resizable
+ */
template< class Container >
struct is_resizeable
{
+ struct type : public boost::false_type { };
+ const static bool value = type::value;
+};
+
+/*
+ * specialization for std::vector
+ */
+template< class V, class A >
+struct is_resizeable< std::vector< V , A > >
+{
+ struct type : public boost::true_type { };
+ const static bool value = type::value;
+};
+
+
+/*
+ * specialization for std::list
+ */
+template< class V , class A >
+struct is_resizeable< std::list< V , A > >
+{
struct type : public boost::true_type { };
const static bool value = type::value;
};
Deleted: sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/tr1_array_resize.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/tr1_array_resize.hpp 2010-07-14 02:41:39 EDT (Wed, 14 Jul 2010)
+++ (empty file)
@@ -1,34 +0,0 @@
-/*
- boost header: BOOST_NUMERIC_ODEINT/tr1_array_resize.hpp
-
- Copyright 2009 Karsten Ahnert
- Copyright 2009 Mario Mulansky
- Copyright 2009 Andre Bergner
-
- Distributed under the Boost Software License, Version 1.0.
- (See accompanying file LICENSE_1_0.txt or
- copy at http://www.boost.org/LICENSE_1_0.txt)
-*/
-
-#ifndef BOOST_BOOST_NUMERIC_ODEINT_TR1_ARRAY_RESIZE_HPP_INCLUDED
-#define BOOST_BOOST_NUMERIC_ODEINT_TR1_ARRAY_RESIZE_HPP_INCLUDED
-
-
-namespace boost {
-namespace numeric {
-namespace odeint {
-
-template< class T , size_t N >
-struct is_resizeable< std::tr1::array< T , N > >
-{
- struct type : public boost::false_type { };
- const static bool value = type::value;
-};
-
-
-} // odeint
-} // numeric
-} // boost
-
-
-#endif //BOOST_BOOST_NUMERIC_ODEINT_TR1_ARRAY_RESIZE_HPP_INCLUDED
Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_stepper_concepts.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_stepper_concepts.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test/check_stepper_concepts.cpp 2010-07-14 02:41:39 EDT (Wed, 14 Jul 2010)
@@ -17,10 +17,13 @@
#include <boost/test/unit_test.hpp>
#include <boost/numeric/odeint.hpp>
-#include <boost/numeric/odeint/algebra/tr1_array_resize.hpp>
+#include <boost/numeric/odeint/algebra/vector_space_algebra.hpp>
+#include <boost/numeric/odeint/algebra/gsl_vector_adaptor.hpp>
#include "vector_space_1d.hpp"
-#include "gsl_vector_adaptor.hpp"
+
+
+
using std::vector;
@@ -84,143 +87,27 @@
BOOST_CHECK_SMALL( fabs( xval - 0.1 ) , eps );
}
-
-//template< class ErrorStepper >
-//void check_error_stepper_concept(
-// ErrorStepper &stepper ,
-// typename ErrorStepper::order_type order_error_step ,
-// typename ErrorStepper::order_type order_error )
-//{
-// typedef ErrorStepper stepper_type;
-// typedef typename stepper_type::container_type container_type;
-// typedef typename stepper_type::traits_type traits_type;
-// typedef typename stepper_type::value_type value_type;
-// typedef typename stepper_type::order_type order_type;
-// typedef typename stepper_type::time_type time_type;
-//
-// constant_system< container_type > con;
-//
-// BOOST_CHECK_EQUAL( order_error_step , stepper.order_error_step() );
-// BOOST_CHECK_EQUAL( order_error , stepper.order_error() );
-//
-// container_type x( 1 , 0.0 ) , xerr( 1 , 0.0 );
-// stepper.adjust_size( x );
-//
-// stepper.do_step( con , x , 0.0 , 0.1 , xerr );
-// BOOST_CHECK_SMALL( fabs( x[0] - 0.1 ) , eps );
-// BOOST_CHECK_SMALL( fabs( xerr[0] ) , eps );
-//
-// container_type dxdt( 1 , 1.0 );
-// stepper.do_step( con , x , dxdt , 0.0 , 0.1 , xerr );
-// BOOST_CHECK_SMALL( fabs( x[0] - 0.2 ) , eps );
-// BOOST_CHECK_SMALL( fabs( xerr[0] ) , eps );
-//
-// stepper_type stepper2( x );
-// stepper_type stepper3;
-//}
-//
-//
-//
-//
-//
-//template< class ControlledErrorStepper >
-//void check_controlled_stepper_concept(
-// ControlledErrorStepper &stepper
-// )
-//{
-// typedef ControlledErrorStepper stepper_type;
-// typedef typename stepper_type::container_type container_type;
-// typedef typename stepper_type::traits_type traits_type;
-// typedef typename stepper_type::value_type value_type;
-// typedef typename stepper_type::order_type order_type;
-// typedef typename stepper_type::time_type time_type;
-//
-//// constant_system< container_type > con;
-//
-// container_type x( 1 , 0.0 );
-// stepper.adjust_size( x );
-//}
-//
-//
-//
-//
-//
-//void test_euler_concept()
-//{
-// stepper_euler< std::vector<double> > stepper;
-// check_stepper_concept( stepper , 1 );
-//}
-//
-//
-//
-//void test_half_step_euler_concept()
-//{
-// stepper_half_step< stepper_euler< std::vector< double > > > stepper;
-// check_stepper_concept( stepper , 1 );
-// check_error_stepper_concept( stepper , 1 , 2 );
-//}
-//
-///*
-//void test_midpoint_concept()
-//{
-// stepper_midpoint< std::vector< double > > stepper;
-// stepper.set_step_number( 4 );
-// unsigned short step_number = stepper.get_step_number();
-// step_number = 5; // no warnings
-// check_stepper_concept( stepper , 2 );
-//}
-//
-//void test_rk4_classical_concept()
+//void test_euler_with_vector( void )
//{
-// stepper_rk4_classical< std::vector<double> > stepper;
-// check_stepper_concept( stepper , 4 );
+// state_type1 x( 1 , 0.0 );
+// explicit_euler< state_type1 > euler;
+// check_stepper_concept( euler , constant_system1 , x );
//}
-//
-//void test_rk4_concept()
-//{
-// stepper_rk4< std::vector<double> > stepper;
-// check_stepper_concept( stepper , 4 );
-//}
-//
-//void test_rk5_ck_concept()
-//{
-// stepper_rk5_ck< std::vector<double> > stepper;
-// check_error_stepper_concept( stepper , 5 , 5 );
-//}
-//
-//void test_rk78_fehlberg_concept()
-//{
-// stepper_rk78_fehlberg< std::vector<double> > stepper;
-// check_stepper_concept( stepper , 8 );
-// check_error_stepper_concept( stepper , 7 , 8 );
-//}
-//*/
-//
-//void test_controlled_stepper_standard_concept()
-//{
-// typedef stepper_euler< std::vector< double > > stepper_type;
-// typedef controlled_stepper_standard< stepper_type > controlled_stepper_type;
-//
-// controlled_stepper_type stepper( 1.0 , 1.0 , 1.0 , 1.0 );
-// check_controlled_stepper_concept( stepper );
-// }
-//
-
-void test_euler_with_vector( void )
+void test_euler_with_gsl_vector( void )
{
- state_type1 x( 1 , 0.0 );
- explicit_euler< state_type1 > euler;
- check_stepper_concept( euler , constant_system1 , x );
+ state_type2 *x = gsl_vector_alloc( 1 );
+ explicit_euler< state_type2 > euler;
+ check_stepper_concept( euler , constant_system2 , *x );
}
-void test_euler_with_array( void )
-{
- state_type4 x;
- x[0] = 0.0;
- explicit_euler< state_type4 > euler;
- check_stepper_concept( euler , constant_system4 , x );
-}
+//void test_euler_with_array( void )
+//{
+// state_type4 x;
+// x[0] = 0.0;
+// explicit_euler< state_type4 > euler;
+// check_stepper_concept( euler , constant_system4 , x );
+//}
void test_runge_kutta_error_ck_with_vector( void )
{
@@ -236,9 +123,11 @@
- test->add( BOOST_TEST_CASE( &test_euler_with_vector ) );
+// test->add( BOOST_TEST_CASE( &test_euler_with_vector ) );
+// test->add( BOOST_TEST_CASE( &test_euler_with_array ) );
+ test->add( BOOST_TEST_CASE( &test_euler_with_gsl_vector ) );
+
-// test->add( BOOST_TEST_CASE( &test_euler_concept ) );
return test;
}
Deleted: sandbox/odeint/branches/karsten/libs/numeric/odeint/test/gsl_vector_adaptor.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/test/gsl_vector_adaptor.hpp 2010-07-14 02:41:39 EDT (Wed, 14 Jul 2010)
+++ (empty file)
@@ -1,46 +0,0 @@
-/*
- boost header: xyz/gsl_vector_adaptor.hpp
-
- Copyright 2009 Karsten Ahnert
- Copyright 2009 Mario Mulansky
- Copyright 2009 Andre Bergner
-
- Distributed under the Boost Software License, Version 1.0.
- (See accompanying file LICENSE_1_0.txt or
- copy at http://www.boost.org/LICENSE_1_0.txt)
-*/
-
-#ifndef GSL_VECTOR_ADAPTOR_HPP_INCLUDED
-#define GSL_VECTOR_ADAPTOR_HPP_INCLUDED
-
-#include <gsl/gsl_vector.h>
-
-#include <boost/range.hpp>
-
-namespace boost
-{
- // ToDo define gsl_vector_iterator which increments x by stride
-
- template<>
- struct range_iterator< gsl_vector >
- {
- typedef double* type;
- };
-
- template<>
- range_iterator< gsl_vector >::type begin( gsl_vector &r )
- {
- return r.data;
- }
-
- template<>
- range_iterator< gsl_vector >::type end( gsl_vector &r )
- {
- return r.data + r.size;
- }
-
-
-
-}
-
-#endif // GSL_VECTOR_ADAPTOR_HPP_INCLUDED
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