File indexing completed on 2025-01-18 09:42:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef _BOOST_UBLAS_DEFINITIONS_
0014 #define _BOOST_UBLAS_DEFINITIONS_
0015
0016
0017 namespace boost { namespace numeric { namespace ublas {
0018
0019 namespace detail {
0020
0021
0022
0023
0024 template <class T> inline
0025 void ignore_unused_variable_warning(const T&) {}
0026 }
0027
0028
0029
0030 namespace nonassignable_
0031 {
0032 class nonassignable {
0033 protected:
0034 nonassignable () {}
0035 ~nonassignable () {}
0036 private:
0037 const nonassignable& operator= (const nonassignable &);
0038 };
0039 }
0040 typedef nonassignable_::nonassignable nonassignable;
0041
0042
0043
0044
0045 template<class C>
0046 class noalias_proxy:
0047 private nonassignable {
0048 public:
0049 typedef typename C::closure_type closure_type;
0050
0051 BOOST_UBLAS_INLINE
0052 noalias_proxy (C& lval):
0053 nonassignable (), lval_ (lval) {}
0054 BOOST_UBLAS_INLINE
0055 noalias_proxy (const noalias_proxy& p):
0056 nonassignable (), lval_ (p.lval_) {}
0057
0058 template <class E>
0059 BOOST_UBLAS_INLINE
0060 closure_type &operator= (const E& e) {
0061 lval_.assign (e);
0062 return lval_;
0063 }
0064
0065 template <class E>
0066 BOOST_UBLAS_INLINE
0067 closure_type &operator+= (const E& e) {
0068 lval_.plus_assign (e);
0069 return lval_;
0070 }
0071
0072 template <class E>
0073 BOOST_UBLAS_INLINE
0074 closure_type &operator-= (const E& e) {
0075 lval_.minus_assign (e);
0076 return lval_;
0077 }
0078
0079 private:
0080 closure_type lval_;
0081 };
0082
0083
0084
0085 template <class C>
0086 BOOST_UBLAS_INLINE
0087 noalias_proxy<C> noalias (C& lvalue) {
0088 return noalias_proxy<C> (lvalue);
0089 }
0090 template <class C>
0091 BOOST_UBLAS_INLINE
0092 noalias_proxy<const C> noalias (const C& lvalue) {
0093 return noalias_proxy<const C> (lvalue);
0094 }
0095
0096
0097
0098 template <class C>
0099 BOOST_UBLAS_INLINE
0100 C& safe (C& lvalue) {
0101 return lvalue;
0102 }
0103 template <class C>
0104 BOOST_UBLAS_INLINE
0105 const C& safe (const C& lvalue) {
0106 return lvalue;
0107 }
0108
0109
0110
0111 namespace dimension {
0112
0113
0114 template<unsigned dimension>
0115 struct dimension_properties {};
0116
0117 template<>
0118 struct dimension_properties<1> {
0119 template <class E>
0120 BOOST_UBLAS_INLINE static
0121 typename E::size_type size (const vector_expression<E> &e) {
0122 return e ().size ();
0123 }
0124 template <class E>
0125 BOOST_UBLAS_INLINE static
0126 typename E::size_type size (const matrix_expression<E> &e) {
0127 return e ().size1 ();
0128 }
0129
0130 template <class V>
0131 BOOST_UBLAS_INLINE static
0132 typename V::size_type index (const typename V::iterator &i) {
0133 return i.index ();
0134 }
0135 template <class M>
0136 BOOST_UBLAS_INLINE static
0137 typename M::size_type index (const typename M::iterator1 &i) {
0138 return i.index1 ();
0139 }
0140 template <class M>
0141 BOOST_UBLAS_INLINE static
0142 typename M::size_type index (const typename M::iterator2 &i) {
0143 return i.index1 ();
0144 }
0145 };
0146 template<>
0147 struct dimension_properties<2> {
0148 template <class E>
0149 BOOST_UBLAS_INLINE static
0150 typename E::size_type size (const vector_expression<E> &) {
0151 return 1;
0152 }
0153 template <class E>
0154 BOOST_UBLAS_INLINE static
0155 typename E::size_type size (const matrix_expression<E> &e) {
0156 return e ().size2 ();
0157 }
0158 template <class V>
0159 BOOST_UBLAS_INLINE static
0160 typename V::size_type index (const typename V::iterator &) {
0161 return 1;
0162 }
0163 template <class M>
0164 BOOST_UBLAS_INLINE static
0165 typename M::size_type index (const typename M::iterator1 &i) {
0166 return i.index2 ();
0167 }
0168 template <class M>
0169 BOOST_UBLAS_INLINE static
0170 typename M::size_type index (const typename M::iterator2 &i) {
0171 return i.index2 ();
0172 }
0173 };
0174
0175 template<unsigned dimension, class E>
0176 BOOST_UBLAS_INLINE
0177 typename E::size_type size (const E& e) {
0178 return dimension_properties<dimension>::size (e);
0179 }
0180
0181 template<unsigned dimension, class I>
0182 BOOST_UBLAS_INLINE
0183 typename I::container_type::size_type
0184 index (const I& i) {
0185 typedef typename I::container_type container_type;
0186 return dimension_properties<dimension>::template index<container_type> (i);
0187 }
0188
0189
0190
0191 template<class V>
0192 typename V::size_type num_elements (const V &v) {
0193 return v.size ();
0194 }
0195 template<class M>
0196 typename M::size_type num_rows (const M &m) {
0197 return m.size1 ();
0198 }
0199 template<class M>
0200 typename M::size_type num_columns (const M &m) {
0201 return m.size2 ();
0202 }
0203 template<class MV>
0204 typename MV::size_type num_non_zeros (const MV &mv) {
0205 return mv.non_zeros ();
0206 }
0207 }
0208
0209
0210 }}}
0211
0212 #endif