Mercurial > hg > segmenter-vamp-plugin
comparison armadillo-3.900.4/include/armadillo_bits/SpSubview_bones.hpp @ 49:1ec0e2823891
Switch to using subrepo copies of qm-dsp, nnls-chroma, vamp-plugin-sdk; update Armadillo version; assume build without external BLAS/LAPACK
author | Chris Cannam |
---|---|
date | Thu, 13 Jun 2013 10:25:24 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
48:69251e11a913 | 49:1ec0e2823891 |
---|---|
1 // Copyright (C) 2011-2012 Ryan Curtin | |
2 // Copyright (C) 2011 Matthew Amidon | |
3 // Copyright (C) 2012 Conrad Sanderson | |
4 // | |
5 // This Source Code Form is subject to the terms of the Mozilla Public | |
6 // License, v. 2.0. If a copy of the MPL was not distributed with this | |
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
8 | |
9 //! \addtogroup SpSubview | |
10 //! @{ | |
11 | |
12 template<typename eT> | |
13 class SpSubview : public SpBase<eT, SpSubview<eT> > | |
14 { | |
15 public: | |
16 | |
17 const SpMat<eT>& m; | |
18 | |
19 typedef eT elem_type; | |
20 typedef typename get_pod_type<elem_type>::result pod_type; | |
21 | |
22 static const bool is_row = false; | |
23 static const bool is_col = false; | |
24 | |
25 const uword aux_row1; | |
26 const uword aux_col1; | |
27 const uword n_rows; | |
28 const uword n_cols; | |
29 const uword n_elem; | |
30 const uword n_nonzero; | |
31 | |
32 // So that SpValProxy can call add_element() and delete_element(). | |
33 friend class SpValProxy<SpSubview<eT> >; | |
34 | |
35 protected: | |
36 | |
37 arma_inline SpSubview(const SpMat<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); | |
38 arma_inline SpSubview( SpMat<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols); | |
39 | |
40 public: | |
41 | |
42 inline ~SpSubview(); | |
43 | |
44 inline const SpSubview& operator+= (const eT val); | |
45 inline const SpSubview& operator-= (const eT val); | |
46 inline const SpSubview& operator*= (const eT val); | |
47 inline const SpSubview& operator/= (const eT val); | |
48 | |
49 inline const SpSubview& operator=(const SpSubview& x); | |
50 | |
51 template<typename T1> inline const SpSubview& operator= (const Base<eT, T1>& x); | |
52 template<typename T1> inline const SpSubview& operator+=(const Base<eT, T1>& x); | |
53 template<typename T1> inline const SpSubview& operator-=(const Base<eT, T1>& x); | |
54 template<typename T1> inline const SpSubview& operator*=(const Base<eT, T1>& x); | |
55 template<typename T1> inline const SpSubview& operator%=(const Base<eT, T1>& x); | |
56 template<typename T1> inline const SpSubview& operator/=(const Base<eT, T1>& x); | |
57 | |
58 template<typename T1> inline const SpSubview& operator= (const SpBase<eT, T1>& x); | |
59 template<typename T1> inline const SpSubview& operator+=(const SpBase<eT, T1>& x); | |
60 template<typename T1> inline const SpSubview& operator-=(const SpBase<eT, T1>& x); | |
61 template<typename T1> inline const SpSubview& operator*=(const SpBase<eT, T1>& x); | |
62 template<typename T1> inline const SpSubview& operator%=(const SpBase<eT, T1>& x); | |
63 template<typename T1> inline const SpSubview& operator/=(const SpBase<eT, T1>& x); | |
64 | |
65 /* | |
66 inline static void extract(SpMat<eT>& out, const SpSubview& in); | |
67 | |
68 inline static void plus_inplace(Mat<eT>& out, const subview& in); | |
69 inline static void minus_inplace(Mat<eT>& out, const subview& in); | |
70 inline static void schur_inplace(Mat<eT>& out, const subview& in); | |
71 inline static void div_inplace(Mat<eT>& out, const subview& in); | |
72 */ | |
73 | |
74 inline void fill(const eT val); | |
75 inline void zeros(); | |
76 inline void ones(); | |
77 inline void eye(); | |
78 | |
79 arma_hot inline SpValProxy<SpSubview<eT> > operator[](const uword i); | |
80 arma_hot inline eT operator[](const uword i) const; | |
81 | |
82 arma_hot inline SpValProxy<SpSubview<eT> > operator()(const uword i); | |
83 arma_hot inline eT operator()(const uword i) const; | |
84 | |
85 arma_hot inline SpValProxy<SpSubview<eT> > operator()(const uword in_row, const uword in_col); | |
86 arma_hot inline eT operator()(const uword in_row, const uword in_col) const; | |
87 | |
88 arma_hot inline SpValProxy<SpSubview<eT> > at(const uword i); | |
89 arma_hot inline eT at(const uword i) const; | |
90 | |
91 arma_hot inline SpValProxy<SpSubview<eT> > at(const uword in_row, const uword in_col); | |
92 arma_hot inline eT at(const uword in_row, const uword in_col) const; | |
93 | |
94 inline bool check_overlap(const SpSubview& x) const; | |
95 | |
96 inline bool is_vec() const; | |
97 | |
98 inline SpSubview row(const uword row_num); | |
99 inline const SpSubview row(const uword row_num) const; | |
100 | |
101 inline SpSubview col(const uword col_num); | |
102 inline const SpSubview col(const uword col_num) const; | |
103 | |
104 inline SpSubview rows(const uword in_row1, const uword in_row2); | |
105 inline const SpSubview rows(const uword in_row1, const uword in_row2) const; | |
106 | |
107 inline SpSubview cols(const uword in_col1, const uword in_col2); | |
108 inline const SpSubview cols(const uword in_col1, const uword in_col2) const; | |
109 | |
110 inline SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); | |
111 inline const SpSubview submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; | |
112 | |
113 inline SpSubview submat(const span& row_span, const span& col_span); | |
114 inline const SpSubview submat(const span& row_span, const span& col_span) const; | |
115 | |
116 inline SpSubview operator()(const uword row_num, const span& col_span); | |
117 inline const SpSubview operator()(const uword row_num, const span& col_span) const; | |
118 | |
119 inline SpSubview operator()(const span& row_span, const uword col_num); | |
120 inline const SpSubview operator()(const span& row_span, const uword col_num) const; | |
121 | |
122 inline SpSubview operator()(const span& row_span, const span& col_span); | |
123 inline const SpSubview operator()(const span& row_span, const span& col_span) const; | |
124 | |
125 /* not yet | |
126 inline SpSubview_row<eT> row(const uword row_num); | |
127 inline const SpSubview_row<eT> row(const uword row_num) const; | |
128 | |
129 inline SpSubview_row<eT> operator()(const uword row_num, const span& col_span); | |
130 inline const SpSubview_row<eT> operator()(const uword row_num, const span& col_span) const; | |
131 | |
132 inline SpSubview_col<eT> col(const uword col_num); | |
133 inline const SpSubview_col<eT> col(const uword col_num) const; | |
134 | |
135 inline SpSubview_col<eT> operator()(const span& row_span, const uword col_num); | |
136 inline const SpSubview_col<eT> operator()(const span& row_span, const uword col_num) const; | |
137 | |
138 inline Col<eT> unsafe_col(const uword col_num); | |
139 inline const Col<eT> unsafe_col(const uword col_num) const; | |
140 | |
141 inline SpSubview<eT> rows(const uword in_row1, const uword in_row2); | |
142 inline const SpSubview<eT> rows(const uword in_row1, const uword in_row2) const; | |
143 | |
144 inline SpSubview<eT> cols(const uword in_col1, const uword in_col2); | |
145 inline const SpSubview<eT> cols(const uword in_col1, const uword in_col2) const; | |
146 | |
147 inline SpSubview<eT> submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2); | |
148 inline const SpSubview<eT> submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const; | |
149 | |
150 inline SpSubview<eT> submat (const span& row_span, const span& col_span); | |
151 inline const SpSubview<eT> submat (const span& row_span, const span& col_span) const; | |
152 | |
153 inline SpSubview<eT> operator()(const span& row_span, const span& col_span); | |
154 inline const SpSubview<eT> operator()(const span& row_span, const span& col_span) const; | |
155 | |
156 inline diagview<eT> diag(const s32 in_id = 0); | |
157 inline const diagview<eT> diag(const s32 in_id = 0) const; | |
158 */ | |
159 | |
160 inline void swap_rows(const uword in_row1, const uword in_row2); | |
161 inline void swap_cols(const uword in_col1, const uword in_col2); | |
162 | |
163 // Forward declarations. | |
164 class iterator_base; | |
165 class const_iterator; | |
166 class iterator; | |
167 class const_row_iterator; | |
168 class row_iterator; | |
169 | |
170 // Similar to SpMat iterators but automatically iterates past and ignores values not in the subview. | |
171 class iterator_base | |
172 { | |
173 public: | |
174 | |
175 inline iterator_base(const SpSubview& in_M); | |
176 inline iterator_base(const SpSubview& in_M, const uword col, const uword pos, const uword skip_pos); | |
177 | |
178 inline eT operator*() const; | |
179 | |
180 // Don't hold location internally; call "dummy" methods to get that information. | |
181 arma_inline uword row() const { return M.m.row_indices[internal_pos + skip_pos] - M.aux_row1; } | |
182 arma_inline uword col() const { return internal_col; } | |
183 arma_inline uword pos() const { return internal_pos; } | |
184 | |
185 arma_aligned const SpSubview& M; | |
186 arma_aligned uword internal_col; | |
187 arma_aligned uword internal_pos; | |
188 arma_aligned uword skip_pos; // not used in row_iterator or const_row_iterator | |
189 | |
190 // So that we satisfy the STL iterator types. | |
191 typedef std::bidirectional_iterator_tag iterator_category; | |
192 typedef eT value_type; | |
193 typedef uword difference_type; // not certain on this one | |
194 typedef const eT* pointer; | |
195 typedef const eT& reference; | |
196 }; | |
197 | |
198 class const_iterator : public iterator_base | |
199 { | |
200 public: | |
201 | |
202 inline const_iterator(const SpSubview& in_M, uword initial_pos = 0); | |
203 inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col); | |
204 inline const_iterator(const SpSubview& in_M, uword in_row, uword in_col, uword in_pos, uword skip_pos); | |
205 inline const_iterator(const const_iterator& other); | |
206 | |
207 inline const_iterator& operator++(); | |
208 inline const_iterator operator++(int); | |
209 | |
210 inline const_iterator& operator--(); | |
211 inline const_iterator operator--(int); | |
212 | |
213 inline bool operator!=(const const_iterator& rhs) const; | |
214 inline bool operator==(const const_iterator& rhs) const; | |
215 | |
216 inline bool operator!=(const typename SpMat<eT>::const_iterator& rhs) const; | |
217 inline bool operator==(const typename SpMat<eT>::const_iterator& rhs) const; | |
218 | |
219 inline bool operator!=(const const_row_iterator& rhs) const; | |
220 inline bool operator==(const const_row_iterator& rhs) const; | |
221 | |
222 inline bool operator!=(const typename SpMat<eT>::const_row_iterator& rhs) const; | |
223 inline bool operator==(const typename SpMat<eT>::const_row_iterator& rhs) const; | |
224 }; | |
225 | |
226 class iterator : public const_iterator | |
227 { | |
228 public: | |
229 | |
230 inline iterator(SpSubview& in_M, const uword initial_pos = 0) : const_iterator(in_M, initial_pos) { } | |
231 inline iterator(SpSubview& in_M, const uword in_row, const uword in_col) : const_iterator(in_M, in_row, in_col) { } | |
232 inline iterator(SpSubview& in_M, const uword in_row, const uword in_col, const uword in_pos, const uword in_skip_pos) : const_iterator(in_M, in_row, in_col, in_pos, in_skip_pos) { } | |
233 inline iterator(const iterator& other) : const_iterator(other) { } | |
234 | |
235 inline SpValProxy<SpSubview<eT> > operator*(); | |
236 | |
237 // overloads needed for return type correctness | |
238 inline iterator& operator++(); | |
239 inline iterator operator++(int); | |
240 | |
241 inline iterator& operator--(); | |
242 inline iterator operator--(int); | |
243 | |
244 // This has a different value_type than iterator_base. | |
245 typedef SpValProxy<SpSubview<eT> > value_type; | |
246 typedef const SpValProxy<SpSubview<eT> >* pointer; | |
247 typedef const SpValProxy<SpSubview<eT> >& reference; | |
248 }; | |
249 | |
250 class const_row_iterator : public iterator_base | |
251 { | |
252 public: | |
253 | |
254 inline const_row_iterator(const SpSubview& in_M, uword initial_pos = 0); | |
255 inline const_row_iterator(const SpSubview& in_M, uword in_row, uword in_col); | |
256 inline const_row_iterator(const const_row_iterator& other); | |
257 | |
258 inline const_row_iterator& operator++(); | |
259 inline const_row_iterator operator++(int); | |
260 | |
261 inline const_row_iterator& operator--(); | |
262 inline const_row_iterator operator--(int); | |
263 | |
264 uword internal_row; // Hold row internally because we use internal_pos differently. | |
265 uword actual_pos; // Actual position in subview's parent matrix. | |
266 | |
267 arma_inline eT operator*() const { return iterator_base::M.m.values[actual_pos]; } | |
268 | |
269 arma_inline uword row() const { return internal_row; } | |
270 | |
271 inline bool operator!=(const const_iterator& rhs) const; | |
272 inline bool operator==(const const_iterator& rhs) const; | |
273 | |
274 inline bool operator!=(const typename SpMat<eT>::const_iterator& rhs) const; | |
275 inline bool operator==(const typename SpMat<eT>::const_iterator& rhs) const; | |
276 | |
277 inline bool operator!=(const const_row_iterator& rhs) const; | |
278 inline bool operator==(const const_row_iterator& rhs) const; | |
279 | |
280 inline bool operator!=(const typename SpMat<eT>::const_row_iterator& rhs) const; | |
281 inline bool operator==(const typename SpMat<eT>::const_row_iterator& rhs) const; | |
282 }; | |
283 | |
284 class row_iterator : public const_row_iterator | |
285 { | |
286 public: | |
287 | |
288 inline row_iterator(SpSubview& in_M, uword initial_pos = 0) : const_row_iterator(in_M, initial_pos) { } | |
289 inline row_iterator(SpSubview& in_M, uword in_row, uword in_col) : const_row_iterator(in_M, in_row, in_col) { } | |
290 inline row_iterator(const row_iterator& other) : const_row_iterator(other) { } | |
291 | |
292 inline SpValProxy<SpSubview<eT> > operator*(); | |
293 | |
294 // overloads needed for return type correctness | |
295 inline row_iterator& operator++(); | |
296 inline row_iterator operator++(int); | |
297 | |
298 inline row_iterator& operator--(); | |
299 inline row_iterator operator--(int); | |
300 | |
301 // This has a different value_type than iterator_base. | |
302 typedef SpValProxy<SpSubview<eT> > value_type; | |
303 typedef const SpValProxy<SpSubview<eT> >* pointer; | |
304 typedef const SpValProxy<SpSubview<eT> >& reference; | |
305 }; | |
306 | |
307 inline iterator begin(); | |
308 inline const_iterator begin() const; | |
309 | |
310 inline iterator begin_col(const uword col_num); | |
311 inline const_iterator begin_col(const uword col_num) const; | |
312 | |
313 inline row_iterator begin_row(const uword row_num = 0); | |
314 inline const_row_iterator begin_row(const uword row_num = 0) const; | |
315 | |
316 inline iterator end(); | |
317 inline const_iterator end() const; | |
318 | |
319 inline row_iterator end_row(); | |
320 inline const_row_iterator end_row() const; | |
321 | |
322 inline row_iterator end_row(const uword row_num = 0); | |
323 inline const_row_iterator end_row(const uword row_num = 0) const; | |
324 | |
325 | |
326 private: | |
327 friend class SpMat<eT>; | |
328 SpSubview(); | |
329 | |
330 // For use by SpValProxy. We just update n_nonzero and pass the call on to the matrix. | |
331 inline arma_hot arma_warn_unused eT& add_element(const uword in_row, const uword in_col, const eT in_val = 0.0); | |
332 inline arma_hot void delete_element(const uword in_row, const uword in_col); | |
333 | |
334 }; | |
335 | |
336 /* | |
337 template<typename eT> | |
338 class SpSubview_col : public SpSubview<eT> | |
339 { | |
340 public: | |
341 | |
342 typedef eT elem_type; | |
343 typedef typename get_pod_type<elem_type>::result pod_type; | |
344 | |
345 inline void operator= (const SpSubview<eT>& x); | |
346 inline void operator= (const SpSubview_col& x); | |
347 | |
348 template<typename T1> | |
349 inline void operator= (const Base<eT,T1>& x); | |
350 | |
351 inline SpSubview_col<eT> rows(const uword in_row1, const uword in_row2); | |
352 inline const SpSubview_col<eT> rows(const uword in_row1, const uword in_row2) const; | |
353 | |
354 inline SpSubview_col<eT> subvec(const uword in_row1, const uword in_row2); | |
355 inline const SpSubview_col<eT> subvec(const uword in_row1, const uword in_row2) const; | |
356 | |
357 | |
358 protected: | |
359 | |
360 inline SpSubview_col(const Mat<eT>& in_m, const uword in_col); | |
361 inline SpSubview_col( Mat<eT>& in_m, const uword in_col); | |
362 | |
363 inline SpSubview_col(const Mat<eT>& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); | |
364 inline SpSubview_col( Mat<eT>& in_m, const uword in_col, const uword in_row1, const uword in_n_rows); | |
365 | |
366 | |
367 private: | |
368 | |
369 friend class Mat<eT>; | |
370 friend class Col<eT>; | |
371 friend class SpSubview<eT>; | |
372 | |
373 SpSubview_col(); | |
374 }; | |
375 | |
376 template<typename eT> | |
377 class SpSubview_row : public SpSubview<eT> | |
378 { | |
379 public: | |
380 | |
381 typedef eT elem_type; | |
382 typedef typename get_pod_type<elem_type>::result pod_type; | |
383 | |
384 inline void operator= (const SpSubview<eT>& x); | |
385 inline void operator= (const SpSubview_row& x); | |
386 | |
387 template<typename T1> | |
388 inline void operator= (const Base<eT,T1>& x); | |
389 | |
390 inline SpSubview_row<eT> cols(const uword in_col1, const uword in_col2); | |
391 inline const SpSubview_row<eT> cols(const uword in_col1, const uword in_col2) const; | |
392 | |
393 inline SpSubview_row<eT> subvec(const uword in_col1, const uword in_col2); | |
394 inline const SpSubview_row<eT> subvec(const uword in_col1, const uword in_col2) const; | |
395 | |
396 | |
397 protected: | |
398 | |
399 inline SpSubview_row(const Mat<eT>& in_m, const uword in_row); | |
400 inline SpSubview_row( Mat<eT>& in_m, const uword in_row); | |
401 | |
402 inline SpSubview_row(const Mat<eT>& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); | |
403 inline SpSubview_row( Mat<eT>& in_m, const uword in_row, const uword in_col1, const uword in_n_cols); | |
404 | |
405 | |
406 private: | |
407 | |
408 friend class Mat<eT>; | |
409 friend class Row<eT>; | |
410 friend class SpSubview<eT>; | |
411 | |
412 SpSubview_row(); | |
413 }; | |
414 */ | |
415 | |
416 //! @} |