ublas_vector.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_VECTOR_H
00015 #define BOOST_NUMERIC_BINDINGS_TRAITS_UBLAS_VECTOR_H
00016
00017 #include <boost/numeric/bindings/traits/vector_traits.hpp>
00018
00019 #ifndef BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
00020
00021 #ifndef BOOST_UBLAS_HAVE_BINDINGS
00022 # include <boost/numeric/ublas/vector.hpp>
00023 #endif
00024
00025
00026 namespace boost { namespace numeric { namespace bindings { namespace traits {
00027
00028
00029 template <typename T, typename ArrT, typename V>
00030 struct vector_detail_traits< boost::numeric::ublas::vector<T, ArrT>, V >
00031 : default_vector_traits< V, T >
00032 {
00033 #ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK
00034 BOOST_STATIC_ASSERT( (boost::is_same< boost::numeric::ublas::vector<T, ArrT>, typename boost::remove_const<V>::type >::value) );
00035 #endif
00036
00037 typedef boost::numeric::ublas::vector<T, ArrT> identifier_type;
00038 typedef V vector_type;
00039 typedef typename default_vector_traits< V, T >::pointer pointer;
00040
00041 static pointer storage (vector_type& v) {
00042 typedef typename detail::generate_const<V,ArrT>::type array_type ;
00043 return vector_traits<array_type>::storage (v.data());
00044 }
00045 };
00046
00047
00048 template <typename V, typename VR>
00049 struct vector_detail_traits< boost::numeric::ublas::vector_reference<V>, VR >
00050 : default_vector_traits< VR, typename V::value_type >
00051 {
00052 #ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK
00053 BOOST_STATIC_ASSERT( (boost::is_same< boost::numeric::ublas::vector_reference<V>, typename boost::remove_const<VR>::type >::value) );
00054 #endif
00055
00056 typedef boost::numeric::ublas::vector_reference<V> identifier_type;
00057 typedef VR vector_type;
00058 typedef typename V::value_type value_type ;
00059 typedef typename default_vector_traits<VR,value_type>::pointer pointer;
00060
00061 private:
00062 typedef typename detail::generate_const<VR,V>::type vct_t;
00063
00064 public:
00065 static pointer storage (vector_type& v) {
00066 return vector_traits<vct_t>::storage (v.expression());
00067 }
00068 static int stride (vector_type& v) {
00069 return vector_traits<vct_t>::stride (v.expression());
00070 }
00071 };
00072
00073
00074 template <typename V, typename VR>
00075 struct vector_detail_traits< boost::numeric::ublas::vector_range<V>, VR >
00076 : default_vector_traits< VR, typename V::value_type >
00077 {
00078 #ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK
00079 BOOST_STATIC_ASSERT( (boost::is_same< boost::numeric::ublas::vector_range<V>, typename boost::remove_const<VR>::type >::value) );
00080 #endif
00081
00082 typedef boost::numeric::ublas::vector_range<V> identifier_type;
00083 typedef VR vector_type;
00084 typedef typename V::value_type value_type ;
00085 typedef typename default_vector_traits<VR,value_type>::pointer pointer;
00086
00087 private:
00088 typedef typename detail::generate_const<VR, typename VR::vector_closure_type>::type v_type;
00089
00090 public:
00091 static pointer storage (vector_type& vr) {
00092 pointer ptr = vector_traits<v_type>::storage (vr.data());
00093 ptr += vr.start() * vector_traits<v_type>::stride (vr.data());
00094 return ptr;
00095 }
00096 static int stride (vector_type& vr) {
00097 return vector_traits<v_type>::stride (vr.data());
00098 }
00099 };
00100
00101
00102
00103 template <typename V, typename VS>
00104 struct vector_detail_traits<boost::numeric::ublas::vector_slice<V>, VS >
00105 : default_vector_traits< VS, typename V::value_type >
00106 {
00107 #ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK
00108 BOOST_STATIC_ASSERT( (boost::is_same< boost::numeric::ublas::vector_slice<V>, typename boost::remove_const<VS>::type >::value) );
00109 #endif
00110
00111 typedef boost::numeric::ublas::vector_slice<V> identifier_type;
00112 typedef VS vector_type;
00113 typedef typename V::value_type value_type ;
00114 typedef typename default_vector_traits<VS,value_type>::pointer pointer;
00115
00116 private:
00117 typedef typename detail::generate_const<VS, typename VS::vector_closure_type>::type v_type;
00118
00119 public:
00120 static pointer storage (vector_type& vs) {
00121 pointer ptr = vector_traits<v_type>::storage (vs.data());
00122 ptr += vs.start() * vector_traits<v_type>::stride (vs.data());
00123 return ptr;
00124 }
00125 static int stride (vector_type& vs) {
00126 return vs.stride() * vector_traits<v_type>::stride (vs.data());
00127 }
00128 };
00129
00130
00131 #ifndef BOOST_NUMERIC_BINDINGS_FORTRAN
00132
00133
00134 template <typename T, std::size_t N, typename V>
00135 struct vector_detail_traits< boost::numeric::ublas::c_vector<T, N>, V >
00136 : default_vector_traits< V, T >
00137 {
00138 #ifndef BOOST_NUMERIC_BINDINGS_NO_SANITY_CHECK
00139 BOOST_STATIC_ASSERT( (boost::is_same< boost::numeric::ublas::c_vector<T,N>, typename boost::remove_const<V>::type >::value) );
00140 #endif
00141
00142 typedef boost::numeric::ublas::c_vector<T,N> identifier_type;
00143 typedef V vector_type;
00144 typedef typename default_vector_traits<V,T>::pointer pointer;
00145
00146 static pointer storage (vector_type& v) { return v.data(); }
00147 };
00148
00149 #endif // BOOST_NUMERIC_BINDINGS_FORTRAN
00150
00151
00152 }}}}
00153
00154 #endif // BOOST_NUMERIC_BINDINGS_POOR_MANS_TRAITS
00155
00156 #endif // BOOST_NUMERIC_BINDINGS_TRAITS_UBLAS_VECTOR_H