|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r58958 - in sandbox/numeric_bindings/boost/numeric/bindings: . detail ublas
From: rutger_at_[hidden]
Date: 2010-01-13 03:31:43
Author: rutger
Date: 2010-01-13 03:31:42 EST (Wed, 13 Jan 2010)
New Revision: 58958
URL: http://svn.boost.org/trac/boost/changeset/58958
Log:
added offset computation for correct handling of linear arrays and band arrays in e.g. matrix ranges. The lapack regression ublas_hbev now passes.
Added:
sandbox/numeric_bindings/boost/numeric/bindings/detail/offset.hpp (contents, props changed)
sandbox/numeric_bindings/boost/numeric/bindings/has_band_array.hpp (contents, props changed)
Text files modified:
sandbox/numeric_bindings/boost/numeric/bindings/ublas/banded.hpp | 5 +++--
sandbox/numeric_bindings/boost/numeric/bindings/ublas/matrix_proxy.hpp | 5 ++---
2 files changed, 5 insertions(+), 5 deletions(-)
Added: sandbox/numeric_bindings/boost/numeric/bindings/detail/offset.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/offset.hpp 2010-01-13 03:31:42 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,62 @@
+//
+// 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_OFFSET_HPP
+#define BOOST_NUMERIC_BINDINGS_DETAIL_OFFSET_HPP
+
+#include <boost/utility/enable_if.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/numeric/bindings/is_column_major.hpp>
+#include <boost/numeric/bindings/has_linear_array.hpp>
+#include <boost/numeric/bindings/has_band_array.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+namespace detail {
+
+template< typename Id, typename Enable = void >
+struct offset_impl {};
+
+template< typename Id >
+struct offset_impl< Id, typename boost::enable_if< has_linear_array< Id > >::type > {
+
+ static std::ptrdiff_t invoke( const Id& id, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
+ return i1 * bindings::stride1( id ) +
+ i2 * bindings::stride2( id );
+ }
+
+};
+
+template< typename Id >
+struct offset_impl< Id,
+ typename boost::enable_if<
+ mpl::and_<
+ has_band_array< Id >,
+ is_column_major< Id >
+ >
+ >::type > {
+
+ static std::ptrdiff_t invoke( const Id& id, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
+ return i1 * bindings::stride1( id ) +
+ i2 * (bindings::stride2( id )-1);
+ }
+
+};
+
+template< typename Id >
+std::ptrdiff_t offset( const Id& id, std::ptrdiff_t i1, std::ptrdiff_t i2 ) {
+ return offset_impl< Id >::invoke( id, i1, i2 );
+}
+
+} // namespace detail
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif
Added: sandbox/numeric_bindings/boost/numeric/bindings/has_band_array.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/has_band_array.hpp 2010-01-13 03:31:42 EST (Wed, 13 Jan 2010)
@@ -0,0 +1,28 @@
+//
+// Copyright (c) 2009 by 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_HAS_BAND_ARRAY_HPP
+#define BOOST_NUMERIC_BINDINGS_HAS_BAND_ARRAY_HPP
+
+#include <boost/numeric/bindings/detail/property_map.hpp>
+#include <boost/numeric/bindings/tag.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+
+template< typename T >
+struct has_band_array:
+ detail::is_same_at< T, tag::data_structure, tag::band_array > {};
+
+
+} // 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-13 03:31:42 EST (Wed, 13 Jan 2010)
@@ -78,9 +78,10 @@
return id.upper();
}
+ // These strides are over the band array structure; not over
+ // the band matrix representation of this structure
static std::ptrdiff_t stride1( const Id& id ) {
- // ?
- return 1;
+ return id.lower() + id.upper() + 1;
}
static std::ptrdiff_t stride2( const Id& id ) {
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-13 03:31:42 EST (Wed, 13 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>
@@ -37,9 +38,7 @@
}
static typename result_of::begin_value< adapted_type >::type begin_value( Id& id ) {
- return bindings::begin_value( id.data() ) +
- id.start1() * stride1( id ) +
- id.start2() * stride2( id );
+ return bindings::begin_value( id.data() ) + offset( id, id.start1(), id.start2() );
}
static typename result_of::end_value< adapted_type >::type end_value( Id& id ) {
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