Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58662 - in sandbox/numeric_bindings/boost/numeric/bindings: . detail
From: rutger_at_[hidden]
Date: 2010-01-04 03:04:53


Author: rutger
Date: 2010-01-04 03:04:52 EST (Mon, 04 Jan 2010)
New Revision: 58662
URL: http://svn.boost.org/trac/boost/changeset/58662

Log:
Initial version of trans should be working

Added:
   sandbox/numeric_bindings/boost/numeric/bindings/has_triangular_array.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/index_trans.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/is_symmetric.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/lower.hpp (contents, props changed)
   sandbox/numeric_bindings/boost/numeric/bindings/upper.hpp (contents, props changed)
Text files modified:
   sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp | 6 ++
   sandbox/numeric_bindings/boost/numeric/bindings/noop.hpp | 23 +--------
   sandbox/numeric_bindings/boost/numeric/bindings/tag.hpp | 2
   sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp | 95 +++++++++++++++++++++++++++++----------
   4 files changed, 82 insertions(+), 44 deletions(-)

Modified: sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/detail/property_map.hpp 2010-01-04 03:04:52 EST (Mon, 04 Jan 2010)
@@ -56,7 +56,11 @@
     typedef typename mpl::fold<
         pair_vector,
         properties,
- mpl::insert< mpl::_1, mpl::_2 >
+ mpl::if_<
+ is_same< mpl::_2, mpl::void_ >,
+ mpl::_1,
+ mpl::insert< mpl::_1, mpl::_2 >
+ >
>::type type;
 
 };

Added: sandbox/numeric_bindings/boost/numeric/bindings/has_triangular_array.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/has_triangular_array.hpp 2010-01-04 03:04:52 EST (Mon, 04 Jan 2010)
@@ -0,0 +1,27 @@
+//
+// 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_TRIANGULAR_ARRAY_HPP
+#define BOOST_NUMERIC_BINDINGS_HAS_TRIANGULAR_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_triangular_array:
+ detail::is_same_at< T, tag::data_structure, tag::triangular_array > {};
+
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

Added: sandbox/numeric_bindings/boost/numeric/bindings/index_trans.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/index_trans.hpp 2010-01-04 03:04:52 EST (Mon, 04 Jan 2010)
@@ -0,0 +1,46 @@
+// 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_INDEX_TRANS_HPP
+#define BOOST_NUMERIC_BINDINGS_INDEX_TRANS_HPP
+
+#include <boost/numeric/bindings/tag.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+
+template< typename Index, typename TransTag >
+struct index_trans {
+ typedef Index type;
+};
+
+template<>
+struct index_trans< tag::index<1>, tag::transpose > {
+ typedef tag::index<2> type;
+};
+
+template<>
+struct index_trans< tag::index<1>, tag::conjugate > {
+ typedef tag::index<2> type;
+};
+
+template<>
+struct index_trans< tag::index<2>, tag::transpose > {
+ typedef tag::index<1> type;
+};
+
+template<>
+struct index_trans< tag::index<2>, tag::conjugate > {
+ typedef tag::index<1> type;
+};
+
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

Added: sandbox/numeric_bindings/boost/numeric/bindings/is_symmetric.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/is_symmetric.hpp 2010-01-04 03:04:52 EST (Mon, 04 Jan 2010)
@@ -0,0 +1,27 @@
+//
+// 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_IS_SYMMETRIC_HPP
+#define BOOST_NUMERIC_BINDINGS_IS_SYMMETRIC_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 is_symmetric:
+ detail::is_same_at< T, tag::matrix_type, tag::symmetric > {};
+
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

