00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 template<typename eT>
00022 inline
00023 Mat<eT>::~Mat()
00024 {
00025 arma_extra_debug_sigprint_this(this);
00026
00027 if(use_aux_mem == false)
00028 {
00029 if(n_elem > sizeof(mem_local)/sizeof(eT) )
00030 {
00031 delete [] mem;
00032 }
00033 }
00034
00035 if(arma_config::debug == true)
00036 {
00037
00038 access::rw(n_rows) = 0;
00039 access::rw(n_cols) = 0;
00040 access::rw(n_elem) = 0;
00041 access::rw(mem) = 0;
00042 }
00043
00044 isnt_supported_elem_type<eT>::check();
00045 }
00046
00047
00048
00049 template<typename eT>
00050 inline
00051 Mat<eT>::Mat()
00052 : n_rows(0)
00053 , n_cols(0)
00054 , n_elem(0)
00055 , use_aux_mem(false)
00056
00057 , mem(mem)
00058 {
00059 arma_extra_debug_sigprint_this(this);
00060 }
00061
00062
00063
00064 template<typename eT>
00065 inline
00066 Mat<eT>::Mat(const u32 in_n_rows, const u32 in_n_cols)
00067 : n_rows(0)
00068 , n_cols(0)
00069 , n_elem(0)
00070 , use_aux_mem(false)
00071
00072 , mem(mem)
00073 {
00074 arma_extra_debug_sigprint_this(this);
00075
00076 init(in_n_rows, in_n_cols);
00077 }
00078
00079
00080
00081
00082 template<typename eT>
00083 inline
00084 void
00085 Mat<eT>::init(const u32 in_n_rows, const u32 in_n_cols)
00086 {
00087 arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols = %d") % in_n_rows % in_n_cols );
00088
00089 const u32 new_n_elem = in_n_rows * in_n_cols;
00090
00091 if(n_elem == new_n_elem)
00092 {
00093 access::rw(n_rows) = in_n_rows;
00094 access::rw(n_cols) = in_n_cols;
00095 }
00096 else
00097 {
00098 arma_debug_check
00099 (
00100 (use_aux_mem == true),
00101 "Mat::init(): can't change the amount of memory as auxiliary memory is in use"
00102 );
00103
00104 if(n_elem > sizeof(mem_local)/sizeof(eT) )
00105 {
00106 delete [] mem;
00107 }
00108
00109 if(new_n_elem <= sizeof(mem_local)/sizeof(eT) )
00110 {
00111 access::rw(mem) = mem_local;
00112 }
00113 else
00114 {
00115 access::rw(mem) = new(std::nothrow) eT[new_n_elem];
00116 arma_check( (mem == 0), "Mat::init(): out of memory" );
00117 }
00118
00119 access::rw(n_elem) = new_n_elem;
00120
00121 if(new_n_elem == 0)
00122 {
00123 access::rw(n_rows) = 0;
00124 access::rw(n_cols) = 0;
00125 }
00126 else
00127 {
00128 access::rw(n_rows) = in_n_rows;
00129 access::rw(n_cols) = in_n_cols;
00130 }
00131
00132 }
00133 }
00134
00135
00136
00137 template<typename eT>
00138 inline
00139 Mat<eT>::Mat(const char* text)
00140 : n_rows(0)
00141 , n_cols(0)
00142 , n_elem(0)
00143 , use_aux_mem(false)
00144
00145 , mem(mem)
00146 {
00147 arma_extra_debug_sigprint_this(this);
00148
00149 init( std::string(text) );
00150 }
00151
00152
00153
00154
00155 template<typename eT>
00156 inline
00157 const Mat<eT>&
00158 Mat<eT>::operator=(const char* text)
00159 {
00160 arma_extra_debug_sigprint();
00161
00162 init( std::string(text) );
00163 return *this;
00164 }
00165
00166
00167
00168
00169 template<typename eT>
00170 inline
00171 Mat<eT>::Mat(const std::string& text)
00172 : n_rows(0)
00173 , n_cols(0)
00174 , n_elem(0)
00175 , use_aux_mem(false)
00176
00177 , mem(mem)
00178 {
00179 arma_extra_debug_sigprint_this(this);
00180
00181 init(text);
00182 }
00183
00184
00185
00186
00187 template<typename eT>
00188 inline
00189 const Mat<eT>&
00190 Mat<eT>::operator=(const std::string& text)
00191 {
00192 arma_extra_debug_sigprint();
00193
00194 init(text);
00195 return *this;
00196 }
00197
00198
00199
00200
00201 template<typename eT>
00202 inline
00203 void
00204 Mat<eT>::init(const std::string& text)
00205 {
00206 arma_extra_debug_sigprint();
00207
00208
00209
00210
00211 u32 t_n_rows = 0;
00212 u32 t_n_cols = 0;
00213
00214 bool t_n_cols_found = false;
00215
00216 std::string token;
00217
00218 std::string::size_type line_start = 0;
00219 std::string::size_type line_end = 0;
00220
00221 while( line_start < text.length() )
00222 {
00223
00224 line_end = text.find(';', line_start);
00225
00226 if(line_end == std::string::npos)
00227 line_end = text.length()-1;
00228
00229 std::string::size_type line_len = line_end - line_start + 1;
00230 std::stringstream line_stream( text.substr(line_start,line_len) );
00231
00232
00233 u32 line_n_cols = 0;
00234 while(line_stream >> token)
00235 {
00236 ++line_n_cols;
00237 }
00238
00239
00240 if(line_n_cols > 0)
00241 {
00242 if(t_n_cols_found == false)
00243 {
00244 t_n_cols = line_n_cols;
00245 t_n_cols_found = true;
00246 }
00247 else
00248 arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent number of columns in given string");
00249
00250 ++t_n_rows;
00251 }
00252 line_start = line_end+1;
00253
00254 }
00255
00256 Mat<eT>& x = *this;
00257 x.set_size(t_n_rows, t_n_cols);
00258
00259 line_start = 0;
00260 line_end = 0;
00261
00262 u32 row = 0;
00263
00264 while( line_start < text.length() )
00265 {
00266
00267 line_end = text.find(';', line_start);
00268
00269 if(line_end == std::string::npos)
00270 line_end = text.length()-1;
00271
00272 std::string::size_type line_len = line_end - line_start + 1;
00273 std::stringstream line_stream( text.substr(line_start,line_len) );
00274
00275
00276
00277
00278
00279
00280
00281
00282 u32 col = 0;
00283 eT val;
00284 while(line_stream >> val)
00285 {
00286 x.at(row,col) = val;
00287 ++col;
00288 }
00289
00290 ++row;
00291 line_start = line_end+1;
00292 }
00293
00294 }
00295
00296
00297
00298
00299
00300 template<typename eT>
00301 arma_inline
00302 const Mat<eT>&
00303 Mat<eT>::operator=(const eT val)
00304 {
00305 arma_extra_debug_sigprint();
00306
00307 init(1,1);
00308 access::rw(mem[0]) = val;
00309 return *this;
00310 }
00311
00312
00313
00314
00315 template<typename eT>
00316 arma_inline
00317 const Mat<eT>&
00318 Mat<eT>::operator+=(const eT val)
00319 {
00320 arma_extra_debug_sigprint();
00321
00322 eT* local_ptr = memptr();
00323 const u32 local_n_elem = n_elem;
00324
00325 u32 i,j;
00326
00327 for(i=0, j=1; j<local_n_elem; i+=2, j+=2)
00328 {
00329 local_ptr[i] += val;
00330 local_ptr[j] += val;
00331 }
00332
00333 if(i < local_n_elem)
00334 {
00335 local_ptr[i] += val;
00336 }
00337
00338 return *this;
00339 }
00340
00341
00342
00343
00344 template<typename eT>
00345 arma_inline
00346 const Mat<eT>&
00347 Mat<eT>::operator-=(const eT val)
00348 {
00349 arma_extra_debug_sigprint();
00350
00351 eT* local_ptr = memptr();
00352 const u32 local_n_elem = n_elem;
00353
00354 u32 i,j;
00355
00356 for(i=0, j=1; j<local_n_elem; i+=2, j+=2)
00357 {
00358 local_ptr[i] -= val;
00359 local_ptr[j] -= val;
00360 }
00361
00362 if(i < local_n_elem)
00363 {
00364 local_ptr[i] -= val;
00365 }
00366
00367 return *this;
00368 }
00369
00370
00371
00372
00373 template<typename eT>
00374 arma_inline
00375 const Mat<eT>&
00376 Mat<eT>::operator*=(const eT val)
00377 {
00378 arma_extra_debug_sigprint();
00379
00380 eT* local_ptr = memptr();
00381 const u32 local_n_elem = n_elem;
00382
00383 u32 i,j;
00384
00385 for(i=0, j=1; j<local_n_elem; i+=2, j+=2)
00386 {
00387 local_ptr[i] *= val;
00388 local_ptr[j] *= val;
00389 }
00390
00391 if(i < local_n_elem)
00392 {
00393 local_ptr[i] *= val;
00394 }
00395
00396 return *this;
00397 }
00398
00399
00400
00401
00402 template<typename eT>
00403 arma_inline
00404 const Mat<eT>&
00405 Mat<eT>::operator/=(const eT val)
00406 {
00407 arma_extra_debug_sigprint();
00408
00409 eT* local_ptr = memptr();
00410 const u32 local_n_elem = n_elem;
00411
00412 u32 i,j;
00413
00414 for(i=0, j=1; j<local_n_elem; i+=2, j+=2)
00415 {
00416 local_ptr[i] /= val;
00417 local_ptr[j] /= val;
00418 }
00419
00420 if(i < local_n_elem)
00421 {
00422 local_ptr[i] /= val;
00423 }
00424
00425 return *this;
00426 }
00427
00428
00429
00430
00431 template<typename eT>
00432 inline
00433 Mat<eT>::Mat(const Mat<eT>& in_mat)
00434 : n_rows(0)
00435 , n_cols(0)
00436 , n_elem(0)
00437 , use_aux_mem(false)
00438
00439 , mem(mem)
00440 {
00441 arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat);
00442
00443 init(in_mat);
00444 }
00445
00446
00447
00448
00449 template<typename eT>
00450 inline
00451 const Mat<eT>&
00452 Mat<eT>::operator=(const Mat<eT>& x)
00453 {
00454 arma_extra_debug_sigprint();
00455
00456 init(x);
00457 return *this;
00458 }
00459
00460
00461
00462
00463 template<typename eT>
00464 inline
00465 void
00466 Mat<eT>::init(const Mat<eT>& x)
00467 {
00468 arma_extra_debug_sigprint();
00469
00470 if(this != &x)
00471 {
00472 init(x.n_rows, x.n_cols);
00473 syslib::copy_elem( memptr(), x.mem, n_elem );
00474 }
00475 }
00476
00477
00478
00479
00480
00481
00482
00483
00484 template<typename eT>
00485 inline
00486 Mat<eT>::Mat(eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols, const bool copy_aux_mem)
00487 : n_rows (copy_aux_mem ? 0 : aux_n_rows )
00488 , n_cols (copy_aux_mem ? 0 : aux_n_cols )
00489 , n_elem (copy_aux_mem ? 0 : aux_n_rows*aux_n_cols)
00490 , use_aux_mem(copy_aux_mem ? false : true )
00491 , mem (copy_aux_mem ? mem : aux_mem )
00492 {
00493 arma_extra_debug_sigprint_this(this);
00494
00495 if(copy_aux_mem == true)
00496 {
00497 init(aux_n_rows, aux_n_cols);
00498 syslib::copy_elem( memptr(), aux_mem, n_elem );
00499 }
00500 }
00501
00502
00503
00504
00505
00506 template<typename eT>
00507 inline
00508 Mat<eT>::Mat(const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols)
00509 : n_rows(0)
00510 , n_cols(0)
00511 , n_elem(0)
00512 , use_aux_mem(false)
00513
00514 , mem(mem)
00515 {
00516 arma_extra_debug_sigprint_this(this);
00517
00518 init(aux_n_rows, aux_n_cols);
00519 syslib::copy_elem( memptr(), aux_mem, n_elem );
00520 }
00521
00522
00523
00524
00525
00526
00527
00528 template<typename eT>
00529 inline
00530 Mat<eT>::Mat(const char junk, const eT* aux_mem, const u32 aux_n_rows, const u32 aux_n_cols)
00531 : n_rows (aux_n_rows )
00532 , n_cols (aux_n_cols )
00533 , n_elem (aux_n_rows*aux_n_cols)
00534 , use_aux_mem(true )
00535 , mem (aux_mem )
00536 {
00537 arma_extra_debug_sigprint_this(this);
00538 }
00539
00540
00541
00542
00543 template<typename eT>
00544 inline
00545 const Mat<eT>&
00546 Mat<eT>::operator+=(const Mat<eT>& m)
00547 {
00548 arma_extra_debug_sigprint();
00549
00550 arma_debug_assert_same_size(*this, m, "matrix addition");
00551
00552 const u32 local_n_elem = m.n_elem;
00553
00554 eT* out_mem = (*this).memptr();
00555 const eT* m_mem = m.memptr();
00556
00557 u32 i,j;
00558
00559 for(i=0, j=1; j<local_n_elem; i+=2, j+=2)
00560 {
00561 out_mem[i] += m_mem[i];
00562 out_mem[j] += m_mem[j];
00563 }
00564
00565 if(i < local_n_elem)
00566 {
00567 out_mem[i] += m_mem[i];
00568 }
00569
00570 return *this;
00571 }
00572
00573
00574
00575
00576 template<typename eT>
00577 inline
00578 const Mat<eT>&
00579 Mat<eT>::operator-=(const Mat<eT>& m)
00580 {
00581 arma_extra_debug_sigprint();
00582
00583 arma_debug_assert_same_size(*this, m, "matrix subtraction");
00584
00585 const u32 local_n_elem = m.n_elem;
00586
00587 eT* out_mem = (*this).memptr();
00588 const eT* m_mem = m.memptr();
00589
00590 u32 i,j;
00591
00592 for(i=0, j=1; j<local_n_elem; i+=2, j+=2)
00593 {
00594 out_mem[i] -= m_mem[i];
00595 out_mem[j] -= m_mem[j];
00596 }
00597
00598 if(i < local_n_elem)
00599 {
00600 out_mem[i] -= m_mem[i];
00601 }
00602
00603 return *this;
00604 }
00605
00606
00607
00608
00609 template<typename eT>
00610 inline
00611 const Mat<eT>&
00612 Mat<eT>::operator*=(const Mat<eT>& m)
00613 {
00614 arma_extra_debug_sigprint();
00615
00616 glue_times::apply_inplace(*this, m);
00617 return *this;
00618 }
00619
00620
00621
00622
00623 template<typename eT>
00624 inline
00625 const Mat<eT>&
00626 Mat<eT>::operator%=(const Mat<eT>& m)
00627 {
00628 arma_extra_debug_sigprint();
00629
00630 arma_debug_assert_same_size(*this, m, "element-wise matrix multplication");
00631
00632 const u32 local_n_elem = m.n_elem;
00633
00634 eT* out_mem = (*this).memptr();
00635 const eT* m_mem = m.memptr();
00636
00637 u32 i,j;
00638
00639 for(i=0, j=1; j<local_n_elem; i+=2, j+=2)
00640 {
00641 out_mem[i] *= m_mem[i];
00642 out_mem[j] *= m_mem[j];
00643 }
00644
00645 if(i < local_n_elem)
00646 {
00647 out_mem[i] *= m_mem[i];
00648 }
00649
00650 return *this;
00651 }
00652
00653
00654
00655
00656 template<typename eT>
00657 inline
00658 const Mat<eT>&
00659 Mat<eT>::operator/=(const Mat<eT>& m)
00660 {
00661 arma_extra_debug_sigprint();
00662
00663 arma_debug_assert_same_size(*this, m, "element-wise matrix division");
00664
00665 const u32 local_n_elem = m.n_elem;
00666
00667 eT* out_mem = (*this).memptr();
00668 const eT* m_mem = m.memptr();
00669
00670 u32 i,j;
00671
00672 for(i=0, j=1; j<local_n_elem; i+=2, j+=2)
00673 {
00674 out_mem[i] /= m_mem[i];
00675 out_mem[j] /= m_mem[j];
00676 }
00677
00678 if(i < local_n_elem)
00679 {
00680 out_mem[i] /= m_mem[i];
00681 }
00682
00683 return *this;
00684 }
00685
00686
00687
00688
00689 template<typename eT>
00690 template<typename T1, typename T2>
00691 inline
00692 Mat<eT>::Mat
00693 (
00694 const Base<typename Mat<eT>::pod_type,T1>& A,
00695 const Base<typename Mat<eT>::pod_type,T2>& B
00696 )
00697 : n_rows(0)
00698 , n_cols(0)
00699 , n_elem(0)
00700 , use_aux_mem(false)
00701
00702 , mem(mem)
00703 {
00704 arma_extra_debug_sigprint_this(this);
00705
00706 arma_type_check< is_complex<eT>::value == false >::apply();
00707
00708 typedef typename T1::elem_type T;
00709 arma_type_check< is_complex<T>::value == true >::apply();
00710
00711 isnt_same_type<std::complex<T>, eT>::check();
00712
00713 const unwrap<T1> tmp_A(A.get_ref());
00714 const unwrap<T2> tmp_B(B.get_ref());
00715
00716 const Mat<T>& X = tmp_A.M;
00717 const Mat<T>& Y = tmp_B.M;
00718
00719 arma_assert_same_size(X, Y, "Mat()");
00720
00721 init(X.n_rows, Y.n_cols);
00722
00723 const T* X_mem = X.mem;
00724 const T* Y_mem = Y.mem;
00725
00726 for(u32 i=0; i<n_elem; ++i)
00727 {
00728 access::rw(mem[i]) = std::complex<T>(X_mem[i], Y_mem[i]);
00729 }
00730 }
00731
00732
00733
00734
00735 template<typename eT>
00736 inline
00737 Mat<eT>::Mat(const subview<eT>& X)
00738 : n_rows(0)
00739 , n_cols(0)
00740 , n_elem(0)
00741 , use_aux_mem(false)
00742
00743 , mem(mem)
00744 {
00745 arma_extra_debug_sigprint_this(this);
00746
00747 this->operator=(X);
00748 }
00749
00750
00751
00752
00753 template<typename eT>
00754 inline
00755 const Mat<eT>&
00756 Mat<eT>::operator=(const subview<eT>& X)
00757 {
00758 arma_extra_debug_sigprint();
00759
00760 subview<eT>::extract(*this, X);
00761 return *this;
00762 }
00763
00764
00765
00766 template<typename eT>
00767 inline
00768 const Mat<eT>&
00769 Mat<eT>::operator+=(const subview<eT>& X)
00770 {
00771 arma_extra_debug_sigprint();
00772
00773 subview<eT>::plus_inplace(*this, X);
00774 return *this;
00775 }
00776
00777
00778
00779 template<typename eT>
00780 inline
00781 const Mat<eT>&
00782 Mat<eT>::operator-=(const subview<eT>& X)
00783 {
00784 arma_extra_debug_sigprint();
00785
00786 subview<eT>::minus_inplace(*this, X);
00787 return *this;
00788 }
00789
00790
00791
00792
00793 template<typename eT>
00794 inline
00795 const Mat<eT>&
00796 Mat<eT>::operator*=(const subview<eT>& X)
00797 {
00798 arma_extra_debug_sigprint();
00799
00800 glue_times::apply_inplace(*this, X);
00801 return *this;
00802 }
00803
00804
00805
00806
00807 template<typename eT>
00808 inline
00809 const Mat<eT>&
00810 Mat<eT>::operator%=(const subview<eT>& X)
00811 {
00812 arma_extra_debug_sigprint();
00813
00814 subview<eT>::schur_inplace(*this, X);
00815 return *this;
00816 }
00817
00818
00819
00820
00821 template<typename eT>
00822 inline
00823 const Mat<eT>&
00824 Mat<eT>::operator/=(const subview<eT>& X)
00825 {
00826 arma_extra_debug_sigprint();
00827
00828 subview<eT>::div_inplace(*this, X);
00829 return *this;
00830 }
00831
00832
00833
00834
00835 template<typename eT>
00836 inline
00837 Mat<eT>::Mat(const subview_cube<eT>& x)
00838 : n_rows(0)
00839 , n_cols(0)
00840 , n_elem(0)
00841 , use_aux_mem(false)
00842
00843 , mem(mem)
00844 {
00845 arma_extra_debug_sigprint_this(this);
00846
00847 this->operator=(x);
00848 }
00849
00850
00851
00852
00853 template<typename eT>
00854 inline
00855 const Mat<eT>&
00856 Mat<eT>::operator=(const subview_cube<eT>& X)
00857 {
00858 arma_extra_debug_sigprint();
00859
00860 subview_cube<eT>::extract(*this, X);
00861 return *this;
00862 }
00863
00864
00865
00866
00867 template<typename eT>
00868 inline
00869 const Mat<eT>&
00870 Mat<eT>::operator+=(const subview_cube<eT>& X)
00871 {
00872 arma_extra_debug_sigprint();
00873
00874 subview_cube<eT>::plus_inplace(*this, X);
00875 return *this;
00876 }
00877
00878
00879
00880
00881 template<typename eT>
00882 inline
00883 const Mat<eT>&
00884 Mat<eT>::operator-=(const subview_cube<eT>& X)
00885 {
00886 arma_extra_debug_sigprint();
00887
00888 subview_cube<eT>::minus_inplace(*this, X);
00889 return *this;
00890 }
00891
00892
00893
00894
00895 template<typename eT>
00896 inline
00897 const Mat<eT>&
00898 Mat<eT>::operator*=(const subview_cube<eT>& X)
00899 {
00900 arma_extra_debug_sigprint();
00901
00902 const Mat<eT> tmp(X);
00903 glue_times::apply_inplace(*this, tmp);
00904 return *this;
00905 }
00906
00907
00908
00909
00910 template<typename eT>
00911 inline
00912 const Mat<eT>&
00913 Mat<eT>::operator%=(const subview_cube<eT>& X)
00914 {
00915 arma_extra_debug_sigprint();
00916
00917 subview_cube<eT>::schur_inplace(*this, X);
00918 return *this;
00919 }
00920
00921
00922
00923
00924 template<typename eT>
00925 inline
00926 const Mat<eT>&
00927 Mat<eT>::operator/=(const subview_cube<eT>& X)
00928 {
00929 arma_extra_debug_sigprint();
00930
00931 subview_cube<eT>::div_inplace(*this, X);
00932 return *this;
00933 }
00934
00935
00936
00937
00938 template<typename eT>
00939 inline
00940 Mat<eT>::Mat(const diagview<eT>& X)
00941 : n_rows(0)
00942 , n_cols(0)
00943 , n_elem(0)
00944 , use_aux_mem(false)
00945
00946 , mem(mem)
00947 {
00948 arma_extra_debug_sigprint_this(this);
00949
00950 this->operator=(X);
00951 }
00952
00953
00954
00955
00956 template<typename eT>
00957 inline
00958 const Mat<eT>&
00959 Mat<eT>::operator=(const diagview<eT>& X)
00960 {
00961 arma_extra_debug_sigprint();
00962
00963 diagview<eT>::extract(*this, X);
00964 return *this;
00965 }
00966
00967
00968
00969
00970 template<typename eT>
00971 inline
00972 const Mat<eT>&
00973 Mat<eT>::operator+=(const diagview<eT>& X)
00974 {
00975 arma_extra_debug_sigprint();
00976
00977 diagview<eT>::plus_inplace(*this, X);
00978 return *this;
00979 }
00980
00981
00982
00983 template<typename eT>
00984 inline
00985 const Mat<eT>&
00986 Mat<eT>::operator-=(const diagview<eT>& X)
00987 {
00988 arma_extra_debug_sigprint();
00989
00990 diagview<eT>::minus_inplace(*this, X);
00991 return *this;
00992 }
00993
00994
00995
00996
00997 template<typename eT>
00998 inline
00999 const Mat<eT>&
01000 Mat<eT>::operator*=(const diagview<eT>& X)
01001 {
01002 arma_extra_debug_sigprint();
01003
01004 glue_times::apply_inplace(*this, X);
01005 return *this;
01006 }
01007
01008
01009
01010
01011 template<typename eT>
01012 inline
01013 const Mat<eT>&
01014 Mat<eT>::operator%=(const diagview<eT>& X)
01015 {
01016 arma_extra_debug_sigprint();
01017
01018 diagview<eT>::schur_inplace(*this, X);
01019 return *this;
01020 }
01021
01022
01023
01024
01025 template<typename eT>
01026 inline
01027 const Mat<eT>&
01028 Mat<eT>::operator/=(const diagview<eT>& X)
01029 {
01030 arma_extra_debug_sigprint();
01031
01032 diagview<eT>::div_inplace(*this, X);
01033 return *this;
01034 }
01035
01036
01037
01038
01039 template<typename eT>
01040 arma_inline
01041 subview_row<eT>
01042 Mat<eT>::row(const u32 row_num)
01043 {
01044 arma_extra_debug_sigprint();
01045
01046 arma_debug_check( row_num >= n_rows, "Mat::row(): row out of bounds" );
01047
01048 return subview_row<eT>(*this, row_num);
01049 }
01050
01051
01052
01053
01054 template<typename eT>
01055 arma_inline
01056 const subview_row<eT>
01057 Mat<eT>::row(const u32 row_num) const
01058 {
01059 arma_extra_debug_sigprint();
01060
01061 arma_debug_check( row_num >= n_rows, "Mat::row(): row out of bounds" );
01062
01063 return subview_row<eT>(*this, row_num);
01064 }
01065
01066
01067
01068
01069 template<typename eT>
01070 arma_inline
01071 subview_col<eT>
01072 Mat<eT>::col(const u32 col_num)
01073 {
01074 arma_extra_debug_sigprint();
01075
01076 arma_debug_check( col_num >= n_cols, "Mat::col(): out of bounds");
01077
01078 return subview_col<eT>(*this, col_num);
01079 }
01080
01081
01082
01083
01084 template<typename eT>
01085 arma_inline
01086 const subview_col<eT>
01087 Mat<eT>::col(const u32 col_num) const
01088 {
01089 arma_extra_debug_sigprint();
01090
01091 arma_debug_check( col_num >= n_cols, "Mat::col(): out of bounds");
01092
01093 return subview_col<eT>(*this, col_num);
01094 }
01095
01096
01097
01098
01099 template<typename eT>
01100 arma_inline
01101 subview<eT>
01102 Mat<eT>::rows(const u32 in_row1, const u32 in_row2)
01103 {
01104 arma_extra_debug_sigprint();
01105
01106 arma_debug_check
01107 (
01108 (in_row1 > in_row2) || (in_row2 >= n_rows),
01109 "Mat::rows(): indices out of bounds or incorrectly used"
01110 );
01111
01112 return subview<eT>(*this, in_row1, 0, in_row2, ((n_cols>0) ? n_cols-1 : 0) );
01113 }
01114
01115
01116
01117
01118 template<typename eT>
01119 arma_inline
01120 const subview<eT>
01121 Mat<eT>::rows(const u32 in_row1, const u32 in_row2) const
01122 {
01123 arma_extra_debug_sigprint();
01124
01125 arma_debug_check
01126 (
01127 (in_row1 > in_row2) || (in_row2 >= n_rows),
01128 "Mat::rows(): indices out of bounds or incorrectly used"
01129 );
01130
01131 return subview<eT>(*this, in_row1, 0, in_row2, ((n_cols>0) ? n_cols-1 : 0) );
01132 }
01133
01134
01135
01136
01137 template<typename eT>
01138 arma_inline
01139 subview<eT>
01140 Mat<eT>::cols(const u32 in_col1, const u32 in_col2)
01141 {
01142 arma_extra_debug_sigprint();
01143
01144 arma_debug_check
01145 (
01146 (in_col1 > in_col2) || (in_col2 >= n_cols),
01147 "Mat::cols(): indices out of bounds or incorrectly used"
01148 );
01149
01150 return subview<eT>(*this, 0, in_col1, ((n_rows>0) ? n_rows-1 : 0), in_col2);
01151 }
01152
01153
01154
01155
01156 template<typename eT>
01157 arma_inline
01158 const subview<eT>
01159 Mat<eT>::cols(const u32 in_col1, const u32 in_col2) const
01160 {
01161 arma_extra_debug_sigprint();
01162
01163 arma_debug_check
01164 (
01165 (in_col1 > in_col2) || (in_col2 >= n_cols),
01166 "Mat::cols(): indices out of bounds or incorrectly used"
01167 );
01168
01169 return subview<eT>(*this, 0, in_col1, ((n_rows>0) ? n_rows-1 : 0), in_col2);
01170 }
01171
01172
01173
01174
01175 template<typename eT>
01176 arma_inline
01177 subview<eT>
01178 Mat<eT>::submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2)
01179 {
01180 arma_extra_debug_sigprint();
01181
01182 arma_debug_check
01183 (
01184 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
01185 "Mat::submat(): indices out of bounds or incorrectly used"
01186 );
01187
01188 return subview<eT>(*this, in_row1, in_col1, in_row2, in_col2);
01189 }
01190
01191
01192
01193
01194 template<typename eT>
01195 arma_inline
01196 const subview<eT>
01197 Mat<eT>::submat(const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2) const
01198 {
01199 arma_extra_debug_sigprint();
01200
01201 arma_debug_check
01202 (
01203 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols),
01204 "Mat::submat(): indices out of bounds or incorrectly used"
01205 );
01206
01207 return subview<eT>(*this, in_row1, in_col1, in_row2, in_col2);
01208 }
01209
01210
01211
01212
01213 template<typename eT>
01214 arma_inline
01215 diagview<eT>
01216 Mat<eT>::diag(const s32 in_id)
01217 {
01218 arma_extra_debug_sigprint();
01219
01220 const u32 row_offset = (in_id < 0) ? -in_id : 0;
01221 const u32 col_offset = (in_id > 0) ? in_id : 0;
01222
01223 arma_debug_check
01224 (
01225 (row_offset >= n_rows) || (col_offset >= n_cols),
01226 "Mat::diag(): requested diagonal out of bounds"
01227 );
01228
01229 const u32 len = (std::min)(n_rows - row_offset, n_cols - col_offset);
01230
01231 return diagview<eT>(*this, row_offset, col_offset, len);
01232 }
01233
01234
01235
01236
01237 template<typename eT>
01238 arma_inline
01239 const diagview<eT>
01240 Mat<eT>::diag(const s32 in_id) const
01241 {
01242 arma_extra_debug_sigprint();
01243
01244 const u32 row_offset = (in_id < 0) ? -in_id : 0;
01245 const u32 col_offset = (in_id > 0) ? in_id : 0;
01246
01247 arma_debug_check
01248 (
01249 (row_offset >= n_rows) || (col_offset >= n_cols),
01250 "Mat::diag(): requested diagonal out of bounds"
01251 );
01252
01253
01254 const u32 len = (std::min)(n_rows - row_offset, n_cols - col_offset);
01255
01256 return diagview<eT>(*this, row_offset, col_offset, len);
01257 }
01258
01259
01260
01261 template<typename eT>
01262 inline
01263 void
01264 Mat<eT>::swap_rows(const u32 in_row1, const u32 in_row2)
01265 {
01266 arma_extra_debug_sigprint();
01267
01268 arma_debug_check
01269 (
01270 (in_row1 >= n_rows) || (in_row2 >= n_rows),
01271 "Mat::swap_rows(): out of bounds"
01272 );
01273
01274 for(u32 col=0; col<n_cols; ++col)
01275 {
01276 const u32 offset = col*n_rows;
01277 const u32 pos1 = in_row1 + offset;
01278 const u32 pos2 = in_row2 + offset;
01279
01280 const eT tmp = mem[pos1];
01281 access::rw(mem[pos1]) = mem[pos2];
01282 access::rw(mem[pos2]) = tmp;
01283 }
01284
01285 }
01286
01287
01288
01289 template<typename eT>
01290 inline
01291 void
01292 Mat<eT>::swap_cols(const u32 in_col1, const u32 in_col2)
01293 {
01294 arma_extra_debug_sigprint();
01295
01296 arma_debug_check
01297 (
01298 (in_col1 >= n_cols) || (in_col2 >= n_cols),
01299 "Mat::swap_cols(): out of bounds"
01300 );
01301
01302 eT* ptr1 = colptr(in_col1);
01303 eT* ptr2 = colptr(in_col2);
01304
01305 for(u32 row=0; row<n_rows; ++row)
01306 {
01307 const eT tmp = ptr1[row];
01308 ptr1[row] = ptr2[row];
01309 ptr2[row] = tmp;
01310 }
01311
01312 }
01313
01314
01315
01316
01317 template<typename eT>
01318 template<typename T1, typename op_type>
01319 inline
01320 Mat<eT>::Mat(const Op<T1, op_type>& X)
01321 : n_rows(0)
01322 , n_cols(0)
01323 , n_elem(0)
01324 , use_aux_mem(false)
01325
01326 , mem(mem)
01327 {
01328 arma_extra_debug_sigprint_this(this);
01329
01330 isnt_same_type<eT, typename T1::elem_type>::check();
01331
01332 op_type::apply(*this, X);
01333 }
01334
01335
01336
01337
01338 template<typename eT>
01339 template<typename T1, typename op_type>
01340 inline
01341 const Mat<eT>&
01342 Mat<eT>::operator=(const Op<T1, op_type>& X)
01343 {
01344 arma_extra_debug_sigprint();
01345
01346 isnt_same_type<eT, typename T1::elem_type>::check();
01347
01348 op_type::apply(*this, X);
01349
01350 return *this;
01351 }
01352
01353
01354
01355
01356 template<typename eT>
01357 template<typename T1, typename op_type>
01358 inline
01359 const Mat<eT>&
01360 Mat<eT>::operator+=(const Op<T1, op_type>& X)
01361 {
01362 arma_extra_debug_sigprint();
01363
01364 isnt_same_type<eT, typename T1::elem_type>::check();
01365
01366 const Mat<eT> m(X);
01367
01368 return (*this).operator+=(m);
01369 }
01370
01371
01372
01373
01374 template<typename eT>
01375 template<typename T1, typename op_type>
01376 inline
01377 const Mat<eT>&
01378 Mat<eT>::operator-=(const Op<T1, op_type>& X)
01379 {
01380 arma_extra_debug_sigprint();
01381
01382 isnt_same_type<eT, typename T1::elem_type>::check();
01383
01384 const Mat<eT> m(X);
01385
01386 return (*this).operator-=(m);
01387 }
01388
01389
01390
01391
01392 template<typename eT>
01393 template<typename T1, typename op_type>
01394 inline
01395 const Mat<eT>&
01396 Mat<eT>::operator*=(const Op<T1, op_type>& X)
01397 {
01398 arma_extra_debug_sigprint();
01399
01400 isnt_same_type<eT, typename T1::elem_type>::check();
01401
01402 glue_times::apply_inplace(*this, X);
01403
01404 return *this;
01405 }
01406
01407
01408
01409
01410 template<typename eT>
01411 template<typename T1, typename op_type>
01412 inline
01413 const Mat<eT>&
01414 Mat<eT>::operator%=(const Op<T1, op_type>& X)
01415 {
01416 arma_extra_debug_sigprint();
01417
01418 isnt_same_type<eT, typename T1::elem_type>::check();
01419
01420 const Mat<eT> m(X);
01421
01422 return (*this).operator%=(m);
01423 }
01424
01425
01426
01427
01428 template<typename eT>
01429 template<typename T1, typename op_type>
01430 inline
01431 const Mat<eT>&
01432 Mat<eT>::operator/=(const Op<T1, op_type>& X)
01433 {
01434 arma_extra_debug_sigprint();
01435
01436 isnt_same_type<eT, typename T1::elem_type>::check();
01437
01438 const Mat<eT> m(X);
01439
01440 return (*this).operator/=(m);
01441 }
01442
01443
01444
01445
01446 template<typename eT>
01447 template<typename T1, typename eop_type>
01448 inline
01449 Mat<eT>::Mat(const eOp<T1, eop_type>& X)
01450 : n_rows(0)
01451 , n_cols(0)
01452 , n_elem(0)
01453 , use_aux_mem(false)
01454
01455 , mem(mem)
01456 {
01457 arma_extra_debug_sigprint_this(this);
01458
01459 isnt_same_type<eT, typename T1::elem_type>::check();
01460
01461 eop_type::apply(*this, X);
01462 }
01463
01464
01465
01466
01467 template<typename eT>
01468 template<typename T1, typename eop_type>
01469 inline
01470 const Mat<eT>&
01471 Mat<eT>::operator=(const eOp<T1, eop_type>& X)
01472 {
01473 arma_extra_debug_sigprint();
01474
01475 isnt_same_type<eT, typename T1::elem_type>::check();
01476
01477 eop_type::apply(*this, X);
01478
01479 return *this;
01480 }
01481
01482
01483
01484 template<typename eT>
01485 template<typename T1, typename eop_type>
01486 inline
01487 const Mat<eT>&
01488 Mat<eT>::operator+=(const eOp<T1, eop_type>& X)
01489 {
01490 arma_extra_debug_sigprint();
01491
01492 isnt_same_type<eT, typename T1::elem_type>::check();
01493
01494 eop_type::apply_inplace_plus(*this, X);
01495
01496 return *this;
01497 }
01498
01499
01500
01501 template<typename eT>
01502 template<typename T1, typename eop_type>
01503 inline
01504 const Mat<eT>&
01505 Mat<eT>::operator-=(const eOp<T1, eop_type>& X)
01506 {
01507 arma_extra_debug_sigprint();
01508
01509 isnt_same_type<eT, typename T1::elem_type>::check();
01510
01511 eop_type::apply_inplace_minus(*this, X);
01512
01513 return *this;
01514 }
01515
01516
01517
01518 template<typename eT>
01519 template<typename T1, typename eop_type>
01520 inline
01521 const Mat<eT>&
01522 Mat<eT>::operator*=(const eOp<T1, eop_type>& X)
01523 {
01524 arma_extra_debug_sigprint();
01525
01526 isnt_same_type<eT, typename T1::elem_type>::check();
01527
01528 glue_times::apply_inplace(*this, X);
01529
01530 return *this;
01531 }
01532
01533
01534
01535 template<typename eT>
01536 template<typename T1, typename eop_type>
01537 inline
01538 const Mat<eT>&
01539 Mat<eT>::operator%=(const eOp<T1, eop_type>& X)
01540 {
01541 arma_extra_debug_sigprint();
01542
01543 isnt_same_type<eT, typename T1::elem_type>::check();
01544
01545 eop_type::apply_inplace_schur(*this, X);
01546
01547 return *this;
01548 }
01549
01550
01551
01552 template<typename eT>
01553 template<typename T1, typename eop_type>
01554 inline
01555 const Mat<eT>&
01556 Mat<eT>::operator/=(const eOp<T1, eop_type>& X)
01557 {
01558 arma_extra_debug_sigprint();
01559
01560 isnt_same_type<eT, typename T1::elem_type>::check();
01561
01562 eop_type::apply_inplace_div(*this, X);
01563
01564 return *this;
01565 }
01566
01567
01568
01569
01570 template<typename eT>
01571 template<typename T1, typename op_type>
01572 inline
01573 Mat<eT>::Mat(const mtOp<eT, T1, op_type>& X)
01574 : n_rows(0)
01575 , n_cols(0)
01576 , n_elem(0)
01577 , use_aux_mem(false)
01578
01579 , mem(mem)
01580 {
01581 arma_extra_debug_sigprint_this(this);
01582
01583 op_type::apply(*this, X);
01584 }
01585
01586
01587
01588
01589 template<typename eT>
01590 template<typename T1, typename op_type>
01591 inline
01592 const Mat<eT>&
01593 Mat<eT>::operator=(const mtOp<eT, T1, op_type>& X)
01594 {
01595 arma_extra_debug_sigprint();
01596
01597 op_type::apply(*this, X);
01598
01599 return *this;
01600 }
01601
01602
01603
01604
01605 template<typename eT>
01606 template<typename T1, typename op_type>
01607 inline
01608 const Mat<eT>&
01609 Mat<eT>::operator+=(const mtOp<eT, T1, op_type>& X)
01610 {
01611 arma_extra_debug_sigprint();
01612
01613 const Mat<eT> m(X);
01614
01615 return (*this).operator+=(m);
01616 }
01617
01618
01619
01620
01621 template<typename eT>
01622 template<typename T1, typename op_type>
01623 inline
01624 const Mat<eT>&
01625 Mat<eT>::operator-=(const mtOp<eT, T1, op_type>& X)
01626 {
01627 arma_extra_debug_sigprint();
01628
01629 const Mat<eT> m(X);
01630
01631 return (*this).operator-=(m);
01632 }
01633
01634
01635
01636
01637 template<typename eT>
01638 template<typename T1, typename op_type>
01639 inline
01640 const Mat<eT>&
01641 Mat<eT>::operator*=(const mtOp<eT, T1, op_type>& X)
01642 {
01643 arma_extra_debug_sigprint();
01644
01645 const Mat<eT> m(X);
01646
01647 return (*this).operator*=(m);
01648 }
01649
01650
01651
01652
01653 template<typename eT>
01654 template<typename T1, typename op_type>
01655 inline
01656 const Mat<eT>&
01657 Mat<eT>::operator%=(const mtOp<eT, T1, op_type>& X)
01658 {
01659 arma_extra_debug_sigprint();
01660
01661 const Mat<eT> m(X);
01662
01663 return (*this).operator%=(m);
01664 }
01665
01666
01667
01668
01669 template<typename eT>
01670 template<typename T1, typename op_type>
01671 inline
01672 const Mat<eT>&
01673 Mat<eT>::operator/=(const mtOp<eT, T1, op_type>& X)
01674 {
01675 arma_extra_debug_sigprint();
01676
01677 const Mat<eT> m(X);
01678
01679 return (*this).operator/=(m);
01680 }
01681
01682
01683
01684
01685 template<typename eT>
01686 template<typename T1, typename T2, typename glue_type>
01687 inline
01688 Mat<eT>::Mat(const Glue<T1, T2, glue_type>& X)
01689 : n_rows(0)
01690 , n_cols(0)
01691 , n_elem(0)
01692 , use_aux_mem(false)
01693
01694 , mem(mem)
01695 {
01696 arma_extra_debug_sigprint_this(this);
01697
01698 isnt_same_type<eT, typename T1::elem_type>::check();
01699 isnt_same_type<eT, typename T2::elem_type>::check();
01700
01701 glue_type::apply(*this, X);
01702 }
01703
01704
01705
01706
01707 template<typename eT>
01708 template<typename T1, typename T2, typename glue_type>
01709 inline
01710 const Mat<eT>&
01711 Mat<eT>::operator=(const Glue<T1, T2, glue_type>& X)
01712 {
01713 arma_extra_debug_sigprint();
01714
01715 isnt_same_type<eT, typename T1::elem_type>::check();
01716 isnt_same_type<eT, typename T2::elem_type>::check();
01717
01718 glue_type::apply(*this, X);
01719
01720 return *this;
01721 }
01722
01723
01724
01725
01726 template<typename eT>
01727 template<typename T1, typename T2, typename glue_type>
01728 inline
01729 const Mat<eT>&
01730 Mat<eT>::operator+=(const Glue<T1, T2, glue_type>& X)
01731 {
01732 arma_extra_debug_sigprint();
01733
01734 isnt_same_type<eT, typename T1::elem_type>::check();
01735 isnt_same_type<eT, typename T2::elem_type>::check();
01736
01737 const Mat<eT> m(X);
01738
01739 return (*this).operator+=(m);
01740 }
01741
01742
01743
01744
01745 template<typename eT>
01746 template<typename T1, typename T2, typename glue_type>
01747 inline
01748 const Mat<eT>&
01749 Mat<eT>::operator-=(const Glue<T1, T2, glue_type>& X)
01750 {
01751 arma_extra_debug_sigprint();
01752
01753 isnt_same_type<eT, typename T1::elem_type>::check();
01754 isnt_same_type<eT, typename T2::elem_type>::check();
01755
01756 const Mat<eT> m(X);
01757
01758 return (*this).operator-=(m);
01759 }
01760
01761
01762
01763
01764 template<typename eT>
01765 template<typename T1, typename T2, typename glue_type>
01766 inline
01767 const Mat<eT>&
01768 Mat<eT>::operator*=(const Glue<T1, T2, glue_type>& X)
01769 {
01770 arma_extra_debug_sigprint();
01771
01772 isnt_same_type<eT, typename T1::elem_type>::check();
01773 isnt_same_type<eT, typename T2::elem_type>::check();
01774
01775 glue_times::apply_inplace(*this, X);
01776
01777 return *this;
01778 }
01779
01780
01781
01782
01783 template<typename eT>
01784 template<typename T1, typename T2, typename glue_type>
01785 inline
01786 const Mat<eT>&
01787 Mat<eT>::operator%=(const Glue<T1, T2, glue_type>& X)
01788 {
01789 arma_extra_debug_sigprint();
01790
01791 isnt_same_type<eT, typename T1::elem_type>::check();
01792 isnt_same_type<eT, typename T2::elem_type>::check();
01793
01794 const Mat<eT> m(X);
01795
01796 return (*this).operator%=(m);
01797 }
01798
01799
01800
01801
01802 template<typename eT>
01803 template<typename T1, typename T2, typename glue_type>
01804 inline
01805 const Mat<eT>&
01806 Mat<eT>::operator/=(const Glue<T1, T2, glue_type>& X)
01807 {
01808 arma_extra_debug_sigprint();
01809
01810 isnt_same_type<eT, typename T1::elem_type>::check();
01811 isnt_same_type<eT, typename T2::elem_type>::check();
01812
01813 const Mat<eT> m(X);
01814
01815 return (*this).operator/=(m);
01816 }
01817
01818
01819
01820 template<typename eT>
01821 template<typename T1, typename T2>
01822 inline
01823 const Mat<eT>&
01824 Mat<eT>::operator+=(const Glue<T1, T2, glue_times>& X)
01825 {
01826 arma_extra_debug_sigprint();
01827
01828 glue_times::apply_inplace_plus(*this, X, s32(+1));
01829
01830 return *this;
01831 }
01832
01833
01834
01835 template<typename eT>
01836 template<typename T1, typename T2>
01837 inline
01838 const Mat<eT>&
01839 Mat<eT>::operator-=(const Glue<T1, T2, glue_times>& X)
01840 {
01841 arma_extra_debug_sigprint();
01842
01843 glue_times::apply_inplace_plus(*this, X, s32(-1));
01844
01845 return *this;
01846 }
01847
01848
01849
01850
01851 template<typename eT>
01852 template<typename T1, typename T2, typename eglue_type>
01853 inline
01854 Mat<eT>::Mat(const eGlue<T1, T2, eglue_type>& X)
01855 : n_rows(0)
01856 , n_cols(0)
01857 , n_elem(0)
01858 , use_aux_mem(false)
01859
01860 , mem(mem)
01861 {
01862 arma_extra_debug_sigprint_this(this);
01863
01864 isnt_same_type<eT, typename T1::elem_type>::check();
01865 isnt_same_type<eT, typename T2::elem_type>::check();
01866
01867 eglue_type::apply(*this, X);
01868 }
01869
01870
01871
01872
01873 template<typename eT>
01874 template<typename T1, typename T2, typename eglue_type>
01875 inline
01876 const Mat<eT>&
01877 Mat<eT>::operator=(const eGlue<T1, T2, eglue_type>& X)
01878 {
01879 arma_extra_debug_sigprint();
01880
01881 isnt_same_type<eT, typename T1::elem_type>::check();
01882 isnt_same_type<eT, typename T2::elem_type>::check();
01883
01884 eglue_type::apply(*this, X);
01885
01886 return *this;
01887 }
01888
01889
01890
01891
01892 template<typename eT>
01893 template<typename T1, typename T2, typename eglue_type>
01894 inline
01895 const Mat<eT>&
01896 Mat<eT>::operator+=(const eGlue<T1, T2, eglue_type>& X)
01897 {
01898 arma_extra_debug_sigprint();
01899
01900 isnt_same_type<eT, typename T1::elem_type>::check();
01901 isnt_same_type<eT, typename T2::elem_type>::check();
01902
01903 eglue_type::apply_inplace_plus(*this, X);
01904
01905 return *this;
01906 }
01907
01908
01909
01910
01911 template<typename eT>
01912 template<typename T1, typename T2, typename eglue_type>
01913 inline
01914 const Mat<eT>&
01915 Mat<eT>::operator-=(const eGlue<T1, T2, eglue_type>& X)
01916 {
01917 arma_extra_debug_sigprint();
01918
01919 isnt_same_type<eT, typename T1::elem_type>::check();
01920 isnt_same_type<eT, typename T2::elem_type>::check();
01921
01922 eglue_type::apply_inplace_minus(*this, X);
01923
01924 return *this;
01925 }
01926
01927
01928
01929 template<typename eT>
01930 template<typename T1, typename T2, typename eglue_type>
01931 inline
01932 const Mat<eT>&
01933 Mat<eT>::operator*=(const eGlue<T1, T2, eglue_type>& X)
01934 {
01935 arma_extra_debug_sigprint();
01936
01937 isnt_same_type<eT, typename T1::elem_type>::check();
01938 isnt_same_type<eT, typename T2::elem_type>::check();
01939
01940 glue_times::apply_inplace(*this, X);
01941 return *this;
01942 }
01943
01944
01945
01946 template<typename eT>
01947 template<typename T1, typename T2, typename eglue_type>
01948 inline
01949 const Mat<eT>&
01950 Mat<eT>::operator%=(const eGlue<T1, T2, eglue_type>& X)
01951 {
01952 arma_extra_debug_sigprint();
01953
01954 isnt_same_type<eT, typename T1::elem_type>::check();
01955 isnt_same_type<eT, typename T2::elem_type>::check();
01956
01957 eglue_type::apply_inplace_schur(*this, X);
01958 return *this;
01959 }
01960
01961
01962
01963 template<typename eT>
01964 template<typename T1, typename T2, typename eglue_type>
01965 inline
01966 const Mat<eT>&
01967 Mat<eT>::operator/=(const eGlue<T1, T2, eglue_type>& X)
01968 {
01969 arma_extra_debug_sigprint();
01970
01971 isnt_same_type<eT, typename T1::elem_type>::check();
01972 isnt_same_type<eT, typename T2::elem_type>::check();
01973
01974 eglue_type::apply_inplace_div(*this, X);
01975 return *this;
01976 }
01977
01978
01979
01980
01981 template<typename eT>
01982 template<typename T1, typename T2, typename glue_type>
01983 inline
01984 Mat<eT>::Mat(const mtGlue<eT, T1, T2, glue_type>& X)
01985 : n_rows(0)
01986 , n_cols(0)
01987 , n_elem(0)
01988 , use_aux_mem(false)
01989
01990 , mem(mem)
01991 {
01992 arma_extra_debug_sigprint_this(this);
01993
01994 glue_type::apply(*this, X);
01995 }
01996
01997
01998
01999
02000 template<typename eT>
02001 template<typename T1, typename T2, typename glue_type>
02002 inline
02003 const Mat<eT>&
02004 Mat<eT>::operator=(const mtGlue<eT, T1, T2, glue_type>& X)
02005 {
02006 arma_extra_debug_sigprint();
02007
02008 glue_type::apply(*this, X);
02009
02010 return *this;
02011 }
02012
02013
02014
02015
02016 template<typename eT>
02017 template<typename T1, typename T2, typename glue_type>
02018 inline
02019 const Mat<eT>&
02020 Mat<eT>::operator+=(const mtGlue<eT, T1, T2, glue_type>& X)
02021 {
02022 arma_extra_debug_sigprint();
02023
02024 const Mat<eT> m(X);
02025
02026 return (*this).operator+=(m);
02027 }
02028
02029
02030
02031
02032 template<typename eT>
02033 template<typename T1, typename T2, typename glue_type>
02034 inline
02035 const Mat<eT>&
02036 Mat<eT>::operator-=(const mtGlue<eT, T1, T2, glue_type>& X)
02037 {
02038 arma_extra_debug_sigprint();
02039
02040 const Mat<eT> m(X);
02041
02042 return (*this).operator-=(m);
02043 }
02044
02045
02046
02047
02048 template<typename eT>
02049 template<typename T1, typename T2, typename glue_type>
02050 inline
02051 const Mat<eT>&
02052 Mat<eT>::operator*=(const mtGlue<eT, T1, T2, glue_type>& X)
02053 {
02054 arma_extra_debug_sigprint();
02055
02056 const Mat<eT> m(X);
02057
02058 glue_times::apply_inplace(*this, m);
02059
02060 return *this;
02061 }
02062
02063
02064
02065
02066 template<typename eT>
02067 template<typename T1, typename T2, typename glue_type>
02068 inline
02069 const Mat<eT>&
02070 Mat<eT>::operator%=(const mtGlue<eT, T1, T2, glue_type>& X)
02071 {
02072 arma_extra_debug_sigprint();
02073
02074 const Mat<eT> m(X);
02075
02076 return (*this).operator%=(m);
02077 }
02078
02079
02080
02081
02082 template<typename eT>
02083 template<typename T1, typename T2, typename glue_type>
02084 inline
02085 const Mat<eT>&
02086 Mat<eT>::operator/=(const mtGlue<eT, T1, T2, glue_type>& X)
02087 {
02088 arma_extra_debug_sigprint();
02089
02090 const Mat<eT> m(X);
02091
02092 return (*this).operator/=(m);
02093 }
02094
02095
02096
02097
02098 template<typename eT>
02099 arma_inline
02100 eT&
02101 Mat<eT>::operator() (const u32 i)
02102 {
02103 arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds");
02104 return access::rw(mem[i]);
02105 }
02106
02107
02108
02109
02110 template<typename eT>
02111 arma_inline
02112 eT
02113 Mat<eT>::operator() (const u32 i) const
02114 {
02115 arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds");
02116 return mem[i];
02117 }
02118
02119
02120
02121 template<typename eT>
02122 arma_inline
02123 eT&
02124 Mat<eT>::operator[] (const u32 i)
02125 {
02126 return access::rw(mem[i]);
02127 }
02128
02129
02130
02131
02132 template<typename eT>
02133 arma_inline
02134 eT
02135 Mat<eT>::operator[] (const u32 i) const
02136 {
02137 return mem[i];
02138 }
02139
02140
02141
02142
02143 template<typename eT>
02144 arma_inline
02145 eT&
02146 Mat<eT>::operator() (const u32 in_row, const u32 in_col)
02147 {
02148 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): out of bounds");
02149 return access::rw(mem[in_row + in_col*n_rows]);
02150 }
02151
02152
02153
02154
02155 template<typename eT>
02156 arma_inline
02157 eT
02158 Mat<eT>::operator() (const u32 in_row, const u32 in_col) const
02159 {
02160 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): out of bounds");
02161 return mem[in_row + in_col*n_rows];
02162 }
02163
02164
02165
02166
02167 template<typename eT>
02168 arma_inline
02169 eT&
02170 Mat<eT>::at(const u32 in_row, const u32 in_col)
02171 {
02172 return access::rw( mem[in_row + in_col*n_rows] );
02173 }
02174
02175
02176
02177
02178 template<typename eT>
02179 arma_inline
02180 eT
02181 Mat<eT>::at(const u32 in_row, const u32 in_col) const
02182 {
02183 return mem[in_row + in_col*n_rows];
02184 }
02185
02186
02187
02188
02189 template<typename eT>
02190 arma_inline
02191 const Mat<eT>&
02192 Mat<eT>::operator++()
02193 {
02194 Mat_aux::prefix_pp(*this);
02195 return *this;
02196 }
02197
02198
02199
02200
02201 template<typename eT>
02202 arma_inline
02203 void
02204 Mat<eT>::operator++(int)
02205 {
02206 Mat_aux::postfix_pp(*this);
02207 }
02208
02209
02210
02211
02212 template<typename eT>
02213 arma_inline
02214 const Mat<eT>&
02215 Mat<eT>::operator--()
02216 {
02217 Mat_aux::prefix_mm(*this);
02218 return *this;
02219 }
02220
02221
02222
02223
02224 template<typename eT>
02225 arma_inline
02226 void
02227 Mat<eT>::operator--(int)
02228 {
02229 Mat_aux::postfix_mm(*this);
02230 }
02231
02232
02233
02234
02235 template<typename eT>
02236 arma_inline
02237 bool
02238 Mat<eT>::is_vec() const
02239 {
02240 return ( (n_rows == 1) || (n_cols == 1) );
02241 }
02242
02243
02244
02245
02246 template<typename eT>
02247 arma_inline
02248 bool
02249 Mat<eT>::is_square() const
02250 {
02251 return ( (n_rows == n_cols) && (n_elem > 0) );
02252 }
02253
02254
02255
02256
02257 template<typename eT>
02258 arma_inline
02259 bool
02260 Mat<eT>::is_finite() const
02261 {
02262 for(u32 i=0; i<n_elem; ++i)
02263 {
02264 if(arma_isfinite(mem[i]) == false)
02265 {
02266 return false;
02267 }
02268 }
02269
02270 return true;
02271 }
02272
02273
02274
02275
02276 template<typename eT>
02277 arma_inline
02278 eT*
02279 Mat<eT>::colptr(const u32 in_col)
02280 {
02281 return & access::rw(mem[in_col*n_rows]);
02282 }
02283
02284
02285
02286
02287 template<typename eT>
02288 arma_inline
02289 const eT*
02290 Mat<eT>::colptr(const u32 in_col) const
02291 {
02292 return & mem[in_col*n_rows];
02293 }
02294
02295
02296
02297
02298 template<typename eT>
02299 arma_inline
02300 eT*
02301 Mat<eT>::memptr()
02302 {
02303 return const_cast<eT*>(mem);
02304 }
02305
02306
02307
02308
02309 template<typename eT>
02310 arma_inline
02311 const eT*
02312 Mat<eT>::memptr() const
02313 {
02314 return mem;
02315 }
02316
02317
02318
02319
02320
02321
02322
02323 template<typename eT>
02324 inline
02325 void
02326 Mat<eT>::print(const std::string extra_text) const
02327 {
02328 arma_extra_debug_sigprint();
02329
02330 if(extra_text.length() != 0)
02331 {
02332 const std::streamsize orig_width = cout.width();
02333
02334 cout << extra_text << '\n';
02335
02336 cout.width(orig_width);
02337 }
02338
02339 arma_ostream::print(cout, *this, true);
02340 }
02341
02342
02343
02344
02345
02346
02347
02348 template<typename eT>
02349 inline
02350 void
02351 Mat<eT>::print(std::ostream& user_stream, const std::string extra_text) const
02352 {
02353 arma_extra_debug_sigprint();
02354
02355 if(extra_text.length() != 0)
02356 {
02357 const std::streamsize orig_width = user_stream.width();
02358
02359 user_stream << extra_text << '\n';
02360
02361 user_stream.width(orig_width);
02362 }
02363
02364 arma_ostream::print(user_stream, *this, true);
02365 }
02366
02367
02368
02369
02370
02371
02372
02373 template<typename eT>
02374 inline
02375 void
02376 Mat<eT>::print_trans(const std::string extra_text) const
02377 {
02378 arma_extra_debug_sigprint();
02379
02380 Mat<eT> tmp;
02381 op_trans::apply_noalias(tmp, *this);
02382
02383 tmp.print(extra_text);
02384 }
02385
02386
02387
02388
02389
02390
02391
02392 template<typename eT>
02393 inline
02394 void
02395 Mat<eT>::print_trans(std::ostream& user_stream, const std::string extra_text) const
02396 {
02397 arma_extra_debug_sigprint();
02398
02399 Mat<eT> tmp;
02400 op_trans::apply_noalias(tmp, *this);
02401
02402 tmp.print(user_stream, extra_text);
02403 }
02404
02405
02406
02407
02408
02409
02410
02411 template<typename eT>
02412 inline
02413 void
02414 Mat<eT>::raw_print(const std::string extra_text) const
02415 {
02416 arma_extra_debug_sigprint();
02417
02418 if(extra_text.length() != 0)
02419 {
02420 const std::streamsize orig_width = cout.width();
02421
02422 cout << extra_text << '\n';
02423
02424 cout.width(orig_width);
02425 }
02426
02427 arma_ostream::print(cout, *this, false);
02428 }
02429
02430
02431
02432
02433
02434
02435
02436 template<typename eT>
02437 inline
02438 void
02439 Mat<eT>::raw_print(std::ostream& user_stream, const std::string extra_text) const
02440 {
02441 arma_extra_debug_sigprint();
02442
02443 if(extra_text.length() != 0)
02444 {
02445 const std::streamsize orig_width = user_stream.width();
02446
02447 user_stream << extra_text << '\n';
02448
02449 user_stream.width(orig_width);
02450 }
02451
02452 arma_ostream::print(user_stream, *this, false);
02453 }
02454
02455
02456
02457
02458
02459
02460
02461 template<typename eT>
02462 inline
02463 void
02464 Mat<eT>::raw_print_trans(const std::string extra_text) const
02465 {
02466 arma_extra_debug_sigprint();
02467
02468 Mat<eT> tmp;
02469 op_trans::apply_noalias(tmp, *this);
02470
02471 tmp.raw_print(extra_text);
02472 }
02473
02474
02475
02476
02477
02478
02479
02480 template<typename eT>
02481 inline
02482 void
02483 Mat<eT>::raw_print_trans(std::ostream& user_stream, const std::string extra_text) const
02484 {
02485 arma_extra_debug_sigprint();
02486
02487 Mat<eT> tmp;
02488 op_trans::apply_noalias(tmp, *this);
02489
02490 tmp.raw_print(user_stream, extra_text);
02491 }
02492
02493
02494
02495
02496 template<typename eT>
02497 inline
02498 void
02499 Mat<eT>::set_size(const u32 in_n_rows, const u32 in_n_cols)
02500 {
02501 arma_extra_debug_sigprint();
02502
02503 init(in_n_rows, in_n_cols);
02504 }
02505
02506
02507
02508
02509 template<typename eT>
02510 template<typename eT2>
02511 inline
02512 void
02513 Mat<eT>::copy_size(const Mat<eT2>& m)
02514 {
02515 arma_extra_debug_sigprint();
02516
02517 init(m.n_rows, m.n_cols);
02518 }
02519
02520
02521
02522
02523 template<typename eT>
02524 arma_hot
02525 inline
02526 void
02527 Mat<eT>::fill(const eT val)
02528 {
02529 arma_extra_debug_sigprint();
02530
02531 eT* local_ptr = memptr();
02532 const u32 local_n_elem = n_elem;
02533
02534 u32 i,j;
02535
02536 for(i=0, j=1; j<local_n_elem; i+=2, j+=2)
02537 {
02538 local_ptr[i] = val;
02539 local_ptr[j] = val;
02540 }
02541
02542 if(i < local_n_elem)
02543 {
02544 local_ptr[i] = val;
02545 }
02546 }
02547
02548
02549
02550 template<typename eT>
02551 inline
02552 void
02553 Mat<eT>::zeros()
02554 {
02555 arma_extra_debug_sigprint();
02556
02557 fill(eT(0));
02558 }
02559
02560
02561
02562 template<typename eT>
02563 inline
02564 void
02565 Mat<eT>::zeros(const u32 in_rows, const u32 in_cols)
02566 {
02567 arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d") % in_rows % in_cols );
02568
02569 set_size(in_rows, in_cols);
02570 fill(eT(0));
02571 }
02572
02573
02574
02575 template<typename eT>
02576 inline
02577 void
02578 Mat<eT>::ones()
02579 {
02580 arma_extra_debug_sigprint();
02581
02582 fill(eT(1));
02583 }
02584
02585
02586
02587 template<typename eT>
02588 inline
02589 void
02590 Mat<eT>::ones(const u32 in_rows, const u32 in_cols)
02591 {
02592 arma_extra_debug_sigprint( arma_boost::format("in_rows = %d, in_cols = %d") % in_rows % in_cols );
02593
02594 set_size(in_rows, in_cols);
02595 fill(eT(1));
02596 }
02597
02598
02599
02600 template<typename eT>
02601 inline
02602 void
02603 Mat<eT>::reset()
02604 {
02605 arma_extra_debug_sigprint();
02606
02607 init(0,0);
02608 }
02609
02610
02611
02612
02613 template<typename eT>
02614 inline
02615 bool
02616 Mat<eT>::save(const std::string name, const file_type type, const bool print_status) const
02617 {
02618 arma_extra_debug_sigprint();
02619
02620 bool save_okay;
02621
02622 switch(type)
02623 {
02624 case raw_ascii:
02625 save_okay = diskio::save_raw_ascii(*this, name);
02626 break;
02627
02628 case arma_ascii:
02629 save_okay = diskio::save_arma_ascii(*this, name);
02630 break;
02631
02632 case arma_binary:
02633 save_okay = diskio::save_arma_binary(*this, name);
02634 break;
02635
02636 case pgm_binary:
02637 save_okay = diskio::save_pgm_binary(*this, name);
02638 break;
02639
02640 default:
02641 arma_warn(print_status, "Mat::save(): unsupported file type");
02642 save_okay = false;
02643 }
02644
02645 arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't write to ", name);
02646
02647 return save_okay;
02648 }
02649
02650
02651
02652
02653 template<typename eT>
02654 inline
02655 bool
02656 Mat<eT>::save(std::ostream& os, const file_type type, const bool print_status) const
02657 {
02658 arma_extra_debug_sigprint();
02659
02660 bool save_okay;
02661
02662 switch(type)
02663 {
02664 case raw_ascii:
02665 save_okay = diskio::save_raw_ascii(*this, os);
02666 break;
02667
02668 case arma_ascii:
02669 save_okay = diskio::save_arma_ascii(*this, os);
02670 break;
02671
02672 case arma_binary:
02673 save_okay = diskio::save_arma_binary(*this, os);
02674 break;
02675
02676 case pgm_binary:
02677 save_okay = diskio::save_pgm_binary(*this, os);
02678 break;
02679
02680 default:
02681 arma_warn(print_status, "Mat::save(): unsupported file type");
02682 save_okay = false;
02683 }
02684
02685 arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't write to the given stream");
02686
02687 return save_okay;
02688 }
02689
02690
02691
02692
02693 template<typename eT>
02694 inline
02695 bool
02696 Mat<eT>::load(const std::string name, const file_type type, const bool print_status)
02697 {
02698 arma_extra_debug_sigprint();
02699
02700 bool load_okay;
02701 std::string err_msg;
02702
02703 switch(type)
02704 {
02705 case auto_detect:
02706 load_okay = diskio::load_auto_detect(*this, name, err_msg);
02707 break;
02708
02709 case raw_ascii:
02710 load_okay = diskio::load_raw_ascii(*this, name, err_msg);
02711 break;
02712
02713 case arma_ascii:
02714 load_okay = diskio::load_arma_ascii(*this, name, err_msg);
02715 break;
02716
02717 case arma_binary:
02718 load_okay = diskio::load_arma_binary(*this, name, err_msg);
02719 break;
02720
02721 case pgm_binary:
02722 load_okay = diskio::load_pgm_binary(*this, name, err_msg);
02723 break;
02724
02725 default:
02726 arma_warn(print_status, "Mat::load(): unsupported file type");
02727 load_okay = false;
02728 }
02729
02730 if( (print_status == true) && (load_okay == false) )
02731 {
02732 if(err_msg.length() > 0)
02733 {
02734 arma_print("Mat::load(): ", err_msg, name);
02735 }
02736 else
02737 {
02738 arma_print("Mat::load(): couldn't read ", name);
02739 }
02740 }
02741
02742 if(load_okay == false)
02743 {
02744 (*this).reset();
02745 }
02746
02747 return load_okay;
02748 }
02749
02750
02751
02752
02753 template<typename eT>
02754 inline
02755 bool
02756 Mat<eT>::load(std::istream& is, const file_type type, const bool print_status)
02757 {
02758 arma_extra_debug_sigprint();
02759
02760 bool load_okay;
02761 std::string err_msg;
02762
02763 switch(type)
02764 {
02765 case auto_detect:
02766 load_okay = diskio::load_auto_detect(*this, is, err_msg);
02767 break;
02768
02769 case raw_ascii:
02770 load_okay = diskio::load_raw_ascii(*this, is, err_msg);
02771 break;
02772
02773 case arma_ascii:
02774 load_okay = diskio::load_arma_ascii(*this, is, err_msg);
02775 break;
02776
02777 case arma_binary:
02778 load_okay = diskio::load_arma_binary(*this, is, err_msg);
02779 break;
02780
02781 case pgm_binary:
02782 load_okay = diskio::load_pgm_binary(*this, is, err_msg);
02783 break;
02784
02785 default:
02786 arma_warn(print_status, "Mat::load(): unsupported file type");
02787 load_okay = false;
02788 }
02789
02790
02791 if( (print_status == true) && (load_okay == false) )
02792 {
02793 if(err_msg.length() > 0)
02794 {
02795 arma_print("Mat::load(): ", err_msg, "the given stream");
02796 }
02797 else
02798 {
02799 arma_print("Mat::load(): couldn't load from the given stream");
02800 }
02801 }
02802
02803 if(load_okay == false)
02804 {
02805 (*this).reset();
02806 }
02807
02808 return load_okay;
02809 }
02810
02811
02812
02813
02814 template<typename eT>
02815 inline
02816 bool
02817 Mat<eT>::quiet_save(const std::string name, const file_type type) const
02818 {
02819 arma_extra_debug_sigprint();
02820
02821 return (*this).save(name, type, false);
02822 }
02823
02824
02825
02826
02827 template<typename eT>
02828 inline
02829 bool
02830 Mat<eT>::quiet_save(std::ostream& os, const file_type type) const
02831 {
02832 arma_extra_debug_sigprint();
02833
02834 return (*this).save(os, type, false);
02835 }
02836
02837
02838
02839
02840 template<typename eT>
02841 inline
02842 bool
02843 Mat<eT>::quiet_load(const std::string name, const file_type type)
02844 {
02845 arma_extra_debug_sigprint();
02846
02847 return (*this).load(name, type, false);
02848 }
02849
02850
02851
02852
02853 template<typename eT>
02854 inline
02855 bool
02856 Mat<eT>::quiet_load(std::istream& is, const file_type type)
02857 {
02858 arma_extra_debug_sigprint();
02859
02860 return (*this).load(is, type, false);
02861 }
02862
02863
02864
02865 template<typename eT>
02866 inline
02867 Mat<eT>::row_iterator::row_iterator(Mat<eT>& in_M, const u32 in_row)
02868 : M (in_M )
02869 , row(in_row)
02870 , col(0 )
02871 {
02872 arma_extra_debug_sigprint();
02873 }
02874
02875
02876
02877 template<typename eT>
02878 inline
02879 eT&
02880 Mat<eT>::row_iterator::operator*()
02881 {
02882 return M.at(row,col);
02883 }
02884
02885
02886
02887 template<typename eT>
02888 inline
02889 typename Mat<eT>::row_iterator&
02890 Mat<eT>::row_iterator::operator++()
02891 {
02892 ++col;
02893
02894 if(col >= M.n_cols)
02895 {
02896 col = 0;
02897 ++row;
02898 }
02899
02900 return *this;
02901 }
02902
02903
02904
02905 template<typename eT>
02906 inline
02907 void
02908 Mat<eT>::row_iterator::operator++(int)
02909 {
02910 operator++();
02911 }
02912
02913
02914
02915 template<typename eT>
02916 inline
02917 typename Mat<eT>::row_iterator&
02918 Mat<eT>::row_iterator::operator--()
02919 {
02920 if(col > 0)
02921 {
02922 --col;
02923 }
02924 else
02925 {
02926 if(row > 0)
02927 {
02928 col = M.n_cols - 1;
02929 --row;
02930 }
02931 }
02932
02933 return *this;
02934 }
02935
02936
02937
02938 template<typename eT>
02939 inline
02940 void
02941 Mat<eT>::row_iterator::operator--(int)
02942 {
02943 operator--();
02944 }
02945
02946
02947
02948 template<typename eT>
02949 inline
02950 bool
02951 Mat<eT>::row_iterator::operator!=(const typename Mat<eT>::row_iterator& X) const
02952 {
02953 return ( (row != X.row) || (col != X.col) ) ? true : false;
02954 }
02955
02956
02957
02958 template<typename eT>
02959 inline
02960 bool
02961 Mat<eT>::row_iterator::operator==(const typename Mat<eT>::row_iterator& X) const
02962 {
02963 return ( (row == X.row) && (col == X.col) ) ? true : false;
02964 }
02965
02966
02967
02968 template<typename eT>
02969 inline
02970 Mat<eT>::const_row_iterator::const_row_iterator(const Mat<eT>& in_M, const u32 in_row)
02971 : M (in_M )
02972 , row(in_row)
02973 , col(0 )
02974 {
02975 arma_extra_debug_sigprint();
02976 }
02977
02978
02979
02980 template<typename eT>
02981 inline
02982 Mat<eT>::const_row_iterator::const_row_iterator(const typename Mat<eT>::row_iterator& X)
02983 : M (X.M)
02984 , row(X.row)
02985 , col(X.col)
02986 {
02987 arma_extra_debug_sigprint();
02988 }
02989
02990
02991
02992 template<typename eT>
02993 inline
02994 eT
02995 Mat<eT>::const_row_iterator::operator*() const
02996 {
02997 return M.at(row,col);
02998 }
02999
03000
03001
03002 template<typename eT>
03003 inline
03004 typename Mat<eT>::const_row_iterator&
03005 Mat<eT>::const_row_iterator::operator++()
03006 {
03007 ++col;
03008
03009 if(col >= M.n_cols)
03010 {
03011 col = 0;
03012 ++row;
03013 }
03014
03015 return *this;
03016 }
03017
03018
03019
03020 template<typename eT>
03021 inline
03022 void
03023 Mat<eT>::const_row_iterator::operator++(int)
03024 {
03025 operator++();
03026 }
03027
03028
03029
03030 template<typename eT>
03031 inline
03032 typename Mat<eT>::const_row_iterator&
03033 Mat<eT>::const_row_iterator::operator--()
03034 {
03035 if(col > 0)
03036 {
03037 --col;
03038 }
03039 else
03040 {
03041 if(row > 0)
03042 {
03043 col = M.n_cols - 1;
03044 --row;
03045 }
03046 }
03047
03048 return *this;
03049 }
03050
03051
03052
03053 template<typename eT>
03054 inline
03055 void
03056 Mat<eT>::const_row_iterator::operator--(int)
03057 {
03058 operator--();
03059 }
03060
03061
03062
03063 template<typename eT>
03064 inline
03065 bool
03066 Mat<eT>::const_row_iterator::operator!=(const typename Mat<eT>::const_row_iterator& X) const
03067 {
03068 return ( (row != X.row) || (col != X.col) ) ? true : false;
03069 }
03070
03071
03072
03073 template<typename eT>
03074 inline
03075 bool
03076 Mat<eT>::const_row_iterator::operator==(const typename Mat<eT>::const_row_iterator& X) const
03077 {
03078 return ( (row == X.row) && (col == X.col) ) ? true : false;
03079 }
03080
03081
03082
03083 template<typename eT>
03084 inline
03085 typename Mat<eT>::iterator
03086 Mat<eT>::begin()
03087 {
03088 arma_extra_debug_sigprint();
03089
03090 return memptr();
03091 }
03092
03093
03094
03095 template<typename eT>
03096 inline
03097 typename Mat<eT>::const_iterator
03098 Mat<eT>::begin() const
03099 {
03100 arma_extra_debug_sigprint();
03101
03102 return memptr();
03103 }
03104
03105
03106
03107 template<typename eT>
03108 inline
03109 typename Mat<eT>::iterator
03110 Mat<eT>::end()
03111 {
03112 arma_extra_debug_sigprint();
03113
03114 return memptr() + n_elem;
03115 }
03116
03117
03118
03119 template<typename eT>
03120 inline
03121 typename Mat<eT>::const_iterator
03122 Mat<eT>::end() const
03123 {
03124 arma_extra_debug_sigprint();
03125
03126 return memptr() + n_elem;
03127 }
03128
03129
03130
03131 template<typename eT>
03132 inline
03133 typename Mat<eT>::col_iterator
03134 Mat<eT>::begin_col(const u32 col_num)
03135 {
03136 arma_extra_debug_sigprint();
03137
03138 arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds");
03139
03140 return colptr(col_num);
03141 }
03142
03143
03144
03145 template<typename eT>
03146 inline
03147 typename Mat<eT>::const_col_iterator
03148 Mat<eT>::begin_col(const u32 col_num) const
03149 {
03150 arma_extra_debug_sigprint();
03151
03152 arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds");
03153
03154 return colptr(col_num);
03155 }
03156
03157
03158
03159 template<typename eT>
03160 inline
03161 typename Mat<eT>::col_iterator
03162 Mat<eT>::end_col(const u32 col_num)
03163 {
03164 arma_extra_debug_sigprint();
03165
03166 arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds");
03167
03168 return colptr(col_num) + n_rows;
03169 }
03170
03171
03172
03173 template<typename eT>
03174 inline
03175 typename Mat<eT>::const_col_iterator
03176 Mat<eT>::end_col(const u32 col_num) const
03177 {
03178 arma_extra_debug_sigprint();
03179
03180 arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds");
03181
03182 return colptr(col_num) + n_rows;
03183 }
03184
03185
03186
03187 template<typename eT>
03188 inline
03189 typename Mat<eT>::row_iterator
03190 Mat<eT>::begin_row(const u32 row_num)
03191 {
03192 arma_extra_debug_sigprint();
03193
03194 arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" );
03195
03196 return typename Mat<eT>::row_iterator(*this, row_num);
03197 }
03198
03199
03200
03201 template<typename eT>
03202 inline
03203 typename Mat<eT>::const_row_iterator
03204 Mat<eT>::begin_row(const u32 row_num) const
03205 {
03206 arma_extra_debug_sigprint();
03207
03208 arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" );
03209
03210 return typename Mat<eT>::const_row_iterator(*this, row_num);
03211 }
03212
03213
03214
03215 template<typename eT>
03216 inline
03217 typename Mat<eT>::row_iterator
03218 Mat<eT>::end_row(const u32 row_num)
03219 {
03220 arma_extra_debug_sigprint();
03221
03222 arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" );
03223
03224 return typename Mat<eT>::row_iterator(*this, row_num + 1);
03225 }
03226
03227
03228
03229 template<typename eT>
03230 inline
03231 typename Mat<eT>::const_row_iterator
03232 Mat<eT>::end_row(const u32 row_num) const
03233 {
03234 arma_extra_debug_sigprint();
03235
03236 arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" );
03237
03238 return typename Mat<eT>::const_row_iterator(*this, row_num + 1);
03239 }
03240
03241
03242
03243
03244 template<typename eT>
03245 arma_inline
03246 void
03247 Mat_aux::prefix_pp(Mat<eT>& x)
03248 {
03249 eT* memptr = x.memptr();
03250 const u32 n_elem = x.n_elem;
03251
03252 u32 i,j;
03253
03254 for(i=0, j=1; j<n_elem; i+=2, j+=2)
03255 {
03256 ++(memptr[i]);
03257 ++(memptr[j]);
03258 }
03259
03260 if(i < n_elem)
03261 {
03262 ++(memptr[i]);
03263 }
03264 }
03265
03266
03267
03268
03269 template<typename T>
03270 arma_inline
03271 void
03272 Mat_aux::prefix_pp(Mat< std::complex<T> >& x)
03273 {
03274 x += T(1);
03275 }
03276
03277
03278
03279
03280 template<typename eT>
03281 arma_inline
03282 void
03283 Mat_aux::postfix_pp(Mat<eT>& x)
03284 {
03285 eT* memptr = x.memptr();
03286 const u32 n_elem = x.n_elem;
03287
03288 u32 i,j;
03289
03290 for(i=0, j=1; j<n_elem; i+=2, j+=2)
03291 {
03292 (memptr[i])++;
03293 (memptr[j])++;
03294 }
03295
03296 if(i < n_elem)
03297 {
03298 (memptr[i])++;
03299 }
03300 }
03301
03302
03303
03304
03305 template<typename T>
03306 arma_inline
03307 void
03308 Mat_aux::postfix_pp(Mat< std::complex<T> >& x)
03309 {
03310 x += T(1);
03311 }
03312
03313
03314
03315
03316 template<typename eT>
03317 arma_inline
03318 void
03319 Mat_aux::prefix_mm(Mat<eT>& x)
03320 {
03321 eT* memptr = x.memptr();
03322 const u32 n_elem = x.n_elem;
03323
03324 u32 i,j;
03325
03326 for(i=0, j=1; j<n_elem; i+=2, j+=2)
03327 {
03328 --(memptr[i]);
03329 --(memptr[j]);
03330 }
03331
03332 if(i < n_elem)
03333 {
03334 --(memptr[i]);
03335 }
03336 }
03337
03338
03339
03340
03341 template<typename T>
03342 arma_inline
03343 void
03344 Mat_aux::prefix_mm(Mat< std::complex<T> >& x)
03345 {
03346 x -= T(1);
03347 }
03348
03349
03350
03351
03352 template<typename eT>
03353 arma_inline
03354 void
03355 Mat_aux::postfix_mm(Mat<eT>& x)
03356 {
03357 eT* memptr = x.memptr();
03358 const u32 n_elem = x.n_elem;
03359
03360 u32 i,j;
03361
03362 for(i=0, j=1; j<n_elem; i+=2, j+=2)
03363 {
03364 (memptr[i])--;
03365 (memptr[j])--;
03366 }
03367
03368 if(i < n_elem)
03369 {
03370 (memptr[i])--;
03371 }
03372 }
03373
03374
03375
03376
03377 template<typename T>
03378 arma_inline
03379 void
03380 Mat_aux::postfix_mm(Mat< std::complex<T> >& x)
03381 {
03382 x -= T(1);
03383 }
03384
03385
03386
03387