annotate armadillo-2.4.4/include/armadillo_bits/Col_meat.hpp @ 18:8d046a9d36aa slimline

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