max@0
|
1 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
|
max@0
|
2 // Copyright (C) 2008-2011 Conrad Sanderson
|
max@0
|
3 // Copyright (C) 2011 James Sanders
|
max@0
|
4 //
|
max@0
|
5 // This file is part of the Armadillo C++ library.
|
max@0
|
6 // It is provided without any warranty of fitness
|
max@0
|
7 // for any purpose. You can redistribute this file
|
max@0
|
8 // and/or modify it under the terms of the GNU
|
max@0
|
9 // Lesser General Public License (LGPL) as published
|
max@0
|
10 // by the Free Software Foundation, either version 3
|
max@0
|
11 // of the License or (at your option) any later version.
|
max@0
|
12 // (see http://www.opensource.org/licenses for more info)
|
max@0
|
13
|
max@0
|
14
|
max@0
|
15 //! \addtogroup subview
|
max@0
|
16 //! @{
|
max@0
|
17
|
max@0
|
18
|
max@0
|
19 template<typename eT>
|
max@0
|
20 inline
|
max@0
|
21 subview<eT>::~subview()
|
max@0
|
22 {
|
max@0
|
23 arma_extra_debug_sigprint();
|
max@0
|
24 }
|
max@0
|
25
|
max@0
|
26
|
max@0
|
27 template<typename eT>
|
max@0
|
28 inline
|
max@0
|
29 subview<eT>::subview(const Mat<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols)
|
max@0
|
30 : m(in_m)
|
max@0
|
31 , m_ptr(0)
|
max@0
|
32 , aux_row1(in_row1)
|
max@0
|
33 , aux_col1(in_col1)
|
max@0
|
34 , n_rows(in_n_rows)
|
max@0
|
35 , n_cols(in_n_cols)
|
max@0
|
36 , n_elem(in_n_rows*in_n_cols)
|
max@0
|
37 {
|
max@0
|
38 arma_extra_debug_sigprint();
|
max@0
|
39 }
|
max@0
|
40
|
max@0
|
41
|
max@0
|
42
|
max@0
|
43 template<typename eT>
|
max@0
|
44 inline
|
max@0
|
45 subview<eT>::subview(Mat<eT>& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols)
|
max@0
|
46 : m(in_m)
|
max@0
|
47 , m_ptr(&in_m)
|
max@0
|
48 , aux_row1(in_row1)
|
max@0
|
49 , aux_col1(in_col1)
|
max@0
|
50 , n_rows(in_n_rows)
|
max@0
|
51 , n_cols(in_n_cols)
|
max@0
|
52 , n_elem(in_n_rows*in_n_cols)
|
max@0
|
53 {
|
max@0
|
54 arma_extra_debug_sigprint();
|
max@0
|
55 }
|
max@0
|
56
|
max@0
|
57
|
max@0
|
58
|
max@0
|
59 template<typename eT>
|
max@0
|
60 inline
|
max@0
|
61 void
|
max@0
|
62 subview<eT>::operator+= (const eT val)
|
max@0
|
63 {
|
max@0
|
64 arma_extra_debug_sigprint();
|
max@0
|
65
|
max@0
|
66 const uword local_n_cols = n_cols;
|
max@0
|
67 const uword local_n_rows = n_rows;
|
max@0
|
68
|
max@0
|
69 if(local_n_rows == 1)
|
max@0
|
70 {
|
max@0
|
71 Mat<eT>& X = (*m_ptr);
|
max@0
|
72
|
max@0
|
73 const uword row = aux_row1;
|
max@0
|
74 const uword start_col = aux_col1;
|
max@0
|
75 const uword end_col_plus1 = start_col + local_n_cols;
|
max@0
|
76
|
max@0
|
77 uword i,j;
|
max@0
|
78
|
max@0
|
79 for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2)
|
max@0
|
80 {
|
max@0
|
81 X.at(row, i) += val;
|
max@0
|
82 X.at(row, j) += val;
|
max@0
|
83 }
|
max@0
|
84
|
max@0
|
85 if(i < end_col_plus1)
|
max@0
|
86 {
|
max@0
|
87 X.at(row, i) += val;
|
max@0
|
88 }
|
max@0
|
89 }
|
max@0
|
90 else
|
max@0
|
91 {
|
max@0
|
92 for(uword col=0; col<local_n_cols; ++col)
|
max@0
|
93 {
|
max@0
|
94 arrayops::inplace_plus( colptr(col), val, local_n_rows );
|
max@0
|
95 }
|
max@0
|
96 }
|
max@0
|
97 }
|
max@0
|
98
|
max@0
|
99
|
max@0
|
100
|
max@0
|
101 template<typename eT>
|
max@0
|
102 inline
|
max@0
|
103 void
|
max@0
|
104 subview<eT>::operator-= (const eT val)
|
max@0
|
105 {
|
max@0
|
106 arma_extra_debug_sigprint();
|
max@0
|
107
|
max@0
|
108 const uword local_n_cols = n_cols;
|
max@0
|
109 const uword local_n_rows = n_rows;
|
max@0
|
110
|
max@0
|
111 if(local_n_rows == 1)
|
max@0
|
112 {
|
max@0
|
113 Mat<eT>& X = (*m_ptr);
|
max@0
|
114
|
max@0
|
115 const uword row = aux_row1;
|
max@0
|
116 const uword start_col = aux_col1;
|
max@0
|
117 const uword end_col_plus1 = start_col + local_n_cols;
|
max@0
|
118
|
max@0
|
119 uword i,j;
|
max@0
|
120
|
max@0
|
121 for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2)
|
max@0
|
122 {
|
max@0
|
123 X.at(row, i) -= val;
|
max@0
|
124 X.at(row, j) -= val;
|
max@0
|
125 }
|
max@0
|
126
|
max@0
|
127 if(i < end_col_plus1)
|
max@0
|
128 {
|
max@0
|
129 X.at(row, i) -= val;
|
max@0
|
130 }
|
max@0
|
131 }
|
max@0
|
132 else
|
max@0
|
133 {
|
max@0
|
134 for(uword col=0; col<local_n_cols; ++col)
|
max@0
|
135 {
|
max@0
|
136 arrayops::inplace_minus( colptr(col), val, local_n_rows );
|
max@0
|
137 }
|
max@0
|
138 }
|
max@0
|
139 }
|
max@0
|
140
|
max@0
|
141
|
max@0
|
142
|
max@0
|
143 template<typename eT>
|
max@0
|
144 inline
|
max@0
|
145 void
|
max@0
|
146 subview<eT>::operator*= (const eT val)
|
max@0
|
147 {
|
max@0
|
148 arma_extra_debug_sigprint();
|
max@0
|
149
|
max@0
|
150 const uword local_n_cols = n_cols;
|
max@0
|
151 const uword local_n_rows = n_rows;
|
max@0
|
152
|
max@0
|
153 if(local_n_rows == 1)
|
max@0
|
154 {
|
max@0
|
155 Mat<eT>& X = (*m_ptr);
|
max@0
|
156
|
max@0
|
157 const uword row = aux_row1;
|
max@0
|
158 const uword start_col = aux_col1;
|
max@0
|
159 const uword end_col_plus1 = start_col + local_n_cols;
|
max@0
|
160
|
max@0
|
161 uword i,j;
|
max@0
|
162
|
max@0
|
163 for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2)
|
max@0
|
164 {
|
max@0
|
165 X.at(row, i) *= val;
|
max@0
|
166 X.at(row, j) *= val;
|
max@0
|
167 }
|
max@0
|
168
|
max@0
|
169 if(i < end_col_plus1)
|
max@0
|
170 {
|
max@0
|
171 X.at(row, i) *= val;
|
max@0
|
172 }
|
max@0
|
173 }
|
max@0
|
174 else
|
max@0
|
175 {
|
max@0
|
176 for(uword col=0; col<local_n_cols; ++col)
|
max@0
|
177 {
|
max@0
|
178 arrayops::inplace_mul( colptr(col), val, local_n_rows );
|
max@0
|
179 }
|
max@0
|
180 }
|
max@0
|
181 }
|
max@0
|
182
|
max@0
|
183
|
max@0
|
184
|
max@0
|
185 template<typename eT>
|
max@0
|
186 inline
|
max@0
|
187 void
|
max@0
|
188 subview<eT>::operator/= (const eT val)
|
max@0
|
189 {
|
max@0
|
190 arma_extra_debug_sigprint();
|
max@0
|
191
|
max@0
|
192 const uword local_n_cols = n_cols;
|
max@0
|
193 const uword local_n_rows = n_rows;
|
max@0
|
194
|
max@0
|
195 if(local_n_rows == 1)
|
max@0
|
196 {
|
max@0
|
197 Mat<eT>& X = (*m_ptr);
|
max@0
|
198
|
max@0
|
199 const uword row = aux_row1;
|
max@0
|
200 const uword start_col = aux_col1;
|
max@0
|
201 const uword end_col_plus1 = start_col + local_n_cols;
|
max@0
|
202
|
max@0
|
203 uword i,j;
|
max@0
|
204
|
max@0
|
205 for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2)
|
max@0
|
206 {
|
max@0
|
207 X.at(row, i) /= val;
|
max@0
|
208 X.at(row, j) /= val;
|
max@0
|
209 }
|
max@0
|
210
|
max@0
|
211 if(i < end_col_plus1)
|
max@0
|
212 {
|
max@0
|
213 X.at(row, i) /= val;
|
max@0
|
214 }
|
max@0
|
215 }
|
max@0
|
216 else
|
max@0
|
217 {
|
max@0
|
218 for(uword col=0; col<local_n_cols; ++col)
|
max@0
|
219 {
|
max@0
|
220 arrayops::inplace_div( colptr(col), val, local_n_rows );
|
max@0
|
221 }
|
max@0
|
222 }
|
max@0
|
223 }
|
max@0
|
224
|
max@0
|
225
|
max@0
|
226
|
max@0
|
227 template<typename eT>
|
max@0
|
228 template<typename T1>
|
max@0
|
229 inline
|
max@0
|
230 void
|
max@0
|
231 subview<eT>::operator= (const Base<eT,T1>& in)
|
max@0
|
232 {
|
max@0
|
233 arma_extra_debug_sigprint();
|
max@0
|
234
|
max@0
|
235 const Proxy<T1> P(in.get_ref());
|
max@0
|
236
|
max@0
|
237 subview<eT>& t = *this;
|
max@0
|
238
|
max@0
|
239 const uword t_n_rows = t.n_rows;
|
max@0
|
240 const uword t_n_cols = t.n_cols;
|
max@0
|
241
|
max@0
|
242 arma_debug_assert_same_size(t, P, "insert into submatrix");
|
max@0
|
243
|
max@0
|
244 const bool alias = P.is_alias(t.m);
|
max@0
|
245
|
max@0
|
246 arma_extra_debug_warn(alias, "aliasing detected");
|
max@0
|
247
|
max@0
|
248 if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value == true) )
|
max@0
|
249 {
|
max@0
|
250 const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m);
|
max@0
|
251 const Mat<eT>& x = tmp.M;
|
max@0
|
252
|
max@0
|
253 if(t_n_rows == 1)
|
max@0
|
254 {
|
max@0
|
255 const eT* x_mem = x.memptr();
|
max@0
|
256
|
max@0
|
257 Mat<eT>& A = (*m_ptr);
|
max@0
|
258
|
max@0
|
259 const uword row = aux_row1;
|
max@0
|
260 const uword start_col = aux_col1;
|
max@0
|
261
|
max@0
|
262 uword i,j;
|
max@0
|
263
|
max@0
|
264 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
265 {
|
max@0
|
266 A.at(row, start_col+i) = x_mem[i];
|
max@0
|
267 A.at(row, start_col+j) = x_mem[j];
|
max@0
|
268 }
|
max@0
|
269
|
max@0
|
270 if(i < t_n_cols)
|
max@0
|
271 {
|
max@0
|
272 A.at(row, start_col+i) = x_mem[i];
|
max@0
|
273 }
|
max@0
|
274 }
|
max@0
|
275 else
|
max@0
|
276 {
|
max@0
|
277 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
278 {
|
max@0
|
279 arrayops::copy( t.colptr(col), x.colptr(col), t_n_rows );
|
max@0
|
280 }
|
max@0
|
281 }
|
max@0
|
282 }
|
max@0
|
283 else
|
max@0
|
284 {
|
max@0
|
285 if(t_n_rows == 1)
|
max@0
|
286 {
|
max@0
|
287 Mat<eT>& A = (*m_ptr);
|
max@0
|
288
|
max@0
|
289 const uword row = aux_row1;
|
max@0
|
290 const uword start_col = aux_col1;
|
max@0
|
291
|
max@0
|
292 uword i,j;
|
max@0
|
293
|
max@0
|
294 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
295 {
|
max@0
|
296 const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
|
max@0
|
297 const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j];
|
max@0
|
298
|
max@0
|
299 A.at(row, start_col+i) = tmp1;
|
max@0
|
300 A.at(row, start_col+j) = tmp2;
|
max@0
|
301 }
|
max@0
|
302
|
max@0
|
303 if(i < t_n_cols)
|
max@0
|
304 {
|
max@0
|
305 A.at(row, start_col+i) = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
|
max@0
|
306 }
|
max@0
|
307 }
|
max@0
|
308 else
|
max@0
|
309 {
|
max@0
|
310 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
311 {
|
max@0
|
312 eT* t_col_data = t.colptr(col);
|
max@0
|
313
|
max@0
|
314 uword i,j;
|
max@0
|
315 for(i=0, j=1; j<t_n_rows; i+=2, j+=2)
|
max@0
|
316 {
|
max@0
|
317 const eT tmp1 = P.at(i,col);
|
max@0
|
318 const eT tmp2 = P.at(j,col);
|
max@0
|
319
|
max@0
|
320 t_col_data[i] = tmp1;
|
max@0
|
321 t_col_data[j] = tmp2;
|
max@0
|
322 }
|
max@0
|
323
|
max@0
|
324 if(i < t_n_rows)
|
max@0
|
325 {
|
max@0
|
326 t_col_data[i] = P.at(i,col);
|
max@0
|
327 }
|
max@0
|
328 }
|
max@0
|
329 }
|
max@0
|
330 }
|
max@0
|
331 }
|
max@0
|
332
|
max@0
|
333
|
max@0
|
334
|
max@0
|
335 template<typename eT>
|
max@0
|
336 template<typename T1>
|
max@0
|
337 inline
|
max@0
|
338 void
|
max@0
|
339 subview<eT>::operator+= (const Base<eT,T1>& in)
|
max@0
|
340 {
|
max@0
|
341 arma_extra_debug_sigprint();
|
max@0
|
342
|
max@0
|
343 const Proxy<T1> P(in.get_ref());
|
max@0
|
344
|
max@0
|
345 subview<eT>& t = *this;
|
max@0
|
346
|
max@0
|
347 const uword t_n_rows = t.n_rows;
|
max@0
|
348 const uword t_n_cols = t.n_cols;
|
max@0
|
349
|
max@0
|
350 arma_debug_assert_same_size(t, P, "addition");
|
max@0
|
351
|
max@0
|
352 const bool alias = P.is_alias(t.m);
|
max@0
|
353
|
max@0
|
354 arma_extra_debug_warn(alias, "aliasing detected");
|
max@0
|
355
|
max@0
|
356 if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value == true) )
|
max@0
|
357 {
|
max@0
|
358 const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m);
|
max@0
|
359 const Mat<eT>& x = tmp.M;
|
max@0
|
360
|
max@0
|
361 if(t_n_rows == 1)
|
max@0
|
362 {
|
max@0
|
363 const eT* x_mem = x.memptr();
|
max@0
|
364
|
max@0
|
365 Mat<eT>& A = (*m_ptr);
|
max@0
|
366
|
max@0
|
367 const uword row = aux_row1;
|
max@0
|
368 const uword start_col = aux_col1;
|
max@0
|
369
|
max@0
|
370 uword i,j;
|
max@0
|
371
|
max@0
|
372 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
373 {
|
max@0
|
374 A.at(row, start_col+i) += x_mem[i];
|
max@0
|
375 A.at(row, start_col+j) += x_mem[j];
|
max@0
|
376 }
|
max@0
|
377
|
max@0
|
378 if(i < t_n_cols)
|
max@0
|
379 {
|
max@0
|
380 A.at(row, start_col+i) += x_mem[i];
|
max@0
|
381 }
|
max@0
|
382 }
|
max@0
|
383 else
|
max@0
|
384 {
|
max@0
|
385 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
386 {
|
max@0
|
387 arrayops::inplace_plus( t.colptr(col), x.colptr(col), t_n_rows );
|
max@0
|
388 }
|
max@0
|
389 }
|
max@0
|
390 }
|
max@0
|
391 else
|
max@0
|
392 {
|
max@0
|
393 if(t_n_rows == 1)
|
max@0
|
394 {
|
max@0
|
395 Mat<eT>& A = (*m_ptr);
|
max@0
|
396
|
max@0
|
397 const uword row = aux_row1;
|
max@0
|
398 const uword start_col = aux_col1;
|
max@0
|
399
|
max@0
|
400 uword i,j;
|
max@0
|
401
|
max@0
|
402 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
403 {
|
max@0
|
404 const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
|
max@0
|
405 const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j];
|
max@0
|
406
|
max@0
|
407 A.at(row, start_col+i) += tmp1;
|
max@0
|
408 A.at(row, start_col+j) += tmp2;
|
max@0
|
409 }
|
max@0
|
410
|
max@0
|
411 if(i < t_n_cols)
|
max@0
|
412 {
|
max@0
|
413 A.at(row, start_col+i) += (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
|
max@0
|
414 }
|
max@0
|
415 }
|
max@0
|
416 else
|
max@0
|
417 {
|
max@0
|
418 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
419 {
|
max@0
|
420 eT* t_col_data = t.colptr(col);
|
max@0
|
421
|
max@0
|
422 uword i,j;
|
max@0
|
423 for(i=0, j=1; j<t_n_rows; i+=2, j+=2)
|
max@0
|
424 {
|
max@0
|
425 const eT val1 = P.at(i,col);
|
max@0
|
426 const eT val2 = P.at(j,col);
|
max@0
|
427
|
max@0
|
428 t_col_data[i] += val1;
|
max@0
|
429 t_col_data[j] += val2;
|
max@0
|
430 }
|
max@0
|
431
|
max@0
|
432 if(i < t_n_rows)
|
max@0
|
433 {
|
max@0
|
434 t_col_data[i] += P.at(i,col);
|
max@0
|
435 }
|
max@0
|
436 }
|
max@0
|
437 }
|
max@0
|
438 }
|
max@0
|
439 }
|
max@0
|
440
|
max@0
|
441
|
max@0
|
442
|
max@0
|
443 template<typename eT>
|
max@0
|
444 template<typename T1>
|
max@0
|
445 inline
|
max@0
|
446 void
|
max@0
|
447 subview<eT>::operator-= (const Base<eT,T1>& in)
|
max@0
|
448 {
|
max@0
|
449 arma_extra_debug_sigprint();
|
max@0
|
450
|
max@0
|
451 const Proxy<T1> P(in.get_ref());
|
max@0
|
452
|
max@0
|
453 subview<eT>& t = *this;
|
max@0
|
454
|
max@0
|
455 const uword t_n_rows = t.n_rows;
|
max@0
|
456 const uword t_n_cols = t.n_cols;
|
max@0
|
457
|
max@0
|
458 arma_debug_assert_same_size(t, P, "subtraction");
|
max@0
|
459
|
max@0
|
460 const bool alias = P.is_alias(t.m);
|
max@0
|
461
|
max@0
|
462 if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value == true) )
|
max@0
|
463 {
|
max@0
|
464 const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m);
|
max@0
|
465 const Mat<eT>& x = tmp.M;
|
max@0
|
466
|
max@0
|
467 if(t_n_rows == 1)
|
max@0
|
468 {
|
max@0
|
469 const eT* x_mem = x.memptr();
|
max@0
|
470
|
max@0
|
471 Mat<eT>& A = (*m_ptr);
|
max@0
|
472
|
max@0
|
473 const uword row = aux_row1;
|
max@0
|
474 const uword start_col = aux_col1;
|
max@0
|
475
|
max@0
|
476 uword i,j;
|
max@0
|
477
|
max@0
|
478 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
479 {
|
max@0
|
480 A.at(row, start_col+i) -= x_mem[i];
|
max@0
|
481 A.at(row, start_col+j) -= x_mem[j];
|
max@0
|
482 }
|
max@0
|
483
|
max@0
|
484 if(i < t_n_cols)
|
max@0
|
485 {
|
max@0
|
486 A.at(row, start_col+i) -= x_mem[i];
|
max@0
|
487 }
|
max@0
|
488 }
|
max@0
|
489 else
|
max@0
|
490 {
|
max@0
|
491 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
492 {
|
max@0
|
493 arrayops::inplace_minus( t.colptr(col), x.colptr(col), t_n_rows );
|
max@0
|
494 }
|
max@0
|
495 }
|
max@0
|
496 }
|
max@0
|
497 else
|
max@0
|
498 {
|
max@0
|
499 if(t_n_rows == 1)
|
max@0
|
500 {
|
max@0
|
501 Mat<eT>& A = (*m_ptr);
|
max@0
|
502
|
max@0
|
503 const uword row = aux_row1;
|
max@0
|
504 const uword start_col = aux_col1;
|
max@0
|
505
|
max@0
|
506 uword i,j;
|
max@0
|
507
|
max@0
|
508 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
509 {
|
max@0
|
510 const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
|
max@0
|
511 const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j];
|
max@0
|
512
|
max@0
|
513 A.at(row, start_col+i) -= tmp1;
|
max@0
|
514 A.at(row, start_col+j) -= tmp2;
|
max@0
|
515 }
|
max@0
|
516
|
max@0
|
517 if(i < t_n_cols)
|
max@0
|
518 {
|
max@0
|
519 A.at(row, start_col+i) -= (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
|
max@0
|
520 }
|
max@0
|
521 }
|
max@0
|
522 else
|
max@0
|
523 {
|
max@0
|
524 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
525 {
|
max@0
|
526 eT* t_col_data = t.colptr(col);
|
max@0
|
527
|
max@0
|
528 uword i,j;
|
max@0
|
529 for(i=0, j=1; j<t_n_rows; i+=2, j+=2)
|
max@0
|
530 {
|
max@0
|
531 const eT val1 = P.at(i,col);
|
max@0
|
532 const eT val2 = P.at(j,col);
|
max@0
|
533
|
max@0
|
534 t_col_data[i] -= val1;
|
max@0
|
535 t_col_data[j] -= val2;
|
max@0
|
536 }
|
max@0
|
537
|
max@0
|
538 if(i < t_n_rows)
|
max@0
|
539 {
|
max@0
|
540 t_col_data[i] -= P.at(i,col);
|
max@0
|
541 }
|
max@0
|
542 }
|
max@0
|
543 }
|
max@0
|
544 }
|
max@0
|
545 }
|
max@0
|
546
|
max@0
|
547
|
max@0
|
548
|
max@0
|
549 template<typename eT>
|
max@0
|
550 template<typename T1>
|
max@0
|
551 inline
|
max@0
|
552 void
|
max@0
|
553 subview<eT>::operator%= (const Base<eT,T1>& in)
|
max@0
|
554 {
|
max@0
|
555 arma_extra_debug_sigprint();
|
max@0
|
556
|
max@0
|
557 const Proxy<T1> P(in.get_ref());
|
max@0
|
558
|
max@0
|
559 subview<eT>& t = *this;
|
max@0
|
560
|
max@0
|
561 const uword t_n_rows = t.n_rows;
|
max@0
|
562 const uword t_n_cols = t.n_cols;
|
max@0
|
563
|
max@0
|
564 arma_debug_assert_same_size(t, P, "element-wise multiplication");
|
max@0
|
565
|
max@0
|
566 const bool alias = P.is_alias(t.m);
|
max@0
|
567
|
max@0
|
568 arma_extra_debug_warn(alias, "aliasing detected");
|
max@0
|
569
|
max@0
|
570 if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value == true) )
|
max@0
|
571 {
|
max@0
|
572 const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m);
|
max@0
|
573 const Mat<eT>& x = tmp.M;
|
max@0
|
574
|
max@0
|
575 if(t_n_rows == 1)
|
max@0
|
576 {
|
max@0
|
577 const eT* x_mem = x.memptr();
|
max@0
|
578
|
max@0
|
579 Mat<eT>& A = (*m_ptr);
|
max@0
|
580
|
max@0
|
581 const uword row = aux_row1;
|
max@0
|
582 const uword start_col = aux_col1;
|
max@0
|
583
|
max@0
|
584 uword i,j;
|
max@0
|
585
|
max@0
|
586 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
587 {
|
max@0
|
588 A.at(row, start_col+i) *= x_mem[i];
|
max@0
|
589 A.at(row, start_col+j) *= x_mem[j];
|
max@0
|
590 }
|
max@0
|
591
|
max@0
|
592 if(i < t_n_cols)
|
max@0
|
593 {
|
max@0
|
594 A.at(row, start_col+i) *= x_mem[i];
|
max@0
|
595 }
|
max@0
|
596 }
|
max@0
|
597 else
|
max@0
|
598 {
|
max@0
|
599 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
600 {
|
max@0
|
601 arrayops::inplace_mul( t.colptr(col), x.colptr(col), t_n_rows );
|
max@0
|
602 }
|
max@0
|
603 }
|
max@0
|
604 }
|
max@0
|
605 else
|
max@0
|
606 {
|
max@0
|
607 if(t_n_rows == 1)
|
max@0
|
608 {
|
max@0
|
609 Mat<eT>& A = (*m_ptr);
|
max@0
|
610
|
max@0
|
611 const uword row = aux_row1;
|
max@0
|
612 const uword start_col = aux_col1;
|
max@0
|
613
|
max@0
|
614 uword i,j;
|
max@0
|
615
|
max@0
|
616 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
617 {
|
max@0
|
618 const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
|
max@0
|
619 const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j];
|
max@0
|
620
|
max@0
|
621 A.at(row, start_col+i) *= tmp1;
|
max@0
|
622 A.at(row, start_col+j) *= tmp2;
|
max@0
|
623 }
|
max@0
|
624
|
max@0
|
625 if(i < t_n_cols)
|
max@0
|
626 {
|
max@0
|
627 A.at(row, start_col+i) *= (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
|
max@0
|
628 }
|
max@0
|
629 }
|
max@0
|
630 else
|
max@0
|
631 {
|
max@0
|
632 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
633 {
|
max@0
|
634 eT* t_col_data = t.colptr(col);
|
max@0
|
635
|
max@0
|
636 uword i,j;
|
max@0
|
637 for(i=0, j=1; j<t_n_rows; i+=2, j+=2)
|
max@0
|
638 {
|
max@0
|
639 const eT val1 = P.at(i,col);
|
max@0
|
640 const eT val2 = P.at(j,col);
|
max@0
|
641
|
max@0
|
642 t_col_data[i] *= val1;
|
max@0
|
643 t_col_data[j] *= val2;
|
max@0
|
644 }
|
max@0
|
645
|
max@0
|
646 if(i < t_n_rows)
|
max@0
|
647 {
|
max@0
|
648 t_col_data[i] *= P.at(i,col);
|
max@0
|
649 }
|
max@0
|
650 }
|
max@0
|
651 }
|
max@0
|
652 }
|
max@0
|
653 }
|
max@0
|
654
|
max@0
|
655
|
max@0
|
656
|
max@0
|
657 template<typename eT>
|
max@0
|
658 template<typename T1>
|
max@0
|
659 inline
|
max@0
|
660 void
|
max@0
|
661 subview<eT>::operator/= (const Base<eT,T1>& in)
|
max@0
|
662 {
|
max@0
|
663 arma_extra_debug_sigprint();
|
max@0
|
664
|
max@0
|
665 const Proxy<T1> P(in.get_ref());
|
max@0
|
666
|
max@0
|
667 subview<eT>& t = *this;
|
max@0
|
668
|
max@0
|
669 const uword t_n_rows = t.n_rows;
|
max@0
|
670 const uword t_n_cols = t.n_cols;
|
max@0
|
671
|
max@0
|
672 arma_debug_assert_same_size(t, P, "element-wise division");
|
max@0
|
673
|
max@0
|
674 const bool alias = P.is_alias(t.m);
|
max@0
|
675
|
max@0
|
676 arma_extra_debug_warn(alias, "aliasing detected");
|
max@0
|
677
|
max@0
|
678 if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value == true) )
|
max@0
|
679 {
|
max@0
|
680 const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m);
|
max@0
|
681 const Mat<eT>& x = tmp.M;
|
max@0
|
682
|
max@0
|
683 if(t_n_rows == 1)
|
max@0
|
684 {
|
max@0
|
685 const eT* x_mem = x.memptr();
|
max@0
|
686
|
max@0
|
687 Mat<eT>& A = (*m_ptr);
|
max@0
|
688
|
max@0
|
689 const uword row = aux_row1;
|
max@0
|
690 const uword start_col = aux_col1;
|
max@0
|
691
|
max@0
|
692 uword i,j;
|
max@0
|
693
|
max@0
|
694 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
695 {
|
max@0
|
696 A.at(row, start_col+i) /= x_mem[i];
|
max@0
|
697 A.at(row, start_col+j) /= x_mem[j];
|
max@0
|
698 }
|
max@0
|
699
|
max@0
|
700 if(i < t_n_cols)
|
max@0
|
701 {
|
max@0
|
702 A.at(row, start_col+i) /= x_mem[i];
|
max@0
|
703 }
|
max@0
|
704 }
|
max@0
|
705 else
|
max@0
|
706 {
|
max@0
|
707 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
708 {
|
max@0
|
709 arrayops::inplace_div( t.colptr(col), x.colptr(col), t_n_rows );
|
max@0
|
710 }
|
max@0
|
711 }
|
max@0
|
712 }
|
max@0
|
713 else
|
max@0
|
714 {
|
max@0
|
715 if(t_n_rows == 1)
|
max@0
|
716 {
|
max@0
|
717 Mat<eT>& A = (*m_ptr);
|
max@0
|
718
|
max@0
|
719 const uword row = aux_row1;
|
max@0
|
720 const uword start_col = aux_col1;
|
max@0
|
721
|
max@0
|
722 uword i,j;
|
max@0
|
723
|
max@0
|
724 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
725 {
|
max@0
|
726 const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
|
max@0
|
727 const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j];
|
max@0
|
728
|
max@0
|
729 A.at(row, start_col+i) /= tmp1;
|
max@0
|
730 A.at(row, start_col+j) /= tmp2;
|
max@0
|
731 }
|
max@0
|
732
|
max@0
|
733 if(i < t_n_cols)
|
max@0
|
734 {
|
max@0
|
735 A.at(row, start_col+i) /= (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i];
|
max@0
|
736 }
|
max@0
|
737 }
|
max@0
|
738 else
|
max@0
|
739 {
|
max@0
|
740 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
741 {
|
max@0
|
742 eT* t_col_data = t.colptr(col);
|
max@0
|
743
|
max@0
|
744 uword i,j;
|
max@0
|
745 for(i=0, j=1; j<t_n_rows; i+=2, j+=2)
|
max@0
|
746 {
|
max@0
|
747 const eT val1 = P.at(i,col);
|
max@0
|
748 const eT val2 = P.at(j,col);
|
max@0
|
749
|
max@0
|
750 t_col_data[i] /= val1;
|
max@0
|
751 t_col_data[j] /= val2;
|
max@0
|
752 }
|
max@0
|
753
|
max@0
|
754 if(i < t_n_rows)
|
max@0
|
755 {
|
max@0
|
756 t_col_data[i] /= P.at(i,col);
|
max@0
|
757 }
|
max@0
|
758 }
|
max@0
|
759 }
|
max@0
|
760 }
|
max@0
|
761 }
|
max@0
|
762
|
max@0
|
763
|
max@0
|
764
|
max@0
|
765 //! x.submat(...) = y.submat(...)
|
max@0
|
766 template<typename eT>
|
max@0
|
767 inline
|
max@0
|
768 void
|
max@0
|
769 subview<eT>::operator= (const subview<eT>& x_in)
|
max@0
|
770 {
|
max@0
|
771 arma_extra_debug_sigprint();
|
max@0
|
772
|
max@0
|
773 const bool overlap = check_overlap(x_in);
|
max@0
|
774
|
max@0
|
775 Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
|
max@0
|
776 const subview<eT>* tmp_subview = overlap ? new subview<eT>(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
|
max@0
|
777 const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
|
max@0
|
778
|
max@0
|
779 subview<eT>& t = *this;
|
max@0
|
780
|
max@0
|
781 arma_debug_assert_same_size(t, x, "insert into submatrix");
|
max@0
|
782
|
max@0
|
783 const uword t_n_cols = t.n_cols;
|
max@0
|
784 const uword t_n_rows = t.n_rows;
|
max@0
|
785
|
max@0
|
786 if(t_n_rows == 1)
|
max@0
|
787 {
|
max@0
|
788 Mat<eT>& A = *(t.m_ptr);
|
max@0
|
789 const Mat<eT>& B = x.m;
|
max@0
|
790
|
max@0
|
791 const uword row_A = t.aux_row1;
|
max@0
|
792 const uword row_B = x.aux_row1;
|
max@0
|
793
|
max@0
|
794 const uword start_col_A = t.aux_col1;
|
max@0
|
795 const uword start_col_B = x.aux_col1;
|
max@0
|
796
|
max@0
|
797 uword i,j;
|
max@0
|
798
|
max@0
|
799 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
800 {
|
max@0
|
801 const eT tmp1 = B.at(row_B, start_col_B + i);
|
max@0
|
802 const eT tmp2 = B.at(row_B, start_col_B + j);
|
max@0
|
803
|
max@0
|
804 A.at(row_A, start_col_A + i) = tmp1;
|
max@0
|
805 A.at(row_A, start_col_A + j) = tmp2;
|
max@0
|
806 }
|
max@0
|
807
|
max@0
|
808 if(i < t_n_cols)
|
max@0
|
809 {
|
max@0
|
810 A.at(row_A, start_col_A + i) = B.at(row_B, start_col_B + i);
|
max@0
|
811 }
|
max@0
|
812 }
|
max@0
|
813 else
|
max@0
|
814 {
|
max@0
|
815 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
816 {
|
max@0
|
817 arrayops::copy( t.colptr(col), x.colptr(col), t_n_rows );
|
max@0
|
818 }
|
max@0
|
819 }
|
max@0
|
820
|
max@0
|
821 if(overlap)
|
max@0
|
822 {
|
max@0
|
823 delete tmp_subview;
|
max@0
|
824 delete tmp_mat;
|
max@0
|
825 }
|
max@0
|
826 }
|
max@0
|
827
|
max@0
|
828
|
max@0
|
829
|
max@0
|
830 template<typename eT>
|
max@0
|
831 inline
|
max@0
|
832 void
|
max@0
|
833 subview<eT>::operator+= (const subview<eT>& x_in)
|
max@0
|
834 {
|
max@0
|
835 arma_extra_debug_sigprint();
|
max@0
|
836
|
max@0
|
837 const bool overlap = check_overlap(x_in);
|
max@0
|
838
|
max@0
|
839 Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
|
max@0
|
840 const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
|
max@0
|
841 const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
|
max@0
|
842
|
max@0
|
843 subview<eT>& t = *this;
|
max@0
|
844
|
max@0
|
845 arma_debug_assert_same_size(t, x, "addition");
|
max@0
|
846
|
max@0
|
847 const uword t_n_rows = t.n_rows;
|
max@0
|
848 const uword t_n_cols = t.n_cols;
|
max@0
|
849
|
max@0
|
850 if(t_n_rows == 1)
|
max@0
|
851 {
|
max@0
|
852 Mat<eT>& A = *(t.m_ptr);
|
max@0
|
853 const Mat<eT>& B = x.m;
|
max@0
|
854
|
max@0
|
855 const uword row_A = t.aux_row1;
|
max@0
|
856 const uword row_B = x.aux_row1;
|
max@0
|
857
|
max@0
|
858 const uword start_col_A = t.aux_col1;
|
max@0
|
859 const uword start_col_B = x.aux_col1;
|
max@0
|
860
|
max@0
|
861 uword i,j;
|
max@0
|
862
|
max@0
|
863 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
864 {
|
max@0
|
865 const eT tmp1 = B.at(row_B, start_col_B + i);
|
max@0
|
866 const eT tmp2 = B.at(row_B, start_col_B + j);
|
max@0
|
867
|
max@0
|
868 A.at(row_A, start_col_A + i) += tmp1;
|
max@0
|
869 A.at(row_A, start_col_A + j) += tmp2;
|
max@0
|
870 }
|
max@0
|
871
|
max@0
|
872 if(i < t_n_cols)
|
max@0
|
873 {
|
max@0
|
874 A.at(row_A, start_col_A + i) += B.at(row_B, start_col_B + i);
|
max@0
|
875 }
|
max@0
|
876 }
|
max@0
|
877 else
|
max@0
|
878 {
|
max@0
|
879 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
880 {
|
max@0
|
881 arrayops::inplace_plus( t.colptr(col), x.colptr(col), t_n_rows );
|
max@0
|
882 }
|
max@0
|
883 }
|
max@0
|
884
|
max@0
|
885 if(overlap)
|
max@0
|
886 {
|
max@0
|
887 delete tmp_subview;
|
max@0
|
888 delete tmp_mat;
|
max@0
|
889 }
|
max@0
|
890 }
|
max@0
|
891
|
max@0
|
892
|
max@0
|
893
|
max@0
|
894 template<typename eT>
|
max@0
|
895 inline
|
max@0
|
896 void
|
max@0
|
897 subview<eT>::operator-= (const subview<eT>& x_in)
|
max@0
|
898 {
|
max@0
|
899 arma_extra_debug_sigprint();
|
max@0
|
900
|
max@0
|
901 const bool overlap = check_overlap(x_in);
|
max@0
|
902
|
max@0
|
903 Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
|
max@0
|
904 const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
|
max@0
|
905 const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
|
max@0
|
906
|
max@0
|
907 subview<eT>& t = *this;
|
max@0
|
908
|
max@0
|
909 arma_debug_assert_same_size(t, x, "subtraction");
|
max@0
|
910
|
max@0
|
911 const uword t_n_rows = t.n_rows;
|
max@0
|
912 const uword t_n_cols = t.n_cols;
|
max@0
|
913
|
max@0
|
914 if(t_n_rows == 1)
|
max@0
|
915 {
|
max@0
|
916 Mat<eT>& A = *(t.m_ptr);
|
max@0
|
917 const Mat<eT>& B = x.m;
|
max@0
|
918
|
max@0
|
919 const uword row_A = t.aux_row1;
|
max@0
|
920 const uword row_B = x.aux_row1;
|
max@0
|
921
|
max@0
|
922 const uword start_col_A = t.aux_col1;
|
max@0
|
923 const uword start_col_B = x.aux_col1;
|
max@0
|
924
|
max@0
|
925 uword i,j;
|
max@0
|
926
|
max@0
|
927 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
928 {
|
max@0
|
929 const eT tmp1 = B.at(row_B, start_col_B + i);
|
max@0
|
930 const eT tmp2 = B.at(row_B, start_col_B + j);
|
max@0
|
931
|
max@0
|
932 A.at(row_A, start_col_A + i) -= tmp1;
|
max@0
|
933 A.at(row_A, start_col_A + j) -= tmp2;
|
max@0
|
934 }
|
max@0
|
935
|
max@0
|
936 if(i < t_n_cols)
|
max@0
|
937 {
|
max@0
|
938 A.at(row_A, start_col_A + i) -= B.at(row_B, start_col_B + i);
|
max@0
|
939 }
|
max@0
|
940 }
|
max@0
|
941 else
|
max@0
|
942 {
|
max@0
|
943 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
944 {
|
max@0
|
945 arrayops::inplace_minus( t.colptr(col), x.colptr(col), t_n_rows );
|
max@0
|
946 }
|
max@0
|
947 }
|
max@0
|
948
|
max@0
|
949 if(overlap)
|
max@0
|
950 {
|
max@0
|
951 delete tmp_subview;
|
max@0
|
952 delete tmp_mat;
|
max@0
|
953 }
|
max@0
|
954
|
max@0
|
955 }
|
max@0
|
956
|
max@0
|
957
|
max@0
|
958
|
max@0
|
959 template<typename eT>
|
max@0
|
960 inline
|
max@0
|
961 void
|
max@0
|
962 subview<eT>::operator%= (const subview& x_in)
|
max@0
|
963 {
|
max@0
|
964 arma_extra_debug_sigprint();
|
max@0
|
965
|
max@0
|
966 const bool overlap = check_overlap(x_in);
|
max@0
|
967
|
max@0
|
968 Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
|
max@0
|
969 const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
|
max@0
|
970 const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
|
max@0
|
971
|
max@0
|
972 subview<eT>& t = *this;
|
max@0
|
973
|
max@0
|
974 arma_debug_assert_same_size(t, x, "element-wise multiplication");
|
max@0
|
975
|
max@0
|
976 const uword t_n_rows = t.n_rows;
|
max@0
|
977 const uword t_n_cols = t.n_cols;
|
max@0
|
978
|
max@0
|
979 if(t_n_rows == 1)
|
max@0
|
980 {
|
max@0
|
981 Mat<eT>& A = *(t.m_ptr);
|
max@0
|
982 const Mat<eT>& B = x.m;
|
max@0
|
983
|
max@0
|
984 const uword row_A = t.aux_row1;
|
max@0
|
985 const uword row_B = x.aux_row1;
|
max@0
|
986
|
max@0
|
987 const uword start_col_A = t.aux_col1;
|
max@0
|
988 const uword start_col_B = x.aux_col1;
|
max@0
|
989
|
max@0
|
990 uword i,j;
|
max@0
|
991
|
max@0
|
992 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
993 {
|
max@0
|
994 const eT tmp1 = B.at(row_B, start_col_B + i);
|
max@0
|
995 const eT tmp2 = B.at(row_B, start_col_B + j);
|
max@0
|
996
|
max@0
|
997 A.at(row_A, start_col_A + i) *= tmp1;
|
max@0
|
998 A.at(row_A, start_col_A + j) *= tmp2;
|
max@0
|
999 }
|
max@0
|
1000
|
max@0
|
1001 if(i < t_n_cols)
|
max@0
|
1002 {
|
max@0
|
1003 A.at(row_A, start_col_A + i) *= B.at(row_B, start_col_B + i);
|
max@0
|
1004 }
|
max@0
|
1005 }
|
max@0
|
1006 else
|
max@0
|
1007 {
|
max@0
|
1008 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
1009 {
|
max@0
|
1010 arrayops::inplace_mul( t.colptr(col), x.colptr(col), t_n_rows );
|
max@0
|
1011 }
|
max@0
|
1012 }
|
max@0
|
1013
|
max@0
|
1014 if(overlap)
|
max@0
|
1015 {
|
max@0
|
1016 delete tmp_subview;
|
max@0
|
1017 delete tmp_mat;
|
max@0
|
1018 }
|
max@0
|
1019
|
max@0
|
1020 }
|
max@0
|
1021
|
max@0
|
1022
|
max@0
|
1023
|
max@0
|
1024 template<typename eT>
|
max@0
|
1025 inline
|
max@0
|
1026 void
|
max@0
|
1027 subview<eT>::operator/= (const subview& x_in)
|
max@0
|
1028 {
|
max@0
|
1029 arma_extra_debug_sigprint();
|
max@0
|
1030
|
max@0
|
1031 const bool overlap = check_overlap(x_in);
|
max@0
|
1032
|
max@0
|
1033 Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
|
max@0
|
1034 const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0;
|
max@0
|
1035 const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
|
max@0
|
1036
|
max@0
|
1037 subview<eT>& t = *this;
|
max@0
|
1038
|
max@0
|
1039 arma_debug_assert_same_size(t, x, "element-wise division");
|
max@0
|
1040
|
max@0
|
1041 const uword t_n_rows = t.n_rows;
|
max@0
|
1042 const uword t_n_cols = t.n_cols;
|
max@0
|
1043
|
max@0
|
1044 if(t_n_rows == 1)
|
max@0
|
1045 {
|
max@0
|
1046 Mat<eT>& A = *(t.m_ptr);
|
max@0
|
1047 const Mat<eT>& B = x.m;
|
max@0
|
1048
|
max@0
|
1049 const uword row_A = t.aux_row1;
|
max@0
|
1050 const uword row_B = x.aux_row1;
|
max@0
|
1051
|
max@0
|
1052 const uword start_col_A = t.aux_col1;
|
max@0
|
1053 const uword start_col_B = x.aux_col1;
|
max@0
|
1054
|
max@0
|
1055 uword i,j;
|
max@0
|
1056
|
max@0
|
1057 for(i=0, j=1; j < t_n_cols; i+=2, j+=2)
|
max@0
|
1058 {
|
max@0
|
1059 const eT tmp1 = B.at(row_B, start_col_B + i);
|
max@0
|
1060 const eT tmp2 = B.at(row_B, start_col_B + j);
|
max@0
|
1061
|
max@0
|
1062 A.at(row_A, start_col_A + i) /= tmp1;
|
max@0
|
1063 A.at(row_A, start_col_A + j) /= tmp2;
|
max@0
|
1064 }
|
max@0
|
1065
|
max@0
|
1066 if(i < t_n_cols)
|
max@0
|
1067 {
|
max@0
|
1068 A.at(row_A, start_col_A + i) /= B.at(row_B, start_col_B + i);
|
max@0
|
1069 }
|
max@0
|
1070 }
|
max@0
|
1071 else
|
max@0
|
1072 {
|
max@0
|
1073 for(uword col=0; col<t_n_cols; ++col)
|
max@0
|
1074 {
|
max@0
|
1075 arrayops::inplace_div( t.colptr(col), x.colptr(col), t_n_rows );
|
max@0
|
1076 }
|
max@0
|
1077 }
|
max@0
|
1078
|
max@0
|
1079 if(overlap)
|
max@0
|
1080 {
|
max@0
|
1081 delete tmp_subview;
|
max@0
|
1082 delete tmp_mat;
|
max@0
|
1083 }
|
max@0
|
1084
|
max@0
|
1085 }
|
max@0
|
1086
|
max@0
|
1087
|
max@0
|
1088
|
max@0
|
1089 template<typename eT>
|
max@0
|
1090 inline
|
max@0
|
1091 void
|
max@0
|
1092 subview<eT>::fill(const eT val)
|
max@0
|
1093 {
|
max@0
|
1094 arma_extra_debug_sigprint();
|
max@0
|
1095
|
max@0
|
1096 const uword local_n_cols = n_cols;
|
max@0
|
1097 const uword local_n_rows = n_rows;
|
max@0
|
1098
|
max@0
|
1099 if(local_n_rows == 1)
|
max@0
|
1100 {
|
max@0
|
1101 Mat<eT>& X = (*m_ptr);
|
max@0
|
1102
|
max@0
|
1103 const uword row = aux_row1;
|
max@0
|
1104 const uword start_col = aux_col1;
|
max@0
|
1105 const uword end_col_plus1 = start_col + local_n_cols;
|
max@0
|
1106
|
max@0
|
1107 uword i,j;
|
max@0
|
1108
|
max@0
|
1109 for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2)
|
max@0
|
1110 {
|
max@0
|
1111 X.at(row, i) = val;
|
max@0
|
1112 X.at(row, j) = val;
|
max@0
|
1113 }
|
max@0
|
1114
|
max@0
|
1115 if(i < end_col_plus1)
|
max@0
|
1116 {
|
max@0
|
1117 X.at(row, i) = val;
|
max@0
|
1118 }
|
max@0
|
1119 }
|
max@0
|
1120 else
|
max@0
|
1121 {
|
max@0
|
1122 for(uword col=0; col<local_n_cols; ++col)
|
max@0
|
1123 {
|
max@0
|
1124 arrayops::inplace_set( colptr(col), val, local_n_rows );
|
max@0
|
1125 }
|
max@0
|
1126 }
|
max@0
|
1127 }
|
max@0
|
1128
|
max@0
|
1129
|
max@0
|
1130
|
max@0
|
1131 template<typename eT>
|
max@0
|
1132 inline
|
max@0
|
1133 void
|
max@0
|
1134 subview<eT>::zeros()
|
max@0
|
1135 {
|
max@0
|
1136 arma_extra_debug_sigprint();
|
max@0
|
1137
|
max@0
|
1138 (*this).fill(eT(0));
|
max@0
|
1139 }
|
max@0
|
1140
|
max@0
|
1141
|
max@0
|
1142
|
max@0
|
1143 template<typename eT>
|
max@0
|
1144 inline
|
max@0
|
1145 void
|
max@0
|
1146 subview<eT>::ones()
|
max@0
|
1147 {
|
max@0
|
1148 arma_extra_debug_sigprint();
|
max@0
|
1149
|
max@0
|
1150 (*this).fill(eT(1));
|
max@0
|
1151 }
|
max@0
|
1152
|
max@0
|
1153
|
max@0
|
1154
|
max@0
|
1155 template<typename eT>
|
max@0
|
1156 inline
|
max@0
|
1157 void
|
max@0
|
1158 subview<eT>::eye()
|
max@0
|
1159 {
|
max@0
|
1160 arma_extra_debug_sigprint();
|
max@0
|
1161
|
max@0
|
1162 fill(eT(0));
|
max@0
|
1163
|
max@0
|
1164 const uword N = (std::min)(n_rows, n_cols);
|
max@0
|
1165
|
max@0
|
1166 for(uword i=0; i<N; ++i)
|
max@0
|
1167 {
|
max@0
|
1168 at(i,i) = eT(1);
|
max@0
|
1169 }
|
max@0
|
1170 }
|
max@0
|
1171
|
max@0
|
1172
|
max@0
|
1173
|
max@0
|
1174 template<typename eT>
|
max@0
|
1175 inline
|
max@0
|
1176 eT&
|
max@0
|
1177 subview<eT>::operator[](const uword i)
|
max@0
|
1178 {
|
max@0
|
1179 const uword in_col = i / n_rows;
|
max@0
|
1180 const uword in_row = i % n_rows;
|
max@0
|
1181
|
max@0
|
1182 const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
|
max@0
|
1183 return access::rw( (*m_ptr).mem[index] );
|
max@0
|
1184 }
|
max@0
|
1185
|
max@0
|
1186
|
max@0
|
1187
|
max@0
|
1188 template<typename eT>
|
max@0
|
1189 inline
|
max@0
|
1190 eT
|
max@0
|
1191 subview<eT>::operator[](const uword i) const
|
max@0
|
1192 {
|
max@0
|
1193 const uword in_col = i / n_rows;
|
max@0
|
1194 const uword in_row = i % n_rows;
|
max@0
|
1195
|
max@0
|
1196 const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
|
max@0
|
1197 return m.mem[index];
|
max@0
|
1198 }
|
max@0
|
1199
|
max@0
|
1200
|
max@0
|
1201
|
max@0
|
1202 template<typename eT>
|
max@0
|
1203 inline
|
max@0
|
1204 eT&
|
max@0
|
1205 subview<eT>::operator()(const uword i)
|
max@0
|
1206 {
|
max@0
|
1207 arma_debug_check( (i >= n_elem), "subview::operator(): index out of bounds");
|
max@0
|
1208
|
max@0
|
1209 const uword in_col = i / n_rows;
|
max@0
|
1210 const uword in_row = i % n_rows;
|
max@0
|
1211
|
max@0
|
1212 const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
|
max@0
|
1213 return access::rw( (*m_ptr).mem[index] );
|
max@0
|
1214 }
|
max@0
|
1215
|
max@0
|
1216
|
max@0
|
1217
|
max@0
|
1218 template<typename eT>
|
max@0
|
1219 inline
|
max@0
|
1220 eT
|
max@0
|
1221 subview<eT>::operator()(const uword i) const
|
max@0
|
1222 {
|
max@0
|
1223 arma_debug_check( (i >= n_elem), "subview::operator(): index out of bounds");
|
max@0
|
1224
|
max@0
|
1225 const uword in_col = i / n_rows;
|
max@0
|
1226 const uword in_row = i % n_rows;
|
max@0
|
1227
|
max@0
|
1228 const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
|
max@0
|
1229 return m.mem[index];
|
max@0
|
1230 }
|
max@0
|
1231
|
max@0
|
1232
|
max@0
|
1233
|
max@0
|
1234 template<typename eT>
|
max@0
|
1235 inline
|
max@0
|
1236 eT&
|
max@0
|
1237 subview<eT>::operator()(const uword in_row, const uword in_col)
|
max@0
|
1238 {
|
max@0
|
1239 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds");
|
max@0
|
1240
|
max@0
|
1241 const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
|
max@0
|
1242 return access::rw( (*m_ptr).mem[index] );
|
max@0
|
1243 }
|
max@0
|
1244
|
max@0
|
1245
|
max@0
|
1246
|
max@0
|
1247 template<typename eT>
|
max@0
|
1248 inline
|
max@0
|
1249 eT
|
max@0
|
1250 subview<eT>::operator()(const uword in_row, const uword in_col) const
|
max@0
|
1251 {
|
max@0
|
1252 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds");
|
max@0
|
1253
|
max@0
|
1254 const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
|
max@0
|
1255 return m.mem[index];
|
max@0
|
1256 }
|
max@0
|
1257
|
max@0
|
1258
|
max@0
|
1259
|
max@0
|
1260 template<typename eT>
|
max@0
|
1261 inline
|
max@0
|
1262 eT&
|
max@0
|
1263 subview<eT>::at(const uword in_row, const uword in_col)
|
max@0
|
1264 {
|
max@0
|
1265 const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
|
max@0
|
1266 return access::rw( (*m_ptr).mem[index] );
|
max@0
|
1267 }
|
max@0
|
1268
|
max@0
|
1269
|
max@0
|
1270
|
max@0
|
1271 template<typename eT>
|
max@0
|
1272 inline
|
max@0
|
1273 eT
|
max@0
|
1274 subview<eT>::at(const uword in_row, const uword in_col) const
|
max@0
|
1275 {
|
max@0
|
1276 const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
|
max@0
|
1277 return m.mem[index];
|
max@0
|
1278 }
|
max@0
|
1279
|
max@0
|
1280
|
max@0
|
1281
|
max@0
|
1282 template<typename eT>
|
max@0
|
1283 arma_inline
|
max@0
|
1284 eT*
|
max@0
|
1285 subview<eT>::colptr(const uword in_col)
|
max@0
|
1286 {
|
max@0
|
1287 return & access::rw((*m_ptr).mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]);
|
max@0
|
1288 }
|
max@0
|
1289
|
max@0
|
1290
|
max@0
|
1291
|
max@0
|
1292 template<typename eT>
|
max@0
|
1293 arma_inline
|
max@0
|
1294 const eT*
|
max@0
|
1295 subview<eT>::colptr(const uword in_col) const
|
max@0
|
1296 {
|
max@0
|
1297 return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ];
|
max@0
|
1298 }
|
max@0
|
1299
|
max@0
|
1300
|
max@0
|
1301
|
max@0
|
1302 template<typename eT>
|
max@0
|
1303 inline
|
max@0
|
1304 bool
|
max@0
|
1305 subview<eT>::check_overlap(const subview<eT>& x) const
|
max@0
|
1306 {
|
max@0
|
1307 const subview<eT>& t = *this;
|
max@0
|
1308
|
max@0
|
1309 if(&t.m != &x.m)
|
max@0
|
1310 {
|
max@0
|
1311 return false;
|
max@0
|
1312 }
|
max@0
|
1313 else
|
max@0
|
1314 {
|
max@0
|
1315 if( (t.n_elem == 0) || (x.n_elem == 0) )
|
max@0
|
1316 {
|
max@0
|
1317 return false;
|
max@0
|
1318 }
|
max@0
|
1319 else
|
max@0
|
1320 {
|
max@0
|
1321 const uword t_row_start = t.aux_row1;
|
max@0
|
1322 const uword t_row_end_p1 = t_row_start + t.n_rows;
|
max@0
|
1323
|
max@0
|
1324 const uword t_col_start = t.aux_col1;
|
max@0
|
1325 const uword t_col_end_p1 = t_col_start + t.n_cols;
|
max@0
|
1326
|
max@0
|
1327
|
max@0
|
1328 const uword x_row_start = x.aux_row1;
|
max@0
|
1329 const uword x_row_end_p1 = x_row_start + x.n_rows;
|
max@0
|
1330
|
max@0
|
1331 const uword x_col_start = x.aux_col1;
|
max@0
|
1332 const uword x_col_end_p1 = x_col_start + x.n_cols;
|
max@0
|
1333
|
max@0
|
1334
|
max@0
|
1335 const bool outside_rows = ( (x_row_start >= t_row_end_p1) || (t_row_start >= x_row_end_p1) );
|
max@0
|
1336 const bool outside_cols = ( (x_col_start >= t_col_end_p1) || (t_col_start >= x_col_end_p1) );
|
max@0
|
1337
|
max@0
|
1338 return ( (outside_rows == false) && (outside_cols == false) );
|
max@0
|
1339 }
|
max@0
|
1340 }
|
max@0
|
1341 }
|
max@0
|
1342
|
max@0
|
1343
|
max@0
|
1344
|
max@0
|
1345 template<typename eT>
|
max@0
|
1346 inline
|
max@0
|
1347 bool
|
max@0
|
1348 subview<eT>::is_vec() const
|
max@0
|
1349 {
|
max@0
|
1350 return ( (n_rows == 1) || (n_cols == 1) );
|
max@0
|
1351 }
|
max@0
|
1352
|
max@0
|
1353
|
max@0
|
1354
|
max@0
|
1355 //! X = Y.submat(...)
|
max@0
|
1356 template<typename eT>
|
max@0
|
1357 inline
|
max@0
|
1358 void
|
max@0
|
1359 subview<eT>::extract(Mat<eT>& out, const subview<eT>& in)
|
max@0
|
1360 {
|
max@0
|
1361 arma_extra_debug_sigprint();
|
max@0
|
1362
|
max@0
|
1363 // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing;
|
max@0
|
1364 // size setting and alias checking is done by either the Mat contructor or operator=()
|
max@0
|
1365
|
max@0
|
1366 const uword n_rows = in.n_rows; // number of rows in the subview
|
max@0
|
1367 const uword n_cols = in.n_cols; // number of columns in the subview
|
max@0
|
1368
|
max@0
|
1369 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.m.n_rows % in.m.n_cols );
|
max@0
|
1370
|
max@0
|
1371
|
max@0
|
1372 if(in.is_vec() == true)
|
max@0
|
1373 {
|
max@0
|
1374 if(n_cols == 1) // a column vector
|
max@0
|
1375 {
|
max@0
|
1376 arma_extra_debug_print("subview::extract(): copying col (going across rows)");
|
max@0
|
1377
|
max@0
|
1378 // in.colptr(0) the first column of the subview, taking into account any row offset
|
max@0
|
1379 arrayops::copy( out.memptr(), in.colptr(0), n_rows );
|
max@0
|
1380 }
|
max@0
|
1381 else // a row vector (possibly empty)
|
max@0
|
1382 {
|
max@0
|
1383 arma_extra_debug_print("subview::extract(): copying row (going across columns)");
|
max@0
|
1384
|
max@0
|
1385 const Mat<eT>& X = in.m;
|
max@0
|
1386
|
max@0
|
1387 eT* out_mem = out.memptr();
|
max@0
|
1388
|
max@0
|
1389 const uword row = in.aux_row1;
|
max@0
|
1390 const uword start_col = in.aux_col1;
|
max@0
|
1391
|
max@0
|
1392 uword i,j;
|
max@0
|
1393
|
max@0
|
1394 for(i=0, j=1; j < n_cols; i+=2, j+=2)
|
max@0
|
1395 {
|
max@0
|
1396 const eT tmp1 = X.at(row, start_col+i);
|
max@0
|
1397 const eT tmp2 = X.at(row, start_col+j);
|
max@0
|
1398
|
max@0
|
1399 out_mem[i] = tmp1;
|
max@0
|
1400 out_mem[j] = tmp2;
|
max@0
|
1401 }
|
max@0
|
1402
|
max@0
|
1403 if(i < n_cols)
|
max@0
|
1404 {
|
max@0
|
1405 out_mem[i] = X.at(row, start_col+i);
|
max@0
|
1406 }
|
max@0
|
1407 }
|
max@0
|
1408 }
|
max@0
|
1409 else // general submatrix
|
max@0
|
1410 {
|
max@0
|
1411 arma_extra_debug_print("subview::extract(): general submatrix");
|
max@0
|
1412
|
max@0
|
1413 for(uword col = 0; col<n_cols; ++col)
|
max@0
|
1414 {
|
max@0
|
1415 arrayops::copy( out.colptr(col), in.colptr(col), n_rows );
|
max@0
|
1416 }
|
max@0
|
1417 }
|
max@0
|
1418 }
|
max@0
|
1419
|
max@0
|
1420
|
max@0
|
1421
|
max@0
|
1422 //! X += Y.submat(...)
|
max@0
|
1423 template<typename eT>
|
max@0
|
1424 inline
|
max@0
|
1425 void
|
max@0
|
1426 subview<eT>::plus_inplace(Mat<eT>& out, const subview<eT>& in)
|
max@0
|
1427 {
|
max@0
|
1428 arma_extra_debug_sigprint();
|
max@0
|
1429
|
max@0
|
1430 arma_debug_assert_same_size(out, in, "addition");
|
max@0
|
1431
|
max@0
|
1432 const uword n_rows = in.n_rows;
|
max@0
|
1433 const uword n_cols = in.n_cols;
|
max@0
|
1434
|
max@0
|
1435 if(n_rows == 1)
|
max@0
|
1436 {
|
max@0
|
1437 eT* out_mem = out.memptr();
|
max@0
|
1438
|
max@0
|
1439 const Mat<eT>& X = in.m;
|
max@0
|
1440
|
max@0
|
1441 const uword row = in.aux_row1;
|
max@0
|
1442 const uword start_col = in.aux_col1;
|
max@0
|
1443
|
max@0
|
1444 uword i,j;
|
max@0
|
1445 for(i=0, j=1; j < n_cols; i+=2, j+=2)
|
max@0
|
1446 {
|
max@0
|
1447 const eT tmp1 = X.at(row, start_col+i);
|
max@0
|
1448 const eT tmp2 = X.at(row, start_col+j);
|
max@0
|
1449
|
max@0
|
1450 out_mem[i] += tmp1;
|
max@0
|
1451 out_mem[j] += tmp2;
|
max@0
|
1452 }
|
max@0
|
1453
|
max@0
|
1454 if(i < n_cols)
|
max@0
|
1455 {
|
max@0
|
1456 out_mem[i] += X.at(row, start_col+i);
|
max@0
|
1457 }
|
max@0
|
1458 }
|
max@0
|
1459 else
|
max@0
|
1460 {
|
max@0
|
1461 for(uword col=0; col<n_cols; ++col)
|
max@0
|
1462 {
|
max@0
|
1463 arrayops::inplace_plus(out.colptr(col), in.colptr(col), n_rows);
|
max@0
|
1464 }
|
max@0
|
1465 }
|
max@0
|
1466 }
|
max@0
|
1467
|
max@0
|
1468
|
max@0
|
1469
|
max@0
|
1470 //! X -= Y.submat(...)
|
max@0
|
1471 template<typename eT>
|
max@0
|
1472 inline
|
max@0
|
1473 void
|
max@0
|
1474 subview<eT>::minus_inplace(Mat<eT>& out, const subview<eT>& in)
|
max@0
|
1475 {
|
max@0
|
1476 arma_extra_debug_sigprint();
|
max@0
|
1477
|
max@0
|
1478 arma_debug_assert_same_size(out, in, "subtraction");
|
max@0
|
1479
|
max@0
|
1480 const uword n_rows = in.n_rows;
|
max@0
|
1481 const uword n_cols = in.n_cols;
|
max@0
|
1482
|
max@0
|
1483 if(n_rows == 1)
|
max@0
|
1484 {
|
max@0
|
1485 eT* out_mem = out.memptr();
|
max@0
|
1486
|
max@0
|
1487 const Mat<eT>& X = in.m;
|
max@0
|
1488
|
max@0
|
1489 const uword row = in.aux_row1;
|
max@0
|
1490 const uword start_col = in.aux_col1;
|
max@0
|
1491
|
max@0
|
1492 uword i,j;
|
max@0
|
1493 for(i=0, j=1; j < n_cols; i+=2, j+=2)
|
max@0
|
1494 {
|
max@0
|
1495 const eT tmp1 = X.at(row, start_col+i);
|
max@0
|
1496 const eT tmp2 = X.at(row, start_col+j);
|
max@0
|
1497
|
max@0
|
1498 out_mem[i] -= tmp1;
|
max@0
|
1499 out_mem[j] -= tmp2;
|
max@0
|
1500 }
|
max@0
|
1501
|
max@0
|
1502 if(i < n_cols)
|
max@0
|
1503 {
|
max@0
|
1504 out_mem[i] -= X.at(row, start_col+i);
|
max@0
|
1505 }
|
max@0
|
1506 }
|
max@0
|
1507 else
|
max@0
|
1508 {
|
max@0
|
1509 for(uword col=0; col<n_cols; ++col)
|
max@0
|
1510 {
|
max@0
|
1511 arrayops::inplace_minus(out.colptr(col), in.colptr(col), n_rows);
|
max@0
|
1512 }
|
max@0
|
1513 }
|
max@0
|
1514 }
|
max@0
|
1515
|
max@0
|
1516
|
max@0
|
1517
|
max@0
|
1518 //! X %= Y.submat(...)
|
max@0
|
1519 template<typename eT>
|
max@0
|
1520 inline
|
max@0
|
1521 void
|
max@0
|
1522 subview<eT>::schur_inplace(Mat<eT>& out, const subview<eT>& in)
|
max@0
|
1523 {
|
max@0
|
1524 arma_extra_debug_sigprint();
|
max@0
|
1525
|
max@0
|
1526 arma_debug_assert_same_size(out, in, "element-wise multiplication");
|
max@0
|
1527
|
max@0
|
1528 const uword n_rows = in.n_rows;
|
max@0
|
1529 const uword n_cols = in.n_cols;
|
max@0
|
1530
|
max@0
|
1531 if(n_rows == 1)
|
max@0
|
1532 {
|
max@0
|
1533 eT* out_mem = out.memptr();
|
max@0
|
1534
|
max@0
|
1535 const Mat<eT>& X = in.m;
|
max@0
|
1536
|
max@0
|
1537 const uword row = in.aux_row1;
|
max@0
|
1538 const uword start_col = in.aux_col1;
|
max@0
|
1539
|
max@0
|
1540 uword i,j;
|
max@0
|
1541 for(i=0, j=1; j < n_cols; i+=2, j+=2)
|
max@0
|
1542 {
|
max@0
|
1543 const eT tmp1 = X.at(row, start_col+i);
|
max@0
|
1544 const eT tmp2 = X.at(row, start_col+j);
|
max@0
|
1545
|
max@0
|
1546 out_mem[i] *= tmp1;
|
max@0
|
1547 out_mem[j] *= tmp2;
|
max@0
|
1548 }
|
max@0
|
1549
|
max@0
|
1550 if(i < n_cols)
|
max@0
|
1551 {
|
max@0
|
1552 out_mem[i] *= X.at(row, start_col+i);
|
max@0
|
1553 }
|
max@0
|
1554 }
|
max@0
|
1555 else
|
max@0
|
1556 {
|
max@0
|
1557 for(uword col=0; col<n_cols; ++col)
|
max@0
|
1558 {
|
max@0
|
1559 arrayops::inplace_mul(out.colptr(col), in.colptr(col), n_rows);
|
max@0
|
1560 }
|
max@0
|
1561 }
|
max@0
|
1562 }
|
max@0
|
1563
|
max@0
|
1564
|
max@0
|
1565
|
max@0
|
1566 //! X /= Y.submat(...)
|
max@0
|
1567 template<typename eT>
|
max@0
|
1568 inline
|
max@0
|
1569 void
|
max@0
|
1570 subview<eT>::div_inplace(Mat<eT>& out, const subview<eT>& in)
|
max@0
|
1571 {
|
max@0
|
1572 arma_extra_debug_sigprint();
|
max@0
|
1573
|
max@0
|
1574 arma_debug_assert_same_size(out, in, "element-wise division");
|
max@0
|
1575
|
max@0
|
1576 const uword n_rows = in.n_rows;
|
max@0
|
1577 const uword n_cols = in.n_cols;
|
max@0
|
1578
|
max@0
|
1579 if(n_rows == 1)
|
max@0
|
1580 {
|
max@0
|
1581 eT* out_mem = out.memptr();
|
max@0
|
1582
|
max@0
|
1583 const Mat<eT>& X = in.m;
|
max@0
|
1584
|
max@0
|
1585 const uword row = in.aux_row1;
|
max@0
|
1586 const uword start_col = in.aux_col1;
|
max@0
|
1587
|
max@0
|
1588 uword i,j;
|
max@0
|
1589 for(i=0, j=1; j < n_cols; i+=2, j+=2)
|
max@0
|
1590 {
|
max@0
|
1591 const eT tmp1 = X.at(row, start_col+i);
|
max@0
|
1592 const eT tmp2 = X.at(row, start_col+j);
|
max@0
|
1593
|
max@0
|
1594 out_mem[i] /= tmp1;
|
max@0
|
1595 out_mem[j] /= tmp2;
|
max@0
|
1596 }
|
max@0
|
1597
|
max@0
|
1598 if(i < n_cols)
|
max@0
|
1599 {
|
max@0
|
1600 out_mem[i] /= X.at(row, start_col+i);
|
max@0
|
1601 }
|
max@0
|
1602 }
|
max@0
|
1603 else
|
max@0
|
1604 {
|
max@0
|
1605 for(uword col=0; col<n_cols; ++col)
|
max@0
|
1606 {
|
max@0
|
1607 arrayops::inplace_div(out.colptr(col), in.colptr(col), n_rows);
|
max@0
|
1608 }
|
max@0
|
1609 }
|
max@0
|
1610 }
|
max@0
|
1611
|
max@0
|
1612
|
max@0
|
1613
|
max@0
|
1614 //! creation of subview (row vector)
|
max@0
|
1615 template<typename eT>
|
max@0
|
1616 inline
|
max@0
|
1617 subview_row<eT>
|
max@0
|
1618 subview<eT>::row(const uword row_num)
|
max@0
|
1619 {
|
max@0
|
1620 arma_extra_debug_sigprint();
|
max@0
|
1621
|
max@0
|
1622 arma_debug_check( row_num >= n_rows, "subview::row(): out of bounds" );
|
max@0
|
1623
|
max@0
|
1624 const uword base_row = aux_row1 + row_num;
|
max@0
|
1625
|
max@0
|
1626 return subview_row<eT>(*m_ptr, base_row, aux_col1, n_cols);
|
max@0
|
1627 }
|
max@0
|
1628
|
max@0
|
1629
|
max@0
|
1630
|
max@0
|
1631 //! creation of subview (row vector)
|
max@0
|
1632 template<typename eT>
|
max@0
|
1633 inline
|
max@0
|
1634 const subview_row<eT>
|
max@0
|
1635 subview<eT>::row(const uword row_num) const
|
max@0
|
1636 {
|
max@0
|
1637 arma_extra_debug_sigprint();
|
max@0
|
1638
|
max@0
|
1639 arma_debug_check( row_num >= n_rows, "subview::row(): out of bounds" );
|
max@0
|
1640
|
max@0
|
1641 const uword base_row = aux_row1 + row_num;
|
max@0
|
1642
|
max@0
|
1643 return subview_row<eT>(m, base_row, aux_col1, n_cols);
|
max@0
|
1644 }
|
max@0
|
1645
|
max@0
|
1646
|
max@0
|
1647
|
max@0
|
1648 template<typename eT>
|
max@0
|
1649 inline
|
max@0
|
1650 subview_row<eT>
|
max@0
|
1651 subview<eT>::operator()(const uword row_num, const span& col_span)
|
max@0
|
1652 {
|
max@0
|
1653 arma_extra_debug_sigprint();
|
max@0
|
1654
|
max@0
|
1655 const bool col_all = col_span.whole;
|
max@0
|
1656
|
max@0
|
1657 const uword local_n_cols = n_cols;
|
max@0
|
1658
|
max@0
|
1659 const uword in_col1 = col_all ? 0 : col_span.a;
|
max@0
|
1660 const uword in_col2 = col_span.b;
|
max@0
|
1661 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
|
max@0
|
1662
|
max@0
|
1663 const uword base_col1 = aux_col1 + in_col1;
|
max@0
|
1664 const uword base_row = aux_row1 + row_num;
|
max@0
|
1665
|
max@0
|
1666 arma_debug_check
|
max@0
|
1667 (
|
max@0
|
1668 (row_num >= n_rows)
|
max@0
|
1669 ||
|
max@0
|
1670 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
|
max@0
|
1671 ,
|
max@0
|
1672 "subview::operator(): indices out of bounds or incorrectly used"
|
max@0
|
1673 );
|
max@0
|
1674
|
max@0
|
1675 return subview_row<eT>(*m_ptr, base_row, base_col1, submat_n_cols);
|
max@0
|
1676 }
|
max@0
|
1677
|
max@0
|
1678
|
max@0
|
1679
|
max@0
|
1680 template<typename eT>
|
max@0
|
1681 inline
|
max@0
|
1682 const subview_row<eT>
|
max@0
|
1683 subview<eT>::operator()(const uword row_num, const span& col_span) const
|
max@0
|
1684 {
|
max@0
|
1685 arma_extra_debug_sigprint();
|
max@0
|
1686
|
max@0
|
1687 const bool col_all = col_span.whole;
|
max@0
|
1688
|
max@0
|
1689 const uword local_n_cols = n_cols;
|
max@0
|
1690
|
max@0
|
1691 const uword in_col1 = col_all ? 0 : col_span.a;
|
max@0
|
1692 const uword in_col2 = col_span.b;
|
max@0
|
1693 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
|
max@0
|
1694
|
max@0
|
1695 const uword base_col1 = aux_col1 + in_col1;
|
max@0
|
1696 const uword base_row = aux_row1 + row_num;
|
max@0
|
1697
|
max@0
|
1698 arma_debug_check
|
max@0
|
1699 (
|
max@0
|
1700 (row_num >= n_rows)
|
max@0
|
1701 ||
|
max@0
|
1702 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
|
max@0
|
1703 ,
|
max@0
|
1704 "subview::operator(): indices out of bounds or incorrectly used"
|
max@0
|
1705 );
|
max@0
|
1706
|
max@0
|
1707 return subview_row<eT>(m, base_row, base_col1, submat_n_cols);
|
max@0
|
1708 }
|
max@0
|
1709
|
max@0
|
1710
|
max@0
|
1711
|
max@0
|
1712 //! creation of subview (column vector)
|
max@0
|
1713 template<typename eT>
|
max@0
|
1714 inline
|
max@0
|
1715 subview_col<eT>
|
max@0
|
1716 subview<eT>::col(const uword col_num)
|
max@0
|
1717 {
|
max@0
|
1718 arma_extra_debug_sigprint();
|
max@0
|
1719
|
max@0
|
1720 arma_debug_check( col_num >= n_cols, "subview::col(): out of bounds");
|
max@0
|
1721
|
max@0
|
1722 const uword base_col = aux_col1 + col_num;
|
max@0
|
1723
|
max@0
|
1724 return subview_col<eT>(*m_ptr, base_col, aux_row1, n_rows);
|
max@0
|
1725 }
|
max@0
|
1726
|
max@0
|
1727
|
max@0
|
1728
|
max@0
|
1729 //! creation of subview (column vector)
|
max@0
|
1730 template<typename eT>
|
max@0
|
1731 inline
|
max@0
|
1732 const subview_col<eT>
|
max@0
|
1733 subview<eT>::col(const uword col_num) const
|
max@0
|
1734 {
|
max@0
|
1735 arma_extra_debug_sigprint();
|
max@0
|
1736
|
max@0
|
1737 arma_debug_check( col_num >= n_cols, "subview::col(): out of bounds");
|
max@0
|
1738
|
max@0
|
1739 const uword base_col = aux_col1 + col_num;
|
max@0
|
1740
|
max@0
|
1741 return subview_col<eT>(m, base_col, aux_row1, n_rows);
|
max@0
|
1742 }
|
max@0
|
1743
|
max@0
|
1744
|
max@0
|
1745
|
max@0
|
1746 template<typename eT>
|
max@0
|
1747 inline
|
max@0
|
1748 subview_col<eT>
|
max@0
|
1749 subview<eT>::operator()(const span& row_span, const uword col_num)
|
max@0
|
1750 {
|
max@0
|
1751 arma_extra_debug_sigprint();
|
max@0
|
1752
|
max@0
|
1753 const bool row_all = row_span.whole;
|
max@0
|
1754
|
max@0
|
1755 const uword local_n_rows = n_rows;
|
max@0
|
1756
|
max@0
|
1757 const uword in_row1 = row_all ? 0 : row_span.a;
|
max@0
|
1758 const uword in_row2 = row_span.b;
|
max@0
|
1759 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
|
max@0
|
1760
|
max@0
|
1761 const uword base_row1 = aux_row1 + in_row1;
|
max@0
|
1762 const uword base_col = aux_col1 + col_num;
|
max@0
|
1763
|
max@0
|
1764 arma_debug_check
|
max@0
|
1765 (
|
max@0
|
1766 (col_num >= n_cols)
|
max@0
|
1767 ||
|
max@0
|
1768 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
|
max@0
|
1769 ,
|
max@0
|
1770 "subview::operator(): indices out of bounds or incorrectly used"
|
max@0
|
1771 );
|
max@0
|
1772
|
max@0
|
1773 return subview_col<eT>(*m_ptr, base_col, base_row1, submat_n_rows);
|
max@0
|
1774 }
|
max@0
|
1775
|
max@0
|
1776
|
max@0
|
1777
|
max@0
|
1778 template<typename eT>
|
max@0
|
1779 inline
|
max@0
|
1780 const subview_col<eT>
|
max@0
|
1781 subview<eT>::operator()(const span& row_span, const uword col_num) const
|
max@0
|
1782 {
|
max@0
|
1783 arma_extra_debug_sigprint();
|
max@0
|
1784
|
max@0
|
1785 const bool row_all = row_span.whole;
|
max@0
|
1786
|
max@0
|
1787 const uword local_n_rows = n_rows;
|
max@0
|
1788
|
max@0
|
1789 const uword in_row1 = row_all ? 0 : row_span.a;
|
max@0
|
1790 const uword in_row2 = row_span.b;
|
max@0
|
1791 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
|
max@0
|
1792
|
max@0
|
1793 const uword base_row1 = aux_row1 + in_row1;
|
max@0
|
1794 const uword base_col = aux_col1 + col_num;
|
max@0
|
1795
|
max@0
|
1796 arma_debug_check
|
max@0
|
1797 (
|
max@0
|
1798 (col_num >= n_cols)
|
max@0
|
1799 ||
|
max@0
|
1800 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
|
max@0
|
1801 ,
|
max@0
|
1802 "subview::operator(): indices out of bounds or incorrectly used"
|
max@0
|
1803 );
|
max@0
|
1804
|
max@0
|
1805 return subview_col<eT>(m, base_col, base_row1, submat_n_rows);
|
max@0
|
1806 }
|
max@0
|
1807
|
max@0
|
1808
|
max@0
|
1809
|
max@0
|
1810 //! create a Col object which uses memory from an existing matrix object.
|
max@0
|
1811 //! this approach is currently not alias safe
|
max@0
|
1812 //! and does not take into account that the parent matrix object could be deleted.
|
max@0
|
1813 //! if deleted memory is accessed by the created Col object,
|
max@0
|
1814 //! it will cause memory corruption and/or a crash
|
max@0
|
1815 template<typename eT>
|
max@0
|
1816 inline
|
max@0
|
1817 Col<eT>
|
max@0
|
1818 subview<eT>::unsafe_col(const uword col_num)
|
max@0
|
1819 {
|
max@0
|
1820 arma_extra_debug_sigprint();
|
max@0
|
1821
|
max@0
|
1822 arma_debug_check( col_num >= n_cols, "subview::unsafe_col(): out of bounds");
|
max@0
|
1823
|
max@0
|
1824 return Col<eT>(colptr(col_num), n_rows, false, true);
|
max@0
|
1825 }
|
max@0
|
1826
|
max@0
|
1827
|
max@0
|
1828
|
max@0
|
1829 //! create a Col object which uses memory from an existing matrix object.
|
max@0
|
1830 //! this approach is currently not alias safe
|
max@0
|
1831 //! and does not take into account that the parent matrix object could be deleted.
|
max@0
|
1832 //! if deleted memory is accessed by the created Col object,
|
max@0
|
1833 //! it will cause memory corruption and/or a crash
|
max@0
|
1834 template<typename eT>
|
max@0
|
1835 inline
|
max@0
|
1836 const Col<eT>
|
max@0
|
1837 subview<eT>::unsafe_col(const uword col_num) const
|
max@0
|
1838 {
|
max@0
|
1839 arma_extra_debug_sigprint();
|
max@0
|
1840
|
max@0
|
1841 arma_debug_check( col_num >= n_cols, "subview::unsafe_col(): out of bounds");
|
max@0
|
1842
|
max@0
|
1843 return Col<eT>(const_cast<eT*>(colptr(col_num)), n_rows, false, true);
|
max@0
|
1844 }
|
max@0
|
1845
|
max@0
|
1846
|
max@0
|
1847
|
max@0
|
1848 //! creation of subview (submatrix comprised of specified row vectors)
|
max@0
|
1849 template<typename eT>
|
max@0
|
1850 inline
|
max@0
|
1851 subview<eT>
|
max@0
|
1852 subview<eT>::rows(const uword in_row1, const uword in_row2)
|
max@0
|
1853 {
|
max@0
|
1854 arma_extra_debug_sigprint();
|
max@0
|
1855
|
max@0
|
1856 arma_debug_check
|
max@0
|
1857 (
|
max@0
|
1858 (in_row1 > in_row2) || (in_row2 >= n_rows),
|
max@0
|
1859 "subview::rows(): indices out of bounds or incorrectly used"
|
max@0
|
1860 );
|
max@0
|
1861
|
max@0
|
1862 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
1863 const uword base_row1 = aux_row1 + in_row1;
|
max@0
|
1864
|
max@0
|
1865 return subview<eT>(*m_ptr, base_row1, aux_col1, subview_n_rows, n_cols );
|
max@0
|
1866 }
|
max@0
|
1867
|
max@0
|
1868
|
max@0
|
1869
|
max@0
|
1870 //! creation of subview (submatrix comprised of specified row vectors)
|
max@0
|
1871 template<typename eT>
|
max@0
|
1872 inline
|
max@0
|
1873 const subview<eT>
|
max@0
|
1874 subview<eT>::rows(const uword in_row1, const uword in_row2) const
|
max@0
|
1875 {
|
max@0
|
1876 arma_extra_debug_sigprint();
|
max@0
|
1877
|
max@0
|
1878 arma_debug_check
|
max@0
|
1879 (
|
max@0
|
1880 (in_row1 > in_row2) || (in_row2 >= n_rows),
|
max@0
|
1881 "subview::rows(): indices out of bounds or incorrectly used"
|
max@0
|
1882 );
|
max@0
|
1883
|
max@0
|
1884 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
1885 const uword base_row1 = aux_row1 + in_row1;
|
max@0
|
1886
|
max@0
|
1887 return subview<eT>(m, base_row1, aux_col1, subview_n_rows, n_cols );
|
max@0
|
1888 }
|
max@0
|
1889
|
max@0
|
1890
|
max@0
|
1891
|
max@0
|
1892 //! creation of subview (submatrix comprised of specified column vectors)
|
max@0
|
1893 template<typename eT>
|
max@0
|
1894 inline
|
max@0
|
1895 subview<eT>
|
max@0
|
1896 subview<eT>::cols(const uword in_col1, const uword in_col2)
|
max@0
|
1897 {
|
max@0
|
1898 arma_extra_debug_sigprint();
|
max@0
|
1899
|
max@0
|
1900 arma_debug_check
|
max@0
|
1901 (
|
max@0
|
1902 (in_col1 > in_col2) || (in_col2 >= n_cols),
|
max@0
|
1903 "subview::cols(): indices out of bounds or incorrectly used"
|
max@0
|
1904 );
|
max@0
|
1905
|
max@0
|
1906 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
1907 const uword base_col1 = aux_col1 + in_col1;
|
max@0
|
1908
|
max@0
|
1909 return subview<eT>(*m_ptr, aux_row1, base_col1, n_rows, subview_n_cols);
|
max@0
|
1910 }
|
max@0
|
1911
|
max@0
|
1912
|
max@0
|
1913
|
max@0
|
1914 //! creation of subview (submatrix comprised of specified column vectors)
|
max@0
|
1915 template<typename eT>
|
max@0
|
1916 inline
|
max@0
|
1917 const subview<eT>
|
max@0
|
1918 subview<eT>::cols(const uword in_col1, const uword in_col2) const
|
max@0
|
1919 {
|
max@0
|
1920 arma_extra_debug_sigprint();
|
max@0
|
1921
|
max@0
|
1922 arma_debug_check
|
max@0
|
1923 (
|
max@0
|
1924 (in_col1 > in_col2) || (in_col2 >= n_cols),
|
max@0
|
1925 "subview::cols(): indices out of bounds or incorrectly used"
|
max@0
|
1926 );
|
max@0
|
1927
|
max@0
|
1928 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
1929 const uword base_col1 = aux_col1 + in_col1;
|
max@0
|
1930
|
max@0
|
1931 return subview<eT>(m, aux_row1, base_col1, n_rows, subview_n_cols);
|
max@0
|
1932 }
|
max@0
|
1933
|
max@0
|
1934
|
max@0
|
1935
|
max@0
|
1936 //! creation of subview (submatrix)
|
max@0
|
1937 template<typename eT>
|
max@0
|
1938 inline
|
max@0
|
1939 subview<eT>
|
max@0
|
1940 subview<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2)
|
max@0
|
1941 {
|
max@0
|
1942 arma_extra_debug_sigprint();
|
max@0
|
1943
|
max@0
|
1944 arma_debug_check
|
max@0
|
1945 (
|
max@0
|
1946 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
|
max@0
|
1947 "subview::submat(): indices out of bounds or incorrectly used"
|
max@0
|
1948 );
|
max@0
|
1949
|
max@0
|
1950 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
1951 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
1952
|
max@0
|
1953 const uword base_row1 = aux_row1 + in_row1;
|
max@0
|
1954 const uword base_col1 = aux_col1 + in_col1;
|
max@0
|
1955
|
max@0
|
1956 return subview<eT>(*m_ptr, base_row1, base_col1, subview_n_rows, subview_n_cols);
|
max@0
|
1957 }
|
max@0
|
1958
|
max@0
|
1959
|
max@0
|
1960
|
max@0
|
1961 //! creation of subview (generic submatrix)
|
max@0
|
1962 template<typename eT>
|
max@0
|
1963 inline
|
max@0
|
1964 const subview<eT>
|
max@0
|
1965 subview<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const
|
max@0
|
1966 {
|
max@0
|
1967 arma_extra_debug_sigprint();
|
max@0
|
1968
|
max@0
|
1969 arma_debug_check
|
max@0
|
1970 (
|
max@0
|
1971 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
|
max@0
|
1972 "subview::submat(): indices out of bounds or incorrectly used"
|
max@0
|
1973 );
|
max@0
|
1974
|
max@0
|
1975 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
1976 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
1977
|
max@0
|
1978 const uword base_row1 = aux_row1 + in_row1;
|
max@0
|
1979 const uword base_col1 = aux_col1 + in_col1;
|
max@0
|
1980
|
max@0
|
1981 return subview<eT>(m, base_row1, base_col1, subview_n_rows, subview_n_cols);
|
max@0
|
1982 }
|
max@0
|
1983
|
max@0
|
1984
|
max@0
|
1985
|
max@0
|
1986 //! creation of subview (submatrix)
|
max@0
|
1987 template<typename eT>
|
max@0
|
1988 inline
|
max@0
|
1989 subview<eT>
|
max@0
|
1990 subview<eT>::submat(const span& row_span, const span& col_span)
|
max@0
|
1991 {
|
max@0
|
1992 arma_extra_debug_sigprint();
|
max@0
|
1993
|
max@0
|
1994 const bool row_all = row_span.whole;
|
max@0
|
1995 const bool col_all = col_span.whole;
|
max@0
|
1996
|
max@0
|
1997 const uword local_n_rows = n_rows;
|
max@0
|
1998 const uword local_n_cols = n_cols;
|
max@0
|
1999
|
max@0
|
2000 const uword in_row1 = row_all ? 0 : row_span.a;
|
max@0
|
2001 const uword in_row2 = row_span.b;
|
max@0
|
2002 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
|
max@0
|
2003
|
max@0
|
2004 const uword in_col1 = col_all ? 0 : col_span.a;
|
max@0
|
2005 const uword in_col2 = col_span.b;
|
max@0
|
2006 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
|
max@0
|
2007
|
max@0
|
2008 arma_debug_check
|
max@0
|
2009 (
|
max@0
|
2010 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
|
max@0
|
2011 ||
|
max@0
|
2012 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
|
max@0
|
2013 ,
|
max@0
|
2014 "subview::submat(): indices out of bounds or incorrectly used"
|
max@0
|
2015 );
|
max@0
|
2016
|
max@0
|
2017 const uword base_row1 = aux_row1 + in_row1;
|
max@0
|
2018 const uword base_col1 = aux_col1 + in_col1;
|
max@0
|
2019
|
max@0
|
2020 return subview<eT>(*m_ptr, base_row1, base_col1, submat_n_rows, submat_n_cols);
|
max@0
|
2021 }
|
max@0
|
2022
|
max@0
|
2023
|
max@0
|
2024
|
max@0
|
2025 //! creation of subview (generic submatrix)
|
max@0
|
2026 template<typename eT>
|
max@0
|
2027 inline
|
max@0
|
2028 const subview<eT>
|
max@0
|
2029 subview<eT>::submat(const span& row_span, const span& col_span) const
|
max@0
|
2030 {
|
max@0
|
2031 arma_extra_debug_sigprint();
|
max@0
|
2032
|
max@0
|
2033 const bool row_all = row_span.whole;
|
max@0
|
2034 const bool col_all = col_span.whole;
|
max@0
|
2035
|
max@0
|
2036 const uword local_n_rows = n_rows;
|
max@0
|
2037 const uword local_n_cols = n_cols;
|
max@0
|
2038
|
max@0
|
2039 const uword in_row1 = row_all ? 0 : row_span.a;
|
max@0
|
2040 const uword in_row2 = row_span.b;
|
max@0
|
2041 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
|
max@0
|
2042
|
max@0
|
2043 const uword in_col1 = col_all ? 0 : col_span.a;
|
max@0
|
2044 const uword in_col2 = col_span.b;
|
max@0
|
2045 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1;
|
max@0
|
2046
|
max@0
|
2047 arma_debug_check
|
max@0
|
2048 (
|
max@0
|
2049 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) )
|
max@0
|
2050 ||
|
max@0
|
2051 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) )
|
max@0
|
2052 ,
|
max@0
|
2053 "subview::submat(): indices out of bounds or incorrectly used"
|
max@0
|
2054 );
|
max@0
|
2055
|
max@0
|
2056 const uword base_row1 = aux_row1 + in_row1;
|
max@0
|
2057 const uword base_col1 = aux_col1 + in_col1;
|
max@0
|
2058
|
max@0
|
2059 return subview<eT>(m, base_row1, base_col1, submat_n_rows, submat_n_cols);
|
max@0
|
2060 }
|
max@0
|
2061
|
max@0
|
2062
|
max@0
|
2063
|
max@0
|
2064 template<typename eT>
|
max@0
|
2065 inline
|
max@0
|
2066 subview<eT>
|
max@0
|
2067 subview<eT>::operator()(const span& row_span, const span& col_span)
|
max@0
|
2068 {
|
max@0
|
2069 arma_extra_debug_sigprint();
|
max@0
|
2070
|
max@0
|
2071 return (*this).submat(row_span, col_span);
|
max@0
|
2072 }
|
max@0
|
2073
|
max@0
|
2074
|
max@0
|
2075
|
max@0
|
2076 template<typename eT>
|
max@0
|
2077 inline
|
max@0
|
2078 const subview<eT>
|
max@0
|
2079 subview<eT>::operator()(const span& row_span, const span& col_span) const
|
max@0
|
2080 {
|
max@0
|
2081 arma_extra_debug_sigprint();
|
max@0
|
2082
|
max@0
|
2083 return (*this).submat(row_span, col_span);
|
max@0
|
2084 }
|
max@0
|
2085
|
max@0
|
2086
|
max@0
|
2087
|
max@0
|
2088 //! creation of diagview (diagonal)
|
max@0
|
2089 template<typename eT>
|
max@0
|
2090 inline
|
max@0
|
2091 diagview<eT>
|
max@0
|
2092 subview<eT>::diag(const sword in_id)
|
max@0
|
2093 {
|
max@0
|
2094 arma_extra_debug_sigprint();
|
max@0
|
2095
|
max@0
|
2096 const uword row_offset = (in_id < 0) ? uword(-in_id) : 0;
|
max@0
|
2097 const uword col_offset = (in_id > 0) ? uword( in_id) : 0;
|
max@0
|
2098
|
max@0
|
2099 arma_debug_check
|
max@0
|
2100 (
|
max@0
|
2101 ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)),
|
max@0
|
2102 "subview::diag(): requested diagonal out of bounds"
|
max@0
|
2103 );
|
max@0
|
2104
|
max@0
|
2105 const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset);
|
max@0
|
2106
|
max@0
|
2107 const uword base_row_offset = aux_row1 + row_offset;
|
max@0
|
2108 const uword base_col_offset = aux_col1 + col_offset;
|
max@0
|
2109
|
max@0
|
2110 return diagview<eT>(*m_ptr, base_row_offset, base_col_offset, len);
|
max@0
|
2111 }
|
max@0
|
2112
|
max@0
|
2113
|
max@0
|
2114
|
max@0
|
2115 //! creation of diagview (diagonal)
|
max@0
|
2116 template<typename eT>
|
max@0
|
2117 inline
|
max@0
|
2118 const diagview<eT>
|
max@0
|
2119 subview<eT>::diag(const sword in_id) const
|
max@0
|
2120 {
|
max@0
|
2121 arma_extra_debug_sigprint();
|
max@0
|
2122
|
max@0
|
2123 const uword row_offset = (in_id < 0) ? -in_id : 0;
|
max@0
|
2124 const uword col_offset = (in_id > 0) ? in_id : 0;
|
max@0
|
2125
|
max@0
|
2126 arma_debug_check
|
max@0
|
2127 (
|
max@0
|
2128 ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)),
|
max@0
|
2129 "subview::diag(): requested diagonal out of bounds"
|
max@0
|
2130 );
|
max@0
|
2131
|
max@0
|
2132 const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset);
|
max@0
|
2133
|
max@0
|
2134 const uword base_row_offset = aux_row1 + row_offset;
|
max@0
|
2135 const uword base_col_offset = aux_col1 + col_offset;
|
max@0
|
2136
|
max@0
|
2137 return diagview<eT>(m, base_row_offset, base_col_offset, len);
|
max@0
|
2138 }
|
max@0
|
2139
|
max@0
|
2140
|
max@0
|
2141
|
max@0
|
2142 template<typename eT>
|
max@0
|
2143 inline
|
max@0
|
2144 void
|
max@0
|
2145 subview<eT>::swap_rows(const uword in_row1, const uword in_row2)
|
max@0
|
2146 {
|
max@0
|
2147 arma_extra_debug_sigprint();
|
max@0
|
2148
|
max@0
|
2149 arma_debug_check
|
max@0
|
2150 (
|
max@0
|
2151 (in_row1 >= n_rows) || (in_row2 >= n_rows),
|
max@0
|
2152 "subview::swap_rows(): out of bounds"
|
max@0
|
2153 );
|
max@0
|
2154
|
max@0
|
2155 eT* mem = (*m_ptr).memptr();
|
max@0
|
2156
|
max@0
|
2157 for(uword col=0; col<n_cols; ++col)
|
max@0
|
2158 {
|
max@0
|
2159 const uword offset = (aux_col1 + col) * m.n_rows;
|
max@0
|
2160 const uword pos1 = aux_row1 + in_row1 + offset;
|
max@0
|
2161 const uword pos2 = aux_row1 + in_row2 + offset;
|
max@0
|
2162
|
max@0
|
2163 const eT tmp = mem[pos1];
|
max@0
|
2164 access::rw(mem[pos1]) = mem[pos2];
|
max@0
|
2165 access::rw(mem[pos2]) = tmp;
|
max@0
|
2166 }
|
max@0
|
2167 }
|
max@0
|
2168
|
max@0
|
2169
|
max@0
|
2170
|
max@0
|
2171 template<typename eT>
|
max@0
|
2172 inline
|
max@0
|
2173 void
|
max@0
|
2174 subview<eT>::swap_cols(const uword in_col1, const uword in_col2)
|
max@0
|
2175 {
|
max@0
|
2176 arma_extra_debug_sigprint();
|
max@0
|
2177
|
max@0
|
2178 arma_debug_check
|
max@0
|
2179 (
|
max@0
|
2180 (in_col1 >= n_cols) || (in_col2 >= n_cols),
|
max@0
|
2181 "subview::swap_cols(): out of bounds"
|
max@0
|
2182 );
|
max@0
|
2183
|
max@0
|
2184 if(n_elem > 0)
|
max@0
|
2185 {
|
max@0
|
2186 eT* ptr1 = colptr(in_col1);
|
max@0
|
2187 eT* ptr2 = colptr(in_col2);
|
max@0
|
2188
|
max@0
|
2189 for(uword row=0; row<n_rows; ++row)
|
max@0
|
2190 {
|
max@0
|
2191 const eT tmp = ptr1[row];
|
max@0
|
2192 ptr1[row] = ptr2[row];
|
max@0
|
2193 ptr2[row] = tmp;
|
max@0
|
2194 }
|
max@0
|
2195 }
|
max@0
|
2196 }
|
max@0
|
2197
|
max@0
|
2198
|
max@0
|
2199
|
max@0
|
2200 // template<typename eT>
|
max@0
|
2201 // inline
|
max@0
|
2202 // subview<eT>::iter::iter(const subview<eT>& S)
|
max@0
|
2203 // : mem (S.m.mem)
|
max@0
|
2204 // , n_rows (S.m.n_rows)
|
max@0
|
2205 // , row_start (S.aux_row1)
|
max@0
|
2206 // , row_end_p1(row_start + S.n_rows)
|
max@0
|
2207 // , row (row_start)
|
max@0
|
2208 // , col (S.aux_col1)
|
max@0
|
2209 // , i (row + col*n_rows)
|
max@0
|
2210 // {
|
max@0
|
2211 // arma_extra_debug_sigprint();
|
max@0
|
2212 // }
|
max@0
|
2213 //
|
max@0
|
2214 //
|
max@0
|
2215 //
|
max@0
|
2216 // template<typename eT>
|
max@0
|
2217 // arma_inline
|
max@0
|
2218 // eT
|
max@0
|
2219 // subview<eT>::iter::operator*() const
|
max@0
|
2220 // {
|
max@0
|
2221 // return mem[i];
|
max@0
|
2222 // }
|
max@0
|
2223 //
|
max@0
|
2224 //
|
max@0
|
2225 //
|
max@0
|
2226 // template<typename eT>
|
max@0
|
2227 // inline
|
max@0
|
2228 // void
|
max@0
|
2229 // subview<eT>::iter::operator++()
|
max@0
|
2230 // {
|
max@0
|
2231 // ++row;
|
max@0
|
2232 //
|
max@0
|
2233 // if(row < row_end_p1)
|
max@0
|
2234 // {
|
max@0
|
2235 // ++i;
|
max@0
|
2236 // }
|
max@0
|
2237 // else
|
max@0
|
2238 // {
|
max@0
|
2239 // row = row_start;
|
max@0
|
2240 // ++col;
|
max@0
|
2241 //
|
max@0
|
2242 // i = row + col*n_rows;
|
max@0
|
2243 // }
|
max@0
|
2244 // }
|
max@0
|
2245 //
|
max@0
|
2246 //
|
max@0
|
2247 //
|
max@0
|
2248 // template<typename eT>
|
max@0
|
2249 // inline
|
max@0
|
2250 // void
|
max@0
|
2251 // subview<eT>::iter::operator++(int)
|
max@0
|
2252 // {
|
max@0
|
2253 // operator++();
|
max@0
|
2254 // }
|
max@0
|
2255
|
max@0
|
2256
|
max@0
|
2257
|
max@0
|
2258 //
|
max@0
|
2259 //
|
max@0
|
2260 //
|
max@0
|
2261
|
max@0
|
2262
|
max@0
|
2263
|
max@0
|
2264 template<typename eT>
|
max@0
|
2265 inline
|
max@0
|
2266 subview_col<eT>::subview_col(const Mat<eT>& in_m, const uword in_col)
|
max@0
|
2267 : subview<eT>(in_m, 0, in_col, in_m.n_rows, 1)
|
max@0
|
2268 {
|
max@0
|
2269 arma_extra_debug_sigprint();
|
max@0
|
2270 }
|
max@0
|
2271
|
max@0
|
2272
|
max@0
|
2273
|
max@0
|
2274 template<typename eT>
|
max@0
|
2275 inline
|
max@0
|
2276 subview_col<eT>::subview_col(Mat<eT>& in_m, const uword in_col)
|
max@0
|
2277 : subview<eT>(in_m, 0, in_col, in_m.n_rows, 1)
|
max@0
|
2278 {
|
max@0
|
2279 arma_extra_debug_sigprint();
|
max@0
|
2280 }
|
max@0
|
2281
|
max@0
|
2282
|
max@0
|
2283
|
max@0
|
2284 template<typename eT>
|
max@0
|
2285 inline
|
max@0
|
2286 subview_col<eT>::subview_col(const Mat<eT>& in_m, const uword in_col, const uword in_row1, const uword in_n_rows)
|
max@0
|
2287 : subview<eT>(in_m, in_row1, in_col, in_n_rows, 1)
|
max@0
|
2288 {
|
max@0
|
2289 arma_extra_debug_sigprint();
|
max@0
|
2290 }
|
max@0
|
2291
|
max@0
|
2292
|
max@0
|
2293
|
max@0
|
2294 template<typename eT>
|
max@0
|
2295 inline
|
max@0
|
2296 subview_col<eT>::subview_col(Mat<eT>& in_m, const uword in_col, const uword in_row1, const uword in_n_rows)
|
max@0
|
2297 : subview<eT>(in_m, in_row1, in_col, in_n_rows, 1)
|
max@0
|
2298 {
|
max@0
|
2299 arma_extra_debug_sigprint();
|
max@0
|
2300 }
|
max@0
|
2301
|
max@0
|
2302
|
max@0
|
2303
|
max@0
|
2304 template<typename eT>
|
max@0
|
2305 inline
|
max@0
|
2306 void
|
max@0
|
2307 subview_col<eT>::operator=(const subview<eT>& X)
|
max@0
|
2308 {
|
max@0
|
2309 arma_extra_debug_sigprint();
|
max@0
|
2310
|
max@0
|
2311 subview<eT>::operator=(X);
|
max@0
|
2312 arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
|
max@0
|
2313 }
|
max@0
|
2314
|
max@0
|
2315
|
max@0
|
2316
|
max@0
|
2317 template<typename eT>
|
max@0
|
2318 inline
|
max@0
|
2319 void
|
max@0
|
2320 subview_col<eT>::operator=(const subview_col<eT>& X)
|
max@0
|
2321 {
|
max@0
|
2322 arma_extra_debug_sigprint();
|
max@0
|
2323
|
max@0
|
2324 subview<eT>::operator=(X); // interprets 'subview_col' as 'subview'
|
max@0
|
2325 arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
|
max@0
|
2326 }
|
max@0
|
2327
|
max@0
|
2328
|
max@0
|
2329
|
max@0
|
2330 template<typename eT>
|
max@0
|
2331 template<typename T1>
|
max@0
|
2332 inline
|
max@0
|
2333 void
|
max@0
|
2334 subview_col<eT>::operator=(const Base<eT,T1>& X)
|
max@0
|
2335 {
|
max@0
|
2336 arma_extra_debug_sigprint();
|
max@0
|
2337
|
max@0
|
2338 subview<eT>::operator=(X);
|
max@0
|
2339 arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
|
max@0
|
2340 }
|
max@0
|
2341
|
max@0
|
2342
|
max@0
|
2343
|
max@0
|
2344 template<typename eT>
|
max@0
|
2345 inline
|
max@0
|
2346 subview_col<eT>
|
max@0
|
2347 subview_col<eT>::rows(const uword in_row1, const uword in_row2)
|
max@0
|
2348 {
|
max@0
|
2349 arma_extra_debug_sigprint();
|
max@0
|
2350
|
max@0
|
2351 arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview<eT>::n_rows) ), "subview_col::rows(): indices out of bounds or incorrectly used");
|
max@0
|
2352
|
max@0
|
2353 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
2354
|
max@0
|
2355 const uword base_row1 = this->aux_row1 + in_row1;
|
max@0
|
2356
|
max@0
|
2357 return subview_col<eT>(*(this->m_ptr), this->aux_col1, base_row1, subview_n_rows);
|
max@0
|
2358 }
|
max@0
|
2359
|
max@0
|
2360
|
max@0
|
2361
|
max@0
|
2362 template<typename eT>
|
max@0
|
2363 inline
|
max@0
|
2364 const subview_col<eT>
|
max@0
|
2365 subview_col<eT>::rows(const uword in_row1, const uword in_row2) const
|
max@0
|
2366 {
|
max@0
|
2367 arma_extra_debug_sigprint();
|
max@0
|
2368
|
max@0
|
2369 arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview<eT>::n_rows) ), "subview_col::rows(): indices out of bounds or incorrectly used");
|
max@0
|
2370
|
max@0
|
2371 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
2372
|
max@0
|
2373 const uword base_row1 = this->aux_row1 + in_row1;
|
max@0
|
2374
|
max@0
|
2375 return subview_col<eT>(this->m, this->aux_col1, base_row1, subview_n_rows);
|
max@0
|
2376 }
|
max@0
|
2377
|
max@0
|
2378
|
max@0
|
2379
|
max@0
|
2380 template<typename eT>
|
max@0
|
2381 inline
|
max@0
|
2382 subview_col<eT>
|
max@0
|
2383 subview_col<eT>::subvec(const uword in_row1, const uword in_row2)
|
max@0
|
2384 {
|
max@0
|
2385 arma_extra_debug_sigprint();
|
max@0
|
2386
|
max@0
|
2387 arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview<eT>::n_rows) ), "subview_col::subvec(): indices out of bounds or incorrectly used");
|
max@0
|
2388
|
max@0
|
2389 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
2390
|
max@0
|
2391 const uword base_row1 = this->aux_row1 + in_row1;
|
max@0
|
2392
|
max@0
|
2393 return subview_col<eT>(*(this->m_ptr), this->aux_col1, base_row1, subview_n_rows);
|
max@0
|
2394 }
|
max@0
|
2395
|
max@0
|
2396
|
max@0
|
2397
|
max@0
|
2398 template<typename eT>
|
max@0
|
2399 inline
|
max@0
|
2400 const subview_col<eT>
|
max@0
|
2401 subview_col<eT>::subvec(const uword in_row1, const uword in_row2) const
|
max@0
|
2402 {
|
max@0
|
2403 arma_extra_debug_sigprint();
|
max@0
|
2404
|
max@0
|
2405 arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview<eT>::n_rows) ), "subview_col::subvec(): indices out of bounds or incorrectly used");
|
max@0
|
2406
|
max@0
|
2407 const uword subview_n_rows = in_row2 - in_row1 + 1;
|
max@0
|
2408
|
max@0
|
2409 const uword base_row1 = this->aux_row1 + in_row1;
|
max@0
|
2410
|
max@0
|
2411 return subview_col<eT>(this->m, this->aux_col1, base_row1, subview_n_rows);
|
max@0
|
2412 }
|
max@0
|
2413
|
max@0
|
2414
|
max@0
|
2415
|
max@0
|
2416 //
|
max@0
|
2417 //
|
max@0
|
2418 //
|
max@0
|
2419
|
max@0
|
2420
|
max@0
|
2421
|
max@0
|
2422 template<typename eT>
|
max@0
|
2423 inline
|
max@0
|
2424 subview_row<eT>::subview_row(const Mat<eT>& in_m, const uword in_row)
|
max@0
|
2425 : subview<eT>(in_m, in_row, 0, 1, in_m.n_cols)
|
max@0
|
2426 {
|
max@0
|
2427 arma_extra_debug_sigprint();
|
max@0
|
2428 }
|
max@0
|
2429
|
max@0
|
2430
|
max@0
|
2431
|
max@0
|
2432 template<typename eT>
|
max@0
|
2433 inline
|
max@0
|
2434 subview_row<eT>::subview_row(Mat<eT>& in_m, const uword in_row)
|
max@0
|
2435 : subview<eT>(in_m, in_row, 0, 1, in_m.n_cols)
|
max@0
|
2436 {
|
max@0
|
2437 arma_extra_debug_sigprint();
|
max@0
|
2438 }
|
max@0
|
2439
|
max@0
|
2440
|
max@0
|
2441
|
max@0
|
2442 template<typename eT>
|
max@0
|
2443 inline
|
max@0
|
2444 subview_row<eT>::subview_row(const Mat<eT>& in_m, const uword in_row, const uword in_col1, const uword in_n_cols)
|
max@0
|
2445 : subview<eT>(in_m, in_row, in_col1, 1, in_n_cols)
|
max@0
|
2446 {
|
max@0
|
2447 arma_extra_debug_sigprint();
|
max@0
|
2448 }
|
max@0
|
2449
|
max@0
|
2450
|
max@0
|
2451
|
max@0
|
2452 template<typename eT>
|
max@0
|
2453 inline
|
max@0
|
2454 subview_row<eT>::subview_row(Mat<eT>& in_m, const uword in_row, const uword in_col1, const uword in_n_cols)
|
max@0
|
2455 : subview<eT>(in_m, in_row, in_col1, 1, in_n_cols)
|
max@0
|
2456 {
|
max@0
|
2457 arma_extra_debug_sigprint();
|
max@0
|
2458 }
|
max@0
|
2459
|
max@0
|
2460
|
max@0
|
2461
|
max@0
|
2462 template<typename eT>
|
max@0
|
2463 inline
|
max@0
|
2464 void
|
max@0
|
2465 subview_row<eT>::operator=(const subview<eT>& X)
|
max@0
|
2466 {
|
max@0
|
2467 arma_extra_debug_sigprint();
|
max@0
|
2468
|
max@0
|
2469 subview<eT>::operator=(X);
|
max@0
|
2470 arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
|
max@0
|
2471 }
|
max@0
|
2472
|
max@0
|
2473
|
max@0
|
2474
|
max@0
|
2475 template<typename eT>
|
max@0
|
2476 inline
|
max@0
|
2477 void
|
max@0
|
2478 subview_row<eT>::operator=(const subview_row<eT>& X)
|
max@0
|
2479 {
|
max@0
|
2480 arma_extra_debug_sigprint();
|
max@0
|
2481
|
max@0
|
2482 subview<eT>::operator=(X); // interprets 'subview_row' as 'subview'
|
max@0
|
2483 arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
|
max@0
|
2484 }
|
max@0
|
2485
|
max@0
|
2486
|
max@0
|
2487
|
max@0
|
2488 template<typename eT>
|
max@0
|
2489 template<typename T1>
|
max@0
|
2490 inline
|
max@0
|
2491 void
|
max@0
|
2492 subview_row<eT>::operator=(const Base<eT,T1>& X)
|
max@0
|
2493 {
|
max@0
|
2494 arma_extra_debug_sigprint();
|
max@0
|
2495
|
max@0
|
2496 subview<eT>::operator=(X);
|
max@0
|
2497 arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
|
max@0
|
2498 }
|
max@0
|
2499
|
max@0
|
2500
|
max@0
|
2501
|
max@0
|
2502 template<typename eT>
|
max@0
|
2503 inline
|
max@0
|
2504 subview_row<eT>
|
max@0
|
2505 subview_row<eT>::cols(const uword in_col1, const uword in_col2)
|
max@0
|
2506 {
|
max@0
|
2507 arma_extra_debug_sigprint();
|
max@0
|
2508
|
max@0
|
2509 arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview<eT>::n_cols) ), "subview_row::cols(): indices out of bounds or incorrectly used" );
|
max@0
|
2510
|
max@0
|
2511 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
2512
|
max@0
|
2513 const uword base_col1 = this->aux_col1 + in_col1;
|
max@0
|
2514
|
max@0
|
2515 return subview_row<eT>(*(this->m_ptr), this->aux_row1, base_col1, subview_n_cols);
|
max@0
|
2516 }
|
max@0
|
2517
|
max@0
|
2518
|
max@0
|
2519
|
max@0
|
2520 template<typename eT>
|
max@0
|
2521 inline
|
max@0
|
2522 const subview_row<eT>
|
max@0
|
2523 subview_row<eT>::cols(const uword in_col1, const uword in_col2) const
|
max@0
|
2524 {
|
max@0
|
2525 arma_extra_debug_sigprint();
|
max@0
|
2526
|
max@0
|
2527 arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview<eT>::n_cols) ), "subview_row::cols(): indices out of bounds or incorrectly used");
|
max@0
|
2528
|
max@0
|
2529 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
2530
|
max@0
|
2531 const uword base_col1 = this->aux_col1 + in_col1;
|
max@0
|
2532
|
max@0
|
2533 return subview_row<eT>(this->m, this->aux_row1, base_col1, subview_n_cols);
|
max@0
|
2534 }
|
max@0
|
2535
|
max@0
|
2536
|
max@0
|
2537
|
max@0
|
2538 template<typename eT>
|
max@0
|
2539 inline
|
max@0
|
2540 subview_row<eT>
|
max@0
|
2541 subview_row<eT>::subvec(const uword in_col1, const uword in_col2)
|
max@0
|
2542 {
|
max@0
|
2543 arma_extra_debug_sigprint();
|
max@0
|
2544
|
max@0
|
2545 arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview<eT>::n_cols) ), "subview_row::subvec(): indices out of bounds or incorrectly used");
|
max@0
|
2546
|
max@0
|
2547 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
2548
|
max@0
|
2549 const uword base_col1 = this->aux_col1 + in_col1;
|
max@0
|
2550
|
max@0
|
2551 return subview_row<eT>(*(this->m_ptr), this->aux_row1, base_col1, subview_n_cols);
|
max@0
|
2552 }
|
max@0
|
2553
|
max@0
|
2554
|
max@0
|
2555
|
max@0
|
2556 template<typename eT>
|
max@0
|
2557 inline
|
max@0
|
2558 const subview_row<eT>
|
max@0
|
2559 subview_row<eT>::subvec(const uword in_col1, const uword in_col2) const
|
max@0
|
2560 {
|
max@0
|
2561 arma_extra_debug_sigprint();
|
max@0
|
2562
|
max@0
|
2563 arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview<eT>::n_cols) ), "subview_row::subvec(): indices out of bounds or incorrectly used");
|
max@0
|
2564
|
max@0
|
2565 const uword subview_n_cols = in_col2 - in_col1 + 1;
|
max@0
|
2566
|
max@0
|
2567 const uword base_col1 = this->aux_col1 + in_col1;
|
max@0
|
2568
|
max@0
|
2569 return subview_row<eT>(this->m, this->aux_row1, base_col1, subview_n_cols);
|
max@0
|
2570 }
|
max@0
|
2571
|
max@0
|
2572
|
max@0
|
2573
|
max@0
|
2574 //! @}
|