Added: sandbox/numeric_bindings/boost/numeric/bindings/lower.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/lower.hpp 2010-01-04 03:04:52 EST (Mon, 04 Jan 2010)
@@ -0,0 +1,63 @@
+//
+// 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_LOWER_HPP
+#define BOOST_NUMERIC_BINDINGS_LOWER_HPP
+
+#include <boost/numeric/bindings/detail/adaptor.hpp>
+#include <boost/numeric/bindings/detail/basic_unwrapper.hpp>
+#include <boost/numeric/bindings/tag.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+
+namespace detail {
+
+template< typename T >
+struct lower_wrapper: reference_wrapper<T> {
+ lower_wrapper( T& t ): reference_wrapper<T>( t ) {}
+};
+
+template< typename T, typename Id, typename Enable >
+struct adaptor< lower_wrapper<T>, Id, Enable >
+ basic_unwrapper< T, Id > {
+
+ typedef typename property_insert< T,
+ mpl::pair< tag::matrix_type, tag::triangular >,
+ mpl::pair< tag::data_side, tag::lower >
+ >::type property_map;
+
+};
+
+} // namespace detail
+
+namespace result_of {
+
+template< typename T >
+struct lower {
+ typedef detail::lower_wrapper<T> type;
+};
+
+} // namespace result_of
+
+template< typename T >
+detail::lower_wrapper<T> lower( T& underlying ) {
+ return detail::lower_wrapper<T>( underlying );
+}
+
+template< typename T >
+detail::lower_wrapper<const T> lower( const T& underlying ) {
+ return detail::lower_wrapper<const T>( underlying );
+}
+
+} // namespace bindings
+} // namespace numeric
+} // namespace boost
+
+#endif

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 2010-01-04 03:04:52 EST (Mon, 04 Jan 2010)
@@ -10,10 +10,7 @@
 #define BOOST_NUMERIC_BINDINGS_NOOP_HPP
 
 #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/numeric/bindings/detail/basic_unwrapper.hpp>
 #include <boost/ref.hpp>
 
 namespace boost {
@@ -29,22 +26,10 @@
 };
 
 template< typename T, typename Id, typename Enable >
