Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57927 - in sandbox/numeric_bindings/boost/numeric/bindings: . detail ublas
From: rutger_at_[hidden]
Date: 2009-11-25 10:29:28


Author: rutger
Date: 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
New Revision: 57927
URL: http://svn.boost.org/trac/boost/changeset/57927

Log:
added row and column meta-adaptors, strides and sizes are working

Added:
   sandbox/numeric_bindings/boost/numeric/bindings/column.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/data.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/detail/get.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/row.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp (contents, props changed)
Removed:
   sandbox/numeric_bindings/boost/numeric/bindings/vector_size.hpp
Text files modified:
   sandbox/numeric_bindings/boost/numeric/bindings/detail/adaptable_type.hpp | 9 +-
   sandbox/numeric_bindings/boost/numeric/bindings/detail/adaptor.hpp | 34 +++--------
   sandbox/numeric_bindings/boost/numeric/bindings/detail/pod.hpp | 9 +-
   sandbox/numeric_bindings/boost/numeric/bindings/has_linear_array.hpp | 5 +
   sandbox/numeric_bindings/boost/numeric/bindings/identity.hpp | 1
   sandbox/numeric_bindings/boost/numeric/bindings/num_columns.hpp | 5 -
   sandbox/numeric_bindings/boost/numeric/bindings/num_rows.hpp | 12 +--
   sandbox/numeric_bindings/boost/numeric/bindings/size.hpp | 113 ++++++++-------------------------------
   sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix.hpp | 43 +++++++++++---
   9 files changed, 86 insertions(+), 145 deletions(-)

Added: sandbox/numeric_bindings/boost/numeric/bindings/column.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/column.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -0,0 +1,88 @@
+//
+// Copyright (c) 2009 Rutger ter Borg
+//
+// 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_BINDINGS_COLUMN_HPP
+#define BOOST_NUMERIC_BINDINGS_COLUMN_HPP
+
+#include <boost/numeric/bindings/data.hpp>
+#include <boost/numeric/bindings/detail/adaptable_type.hpp>
+#include <boost/numeric/bindings/size.hpp>
+#include <boost/numeric/bindings/stride.hpp>
+#include <boost/numeric/bindings/value_type.hpp>
+#include <boost/ref.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template< typename T >
+struct column_wrapper:
+ adaptable_type< column_wrapper<T> >,
+ reference_wrapper<T> {
+
+ column_wrapper( T& t, std::size_t index ):
+ reference_wrapper<T>(t),
+ m_index( index ) {}
+
+ std::size_t m_index;
+};
+
+template< typename T, typename Id, typename Enable >
+struct adaptor< column_wrapper<T>, Id, Enable > {
+
+ typedef typename value_type<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>, typename result_of::size<T,1>::type >,
+ mpl::pair< tag::data_structure, tag::linear_array >,
+ mpl::pair< tag::stride_type<1>, typename result_of::stride<T,1>::type >
+ > property_map;
+
+ static typename result_of::size<T,1>::type size1( Id const& id ) {
+ return size<1>( id.get() );
+ }
+
+ static typename result_of::data<T>::type data( Id& id ) {
+ return bindings::data( id.get() ) + id.m_index * stride<2>( id.get() );
+ }
+
+ static typename result_of::stride<T,1>::type stride1( Id const& id ) {
+ return stride<1>( id.get() );
+ }
+
+};
+
+
+} // namespace detail
+
+namespace result_of {
+
+template< typename T >
+struct column {
+ typedef detail::column_wrapper<T> type;
+};
+
+}
+
+template< typename T >
+detail::column_wrapper<T> column( T& underlying, std::size_t index ) {
+ return detail::column_wrapper<T>( underlying, index );
+}
+
+template< typename T >
+detail::column_wrapper<T const> column( T const& underlying, std::size_t index ) {
+ return detail::column_wrapper<T const>( underlying, index );
+}
+
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

