Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59221 - in sandbox/numeric_bindings/boost/numeric/bindings: . detail ublas
From: rutger_at_[hidden]
Date: 2010-01-22 08:43:48


Author: rutger
Date: 2010-01-22 08:43:47 EST (Fri, 22 Jan 2010)
New Revision: 59221
URL: http://svn.boost.org/trac/boost/changeset/59221

Log:
Added ublas traits for matrix_vector_slice and -range, bounded matrices and vectors, bounded array. Fixed trans_tag for vector cases.

Text files modified:
   sandbox/numeric_bindings/boost/numeric/bindings/detail/pod.hpp | 12 ++++----
   sandbox/numeric_bindings/boost/numeric/bindings/is_mutable.hpp | 5 ++
   sandbox/numeric_bindings/boost/numeric/bindings/trans_tag.hpp | 3 +
   sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix.hpp | 44 ++++++++++++++++++++++++++++--
   sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix_proxy.hpp | 57 ++++++++++++++++++++++++++++++++++++++++
   sandbox/numeric_bindings/boost/numeric/bindings/ublas/storage.hpp | 38 ++++++++++++++++++++++----
   sandbox/numeric_bindings/boost/numeric/bindings/ublas/vector.hpp | 4 +-
   7 files changed, 143 insertions(+), 20 deletions(-)

Modified: sandbox/numeric_bindings/boost/numeric/bindings/detail/pod.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/detail/pod.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/pod.hpp 2010-01-22 08:43:47 EST (Fri, 22 Jan 2010)
@@ -56,19 +56,19 @@
 
 };
 
-template< typename T, std::size_t N, std::size_t M, typename Id >
-struct adaptor< T[N][M], Id, typename boost::enable_if< is_numeric<T> >::type > {
+template< typename T, std::size_t M, std::size_t N, typename Id >
+struct adaptor< T[M][N], Id, typename boost::enable_if< is_numeric<T> >::type > {
 
     typedef typename copy_const< Id, T >::type value_type;
     typedef mpl::map<
         mpl::pair< tag::value_type, value_type >,
         mpl::pair< tag::entity, tag::matrix >,
- mpl::pair< tag::size_type<1>, mpl::int_<N> >,
- mpl::pair< tag::size_type<2>, mpl::int_<M> >,
+ mpl::pair< tag::size_type<1>, mpl::int_<M> >,
+ mpl::pair< tag::size_type<2>, mpl::int_<N> >,
         mpl::pair< tag::matrix_type, tag::general >,
         mpl::pair< tag::data_structure, tag::linear_array >,
         mpl::pair< tag::data_order, tag::row_major >,
- mpl::pair< tag::stride_type<1>, mpl::int_<M> >,
+ mpl::pair< tag::stride_type<1>, mpl::int_<N> >,
         mpl::pair< tag::stride_type<2>, tag::contiguous >
> property_map;
 
@@ -77,7 +77,7 @@
     }
 
     static value_type* end_value( Id& t ) {
- return &t[N][M];
+ return &t[M][N];
     }
 
 };

