1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
//
// 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_TRANS_HPP
#define BOOST_NUMERIC_BINDINGS_TRANS_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/end.hpp>
#include <boost/numeric/bindings/is_column_major.hpp>
#include <boost/numeric/bindings/rank.hpp>
#include <boost/numeric/bindings/size.hpp>
#include <boost/numeric/bindings/bandwidth.hpp>
#include <boost/numeric/bindings/tag.hpp>
#include <boost/numeric/bindings/value_type.hpp>
#include <boost/numeric/bindings/has_band_array.hpp>
#include <boost/numeric/bindings/has_linear_array.hpp>
#include <boost/ref.hpp>
namespace boost {
namespace numeric {
namespace bindings {
namespace detail {
template< typename T, typename Conj >
struct trans_wrapper: reference_wrapper<T> {
trans_wrapper( T& t ): reference_wrapper<T>( t ) {}
};
//
// In case of linear storage
//
template< typename T, typename Conj, typename Id, typename Enable >
struct adaptor< trans_wrapper<T, Conj>, Id, Enable > {
typedef typename property_map_of< T >::type prop_of_T;
typedef typename property_insert< T,
// 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 >,
// row_major <-> column_major
mpl::pair<
tag::data_order,
typename mpl::if_<
is_column_major< T >,
tag::row_major,
tag::column_major >::type
>,
// Conjugate transform (if passed by template argument)
Conj,
// If T has a linear array, or has a band array
// flip strides, stride1 <-> stride2
typename mpl::if_< mpl::or_< has_linear_array< T >, has_band_array< T > >,
mpl::pair< tag::stride_type<1>, typename result_of::stride2< T >::type >,
mpl::void_
>::type,
typename mpl::if_< mpl::or_< has_linear_array< T >, has_band_array< T > >,
mpl::pair< tag::stride_type<2>, typename result_of::stride1< T >::type >,
mpl::void_
>::type,
// If T has a band array
// flip bandwidths, bandwidth1 <-> bandwidth2
typename mpl::if_< has_band_array< T >,
mpl::pair< tag::bandwidth_type<1>, typename result_of::bandwidth2< T >::type >,
mpl::void_
>::type,
typename mpl::if_< has_band_array< T >,
mpl::pair< tag::bandwidth_type<2>, typename result_of::bandwidth1< 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
>::type property_map;
// Flip size1/size2
static typename result_of::size2< T >::type size1( const Id& id ) {
return bindings::size2( id.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() );
}
static typename result_of::end_value< T >::type end_value( Id& id ) {
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() );
}
// Banded matrix transpose
// Flip bandwidth1/bandwidth2
static typename result_of::bandwidth2< T >::type bandwidth1( const Id& id ) {
return bindings::bandwidth2( id.get() );
}
static typename result_of::bandwidth1< T >::type bandwidth2( const Id& id ) {
return bindings::bandwidth1( id.get() );
}
};
} // namespace detail
namespace result_of {
template< typename T >
struct trans {
typedef detail::trans_wrapper<T, mpl::void_> type;
};
}
template< typename T >
typename result_of::trans<T>::type const trans( T& underlying ) {
return detail::trans_wrapper<T, mpl::void_>( underlying );
}
template< typename T >
typename result_of::trans<const T>::type const trans( const T& underlying ) {
return detail::trans_wrapper<const T, mpl::void_>( underlying );
}
} // namespace bindings
} // namespace numeric
} // namespace boost
#endif
|