Added: sandbox/numeric_bindings/boost/numeric/bindings/data.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/data.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -0,0 +1,55 @@
+//
+// Copyright (c) 2009 Rutger ter Borg
+//
+// 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_BINDINGS_DATA_HPP
+#define BOOST_NUMERIC_BINDINGS_DATA_HPP
+
+#include <boost/numeric/bindings/detail/adaptor.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template< typename T >
+struct data_impl {
+
+ typedef typename property_at< T, tag::value_type >::type* result_type;
+
+ static result_type data( T& t ) {
+ return adaptor_access<T>::data( t );
+ }
+
+};
+
+} // namespace detail
+
+namespace result_of {
+
+template< typename T >
+struct data {
+ typedef typename detail::data_impl<T>::result_type type;
+};
+
+} // namespace result_of
+
+template< typename T >
+typename result_of::data<T>::type data( T& t ) {
+ return detail::data_impl<T>::data( t );
+}
+
+template< typename T >
+typename result_of::data<T const>::type data( T const& t ) {
+ return detail::data_impl<T const>::data( t );
+}
+
+} // bindings
+} // numeric
+} // boost
+
+#endif

Modified: sandbox/numeric_bindings/boost/numeric/bindings/detail/adaptable_type.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/detail/adaptable_type.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/adaptable_type.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -31,11 +31,10 @@
 
 };
 
-
-} // detail
-} // bindings
-} // numeric
-} // boost
+} // namespace detail
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
 
 template< typename T >
 std::ostream& operator<<( std::ostream& os,

Modified: sandbox/numeric_bindings/boost/numeric/bindings/detail/adaptor.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/detail/adaptor.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/adaptor.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -15,8 +15,6 @@
 #include <boost/numeric/bindings/detail/copy_const.hpp>
 #include <boost/type_traits/remove_const.hpp>
 #include <boost/mpl/map.hpp>
-#include <boost/mpl/at.hpp>
-#include <boost/mpl/has_key.hpp>
 
 namespace boost {
 namespace numeric {
@@ -30,39 +28,25 @@
> property_map;
 };
 
-template< typename T, typename Enable = void >
-struct adaptor_access {};
-
 template< typename T >
 struct is_adaptable: is_numeric< typename mpl::at<
         typename adaptor< typename boost::remove_const<T>::type, T >::property_map,
         tag::value_type >::type > {};
 
+template< typename T, typename Enable = void >
+struct adaptor_access {};
+
 template< typename T >
-struct adaptor_access< T,
- typename boost::enable_if< is_adaptable<T> >::type >:
+struct adaptor_access< T, typename boost::enable_if< is_adaptable<T> >::type >:
     adaptor< typename boost::remove_const<T>::type, T > {};
 
 
+} // namespace detail
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
 
-template< typename T, typename Key >
-struct property_has_key: mpl::has_key< typename adaptor_access<T>::property_map, Key > {};
-
-template< typename T, typename Key >
-struct property_at {
- typedef typename mpl::at< typename adaptor_access<T>::property_map, Key >::type type;
-};
-
-template< typename T, typename Key, typename Value >
-struct is_same_at {
-};
-
-} // detail
-} // bindings
-} // numeric
-} // boost
-
-// include support for POD types
 #include <boost/numeric/bindings/detail/pod.hpp>
+#include <boost/numeric/bindings/detail/property_map.hpp>
 
 #endif

