Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59023 - in sandbox/numeric_bindings/boost/numeric/bindings: . detail ublas
From: rutger_at_[hidden]
Date: 2010-01-15 03:43:35


Author: rutger
Date: 2010-01-15 03:43:34 EST (Fri, 15 Jan 2010)
New Revision: 59023
URL: http://svn.boost.org/trac/boost/changeset/59023

Log:
added ublas' matrix_column to the adaptor stuff. If you would like to have read/write column wrappers, use the one of the bindings.

Text files modified:
   sandbox/numeric_bindings/boost/numeric/bindings/column.hpp | 7 +++--
   sandbox/numeric_bindings/boost/numeric/bindings/detail/offset.hpp | 41 ++++++++++++++++++++++++---------------
   sandbox/numeric_bindings/boost/numeric/bindings/row.hpp | 8 ++++--
   sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix_proxy.hpp | 36 ++++++++++++++++++++++++++++++++++
   sandbox/numeric_bindings/boost/numeric/bindings/ublas/vector_proxy.hpp | 2
   5 files changed, 70 insertions(+), 24 deletions(-)

Modified: sandbox/numeric_bindings/boost/numeric/bindings/column.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/column.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/column.hpp 2010-01-15 03:43:34 EST (Fri, 15 Jan 2010)
@@ -11,6 +11,7 @@
 
 #include <boost/numeric/bindings/begin.hpp>
 #include <boost/numeric/bindings/detail/adaptable_type.hpp>
+#include <boost/numeric/bindings/detail/offset.hpp>
 #include <boost/numeric/bindings/size.hpp>
 #include <boost/numeric/bindings/stride.hpp>
 #include <boost/numeric/bindings/value.hpp>
