Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58244 - in sandbox/odeint: . branches/karsten/boost/numeric/odeint
From: karsten.ahnert_at_[hidden]
Date: 2009-12-08 16:05:01


Author: karsten
Date: 2009-12-08 16:05:00 EST (Tue, 08 Dec 2009)
New Revision: 58244
URL: http://svn.boost.org/trac/boost/changeset/58244

Log:
added container traits to karstens branch
Added:
   sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits.hpp (contents, props changed)
   sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_blitz_array.hpp (contents, props changed)
   sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_mtl4_dense2d.hpp (contents, props changed)
   sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_tr1_array.hpp (contents, props changed)
   sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_ublas_matrix.hpp (contents, props changed)
Text files modified:
   sandbox/odeint/Jamroot | 3 ---
   1 files changed, 0 insertions(+), 3 deletions(-)

Modified: sandbox/odeint/Jamroot
==============================================================================
--- sandbox/odeint/Jamroot (original)
+++ sandbox/odeint/Jamroot 2009-12-08 16:05:00 EST (Tue, 08 Dec 2009)
@@ -26,7 +26,4 @@
 local boost-root = [ modules.peek : BOOST_ROOT ] ;
 local explore-header-include = $(top)/../.. ;
 
-use-project /boost/regex : $(boost-root)/libs/regex/build ;
-
-
 ##################################################################