Added: sandbox/numeric_bindings/boost/numeric/bindings/detail/get.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/get.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -0,0 +1,87 @@
+//
+// Copyright (c) 2009 Rutger ter Borg
+//
+// 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_BINDINGS_DETAIL_GET_HPP
+#define BOOST_NUMERIC_BINDINGS_DETAIL_GET_HPP
+
+#include <boost/numeric/bindings/detail/adaptor.hpp>
+#include <boost/preprocessor/repetition.hpp>
+#include <boost/preprocessor/cat.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template< typename Key >
+struct get_dispatch {};
+
+#define GENERATE_GET( z, which, unused ) \
+template<> \
+struct get_dispatch< tag::size_type<which> > { \
+ template< typename T > \
+ static std::ptrdiff_t invoke( T const& t ) { \
+ return detail::adaptor_access<T>:: \
+ BOOST_PP_CAT( size, which )( t ); \
+ } \
+};\
+\
+template<> \
+struct get_dispatch< tag::stride_type<which> > { \
+ template< typename T > \
+ static std::ptrdiff_t invoke( T const& t ) { \
+ return detail::adaptor_access<T>:: \
+ BOOST_PP_CAT( stride, which )( t ); \
+ } \
+};
+
+BOOST_PP_REPEAT_FROM_TO(1,4,GENERATE_GET,~)
+
+template< typename T, typename Key, typename Enable = void >
+struct get_impl {};
+
+template< typename T, typename Key >
+struct get_impl< T, Key, typename boost::enable_if<
+ is_same_at< T, Key, std::ptrdiff_t > >::type > {
+
+ typedef std::ptrdiff_t result_type;
+
+ static std::ptrdiff_t invoke( T const& t ) {
+ return get_dispatch<Key>::invoke( t );
+ }
+
+};
+
+template< typename T, typename Key >
+struct get_impl< T, Key, typename boost::enable_if<
+ mpl::not_< is_same_at< T, Key, std::ptrdiff_t > > >::type > {
+
+ typedef typename property_at< T, Key >::type result_type;
+
+ static result_type invoke( T const& t ) {
+ return result_type();
+ }
+
+};
+
+template< typename T, typename Key >
+struct result_of_get {
+ typedef typename get_impl< T, Key >::result_type type;
+};
+
+template< typename Key, typename T >
+typename result_of_get< T, Key >::type get( T const& t ) {
+ return get_impl< T, Key >::invoke( t );
+}
+
+} // namespace detail
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

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 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -24,7 +24,8 @@
     typedef mpl::map<
         mpl::pair< tag::value_type, value_type >,
         mpl::pair< tag::entity, tag::scalar >,
- mpl::pair< tag::size_type<1>, mpl::int_<1> >
+ mpl::pair< tag::size_type<1>, mpl::int_<1> >,
+ mpl::pair< tag::stride_type<1>, mpl::int_<0> >
> property_map;
 
     static value_type* data( Id& t ) {
@@ -41,7 +42,7 @@
         mpl::pair< tag::value_type, value_type >,
         mpl::pair< tag::entity, tag::vector >,
         mpl::pair< tag::size_type<1>, mpl::int_<N> >,
- mpl::pair< tag::data_structure, tag::linear_array >
+ mpl::pair< tag::data_structure, tag::linear_array >,
         mpl::pair< tag::stride_type<1>, tag::contiguous >
> property_map;
 
@@ -63,8 +64,8 @@
         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>, tag::contiguous >,
- mpl::pair< tag::stride_type<2>, mpl::int_<N> >
+ mpl::pair< tag::stride_type<1>, mpl::int_<N> >,
+ mpl::pair< tag::stride_type<2>, tag::contiguous >
> property_map;
 
     static value_type* data( Id& t ) {

Added: sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -0,0 +1,37 @@
+//
+// Copyright (c) 2009 Rutger ter Borg
+//
+// 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_BINDINGS_DETAIL_PROPERTY_MAP_HPP
+#define BOOST_NUMERIC_BINDINGS_DETAIL_PROPERTY_MAP_HPP
+
+#include <boost/type_traits/is_same.hpp>
+#include <boost/mpl/at.hpp>
+#include <boost/mpl/has_key.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template< typename T, typename Key >
+struct property_has_key: mpl::has_key< typename adaptor_access<T>::property_map, Key > {};
+
+template< typename T, typename Key >
+struct property_at {
+ typedef typename mpl::at< typename adaptor_access<T>::property_map, Key >::type type;
+};
+
+template< typename T, typename Key, typename Value >
+struct is_same_at: is_same< typename property_at< T, Key >::type, Value > {};
+
+} // namespace detail
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

Modified: sandbox/numeric_bindings/boost/numeric/bindings/has_linear_array.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/has_linear_array.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/has_linear_array.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -17,8 +17,9 @@
 namespace bindings {
 
 template< typename T >
-struct has_linear_array: is_same< typename detail::property_at< T, detail::tag::data_structure >::type,
- detail::tag::linear_array >::type {};
+struct has_linear_array:
+ detail::is_same_at< T, detail::tag::data_structure, detail::tag::linear_array > {};
+
 
 } // namespace bindings
 } // namespace numeric