@@ -51,12 +52,12 @@
 
     static typename result_of::begin_value< T >::type begin_value( Id& id ) {
         return bindings::begin_value( id.get() ) +
- id.m_index * bindings::stride2( id.get() );
+ offset( id.get(), 0, id.m_index );
     }
 
     static typename result_of::end_value< T >::type end_value( Id& id ) {
- // TODO subtract some stuff from the true end
- return bindings::end_value( id.get() );
+ return bindings::begin_value( id.get() ) +
+ offset( id.get(), size1(id), id.m_index );
     }
 
     static typename result_of::stride1<T>::type stride1( const Id& id ) {

Modified: sandbox/numeric_bindings/boost/numeric/bindings/detail/offset.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/detail/offset.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/offset.hpp 2010-01-15 03:43:34 EST (Fri, 15 Jan 2010)
@@ -20,38 +20,47 @@
 namespace bindings {
 namespace detail {
 
-template< typename Id, typename Enable = void >
+template< typename T, typename Enable = void >
 struct offset_impl {};
 
-template< typename Id >
-struct offset_impl< Id, typename boost::enable_if< has_linear_array< Id > >::type > {
+template< typename T >
+struct offset_impl< T, typename boost::enable_if< has_linear_array< T > >::type > {
 
- static std::ptrdiff_t invoke( const Id& id, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
- return i1 * bindings::stride1( id ) +
- i2 * bindings::stride2( id );
+ static std::ptrdiff_t invoke( const T& t, std::ptrdiff_t i1 ) {
+ return i1 * bindings::stride1( t );
+ }
+
+ static std::ptrdiff_t invoke( const T& t, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
+ return i1 * bindings::stride1( t ) +
+ i2 * bindings::stride2( t );
     }
 
 };
 
-template< typename Id >
-struct offset_impl< Id,
+template< typename T >
+struct offset_impl< T,
         typename boost::enable_if<
             mpl::and_<
- has_band_array< Id >,
- is_column_major< Id >
+ has_band_array< T >,
+ is_column_major< T >
>
>::type > {
 
- static std::ptrdiff_t invoke( const Id& id, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
- return i1 * bindings::stride1( id ) +
- i2 * (bindings::stride2( id )-1);
+ static std::ptrdiff_t invoke( const T& t, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
+ return i1 * bindings::stride1( t ) +
+ i2 * (bindings::stride2( t )-1);
     }
 
 };
 
-template< typename Id >
-std::ptrdiff_t offset( const Id& id, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
- return offset_impl< Id >::invoke( id, i1, i2 );
+template< typename T >
+std::ptrdiff_t offset( const T& t, std::ptrdiff_t i1 ) {
+ return offset_impl< T >::invoke( t, i1 );
+}
+
+template< typename T >
+std::ptrdiff_t offset( const T& t, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
+ return offset_impl< T >::invoke( t, i1, i2 );
 }
 
 } // namespace detail

Modified: sandbox/numeric_bindings/boost/numeric/bindings/row.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/row.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/row.hpp 2010-01-15 03:43:34 EST (Fri, 15 Jan 2010)
@@ -11,6 +11,7 @@
 
 #include <boost/numeric/bindings/begin.hpp>
 #include <boost/numeric/bindings/detail/adaptable_type.hpp>
+#include <boost/numeric/bindings/detail/offset.hpp>
 #include <boost/numeric/bindings/size.hpp>
 #include <boost/numeric/bindings/stride.hpp>
 #include <boost/numeric/bindings/value.hpp>
@@ -50,12 +51,13 @@
     }
 
     static typename result_of::begin_value< T >::type begin_value( Id& id ) {
- return bindings::begin_value( id.get() ) +
- id.m_index * bindings::stride1( id.get() );
+ return bindings::begin_value( id.get() ) +
+ offset( id.get(), id.m_index, 0 );
     }
 
     static typename result_of::end_value< T >::type end_value( Id& id ) {
- return bindings::end_value( id.get() );
+ return bindings::begin_value( id.get() ) +
+ offset( id.get(), id.m_index, size1(id) );
     }
 
     static typename result_of::stride2<T>::type stride1( const Id& id ) {

Modified: sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix_proxy.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix_proxy.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix_proxy.hpp 2010-01-15 03:43:34 EST (Fri, 15 Jan 2010)
@@ -9,6 +9,7 @@
 #ifndef BOOST_NUMERIC_BINDINGS_UBLAS_MATRIX_PROXY_HPP
 #define BOOST_NUMERIC_BINDINGS_UBLAS_MATRIX_PROXY_HPP
 
+#include <boost/numeric/bindings/bandwidth.hpp>
 #include <boost/numeric/bindings/begin.hpp>
 #include <boost/numeric/bindings/detail/adaptor.hpp>
 #include <boost/numeric/bindings/detail/offset.hpp>
@@ -38,7 +39,8 @@
     }
 
     static typename result_of::begin_value< adapted_type >::type begin_value( Id& id ) {
- return bindings::begin_value( id.data() ) + offset( id, id.start1(), id.start2() );
+ return bindings::begin_value( id.data() ) +
+ offset( id.data(), id.start1(), id.start2() );
     }
 
     static typename result_of::end_value< adapted_type >::type end_value( Id& id ) {
@@ -63,6 +65,38 @@
 
 };
 
+template< typename T, typename Id, typename Enable >
+struct adaptor< ublas::matrix_column< T >, Id, Enable > {
+
+ typedef typename copy_const< Id, typename value<T>::type >::type value_type;
+ typedef mpl::map<
+ mpl::pair< tag::value_type, value_type >,
+ mpl::pair< tag::entity, tag::vector >,
+ mpl::pair< tag::size_type<1>, std::ptrdiff_t >,
+ mpl::pair< tag::data_structure, tag::linear_array >,
+ mpl::pair< tag::stride_type<1>, tag::contiguous >
+ > property_map;
+
+ static std::ptrdiff_t size1( const Id& id ) {
+ return bindings::size1( id.data() );
+ }
+
+ static value_type* begin_value( Id& id ) {
+ return bindings::begin_value( id.data() ) +
+ offset( id.data(), 0, id.index() );
+ }
+
+ static value_type* end_value( Id& id ) {
+ return bindings::begin_value( id.data() ) +
+ offset( id.data(), id.size1(), id.index() );
+ }
+
+ static std::ptrdiff_t stride1( const Id& id ) {
+ return bindings::stride1( id.data() );
+ }
+
+};
+
 } // namespace detail
 } // namespace bindings
 } // namespace numeric

Modified: sandbox/numeric_bindings/boost/numeric/bindings/ublas/vector_proxy.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/ublas/vector_proxy.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/ublas/vector_proxy.hpp 2010-01-15 03:43:34 EST (Fri, 15 Jan 2010)
@@ -37,7 +37,7 @@
     }
 
     static typename result_of::end_value< adapted_type >::type end_value( Id& id ) {
- return bindings::end_value( id.data() );
+ return bindings::begin_value( id.data() ) + id.size() * stride1( id );
     }
 
     static std::ptrdiff_t stride1( const Id& id ) {


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