Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72749 - in sandbox/odeint/branches/karsten: boost/numeric/odeint/external/gsl boost/numeric/odeint/util libs/numeric/odeint/ideas/state_wrapper libs/numeric/odeint/test_external/gsl tex
From: mario.mulansky_at_[hidden]
Date: 2011-06-25 08:15:20


Author: mariomulansky
Date: 2011-06-25 08:15:18 EDT (Sat, 25 Jun 2011)
New Revision: 72749
URL: http://svn.boost.org/trac/boost/changeset/72749

Log:
changed gsl adapter to run with gsl_vector* instead of gsl_vector
Added:
   sandbox/odeint/branches/karsten/tex/
   sandbox/odeint/branches/karsten/tex/survey_existing_implementations.tex (contents, props changed)
Text files modified:
   sandbox/odeint/branches/karsten/boost/numeric/odeint/external/gsl/gsl_vector_adaptor.hpp | 94 ++++++++++++++-------------------------
   sandbox/odeint/branches/karsten/boost/numeric/odeint/util/size_adjuster.hpp | 1
   sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/state_wrapper/test_gsl_vector.cpp | 2
   sandbox/odeint/branches/karsten/libs/numeric/odeint/test_external/gsl/check_gsl.cpp | 14 ++--
   4 files changed, 44 insertions(+), 67 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-25 08:15:18 EDT (Sat, 25 Jun 2011)
@@ -14,7 +14,7 @@
 #define BOOST_NUMERIC_ODEINT_GSL_VECTOR_ADAPTOR_HPP_INCLUDED
 
 #include <new>
-#include <iostream>
+//#include <iostream>
 
 #include <gsl/gsl_vector.h>
 
@@ -41,8 +41,8 @@
 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 ) { }
- friend gsl_vector_iterator end_iterator( gsl_vector & );
+ explicit gsl_vector_iterator( gsl_vector *p ) : m_p( p->data ) , m_stride( p->stride ) { }
+ friend gsl_vector_iterator end_iterator( gsl_vector * );
 
 private :
 
@@ -70,14 +70,14 @@
 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 ) { }