Added: sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits.hpp 2009-12-08 16:05:00 EST (Tue, 08 Dec 2009)
@@ -0,0 +1,81 @@
+/* Boost odeint/container_traits.hpp header file
+
+ Copyright 2009 Karsten Ahnert
+ Copyright 2009 Mario Mulansky
+
+ This file includes container_traits functionality for containers
+
+ container_traits
+
+ 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_NUMERIC_ODEINT_CONTAINER_TRAITS_HPP
+#define BOOST_NUMERIC_ODEINT_CONTAINER_TRAITS_HPP
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+ template< class Container >
+ struct container_traits
+ {
+
+ typedef Container container_type;
+
+ typedef typename container_type::value_type value_type;
+ typedef typename container_type::iterator iterator;
+ typedef typename container_type::const_iterator const_iterator;
+
+
+ static void resize( const container_type &x , container_type &dxdt )
+ {
+ dxdt.resize( x.size() );
+ }
+
+ static bool same_size(
+ const container_type &x1 ,
+ const container_type &x2
+ )
+ {
+ return (x1.size() == x2.size());
+ }
+
+ static void adjust_size(
+ const container_type &x1 ,
+ container_type &x2
+ )
+ {
+ if( !same_size( x1 , x2 ) ) resize( x1 , x2 );
+ }
+
+ static iterator begin( container_type &x )
+ {
+ return x.begin();
+ }
+
+ static const_iterator begin( const container_type &x )
+ {
+ return x.begin();
+ }
+
+ static iterator end( container_type &x )
+ {
+ return x.end();
+ }
+
+ static const_iterator end( const container_type &x )
+ {
+ return x.end();
+ }
+ };
+
+
+} // namespace odeint
+} // namespace numeric
+} // namespace boost
+
+
+#endif // BOOST_NUMERIC_ODEINT_CONTAINER_TRAITS_HPP

Added: sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_blitz_array.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_blitz_array.hpp 2009-12-08 16:05:00 EST (Tue, 08 Dec 2009)
@@ -0,0 +1,85 @@
+/*
+ boost header: numeric/odeint/blitz_container_traits.hpp
+
+ Copyright 2009 Karsten Ahnert
+ Copyright 2009 Mario Mulansky
+ Copyright 2009 Andre Bergner
+
+ Container traits for blitz::Array.
+
+ 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_NUMERIC_ODEINT_CONTAINER_TRAITS_BLITZ_ARRAY_HPP_INCLUDED
+#define BOOST_NUMERIC_ODEINT_CONTAINER_TRAITS_BLITZ_ARRAY_HPP_INCLUDED
+
+#include <cstdlib>
+#include "container_traits.hpp"
+#include <blitz/array.h>
+
+#include<iostream>
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+ template< typename T , int n >
+ struct container_traits< blitz::Array< T , n > >
+ {
+
+ typedef blitz::Array< T , n > container_type;
+ typedef T value_type;
+ typedef typename container_type::iterator iterator;
+ typedef typename container_type::const_iterator const_iterator;
+
+
+
+ static void resize( const container_type &x , container_type &dxdt )
+ {
+ //dxdt.resize( x.shape() );
+ dxdt.resizeAndPreserve( x.shape() );
+ }
+
+ static bool same_size( const container_type &x1 , const container_type &x2 )
+ {
+ for( int d=0; d<x1.dimensions(); d++ )
+ if( x1.extent(d) != x2.extent(d) )
+ return false;
+ return true;
+ }
+
+ static void adjust_size( const container_type &x1 , container_type &x2 )
+ {
+ //if( !same_size( x1 , x2 ) ) resize( x1 , x2 );
+ x2.resizeAndPreserve( x1.shape() );
+ }
+
+ static iterator begin( container_type &x )
+ {
+ return x.begin();
+ }
+
+ static const_iterator begin( const container_type &x )
+ {
+ return x.begin();
+ }
+
+ static iterator end( container_type &x )
+ {
+ return x.end();
+ }
+
+ static const_iterator end( const container_type &x )
+ {
+ return x.end();
+ }
+ };
+
+} // namespace odeint
+} // namespace numeric
+} // namespace boost
+
+
+#endif //BOOST_NUMERIC_ODEINT_CONTAINER_TRAITS_BLITZ_ARRAY_HPP_INCLUDED

Added: sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_mtl4_dense2d.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_mtl4_dense2d.hpp 2009-12-08 16:05:00 EST (Tue, 08 Dec 2009)
@@ -0,0 +1,170 @@
+/*
+ boost header: numeric/odeint/mtl4_dense2d_container_traits.hpp
+
+ Copyright 2009 Karsten Ahnert
+ Copyright 2009 Mario Mulansky
+ Copyright 2009 Andre Bergner
+
+ Container traits for mtl4::dense2D matrices
+
+ 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_NUMERIC_ODEINT_CONTAINER_TRAITS_MTL4_DENSE2D_HPP_INCLUDED
+#define BOOST_NUMERIC_ODEINT_CONTAINER_TRAITS_MTL4_DENSE2D_HPP_INCLUDED
+
+#include <boost/numeric/odeint/container_traits.hpp>
+#include <boost/numeric/mtl/mtl.hpp>
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+ template <typename Value, typename Parameters >
+ struct container_traits< mtl::dense2D< Value , Parameters > >
+ {
+
+ typedef mtl::matrix::dense2D< Value , Parameters > container_type;
+
+ typedef typename container_type::value_type value_type;
+
+ typedef typename mtl::traits::range_generator<
+ mtl::tag::all, container_type >::type cursor;
+ typedef typename mtl::traits::value< container_type >::type value_map;
+ typedef typename mtl::traits::const_value<
+ container_type >::type const_value_map;
+ typedef mtl::utilities::iterator_adaptor<
+ value_map, cursor, value_type > iterator;
+ typedef mtl::utilities::iterator_adaptor<
+ const_value_map, cursor, value_type > const_iterator;
+
+ static void resize( const container_type &x , container_type &dxdt )
+ {
+ dxdt = container_type( x.num_rows(), x.num_cols() );
+ }
+
+ static bool same_size(
+ const container_type &x1 ,
+ const container_type &x2
+ )
+ {
+ return ( (x1.num_rows() == x2.num_rows()) && (x1.num_cols() == x2.num_cols()));
+ }
+
+ static void adjust_size(
+ const container_type &x1 ,
+ container_type &x2
+ )
+ {
+ if( !same_size( x1 , x2 ) ) resize( x1 , x2 );
+ }
+
+ static iterator begin( container_type &x )
+ {
+ cursor c = mtl::begin< mtl::tag::all >(x);
+ value_map v(x);
+ return iterator(v, c);
+ }
+
+ static const_iterator begin( const container_type &x )
+ {
+ cursor c = mtl::begin< mtl::tag::all >(x);
+ const_value_map v(x);
+ return const_iterator(v, c);
+ }
+
+ static iterator end( container_type &x )
+ {
+ cursor c = mtl::end< mtl::tag::all >(x);
+ value_map v(x);
+ return iterator(v, c);
+ }
+
+ static const_iterator end( const container_type &x )
+ {
+ cursor c = mtl::end< mtl::tag::all >(x);
+ const_value_map v(x);
+ return const_iterator(v, c);
+ }
+
+ };
+
+
+
+} // namespace odeint
+} // namespace numeric
+} // namespace boost
+
+
+
+/* Template Specialization to provide += operator for iterator return type */
+namespace mtl { namespace utilities { namespace detail {
+
+template <typename Cursor, typename ValueType>
+struct iterator_proxy<typename mtl::traits::value< mtl::matrix::dense2D< ValueType > >::type, Cursor, ValueType>
+{
+ typedef iterator_proxy self;
+ typedef typename mtl::traits::value< mtl::matrix::dense2D< ValueType > >::type property_map;
+
+ iterator_proxy(property_map map, Cursor cursor)
+ : map(map), cursor(cursor) {}
+
+ operator ValueType() const
+ {
+ return map(*cursor);
+ }
+
+ self& operator=(ValueType const& value)
+ {
+ map(*cursor, value);
+ return *this;
+ }
+
+ self& operator+=(ValueType const& value)
+ {
+ map( *cursor, value + map(*cursor) );
+ return *this;
+ }
+
+ property_map map;
+ Cursor cursor;
+};
+
+}}} // namespace mtl::utilities::detail
+
+
+// define iterator traits for dense2D iterators
+namespace std {
+
+template <typename Value_Map, typename Cursor , typename Value >
+struct iterator_traits<
+ mtl::utilities::iterator_adaptor< Value_Map, Cursor, Value >
+>
+{
+ typedef Value value_type;
+ typedef int difference_type; // ?
+ typedef Value* pointer;
+ typedef Value& reference;
+ typedef std::random_access_iterator_tag iterator_category;
+};
+
+
+ /*
+template <typename Value, typename Parameters >
+struct iterator_traits<
+ typename boost::numeric::odeint::container_traits< mtl::dense2D< Value , Parameters > >::const_iterator
+>
+{
+ typedef const Value value_type;
+ typedef int difference_type; // ?
+ typedef const Value* pointer;
+ typedef const Value& reference;
+ typedef std::random_access_iterator_tag iterator_category;
+};
+ */
+}
+
+
+#endif //BOOST_NUMERIC_ODEINT_CONTAINER_TRAITS_MTL4_DENSE2D_HPP_INCLUDED

