ublas_sparse.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef BOOST_NUMERIC_BINDINGS_TRAITS_UBLAS_SPARSE_MATRIX_H
00015 #define BOOST_NUMERIC_BINDINGS_TRAITS_UBLAS_SPARSE_MATRIX_H
00016
00017 #include <cstddef>
00018 #ifndef BOOST_UBLAS_HAVE_BINDINGS
00019 # include <boost/numeric/ublas/matrix_sparse.hpp>
00020 #endif
00021 #include <boost/numeric/bindings/traits/sparse_traits.hpp>
00022 #include <boost/numeric/bindings/traits/detail/ublas_ordering.hpp>
00023 #include <algorithm>
00024
00025
00026 namespace boost { namespace numeric { namespace bindings { namespace traits {
00027
00028
00029 template <typename T, typename F, std::size_t IB, typename IA, typename TA,
00030 typename MType
00031 >
00032 struct sparse_matrix_detail_traits<
00033 boost::numeric::ublas::compressed_matrix<T,F,IB,IA,TA>,
00034 MType
00035 >
00036 {
00037 #ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK
00038 BOOST_STATIC_ASSERT(
00039 (boost::is_same<
00040 boost::numeric::ublas::compressed_matrix<T,F,IB,IA,TA>,
00041 typename boost::remove_const<MType>::type
00042 >::value)
00043 );
00044 #endif
00045
00046 typedef
00047 boost::numeric::ublas::compressed_matrix<T,F,IB,IA,TA> identifier_type;
00048 typedef MType matrix_type;
00049
00050 typedef general_t matrix_structure;
00051 typedef compressed_t storage_format;
00052 typedef typename detail::ublas_ordering<
00053 typename F::orientation_category
00054 >::type ordering_type;
00055 typedef F layout_type;
00056
00057 typedef T value_type;
00058
00059 private:
00060 typedef typename detail::generate_const<MType,TA>::type val_array_t;
00061 typedef typename detail::generate_const<MType,IA>::type idx_array_t;
00062
00063 public:
00064 typedef typename vector_traits<val_array_t>::pointer value_pointer;
00065 typedef typename vector_traits<idx_array_t>::pointer index_pointer;
00066
00067 BOOST_STATIC_CONSTANT (std::size_t, index_base = IB);
00068
00069 static index_pointer index1_storage (matrix_type& cm) {
00070
00071 return vector_traits<idx_array_t>::storage (cm.index1_data());
00072 }
00073 static index_pointer index2_storage (matrix_type& cm) {
00074 return vector_traits<idx_array_t>::storage (cm.index2_data());
00075 }
00076 static value_pointer value_storage (matrix_type& cm) {
00077 return vector_traits<val_array_t>::storage (cm.value_data());
00078 }
00079
00080 static int size1 (matrix_type& cm) { return cm.size1(); }
00081 static int size2 (matrix_type& cm) { return cm.size2(); }
00082 static int num_nonzeros (matrix_type& cm) {
00083 return cm.nnz();
00084
00085
00086 }
00087 };
00088
00089
00090
00091 template <typename T, typename F, std::size_t IB, typename IA, typename TA,
00092 typename MType
00093 >
00094 struct sparse_matrix_detail_traits<
00095 boost::numeric::ublas::coordinate_matrix<T,F,IB,IA,TA>,
00096 MType
00097 >
00098 {
00099 #ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK
00100 BOOST_STATIC_ASSERT(
00101 (boost::is_same<
00102 boost::numeric::ublas::coordinate_matrix<T,F,IB,IA,TA>,
00103 typename boost::remove_const<MType>::type
00104 >::value)
00105 );
00106 #endif
00107
00108 typedef
00109 boost::numeric::ublas::coordinate_matrix<T,F,IB,IA,TA> identifier_type;
00110 typedef MType matrix_type;
00111
00112 typedef general_t matrix_structure;
00113 typedef coordinate_t storage_format;
00114 typedef typename detail::ublas_ordering<
00115 typename F::orientation_category
00116 >::type ordering_type;
00117
00118 typedef T value_type;
00119
00120 private:
00121 typedef typename detail::generate_const<MType,TA>::type val_array_t;
00122 typedef typename detail::generate_const<MType,IA>::type idx_array_t;
00123
00124 public:
00125 typedef typename vector_traits<val_array_t>::pointer value_pointer;
00126 typedef typename vector_traits<idx_array_t>::pointer index_pointer;
00127
00128 BOOST_STATIC_CONSTANT (std::size_t, index_base = IB);
00129
00130 static index_pointer index1_storage (matrix_type& cm) {
00131 return vector_traits<idx_array_t>::storage (cm.index1_data());
00132 }
00133 static index_pointer index2_storage (matrix_type& cm) {
00134 return vector_traits<idx_array_t>::storage (cm.index2_data());
00135 }
00136 static value_pointer value_storage (matrix_type& cm) {
00137 return vector_traits<val_array_t>::storage (cm.value_data());
00138 }
00139
00140 static int size1 (matrix_type& cm) { return cm.size1(); }
00141 static int size2 (matrix_type& cm) { return cm.size2(); }
00142 static int num_nonzeros (matrix_type& cm) {
00143 return cm.nnz();
00144
00145
00146 }
00147 };
00148
00149 }}}}
00150
00151 #endif // BOOST_NUMERIC_BINDINGS_TRAITS_UBLAS_SPARSE_MATRIX_H