Modified: sandbox/numeric_bindings/boost/numeric/bindings/is_mutable.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/is_mutable.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/is_mutable.hpp 2010-01-22 08:43:47 EST (Fri, 22 Jan 2010)
@@ -16,8 +16,11 @@
 namespace numeric {
 namespace bindings {
 
+template< typename T, typename Enable = void >
+struct is_mutable: mpl::false_ {};
+
 template< typename T >
-struct is_mutable:
+struct is_mutable< T, typename boost::enable_if< detail::is_adaptable<T> >::type >:
         is_same<
             typename bindings::value_type< T>::type,
             typename remove_const< typename bindings::value_type< T>::type >::type

Modified: sandbox/numeric_bindings/boost/numeric/bindings/trans_tag.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/trans_tag.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/trans_tag.hpp 2010-01-22 08:43:47 EST (Fri, 22 Jan 2010)
@@ -9,6 +9,7 @@
 #ifndef BOOST_NUMERIC_BINDINGS_TRANS_TAG_HPP
 #define BOOST_NUMERIC_BINDINGS_TRANS_TAG_HPP
 
+#include <boost/numeric/bindings/data_order.hpp>
 #include <boost/numeric/bindings/tag.hpp>
 #include <boost/numeric/bindings/detail/property_map.hpp>
 
@@ -63,7 +64,7 @@
 template< typename T, typename Order >
 struct trans_tag {
     typedef typename detail::trans_tag_impl< Order,
- typename detail::property_at< T, tag::data_order >::type,
+ typename result_of::data_order<T>::type,
         typename detail::property_at< T, tag::value_transform >::type >::type type;
 };
 

Modified: sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix.hpp 2010-01-22 08:43:47 EST (Fri, 22 Jan 2010)
@@ -25,7 +25,7 @@
 namespace detail {
 
 template< typename T, typename F, typename A, typename Id, typename Enable >
-struct adaptor< boost::numeric::ublas::matrix< T, F, A >, Id, Enable > {
+struct adaptor< ::boost::numeric::ublas::matrix< T, F, A >, Id, Enable > {
 
     typedef typename copy_const< Id, T >::type value_type;
     typedef typename convert_to< tag::data_order, F >::type data_order;
@@ -68,8 +68,44 @@
 
 };
 
-template< typename T, std::size_t N, std::size_t M, typename Id, typename Enable >
-struct adaptor< ::boost::numeric::ublas::c_matrix< T, N, M >, Id, Enable > {
+template< typename T, std::size_t M, std::size_t N, typename F, typename Id, typename Enable >
+struct adaptor< ::boost::numeric::ublas::bounded_matrix< T, M, N, F >, Id, Enable > {
+
+ typedef typename copy_const< Id, T >::type value_type;
+ typedef typename convert_to< tag::data_order, F >::type data_order;
+ typedef mpl::map<
+ mpl::pair< tag::value_type, value_type >,
+ mpl::pair< tag::entity, tag::matrix >,
+ mpl::pair< tag::size_type<1>, std::ptrdiff_t >,
+ mpl::pair< tag::size_type<2>, std::ptrdiff_t >,
+ mpl::pair< tag::data_structure, tag::linear_array >,
+ mpl::pair< tag::data_order, data_order >,
+ mpl::pair< tag::stride_type<1>,
+ typename if_row_major< data_order, mpl::int_<N>, tag::contiguous >::type >,
+ mpl::pair< tag::stride_type<2>,
+ typename if_row_major< data_order, tag::contiguous, mpl::int_<M> >::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 value_type* begin_value( Id& id ) {
+ return bindings::begin_value( id.data() );
+ }
+
+ static value_type* end_value( Id& id ) {
+ return bindings::end_value( id.data() );
+ }
+
+};
+
+template< typename T, std::size_t M, std::size_t N, typename Id, typename Enable >
+struct adaptor< ::boost::numeric::ublas::c_matrix< T, M, N >, Id, Enable > {
 
     typedef typename copy_const< Id, T >::type value_type;
     typedef mpl::map<
@@ -80,7 +116,7 @@
         mpl::pair< tag::matrix_type, tag::general >,
         mpl::pair< tag::data_structure, tag::linear_array >,
         mpl::pair< tag::data_order, tag::row_major >,
- mpl::pair< tag::stride_type<1>, mpl::int_<M> >,
+ mpl::pair< tag::stride_type<1>, mpl::int_<N> >,
         mpl::pair< tag::stride_type<2>, tag::contiguous >
> property_map;
 

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-22 08:43:47 EST (Fri, 22 Jan 2010)
@@ -177,7 +177,64 @@
 
 };
 
+template< typename T, typename Id, typename Enable >
+struct adaptor< ublas::matrix_vector_range< T >, Id, Enable > {
 
+ typedef typename copy_const< Id, T >::type adapted_type;
+ typedef typename property_insert< adapted_type,
+ mpl::pair< tag::entity, tag::vector >,
+ mpl::pair< tag::stride_type<1>, std::ptrdiff_t >
+ >::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.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 bindings::stride1( id.data() ) + bindings::stride2( id.data() );
+ }
+
+};
+
+template< typename T, typename Id, typename Enable >
+struct adaptor< ublas::matrix_vector_slice< T >, Id, Enable > {
+
+ typedef typename copy_const< Id, T >::type adapted_type;
+ typedef typename property_insert< adapted_type,
+ mpl::pair< tag::entity, tag::vector >,
+ mpl::pair< tag::stride_type<1>, std::ptrdiff_t >
+ >::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.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() * bindings::stride1( id.data() ) +
+ id.stride2() * bindings::stride2( id.data() );
+ }
+
+};
 
 } // namespace detail
 } // namespace bindings

Modified: sandbox/numeric_bindings/boost/numeric/bindings/ublas/storage.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/ublas/storage.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/ublas/storage.hpp 2010-01-22 08:43:47 EST (Fri, 22 Jan 2010)
@@ -17,6 +17,32 @@
 namespace bindings {
 namespace detail {
 
+template< typename T, std::size_t N, typename Alloc, typename Id, typename Enable >
+struct adaptor< ::boost::numeric::ublas::bounded_array< T, N, Alloc >, Id, Enable > {
+
+ typedef typename copy_const< Id, T >::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 id.size();
+ }
+
+ static value_type* begin_value( Id& id ) {
+ return id.begin();
+ }
+
+ static value_type* end_value( Id& id ) {
+ return id.end();
+ }
+
+};
+
 template< typename T, typename Alloc, typename Id, typename Enable >
 struct adaptor< ublas::unbounded_array< T, Alloc >, Id, Enable > {
 
@@ -29,16 +55,16 @@
         mpl::pair< tag::stride_type<1>, tag::contiguous >
> property_map;
 
- static std::ptrdiff_t size1( const Id& t ) {
- return t.size();
+ static std::ptrdiff_t size1( const Id& id ) {
+ return id.size();
     }
 
- static value_type* begin_value( Id& t ) {
- return t.begin();
+ static value_type* begin_value( Id& id ) {
+ return id.begin();
     }
 
- static value_type* end_value( Id& t ) {
- return t.end();
+ static value_type* end_value( Id& id ) {
+ return id.end();
     }
 
 };

Modified: sandbox/numeric_bindings/boost/numeric/bindings/ublas/vector.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/ublas/vector.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/ublas/vector.hpp 2010-01-22 08:43:47 EST (Fri, 22 Jan 2010)
@@ -64,11 +64,11 @@
     }
 
     static value_type* begin_value( Id& id ) {
- return id.begin();
+ return bindings::begin_value( id.data() );
     }
 
     static value_type* end_value( Id& id ) {
- return id.end();
+ return bindings::end_value( id.data() );
     }
 
 };


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