Added: sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_tr1_array.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_tr1_array.hpp 2009-12-08 16:05:00 EST (Tue, 08 Dec 2009)
@@ -0,0 +1,83 @@
+/*
+ boost header: numeric/odeint/container_traits_tr1_array.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_NUMERIC_ODEINT_CONTAINER_TRAITS_TR1_ARRAY_HPP_INCLUDED
+#define BOOST_NUMERIC_ODEINT_CONTAINER_TRAITS_TR1_ARRAY_HPP_INCLUDED
+
+#include <tr1/array>
+#include <boost/numeric/odeint/container_traits.hpp>
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+ // Template Specialization for fixed size array - no resizing can happen
+ template< class T , size_t N >
+ struct container_traits< std::tr1::array< T , N > >
+ {
+ public:
+
+ typedef std::tr1::array< T , N > container_type;
+ typedef typename container_type::value_type value_type;
+ typedef typename container_type::iterator iterator;
+ typedef typename container_type::const_iterator const_iterator;
+
+
+ static void resize( const container_type &x , container_type &dxdt )
+ {
+ throw; // should never be called
+ }
+
+ static const bool same_size(
+ const container_type &x1 ,
+ const container_type &x2
+ )
+ {
+ return true; // if this was false, the code wouldn't compile
+ }
+
+ static void adjust_size(
+ const container_type &x1 ,
+ container_type &x2
+ )
+ {
+ if( !same_size( x1 , x2 ) ) throw;
+ }
+
+ static iterator begin( container_type &x )
+ {
+ return x.begin();
+ }
+
+ static const_iterator begin( const container_type &x )
+ {
+ return x.begin();
+ }
+
+ static iterator end( container_type &x )
+ {
+ return x.end();
+ }
+
+ static const_iterator end( const container_type &x )
+ {
+ return x.end();
+ }
+ };
+
+
+} // namespace odeint
+} // namespace numeric
+} // namespace boost
+
+
+#endif //BOOST_NUMERIC_ODEINT_CONTAINER_TRAITS_TR1_ARRAY_HPP_INCLUDED

Added: sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_ublas_matrix.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/container_traits_ublas_matrix.hpp 2009-12-08 16:05:00 EST (Tue, 08 Dec 2009)
@@ -0,0 +1,82 @@
+/*
+ boost header: numeric/odeint/ublas_matrix_container_traits.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_NUMERIC_ODEINT_UBLAS_MATRIX_CONTAINER_TRAITS_HPP_INCLUDED
+#define BOOST_NUMERIC_ODEINT_UBLAS_MATRIX_CONTAINER_TRAITS_HPP_INCLUDED
+
+#include "container_traits.hpp"
+#include <boost/numeric/ublas/matrix.hpp>
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+
+
+ template<class T, class L, class A>
+ struct container_traits< boost::numeric::ublas::matrix< T , L , A > >
+ {
+
+ typedef boost::numeric::ublas::matrix< T , L , A > container_type;
+ typedef typename container_type::value_type value_type;
+ typedef typename container_type::array_type::iterator iterator;
+ typedef typename container_type::array_type::const_iterator const_iterator;
+
+
+
+ static void resize( const container_type &x , container_type &dxdt )
+ {
+ dxdt.resize( x.size1() , x.size2() );
+ }
+
+ static bool same_size(
+ const container_type &x1 ,
+ const container_type &x2
+ )
+ {
+ return ( ( x1.size1() == x2.size1() ) && ( x1.size2() == x2.size2() ) );
+ }
+
+ static void adjust_size(
+ const container_type &x1 ,
+ container_type &x2
+ )
+ {
+ if( !same_size( x1 , x2 ) ) resize( x1 , x2 );
+ }
+
+ static iterator begin( container_type &x )
+ {
+ return x.data().begin();
+ }
+
+ static const_iterator begin( const container_type &x )
+ {
+ return x.data().begin();
+ }
+
+ static iterator end( container_type &x )
+ {
+ return x.data().end();
+ }
+
+ static const_iterator end( const container_type &x )
+ {
+ return x.data().end();
+ }
+ };
+
+} // namespace odeint
+} // namespace numeric
+} // namespace boost
+
+
+#endif //BOOST_NUMERIC_ODEINT_UBLAS_MATRIX_CONTAINER_TRAITS_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