|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58809 - in sandbox/numeric_bindings/boost/numeric/bindings: . ublas ublas/detail
From: rutger_at_[hidden]
Date: 2010-01-08 06:48:30
Author: rutger
Date: 2010-01-08 06:48:29 EST (Fri, 08 Jan 2010)
New Revision: 58809
URL: http://svn.boost.org/trac/boost/changeset/58809
Log:
Added support for bandwidth free function
Added:
sandbox/numeric_bindings/boost/numeric/bindings/bandwidth.hpp (contents, props changed)
Text files modified:
sandbox/numeric_bindings/boost/numeric/bindings/ublas/banded.hpp | 56 ++++++++++++---------------------------
sandbox/numeric_bindings/boost/numeric/bindings/ublas/detail/basic_ublas_adaptor.hpp | 3 +
2 files changed, 20 insertions(+), 39 deletions(-)
Added: sandbox/numeric_bindings/boost/numeric/bindings/bandwidth.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/bandwidth.hpp 2010-01-08 06:48:29 EST (Fri, 08 Jan 2010)
@@ -0,0 +1,159 @@
+//
+// 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_BANDWIDTH_HPP
+#define BOOST_NUMERIC_BINDINGS_BANDWIDTH_HPP
+
+#include <boost/numeric/bindings/detail/generate_functions.hpp>
+#include <boost/numeric/bindings/detail/get.hpp>
+#include <boost/numeric/bindings/rank.hpp>
+#include <boost/numeric/bindings/index_major.hpp>
+#include <boost/numeric/bindings/index_minor.hpp>
+#include <boost/numeric/bindings/index_trans.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/min.hpp>
+#include <boost/mpl/greater.hpp>
+#include <boost/mpl/less_equal.hpp>
+#include <boost/static_assert.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template< typename T, typename Index, typename Enable = void >
+struct bandwidth_impl {
+
+ typedef typename tag::bandwidth_type< Index::value > key_type;
+ typedef typename result_of_get< T, key_type >::type result_type;
+
+ static result_type invoke( const T& t ) {
+ return get< key_type >( t );
+ }
+
+};
+
+template< typename T, typename Index >
+struct bandwidth_impl< T, Index,
+ typename boost::enable_if< typename mpl::and_<
+ mpl::greater< Index, rank<T> >,
+ is_same_at< T, tag::bandwidth_type<1>, std::ptrdiff_t >
+ >::type >::type > {
+
+ typedef std::ptrdiff_t result_type;
+
+ static result_type invoke( const T& t ) {
+ return std::min< std::ptrdiff_t >( bandwidth_impl<T, tag::index<1> >::invoke(t), 1 );
+ }
+
+};
+
+template< typename T, typename Index >
+struct bandwidth_impl< T, Index,
+ typename boost::enable_if< typename mpl::and_<
+ mpl::greater< Index, rank<T> >,
+ mpl::not_< is_same_at< T, tag::bandwidth_type<1>, std::ptrdiff_t > >
+ >::type >::type > {
+
+ typedef typename mpl::min<
+ typename detail::property_at< T, tag::bandwidth_type<1> >::type,
+ mpl::int_<1>
+ >::type result_type;
+
+ static result_type invoke( const T& t ) {
+ return result_type();
+ }
+
+};
+
+} // namespace detail
+
+
+namespace result_of {
+
+template< typename T, typename Tag = tag::index<1> >
+struct bandwidth {
+ BOOST_STATIC_ASSERT( (is_tag<Tag>::value) );
+ typedef typename detail::bandwidth_impl< T, Tag >::result_type type;
+};
+
+} // namespace result_of
+
+//
+// Overloads for free template functions bandwidth( x, tag ),
+//
+template< typename T, typename Tag >
+inline typename result_of::bandwidth< const T, Tag >::type
+bandwidth( const T& t, Tag ) {
+ return detail::bandwidth_impl< const T, Tag >::invoke( t );
+}
+
+// Overloads for free template function bandwidth( x )
+// Valid 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::bandwidth< const T >::type >::type
+// bandwidth( const T& t ) {
+// return detail::bandwidth_impl< const T, tag::index<1> >::invoke( t );
+// }
+
+#define GENERATE_BANDWIDTH_INDEX( z, which, unused ) \
+GENERATE_FUNCTIONS( bandwidth, which, tag::index<which> )
+
+BOOST_PP_REPEAT_FROM_TO(1,3,GENERATE_BANDWIDTH_INDEX,~)
+
+GENERATE_FUNCTIONS( bandwidth, _left, tag::index<1> )
+GENERATE_FUNCTIONS( bandwidth, _right, tag::index<2> )
+GENERATE_FUNCTIONS( bandwidth, _lower, tag::index<1> )
+GENERATE_FUNCTIONS( bandwidth, _upper, tag::index<2> )
+GENERATE_FUNCTIONS( bandwidth, _major, typename index_major<T>::type )
+GENERATE_FUNCTIONS( bandwidth, _minor, typename index_minor<T>::type )
+
+//
+// Overloads for free template functions bandwidth_row( x, tag ),
+// Here, tag is assumed to be either one of
+// tag::transpose, tag::no_transpose, or tag::conjugate
+//
+namespace result_of {
+
+template< typename T, typename TransTag >
+struct bandwidth_upper_op {
+ typedef typename bandwidth<
+ T,
+ typename index_trans< tag::index<1>, TransTag >::type
+ >::type type;
+};
+
+template< typename T, typename TransTag >
+struct bandwidth_lower_op {
+ typedef typename bandwidth< T,
+ typename index_trans< tag::index<2>, TransTag >::type >::type type;
+};
+
+} // namespace result_of
+
+template< typename T, typename Tag >
+inline typename result_of::bandwidth_upper_op< const T, Tag >::type
+bandwidth_upper_op( const T& t, Tag ) {
+ return bindings::bandwidth( t, typename index_trans< tag::index<1>, Tag >::type() );
+}
+
+template< typename T, typename Tag >
+inline typename result_of::bandwidth_upper_op< const T, Tag >::type
+bandwidth_lower_op( const T& t, Tag ) {
+ return bindings::bandwidth( t, typename index_trans< tag::index<2>, Tag >::type() );
+}
+
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif
Modified: sandbox/numeric_bindings/boost/numeric/bindings/ublas/banded.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/ublas/banded.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/ublas/banded.hpp 2010-01-08 06:48:29 EST (Fri, 08 Jan 2010)
@@ -12,9 +12,10 @@
#include <boost/numeric/bindings/begin.hpp>
#include <boost/numeric/bindings/detail/adaptor.hpp>
#include <boost/numeric/bindings/end.hpp>
+#include <boost/numeric/bindings/ublas/detail/basic_ublas_adaptor.hpp>
#include <boost/numeric/bindings/ublas/detail/convert_to.hpp>
-#include <boost/numeric/bindings/value.hpp>
#include <boost/numeric/bindings/ublas/matrix_expression.hpp>
+#include <boost/numeric/bindings/value.hpp>
#include <boost/numeric/ublas/banded.hpp>
namespace boost {
@@ -31,8 +32,8 @@
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::matrix_type, tag::banded >,
- mpl::pair< tag::data_structure, tag::banded_array >,
+ mpl::pair< tag::matrix_type, tag::band >,
+ mpl::pair< tag::data_structure, tag::band_array >,
mpl::pair< tag::data_order, typename convert_to< tag::data_order, F >::type >,
mpl::pair< tag::bandwidth_type<1>, std::ptrdiff_t >,
mpl::pair< tag::bandwidth_type<2>, std::ptrdiff_t >
@@ -54,58 +55,37 @@
return bindings::end_value( id.data() );
}
+ // A.k.a. left half-bandwidth
static std::ptrdiff_t bandwidth1( const Id& id ) {
- return id.upper();
+ return id.lower();
}
+ // A.k.a. right half-bandwidth
static std::ptrdiff_t bandwidth2( const Id& id ) {
- return id.lower();
+ return id.upper();
}
};
template< typename T, typename Id, typename Enable >
-struct adaptor< ublas::banded_adaptor< T >, Id, Enable > {
-
- typedef typename copy_const< Id, typename value< T >::type >::type value_type;
- typedef typename property_insert< T,
- mpl::pair< tag::value_type, value_type >,
- mpl::pair< tag::matrix_type, tag::banded >,
+struct adaptor< ublas::banded_adaptor< T >, Id, Enable >:
+ basic_ublas_adaptor<
+ T,
+ Id,
+ mpl::pair< tag::matrix_type, tag::band >,
mpl::pair< tag::bandwidth_type<1>, std::ptrdiff_t >,
mpl::pair< tag::bandwidth_type<2>, std::ptrdiff_t >
- >::type property_map;
-
- static std::ptrdiff_t size1( const Id& id ) {
- return bindings::size1( id.data() );
- }
-
- static std::ptrdiff_t size2( const Id& id ) {
- return bindings::size2( id.data() );
- }
-
- 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() );
- }
-
- static std::ptrdiff_t stride1( const Id& id ) {
- return bindings::stride1( id.data() );
- }
-
- static std::ptrdiff_t stride2( const Id& id ) {
- return bindings::stride2( id.data() );
- }
+ > {
+ // A.k.a. left half-bandwidth
static std::ptrdiff_t bandwidth1( const Id& id ) {
- return id.upper();
+ return id.lower();
}
+ // A.k.a. right half-bandwidth
static std::ptrdiff_t bandwidth2( const Id& id ) {
- return id.lower();
+ return id.upper();
}
};
Modified: sandbox/numeric_bindings/boost/numeric/bindings/ublas/detail/basic_ublas_adaptor.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/ublas/detail/basic_ublas_adaptor.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/ublas/detail/basic_ublas_adaptor.hpp 2010-01-08 06:48:29 EST (Fri, 08 Jan 2010)
@@ -19,7 +19,8 @@
namespace bindings {
namespace detail {
-template< typename T, typename Id, typename P1, typename P2 >
+template< typename T, typename Id, typename P1 = mpl::void_,
+ typename P2 = mpl::void_, typename P3 = mpl::void_ >
struct basic_ublas_adaptor {
typedef typename copy_const< Id, T >::type adapted_type;
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