comparison armadillo-3.900.4/include/armadillo_bits/subview_field_meat.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) 2008-2012 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2012 Conrad Sanderson
3 //
4 // This Source Code Form is subject to the terms of the Mozilla Public
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8
9 //! \addtogroup subview_field
10 //! @{
11
12
13 template<typename oT>
14 inline
15 subview_field<oT>::~subview_field()
16 {
17 arma_extra_debug_sigprint();
18 }
19
20
21
22 template<typename oT>
23 arma_inline
24 subview_field<oT>::subview_field
25 (
26 const field<oT>& in_f,
27 const uword in_row1,
28 const uword in_col1,
29 const uword in_n_rows,
30 const uword in_n_cols
31 )
32 : f(in_f)
33 , aux_row1(in_row1)
34 , aux_col1(in_col1)
35 , n_rows(in_n_rows)
36 , n_cols(in_n_cols)
37 , n_elem(in_n_rows*in_n_cols)
38 {
39 arma_extra_debug_sigprint();
40 }
41
42
43
44 template<typename oT>
45 inline
46 void
47 subview_field<oT>::operator= (const field<oT>& x)
48 {
49 arma_extra_debug_sigprint();
50
51 subview_field<oT>& t = *this;
52
53 arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols), "incompatible field dimensions");
54
55 for(uword col=0; col<t.n_cols; ++col)
56 {
57 for(uword row=0; row<t.n_rows; ++row)
58 {
59 t.at(row,col) = x.at(row,col);
60 }
61 }
62 }
63
64
65
66 //! x.subfield(...) = y.subfield(...)
67 template<typename oT>
68 inline
69 void
70 subview_field<oT>::operator= (const subview_field<oT>& x_in)
71 {
72 arma_extra_debug_sigprint();
73
74 const bool overlap = check_overlap(x_in);
75
76 field<oT>* tmp_field = overlap ? new field<oT>(x_in.f) : 0;
77 const subview_field<oT>* tmp_subview = overlap ? new subview_field<oT>(*tmp_field, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
78 const subview_field<oT>& x = overlap ? (*tmp_subview) : x_in;
79
80 subview_field<oT>& t = *this;
81
82 arma_debug_check( (t.n_rows != x.n_rows) || (t.n_cols != x.n_cols), "incompatible field dimensions");
83
84 for(uword col=0; col<t.n_cols; ++col)
85 {
86 for(uword row=0; row<t.n_rows; ++row)
87 {
88 t.at(row,col) = x.at(row,col);
89 }
90 }
91
92 if(overlap)
93 {
94 delete tmp_subview;
95 delete tmp_field;
96 }
97 }
98
99
100
101 template<typename oT>
102 arma_inline
103 oT&
104 subview_field<oT>::operator[](const uword i)
105 {
106 const uword in_col = i / n_rows;
107 const uword in_row = i % n_rows;
108
109 const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
110
111 return *((const_cast< field<oT>& >(f)).mem[index]);
112 }
113
114
115
116 template<typename oT>
117 arma_inline
118 const oT&
119 subview_field<oT>::operator[](const uword i) const
120 {
121 const uword in_col = i / n_rows;
122 const uword in_row = i % n_rows;
123
124 const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
125
126 return *(f.mem[index]);
127 }
128
129
130
131 template<typename oT>
132 arma_inline
133 oT&
134 subview_field<oT>::operator()(const uword i)
135 {
136 arma_debug_check( (i >= n_elem), "subview_field::operator(): index out of bounds");
137
138 const uword in_col = i / n_rows;
139 const uword in_row = i % n_rows;
140
141 const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
142
143 return *((const_cast< field<oT>& >(f)).mem[index]);
144 }
145
146
147
148 template<typename oT>
149 arma_inline
150 const oT&
151 subview_field<oT>::operator()(const uword i) const
152 {
153 arma_debug_check( (i >= n_elem), "subview_field::operator(): index out of bounds");
154
155 const uword in_col = i / n_rows;
156 const uword in_row = i % n_rows;
157
158 const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
159
160 return *(f.mem[index]);
161 }
162
163
164
165 template<typename oT>
166 arma_inline
167 oT&
168 subview_field<oT>::operator()(const uword in_row, const uword in_col)
169 {
170 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview_field::operator(): index out of bounds");
171
172 const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
173
174 return *((const_cast< field<oT>& >(f)).mem[index]);
175 }
176
177
178
179 template<typename oT>
180 arma_inline
181 const oT&
182 subview_field<oT>::operator()(const uword in_row, const uword in_col) const
183 {
184 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview_field::operator(): index out of bounds");
185
186 const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
187
188 return *(f.mem[index]);
189 }
190
191
192
193 template<typename oT>
194 arma_inline
195 oT&
196 subview_field<oT>::at(const uword in_row, const uword in_col)
197 {
198 const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
199
200 return *((const_cast< field<oT>& >(f)).mem[index]);
201 }
202
203
204
205 template<typename oT>
206 arma_inline
207 const oT&
208 subview_field<oT>::at(const uword in_row, const uword in_col) const
209 {
210 //arma_extra_debug_sigprint();
211
212 const uword index = (in_col + aux_col1)*f.n_rows + aux_row1 + in_row;
213
214 return *(f.mem[index]);
215 }
216
217
218
219 template<typename oT>
220 inline
221 bool
222 subview_field<oT>::check_overlap(const subview_field<oT>& x) const
223 {
224 const subview_field<oT>& t = *this;
225
226 if(&t.f != &x.f)
227 {
228 return false;
229 }
230 else
231 {
232 if( (t.n_elem == 0) || (x.n_elem == 0) )
233 {
234 return false;
235 }
236 else
237 {
238 const uword t_row_start = t.aux_row1;
239 const uword t_row_end_p1 = t_row_start + t.n_rows;
240
241 const uword t_col_start = t.aux_col1;
242 const uword t_col_end_p1 = t_col_start + t.n_cols;
243
244
245 const uword x_row_start = x.aux_row1;
246 const uword x_row_end_p1 = x_row_start + x.n_rows;
247
248 const uword x_col_start = x.aux_col1;
249 const uword x_col_end_p1 = x_col_start + x.n_cols;
250
251
252 const bool outside_rows = ( (x_row_start >= t_row_end_p1) || (t_row_start >= x_row_end_p1) );
253 const bool outside_cols = ( (x_col_start >= t_col_end_p1) || (t_col_start >= x_col_end_p1) );
254
255 return ( (outside_rows == false) && (outside_cols == false) );
256 }
257 }
258 }
259
260
261
262 //! X = Y.subfield(...)
263 template<typename oT>
264 inline
265 void
266 subview_field<oT>::extract(field<oT>& actual_out, const subview_field<oT>& in)
267 {
268 arma_extra_debug_sigprint();
269
270 //
271 const bool alias = (&actual_out == &in.f);
272
273 field<oT>* tmp = (alias) ? new field<oT> : 0;
274 field<oT>& out = (alias) ? (*tmp) : actual_out;
275
276 //
277
278 const uword n_rows = in.n_rows;
279 const uword n_cols = in.n_cols;
280
281 out.set_size(n_rows, n_cols);
282
283 arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols = %d in.m.n_rows = %d in.m.n_cols = %d") % out.n_rows % out.n_cols % in.f.n_rows % in.f.n_cols );
284
285 for(uword col = 0; col<n_cols; ++col)
286 {
287 for(uword row = 0; row<n_rows; ++row)
288 {
289 out.at(row,col) = in.at(row,col);
290 }
291 }
292
293
294 if(alias)
295 {
296 actual_out = out;
297 delete tmp;
298 }
299
300 }
301
302
303
304 //! @}