Chris@16
|
1 //
|
Chris@16
|
2 // Copyright (c) 2000-2002
|
Chris@16
|
3 // Joerg Walter, Mathias Koch
|
Chris@16
|
4 //
|
Chris@16
|
5 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
6 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //
|
Chris@16
|
9 // The authors gratefully acknowledge the support of
|
Chris@16
|
10 // GeNeSys mbH & Co. KG in producing this work.
|
Chris@16
|
11 //
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef _BOOST_UBLAS_DEFINITIONS_
|
Chris@16
|
14 #define _BOOST_UBLAS_DEFINITIONS_
|
Chris@16
|
15
|
Chris@16
|
16
|
Chris@16
|
17 namespace boost { namespace numeric { namespace ublas {
|
Chris@16
|
18
|
Chris@16
|
19 namespace detail {
|
Chris@16
|
20 /* Borrowed from boost/concept_checks.hpp
|
Chris@16
|
21 "inline" is used for ignore_unused_variable_warning()
|
Chris@16
|
22 to make sure there is no overhead with g++.
|
Chris@16
|
23 */
|
Chris@16
|
24 template <class T> inline
|
Chris@16
|
25 void ignore_unused_variable_warning(const T&) {}
|
Chris@16
|
26 } // namespace detail
|
Chris@16
|
27
|
Chris@16
|
28 // Borrowed from Dave Abraham's noncopyable.
|
Chris@16
|
29 // I believe this should be part of utility.hpp one day...
|
Chris@16
|
30 namespace nonassignable_ // protection from unintended ADL
|
Chris@16
|
31 {
|
Chris@16
|
32 class nonassignable {
|
Chris@16
|
33 protected:
|
Chris@16
|
34 nonassignable () {}
|
Chris@16
|
35 ~nonassignable () {}
|
Chris@16
|
36 private: // emphasize the following members are private
|
Chris@16
|
37 const nonassignable& operator= (const nonassignable &);
|
Chris@16
|
38 }; // nonassignable
|
Chris@16
|
39 }
|
Chris@16
|
40 typedef nonassignable_::nonassignable nonassignable;
|
Chris@16
|
41
|
Chris@16
|
42
|
Chris@16
|
43 // Assignment proxy.
|
Chris@16
|
44 // Provides temporary free assigment when LHS has no alias on RHS
|
Chris@16
|
45 template<class C>
|
Chris@16
|
46 class noalias_proxy:
|
Chris@16
|
47 private nonassignable {
|
Chris@16
|
48 public:
|
Chris@16
|
49 typedef typename C::closure_type closure_type;
|
Chris@16
|
50
|
Chris@16
|
51 BOOST_UBLAS_INLINE
|
Chris@16
|
52 noalias_proxy (C& lval):
|
Chris@16
|
53 nonassignable (), lval_ (lval) {}
|
Chris@16
|
54 BOOST_UBLAS_INLINE
|
Chris@16
|
55 noalias_proxy (const noalias_proxy& p):
|
Chris@16
|
56 nonassignable (), lval_ (p.lval_) {}
|
Chris@16
|
57
|
Chris@16
|
58 template <class E>
|
Chris@16
|
59 BOOST_UBLAS_INLINE
|
Chris@16
|
60 closure_type &operator= (const E& e) {
|
Chris@16
|
61 lval_.assign (e);
|
Chris@16
|
62 return lval_;
|
Chris@16
|
63 }
|
Chris@16
|
64
|
Chris@16
|
65 template <class E>
|
Chris@16
|
66 BOOST_UBLAS_INLINE
|
Chris@16
|
67 closure_type &operator+= (const E& e) {
|
Chris@16
|
68 lval_.plus_assign (e);
|
Chris@16
|
69 return lval_;
|
Chris@16
|
70 }
|
Chris@16
|
71
|
Chris@16
|
72 template <class E>
|
Chris@16
|
73 BOOST_UBLAS_INLINE
|
Chris@16
|
74 closure_type &operator-= (const E& e) {
|
Chris@16
|
75 lval_.minus_assign (e);
|
Chris@16
|
76 return lval_;
|
Chris@16
|
77 }
|
Chris@16
|
78
|
Chris@16
|
79 private:
|
Chris@16
|
80 closure_type lval_;
|
Chris@16
|
81 };
|
Chris@16
|
82
|
Chris@16
|
83 // Improve syntax of efficient assignment where no aliases of LHS appear on the RHS
|
Chris@16
|
84 // noalias(lhs) = rhs_expression
|
Chris@16
|
85 template <class C>
|
Chris@16
|
86 BOOST_UBLAS_INLINE
|
Chris@16
|
87 noalias_proxy<C> noalias (C& lvalue) {
|
Chris@16
|
88 return noalias_proxy<C> (lvalue);
|
Chris@16
|
89 }
|
Chris@16
|
90 template <class C>
|
Chris@16
|
91 BOOST_UBLAS_INLINE
|
Chris@16
|
92 noalias_proxy<const C> noalias (const C& lvalue) {
|
Chris@16
|
93 return noalias_proxy<const C> (lvalue);
|
Chris@16
|
94 }
|
Chris@16
|
95
|
Chris@16
|
96 // Possible future compatible syntax where lvalue possible has an unsafe alias on the RHS
|
Chris@16
|
97 // safe(lhs) = rhs_expression
|
Chris@16
|
98 template <class C>
|
Chris@16
|
99 BOOST_UBLAS_INLINE
|
Chris@16
|
100 C& safe (C& lvalue) {
|
Chris@16
|
101 return lvalue;
|
Chris@16
|
102 }
|
Chris@16
|
103 template <class C>
|
Chris@16
|
104 BOOST_UBLAS_INLINE
|
Chris@16
|
105 const C& safe (const C& lvalue) {
|
Chris@16
|
106 return lvalue;
|
Chris@16
|
107 }
|
Chris@16
|
108
|
Chris@16
|
109
|
Chris@16
|
110 // Dimension accessors
|
Chris@16
|
111 namespace dimension {
|
Chris@16
|
112
|
Chris@16
|
113 // Generic accessors
|
Chris@16
|
114 template<unsigned dimension>
|
Chris@16
|
115 struct dimension_properties {};
|
Chris@16
|
116
|
Chris@16
|
117 template<>
|
Chris@16
|
118 struct dimension_properties<1> {
|
Chris@16
|
119 template <class E>
|
Chris@16
|
120 BOOST_UBLAS_INLINE static
|
Chris@16
|
121 typename E::size_type size (const vector_expression<E> &e) {
|
Chris@16
|
122 return e ().size ();
|
Chris@16
|
123 }
|
Chris@16
|
124 template <class E>
|
Chris@16
|
125 BOOST_UBLAS_INLINE static
|
Chris@16
|
126 typename E::size_type size (const matrix_expression<E> &e) {
|
Chris@16
|
127 return e ().size1 ();
|
Chris@16
|
128 }
|
Chris@16
|
129 // Note: Index functions cannot deduce dependant template parameter V or M from i
|
Chris@16
|
130 template <class V>
|
Chris@16
|
131 BOOST_UBLAS_INLINE static
|
Chris@16
|
132 typename V::size_type index (const typename V::iterator &i) {
|
Chris@16
|
133 return i.index ();
|
Chris@16
|
134 }
|
Chris@16
|
135 template <class M>
|
Chris@16
|
136 BOOST_UBLAS_INLINE static
|
Chris@16
|
137 typename M::size_type index (const typename M::iterator1 &i) {
|
Chris@16
|
138 return i.index1 ();
|
Chris@16
|
139 }
|
Chris@16
|
140 template <class M>
|
Chris@16
|
141 BOOST_UBLAS_INLINE static
|
Chris@16
|
142 typename M::size_type index (const typename M::iterator2 &i) {
|
Chris@16
|
143 return i.index1 ();
|
Chris@16
|
144 }
|
Chris@16
|
145 };
|
Chris@16
|
146 template<>
|
Chris@16
|
147 struct dimension_properties<2> {
|
Chris@16
|
148 template <class E>
|
Chris@16
|
149 BOOST_UBLAS_INLINE static
|
Chris@16
|
150 typename E::size_type size (const vector_expression<E> &) {
|
Chris@16
|
151 return 1;
|
Chris@16
|
152 }
|
Chris@16
|
153 template <class E>
|
Chris@16
|
154 BOOST_UBLAS_INLINE static
|
Chris@16
|
155 typename E::size_type size (const matrix_expression<E> &e) {
|
Chris@16
|
156 return e ().size2 ();
|
Chris@16
|
157 }
|
Chris@16
|
158 template <class V>
|
Chris@16
|
159 BOOST_UBLAS_INLINE static
|
Chris@16
|
160 typename V::size_type index (const typename V::iterator &) {
|
Chris@16
|
161 return 1;
|
Chris@16
|
162 }
|
Chris@16
|
163 template <class M>
|
Chris@16
|
164 BOOST_UBLAS_INLINE static
|
Chris@16
|
165 typename M::size_type index (const typename M::iterator1 &i) {
|
Chris@16
|
166 return i.index2 ();
|
Chris@16
|
167 }
|
Chris@16
|
168 template <class M>
|
Chris@16
|
169 BOOST_UBLAS_INLINE static
|
Chris@16
|
170 typename M::size_type index (const typename M::iterator2 &i) {
|
Chris@16
|
171 return i.index2 ();
|
Chris@16
|
172 }
|
Chris@16
|
173 };
|
Chris@16
|
174
|
Chris@16
|
175 template<unsigned dimension, class E>
|
Chris@16
|
176 BOOST_UBLAS_INLINE
|
Chris@16
|
177 typename E::size_type size (const E& e) {
|
Chris@16
|
178 return dimension_properties<dimension>::size (e);
|
Chris@16
|
179 }
|
Chris@16
|
180
|
Chris@16
|
181 template<unsigned dimension, class I>
|
Chris@16
|
182 BOOST_UBLAS_INLINE
|
Chris@16
|
183 typename I::container_type::size_type
|
Chris@16
|
184 index (const I& i) {
|
Chris@16
|
185 typedef typename I::container_type container_type;
|
Chris@16
|
186 return dimension_properties<dimension>::template index<container_type> (i);
|
Chris@16
|
187 }
|
Chris@16
|
188
|
Chris@16
|
189
|
Chris@16
|
190 // Named accessors - just syntactic sugar
|
Chris@16
|
191 template<class V>
|
Chris@16
|
192 typename V::size_type num_elements (const V &v) {
|
Chris@16
|
193 return v.size ();
|
Chris@16
|
194 }
|
Chris@16
|
195 template<class M>
|
Chris@16
|
196 typename M::size_type num_rows (const M &m) {
|
Chris@16
|
197 return m.size1 ();
|
Chris@16
|
198 }
|
Chris@16
|
199 template<class M>
|
Chris@16
|
200 typename M::size_type num_columns (const M &m) {
|
Chris@16
|
201 return m.size2 ();
|
Chris@16
|
202 }
|
Chris@16
|
203 template<class MV>
|
Chris@16
|
204 typename MV::size_type num_non_zeros (const MV &mv) {
|
Chris@16
|
205 return mv.non_zeros ();
|
Chris@16
|
206 }
|
Chris@16
|
207 }
|
Chris@16
|
208
|
Chris@16
|
209
|
Chris@16
|
210 }}}
|
Chris@16
|
211
|
Chris@16
|
212 #endif
|