1 // 2 // Copyright (c) 2009 Rutger ter Borg 3 // 4 // Distributed under the Boost Software License, Version 1.0. 5 // (See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 9 #ifndef BOOST_NUMERIC_BINDINGS_UBLAS_MATRIX_EXPRESSION_HPP 10 #define BOOST_NUMERIC_BINDINGS_UBLAS_MATRIX_EXPRESSION_HPP 11 12 #include <boost/numeric/bindings/bandwidth.hpp> 13 #include <boost/numeric/bindings/begin.hpp> 14 #include <boost/numeric/bindings/detail/adaptor.hpp> 15 #include <boost/numeric/bindings/detail/property_map.hpp> 16 #include <boost/numeric/bindings/end.hpp> 17 #include <boost/numeric/bindings/size.hpp> 18 #include <boost/numeric/ublas/matrix_expression.hpp> 19 20 #include <boost/mpl/replace.hpp> 21 22 namespace boost { 23 namespace numeric { 24 namespace bindings { 25 namespace detail { 26 27 template< typename T, typename Id, typename Enable > 28 struct adaptor< boost::numeric::ublas::matrix_reference< T >, Id, Enable > { 29 30 typedef typename copy_const< Id, T >::type adapted_type; 31 typedef typename property_map_of< adapted_type >::type property_map; 32 size1boost::numeric::bindings::detail::adaptor33 static std::ptrdiff_t size1( const Id& id ) { 34 return id.size1(); 35 } 36 size2boost::numeric::bindings::detail::adaptor37 static std::ptrdiff_t size2( const Id& id ) { 38 return id.size2(); 39 } 40 begin_valueboost::numeric::bindings::detail::adaptor41 static typename result_of::begin_value< adapted_type >::type begin_value( Id& id ) { 42 return bindings::begin_value( id.expression() ); 43 } 44 end_valueboost::numeric::bindings::detail::adaptor45 static typename result_of::end_value< adapted_type >::type end_value( Id& id ) { 46 return bindings::end_value( id.expression() ); 47 } 48 stride1boost::numeric::bindings::detail::adaptor49 static std::ptrdiff_t stride1( const Id& id ) { 50 return bindings::stride1( id.expression() ); 51 } 52 stride2boost::numeric::bindings::detail::adaptor53 static std::ptrdiff_t stride2( const Id& id ) { 54 return bindings::stride2( id.expression() ); 55 } 56 bandwidth1boost::numeric::bindings::detail::adaptor57 static std::ptrdiff_t bandwidth1( const Id& id ) { 58 return bindings::bandwidth1( id.expression() ); 59 } 60 bandwidth2boost::numeric::bindings::detail::adaptor61 static std::ptrdiff_t bandwidth2( const Id& id ) { 62 return bindings::bandwidth2( id.expression() ); 63 } 64 65 }; 66 67 template< typename T, typename U, typename Id, typename Enable > 68 struct adaptor< boost::numeric::ublas::matrix_unary2< T, U >, Id, Enable > { 69 70 typedef typename copy_const< Id, T >::type adapted_type; 71 typedef typename property_map_of< adapted_type >::type map; 72 73 typedef mpl::map< 74 mpl::pair<tag::value_type, typename mpl::at<map, tag::value_type>::type>, 75 mpl::pair<tag::entity, typename mpl::at<map, tag::entity>::type>, 76 mpl::pair<tag::size_type<1>, typename mpl::at<map, tag::size_type<1> >::type>, 77 mpl::pair<tag::size_type<2>, typename mpl::at<map, tag::size_type<2> >::type>, 78 mpl::pair<tag::data_structure, typename mpl::at<map, tag::data_structure>::type>, 79 80 mpl::pair<tag::data_order, 81 typename mpl::if_< 82 is_same< 83 typename mpl::at<map, tag::data_order>::type, 84 tag::row_major>, 85 tag::column_major, 86 tag::row_major 87 >::type>, 88 89 mpl::pair<tag::stride_type<1>, typename mpl::at<map, tag::stride_type<2> >:: type>, 90 mpl::pair<tag::stride_type<2>, typename mpl::at<map, tag::stride_type<1> >:: type> 91 > property_map; 92 size1boost::numeric::bindings::detail::adaptor93 static std::ptrdiff_t size1( const Id& id ) { 94 return id.size1(); 95 } 96 size2boost::numeric::bindings::detail::adaptor97 static std::ptrdiff_t size2( const Id& id ) { 98 return id.size2(); 99 } 100 101 static typename result_of::begin_value< adapted_type >::type begin_valueboost::numeric::bindings::detail::adaptor102 begin_value( Id& id ) { 103 return bindings::begin_value( id.expression() ); 104 } 105 106 static typename result_of::end_value< adapted_type >::type end_valueboost::numeric::bindings::detail::adaptor107 end_value( Id& id ) { 108 return bindings::end_value( id.expression() ); 109 } 110 stride1boost::numeric::bindings::detail::adaptor111 static std::ptrdiff_t stride1( const Id& id ) { 112 return bindings::stride2( id.expression() ); 113 } 114 stride2boost::numeric::bindings::detail::adaptor115 static std::ptrdiff_t stride2( const Id& id ) { 116 return bindings::stride1( id.expression() ); 117 } 118 119 }; 120 121 } // namespace detail 122 } // namespace bindings 123 } // namespace numeric 124 } // namespace boost 125 126 #endif 127