+ explicit const_gsl_vector_iterator( const gsl_vector *p ) : m_p( p->data ) , m_stride( p->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;
- friend const_gsl_vector_iterator end_iterator( const gsl_vector & );
+ friend const_gsl_vector_iterator end_iterator( const gsl_vector * );
 
         void increment( void ) { m_p += m_stride; }
         void decrement( void ) { m_p -= m_stride; }
@@ -94,17 +94,17 @@
 bool gsl_vector_iterator::equal( const const_gsl_vector_iterator &other ) const { return this->m_p == other.m_p; }
 
 
-gsl_vector_iterator end_iterator( gsl_vector &x )
+gsl_vector_iterator end_iterator( gsl_vector *x )
 {
         gsl_vector_iterator iter( x );
- iter.m_p += iter.m_stride * x.size;
+ iter.m_p += iter.m_stride * x->size;
         return iter;
 }
 
-const_gsl_vector_iterator end_iterator( const gsl_vector &x )
+const_gsl_vector_iterator end_iterator( const gsl_vector *x )
 {
         const_gsl_vector_iterator iter( x );
- iter.m_p += iter.m_stride * x.size;
+ iter.m_p += iter.m_stride * x->size;
         return iter;
 }
 
@@ -116,13 +116,13 @@
 namespace boost
 {
         template<>
- struct range_mutable_iterator< gsl_vector >
+ struct range_mutable_iterator< gsl_vector* >
         {
                 typedef gsl_vector_iterator type;
         };
 
         template<>
- struct range_const_iterator< gsl_vector >
+ struct range_const_iterator< gsl_vector* >
         {
                 typedef const_gsl_vector_iterator type;
         };
@@ -132,25 +132,25 @@
 
 
 // template<>
-inline gsl_vector_iterator range_begin( gsl_vector &x )
+inline gsl_vector_iterator range_begin( gsl_vector *x )
 {
         return gsl_vector_iterator( x );
 }
 
 // template<>
-inline const_gsl_vector_iterator range_begin( const gsl_vector &x )
+inline const_gsl_vector_iterator range_begin( const gsl_vector *x )
 {
         return const_gsl_vector_iterator( x );
 }
 
 // template<>
-inline gsl_vector_iterator range_end( gsl_vector &x )
+inline gsl_vector_iterator range_end( gsl_vector *x )
 {
         return end_iterator( x );
 }
 
 // template<>
-inline const_gsl_vector_iterator range_end( const gsl_vector &x )
+inline const_gsl_vector_iterator range_end( const gsl_vector *x )
 {
         return end_iterator( x );
 }
@@ -167,84 +167,60 @@
 
 
 template<>
-struct is_resizeable< gsl_vector >
+struct is_resizeable< gsl_vector* >
 {
         struct type : public boost::true_type { };
         const static bool value = type::value;
 };
 
 template<>
-struct construct_impl< gsl_vector >
+struct construct_impl< gsl_vector* >
 {
- static void construct( gsl_vector &x )
+ static void construct( gsl_vector *&x )
     {
- x.owner = 0;
- x.size = 0;
- x.stride = 0;
- x.block = 0;
- x.data = 0;
+ x = gsl_vector_alloc( 1 ); // gsl wants vector length > 0, so we give 1 arbitrarily
     }
 };
 
 template<>
-struct destruct_impl< gsl_vector >
+struct destruct_impl< gsl_vector* >
 {
- static void destruct( gsl_vector &x )
+ static void destruct( gsl_vector *x )
     {
- if( x.owner != 0 )
- {
- gsl_block_free( x.block );
- }
- x.owner = 0;
- x.size = 0;
- x.stride = 0;
- x.block = 0;
- x.data = 0;
+ gsl_vector_free( x );
     }
 };
 
 
 template<>
-struct resize_impl< gsl_vector , gsl_vector >
+struct resize_impl< gsl_vector* , gsl_vector* >
 {
- static void resize( const gsl_vector &x , gsl_vector &dxdt )
+ static void resize( const gsl_vector *x , gsl_vector *&dxdt )
     {
- if( dxdt.owner != 0 )
- {
- gsl_block_free( dxdt.block );
- }
- dxdt.size = 0;
-
- if( x.size == 0 ) return;
-
- gsl_block *block = gsl_block_alloc( x.size );
- if( block == 0 ) throw std::bad_alloc( );
-
- dxdt.data = block->data ;
- dxdt.size = x.size;
- dxdt.stride = 1;
- dxdt.block = block;
- dxdt.owner = 1;
+ if( x->size == 0 ) return;
+
+ gsl_vector_free( dxdt );
+ dxdt = gsl_vector_alloc( x->size );
     }
 };
 
 template<>
-struct same_size_impl< gsl_vector , gsl_vector >
+struct same_size_impl< gsl_vector* , gsl_vector* >
 {
- static bool same_size( const gsl_vector &x1 , const gsl_vector &x2 )
+ static bool same_size( const gsl_vector *x1 , const gsl_vector *x2 )
     {
- return x1.size == x2.size;
+ return x1->size == x2->size;
     }
 };
 
 
 template<>
-struct copy_impl< gsl_vector , gsl_vector >
+struct copy_impl< gsl_vector* , gsl_vector* >
 {
- static void copy( const gsl_vector &from , gsl_vector &to )
+ static void copy( const gsl_vector *from , gsl_vector *to )
     {
- resize( from , to );
- gsl_vector_memcpy( &to , &from );
+ resize_impl< gsl_vector* , gsl_vector* >::resize( from , to );
+ gsl_vector_memcpy( to , from );
     }
 };
 

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-25 08:15:18 EDT (Sat, 25 Jun 2011)
@@ -14,6 +14,7 @@
 #define BOOST_NUMERIC_ODEINT_ADJUST_SIZE_HPP_INCLUDED
 
 #include <algorithm>
+//#include <iostream>
 
 #include <boost/noncopyable.hpp>
 #include <boost/array.hpp>

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-25 08:15:18 EDT (Sat, 25 Jun 2011)
@@ -6,7 +6,7 @@
 
 using namespace std;
 
-typedef gsl_vector *state_type;
+typedef gsl_vector state_type;
 
 const double sigma = 10.0;
 const double R = 28.0;

Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/test_external/gsl/check_gsl.cpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/test_external/gsl/check_gsl.cpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/test_external/gsl/check_gsl.cpp 2011-06-25 08:15:18 EDT (Sat, 25 Jun 2011)
@@ -21,29 +21,29 @@
 using namespace boost::unit_test;
 using namespace boost::numeric::odeint;
 
-typedef gsl_vector state_type;
+typedef gsl_vector *state_type;
 
 const double sigma = 10.0;
 const double R = 28.0;
 const double b = 8.0 / 3.0;
 
-void lorenz( const state_type &x , state_type &dxdt , double t )
+void lorenz( const state_type x , state_type dxdt , double t )
 {
- gsl_vector_set( &dxdt , 0 , sigma * ( gsl_vector_get(&x , 1 ) - gsl_vector_get( &x , 0 ) ) );
- gsl_vector_set( &dxdt , 1 , R * gsl_vector_get( &x , 0 ) - gsl_vector_get( &x , 1 ) - gsl_vector_get( &x , 0 ) * gsl_vector_get( &x , 2) );
- gsl_vector_set( &dxdt , 2 , gsl_vector_get( &x , 0 ) * gsl_vector_get( &x , 1 ) - b * gsl_vector_get( &x , 2) );
+ gsl_vector_set( dxdt , 0 , sigma * ( gsl_vector_get(x , 1 ) - gsl_vector_get( x , 0 ) ) );
+ gsl_vector_set( dxdt , 1 , R * gsl_vector_get( x , 0 ) - gsl_vector_get( x , 1 ) - gsl_vector_get( x , 0 ) * gsl_vector_get( x , 2) );
+ gsl_vector_set( dxdt , 2 , gsl_vector_get( x , 0 ) * gsl_vector_get( x , 1 ) - b * gsl_vector_get( x , 2) );
 }
 
 BOOST_AUTO_TEST_CASE( gsl )
 {
     explicit_euler< state_type > euler;
 
- state_type *x = gsl_vector_alloc( 3 );
+ state_type x = gsl_vector_alloc( 3 );
     gsl_vector_set( x , 0 , 1.0);
     gsl_vector_set( x , 1 , 1.0);
     gsl_vector_set( x , 2 , 2.0);
 
- euler.do_step( lorenz , *x , 0.0 , 0.1 );
+ euler.do_step( lorenz , x , 0.0 , 0.1 );
 
     //cout << gsl_vector_get( x , 0 ) << " " << gsl_vector_get( x , 1 ) << " " << gsl_vector_get( x , 2 ) << endl;
 

Added: sandbox/odeint/branches/karsten/tex/survey_existing_implementations.tex
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/tex/survey_existing_implementations.tex 2011-06-25 08:15:18 EDT (Sat, 25 Jun 2011)
@@ -0,0 +1,42 @@
+\documentclass[a4paper,10pt]{article}
+
+\usepackage{a4wide}
+\usepackage[utf8x]{inputenc}
+\usepackage{url}
+
+\usepackage{amsmath}
+\usepackage{amsfonts}
+\usepackage{amssymb}
+
+\usepackage{color}
+
+\usepackage[final]{listings}
+
+\definecolor{dark-green}{rgb}{0,0.4,0}
+\definecolor{dark-red}{rgb}{0.2,0,0}
+\definecolor{gray}{gray}{0.50}
+
+\lstset{
+%backgroundcolor=\color{gray},
+%frame=single,
+basicstyle=\ttfamily,
+keywordstyle=\color{dark-green},
+identifierstyle=,
+commentstyle=\color{gray}\normalfont\rmfamily\itshape,
+stringstyle=\color{dark-red},
+language=c++,
+showstringspaces=false
+}
+
+\newcommand{\rmd}{\mathrm{d}}
+
+\newcommand{\odeint}{{\tt odeint}}
+
+\title{Survey of Existing ODE libraries}
+
+\begin{document}
+ \maketitle
+
+\section{Numerical Recipes}
+
+\end{document}


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