Modified: sandbox/numeric_bindings/boost/numeric/bindings/identity.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/identity.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/identity.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -11,6 +11,7 @@
 
 #include <boost/numeric/bindings/detail/adaptable_type.hpp>
 #include <boost/numeric/bindings/size.hpp>
+#include <boost/numeric/bindings/stride.hpp>
 #include <boost/ref.hpp>
 
 namespace boost {

Modified: sandbox/numeric_bindings/boost/numeric/bindings/num_columns.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/num_columns.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/num_columns.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -6,8 +6,8 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#ifndef BOOST_NUMERIC_BINDINGS_MATRIX_NUM_COLUMNS_HPP
-#define BOOST_NUMERIC_BINDINGS_MATRIX_NUM_COLUMNS_HPP
+#ifndef BOOST_NUMERIC_BINDINGS_NUM_COLUMNS_HPP
+#define BOOST_NUMERIC_BINDINGS_NUM_COLUMNS_HPP
 
 #include <boost/numeric/bindings/size.hpp>
 
@@ -33,4 +33,3 @@
 } // boost
 
 #endif
-

Modified: sandbox/numeric_bindings/boost/numeric/bindings/num_rows.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/num_rows.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/num_rows.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -6,15 +6,14 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 
-#ifndef BOOST_NUMERIC_BINDINGS_MATRIX_NUM_ROWS_HPP
-#define BOOST_NUMERIC_BINDINGS_MATRIX_NUM_ROWS_HPP
+#ifndef BOOST_NUMERIC_BINDINGS_NUM_ROWS_HPP
+#define BOOST_NUMERIC_BINDINGS_NUM_ROWS_HPP
 
 #include <boost/numeric/bindings/size.hpp>
 
 namespace boost {
 namespace numeric {
 namespace bindings {
-
 namespace result_of {
 
 template< typename T >
@@ -29,9 +28,8 @@
     return size<1>( t );
 }
 
-} // bindings
-} // numeric
-} // boost
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
 
 #endif
-

Added: sandbox/numeric_bindings/boost/numeric/bindings/row.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/row.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -0,0 +1,92 @@
+//
+// Copyright (c) 2009 Rutger ter Borg
+//
+// 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_BINDINGS_ROW_HPP
+#define BOOST_NUMERIC_BINDINGS_ROW_HPP
+
+#include <boost/numeric/bindings/data.hpp>
+#include <boost/numeric/bindings/detail/adaptable_type.hpp>
+#include <boost/numeric/bindings/size.hpp>
+#include <boost/numeric/bindings/stride.hpp>
+#include <boost/numeric/bindings/value_type.hpp>
+#include <boost/ref.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template< typename T >
+struct row_wrapper:
+ adaptable_type< row_wrapper<T> >,
+ reference_wrapper<T> {
+
+ row_wrapper( T& t, std::size_t index ):
+ reference_wrapper<T>(t),
+ m_index( index ) {}
+
+ std::size_t m_index;
+};
+
+template< typename T, typename Id, typename Enable >
+struct adaptor< row_wrapper<T>, Id, Enable > {
+
+ typedef typename value_type<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>, typename result_of::size<T,2>::type >,
+ mpl::pair< tag::data_structure, tag::linear_array >,
+ mpl::pair< tag::stride_type<1>, typename result_of::stride<T,2>::type >
+ > property_map;
+
+ static typename result_of::size<T,2>::type size1( Id const& id ) {
+ return size<2>( id.get() );
+ }
+
+ static typename result_of::data<T>::type data( Id& id ) {
+ return bindings::data( id.get() ) + id.m_index * stride<1>( id.get() );
+ }
+
+ static typename result_of::stride<T,2>::type stride1( Id const& id ) {
+ return stride<2>( id.get() );
+ }
+
+};
+
+} // namespace detail
+
+namespace result_of {
+
+template< typename T >
+struct row {
+ typedef detail::row_wrapper<T> type;
+};
+
+} // namespace result_of
+
+template< typename T >
+detail::row_wrapper<T> row( T& underlying, std::size_t index ) {
+ return detail::row_wrapper<T>( underlying, index );
+}
+
+template< typename T >
+detail::row_wrapper<T const> row( T const& underlying, std::size_t index ) {
+ return detail::row_wrapper<T const>( underlying, index );
+}
+
+template< int N, typename T >
+void row( T const& underlying ) {
+
+}
+
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

