1 //
2 // Copyright (c) 2002 Kresimir Fresl
3 // Copyright (c) 2010 Rutger ter Borg
4 //
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 
10 #ifndef BOOST_NUMERIC_BINDINGS_UBLAS_BANDED_HPP
11 #define BOOST_NUMERIC_BINDINGS_UBLAS_BANDED_HPP
12 
13 #include <boost/numeric/bindings/begin.hpp>
14 #include <boost/numeric/bindings/detail/adaptor.hpp>
15 #include <boost/numeric/bindings/detail/if_row_major.hpp>
16 #include <boost/numeric/bindings/end.hpp>
17 #include <boost/numeric/bindings/ublas/detail/basic_ublas_adaptor.hpp>
18 #include <boost/numeric/bindings/ublas/detail/convert_to.hpp>
19 #include <boost/numeric/bindings/ublas/matrix_expression.hpp>
20 #include <boost/numeric/bindings/value_type.hpp>
21 #include <boost/numeric/ublas/banded.hpp>
22 
23 namespace boost {
24 namespace numeric {
25 namespace bindings {
26 namespace detail {
27 
28 template< typename T, typename F, typename A, typename Id, typename Enable >
29 struct adaptor< ublas::banded_matrix< T, F, A >, Id, Enable > {
30 
31     // The ublas banded row_major format corresponds to the LAPACK band format.
32     // LAPACK is column_major; so we flip the data order reported by uBLAS.
33     typedef typename copy_const< Id, T >::type value_type;
34     typedef typename if_row_major<
35                 typename convert_to< tag::data_order, F >::type,
36                 tag::column_major,
37                 tag::row_major
38             >::type data_order;
39     typedef mpl::map<
40         mpl::pair< tag::value_type, value_type >,
41         mpl::pair< tag::entity, tag::matrix >,
42         mpl::pair< tag::size_type<1>, std::ptrdiff_t >,
43         mpl::pair< tag::size_type<2>, std::ptrdiff_t >,
44         mpl::pair< tag::matrix_type, tag::band >,
45         mpl::pair< tag::data_structure, tag::band_array >,
46         mpl::pair< tag::data_order, data_order >,
47         mpl::pair< tag::bandwidth_type<1>, std::ptrdiff_t >,
48         mpl::pair< tag::bandwidth_type<2>, std::ptrdiff_t >,
49         mpl::pair< tag::stride_type<1>,
50             typename if_row_major< data_order, std::ptrdiff_t, tag::contiguous >::type >,
51         mpl::pair< tag::stride_type<2>,
52             typename if_row_major< data_order, tag::contiguous, std::ptrdiff_t >::type >
53     > property_map;
54 
size1boost::numeric::bindings::detail::adaptor55     static std::ptrdiff_t size1( const Id& id ) {
56         return id.size1();
57     }
58 
size2boost::numeric::bindings::detail::adaptor59     static std::ptrdiff_t size2( const Id& id ) {
60         return id.size2();
61     }
62 
begin_valueboost::numeric::bindings::detail::adaptor63     static value_type* begin_value( Id& id ) {
64         return bindings::begin_value( id.data() );
65     }
66 
end_valueboost::numeric::bindings::detail::adaptor67     static value_type* end_value( Id& id ) {
68         return bindings::end_value( id.data() );
69     }
70 
71     // A.k.a. left half-bandwidth
bandwidth1boost::numeric::bindings::detail::adaptor72     static std::ptrdiff_t bandwidth1( const Id& id ) {
73         return id.lower();
74     }
75 
76     // A.k.a. right half-bandwidth
bandwidth2boost::numeric::bindings::detail::adaptor77     static std::ptrdiff_t bandwidth2( const Id& id ) {
78         return id.upper();
79     }
80 
81     // These strides are over the band array structure; not over
82     // the band matrix representation of this structure
stride1boost::numeric::bindings::detail::adaptor83     static std::ptrdiff_t stride1( const Id& id ) {
84         return id.lower() + id.upper() + 1;
85     }
86 
stride2boost::numeric::bindings::detail::adaptor87     static std::ptrdiff_t stride2( const Id& id ) {
88         return id.lower() + id.upper() + 1;
89     }
90 
91 };
92 
93 
94 template< typename T, typename Id, typename Enable >
95 struct adaptor< ublas::banded_adaptor< T >, Id, Enable >:
96     basic_ublas_adaptor<
97         T,
98         Id,
99         mpl::pair< tag::matrix_type, tag::band >,
100         mpl::pair< tag::bandwidth_type<1>, std::ptrdiff_t >,
101         mpl::pair< tag::bandwidth_type<2>, std::ptrdiff_t >
102     > {
103 
104     // A.k.a. left half-bandwidth
bandwidth1boost::numeric::bindings::detail::adaptor105     static std::ptrdiff_t bandwidth1( const Id& id ) {
106         return id.lower();
107     }
108 
109     // A.k.a. right half-bandwidth
bandwidth2boost::numeric::bindings::detail::adaptor110     static std::ptrdiff_t bandwidth2( const Id& id ) {
111         return id.upper();
112     }
113 
114 };
115 
116 } // detail
117 } // bindings
118 } // numeric
119 } // boost
120 
121 #endif
122