Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59041 - sandbox/numeric_bindings/boost/numeric/bindings/ublas
From: rutger_at_[hidden]
Date: 2010-01-15 09:16:45


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

Log:
added bindings to ublas matrix slice, vector slice, matrix row

Text files modified:
   sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix_proxy.hpp | 83 +++++++++++++++++++++++++++++++++++++++
   sandbox/numeric_bindings/boost/numeric/bindings/ublas/vector_proxy.hpp | 27 +++++++++++++
   2 files changed, 109 insertions(+), 1 deletions(-)

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 09:16:43 EST (Fri, 15 Jan 2010)
@@ -44,7 +44,8 @@
     }
 
     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() ) +
+ offset( id.data(), id.start1() + id.size1(), id.start2() + id.size2() );
     }
 
     static std::ptrdiff_t stride1( const Id& id ) {
@@ -65,6 +66,50 @@
 
 };
 
+
+template< typename T, typename Id, typename Enable >
+struct adaptor< ublas::matrix_slice< T >, Id, Enable > {
+
+ typedef typename copy_const< Id, T >::type adapted_type;
+ typedef typename property_map_of< adapted_type >::type property_map;
+
+ static std::ptrdiff_t size1( const Id& id ) {
+ return id.size1();
+ }
+
+ static std::ptrdiff_t size2( const Id& id ) {
+ return id.size2();
+ }
+
+ static typename result_of::begin_value< adapted_type >::type begin_value( Id& id ) {
+ 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 ) {
+ return bindings::begin_value( id.data() ) +
+ offset( id.data(), id.start1() + id.size1(), id.start2() + id.size2() );
+ }
+
+ static std::ptrdiff_t stride1( const Id& id ) {
+ return id.stride1();
+ }
+
+ static std::ptrdiff_t stride2( const Id& id ) {
+ return id.stride2();
+ }
+
+ static std::ptrdiff_t bandwidth1( const Id& id ) {
+ return bindings::bandwidth1( id.data() );
+ }
+
+ static std::ptrdiff_t bandwidth2( const Id& id ) {
+ return bindings::bandwidth2( id.data() );
+ }
+
+};
+
+
 template< typename T, typename Id, typename Enable >
 struct adaptor< ublas::matrix_column< T >, Id, Enable > {
 
@@ -98,6 +143,42 @@
 
 };
 
+
+template< typename T, typename Id, typename Enable >
+struct adaptor< ublas::matrix_row< 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 >,
+ // TODO in case of row major, this could be contiguous
+ mpl::pair< tag::stride_type<1>, std::ptrdiff_t >
+ > property_map;
+
+ static std::ptrdiff_t size1( const Id& id ) {
+ return id.size();
+ }
+
+ static value_type* begin_value( Id& id ) {
+ return bindings::begin_value( id.data() ) +
+ offset( id.data(), id.index(), 0 );
+ }
+
+ static value_type* end_value( Id& id ) {
+ return bindings::begin_value( id.data() ) +
+ offset( id.data(), id.index(), bindings::size(id) );
+ }
+
+ static std::ptrdiff_t stride1( const Id& id ) {
+ return bindings::stride2( 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 09:16:43 EST (Fri, 15 Jan 2010)
@@ -11,6 +11,7 @@
 
 #include <boost/numeric/bindings/begin.hpp>
 #include <boost/numeric/bindings/detail/adaptor.hpp>
+#include <boost/numeric/bindings/detail/offset.hpp>
 #include <boost/numeric/bindings/detail/property_map.hpp>
 #include <boost/numeric/bindings/end.hpp>
 #include <boost/numeric/bindings/size.hpp>
@@ -46,6 +47,32 @@
 
 };
 
+template< typename T, typename Id, typename Enable >
+struct adaptor< ublas::vector_slice< T >, Id, Enable > {
+
+ typedef typename copy_const< Id, T >::type adapted_type;
+ typedef typename property_map_of< adapted_type >::type property_map;
+
+ static std::ptrdiff_t size1( const Id& id ) {
+ return id.size();
+ }
+
+ static typename result_of::begin_value< adapted_type >::type begin_value( Id& id ) {
+ return bindings::begin_value( id.data() ) +
+ offset( id, id.start() );
+ }
+
+ static typename result_of::end_value< adapted_type >::type end_value( Id& id ) {
+ return bindings::begin_value( id.data() ) +
+ offset( id, id.start() + id.size() );
+ }
+
+ static std::ptrdiff_t stride1( const Id& id ) {
+ return bindings::stride1( id.data() );
+ }
+
+};
+
 } // namespace detail
 } // namespace bindings
 } // namespace numeric


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