comparison armadillo-2.4.4/include/armadillo_bits/subview_meat.hpp @ 0:8b6102e2a9b0

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