|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58240 - sandbox/numeric_bindings/boost/numeric/bindings
From: rutger_at_[hidden]
Date: 2009-12-08 14:38:36
Author: rutger
Date: 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
New Revision: 58240
URL: http://svn.boost.org/trac/boost/changeset/58240
Log:
sync of work on numeric_bindings
Added:
sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp
- copied, changed from r58101, /sandbox/numeric_bindings/boost/numeric/bindings/transpose.hpp
Removed:
sandbox/numeric_bindings/boost/numeric/bindings/transpose.hpp
Text files modified:
sandbox/numeric_bindings/boost/numeric/bindings/begin.hpp | 52 +++++------------------------
sandbox/numeric_bindings/boost/numeric/bindings/column.hpp | 9 ++++-
sandbox/numeric_bindings/boost/numeric/bindings/end.hpp | 68 ++++++++++++++++++++++++++++++++++-----
sandbox/numeric_bindings/boost/numeric/bindings/io.hpp | 9 ++++-
sandbox/numeric_bindings/boost/numeric/bindings/is_mutable.hpp | 20 ++++++-----
sandbox/numeric_bindings/boost/numeric/bindings/noop.hpp | 7 +++
sandbox/numeric_bindings/boost/numeric/bindings/remove_imaginary.hpp | 2 +
sandbox/numeric_bindings/boost/numeric/bindings/row.hpp | 6 ++
sandbox/numeric_bindings/boost/numeric/bindings/size.hpp | 26 ++++++++++-----
sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp | 26 ++++++++++-----
sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp | 35 ++++++++++++++------
11 files changed, 164 insertions(+), 96 deletions(-)
Modified: sandbox/numeric_bindings/boost/numeric/bindings/begin.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/begin.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/begin.hpp 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -15,9 +15,7 @@
#include <boost/numeric/bindings/detail/adaptor.hpp>
#include <boost/numeric/bindings/detail/linear_iterator.hpp>
-
-#include <boost/preprocessor/repetition.hpp>
-#include <boost/preprocessor/cat.hpp>
+#include <boost/numeric/bindings/detail/generate_iter_funcs.hpp>
#include <iostream>
@@ -88,12 +86,12 @@
template< int Dimension, typename T >
typename result_of::begin<T, mpl::int_<Dimension> >::type begin( T& t ) {
- return detail::begin_impl<T, mpl::int_<Dimension> >( t );
+ return detail::begin_impl< T, mpl::int_<Dimension> >( t );
}
template< int Dimension, typename T >
typename result_of::begin<const T, mpl::int_<Dimension> >::type begin( const T& t ) {
- return detail::begin_impl<const T, mpl::int_<Dimension> >( t );
+ return detail::begin_impl< const T, mpl::int_<Dimension> >( t );
}
// Overloads for types with rank <= 1 (scalars, vectors)
@@ -102,55 +100,25 @@
template< typename T >
typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
- typename result_of::begin< T, mpl::int_<1> >::type >::type
+ typename result_of::begin< T >::type >::type
begin( T& t ) {
- return detail::begin_impl<T,mpl::int_<1> >::invoke( t );
+ return detail::begin_impl< T, mpl::int_<1> >::invoke( t );
}
template< typename T >
typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
typename result_of::begin< const T >::type >::type
begin( const T& t ) {
- return detail::begin_impl<const T,mpl::int_<1> >::invoke( t );
-}
-
-//
-// Convenience functions
-//
-
-#define GENERATE_BEGIN( suffix, tag ) \
-\
-namespace result_of {\
-\
-template< typename T > \
-struct BOOST_PP_CAT( begin, suffix ) { \
- typedef typename detail::begin_impl<T,tag>::result_type type;\
-}; \
-\
-}\
-\
-template< typename T >\
-typename BOOST_PP_CAT( result_of::begin, suffix )<T>::type \
-BOOST_PP_CAT( begin, suffix )( T& t ) {\
- return detail::begin_impl<T, tag >::\
- invoke( t );\
-}\
-\
-template< typename T >\
-typename BOOST_PP_CAT( result_of::begin, suffix )<const T>::type \
-BOOST_PP_CAT( begin, suffix )( const T& t ) {\
- return detail::begin_impl<const T, tag >::\
- invoke( t );\
+ return detail::begin_impl< const T, mpl::int_<1> >::invoke( t );
}
#define GENERATE_BEGIN_INDEX( z, which, unused ) \
-GENERATE_BEGIN( which, mpl::int_<which> )
-
+GENERATE_ITER_FUNCS( begin, which, mpl::int_<which> )
BOOST_PP_REPEAT_FROM_TO(1,2,GENERATE_BEGIN_INDEX,~)
-GENERATE_BEGIN( _value, tag::value )
-GENERATE_BEGIN( _row, mpl::int_<1> )
-GENERATE_BEGIN( _column, mpl::int_<2> )
+GENERATE_ITER_FUNCS( begin, _value, tag::value )
+GENERATE_ITER_FUNCS( begin, _row, mpl::int_<1> )
+GENERATE_ITER_FUNCS( begin, _column, mpl::int_<2> )
} // namespace bindings
} // namespace numeric
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 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -49,8 +49,13 @@
return size<1>( id.get() );
}
- static typename result_of::begin<T,tag::value>::type begin_value( Id& id ) {
- return begin<tag::value>( id.get() ) + id.m_index * stride<2>( id.get() );
+ static typename result_of::begin_value< T >::type begin_value( Id& id ) {
+ return bindings::begin_value( id.get() ) + id.m_index * stride<2>( id.get() );
+ }
+
+ 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() );
}
static typename result_of::stride<T,1>::type stride1( const Id& id ) {
Modified: sandbox/numeric_bindings/boost/numeric/bindings/end.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/end.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/end.hpp 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -17,16 +17,31 @@
namespace detail {
-template< typename T, typename Tag = tag::value >
-struct end_impl {
-};
+template< typename T, typename Tag >
+struct end_impl {};
template< typename T >
struct end_impl< T, tag::value > {
typedef typename value<T>::type* result_type;
static result_type invoke( T& t ) {
- return adaptor_access<T>::begin_value( t );
+ return adaptor_access<T>::end_value( t );
+ }
+
+};
+
+template< typename T, int Dimension >
+struct end_impl<T, mpl::int_<Dimension> > {
+
+ typedef mpl::int_<Dimension> dim_type;
+
+ typedef linear_iterator<
+ typename value<T>::type,
+ typename result_of::stride<T,Dimension>::type
+ > result_type;
+
+ static result_type invoke( T& t ) {
+ return result_type( end_value( t ), stride<Dimension>(t) );
}
};
@@ -35,12 +50,17 @@
namespace result_of {
-template< typename T, typename Tag = tag::value >
+template< typename T, typename Tag = mpl::int_<1> >
struct end {
- typedef typename detail::begin_impl<T,Tag>::result_type type;
+ typedef typename detail::end_impl<T,Tag>::result_type type;
};
} // namespace result_of
+//
+// Free Functions
+//
+
+// Overloads like begin< tag::value, etc. >
template< typename Tag, typename T >
typename result_of::end<T,Tag>::type end( T& t ) {
@@ -52,16 +72,44 @@
return detail::end_impl<const T,Tag>::invoke( t );
}
+// Overloads like end<1>, end<2>, etc..
+
+template< int Dimension, typename T >
+typename result_of::end<T, mpl::int_<Dimension> >::type end( T& t ) {
+ return detail::end_impl<T, mpl::int_<Dimension> >( t );
+}
+
+template< int Dimension, typename T >
+typename result_of::end<const T, mpl::int_<Dimension> >::type end( const T& t ) {
+ return detail::end_impl<const T, mpl::int_<Dimension> >( t );
+}
+
+// Overloads for types with rank <= 1 (scalars, vectors)
+// In theory, we could provide overloads for matrices here, too,
+// if their minimal_rank is at most 1.
+
template< typename T >
-typename result_of::end<T>::type end( T& t ) {
- return detail::end_impl<T>::invoke( t );
+typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
+ typename result_of::end< T, mpl::int_<1> >::type >::type
+end( T& t ) {
+ return detail::end_impl<T,mpl::int_<1> >::invoke( t );
}
template< typename T >
-typename result_of::end<const T>::type end( const T& t ) {
- return detail::end_impl<const T>::invoke( t );
+typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
+ typename result_of::end< const T >::type >::type
+end( const T& t ) {
+ return detail::end_impl<const T,mpl::int_<1> >::invoke( t );
}
+#define GENERATE_END_INDEX( z, which, unused ) \
+GENERATE_ITER_FUNCS( end, which, mpl::int_<which> )
+
+BOOST_PP_REPEAT_FROM_TO(1,2,GENERATE_END_INDEX,~)
+GENERATE_ITER_FUNCS( end, _value, tag::value )
+GENERATE_ITER_FUNCS( end, _row, mpl::int_<1> )
+GENERATE_ITER_FUNCS( end, _column, mpl::int_<2> )
+
} // namespace bindings
} // namespace numeric
Modified: sandbox/numeric_bindings/boost/numeric/bindings/io.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/io.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/io.hpp 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -24,8 +24,13 @@
template< typename Stream, typename T >
Stream& pretty_print( Stream& os, const T& t ) {
os << "[" << size<1>(t) << "] ";
- for( typename result_of::begin< const T >::type i = begin(t); i != end(t); ++i ) {
- os << *i << " ";
+ typename result_of::begin< const T >::type i = begin(t);
+ if ( i != end(t) ) {
+ os << *i;
+ ++i;
+ }
+ for( ; i != end(t); ++i ) {
+ os << " " << *i;
}
return os;
}
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 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -9,21 +9,23 @@
#ifndef BOOST_NUMERIC_BINDINGS_IS_MUTABLE_HPP
#define BOOST_NUMERIC_BINDINGS_IS_MUTABLE_HPP
-#include <boost/type_traits/value.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/numeric/bindings/value.hpp>
+#include <boost/numeric/bindings/has_linear_array.hpp>
namespace boost {
namespace numeric {
namespace bindings {
-//
-// TODO things like index arrays should be mutable, too
-//
+template< typename T, typename Enable = void >
+struct is_mutable {};
+
template< typename T >
-struct is_mutable:
- mpl::and_<
- is_reference< typename value<T>::type >,
- mpl::not_< is_const< typename value<T>::type > >
- >::type {};
+struct is_mutable< T, typename enable_if< has_linear_array<T> >::type >:
+ is_same< typename value<T>::type,
+ typename remove_const< typename value<T>::type >::type
+ > {};
} // namespace bindings
} // namespace numeric
Modified: sandbox/numeric_bindings/boost/numeric/bindings/noop.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/noop.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/noop.hpp 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -11,6 +11,7 @@
#include <boost/numeric/bindings/detail/adaptable_type.hpp>
#include <boost/numeric/bindings/begin.hpp>
+#include <boost/numeric/bindings/end.hpp>
#include <boost/numeric/bindings/size.hpp>
#include <boost/numeric/bindings/stride.hpp>
#include <boost/ref.hpp>
@@ -37,10 +38,14 @@
return size<1>( id.get() );
}
- static typename result_of::begin< T, tag::value >::type begin_value( Id& id ) {
+ static typename result_of::begin_value< T >::type begin_value( Id& id ) {
return bindings::begin_value( id.get() );
}
+ static typename result_of::end_value< T >::type end_value( Id& id ) {
+ return bindings::end_value( id.get() );
+ }
+
};
} // namespace detail
Modified: sandbox/numeric_bindings/boost/numeric/bindings/remove_imaginary.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/remove_imaginary.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/remove_imaginary.hpp 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -9,6 +9,8 @@
#ifndef BOOST_NUMERIC_BINDINGS_REMOVE_IMAGINARY_HPP
#define BOOST_NUMERIC_BINDINGS_REMOVE_IMAGINARY_HPP
+#include <complex>
+
namespace boost {
namespace numeric {
namespace bindings {
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 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -49,10 +49,14 @@
return size<2>( id.get() );
}
- static typename result_of::begin<T,tag::value>::type begin_value( Id& id ) {
+ static typename result_of::begin_value< T >::type begin_value( Id& id ) {
return bindings::begin_value( id.get() ) + id.m_index * stride<1>( id.get() );
}
+ static typename result_of::end_value< T >::type end_value( Id& id ) {
+ return bindings::end_value( id.get() );
+ }
+
static typename result_of::stride<T,2>::type stride1( const Id& id ) {
return stride<2>( id.get() );
}
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-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -70,7 +70,7 @@
namespace result_of {
-template< typename T, int Dimension >
+template< typename T, int Dimension = 1 >
struct size {
typedef typename detail::size_impl< T, tag::size_type<Dimension> >::result_type type;
};
@@ -82,15 +82,23 @@
return detail::size_impl< const T, tag::size_type<Dimension> >::size( t );
}
+
+// Overloads for types with rank <= 1 (scalars, vectors)
+// In theory, we could provide overloads for matrices here, too,
+// if their minimal_rank is at most 1.
+
+template< typename T >
+typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
+ typename result_of::size<T>::type >::type
+size( T& t ) {
+ return detail::size_impl<T, tag::size_type<1> >::size( t );
+}
+
template< typename T >
-inline std::ptrdiff_t size( const T& t, std::size_t dimension ) {
- switch( dimension ) {
- case 1: return size<1>(t);
- case 2: return size<2>(t);
- case 3: return size<3>(t);
- case 4: return size<4>(t);
- default: return 0;
- }
+typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
+ typename result_of::size< const T >::type >::type
+size( const T& t ) {
+ return detail::size_impl<const T, tag::size_type<1> >::size( t );
}
} // namespace bindings
Modified: sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/stride.hpp 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -67,7 +67,7 @@
namespace result_of {
-template< typename T, int Dimension >
+template< typename T, int Dimension = 1 >
struct stride {
typedef typename detail::stride_impl< T, tag::stride_type<Dimension> >::result_type type;
};
@@ -79,17 +79,25 @@
return detail::stride_impl< const T, tag::stride_type<Dimension> >::stride( t );
}
+// Overloads for types with rank <= 1 (scalars, vectors)
+// In theory, we could provide overloads for matrices here, too,
+// if their minimal_rank is at most 1.
+
template< typename T >
-inline std::ptrdiff_t stride( const T& 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;
- }
+typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
+ typename result_of::stride<T>::type >::type
+stride( T& t ) {
+ return detail::stride_impl<T, tag::stride_type<1> >::stride( t );
}
+template< typename T >
+typename boost::enable_if< mpl::less< rank<T>, mpl::int_<2> >,
+ typename result_of::stride< const T >::type >::type
+stride( const T& t ) {
+ return detail::stride_impl<const T, tag::stride_type<1> >::stride( t );
+}
+
+
} // namespace bindings
} // namespace numeric
} // namespace boost
Copied: sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp (from r58101, /sandbox/numeric_bindings/boost/numeric/bindings/transpose.hpp)
==============================================================================
--- /sandbox/numeric_bindings/boost/numeric/bindings/transpose.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
@@ -6,11 +6,12 @@
// http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef BOOST_NUMERIC_BINDINGS_TRANSPOSE_HPP
-#define BOOST_NUMERIC_BINDINGS_TRANSPOSE_HPP
+#ifndef BOOST_NUMERIC_BINDINGS_TRANSP_HPP
+#define BOOST_NUMERIC_BINDINGS_TRANSP_HPP
#include <boost/numeric/bindings/value.hpp>
-#include <boost/numeric/bindings/entity.hpp>
+#include <boost/numeric/bindings/size.hpp>
+#include <boost/numeric/bindings/begin.hpp>
#include <boost/mpl/max.hpp>
namespace boost {
@@ -19,22 +20,34 @@
namespace detail {
template< typename T >
-struct transpose_wrapper: reference_wrapper<T> {}
+struct trans_wrapper: reference_wrapper<T> {}
template< typename T, typename Id, typename Enable >
-struct adaptor< transpose_wrapper<T>, Id, Enable > {
+struct adaptor< trans_wrapper<T>, Id, Enable > {
typedef typename value<T>::type value_type;
typedef typename boost::mpl::max<
boost::mpl::int_<2>,
typename entity<T>::type >::type entity;
+ // Flip the data order
+ typedef typename flip_data_order< key_at::data_order >::type data_order;
+
+ // Flip size1/size2
static std::ptrdiff_t size1( const Id& t ) {
- return bindings::tensor_size2( t.get() );
+ return bindings::size2( t.get() );
}
static std::ptrdiff_t size2( const Id& t ) {
- return bindings::tensor_size1( t.get() );
+ return bindings::size1( t.get() );
+ }
+
+ static typename result_of::begin_value< T >::type begin_value( Id& id ) {
+ return bindings::begin_value( id.get() );
+ }
+
+ static typename result_of::end_value< T >::type end_value( Id& id ) {
+ return bindings::end_value( id.get() );
}
};
@@ -43,13 +56,13 @@
template< typename T >
-detail::transpose_wrapper<T> trans( T& underlying ) {
- return detail::transpose_wrapper<T>( underlying );
+detail::trans_wrapper<T> trans( T& underlying ) {
+ return detail::trans_wrapper<T>( underlying );
}
template< typename T >
-detail::transpose_wrapper<const T> trans( const T& underlying ) {
- return detail::transpose_wrapper<const T>( underlying );
+detail::trans_wrapper<const T> trans( const T& underlying ) {
+ return detail::trans_wrapper<const T>( underlying );
}
} // namespace bindings
Deleted: sandbox/numeric_bindings/boost/numeric/bindings/transpose.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/transpose.hpp 2009-12-08 14:38:34 EST (Tue, 08 Dec 2009)
+++ (empty file)
@@ -1,59 +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_TRANSPOSE_HPP
-#define BOOST_NUMERIC_BINDINGS_TRANSPOSE_HPP
-
-#include <boost/numeric/bindings/value.hpp>
-#include <boost/numeric/bindings/entity.hpp>
-#include <boost/mpl/max.hpp>
-
-namespace boost {
-namespace numeric {
-namespace bindings {
-namespace detail {
-
-template< typename T >
-struct transpose_wrapper: reference_wrapper<T> {}
-
-template< typename T, typename Id, typename Enable >
-struct adaptor< transpose_wrapper<T>, Id, Enable > {
-
- typedef typename value<T>::type value_type;
- typedef typename boost::mpl::max<
- boost::mpl::int_<2>,
- typename entity<T>::type >::type entity;
-
- static std::ptrdiff_t size1( const Id& t ) {
- return bindings::tensor_size2( t.get() );
- }
-
- static std::ptrdiff_t size2( const Id& t ) {
- return bindings::tensor_size1( t.get() );
- }
-
-};
-
-} // namespace detail
-
-
-template< typename T >
-detail::transpose_wrapper<T> trans( T& underlying ) {
- return detail::transpose_wrapper<T>( underlying );
-}
-
-template< typename T >
-detail::transpose_wrapper<const T> trans( const T& underlying ) {
- return detail::transpose_wrapper<const T>( underlying );
-}
-
-} // namespace bindings
-} // namespace numeric
-} // namespace 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