comparison armadillo-3.900.4/include/armadillo_bits/Col_meat.hpp @ 49:1ec0e2823891

Switch to using subrepo copies of qm-dsp, nnls-chroma, vamp-plugin-sdk; update Armadillo version; assume build without external BLAS/LAPACK
author Chris Cannam
date Thu, 13 Jun 2013 10:25:24 +0100
parents
children
comparison
equal deleted inserted replaced
48:69251e11a913 49:1ec0e2823891
1 // Copyright (C) 2008-2013 NICTA (www.nicta.com.au)
2 // Copyright (C) 2008-2013 Conrad Sanderson
3 //
4 // This Source Code Form is subject to the terms of the Mozilla Public
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8
9 //! \addtogroup Col
10 //! @{
11
12
13 //! construct an empty column vector
14 template<typename eT>
15 inline
16 Col<eT>::Col()
17 : Mat<eT>(arma_vec_indicator(), 1)
18 {
19 arma_extra_debug_sigprint();
20 }
21
22
23
24 template<typename eT>
25 inline
26 Col<eT>::Col(const Col<eT>& X)
27 : Mat<eT>(arma_vec_indicator(), X.n_elem, 1, 1)
28 {
29 arma_extra_debug_sigprint();
30
31 arrayops::copy((*this).memptr(), X.memptr(), X.n_elem);
32 }
33
34
35
36 //! construct a column vector with the specified number of n_elem
37 template<typename eT>
38 inline
39 Col<eT>::Col(const uword in_n_elem)
40 : Mat<eT>(arma_vec_indicator(), in_n_elem, 1, 1)
41 {
42 arma_extra_debug_sigprint();
43 }
44
45
46
47 template<typename eT>
48 inline
49 Col<eT>::Col(const uword in_n_rows, const uword in_n_cols)
50 : Mat<eT>(arma_vec_indicator(), 0, 0, 1)
51 {
52 arma_extra_debug_sigprint();
53
54 Mat<eT>::init_warm(in_n_rows, in_n_cols);
55 }
56
57
58
59 //! construct a column vector from specified text
60 template<typename eT>
61 inline
62 Col<eT>::Col(const char* text)
63 {
64 arma_extra_debug_sigprint();
65
66 access::rw(Mat<eT>::vec_state) = 2;
67
68 Mat<eT>::operator=(text);
69
70 std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
71
72 access::rw(Mat<eT>::vec_state) = 1;
73 }
74
75
76
77 //! construct a column vector from specified text
78 template<typename eT>
79 inline
80 const Col<eT>&
81 Col<eT>::operator=(const char* text)
82 {
83 arma_extra_debug_sigprint();
84
85 access::rw(Mat<eT>::vec_state) = 2;
86
87 Mat<eT>::operator=(text);
88
89 std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
90
91 access::rw(Mat<eT>::vec_state) = 1;
92
93 return *this;
94 }
95
96
97
98 //! construct a column vector from specified text
99 template<typename eT>
100 inline
101 Col<eT>::Col(const std::string& text)
102 {
103 arma_extra_debug_sigprint();
104
105 access::rw(Mat<eT>::vec_state) = 2;
106
107 Mat<eT>::operator=(text);
108
109 std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
110
111 access::rw(Mat<eT>::vec_state) = 1;
112 }
113
114
115
116 //! construct a column vector from specified text
117 template<typename eT>
118 inline
119 const Col<eT>&
120 Col<eT>::operator=(const std::string& text)
121 {
122 arma_extra_debug_sigprint();
123
124 access::rw(Mat<eT>::vec_state) = 2;
125
126 Mat<eT>::operator=(text);
127
128 std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
129
130 access::rw(Mat<eT>::vec_state) = 1;
131
132 return *this;
133 }
134
135
136
137 //! create a column vector from std::vector
138 template<typename eT>
139 inline
140 Col<eT>::Col(const std::vector<eT>& x)
141 : Mat<eT>(arma_vec_indicator(), uword(x.size()), 1, 1)
142 {
143 arma_extra_debug_sigprint_this(this);
144
145 if(x.size() > 0)
146 {
147 arrayops::copy( Mat<eT>::memptr(), &(x[0]), uword(x.size()) );
148 }
149 }
150
151
152
153 //! create a column vector from std::vector
154 template<typename eT>
155 inline
156 const Col<eT>&
157 Col<eT>::operator=(const std::vector<eT>& x)
158 {
159 arma_extra_debug_sigprint();
160
161 Mat<eT>::init_warm(uword(x.size()), 1);
162
163 if(x.size() > 0)
164 {
165 arrayops::copy( Mat<eT>::memptr(), &(x[0]), uword(x.size()) );
166 }
167
168 return *this;
169 }
170
171
172
173 #if defined(ARMA_USE_CXX11)
174
175 template<typename eT>
176 inline
177 Col<eT>::Col(const std::initializer_list<eT>& list)
178 {
179 arma_extra_debug_sigprint();
180
181 access::rw(Mat<eT>::vec_state) = 2;
182
183 Mat<eT>::operator=(list);
184
185 std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
186
187 access::rw(Mat<eT>::vec_state) = 1;
188 }
189
190
191
192 template<typename eT>
193 inline
194 const Col<eT>&
195 Col<eT>::operator=(const std::initializer_list<eT>& list)
196 {
197 arma_extra_debug_sigprint();
198
199 access::rw(Mat<eT>::vec_state) = 2;
200
201 Mat<eT>::operator=(list);
202
203 std::swap( access::rw(Mat<eT>::n_rows), access::rw(Mat<eT>::n_cols) );
204
205 access::rw(Mat<eT>::vec_state) = 1;
206
207 return *this;
208 }
209
210 #endif
211
212
213
214 template<typename eT>
215 inline
216 Col<eT>::Col(const SpCol<eT>& X)
217 : Mat<eT>(arma_vec_indicator(), X.n_elem, 1, 1)
218 {
219 arma_extra_debug_sigprint_this(this);
220
221 arrayops::inplace_set(Mat<eT>::memptr(), eT(0), X.n_elem);
222
223 for(typename SpCol<eT>::const_iterator it = X.begin(); it != X.end(); ++it)
224 at(it.row()) = (*it);
225 }
226
227
228
229 template<typename eT>
230 inline
231 const Col<eT>&
232 Col<eT>::operator=(const eT val)
233 {
234 arma_extra_debug_sigprint();
235
236 Mat<eT>::operator=(val);
237
238 return *this;
239 }
240
241
242
243 template<typename eT>
244 template<typename T1>
245 inline
246 Col<eT>::Col(const Base<eT,T1>& X)
247 : Mat<eT>(arma_vec_indicator(), 1)
248 {
249 arma_extra_debug_sigprint();
250
251 Mat<eT>::operator=(X.get_ref());
252 }
253
254
255
256 template<typename eT>
257 template<typename T1>
258 inline
259 const Col<eT>&
260 Col<eT>::operator=(const Base<eT,T1>& X)
261 {
262 arma_extra_debug_sigprint();
263
264 Mat<eT>::operator=(X.get_ref());
265
266 return *this;
267 }
268
269
270
271 //! construct a column vector from a given auxiliary array of eTs
272 template<typename eT>
273 inline
274 Col<eT>::Col(eT* aux_mem, const uword aux_length, const bool copy_aux_mem, const bool strict)
275 : Mat<eT>(aux_mem, aux_length, 1, copy_aux_mem, strict)
276 {
277 arma_extra_debug_sigprint();
278
279 access::rw(Mat<eT>::vec_state) = 1;
280 }
281
282
283
284 //! construct a column vector from a given auxiliary array of eTs
285 template<typename eT>
286 inline
287 Col<eT>::Col(const eT* aux_mem, const uword aux_length)
288 : Mat<eT>(aux_mem, aux_length, 1)
289 {
290 arma_extra_debug_sigprint();
291
292 access::rw(Mat<eT>::vec_state) = 1;
293 }
294
295
296
297 template<typename eT>
298 template<typename T1, typename T2>
299 inline
300 Col<eT>::Col
301 (
302 const Base<typename Col<eT>::pod_type, T1>& A,
303 const Base<typename Col<eT>::pod_type, T2>& B
304 )
305 {
306 arma_extra_debug_sigprint();
307
308 access::rw(Mat<eT>::vec_state) = 1;
309
310 Mat<eT>::init(A,B);
311 }
312
313
314
315 template<typename eT>
316 template<typename T1>
317 inline
318 Col<eT>::Col(const BaseCube<eT,T1>& X)
319 {
320 arma_extra_debug_sigprint();
321
322 access::rw(Mat<eT>::vec_state) = 1;
323
324 Mat<eT>::operator=(X);
325 }
326
327
328
329 template<typename eT>
330 template<typename T1>
331 inline
332 const Col<eT>&
333 Col<eT>::operator=(const BaseCube<eT,T1>& X)
334 {
335 arma_extra_debug_sigprint();
336
337 Mat<eT>::operator=(X);
338
339 return *this;
340 }
341
342
343
344 template<typename eT>
345 inline
346 Col<eT>::Col(const subview_cube<eT>& X)
347 {
348 arma_extra_debug_sigprint();
349
350 access::rw(Mat<eT>::vec_state) = 1;
351
352 Mat<eT>::operator=(X);
353 }
354
355
356
357 template<typename eT>
358 inline
359 const Col<eT>&
360 Col<eT>::operator=(const subview_cube<eT>& X)
361 {
362 arma_extra_debug_sigprint();
363
364 Mat<eT>::operator=(X);
365
366 return *this;
367 }
368
369
370
371 template<typename eT>
372 inline
373 mat_injector< Col<eT> >
374 Col<eT>::operator<<(const eT val)
375 {
376 return mat_injector< Col<eT> >(*this, val);
377 }
378
379
380
381 template<typename eT>
382 arma_inline
383 const Op<Col<eT>,op_htrans>
384 Col<eT>::t() const
385 {
386 return Op<Col<eT>,op_htrans>(*this);
387 }
388
389
390
391 template<typename eT>
392 arma_inline
393 const Op<Col<eT>,op_htrans>
394 Col<eT>::ht() const
395 {
396 return Op<Col<eT>,op_htrans>(*this);
397 }
398
399
400
401 template<typename eT>
402 arma_inline
403 const Op<Col<eT>,op_strans>
404 Col<eT>::st() const
405 {
406 return Op<Col<eT>,op_strans>(*this);
407 }
408
409
410
411 template<typename eT>
412 arma_inline
413 eT&
414 Col<eT>::row(const uword row_num)
415 {
416 arma_debug_check( (row_num >= Mat<eT>::n_rows), "Col::row(): index out of bounds" );
417
418 return access::rw(Mat<eT>::mem[row_num]);
419 }
420
421
422
423 template<typename eT>
424 arma_inline
425 eT
426 Col<eT>::row(const uword row_num) const
427 {
428 arma_debug_check( (row_num >= Mat<eT>::n_rows), "Col::row(): index out of bounds" );
429
430 return Mat<eT>::mem[row_num];
431 }
432
433
434
435 template<typename eT>
436 arma_inline
437 subview_col<eT>
438 Col<eT>::rows(const uword in_row1, const uword in_row2)
439 {
440 arma_extra_debug_sigprint();
441
442 arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat<eT>::n_rows) ), "Col::rows(): indices out of bounds or incorrectly used");
443
444 const uword subview_n_rows = in_row2 - in_row1 + 1;
445
446 return subview_col<eT>(*this, 0, in_row1, subview_n_rows);
447 }
448
449
450
451 template<typename eT>
452 arma_inline
453 const subview_col<eT>
454 Col<eT>::rows(const uword in_row1, const uword in_row2) const
455 {
456 arma_extra_debug_sigprint();
457
458 arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat<eT>::n_rows) ), "Col::rows(): indices out of bounds or incorrectly used");
459
460 const uword subview_n_rows = in_row2 - in_row1 + 1;
461
462 return subview_col<eT>(*this, 0, in_row1, subview_n_rows);
463 }
464
465
466
467 template<typename eT>
468 arma_inline
469 subview_col<eT>
470 Col<eT>::subvec(const uword in_row1, const uword in_row2)
471 {
472 arma_extra_debug_sigprint();
473
474 arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat<eT>::n_rows) ), "Col::subvec(): indices out of bounds or incorrectly used");
475
476 const uword subview_n_rows = in_row2 - in_row1 + 1;
477
478 return subview_col<eT>(*this, 0, in_row1, subview_n_rows);
479 }
480
481
482
483 template<typename eT>
484 arma_inline
485 const subview_col<eT>
486 Col<eT>::subvec(const uword in_row1, const uword in_row2) const
487 {
488 arma_extra_debug_sigprint();
489
490 arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= Mat<eT>::n_rows) ), "Col::subvec(): indices out of bounds or incorrectly used");
491
492 const uword subview_n_rows = in_row2 - in_row1 + 1;
493
494 return subview_col<eT>(*this, 0, in_row1, subview_n_rows);
495 }
496
497
498
499 template<typename eT>
500 arma_inline
501 subview_col<eT>
502 Col<eT>::subvec(const span& row_span)
503 {
504 arma_extra_debug_sigprint();
505
506 const bool row_all = row_span.whole;
507
508 const uword local_n_rows = Mat<eT>::n_rows;
509
510 const uword in_row1 = row_all ? 0 : row_span.a;
511 const uword in_row2 = row_span.b;
512 const uword subvec_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
513
514 arma_debug_check( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ), "Col::subvec(): indices out of bounds or incorrectly used");
515
516 return subview_col<eT>(*this, 0, in_row1, subvec_n_rows);
517 }
518
519
520
521 template<typename eT>
522 arma_inline
523 const subview_col<eT>
524 Col<eT>::subvec(const span& row_span) const
525 {
526 arma_extra_debug_sigprint();
527
528 const bool row_all = row_span.whole;
529
530 const uword local_n_rows = Mat<eT>::n_rows;
531
532 const uword in_row1 = row_all ? 0 : row_span.a;
533 const uword in_row2 = row_span.b;
534 const uword subvec_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1;
535
536 arma_debug_check( ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ), "Col::subvec(): indices out of bounds or incorrectly used");
537
538 return subview_col<eT>(*this, 0, in_row1, subvec_n_rows);
539 }
540
541
542
543 template<typename eT>
544 arma_inline
545 subview_col<eT>
546 Col<eT>::operator()(const span& row_span)
547 {
548 arma_extra_debug_sigprint();
549
550 return subvec(row_span);
551 }
552
553
554
555 template<typename eT>
556 arma_inline
557 const subview_col<eT>
558 Col<eT>::operator()(const span& row_span) const
559 {
560 arma_extra_debug_sigprint();
561
562 return subvec(row_span);
563 }
564
565
566
567 //! remove specified row
568 template<typename eT>
569 inline
570 void
571 Col<eT>::shed_row(const uword row_num)
572 {
573 arma_extra_debug_sigprint();
574
575 arma_debug_check( row_num >= Mat<eT>::n_rows, "Col::shed_row(): index out of bounds");
576
577 shed_rows(row_num, row_num);
578 }
579
580
581
582 //! remove specified rows
583 template<typename eT>
584 inline
585 void
586 Col<eT>::shed_rows(const uword in_row1, const uword in_row2)
587 {
588 arma_extra_debug_sigprint();
589
590 arma_debug_check
591 (
592 (in_row1 > in_row2) || (in_row2 >= Mat<eT>::n_rows),
593 "Col::shed_rows(): indices out of bounds or incorrectly used"
594 );
595
596 const uword n_keep_front = in_row1;
597 const uword n_keep_back = Mat<eT>::n_rows - (in_row2 + 1);
598
599 Col<eT> X(n_keep_front + n_keep_back);
600
601 eT* X_mem = X.memptr();
602 const eT* t_mem = (*this).memptr();
603
604 if(n_keep_front > 0)
605 {
606 arrayops::copy( X_mem, t_mem, n_keep_front );
607 }
608
609 if(n_keep_back > 0)
610 {
611 arrayops::copy( &(X_mem[n_keep_front]), &(t_mem[in_row2+1]), n_keep_back);
612 }
613
614 Mat<eT>::steal_mem(X);
615 }
616
617
618
619 //! insert N rows at the specified row position,
620 //! optionally setting the elements of the inserted rows to zero
621 template<typename eT>
622 inline
623 void
624 Col<eT>::insert_rows(const uword row_num, const uword N, const bool set_to_zero)
625 {
626 arma_extra_debug_sigprint();
627
628 const uword t_n_rows = Mat<eT>::n_rows;
629
630 const uword A_n_rows = row_num;
631 const uword B_n_rows = t_n_rows - row_num;
632
633 // insertion at row_num == n_rows is in effect an append operation
634 arma_debug_check( (row_num > t_n_rows), "Col::insert_rows(): index out of bounds");
635
636 if(N > 0)
637 {
638 Col<eT> out(t_n_rows + N);
639
640 eT* out_mem = out.memptr();
641 const eT* t_mem = (*this).memptr();
642
643 if(A_n_rows > 0)
644 {
645 arrayops::copy( out_mem, t_mem, A_n_rows );
646 }
647
648 if(B_n_rows > 0)
649 {
650 arrayops::copy( &(out_mem[row_num + N]), &(t_mem[row_num]), B_n_rows );
651 }
652
653 if(set_to_zero == true)
654 {
655 arrayops::inplace_set( &(out_mem[row_num]), eT(0), N );
656 }
657
658 Mat<eT>::steal_mem(out);
659 }
660 }
661
662
663
664 //! insert the given object at the specified row position;
665 //! the given object must have one column
666 template<typename eT>
667 template<typename T1>
668 inline
669 void
670 Col<eT>::insert_rows(const uword row_num, const Base<eT,T1>& X)
671 {
672 arma_extra_debug_sigprint();
673
674 Mat<eT>::insert_rows(row_num, X);
675 }
676
677
678
679 template<typename eT>
680 arma_inline
681 arma_warn_unused
682 eT&
683 Col<eT>::at(const uword i)
684 {
685 return access::rw(Mat<eT>::mem[i]);
686 }
687
688
689
690 template<typename eT>
691 arma_inline
692 arma_warn_unused
693 const eT&
694 Col<eT>::at(const uword i) const
695 {
696 return Mat<eT>::mem[i];
697 }
698
699
700
701 template<typename eT>
702 arma_inline
703 arma_warn_unused
704 eT&
705 Col<eT>::at(const uword in_row, const uword)
706 {
707 return access::rw( Mat<eT>::mem[in_row] );
708 }
709
710
711
712 template<typename eT>
713 arma_inline
714 arma_warn_unused
715 const eT&
716 Col<eT>::at(const uword in_row, const uword) const
717 {
718 return Mat<eT>::mem[in_row];
719 }
720
721
722
723 template<typename eT>
724 inline
725 typename Col<eT>::row_iterator
726 Col<eT>::begin_row(const uword row_num)
727 {
728 arma_extra_debug_sigprint();
729
730 arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out of bounds");
731
732 return Mat<eT>::memptr() + row_num;
733 }
734
735
736
737 template<typename eT>
738 inline
739 typename Col<eT>::const_row_iterator
740 Col<eT>::begin_row(const uword row_num) const
741 {
742 arma_extra_debug_sigprint();
743
744 arma_debug_check( (row_num >= Mat<eT>::n_rows), "begin_row(): index out of bounds");
745
746 return Mat<eT>::memptr() + row_num;
747 }
748
749
750
751 template<typename eT>
752 inline
753 typename Col<eT>::row_iterator
754 Col<eT>::end_row(const uword row_num)
755 {
756 arma_extra_debug_sigprint();
757
758 arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of bounds");
759
760 return Mat<eT>::memptr() + row_num + 1;
761 }
762
763
764
765 template<typename eT>
766 inline
767 typename Col<eT>::const_row_iterator
768 Col<eT>::end_row(const uword row_num) const
769 {
770 arma_extra_debug_sigprint();
771
772 arma_debug_check( (row_num >= Mat<eT>::n_rows), "end_row(): index out of bounds");
773
774 return Mat<eT>::memptr() + row_num + 1;
775 }
776
777
778
779 template<typename eT>
780 template<uword fixed_n_elem>
781 arma_inline
782 void
783 Col<eT>::fixed<fixed_n_elem>::change_to_row()
784 {
785 arma_extra_debug_sigprint();
786
787 access::rw(Mat<eT>::n_cols) = fixed_n_elem;
788 access::rw(Mat<eT>::n_rows) = 1;
789 }
790
791
792
793 template<typename eT>
794 template<uword fixed_n_elem>
795 arma_inline
796 Col<eT>::fixed<fixed_n_elem>::fixed()
797 : Col<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
798 {
799 arma_extra_debug_sigprint_this(this);
800 }
801
802
803
804 template<typename eT>
805 template<uword fixed_n_elem>
806 arma_inline
807 Col<eT>::fixed<fixed_n_elem>::fixed(const fixed<fixed_n_elem>& X)
808 : Col<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
809 {
810 arma_extra_debug_sigprint_this(this);
811
812 eT* dest = (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
813
814 arrayops::copy( dest, X.mem, fixed_n_elem );
815 }
816
817
818
819 template<typename eT>
820 template<uword fixed_n_elem>
821 inline
822 Col<eT>::fixed<fixed_n_elem>::fixed(const subview_cube<eT>& X)
823 : Col<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
824 {
825 arma_extra_debug_sigprint_this(this);
826
827 Col<eT>::operator=(X);
828 }
829
830
831
832 template<typename eT>
833 template<uword fixed_n_elem>
834 template<typename T1>
835 inline
836 Col<eT>::fixed<fixed_n_elem>::fixed(const Base<eT,T1>& A)
837 : Col<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
838 {
839 arma_extra_debug_sigprint_this(this);
840
841 Col<eT>::operator=(A.get_ref());
842 }
843
844
845
846 template<typename eT>
847 template<uword fixed_n_elem>
848 template<typename T1, typename T2>
849 inline
850 Col<eT>::fixed<fixed_n_elem>::fixed(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B)
851 : Col<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
852 {
853 arma_extra_debug_sigprint_this(this);
854
855 Col<eT>::init(A,B);
856 }
857
858
859
860 template<typename eT>
861 template<uword fixed_n_elem>
862 inline
863 Col<eT>::fixed<fixed_n_elem>::fixed(const eT* aux_mem)
864 : Col<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
865 {
866 arma_extra_debug_sigprint_this(this);
867
868 eT* dest = (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
869
870 arrayops::copy( dest, aux_mem, fixed_n_elem );
871 }
872
873
874
875 //! NOTE: this function relies on
876 //! Col::operator=(text), to change vec_state as well as swapping n_rows and n_cols,
877 //! and Mat::init(), to check that the given vector will not have a different size than fixed_n_elem.
878 template<typename eT>
879 template<uword fixed_n_elem>
880 inline
881 Col<eT>::fixed<fixed_n_elem>::fixed(const char* text)
882 : Col<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
883 {
884 arma_extra_debug_sigprint_this(this);
885
886 change_to_row();
887
888 Col<eT>::operator=(text);
889 }
890
891
892
893 //! NOTE: this function relies on
894 //! Col::operator=(text), to change vec_state as well as swapping n_rows and n_cols,
895 //! and Mat::init(), to check that the given vector will not have a different size than fixed_n_elem.
896 template<typename eT>
897 template<uword fixed_n_elem>
898 inline
899 Col<eT>::fixed<fixed_n_elem>::fixed(const std::string& text)
900 : Col<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
901 {
902 arma_extra_debug_sigprint_this(this);
903
904 change_to_row();
905
906 Col<eT>::operator=(text);
907 }
908
909
910
911 template<typename eT>
912 template<uword fixed_n_elem>
913 template<typename T1>
914 const Col<eT>&
915 Col<eT>::fixed<fixed_n_elem>::operator=(const Base<eT,T1>& A)
916 {
917 arma_extra_debug_sigprint();
918
919 Col<eT>::operator=(A.get_ref());
920
921 return *this;
922 }
923
924
925
926 template<typename eT>
927 template<uword fixed_n_elem>
928 const Col<eT>&
929 Col<eT>::fixed<fixed_n_elem>::operator=(const eT val)
930 {
931 arma_extra_debug_sigprint();
932
933 Col<eT>::operator=(val);
934
935 return *this;
936 }
937
938
939
940 template<typename eT>
941 template<uword fixed_n_elem>
942 const Col<eT>&
943 Col<eT>::fixed<fixed_n_elem>::operator=(const char* text)
944 {
945 arma_extra_debug_sigprint();
946
947 change_to_row();
948
949 Col<eT>::operator=(text);
950
951 return *this;
952 }
953
954
955
956 template<typename eT>
957 template<uword fixed_n_elem>
958 const Col<eT>&
959 Col<eT>::fixed<fixed_n_elem>::operator=(const std::string& text)
960 {
961 arma_extra_debug_sigprint();
962
963 change_to_row();
964
965 Col<eT>::operator=(text);
966
967 return *this;
968 }
969
970
971
972 template<typename eT>
973 template<uword fixed_n_elem>
974 const Col<eT>&
975 Col<eT>::fixed<fixed_n_elem>::operator=(const subview_cube<eT>& X)
976 {
977 arma_extra_debug_sigprint();
978
979 Col<eT>::operator=(X);
980
981 return *this;
982 }
983
984
985
986 #if defined(ARMA_USE_CXX11)
987
988 template<typename eT>
989 template<uword fixed_n_elem>
990 inline
991 Col<eT>::fixed<fixed_n_elem>::fixed(const std::initializer_list<eT>& list)
992 : Col<eT>( arma_fixed_indicator(), fixed_n_elem, ((use_extra) ? mem_local_extra : Mat<eT>::mem_local) )
993 {
994 arma_extra_debug_sigprint_this(this);
995
996 (*this).operator=(list);
997 }
998
999
1000
1001 template<typename eT>
1002 template<uword fixed_n_elem>
1003 inline
1004 const Col<eT>&
1005 Col<eT>::fixed<fixed_n_elem>::operator=(const std::initializer_list<eT>& list)
1006 {
1007 arma_extra_debug_sigprint();
1008
1009 const uword N = list.size();
1010
1011 arma_debug_check( (N > fixed_n_elem), "Col::fixed: initialiser list is too long" );
1012
1013 eT* this_mem = (*this).memptr();
1014
1015 arrayops::copy( this_mem, list.begin(), N );
1016
1017 for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); }
1018
1019 return *this;
1020 }
1021
1022 #endif
1023
1024
1025
1026 template<typename eT>
1027 template<uword fixed_n_elem>
1028 arma_inline
1029 const Op< typename Col<eT>::template fixed<fixed_n_elem>::Col_fixed_type, op_htrans >
1030 Col<eT>::fixed<fixed_n_elem>::t() const
1031 {
1032 return Op< typename Col<eT>::template fixed<fixed_n_elem>::Col_fixed_type, op_htrans >(*this);
1033 }
1034
1035
1036
1037 template<typename eT>
1038 template<uword fixed_n_elem>
1039 arma_inline
1040 const Op< typename Col<eT>::template fixed<fixed_n_elem>::Col_fixed_type, op_htrans >
1041 Col<eT>::fixed<fixed_n_elem>::ht() const
1042 {
1043 return Op< typename Col<eT>::template fixed<fixed_n_elem>::Col_fixed_type, op_htrans >(*this);
1044 }
1045
1046
1047
1048 template<typename eT>
1049 template<uword fixed_n_elem>
1050 arma_inline
1051 const Op< typename Col<eT>::template fixed<fixed_n_elem>::Col_fixed_type, op_strans >
1052 Col<eT>::fixed<fixed_n_elem>::st() const
1053 {
1054 return Op< typename Col<eT>::template fixed<fixed_n_elem>::Col_fixed_type, op_strans >(*this);
1055 }
1056
1057
1058
1059 template<typename eT>
1060 template<uword fixed_n_elem>
1061 arma_inline
1062 arma_warn_unused
1063 const eT&
1064 Col<eT>::fixed<fixed_n_elem>::at_alt(const uword ii) const
1065 {
1066 #if defined(ARMA_HAVE_ALIGNED_ATTRIBUTE)
1067
1068 return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
1069
1070 #else
1071 const eT* mem_aligned = (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
1072
1073 memory::mark_as_aligned(mem_aligned);
1074
1075 return mem_aligned[ii];
1076 #endif
1077 }
1078
1079
1080
1081 template<typename eT>
1082 template<uword fixed_n_elem>
1083 arma_inline
1084 arma_warn_unused
1085 eT&
1086 Col<eT>::fixed<fixed_n_elem>::operator[] (const uword ii)
1087 {
1088 return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
1089 }
1090
1091
1092
1093 template<typename eT>
1094 template<uword fixed_n_elem>
1095 arma_inline
1096 arma_warn_unused
1097 const eT&
1098 Col<eT>::fixed<fixed_n_elem>::operator[] (const uword ii) const
1099 {
1100 return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
1101 }
1102
1103
1104
1105 template<typename eT>
1106 template<uword fixed_n_elem>
1107 arma_inline
1108 arma_warn_unused
1109 eT&
1110 Col<eT>::fixed<fixed_n_elem>::at(const uword ii)
1111 {
1112 return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
1113 }
1114
1115
1116
1117 template<typename eT>
1118 template<uword fixed_n_elem>
1119 arma_inline
1120 arma_warn_unused
1121 const eT&
1122 Col<eT>::fixed<fixed_n_elem>::at(const uword ii) const
1123 {
1124 return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
1125 }
1126
1127
1128
1129 template<typename eT>
1130 template<uword fixed_n_elem>
1131 arma_inline
1132 arma_warn_unused
1133 eT&
1134 Col<eT>::fixed<fixed_n_elem>::operator() (const uword ii)
1135 {
1136 arma_debug_check( (ii >= fixed_n_elem), "Col::operator(): index out of bounds");
1137
1138 return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
1139 }
1140
1141
1142
1143 template<typename eT>
1144 template<uword fixed_n_elem>
1145 arma_inline
1146 arma_warn_unused
1147 const eT&
1148 Col<eT>::fixed<fixed_n_elem>::operator() (const uword ii) const
1149 {
1150 arma_debug_check( (ii >= fixed_n_elem), "Col::operator(): index out of bounds");
1151
1152 return (use_extra) ? mem_local_extra[ii] : Mat<eT>::mem_local[ii];
1153 }
1154
1155
1156
1157 template<typename eT>
1158 template<uword fixed_n_elem>
1159 arma_inline
1160 arma_warn_unused
1161 eT&
1162 Col<eT>::fixed<fixed_n_elem>::at(const uword in_row, const uword)
1163 {
1164 return (use_extra) ? mem_local_extra[in_row] : Mat<eT>::mem_local[in_row];
1165 }
1166
1167
1168
1169 template<typename eT>
1170 template<uword fixed_n_elem>
1171 arma_inline
1172 arma_warn_unused
1173 const eT&
1174 Col<eT>::fixed<fixed_n_elem>::at(const uword in_row, const uword) const
1175 {
1176 return (use_extra) ? mem_local_extra[in_row] : Mat<eT>::mem_local[in_row];
1177 }
1178
1179
1180
1181 template<typename eT>
1182 template<uword fixed_n_elem>
1183 arma_inline
1184 arma_warn_unused
1185 eT&
1186 Col<eT>::fixed<fixed_n_elem>::operator() (const uword in_row, const uword in_col)
1187 {
1188 arma_debug_check( ((in_row >= fixed_n_elem) || (in_col > 0)), "Col::operator(): index out of bounds" );
1189
1190 return (use_extra) ? mem_local_extra[in_row] : Mat<eT>::mem_local[in_row];
1191 }
1192
1193
1194
1195 template<typename eT>
1196 template<uword fixed_n_elem>
1197 arma_inline
1198 arma_warn_unused
1199 const eT&
1200 Col<eT>::fixed<fixed_n_elem>::operator() (const uword in_row, const uword in_col) const
1201 {
1202 arma_debug_check( ((in_row >= fixed_n_elem) || (in_col > 0)), "Col::operator(): index out of bounds" );
1203
1204 return (use_extra) ? mem_local_extra[in_row] : Mat<eT>::mem_local[in_row];
1205 }
1206
1207
1208
1209 template<typename eT>
1210 template<uword fixed_n_elem>
1211 arma_inline
1212 arma_warn_unused
1213 eT*
1214 Col<eT>::fixed<fixed_n_elem>::memptr()
1215 {
1216 return (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
1217 }
1218
1219
1220
1221 template<typename eT>
1222 template<uword fixed_n_elem>
1223 arma_inline
1224 arma_warn_unused
1225 const eT*
1226 Col<eT>::fixed<fixed_n_elem>::memptr() const
1227 {
1228 return (use_extra) ? mem_local_extra : Mat<eT>::mem_local;
1229 }
1230
1231
1232
1233 template<typename eT>
1234 template<uword fixed_n_elem>
1235 arma_hot
1236 inline
1237 const Col<eT>&
1238 Col<eT>::fixed<fixed_n_elem>::fill(const eT val)
1239 {
1240 arma_extra_debug_sigprint();
1241
1242 eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat<eT>::mem_local[0]);
1243
1244 arrayops::inplace_set_fixed<eT,fixed_n_elem>( mem_use, val );
1245
1246 return *this;
1247 }
1248
1249
1250
1251 template<typename eT>
1252 template<uword fixed_n_elem>
1253 arma_hot
1254 inline
1255 const Col<eT>&
1256 Col<eT>::fixed<fixed_n_elem>::zeros()
1257 {
1258 arma_extra_debug_sigprint();
1259
1260 eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat<eT>::mem_local[0]);
1261
1262 arrayops::inplace_set_fixed<eT,fixed_n_elem>( mem_use, eT(0) );
1263
1264 return *this;
1265 }
1266
1267
1268
1269 template<typename eT>
1270 template<uword fixed_n_elem>
1271 arma_hot
1272 inline
1273 const Col<eT>&
1274 Col<eT>::fixed<fixed_n_elem>::ones()
1275 {
1276 arma_extra_debug_sigprint();
1277
1278 eT* mem_use = (use_extra) ? &(mem_local_extra[0]) : &(Mat<eT>::mem_local[0]);
1279
1280 arrayops::inplace_set_fixed<eT,fixed_n_elem>( mem_use, eT(1) );
1281
1282 return *this;
1283 }
1284
1285
1286
1287 template<typename eT>
1288 inline
1289 Col<eT>::Col(const arma_fixed_indicator&, const uword in_n_elem, const eT* in_mem)
1290 : Mat<eT>(arma_fixed_indicator(), in_n_elem, 1, 1, in_mem)
1291 {
1292 arma_extra_debug_sigprint_this(this);
1293 }
1294
1295
1296
1297 #ifdef ARMA_EXTRA_COL_MEAT
1298 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_COL_MEAT)
1299 #endif
1300
1301
1302
1303 //! @}