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_SPARSE_HPP 10 #define BOOST_NUMERIC_BINDINGS_UBLAS_MATRIX_SPARSE_HPP 11 12 #include <boost/numeric/bindings/begin.hpp> 13 #include <boost/numeric/bindings/end.hpp> 14 #include <boost/numeric/bindings/detail/adaptor.hpp> 15 #include <boost/numeric/bindings/detail/copy_const.hpp> 16 #include <boost/numeric/bindings/ublas/detail/convert_to.hpp> 17 #include <boost/numeric/bindings/ublas/matrix_expression.hpp> 18 #include <boost/numeric/bindings/ublas/storage.hpp> 19 #include <boost/numeric/ublas/matrix_sparse.hpp> 20 21 namespace boost { 22 namespace numeric { 23 namespace bindings { 24 namespace detail { 25 26 template< typename T, typename F, std::size_t IB, typename IA, typename TA, typename Id, typename Enable > 27 struct adaptor< ublas::compressed_matrix< T, F, IB, IA, TA >, Id, Enable > { 28 29 typedef typename copy_const< Id, T >::type value_type; 30 typedef typename copy_const< Id, typename bindings::value_type<IA>::type >::type index_type; 31 typedef typename convert_to< tag::data_order, F >::type data_order; 32 typedef mpl::map< 33 mpl::pair< tag::value_type, value_type >, 34 mpl::pair< tag::index_type, index_type >, 35 mpl::pair< tag::entity, tag::matrix >, 36 mpl::pair< tag::size_type<1>, std::ptrdiff_t >, 37 mpl::pair< tag::size_type<2>, std::ptrdiff_t >, 38 mpl::pair< tag::matrix_type, tag::general >, 39 mpl::pair< tag::data_structure, tag::compressed_sparse >, 40 mpl::pair< tag::data_order, data_order >, 41 mpl::pair< tag::index_base, mpl::int_<IB> > 42 > property_map; 43 size1boost::numeric::bindings::detail::adaptor44 static std::ptrdiff_t size1( const Id& id ) { 45 return id.size1(); 46 } 47 size2boost::numeric::bindings::detail::adaptor48 static std::ptrdiff_t size2( const Id& id ) { 49 return id.size2(); 50 } 51 begin_valueboost::numeric::bindings::detail::adaptor52 static value_type* begin_value( Id& id ) { 53 return bindings::begin_value( id.value_data() ); 54 } 55 end_valueboost::numeric::bindings::detail::adaptor56 static value_type* end_value( Id& id ) { 57 return bindings::begin_value( id.value_data() ) + id.nnz(); 58 } 59 begin_compressed_index_majorboost::numeric::bindings::detail::adaptor60 static index_type* begin_compressed_index_major( Id& id ) { 61 return bindings::begin_value( id.index1_data() ); 62 } 63 end_compressed_index_majorboost::numeric::bindings::detail::adaptor64 static index_type* end_compressed_index_major( Id& id ) { 65 return bindings::end_value( id.index1_data() ); 66 } 67 begin_index_minorboost::numeric::bindings::detail::adaptor68 static index_type* begin_index_minor( Id& id ) { 69 return bindings::begin_value( id.index2_data() ); 70 } 71 end_index_minorboost::numeric::bindings::detail::adaptor72 static index_type* end_index_minor( Id& id ) { 73 return bindings::begin_value( id.index2_data() ) + id.nnz(); 74 } 75 76 }; 77 78 template< typename T, typename F, std::size_t IB, typename IA, typename TA, typename Id, typename Enable > 79 struct adaptor< ublas::coordinate_matrix< T, F, IB, IA, TA >, Id, Enable > { 80 81 typedef typename copy_const< Id, T >::type value_type; 82 typedef typename copy_const< Id, typename bindings::value_type<IA>::type >::type index_type; 83 typedef typename convert_to< tag::data_order, F >::type data_order; 84 typedef mpl::map< 85 mpl::pair< tag::value_type, value_type >, 86 mpl::pair< tag::index_type, index_type >, 87 mpl::pair< tag::entity, tag::matrix >, 88 mpl::pair< tag::size_type<1>, std::ptrdiff_t >, 89 mpl::pair< tag::size_type<2>, std::ptrdiff_t >, 90 mpl::pair< tag::matrix_type, tag::general >, 91 mpl::pair< tag::data_structure, tag::coordinate_sparse >, 92 mpl::pair< tag::data_order, data_order >, 93 mpl::pair< tag::index_base, mpl::int_<IB> > 94 > property_map; 95 size1boost::numeric::bindings::detail::adaptor96 static std::ptrdiff_t size1( const Id& id ) { 97 return id.size1(); 98 } 99 size2boost::numeric::bindings::detail::adaptor100 static std::ptrdiff_t size2( const Id& id ) { 101 return id.size2(); 102 } 103 begin_valueboost::numeric::bindings::detail::adaptor104 static value_type* begin_value( Id& id ) { 105 return bindings::begin_value( id.value_data() ); 106 } 107 end_valueboost::numeric::bindings::detail::adaptor108 static value_type* end_value( Id& id ) { 109 return bindings::begin_value( id.value_data() ) + id.nnz(); 110 } 111 begin_index_majorboost::numeric::bindings::detail::adaptor112 static index_type* begin_index_major( Id& id ) { 113 return bindings::begin_value( id.index1_data() ); 114 } 115 end_index_majorboost::numeric::bindings::detail::adaptor116 static index_type* end_index_major( Id& id ) { 117 return bindings::begin_value( id.index1_data() ) + id.nnz(); 118 } 119 begin_index_minorboost::numeric::bindings::detail::adaptor120 static index_type* begin_index_minor( Id& id ) { 121 return bindings::begin_value( id.index2_data() ); 122 } 123 end_index_minorboost::numeric::bindings::detail::adaptor124 static index_type* end_index_minor( Id& id ) { 125 return bindings::begin_value( id.index2_data() ) + id.nnz(); 126 } 127 128 }; 129 130 } // namespace detail 131 } // namespace bindings 132 } // namespace numeric 133 } // namespace boost 134 135 #endif 136