Modified: sandbox/numeric_bindings/boost/numeric/bindings/size.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/size.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/size.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -9,9 +9,8 @@
 #ifndef BOOST_NUMERIC_BINDINGS_SIZE_HPP
 #define BOOST_NUMERIC_BINDINGS_SIZE_HPP
 
-#include <boost/numeric/bindings/detail/adaptor.hpp>
+#include <boost/numeric/bindings/detail/get.hpp>
 #include <boost/numeric/bindings/tensor_rank.hpp>
-#include <boost/type_traits/is_same.hpp>
 #include <boost/mpl/min.hpp>
 #include <boost/mpl/and.hpp>
 #include <boost/mpl/less_equal.hpp>
@@ -22,104 +21,43 @@
 namespace bindings {
 namespace detail {
 
-template< typename T, int Dimension >
-struct is_dynamic_size: is_same<
- typename detail::property_at< T, detail::tag::size_type<Dimension> >::type,
- std::ptrdiff_t > {};
-
-template< int Dimension >
-struct get_dynamic_size {};
-
-template<>
-struct get_dynamic_size<1> {
- template< typename T >
- static std::ptrdiff_t size( T const& t ) {
- return detail::adaptor_access<T>::size1( t );
- }
-};
+template< typename T, typename Key, typename Enable = void >
+struct size_impl {
 
-template<>
-struct get_dynamic_size<2> {
- template< typename T >
- static std::ptrdiff_t size( T const& t ) {
- return detail::adaptor_access<T>::size2( t );
- }
-};
-
-template<>
-struct get_dynamic_size<3> {
- template< typename T >
- static std::ptrdiff_t size( T const& t ) {
- return detail::adaptor_access<T>::size3( t );
- }
-};
-
-template<>
-struct get_dynamic_size<4> {
- template< typename T >
- static std::ptrdiff_t size( T const& t ) {
- return detail::adaptor_access<T>::size4( t );
- }
-};
-
-
-template< typename T, int Dimension, typename Enable = void >
-struct size_impl {};
-
-template< typename T, int Dimension >
-struct size_impl< T, Dimension,
- typename boost::enable_if< typename mpl::and_<
- mpl::less_equal< mpl::int_<Dimension>, tensor_rank<T> >,
- is_dynamic_size< T, Dimension > >::type
- >::type > {
-
- typedef std::ptrdiff_t result_type;
-
- static std::ptrdiff_t size( T const& t ) {
- return get_dynamic_size<Dimension>::size( t );
- }
-
-};
-
-template< typename T, int Dimension >
-struct size_impl< T, Dimension,
- typename boost::enable_if< typename mpl::and_<
- mpl::less_equal< mpl::int_<Dimension>, tensor_rank<T> >,
- mpl::not_< is_dynamic_size< T, Dimension > > >::type
- >::type > {
-
- typedef typename detail::property_at< T, detail::tag::size_type<Dimension> >::type result_type;
+ typedef typename result_of_get< T, Key >::type result_type;
 
     static result_type size( T const& t ) {
- return result_type();
+ return get< Key >( t );
     }
 
 };
 
-template< typename T, int Dimension >
-struct size_impl< T, Dimension,
+template< typename T, typename Key >
+struct size_impl< T, Key,
         typename boost::enable_if< typename mpl::and_<
- mpl::greater< mpl::int_<Dimension>, tensor_rank<T> >,
- is_dynamic_size< T, 1 > >::type
- >::type > {
+ mpl::greater< Key, tensor_rank<T> >,
+ is_same_at< T, tag::size_type<1>, std::ptrdiff_t >
+ >::type >::type > {
 
     typedef std::ptrdiff_t result_type;
 
- static std::ptrdiff_t size( T const& t ) {
- return std::min< std::ptrdiff_t >( size_impl<T,1>::size(t), 1 );
+ static result_type size( T const& t ) {
+ return std::min< std::ptrdiff_t >( size_impl<T, tag::size_type<1> >::size(t), 1 );
     }
 
 };
 
-template< typename T, int Dimension >
-struct size_impl< T, Dimension,
+template< typename T, typename Key >
+struct size_impl< T, Key,
         typename boost::enable_if< typename mpl::and_<
- mpl::greater< mpl::int_<Dimension>, tensor_rank<T> >,
- mpl::not_< is_dynamic_size< T, 1 > > >::type
- >::type > {
-
- typedef typename mpl::min< typename detail::property_at< T, detail::tag::size_type<1> >::type,
- mpl::int_<1> >::type result_type;
+ mpl::greater< Key, tensor_rank<T> >,
+ mpl::not_< is_same_at< T, tag::size_type<1>, std::ptrdiff_t > >
+ >::type >::type > {
+
+ typedef typename mpl::min<
+ typename detail::property_at< T, tag::size_type<1> >::type,
+ mpl::int_<1>
+ >::type result_type;
 
     static result_type size( T const& t ) {
         return result_type();
@@ -134,14 +72,14 @@
 
 template< typename T, int Dimension >
 struct size {
- typedef typename detail::size_impl< T, Dimension >::result_type type;
+ typedef typename detail::size_impl< T, detail::tag::size_type<Dimension> >::result_type type;
 };
 
-}
+} // namespace result_of
 
 template< int Dimension, typename T >
 inline typename result_of::size< T const, Dimension >::type size( T const& t ) {
- return detail::size_impl< T const, Dimension >::size( t );
+ return detail::size_impl< T const, detail::tag::size_type<Dimension> >::size( t );
 }
 
 template< typename T >
@@ -160,4 +98,3 @@
 } // namespace boost
 
 #endif
-

Added: sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -0,0 +1,97 @@
+//
+// Copyright (c) 2009 Rutger ter Borg
+//
+// 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_BINDINGS_STRIDE_HPP
+#define BOOST_NUMERIC_BINDINGS_STRIDE_HPP
+
+#include <boost/numeric/bindings/detail/adaptor.hpp>
+#include <boost/numeric/bindings/detail/get.hpp>
+#include <boost/numeric/bindings/tensor_rank.hpp>
+#include <boost/mpl/min.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/less_equal.hpp>
+#include <boost/mpl/greater.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template< typename T, typename Key, typename Enable = void >
+struct stride_impl {
+
+ typedef typename result_of_get< T, Key >::type result_type;
+
+ static result_type stride( T const& t ) {
+ return get< Key >( t );
+ }
+
+};
+
+template< typename T, typename Key >
+struct stride_impl< T, Key,
+ typename boost::enable_if< typename mpl::and_<
+ mpl::greater< Key, tensor_rank<T> >,
+ is_same_at< T, tag::stride_type<1>, std::ptrdiff_t >
+ >::type >::type > {
+
+ typedef std::ptrdiff_t result_type;
+
+ static result_type stride( T const& t ) {
+ return 0;
+ }
+
+};
+
+template< typename T, typename Key >
+struct stride_impl< T, Key,
+ typename boost::enable_if< typename mpl::and_<
+ mpl::greater< Key, tensor_rank<T> >,
+ mpl::not_< is_same_at< T, tag::stride_type<1>, std::ptrdiff_t > >
+ >::type >::type > {
+
+ typedef typename mpl::int_<0> result_type;
+
+ static result_type stride( T const& t ) {
+ return result_type();
+ }
+
+};
+
+} // namespace detail
+
+namespace result_of {
+
+template< typename T, int Dimension >
+struct stride {
+ typedef typename detail::stride_impl< T, detail::tag::stride_type<Dimension> >::result_type type;
+};
+
+} // namespace result_of
+
+template< int Dimension, typename T >
+inline typename result_of::stride< T const, Dimension >::type stride( T const& t ) {
+ return detail::stride_impl< T const, detail::tag::stride_type<Dimension> >::stride( t );
+}
+
+template< typename T >
+inline std::ptrdiff_t stride( T const& t, std::size_t dimension ) {
+ switch( dimension ) {
+ case 1: return stride<1>(t);
+ case 2: return stride<2>(t);
+ case 3: return stride<3>(t);
+ case 4: return stride<4>(t);
+ default: return 0;
+ }
+}
+
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

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 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
@@ -18,26 +18,46 @@
 namespace bindings {
 namespace detail {
 
+template< typename DataOrder, int StrideDimension >
+struct select_stride {};
+
+template<>
+struct select_stride< tag::row_major, 1 > {
+ typedef std::ptrdiff_t type;
+};
+
+template<>
+struct select_stride< tag::row_major, 2 > {
+ typedef tag::contiguous type;
+};
+
+template<>
+struct select_stride< tag::column_major, 1 > {
+ typedef tag::contiguous type;
+};
+
+template<>
+struct select_stride< tag::column_major, 2 > {
+ typedef std::ptrdiff_t type;
+};
+
+
+
+
 template< typename T, typename F, typename A, typename Id, typename Enable >
 struct adaptor< boost::numeric::ublas::matrix< T, F, A >, Id, Enable > {
 
     typedef typename copy_const< Id, T >::type value_type;
+ typedef typename detail::to_bindings_tag<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 >,
-
- // either tag::column_major or tag::row_major
- mpl::pair< tag::data_order, typename detail::to_bindings_tag<F>::type >,
-
- //
- // is either contiguous in case of column/row major stuff, or it is dynamic, too.
- //
- mpl::pair< tag::stride_type<1>, std::ptrdiff_t >,
- mpl::pair< tag::stride_type<2>, std::ptrdiff_t >,
-
+ mpl::pair< tag::data_order, data_order >,
+ mpl::pair< tag::stride_type<1>, typename select_stride< data_order, 1 >::type >,
+ mpl::pair< tag::stride_type<2>, typename select_stride< data_order, 2 >::type >
> property_map;
 
     static std::ptrdiff_t size1( Id const& t ) {
@@ -53,10 +73,11 @@
     }
 
     static std::ptrdiff_t stride1( Id const& t ) {
-
+ return t.size2();
     }
 
     static std::ptrdiff_t stride2( Id const& t ) {
+ return t.size1();
     }
 
 };

Deleted: sandbox/numeric_bindings/boost/numeric/bindings/vector_size.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/vector_size.hpp 2009-11-25 10:29:26 EST (Wed, 25 Nov 2009)
+++ (empty file)
@@ -1,52 +0,0 @@
-//
-// Copyright (c) 2009 Rutger ter Borg
-//
-// 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_BINDINGS_VECTOR_SIZE_HPP
-#define BOOST_NUMERIC_BINDINGS_VECTOR_SIZE_HPP
-
-#include <boost/assert.hpp>
-#include <boost/numeric/bindings/tensor_size.hpp>
-
-namespace boost {
-namespace numeric {
-namespace bindings {
-
-template< typename T, typename Enable = void >
-struct vector_size_impl {};
-
-template< typename T >
-struct vector_size_impl< T,
- typename boost::enable_if< boost::mpl::less< tensor_rank<T>, mpl::int_<2> > >::type > {
-
- static std::ptrdiff_t size( T const& t ) {
- return tensor_size1( t );
- }
-};
-
-template< typename T >
-struct vector_size_impl< T,
- typename boost::enable_if< boost::mpl::greater_equal< tensor_rank<T>, mpl::int_<2> > >::type > {
-
- static std::ptrdiff_t size( T const& t ) {
- BOOST_ASSERT( tensor_size2( t )==1 );
- return tensor_size1( t );
- }
-
-};
-
-template< typename T >
-inline std::ptrdiff_t vector_size( T const& t ) {
- return vector_size_impl<T>::size( t );
-}
-
-} // bindings
-} // numeric
-} // boost
-
-#endif
-


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