-struct adaptor< noop_wrapper<T>, Id, Enable > {
+struct adaptor< noop_wrapper<T>, Id, Enable >:
+ basic_unwrapper< T, Id > {
 
- typedef adaptor< typename boost::remove_const<T>::type, T > underlying_adaptor;
- typedef typename underlying_adaptor::property_map property_map;
-
- static typename result_of::size1<T>::type size1( const Id& id ) {
- return bindings::size1( id.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() );
- }
+ typedef typename property_map_of< T >::type property_map;
 
 };
 

Modified: sandbox/numeric_bindings/boost/numeric/bindings/tag.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/tag.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/tag.hpp 2010-01-04 03:04:52 EST (Mon, 04 Jan 2010)
@@ -75,7 +75,9 @@
 ADD_TAG( structure )
 ADD_TAG( general )
 ADD_TAG( triangular )
+ADD_TAG( unit_triangular )
 ADD_TAG( symmetric )
+ADD_TAG( hermitian )
 
 ADD_TAG( num_strides )
 

Modified: sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp
==============================================================================
--- sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp (original)
+++ sandbox/numeric_bindings/boost/numeric/bindings/trans.hpp 2010-01-04 03:04:52 EST (Mon, 04 Jan 2010)
@@ -9,10 +9,15 @@
 #ifndef BOOST_NUMERIC_BINDINGS_TRANS_HPP
 #define BOOST_NUMERIC_BINDINGS_TRANS_HPP
 
-#include <boost/numeric/bindings/value.hpp>
-#include <boost/numeric/bindings/size.hpp>
-#include <boost/numeric/bindings/begin.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/insert.hpp>
 #include <boost/mpl/max.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/numeric/bindings/begin.hpp>
+#include <boost/numeric/bindings/rank.hpp>
+#include <boost/numeric/bindings/size.hpp>
+#include <boost/numeric/bindings/tag.hpp>
+#include <boost/numeric/bindings/value.hpp>
 
 namespace boost {
 namespace numeric {
@@ -24,40 +29,72 @@
     trans_wrapper( T& t ): reference_wrapper<T>( t ) {}
 };
 
+//
+// In case of linear storage
+//
 template< typename T, typename Id, typename Enable >
 struct adaptor< trans_wrapper<T>, Id, Enable > {
 
+ typedef typename property_map_of< T >::type prop_of_T;
     typedef typename property_insert< T,
- mpl::pair< tag::entity,
- typename mpl::max< tag::matrix, rank< T > >::type >,
- mpl::pair< tag::data_order,
- typename mpl::if_< is_row_major< T >,
- tag::column_major,
- tag::row_major >::type >,
+
+ // upgrade to at least a matrix
+ mpl::pair<
+ tag::entity,
+ tag::tensor< mpl::max< tag::matrix, rank< T > >::type::value >
+ >,
+
+ // size1 <-> size2
         mpl::pair< tag::size_type<1>, typename result_of::size2< T >::type >,
         mpl::pair< tag::size_type<2>, typename result_of::size1< T >::type >,
- mpl::pair< tag::stride_type<1>, typename result_of::stride2< T >::type >,
- mpl::pair< tag::stride_type<2>, typename result_of::stride1< T >::type >
- >::type property_map;
 
- // Flip size1/size2
- static typename result_of::size2< T >::type size1( const Id& t ) {
- return bindings::size2( t.get() );
- }
+ // row_major <-> column_major
+ mpl::pair<
+ tag::data_order,
+ typename mpl::if_<
+ is_row_major< T >,
+ tag::column_major,
+ tag::row_major >::type
+ >,
+
+ // If T has a linear array:
+ // stride1 <-> stride2
+ typename mpl::if_< has_linear_array< T >,
+ mpl::pair< tag::stride_type<1>, typename result_of::stride2< T >::type >,
+ mpl::void_
+ >::type,
+ typename mpl::if_< has_linear_array< T >,
+ mpl::pair< tag::stride_type<2>, typename result_of::stride1< T >::type >,
+ mpl::void_
+ >::type,
+
+ // If a data_side tag is present:
+ // upper <-> lower
+ typename mpl::if_<
+ mpl::has_key< prop_of_T, tag::data_side >,
+ typename mpl::if_<
+ is_same<
+ typename mpl::at< prop_of_T, tag::data_side >::type,
+ tag::upper
+ >,
+ mpl::pair< tag::data_side, tag::lower >,
+ mpl::pair< tag::data_side, tag::upper >
+ >::type,
+ mpl::void_
+ >::type
 
- static typename result_of::size1< T >::type size2( const Id& t ) {
- return bindings::size1( t.get() );
- }
+ >::type property_map;
 
- // Flip stride1/stride2
- static typename result_of::stride2< T >::type stride1( const Id& t ) {
- return bindings::stride2( t.get() );
+ // Flip size1/size2
+ static typename result_of::size2< T >::type size1( const Id& id ) {
+ return bindings::size2( id.get() );
     }
 
- static typename result_of::stride1< T >::type stride2( const Id& t ) {
- return bindings::stride1( t.get() );
+ static typename result_of::size1< T >::type size2( const Id& id ) {
+ return bindings::size1( id.get() );
     }
 
+ // Value array access
     static typename result_of::begin_value< T >::type begin_value( Id& id ) {
         return bindings::begin_value( id.get() );
     }
@@ -66,6 +103,16 @@
         return bindings::end_value( id.get() );
     }
 
+ // Linear array storage transpose
+ // Flip stride1/stride2
+ static typename result_of::stride2< T >::type stride1( const Id& id ) {
+ return bindings::stride2( id.get() );
+ }
+
+ static typename result_of::stride1< T >::type stride2( const Id& id ) {
+ return bindings::stride1( id.get() );
+ }
+
 };
 
 } // namespace detail

Added: sandbox/numeric_bindings/boost/numeric/bindings/upper.hpp
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/boost/numeric/bindings/upper.hpp 2010-01-04 03:04:52 EST (Mon, 04 Jan 2010)
@@ -0,0 +1,63 @@
+//
+// 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_UPPER_HPP
+#define BOOST_NUMERIC_BINDINGS_UPPER_HPP
+
+#include <boost/numeric/bindings/detail/adaptor.hpp>
+#include <boost/numeric/bindings/detail/basic_unwrapper.hpp>
+#include <boost/numeric/bindings/tag.hpp>
+
+namespace boost {
+namespace numeric {
+namespace bindings {
+
+namespace detail {
+
+template< typename T >
+struct upper_wrapper: reference_wrapper<T> {
+ upper_wrapper( T& t ): reference_wrapper<T>( t ) {}
+};
+
+template< typename T, typename Id, typename Enable >
+struct adaptor< upper_wrapper<T>, Id, Enable >:
+ basic_unwrapper< T, Id > {
+
+ typedef typename property_insert< T,
+ mpl::pair< tag::matrix_type, tag::triangular >,
+ mpl::pair< tag::data_side, tag::upper >
+ >::type property_map;
+
+};
+
+} // namespace detail
+
+namespace result_of {
+
+template< typename T >
+struct upper {
+ typedef detail::upper_wrapper<T> type;
+};
+
+} // namespace result_of
+
+template< typename T >
+detail::upper_wrapper<T> upper( T& underlying ) {
+ return detail::upper_wrapper<T>( underlying );
+}
+
+template< typename T >
+detail::upper_wrapper<const T> upper( const T& underlying ) {
+ return detail::upper_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