$search
00001 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) 00002 // Copyright (C) 2008-2011 Conrad Sanderson 00003 // 00004 // This file is part of the Armadillo C++ library. 00005 // It is provided without any warranty of fitness 00006 // for any purpose. You can redistribute this file 00007 // and/or modify it under the terms of the GNU 00008 // Lesser General Public License (LGPL) as published 00009 // by the Free Software Foundation, either version 3 00010 // of the License or (at your option) any later version. 00011 // (see http://www.opensource.org/licenses for more info) 00012 00013 00016 00017 00018 template<typename eT> 00019 inline 00020 Mat<eT>::~Mat() 00021 { 00022 arma_extra_debug_sigprint_this(this); 00023 00024 if(mem_state == 0) 00025 { 00026 if(n_elem > arma_config::mat_prealloc) 00027 { 00028 #if defined(ARMA_USE_TBB_ALLOC) 00029 scalable_free((void *)(mem)); 00030 #else 00031 delete [] mem; 00032 #endif 00033 } 00034 } 00035 00036 if(arma_config::debug == true) 00037 { 00038 // try to expose buggy user code that accesses deleted objects 00039 access::rw(n_rows) = 0; 00040 access::rw(n_cols) = 0; 00041 access::rw(n_elem) = 0; 00042 access::rw(mem) = 0; 00043 } 00044 00045 arma_type_check(( is_supported_elem_type<eT>::value == false )); 00046 } 00047 00048 00049 00050 template<typename eT> 00051 inline 00052 Mat<eT>::Mat() 00053 : n_rows(0) 00054 , n_cols(0) 00055 , n_elem(0) 00056 , vec_state(0) 00057 , mem_state(0) 00058 , mem() 00059 { 00060 arma_extra_debug_sigprint_this(this); 00061 } 00062 00063 00064 00066 template<typename eT> 00067 inline 00068 Mat<eT>::Mat(const uword in_n_rows, const uword in_n_cols) 00069 : n_rows(in_n_rows) 00070 , n_cols(in_n_cols) 00071 , n_elem(in_n_rows*in_n_cols) 00072 , vec_state(0) 00073 , mem_state(0) 00074 , mem() 00075 { 00076 arma_extra_debug_sigprint_this(this); 00077 00078 init_cold(); 00079 } 00080 00081 00082 00083 template<typename eT> 00084 inline 00085 void 00086 Mat<eT>::init_cold() 00087 { 00088 arma_extra_debug_sigprint( arma_boost::format("n_rows = %d, n_cols = %d") % n_rows % n_cols ); 00089 00090 // ensure that n_elem can hold the result of (n_rows * n_cols) 00091 00092 arma_debug_check 00093 ( 00094 ( 00095 ( (n_rows > ARMA_MAX_UHWORD) || (n_cols > ARMA_MAX_UHWORD) ) 00096 ? ( (float(n_rows) * float(n_cols)) > float(ARMA_MAX_UWORD) ) 00097 : false 00098 ), 00099 "Mat::init(): requested size is too large" 00100 ); 00101 00102 if(n_elem <= arma_config::mat_prealloc) 00103 { 00104 access::rw(mem) = mem_local; 00105 } 00106 else 00107 { 00108 arma_extra_debug_print("Mat::init(): allocating memory"); 00109 00110 #if defined(ARMA_USE_TBB_ALLOC) 00111 access::rw(mem) = (eT *) scalable_malloc(sizeof(eT)*n_elem); 00112 #else 00113 access::rw(mem) = new(std::nothrow) eT[n_elem]; 00114 #endif 00115 00116 arma_check_bad_alloc( (mem == 0), "Mat::init(): out of memory" ); 00117 } 00118 } 00119 00120 00121 00123 template<typename eT> 00124 inline 00125 void 00126 Mat<eT>::init_warm(uword in_n_rows, uword in_n_cols) 00127 { 00128 arma_extra_debug_sigprint( arma_boost::format("in_n_rows = %d, in_n_cols = %d") % in_n_rows % in_n_cols ); 00129 00130 if( (n_rows == in_n_rows) && (n_cols == in_n_cols) ) 00131 { 00132 return; 00133 } 00134 00135 bool err_state = false; 00136 char* err_msg = 0; 00137 00138 const uhword t_vec_state = vec_state; 00139 const uhword t_mem_state = mem_state; 00140 00141 arma_debug_set_error 00142 ( 00143 err_state, 00144 err_msg, 00145 (t_mem_state == 3), 00146 "Mat::init(): size is fixed and hence cannot be changed" 00147 ); 00148 00149 if(t_vec_state > 0) 00150 { 00151 if( (in_n_rows == 0) && (in_n_cols == 0) ) 00152 { 00153 if(t_vec_state == 1) 00154 { 00155 in_n_cols = 1; 00156 } 00157 else 00158 if(t_vec_state == 2) 00159 { 00160 in_n_rows = 1; 00161 } 00162 } 00163 else 00164 { 00165 arma_debug_set_error 00166 ( 00167 err_state, 00168 err_msg, 00169 ( ((t_vec_state == 1) && (in_n_cols != 1)) || ((t_vec_state == 2) && (in_n_rows != 1)) ), 00170 "Mat::init(): object is a vector; requested size is not compatible" 00171 ); 00172 } 00173 } 00174 00175 // ensure that n_elem can hold the result of (n_rows * n_cols) 00176 00177 arma_debug_set_error 00178 ( 00179 err_state, 00180 err_msg, 00181 ( 00182 ( (in_n_rows > ARMA_MAX_UHWORD) || (in_n_cols > ARMA_MAX_UHWORD) ) 00183 ? ( (float(in_n_rows) * float(in_n_cols)) > float(ARMA_MAX_UWORD) ) 00184 : false 00185 ), 00186 "Mat::init(): requested size is too large" 00187 ); 00188 00189 arma_debug_check(err_state, err_msg); 00190 00191 const uword old_n_elem = n_elem; 00192 const uword new_n_elem = in_n_rows * in_n_cols; 00193 00194 if(old_n_elem == new_n_elem) 00195 { 00196 arma_extra_debug_print("Mat::init(): reusing memory"); 00197 00198 access::rw(n_rows) = in_n_rows; 00199 access::rw(n_cols) = in_n_cols; 00200 } 00201 else 00202 { 00203 arma_debug_check 00204 ( 00205 (t_mem_state == 2), 00206 "Mat::init(): mismatch between size of auxiliary memory and requested size" 00207 ); 00208 00209 if(t_mem_state == 0) 00210 { 00211 if(old_n_elem > arma_config::mat_prealloc) 00212 { 00213 arma_extra_debug_print("Mat::init(): freeing memory"); 00214 00215 #if defined(ARMA_USE_TBB_ALLOC) 00216 scalable_free((void *)(mem)); 00217 #else 00218 delete [] mem; 00219 #endif 00220 } 00221 } 00222 00223 00224 if(new_n_elem <= arma_config::mat_prealloc) 00225 { 00226 access::rw(mem) = mem_local; 00227 } 00228 else 00229 { 00230 arma_extra_debug_print("Mat::init(): allocating memory"); 00231 00232 #if defined(ARMA_USE_TBB_ALLOC) 00233 access::rw(mem) = (eT *) scalable_malloc(sizeof(eT)*new_n_elem); 00234 #else 00235 access::rw(mem) = new(std::nothrow) eT[new_n_elem]; 00236 #endif 00237 00238 arma_check_bad_alloc( (mem == 0), "Mat::init(): out of memory" ); 00239 } 00240 00241 access::rw(n_rows) = in_n_rows; 00242 access::rw(n_cols) = in_n_cols; 00243 access::rw(n_elem) = new_n_elem; 00244 access::rw(mem_state) = 0; 00245 } 00246 } 00247 00248 00249 00251 template<typename eT> 00252 inline 00253 Mat<eT>::Mat(const char* text) 00254 : n_rows(0) 00255 , n_cols(0) 00256 , n_elem(0) 00257 , vec_state(0) 00258 , mem_state(0) 00259 , mem() 00260 { 00261 arma_extra_debug_sigprint_this(this); 00262 00263 init( std::string(text) ); 00264 } 00265 00266 00267 00269 template<typename eT> 00270 inline 00271 const Mat<eT>& 00272 Mat<eT>::operator=(const char* text) 00273 { 00274 arma_extra_debug_sigprint(); 00275 00276 init( std::string(text) ); 00277 return *this; 00278 } 00279 00280 00281 00283 template<typename eT> 00284 inline 00285 Mat<eT>::Mat(const std::string& text) 00286 : n_rows(0) 00287 , n_cols(0) 00288 , n_elem(0) 00289 , vec_state(0) 00290 , mem_state(0) 00291 , mem() 00292 { 00293 arma_extra_debug_sigprint_this(this); 00294 00295 init(text); 00296 } 00297 00298 00299 00301 template<typename eT> 00302 inline 00303 const Mat<eT>& 00304 Mat<eT>::operator=(const std::string& text) 00305 { 00306 arma_extra_debug_sigprint(); 00307 00308 init(text); 00309 return *this; 00310 } 00311 00312 00313 00315 template<typename eT> 00316 inline 00317 void 00318 Mat<eT>::init(const std::string& text) 00319 { 00320 arma_extra_debug_sigprint(); 00321 00322 // 00323 // work out the size 00324 00325 uword t_n_rows = 0; 00326 uword t_n_cols = 0; 00327 00328 bool t_n_cols_found = false; 00329 00330 std::string token; 00331 00332 std::string::size_type line_start = 0; 00333 std::string::size_type line_end = 0; 00334 00335 while( line_start < text.length() ) 00336 { 00337 00338 line_end = text.find(';', line_start); 00339 00340 if(line_end == std::string::npos) 00341 line_end = text.length()-1; 00342 00343 std::string::size_type line_len = line_end - line_start + 1; 00344 std::stringstream line_stream( text.substr(line_start,line_len) ); 00345 00346 00347 uword line_n_cols = 0; 00348 while(line_stream >> token) 00349 { 00350 ++line_n_cols; 00351 } 00352 00353 00354 if(line_n_cols > 0) 00355 { 00356 if(t_n_cols_found == false) 00357 { 00358 t_n_cols = line_n_cols; 00359 t_n_cols_found = true; 00360 } 00361 else 00362 arma_check( (line_n_cols != t_n_cols), "Mat::init(): inconsistent number of columns in given string"); 00363 00364 ++t_n_rows; 00365 } 00366 line_start = line_end+1; 00367 00368 } 00369 00370 Mat<eT>& x = *this; 00371 x.set_size(t_n_rows, t_n_cols); 00372 00373 line_start = 0; 00374 line_end = 0; 00375 00376 uword row = 0; 00377 00378 while( line_start < text.length() ) 00379 { 00380 00381 line_end = text.find(';', line_start); 00382 00383 if(line_end == std::string::npos) 00384 line_end = text.length()-1; 00385 00386 std::string::size_type line_len = line_end - line_start + 1; 00387 std::stringstream line_stream( text.substr(line_start,line_len) ); 00388 00389 // uword col = 0; 00390 // while(line_stream >> token) 00391 // { 00392 // x.at(row,col) = strtod(token.c_str(), 0); 00393 // ++col; 00394 // } 00395 00396 uword col = 0; 00397 eT val; 00398 while(line_stream >> val) 00399 { 00400 x.at(row,col) = val; 00401 ++col; 00402 } 00403 00404 ++row; 00405 line_start = line_end+1; 00406 } 00407 00408 } 00409 00410 00411 00412 #if defined(ARMA_USE_CXX11) 00413 00414 template<typename eT> 00415 inline 00416 Mat<eT>::Mat(const std::initializer_list<eT>& list) 00417 : n_rows(0) 00418 , n_cols(0) 00419 , n_elem(0) 00420 , vec_state(0) 00421 , mem_state(0) 00422 , mem() 00423 { 00424 arma_extra_debug_sigprint_this(this); 00425 00426 init(list); 00427 } 00428 00429 00430 00431 template<typename eT> 00432 inline 00433 const Mat<eT>& 00434 Mat<eT>::operator=(const std::initializer_list<eT>& list) 00435 { 00436 arma_extra_debug_sigprint(); 00437 00438 init(list); 00439 00440 return *this; 00441 } 00442 00443 #endif 00444 00445 00446 00449 template<typename eT> 00450 arma_inline 00451 const Mat<eT>& 00452 Mat<eT>::operator=(const eT val) 00453 { 00454 arma_extra_debug_sigprint(); 00455 00456 init_warm(1,1); 00457 access::rw(mem[0]) = val; 00458 return *this; 00459 } 00460 00461 00462 00464 template<typename eT> 00465 arma_inline 00466 const Mat<eT>& 00467 Mat<eT>::operator+=(const eT val) 00468 { 00469 arma_extra_debug_sigprint(); 00470 00471 arrayops::inplace_plus( memptr(), val, n_elem ); 00472 00473 return *this; 00474 } 00475 00476 00477 00479 template<typename eT> 00480 arma_inline 00481 const Mat<eT>& 00482 Mat<eT>::operator-=(const eT val) 00483 { 00484 arma_extra_debug_sigprint(); 00485 00486 arrayops::inplace_minus( memptr(), val, n_elem ); 00487 00488 return *this; 00489 } 00490 00491 00492 00494 template<typename eT> 00495 arma_inline 00496 const Mat<eT>& 00497 Mat<eT>::operator*=(const eT val) 00498 { 00499 arma_extra_debug_sigprint(); 00500 00501 arrayops::inplace_mul( memptr(), val, n_elem ); 00502 00503 return *this; 00504 } 00505 00506 00507 00509 template<typename eT> 00510 arma_inline 00511 const Mat<eT>& 00512 Mat<eT>::operator/=(const eT val) 00513 { 00514 arma_extra_debug_sigprint(); 00515 00516 arrayops::inplace_div( memptr(), val, n_elem ); 00517 00518 return *this; 00519 } 00520 00521 00522 00524 template<typename eT> 00525 inline 00526 Mat<eT>::Mat(const Mat<eT>& in_mat) 00527 : n_rows(in_mat.n_rows) 00528 , n_cols(in_mat.n_cols) 00529 , n_elem(in_mat.n_elem) 00530 , vec_state(0) 00531 , mem_state(0) 00532 , mem() 00533 { 00534 arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat); 00535 00536 init_cold(); 00537 00538 arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem ); 00539 } 00540 00541 00542 00544 template<typename eT> 00545 inline 00546 const Mat<eT>& 00547 Mat<eT>::operator=(const Mat<eT>& in_mat) 00548 { 00549 arma_extra_debug_sigprint(arma_boost::format("this = %x in_mat = %x") % this % &in_mat); 00550 00551 if(this != &in_mat) 00552 { 00553 init_warm(in_mat.n_rows, in_mat.n_cols); 00554 00555 arrayops::copy( memptr(), in_mat.mem, in_mat.n_elem ); 00556 } 00557 00558 return *this; 00559 } 00560 00561 00562 00563 #if defined(ARMA_USE_CXX11) 00564 00565 template<typename eT> 00566 inline 00567 void 00568 Mat<eT>::init(const std::initializer_list<eT>& list) 00569 { 00570 arma_extra_debug_sigprint(); 00571 00572 const uword N = list.size(); 00573 00574 set_size(1, N); 00575 00576 arrayops::copy( memptr(), list.begin(), N ); 00577 } 00578 00579 #endif 00580 00581 00582 00584 template<typename eT> 00585 template<typename T1, typename T2> 00586 inline 00587 void 00588 Mat<eT>::init 00589 ( 00590 const Base<typename Mat<eT>::pod_type, T1>& A, 00591 const Base<typename Mat<eT>::pod_type, T2>& B 00592 ) 00593 { 00594 arma_extra_debug_sigprint(); 00595 00596 typedef typename T1::elem_type T; 00597 typedef typename Proxy<T1>::ea_type ea_type1; 00598 typedef typename Proxy<T2>::ea_type ea_type2; 00599 00600 arma_type_check(( is_complex<eT>::value == false )); 00601 arma_type_check(( is_complex< T>::value == true )); 00602 00603 arma_type_check(( is_same_type< std::complex<T>, eT >::value == false )); 00604 00605 const Proxy<T1> X(A.get_ref()); 00606 const Proxy<T2> Y(B.get_ref()); 00607 00608 arma_assert_same_size(X, Y, "Mat()"); 00609 00610 init_warm(X.get_n_rows(), X.get_n_cols()); 00611 00612 const uword N = n_elem; 00613 eT* out_mem = memptr(); 00614 ea_type1 PX = X.get_ea(); 00615 ea_type2 PY = Y.get_ea(); 00616 00617 for(uword i=0; i<N; ++i) 00618 { 00619 out_mem[i] = std::complex<T>(PX[i], PY[i]); 00620 } 00621 } 00622 00623 00624 00627 template<typename eT> 00628 inline 00629 void 00630 Mat<eT>::steal_mem(Mat<eT>& x) 00631 { 00632 arma_extra_debug_sigprint(); 00633 00634 if(this != &x) 00635 { 00636 const uword x_n_rows = x.n_rows; 00637 const uword x_n_cols = x.n_cols; 00638 const uword x_n_elem = x.n_elem; 00639 const uword x_vec_state = x.vec_state; 00640 const uword x_mem_state = x.mem_state; 00641 00642 const uword t_vec_state = vec_state; 00643 00644 bool layout_ok = false; 00645 00646 if(t_vec_state == x_vec_state) 00647 { 00648 layout_ok = true; 00649 } 00650 else 00651 { 00652 if( (t_vec_state == 1) && ( x_n_cols == 1) ) 00653 { 00654 layout_ok = true; 00655 } 00656 00657 if( (t_vec_state == 2) && ( x_n_rows == 1) ) 00658 { 00659 layout_ok = true; 00660 } 00661 } 00662 00663 00664 if( (x_mem_state == 0) && (x_n_elem > arma_config::mat_prealloc) && (layout_ok == true) ) 00665 { 00666 reset(); 00667 // note: calling reset() also prevents fixed size matrices from changing size or using non-local memory 00668 00669 access::rw(n_rows) = x_n_rows; 00670 access::rw(n_cols) = x_n_cols; 00671 access::rw(n_elem) = x_n_elem; 00672 access::rw(mem) = x.mem; 00673 00674 access::rw(x.n_rows) = 0; 00675 access::rw(x.n_cols) = 0; 00676 access::rw(x.n_elem) = 0; 00677 access::rw(x.mem) = 0; 00678 } 00679 else 00680 { 00681 (*this).operator=(x); 00682 } 00683 } 00684 } 00685 00686 00687 00692 00693 template<typename eT> 00694 inline 00695 Mat<eT>::Mat(eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols, const bool copy_aux_mem, const bool strict) 00696 : n_rows ( aux_n_rows ) 00697 , n_cols ( aux_n_cols ) 00698 , n_elem ( aux_n_rows*aux_n_cols ) 00699 , vec_state( 0 ) 00700 , mem_state( copy_aux_mem ? 0 : ( strict ? 2 : 1 ) ) 00701 , mem ( copy_aux_mem ? 0 : aux_mem ) 00702 { 00703 arma_extra_debug_sigprint_this(this); 00704 00705 if(copy_aux_mem == true) 00706 { 00707 init_cold(); 00708 00709 arrayops::copy( memptr(), aux_mem, n_elem ); 00710 } 00711 } 00712 00713 00714 00717 template<typename eT> 00718 inline 00719 Mat<eT>::Mat(const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols) 00720 : n_rows(aux_n_rows) 00721 , n_cols(aux_n_cols) 00722 , n_elem(aux_n_rows*aux_n_cols) 00723 , vec_state(0) 00724 , mem_state(0) 00725 , mem() 00726 { 00727 arma_extra_debug_sigprint_this(this); 00728 00729 init_cold(); 00730 00731 arrayops::copy( memptr(), aux_mem, n_elem ); 00732 } 00733 00734 00735 00739 00740 template<typename eT> 00741 inline 00742 Mat<eT>::Mat(const char junk, const eT* aux_mem, const uword aux_n_rows, const uword aux_n_cols) 00743 : n_rows (aux_n_rows ) 00744 , n_cols (aux_n_cols ) 00745 , n_elem (aux_n_rows*aux_n_cols) 00746 , vec_state(0 ) 00747 , mem_state(3 ) 00748 , mem (aux_mem ) 00749 { 00750 arma_extra_debug_sigprint_this(this); 00751 arma_ignore(junk); 00752 } 00753 00754 00755 00757 template<typename eT> 00758 inline 00759 const Mat<eT>& 00760 Mat<eT>::operator+=(const Mat<eT>& m) 00761 { 00762 arma_extra_debug_sigprint(); 00763 00764 arma_debug_assert_same_size(*this, m, "addition"); 00765 00766 arrayops::inplace_plus( memptr(), m.memptr(), n_elem ); 00767 00768 return *this; 00769 } 00770 00771 00772 00774 template<typename eT> 00775 inline 00776 const Mat<eT>& 00777 Mat<eT>::operator-=(const Mat<eT>& m) 00778 { 00779 arma_extra_debug_sigprint(); 00780 00781 arma_debug_assert_same_size(*this, m, "subtraction"); 00782 00783 arrayops::inplace_minus( memptr(), m.memptr(), n_elem ); 00784 00785 return *this; 00786 } 00787 00788 00789 00791 template<typename eT> 00792 inline 00793 const Mat<eT>& 00794 Mat<eT>::operator*=(const Mat<eT>& m) 00795 { 00796 arma_extra_debug_sigprint(); 00797 00798 glue_times::apply_inplace(*this, m); 00799 00800 return *this; 00801 } 00802 00803 00804 00806 template<typename eT> 00807 inline 00808 const Mat<eT>& 00809 Mat<eT>::operator%=(const Mat<eT>& m) 00810 { 00811 arma_extra_debug_sigprint(); 00812 00813 arma_debug_assert_same_size(*this, m, "element-wise multiplication"); 00814 00815 arrayops::inplace_mul( memptr(), m.memptr(), n_elem ); 00816 00817 return *this; 00818 } 00819 00820 00821 00823 template<typename eT> 00824 inline 00825 const Mat<eT>& 00826 Mat<eT>::operator/=(const Mat<eT>& m) 00827 { 00828 arma_extra_debug_sigprint(); 00829 00830 arma_debug_assert_same_size(*this, m, "element-wise division"); 00831 00832 arrayops::inplace_div( memptr(), m.memptr(), n_elem ); 00833 00834 return *this; 00835 } 00836 00837 00838 00839 template<typename eT> 00840 template<typename T1> 00841 inline 00842 Mat<eT>::Mat(const BaseCube<eT,T1>& X) 00843 : n_rows(0) 00844 , n_cols(0) 00845 , n_elem(0) 00846 , vec_state(0) 00847 , mem_state(0) 00848 , mem() 00849 { 00850 arma_extra_debug_sigprint_this(this); 00851 00852 (*this).operator=(X); 00853 } 00854 00855 00856 00857 template<typename eT> 00858 template<typename T1> 00859 inline 00860 const Mat<eT>& 00861 Mat<eT>::operator=(const BaseCube<eT,T1>& X) 00862 { 00863 arma_extra_debug_sigprint(); 00864 00865 Mat<eT>& out = *this; 00866 00867 const unwrap_cube<T1> tmp(X.get_ref()); 00868 const Cube<eT>& in = tmp.M; 00869 00870 arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false); 00871 00872 const uword in_n_rows = in.n_rows; 00873 const uword in_n_cols = in.n_cols; 00874 const uword in_n_slices = in.n_slices; 00875 00876 const uword out_vec_state = out.vec_state; 00877 00878 if(in_n_slices == 1) 00879 { 00880 out.set_size(in_n_rows, in_n_cols); 00881 00882 for(uword col=0; col < in_n_cols; ++col) 00883 { 00884 arrayops::copy( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); 00885 } 00886 } 00887 else 00888 { 00889 if(out_vec_state == 0) 00890 { 00891 if(in_n_cols == 1) 00892 { 00893 out.set_size(in_n_rows, in_n_slices); 00894 00895 for(uword i=0; i < in_n_slices; ++i) 00896 { 00897 arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); 00898 } 00899 } 00900 else 00901 if(in_n_rows == 1) 00902 { 00903 out.set_size(in_n_cols, in_n_slices); 00904 00905 for(uword slice=0; slice < in_n_slices; ++slice) 00906 { 00907 eT* out_colptr = out.colptr(slice); 00908 00909 uword i,j; 00910 for(i=0, j=1; j < in_n_cols; i+=2, j+=2) 00911 { 00912 const eT tmp_i = in.at(0, i, slice); 00913 const eT tmp_j = in.at(0, j, slice); 00914 00915 out_colptr[i] = tmp_i; 00916 out_colptr[j] = tmp_j; 00917 } 00918 00919 if(i < in_n_cols) 00920 { 00921 out_colptr[i] = in.at(0, i, slice); 00922 } 00923 } 00924 } 00925 } 00926 else 00927 { 00928 out.set_size(in_n_slices); 00929 00930 eT* out_mem = out.memptr(); 00931 00932 for(uword i=0; i<in_n_slices; ++i) 00933 { 00934 out_mem[i] = in.at(0, 0, i); 00935 } 00936 } 00937 } 00938 00939 return *this; 00940 } 00941 00942 00943 00944 template<typename eT> 00945 template<typename T1> 00946 inline 00947 const Mat<eT>& 00948 Mat<eT>::operator+=(const BaseCube<eT,T1>& X) 00949 { 00950 arma_extra_debug_sigprint(); 00951 00952 Mat<eT>& out = *this; 00953 00954 const unwrap_cube<T1> tmp(X.get_ref()); 00955 const Cube<eT>& in = tmp.M; 00956 00957 arma_debug_assert_cube_as_mat(out, in, "addition", true); 00958 00959 const uword in_n_rows = in.n_rows; 00960 const uword in_n_cols = in.n_cols; 00961 const uword in_n_slices = in.n_slices; 00962 00963 const uword out_n_rows = out.n_rows; 00964 const uword out_n_cols = out.n_cols; 00965 const uword out_vec_state = out.vec_state; 00966 00967 if(in_n_slices == 1) 00968 { 00969 for(uword col=0; col < in_n_cols; ++col) 00970 { 00971 arrayops::inplace_plus( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); 00972 } 00973 } 00974 else 00975 { 00976 if(out_vec_state == 0) 00977 { 00978 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) 00979 { 00980 for(uword i=0; i < in_n_slices; ++i) 00981 { 00982 arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); 00983 } 00984 } 00985 else 00986 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) 00987 { 00988 for(uword slice=0; slice < in_n_slices; ++slice) 00989 { 00990 eT* out_colptr = out.colptr(slice); 00991 00992 uword i,j; 00993 for(i=0, j=1; j < in_n_cols; i+=2, j+=2) 00994 { 00995 const eT tmp_i = in.at(0, i, slice); 00996 const eT tmp_j = in.at(0, j, slice); 00997 00998 out_colptr[i] += tmp_i; 00999 out_colptr[j] += tmp_j; 01000 } 01001 01002 if(i < in_n_cols) 01003 { 01004 out_colptr[i] += in.at(0, i, slice); 01005 } 01006 } 01007 } 01008 } 01009 else 01010 { 01011 eT* out_mem = out.memptr(); 01012 01013 for(uword i=0; i<in_n_slices; ++i) 01014 { 01015 out_mem[i] += in.at(0, 0, i); 01016 } 01017 } 01018 } 01019 01020 return *this; 01021 } 01022 01023 01024 01025 template<typename eT> 01026 template<typename T1> 01027 inline 01028 const Mat<eT>& 01029 Mat<eT>::operator-=(const BaseCube<eT,T1>& X) 01030 { 01031 arma_extra_debug_sigprint(); 01032 01033 Mat<eT>& out = *this; 01034 01035 const unwrap_cube<T1> tmp(X.get_ref()); 01036 const Cube<eT>& in = tmp.M; 01037 01038 arma_debug_assert_cube_as_mat(out, in, "subtraction", true); 01039 01040 const uword in_n_rows = in.n_rows; 01041 const uword in_n_cols = in.n_cols; 01042 const uword in_n_slices = in.n_slices; 01043 01044 const uword out_n_rows = out.n_rows; 01045 const uword out_n_cols = out.n_cols; 01046 const uword out_vec_state = out.vec_state; 01047 01048 if(in_n_slices == 1) 01049 { 01050 for(uword col=0; col < in_n_cols; ++col) 01051 { 01052 arrayops::inplace_minus( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); 01053 } 01054 } 01055 else 01056 { 01057 if(out_vec_state == 0) 01058 { 01059 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) 01060 { 01061 for(uword i=0; i < in_n_slices; ++i) 01062 { 01063 arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); 01064 } 01065 } 01066 else 01067 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) 01068 { 01069 for(uword slice=0; slice < in_n_slices; ++slice) 01070 { 01071 eT* out_colptr = out.colptr(slice); 01072 01073 uword i,j; 01074 for(i=0, j=1; j < in_n_cols; i+=2, j+=2) 01075 { 01076 const eT tmp_i = in.at(0, i, slice); 01077 const eT tmp_j = in.at(0, j, slice); 01078 01079 out_colptr[i] -= tmp_i; 01080 out_colptr[j] -= tmp_j; 01081 } 01082 01083 if(i < in_n_cols) 01084 { 01085 out_colptr[i] -= in.at(0, i, slice); 01086 } 01087 } 01088 } 01089 } 01090 else 01091 { 01092 eT* out_mem = out.memptr(); 01093 01094 for(uword i=0; i<in_n_slices; ++i) 01095 { 01096 out_mem[i] -= in.at(0, 0, i); 01097 } 01098 } 01099 } 01100 01101 return *this; 01102 } 01103 01104 01105 01106 template<typename eT> 01107 template<typename T1> 01108 inline 01109 const Mat<eT>& 01110 Mat<eT>::operator*=(const BaseCube<eT,T1>& X) 01111 { 01112 arma_extra_debug_sigprint(); 01113 01114 const Mat<eT> B(X); 01115 01116 (*this).operator*=(B); 01117 01118 return *this; 01119 } 01120 01121 01122 01123 template<typename eT> 01124 template<typename T1> 01125 inline 01126 const Mat<eT>& 01127 Mat<eT>::operator%=(const BaseCube<eT,T1>& X) 01128 { 01129 arma_extra_debug_sigprint(); 01130 01131 Mat<eT>& out = *this; 01132 01133 const unwrap_cube<T1> tmp(X.get_ref()); 01134 const Cube<eT>& in = tmp.M; 01135 01136 arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", true); 01137 01138 const uword in_n_rows = in.n_rows; 01139 const uword in_n_cols = in.n_cols; 01140 const uword in_n_slices = in.n_slices; 01141 01142 const uword out_n_rows = out.n_rows; 01143 const uword out_n_cols = out.n_cols; 01144 const uword out_vec_state = out.vec_state; 01145 01146 if(in_n_slices == 1) 01147 { 01148 for(uword col=0; col < in_n_cols; ++col) 01149 { 01150 arrayops::inplace_mul( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); 01151 } 01152 } 01153 else 01154 { 01155 if(out_vec_state == 0) 01156 { 01157 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) 01158 { 01159 for(uword i=0; i < in_n_slices; ++i) 01160 { 01161 arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); 01162 } 01163 } 01164 else 01165 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) 01166 { 01167 for(uword slice=0; slice < in_n_slices; ++slice) 01168 { 01169 eT* out_colptr = out.colptr(slice); 01170 01171 uword i,j; 01172 for(i=0, j=1; j < in_n_cols; i+=2, j+=2) 01173 { 01174 const eT tmp_i = in.at(0, i, slice); 01175 const eT tmp_j = in.at(0, j, slice); 01176 01177 out_colptr[i] *= tmp_i; 01178 out_colptr[j] *= tmp_j; 01179 } 01180 01181 if(i < in_n_cols) 01182 { 01183 out_colptr[i] *= in.at(0, i, slice); 01184 } 01185 } 01186 } 01187 } 01188 else 01189 { 01190 eT* out_mem = out.memptr(); 01191 01192 for(uword i=0; i<in_n_slices; ++i) 01193 { 01194 out_mem[i] *= in.at(0, 0, i); 01195 } 01196 } 01197 } 01198 01199 return *this; 01200 } 01201 01202 01203 01204 template<typename eT> 01205 template<typename T1> 01206 inline 01207 const Mat<eT>& 01208 Mat<eT>::operator/=(const BaseCube<eT,T1>& X) 01209 { 01210 arma_extra_debug_sigprint(); 01211 01212 Mat<eT>& out = *this; 01213 01214 const unwrap_cube<T1> tmp(X.get_ref()); 01215 const Cube<eT>& in = tmp.M; 01216 01217 arma_debug_assert_cube_as_mat(out, in, "element-wise division", true); 01218 01219 const uword in_n_rows = in.n_rows; 01220 const uword in_n_cols = in.n_cols; 01221 const uword in_n_slices = in.n_slices; 01222 01223 const uword out_n_rows = out.n_rows; 01224 const uword out_n_cols = out.n_cols; 01225 const uword out_vec_state = out.vec_state; 01226 01227 if(in_n_slices == 1) 01228 { 01229 for(uword col=0; col < in_n_cols; ++col) 01230 { 01231 arrayops::inplace_div( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); 01232 } 01233 } 01234 else 01235 { 01236 if(out_vec_state == 0) 01237 { 01238 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) 01239 { 01240 for(uword i=0; i < in_n_slices; ++i) 01241 { 01242 arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); 01243 } 01244 } 01245 else 01246 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) 01247 { 01248 for(uword slice=0; slice < in_n_slices; ++slice) 01249 { 01250 eT* out_colptr = out.colptr(slice); 01251 01252 uword i,j; 01253 for(i=0, j=1; j < in_n_cols; i+=2, j+=2) 01254 { 01255 const eT tmp_i = in.at(0, i, slice); 01256 const eT tmp_j = in.at(0, j, slice); 01257 01258 out_colptr[i] /= tmp_i; 01259 out_colptr[j] /= tmp_j; 01260 } 01261 01262 if(i < in_n_cols) 01263 { 01264 out_colptr[i] /= in.at(0, i, slice); 01265 } 01266 } 01267 } 01268 } 01269 else 01270 { 01271 eT* out_mem = out.memptr(); 01272 01273 for(uword i=0; i<in_n_slices; ++i) 01274 { 01275 out_mem[i] /= in.at(0, 0, i); 01276 } 01277 } 01278 } 01279 01280 return *this; 01281 } 01282 01283 01284 01286 template<typename eT> 01287 template<typename T1, typename T2> 01288 inline 01289 Mat<eT>::Mat 01290 ( 01291 const Base<typename Mat<eT>::pod_type,T1>& A, 01292 const Base<typename Mat<eT>::pod_type,T2>& B 01293 ) 01294 : n_rows(0) 01295 , n_cols(0) 01296 , n_elem(0) 01297 , vec_state(0) 01298 , mem_state(0) 01299 , mem() 01300 { 01301 arma_extra_debug_sigprint_this(this); 01302 01303 init(A,B); 01304 } 01305 01306 01307 01309 template<typename eT> 01310 inline 01311 Mat<eT>::Mat(const subview<eT>& X) 01312 : n_rows(X.n_rows) 01313 , n_cols(X.n_cols) 01314 , n_elem(X.n_elem) 01315 , vec_state(0) 01316 , mem_state(0) 01317 , mem() 01318 { 01319 arma_extra_debug_sigprint_this(this); 01320 01321 init_cold(); 01322 01323 subview<eT>::extract(*this, X); 01324 } 01325 01326 01327 01329 template<typename eT> 01330 inline 01331 const Mat<eT>& 01332 Mat<eT>::operator=(const subview<eT>& X) 01333 { 01334 arma_extra_debug_sigprint(); 01335 01336 const bool alias = (this == &(X.m)); 01337 01338 if(alias == false) 01339 { 01340 init_warm(X.n_rows, X.n_cols); 01341 01342 subview<eT>::extract(*this, X); 01343 } 01344 else 01345 { 01346 Mat<eT> tmp(X); 01347 01348 steal_mem(tmp); 01349 } 01350 01351 return *this; 01352 } 01353 01354 01356 template<typename eT> 01357 inline 01358 const Mat<eT>& 01359 Mat<eT>::operator+=(const subview<eT>& X) 01360 { 01361 arma_extra_debug_sigprint(); 01362 01363 subview<eT>::plus_inplace(*this, X); 01364 01365 return *this; 01366 } 01367 01368 01370 template<typename eT> 01371 inline 01372 const Mat<eT>& 01373 Mat<eT>::operator-=(const subview<eT>& X) 01374 { 01375 arma_extra_debug_sigprint(); 01376 01377 subview<eT>::minus_inplace(*this, X); 01378 01379 return *this; 01380 } 01381 01382 01383 01385 template<typename eT> 01386 inline 01387 const Mat<eT>& 01388 Mat<eT>::operator*=(const subview<eT>& X) 01389 { 01390 arma_extra_debug_sigprint(); 01391 01392 glue_times::apply_inplace(*this, X); 01393 01394 return *this; 01395 } 01396 01397 01398 01400 template<typename eT> 01401 inline 01402 const Mat<eT>& 01403 Mat<eT>::operator%=(const subview<eT>& X) 01404 { 01405 arma_extra_debug_sigprint(); 01406 01407 subview<eT>::schur_inplace(*this, X); 01408 01409 return *this; 01410 } 01411 01412 01413 01415 template<typename eT> 01416 inline 01417 const Mat<eT>& 01418 Mat<eT>::operator/=(const subview<eT>& X) 01419 { 01420 arma_extra_debug_sigprint(); 01421 01422 subview<eT>::div_inplace(*this, X); 01423 01424 return *this; 01425 } 01426 01427 01428 01430 template<typename eT> 01431 inline 01432 Mat<eT>::Mat(const subview_cube<eT>& x) 01433 : n_rows(0) 01434 , n_cols(0) 01435 , n_elem(0) 01436 , vec_state(0) 01437 , mem_state(0) 01438 , mem() 01439 { 01440 arma_extra_debug_sigprint_this(this); 01441 01442 this->operator=(x); 01443 } 01444 01445 01446 01448 template<typename eT> 01449 inline 01450 const Mat<eT>& 01451 Mat<eT>::operator=(const subview_cube<eT>& X) 01452 { 01453 arma_extra_debug_sigprint(); 01454 01455 subview_cube<eT>::extract(*this, X); 01456 01457 return *this; 01458 } 01459 01460 01461 01463 template<typename eT> 01464 inline 01465 const Mat<eT>& 01466 Mat<eT>::operator+=(const subview_cube<eT>& X) 01467 { 01468 arma_extra_debug_sigprint(); 01469 01470 subview_cube<eT>::plus_inplace(*this, X); 01471 01472 return *this; 01473 } 01474 01475 01476 01478 template<typename eT> 01479 inline 01480 const Mat<eT>& 01481 Mat<eT>::operator-=(const subview_cube<eT>& X) 01482 { 01483 arma_extra_debug_sigprint(); 01484 01485 subview_cube<eT>::minus_inplace(*this, X); 01486 01487 return *this; 01488 } 01489 01490 01491 01493 template<typename eT> 01494 inline 01495 const Mat<eT>& 01496 Mat<eT>::operator*=(const subview_cube<eT>& X) 01497 { 01498 arma_extra_debug_sigprint(); 01499 01500 const Mat<eT> tmp(X); 01501 glue_times::apply_inplace(*this, tmp); 01502 01503 return *this; 01504 } 01505 01506 01507 01509 template<typename eT> 01510 inline 01511 const Mat<eT>& 01512 Mat<eT>::operator%=(const subview_cube<eT>& X) 01513 { 01514 arma_extra_debug_sigprint(); 01515 01516 subview_cube<eT>::schur_inplace(*this, X); 01517 01518 return *this; 01519 } 01520 01521 01522 01524 template<typename eT> 01525 inline 01526 const Mat<eT>& 01527 Mat<eT>::operator/=(const subview_cube<eT>& X) 01528 { 01529 arma_extra_debug_sigprint(); 01530 01531 subview_cube<eT>::div_inplace(*this, X); 01532 01533 return *this; 01534 } 01535 01536 01537 01539 template<typename eT> 01540 inline 01541 Mat<eT>::Mat(const diagview<eT>& X) 01542 : n_rows(X.n_rows) 01543 , n_cols(X.n_cols) 01544 , n_elem(X.n_elem) 01545 , vec_state(0) 01546 , mem_state(0) 01547 , mem() 01548 { 01549 arma_extra_debug_sigprint_this(this); 01550 01551 init_cold(); 01552 01553 diagview<eT>::extract(*this, X); 01554 } 01555 01556 01557 01559 template<typename eT> 01560 inline 01561 const Mat<eT>& 01562 Mat<eT>::operator=(const diagview<eT>& X) 01563 { 01564 arma_extra_debug_sigprint(); 01565 01566 const bool alias = (this == &(X.m)); 01567 01568 if(alias == false) 01569 { 01570 init_warm(X.n_rows, X.n_cols); 01571 01572 diagview<eT>::extract(*this, X); 01573 } 01574 else 01575 { 01576 Mat<eT> tmp(X); 01577 01578 steal_mem(tmp); 01579 } 01580 01581 return *this; 01582 } 01583 01584 01585 01587 template<typename eT> 01588 inline 01589 const Mat<eT>& 01590 Mat<eT>::operator+=(const diagview<eT>& X) 01591 { 01592 arma_extra_debug_sigprint(); 01593 01594 diagview<eT>::plus_inplace(*this, X); 01595 01596 return *this; 01597 } 01598 01599 01601 template<typename eT> 01602 inline 01603 const Mat<eT>& 01604 Mat<eT>::operator-=(const diagview<eT>& X) 01605 { 01606 arma_extra_debug_sigprint(); 01607 01608 diagview<eT>::minus_inplace(*this, X); 01609 01610 return *this; 01611 } 01612 01613 01614 01616 template<typename eT> 01617 inline 01618 const Mat<eT>& 01619 Mat<eT>::operator*=(const diagview<eT>& X) 01620 { 01621 arma_extra_debug_sigprint(); 01622 01623 glue_times::apply_inplace(*this, X); 01624 01625 return *this; 01626 } 01627 01628 01629 01631 template<typename eT> 01632 inline 01633 const Mat<eT>& 01634 Mat<eT>::operator%=(const diagview<eT>& X) 01635 { 01636 arma_extra_debug_sigprint(); 01637 01638 diagview<eT>::schur_inplace(*this, X); 01639 01640 return *this; 01641 } 01642 01643 01644 01646 template<typename eT> 01647 inline 01648 const Mat<eT>& 01649 Mat<eT>::operator/=(const diagview<eT>& X) 01650 { 01651 arma_extra_debug_sigprint(); 01652 01653 diagview<eT>::div_inplace(*this, X); 01654 01655 return *this; 01656 } 01657 01658 01659 01660 template<typename eT> 01661 template<typename T1> 01662 inline 01663 Mat<eT>::Mat(const subview_elem1<eT,T1>& X) 01664 : n_rows(0) 01665 , n_cols(0) 01666 , n_elem(0) 01667 , vec_state(0) 01668 , mem_state(0) 01669 , mem() 01670 { 01671 arma_extra_debug_sigprint_this(this); 01672 01673 this->operator=(X); 01674 } 01675 01676 01677 01678 template<typename eT> 01679 template<typename T1> 01680 inline 01681 const Mat<eT>& 01682 Mat<eT>::operator=(const subview_elem1<eT,T1>& X) 01683 { 01684 arma_extra_debug_sigprint(); 01685 01686 subview_elem1<eT,T1>::extract(*this, X); 01687 01688 return *this; 01689 } 01690 01691 01692 01693 template<typename eT> 01694 template<typename T1> 01695 inline 01696 const Mat<eT>& 01697 Mat<eT>::operator+=(const subview_elem1<eT,T1>& X) 01698 { 01699 arma_extra_debug_sigprint(); 01700 01701 subview_elem1<eT,T1>::plus_inplace(*this, X); 01702 01703 return *this; 01704 } 01705 01706 01707 01708 template<typename eT> 01709 template<typename T1> 01710 inline 01711 const Mat<eT>& 01712 Mat<eT>::operator-=(const subview_elem1<eT,T1>& X) 01713 { 01714 arma_extra_debug_sigprint(); 01715 01716 subview_elem1<eT,T1>::minus_inplace(*this, X); 01717 01718 return *this; 01719 } 01720 01721 01722 01723 template<typename eT> 01724 template<typename T1> 01725 inline 01726 const Mat<eT>& 01727 Mat<eT>::operator*=(const subview_elem1<eT,T1>& X) 01728 { 01729 arma_extra_debug_sigprint(); 01730 01731 glue_times::apply_inplace(*this, X); 01732 01733 return *this; 01734 } 01735 01736 01737 01738 template<typename eT> 01739 template<typename T1> 01740 inline 01741 const Mat<eT>& 01742 Mat<eT>::operator%=(const subview_elem1<eT,T1>& X) 01743 { 01744 arma_extra_debug_sigprint(); 01745 01746 subview_elem1<eT,T1>::schur_inplace(*this, X); 01747 01748 return *this; 01749 } 01750 01751 01752 01753 template<typename eT> 01754 template<typename T1> 01755 inline 01756 const Mat<eT>& 01757 Mat<eT>::operator/=(const subview_elem1<eT,T1>& X) 01758 { 01759 arma_extra_debug_sigprint(); 01760 01761 subview_elem1<eT,T1>::div_inplace(*this, X); 01762 01763 return *this; 01764 } 01765 01766 01767 01768 template<typename eT> 01769 inline 01770 mat_injector< Mat<eT> > 01771 Mat<eT>::operator<<(const eT val) 01772 { 01773 return mat_injector< Mat<eT> >(*this, val); 01774 } 01775 01776 01777 01778 template<typename eT> 01779 inline 01780 mat_injector< Mat<eT> > 01781 Mat<eT>::operator<<(const injector_end_of_row& x) 01782 { 01783 return mat_injector< Mat<eT> >(*this, x); 01784 } 01785 01786 01787 01789 template<typename eT> 01790 arma_inline 01791 subview_row<eT> 01792 Mat<eT>::row(const uword row_num) 01793 { 01794 arma_extra_debug_sigprint(); 01795 01796 arma_debug_check( row_num >= n_rows, "Mat::row(): out of bounds" ); 01797 01798 return subview_row<eT>(*this, row_num); 01799 } 01800 01801 01802 01804 template<typename eT> 01805 arma_inline 01806 const subview_row<eT> 01807 Mat<eT>::row(const uword row_num) const 01808 { 01809 arma_extra_debug_sigprint(); 01810 01811 arma_debug_check( row_num >= n_rows, "Mat::row(): out of bounds" ); 01812 01813 return subview_row<eT>(*this, row_num); 01814 } 01815 01816 01817 01818 template<typename eT> 01819 inline 01820 subview_row<eT> 01821 Mat<eT>::operator()(const uword row_num, const span& col_span) 01822 { 01823 arma_extra_debug_sigprint(); 01824 01825 const bool col_all = col_span.whole; 01826 01827 const uword local_n_cols = n_cols; 01828 01829 const uword in_col1 = col_all ? 0 : col_span.a; 01830 const uword in_col2 = col_span.b; 01831 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; 01832 01833 arma_debug_check 01834 ( 01835 (row_num >= n_rows) 01836 || 01837 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) 01838 , 01839 "Mat::operator(): indices out of bounds or incorrectly used" 01840 ); 01841 01842 return subview_row<eT>(*this, row_num, in_col1, submat_n_cols); 01843 } 01844 01845 01846 01847 template<typename eT> 01848 inline 01849 const subview_row<eT> 01850 Mat<eT>::operator()(const uword row_num, const span& col_span) const 01851 { 01852 arma_extra_debug_sigprint(); 01853 01854 const bool col_all = col_span.whole; 01855 01856 const uword local_n_cols = n_cols; 01857 01858 const uword in_col1 = col_all ? 0 : col_span.a; 01859 const uword in_col2 = col_span.b; 01860 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; 01861 01862 arma_debug_check 01863 ( 01864 (row_num >= n_rows) 01865 || 01866 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) 01867 , 01868 "Mat::operator(): indices out of bounds or incorrectly used" 01869 ); 01870 01871 return subview_row<eT>(*this, row_num, in_col1, submat_n_cols); 01872 } 01873 01874 01875 01877 template<typename eT> 01878 arma_inline 01879 subview_col<eT> 01880 Mat<eT>::col(const uword col_num) 01881 { 01882 arma_extra_debug_sigprint(); 01883 01884 arma_debug_check( col_num >= n_cols, "Mat::col(): out of bounds"); 01885 01886 return subview_col<eT>(*this, col_num); 01887 } 01888 01889 01890 01892 template<typename eT> 01893 arma_inline 01894 const subview_col<eT> 01895 Mat<eT>::col(const uword col_num) const 01896 { 01897 arma_extra_debug_sigprint(); 01898 01899 arma_debug_check( col_num >= n_cols, "Mat::col(): out of bounds"); 01900 01901 return subview_col<eT>(*this, col_num); 01902 } 01903 01904 01905 01906 template<typename eT> 01907 inline 01908 subview_col<eT> 01909 Mat<eT>::operator()(const span& row_span, const uword col_num) 01910 { 01911 arma_extra_debug_sigprint(); 01912 01913 const bool row_all = row_span.whole; 01914 01915 const uword local_n_rows = n_rows; 01916 01917 const uword in_row1 = row_all ? 0 : row_span.a; 01918 const uword in_row2 = row_span.b; 01919 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; 01920 01921 arma_debug_check 01922 ( 01923 (col_num >= n_cols) 01924 || 01925 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) 01926 , 01927 "Mat::operator(): indices out of bounds or incorrectly used" 01928 ); 01929 01930 return subview_col<eT>(*this, col_num, in_row1, submat_n_rows); 01931 } 01932 01933 01934 01935 template<typename eT> 01936 inline 01937 const subview_col<eT> 01938 Mat<eT>::operator()(const span& row_span, const uword col_num) const 01939 { 01940 arma_extra_debug_sigprint(); 01941 01942 const bool row_all = row_span.whole; 01943 01944 const uword local_n_rows = n_rows; 01945 01946 const uword in_row1 = row_all ? 0 : row_span.a; 01947 const uword in_row2 = row_span.b; 01948 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; 01949 01950 arma_debug_check 01951 ( 01952 (col_num >= n_cols) 01953 || 01954 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) 01955 , 01956 "Mat::operator(): indices out of bounds or incorrectly used" 01957 ); 01958 01959 return subview_col<eT>(*this, col_num, in_row1, submat_n_rows); 01960 } 01961 01962 01963 01969 template<typename eT> 01970 inline 01971 Col<eT> 01972 Mat<eT>::unsafe_col(const uword col_num) 01973 { 01974 arma_extra_debug_sigprint(); 01975 01976 arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): out of bounds"); 01977 01978 return Col<eT>(colptr(col_num), n_rows, false, true); 01979 } 01980 01981 01982 01988 template<typename eT> 01989 inline 01990 const Col<eT> 01991 Mat<eT>::unsafe_col(const uword col_num) const 01992 { 01993 arma_extra_debug_sigprint(); 01994 01995 arma_debug_check( col_num >= n_cols, "Mat::unsafe_col(): out of bounds"); 01996 01997 typedef const Col<eT> out_type; 01998 01999 return out_type(const_cast<eT*>(colptr(col_num)), n_rows, false, true); 02000 } 02001 02002 02003 02005 template<typename eT> 02006 arma_inline 02007 subview<eT> 02008 Mat<eT>::rows(const uword in_row1, const uword in_row2) 02009 { 02010 arma_extra_debug_sigprint(); 02011 02012 arma_debug_check 02013 ( 02014 (in_row1 > in_row2) || (in_row2 >= n_rows), 02015 "Mat::rows(): indices out of bounds or incorrectly used" 02016 ); 02017 02018 const uword subview_n_rows = in_row2 - in_row1 + 1; 02019 02020 return subview<eT>(*this, in_row1, 0, subview_n_rows, n_cols ); 02021 } 02022 02023 02024 02026 template<typename eT> 02027 arma_inline 02028 const subview<eT> 02029 Mat<eT>::rows(const uword in_row1, const uword in_row2) const 02030 { 02031 arma_extra_debug_sigprint(); 02032 02033 arma_debug_check 02034 ( 02035 (in_row1 > in_row2) || (in_row2 >= n_rows), 02036 "Mat::rows(): indices out of bounds or incorrectly used" 02037 ); 02038 02039 const uword subview_n_rows = in_row2 - in_row1 + 1; 02040 02041 return subview<eT>(*this, in_row1, 0, subview_n_rows, n_cols ); 02042 } 02043 02044 02045 02047 template<typename eT> 02048 arma_inline 02049 subview<eT> 02050 Mat<eT>::cols(const uword in_col1, const uword in_col2) 02051 { 02052 arma_extra_debug_sigprint(); 02053 02054 arma_debug_check 02055 ( 02056 (in_col1 > in_col2) || (in_col2 >= n_cols), 02057 "Mat::cols(): indices out of bounds or incorrectly used" 02058 ); 02059 02060 const uword subview_n_cols = in_col2 - in_col1 + 1; 02061 02062 return subview<eT>(*this, 0, in_col1, n_rows, subview_n_cols); 02063 } 02064 02065 02066 02068 template<typename eT> 02069 arma_inline 02070 const subview<eT> 02071 Mat<eT>::cols(const uword in_col1, const uword in_col2) const 02072 { 02073 arma_extra_debug_sigprint(); 02074 02075 arma_debug_check 02076 ( 02077 (in_col1 > in_col2) || (in_col2 >= n_cols), 02078 "Mat::cols(): indices out of bounds or incorrectly used" 02079 ); 02080 02081 const uword subview_n_cols = in_col2 - in_col1 + 1; 02082 02083 return subview<eT>(*this, 0, in_col1, n_rows, subview_n_cols); 02084 } 02085 02086 02087 02089 template<typename eT> 02090 arma_inline 02091 subview<eT> 02092 Mat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) 02093 { 02094 arma_extra_debug_sigprint(); 02095 02096 arma_debug_check 02097 ( 02098 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), 02099 "Mat::submat(): indices out of bounds or incorrectly used" 02100 ); 02101 02102 const uword subview_n_rows = in_row2 - in_row1 + 1; 02103 const uword subview_n_cols = in_col2 - in_col1 + 1; 02104 02105 return subview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); 02106 } 02107 02108 02109 02111 template<typename eT> 02112 arma_inline 02113 const subview<eT> 02114 Mat<eT>::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const 02115 { 02116 arma_extra_debug_sigprint(); 02117 02118 arma_debug_check 02119 ( 02120 (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), 02121 "Mat::submat(): indices out of bounds or incorrectly used" 02122 ); 02123 02124 const uword subview_n_rows = in_row2 - in_row1 + 1; 02125 const uword subview_n_cols = in_col2 - in_col1 + 1; 02126 02127 return subview<eT>(*this, in_row1, in_col1, subview_n_rows, subview_n_cols); 02128 } 02129 02130 02131 02133 template<typename eT> 02134 inline 02135 subview<eT> 02136 Mat<eT>::submat(const span& row_span, const span& col_span) 02137 { 02138 arma_extra_debug_sigprint(); 02139 02140 const bool row_all = row_span.whole; 02141 const bool col_all = col_span.whole; 02142 02143 const uword local_n_rows = n_rows; 02144 const uword local_n_cols = n_cols; 02145 02146 const uword in_row1 = row_all ? 0 : row_span.a; 02147 const uword in_row2 = row_span.b; 02148 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; 02149 02150 const uword in_col1 = col_all ? 0 : col_span.a; 02151 const uword in_col2 = col_span.b; 02152 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; 02153 02154 arma_debug_check 02155 ( 02156 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) 02157 || 02158 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) 02159 , 02160 "Mat::submat(): indices out of bounds or incorrectly used" 02161 ); 02162 02163 return subview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); 02164 } 02165 02166 02167 02169 template<typename eT> 02170 inline 02171 const subview<eT> 02172 Mat<eT>::submat(const span& row_span, const span& col_span) const 02173 { 02174 arma_extra_debug_sigprint(); 02175 02176 const bool row_all = row_span.whole; 02177 const bool col_all = col_span.whole; 02178 02179 const uword local_n_rows = n_rows; 02180 const uword local_n_cols = n_cols; 02181 02182 const uword in_row1 = row_all ? 0 : row_span.a; 02183 const uword in_row2 = row_span.b; 02184 const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; 02185 02186 const uword in_col1 = col_all ? 0 : col_span.a; 02187 const uword in_col2 = col_span.b; 02188 const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; 02189 02190 arma_debug_check 02191 ( 02192 ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) 02193 || 02194 ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) 02195 , 02196 "Mat::submat(): indices out of bounds or incorrectly used" 02197 ); 02198 02199 return subview<eT>(*this, in_row1, in_col1, submat_n_rows, submat_n_cols); 02200 } 02201 02202 02203 02204 template<typename eT> 02205 inline 02206 subview<eT> 02207 Mat<eT>::operator()(const span& row_span, const span& col_span) 02208 { 02209 arma_extra_debug_sigprint(); 02210 02211 return (*this).submat(row_span, col_span); 02212 } 02213 02214 02215 02216 template<typename eT> 02217 inline 02218 const subview<eT> 02219 Mat<eT>::operator()(const span& row_span, const span& col_span) const 02220 { 02221 arma_extra_debug_sigprint(); 02222 02223 return (*this).submat(row_span, col_span); 02224 } 02225 02226 02227 02228 template<typename eT> 02229 template<typename T1> 02230 arma_inline 02231 subview_elem1<eT,T1> 02232 Mat<eT>::elem(const Base<uword,T1>& a) 02233 { 02234 arma_extra_debug_sigprint(); 02235 02236 return subview_elem1<eT,T1>(*this, a); 02237 } 02238 02239 02240 02241 template<typename eT> 02242 template<typename T1> 02243 arma_inline 02244 const subview_elem1<eT,T1> 02245 Mat<eT>::elem(const Base<uword,T1>& a) const 02246 { 02247 arma_extra_debug_sigprint(); 02248 02249 return subview_elem1<eT,T1>(*this, a); 02250 } 02251 02252 02253 02254 // template<typename eT> 02255 // template<typename T1, typename T2> 02256 // arma_inline 02257 // subview_elem2<eT,T1,T2> 02258 // Mat<eT>::elem(const Base<uword,T1>& a, const Base<uword,T2>& b) 02259 // { 02260 // arma_extra_debug_sigprint(); 02261 // 02262 // return subview_elem2<eT,T1,T2>(*this, a, b); 02263 // } 02264 // 02265 // 02266 // 02267 // template<typename eT> 02268 // template<typename T1, typename T2> 02269 // arma_inline 02270 // const subview_elem2<eT,T1,T2> 02271 // Mat<eT>::elem(const Base<uword,T1>& a, const Base<uword,T2>& b) const 02272 // { 02273 // arma_extra_debug_sigprint(); 02274 // 02275 // return subview_elem2<eT,T1,T2>(*this, a, b); 02276 // } 02277 02278 02279 02281 template<typename eT> 02282 arma_inline 02283 diagview<eT> 02284 Mat<eT>::diag(const sword in_id) 02285 { 02286 arma_extra_debug_sigprint(); 02287 02288 const uword row_offset = (in_id < 0) ? uword(-in_id) : 0; 02289 const uword col_offset = (in_id > 0) ? uword( in_id) : 0; 02290 02291 arma_debug_check 02292 ( 02293 ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), 02294 "Mat::diag(): requested diagonal out of bounds" 02295 ); 02296 02297 const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); 02298 02299 return diagview<eT>(*this, row_offset, col_offset, len); 02300 } 02301 02302 02303 02305 template<typename eT> 02306 arma_inline 02307 const diagview<eT> 02308 Mat<eT>::diag(const sword in_id) const 02309 { 02310 arma_extra_debug_sigprint(); 02311 02312 const uword row_offset = (in_id < 0) ? -in_id : 0; 02313 const uword col_offset = (in_id > 0) ? in_id : 0; 02314 02315 arma_debug_check 02316 ( 02317 ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), 02318 "Mat::diag(): requested diagonal out of bounds" 02319 ); 02320 02321 const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); 02322 02323 return diagview<eT>(*this, row_offset, col_offset, len); 02324 } 02325 02326 02327 02328 template<typename eT> 02329 inline 02330 void 02331 Mat<eT>::swap_rows(const uword in_row1, const uword in_row2) 02332 { 02333 arma_extra_debug_sigprint(); 02334 02335 arma_debug_check 02336 ( 02337 (in_row1 >= n_rows) || (in_row2 >= n_rows), 02338 "Mat::swap_rows(): out of bounds" 02339 ); 02340 02341 for(uword col=0; col<n_cols; ++col) 02342 { 02343 const uword offset = col*n_rows; 02344 const uword pos1 = in_row1 + offset; 02345 const uword pos2 = in_row2 + offset; 02346 02347 const eT tmp = mem[pos1]; 02348 access::rw(mem[pos1]) = mem[pos2]; 02349 access::rw(mem[pos2]) = tmp; 02350 } 02351 02352 } 02353 02354 02355 02356 template<typename eT> 02357 inline 02358 void 02359 Mat<eT>::swap_cols(const uword in_col1, const uword in_col2) 02360 { 02361 arma_extra_debug_sigprint(); 02362 02363 arma_debug_check 02364 ( 02365 (in_col1 >= n_cols) || (in_col2 >= n_cols), 02366 "Mat::swap_cols(): out of bounds" 02367 ); 02368 02369 if(n_elem > 0) 02370 { 02371 eT* ptr1 = colptr(in_col1); 02372 eT* ptr2 = colptr(in_col2); 02373 02374 for(uword row=0; row<n_rows; ++row) 02375 { 02376 const eT tmp = ptr1[row]; 02377 ptr1[row] = ptr2[row]; 02378 ptr2[row] = tmp; 02379 } 02380 } 02381 } 02382 02383 02384 02386 template<typename eT> 02387 inline 02388 void 02389 Mat<eT>::shed_row(const uword row_num) 02390 { 02391 arma_extra_debug_sigprint(); 02392 02393 arma_debug_check( row_num >= n_rows, "Mat::shed_row(): out of bounds"); 02394 02395 shed_rows(row_num, row_num); 02396 } 02397 02398 02399 02401 template<typename eT> 02402 inline 02403 void 02404 Mat<eT>::shed_col(const uword col_num) 02405 { 02406 arma_extra_debug_sigprint(); 02407 02408 arma_debug_check( col_num >= n_cols, "Mat::shed_col(): out of bounds"); 02409 02410 shed_cols(col_num, col_num); 02411 } 02412 02413 02414 02416 template<typename eT> 02417 inline 02418 void 02419 Mat<eT>::shed_rows(const uword in_row1, const uword in_row2) 02420 { 02421 arma_extra_debug_sigprint(); 02422 02423 arma_debug_check 02424 ( 02425 (in_row1 > in_row2) || (in_row2 >= n_rows), 02426 "Mat::shed_rows(): indices out of bounds or incorrectly used" 02427 ); 02428 02429 const uword n_keep_front = in_row1; 02430 const uword n_keep_back = n_rows - (in_row2 + 1); 02431 02432 Mat<eT> X(n_keep_front + n_keep_back, n_cols); 02433 02434 if(n_keep_front > 0) 02435 { 02436 X.rows( 0, (n_keep_front-1) ) = rows( 0, (in_row1-1) ); 02437 } 02438 02439 if(n_keep_back > 0) 02440 { 02441 X.rows( n_keep_front, (n_keep_front+n_keep_back-1) ) = rows( (in_row2+1), (n_rows-1) ); 02442 } 02443 02444 steal_mem(X); 02445 } 02446 02447 02448 02450 template<typename eT> 02451 inline 02452 void 02453 Mat<eT>::shed_cols(const uword in_col1, const uword in_col2) 02454 { 02455 arma_extra_debug_sigprint(); 02456 02457 arma_debug_check 02458 ( 02459 (in_col1 > in_col2) || (in_col2 >= n_cols), 02460 "Mat::shed_cols(): indices out of bounds or incorrectly used" 02461 ); 02462 02463 const uword n_keep_front = in_col1; 02464 const uword n_keep_back = n_cols - (in_col2 + 1); 02465 02466 Mat<eT> X(n_rows, n_keep_front + n_keep_back); 02467 02468 if(n_keep_front > 0) 02469 { 02470 X.cols( 0, (n_keep_front-1) ) = cols( 0, (in_col1-1) ); 02471 } 02472 02473 if(n_keep_back > 0) 02474 { 02475 X.cols( n_keep_front, (n_keep_front+n_keep_back-1) ) = cols( (in_col2+1), (n_cols-1) ); 02476 } 02477 02478 steal_mem(X); 02479 } 02480 02481 02482 02485 template<typename eT> 02486 inline 02487 void 02488 Mat<eT>::insert_rows(const uword row_num, const uword N, const bool set_to_zero) 02489 { 02490 arma_extra_debug_sigprint(); 02491 02492 const uword t_n_rows = n_rows; 02493 const uword t_n_cols = n_cols; 02494 02495 const uword A_n_rows = row_num; 02496 const uword B_n_rows = t_n_rows - row_num; 02497 02498 // insertion at row_num == n_rows is in effect an append operation 02499 arma_debug_check( (row_num > t_n_rows), "Mat::insert_rows(): out of bounds"); 02500 02501 if(N > 0) 02502 { 02503 Mat<eT> out(t_n_rows + N, t_n_cols); 02504 02505 if(A_n_rows > 0) 02506 { 02507 out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1); 02508 } 02509 02510 if(B_n_rows > 0) 02511 { 02512 out.rows(row_num + N, t_n_rows + N - 1) = rows(row_num, t_n_rows-1); 02513 } 02514 02515 if(set_to_zero == true) 02516 { 02517 out.rows(row_num, row_num + N - 1).zeros(); 02518 } 02519 02520 steal_mem(out); 02521 } 02522 } 02523 02524 02525 02528 template<typename eT> 02529 inline 02530 void 02531 Mat<eT>::insert_cols(const uword col_num, const uword N, const bool set_to_zero) 02532 { 02533 arma_extra_debug_sigprint(); 02534 02535 const uword t_n_rows = n_rows; 02536 const uword t_n_cols = n_cols; 02537 02538 const uword A_n_cols = col_num; 02539 const uword B_n_cols = t_n_cols - col_num; 02540 02541 // insertion at col_num == n_cols is in effect an append operation 02542 arma_debug_check( (col_num > t_n_cols), "Mat::insert_cols(): out of bounds"); 02543 02544 if(N > 0) 02545 { 02546 Mat<eT> out(t_n_rows, t_n_cols + N); 02547 02548 if(A_n_cols > 0) 02549 { 02550 out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1); 02551 } 02552 02553 if(B_n_cols > 0) 02554 { 02555 out.cols(col_num + N, t_n_cols + N - 1) = cols(col_num, t_n_cols-1); 02556 } 02557 02558 if(set_to_zero == true) 02559 { 02560 out.cols(col_num, col_num + N - 1).zeros(); 02561 } 02562 02563 steal_mem(out); 02564 } 02565 } 02566 02567 02568 02571 template<typename eT> 02572 template<typename T1> 02573 inline 02574 void 02575 Mat<eT>::insert_rows(const uword row_num, const Base<eT,T1>& X) 02576 { 02577 arma_extra_debug_sigprint(); 02578 02579 const unwrap<T1> tmp(X.get_ref()); 02580 const Mat<eT>& C = tmp.M; 02581 02582 const uword C_n_rows = C.n_rows; 02583 const uword C_n_cols = C.n_cols; 02584 02585 const uword t_n_rows = n_rows; 02586 const uword t_n_cols = n_cols; 02587 02588 const uword A_n_rows = row_num; 02589 const uword B_n_rows = t_n_rows - row_num; 02590 02591 bool err_state = false; 02592 char* err_msg = 0; 02593 02594 // insertion at row_num == n_rows is in effect an append operation 02595 02596 arma_debug_set_error 02597 ( 02598 err_state, 02599 err_msg, 02600 (row_num > t_n_rows), 02601 "Mat::insert_rows(): out of bounds" 02602 ); 02603 02604 arma_debug_set_error 02605 ( 02606 err_state, 02607 err_msg, 02608 ( (C_n_cols != t_n_cols) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ), 02609 "Mat::insert_rows(): given object has an incompatible number of columns" 02610 ); 02611 02612 arma_debug_check(err_state, err_msg); 02613 02614 if(C_n_rows > 0) 02615 { 02616 Mat<eT> out( t_n_rows + C_n_rows, (std::max)(t_n_cols, C_n_cols) ); 02617 02618 if(t_n_cols > 0) 02619 { 02620 if(A_n_rows > 0) 02621 { 02622 out.rows(0, A_n_rows-1) = rows(0, A_n_rows-1); 02623 } 02624 02625 if( (t_n_cols > 0) && (B_n_rows > 0) ) 02626 { 02627 out.rows(row_num + C_n_rows, t_n_rows + C_n_rows - 1) = rows(row_num, t_n_rows - 1); 02628 } 02629 } 02630 02631 if(C_n_cols > 0) 02632 { 02633 out.rows(row_num, row_num + C_n_rows - 1) = C; 02634 } 02635 02636 steal_mem(out); 02637 } 02638 } 02639 02640 02641 02644 template<typename eT> 02645 template<typename T1> 02646 inline 02647 void 02648 Mat<eT>::insert_cols(const uword col_num, const Base<eT,T1>& X) 02649 { 02650 arma_extra_debug_sigprint(); 02651 02652 const unwrap<T1> tmp(X.get_ref()); 02653 const Mat<eT>& C = tmp.M; 02654 02655 const uword C_n_rows = C.n_rows; 02656 const uword C_n_cols = C.n_cols; 02657 02658 const uword t_n_rows = n_rows; 02659 const uword t_n_cols = n_cols; 02660 02661 const uword A_n_cols = col_num; 02662 const uword B_n_cols = t_n_cols - col_num; 02663 02664 bool err_state = false; 02665 char* err_msg = 0; 02666 02667 // insertion at col_num == n_cols is in effect an append operation 02668 02669 arma_debug_set_error 02670 ( 02671 err_state, 02672 err_msg, 02673 (col_num > t_n_cols), 02674 "Mat::insert_cols(): out of bounds" 02675 ); 02676 02677 arma_debug_set_error 02678 ( 02679 err_state, 02680 err_msg, 02681 ( (C_n_rows != t_n_rows) && ( (t_n_rows > 0) || (t_n_cols > 0) ) && ( (C_n_rows > 0) || (C_n_cols > 0) ) ), 02682 "Mat::insert_cols(): given object has an incompatible number of rows" 02683 ); 02684 02685 arma_debug_check(err_state, err_msg); 02686 02687 if(C_n_cols > 0) 02688 { 02689 Mat<eT> out( (std::max)(t_n_rows, C_n_rows), t_n_cols + C_n_cols ); 02690 02691 if(t_n_rows > 0) 02692 { 02693 if(A_n_cols > 0) 02694 { 02695 out.cols(0, A_n_cols-1) = cols(0, A_n_cols-1); 02696 } 02697 02698 if(B_n_cols > 0) 02699 { 02700 out.cols(col_num + C_n_cols, t_n_cols + C_n_cols - 1) = cols(col_num, t_n_cols - 1); 02701 } 02702 } 02703 02704 if(C_n_rows > 0) 02705 { 02706 out.cols(col_num, col_num + C_n_cols - 1) = C; 02707 } 02708 02709 steal_mem(out); 02710 } 02711 } 02712 02713 02714 02715 template<typename eT> 02716 template<typename gen_type> 02717 inline 02718 Mat<eT>::Mat(const Gen<eT, gen_type>& X) 02719 : n_rows(X.n_rows) 02720 , n_cols(X.n_cols) 02721 , n_elem(n_rows*n_cols) 02722 , vec_state(0) 02723 , mem_state(0) 02724 , mem() 02725 { 02726 arma_extra_debug_sigprint_this(this); 02727 02728 init_cold(); 02729 02730 X.apply(*this); 02731 } 02732 02733 02734 02735 template<typename eT> 02736 template<typename gen_type> 02737 inline 02738 const Mat<eT>& 02739 Mat<eT>::operator=(const Gen<eT, gen_type>& X) 02740 { 02741 arma_extra_debug_sigprint(); 02742 02743 init_warm(X.n_rows, X.n_cols); 02744 02745 X.apply(*this); 02746 02747 return *this; 02748 } 02749 02750 02751 02752 template<typename eT> 02753 template<typename gen_type> 02754 inline 02755 const Mat<eT>& 02756 Mat<eT>::operator+=(const Gen<eT, gen_type>& X) 02757 { 02758 arma_extra_debug_sigprint(); 02759 02760 X.apply_inplace_plus(*this); 02761 02762 return *this; 02763 } 02764 02765 02766 02767 template<typename eT> 02768 template<typename gen_type> 02769 inline 02770 const Mat<eT>& 02771 Mat<eT>::operator-=(const Gen<eT, gen_type>& X) 02772 { 02773 arma_extra_debug_sigprint(); 02774 02775 X.apply_inplace_minus(*this); 02776 02777 return *this; 02778 } 02779 02780 02781 02782 template<typename eT> 02783 template<typename gen_type> 02784 inline 02785 const Mat<eT>& 02786 Mat<eT>::operator*=(const Gen<eT, gen_type>& X) 02787 { 02788 arma_extra_debug_sigprint(); 02789 02790 const Mat<eT> tmp(X); 02791 02792 return (*this).operator*=(tmp); 02793 } 02794 02795 02796 02797 template<typename eT> 02798 template<typename gen_type> 02799 inline 02800 const Mat<eT>& 02801 Mat<eT>::operator%=(const Gen<eT, gen_type>& X) 02802 { 02803 arma_extra_debug_sigprint(); 02804 02805 X.apply_inplace_schur(*this); 02806 02807 return *this; 02808 } 02809 02810 02811 02812 template<typename eT> 02813 template<typename gen_type> 02814 inline 02815 const Mat<eT>& 02816 Mat<eT>::operator/=(const Gen<eT, gen_type>& X) 02817 { 02818 arma_extra_debug_sigprint(); 02819 02820 X.apply_inplace_div(*this); 02821 02822 return *this; 02823 } 02824 02825 02826 02828 template<typename eT> 02829 template<typename T1, typename op_type> 02830 inline 02831 Mat<eT>::Mat(const Op<T1, op_type>& X) 02832 : n_rows(0) 02833 , n_cols(0) 02834 , n_elem(0) 02835 , vec_state(0) 02836 , mem_state(0) 02837 , mem() 02838 { 02839 arma_extra_debug_sigprint_this(this); 02840 02841 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 02842 02843 op_type::apply(*this, X); 02844 } 02845 02846 02847 02849 template<typename eT> 02850 template<typename T1, typename op_type> 02851 inline 02852 const Mat<eT>& 02853 Mat<eT>::operator=(const Op<T1, op_type>& X) 02854 { 02855 arma_extra_debug_sigprint(); 02856 02857 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 02858 02859 op_type::apply(*this, X); 02860 02861 return *this; 02862 } 02863 02864 02865 02867 template<typename eT> 02868 template<typename T1, typename op_type> 02869 inline 02870 const Mat<eT>& 02871 Mat<eT>::operator+=(const Op<T1, op_type>& X) 02872 { 02873 arma_extra_debug_sigprint(); 02874 02875 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 02876 02877 const Mat<eT> m(X); 02878 02879 return (*this).operator+=(m); 02880 } 02881 02882 02883 02885 template<typename eT> 02886 template<typename T1, typename op_type> 02887 inline 02888 const Mat<eT>& 02889 Mat<eT>::operator-=(const Op<T1, op_type>& X) 02890 { 02891 arma_extra_debug_sigprint(); 02892 02893 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 02894 02895 const Mat<eT> m(X); 02896 02897 return (*this).operator-=(m); 02898 } 02899 02900 02901 02903 template<typename eT> 02904 template<typename T1, typename op_type> 02905 inline 02906 const Mat<eT>& 02907 Mat<eT>::operator*=(const Op<T1, op_type>& X) 02908 { 02909 arma_extra_debug_sigprint(); 02910 02911 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 02912 02913 glue_times::apply_inplace(*this, X); 02914 02915 return *this; 02916 } 02917 02918 02919 02921 template<typename eT> 02922 template<typename T1, typename op_type> 02923 inline 02924 const Mat<eT>& 02925 Mat<eT>::operator%=(const Op<T1, op_type>& X) 02926 { 02927 arma_extra_debug_sigprint(); 02928 02929 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 02930 02931 const Mat<eT> m(X); 02932 02933 return (*this).operator%=(m); 02934 } 02935 02936 02937 02939 template<typename eT> 02940 template<typename T1, typename op_type> 02941 inline 02942 const Mat<eT>& 02943 Mat<eT>::operator/=(const Op<T1, op_type>& X) 02944 { 02945 arma_extra_debug_sigprint(); 02946 02947 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 02948 02949 const Mat<eT> m(X); 02950 02951 return (*this).operator/=(m); 02952 } 02953 02954 02955 02957 template<typename eT> 02958 template<typename T1, typename eop_type> 02959 inline 02960 Mat<eT>::Mat(const eOp<T1, eop_type>& X) 02961 : n_rows(X.get_n_rows()) 02962 , n_cols(X.get_n_cols()) 02963 , n_elem(X.get_n_elem()) 02964 , vec_state(0) 02965 , mem_state(0) 02966 , mem() 02967 { 02968 arma_extra_debug_sigprint_this(this); 02969 02970 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 02971 02972 init_cold(); 02973 02974 eop_type::apply(*this, X); 02975 } 02976 02977 02978 02980 template<typename eT> 02981 template<typename T1, typename eop_type> 02982 inline 02983 const Mat<eT>& 02984 Mat<eT>::operator=(const eOp<T1, eop_type>& X) 02985 { 02986 arma_extra_debug_sigprint(); 02987 02988 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 02989 02990 const bool bad_alias = (X.P.has_subview && X.P.is_alias(*this)); 02991 02992 if(bad_alias == false) 02993 { 02994 init_warm(X.get_n_rows(), X.get_n_cols()); 02995 02996 eop_type::apply(*this, X); 02997 } 02998 else 02999 { 03000 Mat<eT> tmp(X); 03001 03002 steal_mem(tmp); 03003 } 03004 03005 return *this; 03006 } 03007 03008 03009 03010 template<typename eT> 03011 template<typename T1, typename eop_type> 03012 inline 03013 const Mat<eT>& 03014 Mat<eT>::operator+=(const eOp<T1, eop_type>& X) 03015 { 03016 arma_extra_debug_sigprint(); 03017 03018 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03019 03020 eop_type::apply_inplace_plus(*this, X); 03021 03022 return *this; 03023 } 03024 03025 03026 03027 template<typename eT> 03028 template<typename T1, typename eop_type> 03029 inline 03030 const Mat<eT>& 03031 Mat<eT>::operator-=(const eOp<T1, eop_type>& X) 03032 { 03033 arma_extra_debug_sigprint(); 03034 03035 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03036 03037 eop_type::apply_inplace_minus(*this, X); 03038 03039 return *this; 03040 } 03041 03042 03043 03044 template<typename eT> 03045 template<typename T1, typename eop_type> 03046 inline 03047 const Mat<eT>& 03048 Mat<eT>::operator*=(const eOp<T1, eop_type>& X) 03049 { 03050 arma_extra_debug_sigprint(); 03051 03052 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03053 03054 glue_times::apply_inplace(*this, X); 03055 03056 return *this; 03057 } 03058 03059 03060 03061 template<typename eT> 03062 template<typename T1, typename eop_type> 03063 inline 03064 const Mat<eT>& 03065 Mat<eT>::operator%=(const eOp<T1, eop_type>& X) 03066 { 03067 arma_extra_debug_sigprint(); 03068 03069 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03070 03071 eop_type::apply_inplace_schur(*this, X); 03072 03073 return *this; 03074 } 03075 03076 03077 03078 template<typename eT> 03079 template<typename T1, typename eop_type> 03080 inline 03081 const Mat<eT>& 03082 Mat<eT>::operator/=(const eOp<T1, eop_type>& X) 03083 { 03084 arma_extra_debug_sigprint(); 03085 03086 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03087 03088 eop_type::apply_inplace_div(*this, X); 03089 03090 return *this; 03091 } 03092 03093 03094 03096 template<typename eT> 03097 template<typename T1, typename op_type> 03098 inline 03099 Mat<eT>::Mat(const mtOp<eT, T1, op_type>& X) 03100 : n_rows(0) 03101 , n_cols(0) 03102 , n_elem(0) 03103 , vec_state(0) 03104 , mem_state(0) 03105 , mem() 03106 { 03107 arma_extra_debug_sigprint_this(this); 03108 03109 op_type::apply(*this, X); 03110 } 03111 03112 03113 03115 template<typename eT> 03116 template<typename T1, typename op_type> 03117 inline 03118 const Mat<eT>& 03119 Mat<eT>::operator=(const mtOp<eT, T1, op_type>& X) 03120 { 03121 arma_extra_debug_sigprint(); 03122 03123 op_type::apply(*this, X); 03124 03125 return *this; 03126 } 03127 03128 03129 03131 template<typename eT> 03132 template<typename T1, typename op_type> 03133 inline 03134 const Mat<eT>& 03135 Mat<eT>::operator+=(const mtOp<eT, T1, op_type>& X) 03136 { 03137 arma_extra_debug_sigprint(); 03138 03139 const Mat<eT> m(X); 03140 03141 return (*this).operator+=(m); 03142 } 03143 03144 03145 03147 template<typename eT> 03148 template<typename T1, typename op_type> 03149 inline 03150 const Mat<eT>& 03151 Mat<eT>::operator-=(const mtOp<eT, T1, op_type>& X) 03152 { 03153 arma_extra_debug_sigprint(); 03154 03155 const Mat<eT> m(X); 03156 03157 return (*this).operator-=(m); 03158 } 03159 03160 03161 03163 template<typename eT> 03164 template<typename T1, typename op_type> 03165 inline 03166 const Mat<eT>& 03167 Mat<eT>::operator*=(const mtOp<eT, T1, op_type>& X) 03168 { 03169 arma_extra_debug_sigprint(); 03170 03171 const Mat<eT> m(X); 03172 03173 return (*this).operator*=(m); 03174 } 03175 03176 03177 03179 template<typename eT> 03180 template<typename T1, typename op_type> 03181 inline 03182 const Mat<eT>& 03183 Mat<eT>::operator%=(const mtOp<eT, T1, op_type>& X) 03184 { 03185 arma_extra_debug_sigprint(); 03186 03187 const Mat<eT> m(X); 03188 03189 return (*this).operator%=(m); 03190 } 03191 03192 03193 03195 template<typename eT> 03196 template<typename T1, typename op_type> 03197 inline 03198 const Mat<eT>& 03199 Mat<eT>::operator/=(const mtOp<eT, T1, op_type>& X) 03200 { 03201 arma_extra_debug_sigprint(); 03202 03203 const Mat<eT> m(X); 03204 03205 return (*this).operator/=(m); 03206 } 03207 03208 03209 03211 template<typename eT> 03212 template<typename T1, typename T2, typename glue_type> 03213 inline 03214 Mat<eT>::Mat(const Glue<T1, T2, glue_type>& X) 03215 : n_rows(0) 03216 , n_cols(0) 03217 , n_elem(0) 03218 , vec_state(0) 03219 , mem_state(0) 03220 , mem() 03221 { 03222 arma_extra_debug_sigprint_this(this); 03223 03224 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03225 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03226 03227 glue_type::apply(*this, X); 03228 } 03229 03230 03231 03233 template<typename eT> 03234 template<typename T1, typename T2, typename glue_type> 03235 inline 03236 const Mat<eT>& 03237 Mat<eT>::operator=(const Glue<T1, T2, glue_type>& X) 03238 { 03239 arma_extra_debug_sigprint(); 03240 03241 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03242 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03243 03244 glue_type::apply(*this, X); 03245 03246 return *this; 03247 } 03248 03249 03250 03252 template<typename eT> 03253 template<typename T1, typename T2, typename glue_type> 03254 inline 03255 const Mat<eT>& 03256 Mat<eT>::operator+=(const Glue<T1, T2, glue_type>& X) 03257 { 03258 arma_extra_debug_sigprint(); 03259 03260 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03261 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03262 03263 const Mat<eT> m(X); 03264 03265 return (*this).operator+=(m); 03266 } 03267 03268 03269 03271 template<typename eT> 03272 template<typename T1, typename T2, typename glue_type> 03273 inline 03274 const Mat<eT>& 03275 Mat<eT>::operator-=(const Glue<T1, T2, glue_type>& X) 03276 { 03277 arma_extra_debug_sigprint(); 03278 03279 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03280 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03281 03282 const Mat<eT> m(X); 03283 03284 return (*this).operator-=(m); 03285 } 03286 03287 03288 03290 template<typename eT> 03291 template<typename T1, typename T2, typename glue_type> 03292 inline 03293 const Mat<eT>& 03294 Mat<eT>::operator*=(const Glue<T1, T2, glue_type>& X) 03295 { 03296 arma_extra_debug_sigprint(); 03297 03298 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03299 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03300 03301 glue_times::apply_inplace(*this, X); 03302 03303 return *this; 03304 } 03305 03306 03307 03309 template<typename eT> 03310 template<typename T1, typename T2, typename glue_type> 03311 inline 03312 const Mat<eT>& 03313 Mat<eT>::operator%=(const Glue<T1, T2, glue_type>& X) 03314 { 03315 arma_extra_debug_sigprint(); 03316 03317 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03318 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03319 03320 const Mat<eT> m(X); 03321 03322 return (*this).operator%=(m); 03323 } 03324 03325 03326 03328 template<typename eT> 03329 template<typename T1, typename T2, typename glue_type> 03330 inline 03331 const Mat<eT>& 03332 Mat<eT>::operator/=(const Glue<T1, T2, glue_type>& X) 03333 { 03334 arma_extra_debug_sigprint(); 03335 03336 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03337 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03338 03339 const Mat<eT> m(X); 03340 03341 return (*this).operator/=(m); 03342 } 03343 03344 03345 03346 template<typename eT> 03347 template<typename T1, typename T2> 03348 inline 03349 const Mat<eT>& 03350 Mat<eT>::operator+=(const Glue<T1, T2, glue_times>& X) 03351 { 03352 arma_extra_debug_sigprint(); 03353 03354 glue_times::apply_inplace_plus(*this, X, sword(+1)); 03355 03356 return *this; 03357 } 03358 03359 03360 03361 template<typename eT> 03362 template<typename T1, typename T2> 03363 inline 03364 const Mat<eT>& 03365 Mat<eT>::operator-=(const Glue<T1, T2, glue_times>& X) 03366 { 03367 arma_extra_debug_sigprint(); 03368 03369 glue_times::apply_inplace_plus(*this, X, sword(-1)); 03370 03371 return *this; 03372 } 03373 03374 03375 03377 template<typename eT> 03378 template<typename T1, typename T2, typename eglue_type> 03379 inline 03380 Mat<eT>::Mat(const eGlue<T1, T2, eglue_type>& X) 03381 : n_rows(X.get_n_rows()) 03382 , n_cols(X.get_n_cols()) 03383 , n_elem(X.get_n_elem()) 03384 , vec_state(0) 03385 , mem_state(0) 03386 , mem() 03387 { 03388 arma_extra_debug_sigprint_this(this); 03389 03390 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03391 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03392 03393 init_cold(); 03394 03395 eglue_type::apply(*this, X); 03396 } 03397 03398 03399 03401 template<typename eT> 03402 template<typename T1, typename T2, typename eglue_type> 03403 inline 03404 const Mat<eT>& 03405 Mat<eT>::operator=(const eGlue<T1, T2, eglue_type>& X) 03406 { 03407 arma_extra_debug_sigprint(); 03408 03409 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03410 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03411 03412 const bool bad_alias = ( (X.P1.has_subview && X.P1.is_alias(*this)) || ( X.P2.has_subview && X.P2.is_alias(*this)) ); 03413 03414 if(bad_alias == false) 03415 { 03416 init_warm(X.get_n_rows(), X.get_n_cols()); 03417 03418 eglue_type::apply(*this, X); 03419 } 03420 else 03421 { 03422 Mat<eT> tmp(X); 03423 03424 steal_mem(tmp); 03425 } 03426 03427 return *this; 03428 } 03429 03430 03431 03433 template<typename eT> 03434 template<typename T1, typename T2, typename eglue_type> 03435 inline 03436 const Mat<eT>& 03437 Mat<eT>::operator+=(const eGlue<T1, T2, eglue_type>& X) 03438 { 03439 arma_extra_debug_sigprint(); 03440 03441 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03442 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03443 03444 eglue_type::apply_inplace_plus(*this, X); 03445 03446 return *this; 03447 } 03448 03449 03450 03452 template<typename eT> 03453 template<typename T1, typename T2, typename eglue_type> 03454 inline 03455 const Mat<eT>& 03456 Mat<eT>::operator-=(const eGlue<T1, T2, eglue_type>& X) 03457 { 03458 arma_extra_debug_sigprint(); 03459 03460 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03461 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03462 03463 eglue_type::apply_inplace_minus(*this, X); 03464 03465 return *this; 03466 } 03467 03468 03469 03470 template<typename eT> 03471 template<typename T1, typename T2, typename eglue_type> 03472 inline 03473 const Mat<eT>& 03474 Mat<eT>::operator*=(const eGlue<T1, T2, eglue_type>& X) 03475 { 03476 arma_extra_debug_sigprint(); 03477 03478 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03479 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03480 03481 glue_times::apply_inplace(*this, X); 03482 return *this; 03483 } 03484 03485 03486 03487 template<typename eT> 03488 template<typename T1, typename T2, typename eglue_type> 03489 inline 03490 const Mat<eT>& 03491 Mat<eT>::operator%=(const eGlue<T1, T2, eglue_type>& X) 03492 { 03493 arma_extra_debug_sigprint(); 03494 03495 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03496 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03497 03498 eglue_type::apply_inplace_schur(*this, X); 03499 return *this; 03500 } 03501 03502 03503 03504 template<typename eT> 03505 template<typename T1, typename T2, typename eglue_type> 03506 inline 03507 const Mat<eT>& 03508 Mat<eT>::operator/=(const eGlue<T1, T2, eglue_type>& X) 03509 { 03510 arma_extra_debug_sigprint(); 03511 03512 arma_type_check(( is_same_type< eT, typename T1::elem_type >::value == false )); 03513 arma_type_check(( is_same_type< eT, typename T2::elem_type >::value == false )); 03514 03515 eglue_type::apply_inplace_div(*this, X); 03516 return *this; 03517 } 03518 03519 03520 03522 template<typename eT> 03523 template<typename T1, typename T2, typename glue_type> 03524 inline 03525 Mat<eT>::Mat(const mtGlue<eT, T1, T2, glue_type>& X) 03526 : n_rows(0) 03527 , n_cols(0) 03528 , n_elem(0) 03529 , vec_state(0) 03530 , mem_state(0) 03531 , mem() 03532 { 03533 arma_extra_debug_sigprint_this(this); 03534 03535 glue_type::apply(*this, X); 03536 } 03537 03538 03539 03541 template<typename eT> 03542 template<typename T1, typename T2, typename glue_type> 03543 inline 03544 const Mat<eT>& 03545 Mat<eT>::operator=(const mtGlue<eT, T1, T2, glue_type>& X) 03546 { 03547 arma_extra_debug_sigprint(); 03548 03549 glue_type::apply(*this, X); 03550 03551 return *this; 03552 } 03553 03554 03555 03557 template<typename eT> 03558 template<typename T1, typename T2, typename glue_type> 03559 inline 03560 const Mat<eT>& 03561 Mat<eT>::operator+=(const mtGlue<eT, T1, T2, glue_type>& X) 03562 { 03563 arma_extra_debug_sigprint(); 03564 03565 const Mat<eT> m(X); 03566 03567 return (*this).operator+=(m); 03568 } 03569 03570 03571 03573 template<typename eT> 03574 template<typename T1, typename T2, typename glue_type> 03575 inline 03576 const Mat<eT>& 03577 Mat<eT>::operator-=(const mtGlue<eT, T1, T2, glue_type>& X) 03578 { 03579 arma_extra_debug_sigprint(); 03580 03581 const Mat<eT> m(X); 03582 03583 return (*this).operator-=(m); 03584 } 03585 03586 03587 03589 template<typename eT> 03590 template<typename T1, typename T2, typename glue_type> 03591 inline 03592 const Mat<eT>& 03593 Mat<eT>::operator*=(const mtGlue<eT, T1, T2, glue_type>& X) 03594 { 03595 arma_extra_debug_sigprint(); 03596 03597 const Mat<eT> m(X); 03598 03599 glue_times::apply_inplace(*this, m); 03600 03601 return *this; 03602 } 03603 03604 03605 03607 template<typename eT> 03608 template<typename T1, typename T2, typename glue_type> 03609 inline 03610 const Mat<eT>& 03611 Mat<eT>::operator%=(const mtGlue<eT, T1, T2, glue_type>& X) 03612 { 03613 arma_extra_debug_sigprint(); 03614 03615 const Mat<eT> m(X); 03616 03617 return (*this).operator%=(m); 03618 } 03619 03620 03621 03623 template<typename eT> 03624 template<typename T1, typename T2, typename glue_type> 03625 inline 03626 const Mat<eT>& 03627 Mat<eT>::operator/=(const mtGlue<eT, T1, T2, glue_type>& X) 03628 { 03629 arma_extra_debug_sigprint(); 03630 03631 const Mat<eT> m(X); 03632 03633 return (*this).operator/=(m); 03634 } 03635 03636 03637 03639 template<typename eT> 03640 arma_inline 03641 arma_warn_unused 03642 eT& 03643 Mat<eT>::operator() (const uword i) 03644 { 03645 arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds"); 03646 return access::rw(mem[i]); 03647 } 03648 03649 03650 03652 template<typename eT> 03653 arma_inline 03654 arma_warn_unused 03655 eT 03656 Mat<eT>::operator() (const uword i) const 03657 { 03658 arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds"); 03659 return mem[i]; 03660 } 03661 03662 03664 template<typename eT> 03665 arma_inline 03666 arma_warn_unused 03667 eT& 03668 Mat<eT>::operator[] (const uword i) 03669 { 03670 return access::rw(mem[i]); 03671 } 03672 03673 03674 03676 template<typename eT> 03677 arma_inline 03678 arma_warn_unused 03679 eT 03680 Mat<eT>::operator[] (const uword i) const 03681 { 03682 return mem[i]; 03683 } 03684 03685 03686 03688 template<typename eT> 03689 arma_inline 03690 arma_warn_unused 03691 eT& 03692 Mat<eT>::at(const uword i) 03693 { 03694 return access::rw(mem[i]); 03695 } 03696 03697 03698 03700 template<typename eT> 03701 arma_inline 03702 arma_warn_unused 03703 eT 03704 Mat<eT>::at(const uword i) const 03705 { 03706 return mem[i]; 03707 } 03708 03709 03710 03712 template<typename eT> 03713 arma_inline 03714 arma_warn_unused 03715 eT& 03716 Mat<eT>::operator() (const uword in_row, const uword in_col) 03717 { 03718 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): out of bounds"); 03719 return access::rw(mem[in_row + in_col*n_rows]); 03720 } 03721 03722 03723 03725 template<typename eT> 03726 arma_inline 03727 arma_warn_unused 03728 eT 03729 Mat<eT>::operator() (const uword in_row, const uword in_col) const 03730 { 03731 arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::operator(): out of bounds"); 03732 return mem[in_row + in_col*n_rows]; 03733 } 03734 03735 03736 03738 template<typename eT> 03739 arma_inline 03740 arma_warn_unused 03741 eT& 03742 Mat<eT>::at(const uword in_row, const uword in_col) 03743 { 03744 return access::rw( mem[in_row + in_col*n_rows] ); 03745 } 03746 03747 03748 03750 template<typename eT> 03751 arma_inline 03752 arma_warn_unused 03753 eT 03754 Mat<eT>::at(const uword in_row, const uword in_col) const 03755 { 03756 return mem[in_row + in_col*n_rows]; 03757 } 03758 03759 03760 03762 template<typename eT> 03763 arma_inline 03764 const Mat<eT>& 03765 Mat<eT>::operator++() 03766 { 03767 Mat_aux::prefix_pp(*this); 03768 return *this; 03769 } 03770 03771 03772 03774 template<typename eT> 03775 arma_inline 03776 void 03777 Mat<eT>::operator++(int) 03778 { 03779 Mat_aux::postfix_pp(*this); 03780 } 03781 03782 03783 03785 template<typename eT> 03786 arma_inline 03787 const Mat<eT>& 03788 Mat<eT>::operator--() 03789 { 03790 Mat_aux::prefix_mm(*this); 03791 return *this; 03792 } 03793 03794 03795 03797 template<typename eT> 03798 arma_inline 03799 void 03800 Mat<eT>::operator--(int) 03801 { 03802 Mat_aux::postfix_mm(*this); 03803 } 03804 03805 03806 03808 template<typename eT> 03809 arma_inline 03810 arma_warn_unused 03811 bool 03812 Mat<eT>::is_empty() const 03813 { 03814 return (n_elem == 0); 03815 } 03816 03817 03818 03820 template<typename eT> 03821 arma_inline 03822 arma_warn_unused 03823 bool 03824 Mat<eT>::is_vec() const 03825 { 03826 return ( (n_rows == 1) || (n_cols == 1) ); 03827 } 03828 03829 03830 03832 template<typename eT> 03833 arma_inline 03834 arma_warn_unused 03835 bool 03836 Mat<eT>::is_rowvec() const 03837 { 03838 return (n_rows == 1); 03839 } 03840 03841 03842 03844 template<typename eT> 03845 arma_inline 03846 arma_warn_unused 03847 bool 03848 Mat<eT>::is_colvec() const 03849 { 03850 return (n_cols == 1); 03851 } 03852 03853 03854 03856 template<typename eT> 03857 arma_inline 03858 arma_warn_unused 03859 bool 03860 Mat<eT>::is_square() const 03861 { 03862 return (n_rows == n_cols); 03863 } 03864 03865 03866 03868 template<typename eT> 03869 inline 03870 arma_warn_unused 03871 bool 03872 Mat<eT>::is_finite() const 03873 { 03874 return arrayops::is_finite( memptr(), n_elem ); 03875 } 03876 03877 03878 03880 template<typename eT> 03881 arma_inline 03882 arma_warn_unused 03883 bool 03884 Mat<eT>::in_range(const uword i) const 03885 { 03886 return (i < n_elem); 03887 } 03888 03889 03890 03892 template<typename eT> 03893 arma_inline 03894 arma_warn_unused 03895 bool 03896 Mat<eT>::in_range(const span& x) const 03897 { 03898 arma_extra_debug_sigprint(); 03899 03900 if(x.whole == true) 03901 { 03902 return true; 03903 } 03904 else 03905 { 03906 const uword a = x.a; 03907 const uword b = x.b; 03908 03909 return ( (a <= b) && (b < n_elem) ); 03910 } 03911 } 03912 03913 03914 03916 template<typename eT> 03917 arma_inline 03918 arma_warn_unused 03919 bool 03920 Mat<eT>::in_range(const uword in_row, const uword in_col) const 03921 { 03922 return ( (in_row < n_rows) && (in_col < n_cols) ); 03923 } 03924 03925 03926 03927 template<typename eT> 03928 arma_inline 03929 arma_warn_unused 03930 bool 03931 Mat<eT>::in_range(const span& row_span, const uword in_col) const 03932 { 03933 arma_extra_debug_sigprint(); 03934 03935 if(row_span.whole == true) 03936 { 03937 return (in_col < n_cols); 03938 } 03939 else 03940 { 03941 const uword in_row1 = row_span.a; 03942 const uword in_row2 = row_span.b; 03943 03944 return ( (in_row1 <= in_row2) && (in_row2 < n_rows) && (in_col < n_cols) ); 03945 } 03946 } 03947 03948 03949 03950 template<typename eT> 03951 arma_inline 03952 arma_warn_unused 03953 bool 03954 Mat<eT>::in_range(const uword in_row, const span& col_span) const 03955 { 03956 arma_extra_debug_sigprint(); 03957 03958 if(col_span.whole == true) 03959 { 03960 return (in_row < n_rows); 03961 } 03962 else 03963 { 03964 const uword in_col1 = col_span.a; 03965 const uword in_col2 = col_span.b; 03966 03967 return ( (in_row < n_rows) && (in_col1 <= in_col2) && (in_col2 < n_cols) ); 03968 } 03969 } 03970 03971 03972 03973 template<typename eT> 03974 arma_inline 03975 arma_warn_unused 03976 bool 03977 Mat<eT>::in_range(const span& row_span, const span& col_span) const 03978 { 03979 arma_extra_debug_sigprint(); 03980 03981 const uword in_row1 = row_span.a; 03982 const uword in_row2 = row_span.b; 03983 03984 const uword in_col1 = col_span.a; 03985 const uword in_col2 = col_span.b; 03986 03987 const bool rows_ok = row_span.whole ? true : ( (in_row1 <= in_row2) && (in_row2 < n_rows) ); 03988 const bool cols_ok = col_span.whole ? true : ( (in_col1 <= in_col2) && (in_col2 < n_cols) ); 03989 03990 return ( (rows_ok == true) && (cols_ok == true) ); 03991 } 03992 03993 03994 03996 template<typename eT> 03997 arma_inline 03998 arma_warn_unused 03999 eT* 04000 Mat<eT>::colptr(const uword in_col) 04001 { 04002 return & access::rw(mem[in_col*n_rows]); 04003 } 04004 04005 04006 04008 template<typename eT> 04009 arma_inline 04010 arma_warn_unused 04011 const eT* 04012 Mat<eT>::colptr(const uword in_col) const 04013 { 04014 return & mem[in_col*n_rows]; 04015 } 04016 04017 04018 04020 template<typename eT> 04021 arma_inline 04022 arma_warn_unused 04023 eT* 04024 Mat<eT>::memptr() 04025 { 04026 return const_cast<eT*>(mem); 04027 } 04028 04029 04030 04032 template<typename eT> 04033 arma_inline 04034 arma_warn_unused 04035 const eT* 04036 Mat<eT>::memptr() const 04037 { 04038 return mem; 04039 } 04040 04041 04042 04047 template<typename eT> 04048 inline 04049 void 04050 Mat<eT>::impl_print(const std::string& extra_text) const 04051 { 04052 arma_extra_debug_sigprint(); 04053 04054 if(extra_text.length() != 0) 04055 { 04056 const std::streamsize orig_width = cout.width(); 04057 04058 cout << extra_text << '\n'; 04059 04060 cout.width(orig_width); 04061 } 04062 04063 arma_ostream::print(cout, *this, true); 04064 } 04065 04066 04067 04072 template<typename eT> 04073 inline 04074 void 04075 Mat<eT>::impl_print(std::ostream& user_stream, const std::string& extra_text) const 04076 { 04077 arma_extra_debug_sigprint(); 04078 04079 if(extra_text.length() != 0) 04080 { 04081 const std::streamsize orig_width = user_stream.width(); 04082 04083 user_stream << extra_text << '\n'; 04084 04085 user_stream.width(orig_width); 04086 } 04087 04088 arma_ostream::print(user_stream, *this, true); 04089 } 04090 04091 04092 04094 template<typename eT> 04095 inline 04096 void 04097 Mat<eT>::impl_print_trans(const std::string& extra_text) const 04098 { 04099 arma_extra_debug_sigprint(); 04100 04101 Mat<eT> tmp; 04102 op_strans::apply_noalias(tmp, *this); 04103 04104 tmp.impl_print(extra_text); 04105 } 04106 04107 04108 04110 template<typename eT> 04111 inline 04112 void 04113 Mat<eT>::impl_print_trans(std::ostream& user_stream, const std::string& extra_text) const 04114 { 04115 arma_extra_debug_sigprint(); 04116 04117 Mat<eT> tmp; 04118 op_strans::apply_noalias(tmp, *this); 04119 04120 tmp.impl_print(user_stream, extra_text); 04121 } 04122 04123 04124 04129 template<typename eT> 04130 inline 04131 void 04132 Mat<eT>::impl_raw_print(const std::string& extra_text) const 04133 { 04134 arma_extra_debug_sigprint(); 04135 04136 if(extra_text.length() != 0) 04137 { 04138 const std::streamsize orig_width = cout.width(); 04139 04140 cout << extra_text << '\n'; 04141 04142 cout.width(orig_width); 04143 } 04144 04145 arma_ostream::print(cout, *this, false); 04146 } 04147 04148 04149 04154 template<typename eT> 04155 inline 04156 void 04157 Mat<eT>::impl_raw_print(std::ostream& user_stream, const std::string& extra_text) const 04158 { 04159 arma_extra_debug_sigprint(); 04160 04161 if(extra_text.length() != 0) 04162 { 04163 const std::streamsize orig_width = user_stream.width(); 04164 04165 user_stream << extra_text << '\n'; 04166 04167 user_stream.width(orig_width); 04168 } 04169 04170 arma_ostream::print(user_stream, *this, false); 04171 } 04172 04173 04174 04176 template<typename eT> 04177 inline 04178 void 04179 Mat<eT>::impl_raw_print_trans(const std::string& extra_text) const 04180 { 04181 arma_extra_debug_sigprint(); 04182 04183 Mat<eT> tmp; 04184 op_strans::apply_noalias(tmp, *this); 04185 04186 tmp.impl_raw_print(extra_text); 04187 } 04188 04189 04190 04192 template<typename eT> 04193 inline 04194 void 04195 Mat<eT>::impl_raw_print_trans(std::ostream& user_stream, const std::string& extra_text) const 04196 { 04197 arma_extra_debug_sigprint(); 04198 04199 Mat<eT> tmp; 04200 op_strans::apply_noalias(tmp, *this); 04201 04202 tmp.impl_raw_print(user_stream, extra_text); 04203 } 04204 04205 04206 04208 template<typename eT> 04209 inline 04210 void 04211 Mat<eT>::set_size(const uword in_elem) 04212 { 04213 arma_extra_debug_sigprint(); 04214 04215 switch(vec_state) 04216 { 04217 case 0: 04218 case 1: 04219 init_warm(in_elem, 1); 04220 break; 04221 04222 case 2: 04223 init_warm(1, in_elem); 04224 break; 04225 04226 default: 04227 ; 04228 } 04229 } 04230 04231 04232 04234 template<typename eT> 04235 inline 04236 void 04237 Mat<eT>::set_size(const uword in_rows, const uword in_cols) 04238 { 04239 arma_extra_debug_sigprint(); 04240 04241 init_warm(in_rows, in_cols); 04242 } 04243 04244 04245 04247 template<typename eT> 04248 inline 04249 void 04250 Mat<eT>::resize(const uword in_elem) 04251 { 04252 arma_extra_debug_sigprint(); 04253 04254 switch(vec_state) 04255 { 04256 case 0: 04257 case 1: 04258 (*this).resize(in_elem, 1); 04259 break; 04260 04261 case 2: 04262 (*this).resize(1, in_elem); 04263 break; 04264 04265 default: 04266 ; 04267 } 04268 } 04269 04270 04271 04273 template<typename eT> 04274 inline 04275 void 04276 Mat<eT>::resize(const uword in_rows, const uword in_cols) 04277 { 04278 arma_extra_debug_sigprint(); 04279 04280 *this = arma::resize(*this, in_rows, in_cols); 04281 } 04282 04283 04284 04286 template<typename eT> 04287 inline 04288 void 04289 Mat<eT>::reshape(const uword in_rows, const uword in_cols, const uword dim) 04290 { 04291 arma_extra_debug_sigprint(); 04292 04293 *this = arma::reshape(*this, in_rows, in_cols, dim); 04294 } 04295 04296 04297 04299 template<typename eT> 04300 template<typename eT2> 04301 inline 04302 void 04303 Mat<eT>::copy_size(const Mat<eT2>& m) 04304 { 04305 arma_extra_debug_sigprint(); 04306 04307 init_warm(m.n_rows, m.n_cols); 04308 } 04309 04310 04311 04313 template<typename eT> 04314 arma_hot 04315 inline 04316 const Mat<eT>& 04317 Mat<eT>::fill(const eT val) 04318 { 04319 arma_extra_debug_sigprint(); 04320 04321 arrayops::inplace_set( memptr(), val, n_elem ); 04322 04323 return *this; 04324 } 04325 04326 04327 04328 template<typename eT> 04329 inline 04330 const Mat<eT>& 04331 Mat<eT>::zeros() 04332 { 04333 arma_extra_debug_sigprint(); 04334 04335 return fill(eT(0)); 04336 } 04337 04338 04339 04340 template<typename eT> 04341 inline 04342 const Mat<eT>& 04343 Mat<eT>::zeros(const uword in_elem) 04344 { 04345 arma_extra_debug_sigprint(); 04346 04347 set_size(in_elem); 04348 04349 return fill(eT(0)); 04350 } 04351 04352 04353 04354 template<typename eT> 04355 inline 04356 const Mat<eT>& 04357 Mat<eT>::zeros(const uword in_rows, const uword in_cols) 04358 { 04359 arma_extra_debug_sigprint(); 04360 04361 set_size(in_rows, in_cols); 04362 04363 return fill(eT(0)); 04364 } 04365 04366 04367 04368 template<typename eT> 04369 inline 04370 const Mat<eT>& 04371 Mat<eT>::ones() 04372 { 04373 arma_extra_debug_sigprint(); 04374 04375 return fill(eT(1)); 04376 } 04377 04378 04379 04380 template<typename eT> 04381 inline 04382 const Mat<eT>& 04383 Mat<eT>::ones(const uword in_elem) 04384 { 04385 arma_extra_debug_sigprint(); 04386 04387 set_size(in_elem); 04388 04389 return fill(eT(1)); 04390 } 04391 04392 04393 04394 template<typename eT> 04395 inline 04396 const Mat<eT>& 04397 Mat<eT>::ones(const uword in_rows, const uword in_cols) 04398 { 04399 arma_extra_debug_sigprint(); 04400 04401 set_size(in_rows, in_cols); 04402 04403 return fill(eT(1)); 04404 } 04405 04406 04407 04408 template<typename eT> 04409 inline 04410 const Mat<eT>& 04411 Mat<eT>::randu() 04412 { 04413 arma_extra_debug_sigprint(); 04414 04415 const uword N = n_elem; 04416 eT* ptr = memptr(); 04417 04418 uword i,j; 04419 04420 for(i=0, j=1; j<N; i+=2, j+=2) 04421 { 04422 const eT tmp_i = eT(eop_aux_randu<eT>()); 04423 const eT tmp_j = eT(eop_aux_randu<eT>()); 04424 04425 ptr[i] = tmp_i; 04426 ptr[j] = tmp_j; 04427 } 04428 04429 if(i < N) 04430 { 04431 ptr[i] = eT(eop_aux_randu<eT>()); 04432 } 04433 04434 return *this; 04435 } 04436 04437 04438 04439 template<typename eT> 04440 inline 04441 const Mat<eT>& 04442 Mat<eT>::randu(const uword in_elem) 04443 { 04444 arma_extra_debug_sigprint(); 04445 04446 set_size(in_elem); 04447 04448 return (*this).randu(); 04449 } 04450 04451 04452 04453 template<typename eT> 04454 inline 04455 const Mat<eT>& 04456 Mat<eT>::randu(const uword in_rows, const uword in_cols) 04457 { 04458 arma_extra_debug_sigprint(); 04459 04460 set_size(in_rows, in_cols); 04461 04462 return (*this).randu(); 04463 } 04464 04465 04466 04467 template<typename eT> 04468 inline 04469 const Mat<eT>& 04470 Mat<eT>::randn() 04471 { 04472 arma_extra_debug_sigprint(); 04473 04474 const uword N = n_elem; 04475 eT* ptr = memptr(); 04476 04477 for(uword i=0; i<N; ++i) 04478 { 04479 ptr[i] = eT(eop_aux_randn<eT>()); 04480 } 04481 04482 return *this; 04483 } 04484 04485 04486 04487 template<typename eT> 04488 inline 04489 const Mat<eT>& 04490 Mat<eT>::randn(const uword in_elem) 04491 { 04492 arma_extra_debug_sigprint(); 04493 04494 set_size(in_elem); 04495 04496 return (*this).randn(); 04497 } 04498 04499 04500 04501 template<typename eT> 04502 inline 04503 const Mat<eT>& 04504 Mat<eT>::randn(const uword in_rows, const uword in_cols) 04505 { 04506 arma_extra_debug_sigprint(); 04507 04508 set_size(in_rows, in_cols); 04509 04510 return (*this).randn(); 04511 } 04512 04513 04514 04515 template<typename eT> 04516 inline 04517 const Mat<eT>& 04518 Mat<eT>::eye() 04519 { 04520 arma_extra_debug_sigprint(); 04521 04522 fill(eT(0)); 04523 04524 const uword N = (std::min)(n_rows, n_cols); 04525 04526 for(uword i=0; i<N; ++i) 04527 { 04528 at(i,i) = eT(1); 04529 } 04530 04531 return *this; 04532 } 04533 04534 04535 04536 template<typename eT> 04537 inline 04538 const Mat<eT>& 04539 Mat<eT>::eye(const uword in_rows, const uword in_cols) 04540 { 04541 arma_extra_debug_sigprint(); 04542 04543 set_size(in_rows, in_cols); 04544 04545 return (*this).eye(); 04546 } 04547 04548 04549 04550 template<typename eT> 04551 inline 04552 void 04553 Mat<eT>::reset() 04554 { 04555 arma_extra_debug_sigprint(); 04556 04557 switch(vec_state) 04558 { 04559 default: 04560 init_warm(0, 0); 04561 break; 04562 04563 case 1: 04564 init_warm(0, 1); 04565 break; 04566 04567 case 2: 04568 init_warm(1, 0); 04569 break; 04570 } 04571 } 04572 04573 04574 04575 template<typename eT> 04576 template<typename T1> 04577 inline 04578 void 04579 Mat<eT>::set_real(const Base<typename Mat<eT>::pod_type,T1>& X) 04580 { 04581 arma_extra_debug_sigprint(); 04582 04583 Mat_aux::set_real(*this, X); 04584 } 04585 04586 04587 04588 template<typename eT> 04589 template<typename T1> 04590 inline 04591 void 04592 Mat<eT>::set_imag(const Base<typename Mat<eT>::pod_type,T1>& X) 04593 { 04594 arma_extra_debug_sigprint(); 04595 04596 Mat_aux::set_imag(*this, X); 04597 } 04598 04599 04600 04601 template<typename eT> 04602 inline 04603 arma_warn_unused 04604 eT 04605 Mat<eT>::min() const 04606 { 04607 arma_extra_debug_sigprint(); 04608 04609 arma_debug_check( (n_elem == 0), "min(): object has no elements" ); 04610 04611 return op_min::direct_min(memptr(), n_elem); 04612 } 04613 04614 04615 04616 template<typename eT> 04617 inline 04618 arma_warn_unused 04619 eT 04620 Mat<eT>::max() const 04621 { 04622 arma_extra_debug_sigprint(); 04623 04624 arma_debug_check( (n_elem == 0), "max(): object has no elements" ); 04625 04626 return op_max::direct_max(memptr(), n_elem); 04627 } 04628 04629 04630 04631 template<typename eT> 04632 inline 04633 eT 04634 Mat<eT>::min(uword& index_of_min_val) const 04635 { 04636 arma_extra_debug_sigprint(); 04637 04638 arma_debug_check( (n_elem == 0), "min(): object has no elements" ); 04639 04640 return op_min::direct_min(memptr(), n_elem, index_of_min_val); 04641 } 04642 04643 04644 04645 template<typename eT> 04646 inline 04647 eT 04648 Mat<eT>::max(uword& index_of_max_val) const 04649 { 04650 arma_extra_debug_sigprint(); 04651 04652 arma_debug_check( (n_elem == 0), "max(): object has no elements" ); 04653 04654 return op_max::direct_max(memptr(), n_elem, index_of_max_val); 04655 } 04656 04657 04658 04659 template<typename eT> 04660 inline 04661 eT 04662 Mat<eT>::min(uword& row_of_min_val, uword& col_of_min_val) const 04663 { 04664 arma_extra_debug_sigprint(); 04665 04666 arma_debug_check( (n_elem == 0), "min(): object has no elements" ); 04667 04668 uword i; 04669 04670 eT val = op_min::direct_min(memptr(), n_elem, i); 04671 04672 row_of_min_val = i % n_rows; 04673 col_of_min_val = i / n_rows; 04674 04675 return val; 04676 } 04677 04678 04679 04680 template<typename eT> 04681 inline 04682 eT 04683 Mat<eT>::max(uword& row_of_max_val, uword& col_of_max_val) const 04684 { 04685 arma_extra_debug_sigprint(); 04686 04687 arma_debug_check( (n_elem == 0), "max(): object has no elements" ); 04688 04689 uword i; 04690 04691 eT val = op_max::direct_max(memptr(), n_elem, i); 04692 04693 row_of_max_val = i % n_rows; 04694 col_of_max_val = i / n_rows; 04695 04696 return val; 04697 } 04698 04699 04700 04702 template<typename eT> 04703 inline 04704 bool 04705 Mat<eT>::save(const std::string name, const file_type type, const bool print_status) const 04706 { 04707 arma_extra_debug_sigprint(); 04708 04709 bool save_okay; 04710 04711 switch(type) 04712 { 04713 case raw_ascii: 04714 save_okay = diskio::save_raw_ascii(*this, name); 04715 break; 04716 04717 case arma_ascii: 04718 save_okay = diskio::save_arma_ascii(*this, name); 04719 break; 04720 04721 case csv_ascii: 04722 save_okay = diskio::save_csv_ascii(*this, name); 04723 break; 04724 04725 case raw_binary: 04726 save_okay = diskio::save_raw_binary(*this, name); 04727 break; 04728 04729 case arma_binary: 04730 save_okay = diskio::save_arma_binary(*this, name); 04731 break; 04732 04733 case pgm_binary: 04734 save_okay = diskio::save_pgm_binary(*this, name); 04735 break; 04736 04737 default: 04738 arma_warn(print_status, "Mat::save(): unsupported file type"); 04739 save_okay = false; 04740 } 04741 04742 arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't write to ", name); 04743 04744 return save_okay; 04745 } 04746 04747 04748 04750 template<typename eT> 04751 inline 04752 bool 04753 Mat<eT>::save(std::ostream& os, const file_type type, const bool print_status) const 04754 { 04755 arma_extra_debug_sigprint(); 04756 04757 bool save_okay; 04758 04759 switch(type) 04760 { 04761 case raw_ascii: 04762 save_okay = diskio::save_raw_ascii(*this, os); 04763 break; 04764 04765 case arma_ascii: 04766 save_okay = diskio::save_arma_ascii(*this, os); 04767 break; 04768 04769 case csv_ascii: 04770 save_okay = diskio::save_csv_ascii(*this, os); 04771 break; 04772 04773 case raw_binary: 04774 save_okay = diskio::save_raw_binary(*this, os); 04775 break; 04776 04777 case arma_binary: 04778 save_okay = diskio::save_arma_binary(*this, os); 04779 break; 04780 04781 case pgm_binary: 04782 save_okay = diskio::save_pgm_binary(*this, os); 04783 break; 04784 04785 default: 04786 arma_warn(print_status, "Mat::save(): unsupported file type"); 04787 save_okay = false; 04788 } 04789 04790 arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't write to the given stream"); 04791 04792 return save_okay; 04793 } 04794 04795 04796 04798 template<typename eT> 04799 inline 04800 bool 04801 Mat<eT>::load(const std::string name, const file_type type, const bool print_status) 04802 { 04803 arma_extra_debug_sigprint(); 04804 04805 bool load_okay; 04806 std::string err_msg; 04807 04808 switch(type) 04809 { 04810 case auto_detect: 04811 load_okay = diskio::load_auto_detect(*this, name, err_msg); 04812 break; 04813 04814 case raw_ascii: 04815 load_okay = diskio::load_raw_ascii(*this, name, err_msg); 04816 break; 04817 04818 case arma_ascii: 04819 load_okay = diskio::load_arma_ascii(*this, name, err_msg); 04820 break; 04821 04822 case csv_ascii: 04823 load_okay = diskio::load_csv_ascii(*this, name, err_msg); 04824 break; 04825 04826 case raw_binary: 04827 load_okay = diskio::load_raw_binary(*this, name, err_msg); 04828 break; 04829 04830 case arma_binary: 04831 load_okay = diskio::load_arma_binary(*this, name, err_msg); 04832 break; 04833 04834 case pgm_binary: 04835 load_okay = diskio::load_pgm_binary(*this, name, err_msg); 04836 break; 04837 04838 default: 04839 arma_warn(print_status, "Mat::load(): unsupported file type"); 04840 load_okay = false; 04841 } 04842 04843 if( (print_status == true) && (load_okay == false) ) 04844 { 04845 if(err_msg.length() > 0) 04846 { 04847 arma_warn(true, "Mat::load(): ", err_msg, name); 04848 } 04849 else 04850 { 04851 arma_warn(true, "Mat::load(): couldn't read ", name); 04852 } 04853 } 04854 04855 if(load_okay == false) 04856 { 04857 (*this).reset(); 04858 } 04859 04860 return load_okay; 04861 } 04862 04863 04864 04866 template<typename eT> 04867 inline 04868 bool 04869 Mat<eT>::load(std::istream& is, const file_type type, const bool print_status) 04870 { 04871 arma_extra_debug_sigprint(); 04872 04873 bool load_okay; 04874 std::string err_msg; 04875 04876 switch(type) 04877 { 04878 case auto_detect: 04879 load_okay = diskio::load_auto_detect(*this, is, err_msg); 04880 break; 04881 04882 case raw_ascii: 04883 load_okay = diskio::load_raw_ascii(*this, is, err_msg); 04884 break; 04885 04886 case arma_ascii: 04887 load_okay = diskio::load_arma_ascii(*this, is, err_msg); 04888 break; 04889 04890 case csv_ascii: 04891 load_okay = diskio::load_csv_ascii(*this, is, err_msg); 04892 break; 04893 04894 case raw_binary: 04895 load_okay = diskio::load_raw_binary(*this, is, err_msg); 04896 break; 04897 04898 case arma_binary: 04899 load_okay = diskio::load_arma_binary(*this, is, err_msg); 04900 break; 04901 04902 case pgm_binary: 04903 load_okay = diskio::load_pgm_binary(*this, is, err_msg); 04904 break; 04905 04906 default: 04907 arma_warn(print_status, "Mat::load(): unsupported file type"); 04908 load_okay = false; 04909 } 04910 04911 04912 if( (print_status == true) && (load_okay == false) ) 04913 { 04914 if(err_msg.length() > 0) 04915 { 04916 arma_warn(true, "Mat::load(): ", err_msg, "the given stream"); 04917 } 04918 else 04919 { 04920 arma_warn(true, "Mat::load(): couldn't load from the given stream"); 04921 } 04922 } 04923 04924 if(load_okay == false) 04925 { 04926 (*this).reset(); 04927 } 04928 04929 return load_okay; 04930 } 04931 04932 04933 04935 template<typename eT> 04936 inline 04937 bool 04938 Mat<eT>::quiet_save(const std::string name, const file_type type) const 04939 { 04940 arma_extra_debug_sigprint(); 04941 04942 return (*this).save(name, type, false); 04943 } 04944 04945 04946 04948 template<typename eT> 04949 inline 04950 bool 04951 Mat<eT>::quiet_save(std::ostream& os, const file_type type) const 04952 { 04953 arma_extra_debug_sigprint(); 04954 04955 return (*this).save(os, type, false); 04956 } 04957 04958 04959 04961 template<typename eT> 04962 inline 04963 bool 04964 Mat<eT>::quiet_load(const std::string name, const file_type type) 04965 { 04966 arma_extra_debug_sigprint(); 04967 04968 return (*this).load(name, type, false); 04969 } 04970 04971 04972 04974 template<typename eT> 04975 inline 04976 bool 04977 Mat<eT>::quiet_load(std::istream& is, const file_type type) 04978 { 04979 arma_extra_debug_sigprint(); 04980 04981 return (*this).load(is, type, false); 04982 } 04983 04984 04985 04986 template<typename eT> 04987 inline 04988 Mat<eT>::row_iterator::row_iterator(Mat<eT>& in_M, const uword in_row) 04989 : M (in_M ) 04990 , row(in_row) 04991 , col(0 ) 04992 { 04993 arma_extra_debug_sigprint(); 04994 } 04995 04996 04997 04998 template<typename eT> 04999 inline 05000 eT& 05001 Mat<eT>::row_iterator::operator*() 05002 { 05003 return M.at(row,col); 05004 } 05005 05006 05007 05008 template<typename eT> 05009 inline 05010 typename Mat<eT>::row_iterator& 05011 Mat<eT>::row_iterator::operator++() 05012 { 05013 ++col; 05014 05015 if(col >= M.n_cols) 05016 { 05017 col = 0; 05018 ++row; 05019 } 05020 05021 return *this; 05022 } 05023 05024 05025 05026 template<typename eT> 05027 inline 05028 void 05029 Mat<eT>::row_iterator::operator++(int) 05030 { 05031 operator++(); 05032 } 05033 05034 05035 05036 template<typename eT> 05037 inline 05038 typename Mat<eT>::row_iterator& 05039 Mat<eT>::row_iterator::operator--() 05040 { 05041 if(col > 0) 05042 { 05043 --col; 05044 } 05045 else 05046 { 05047 if(row > 0) 05048 { 05049 col = M.n_cols - 1; 05050 --row; 05051 } 05052 } 05053 05054 return *this; 05055 } 05056 05057 05058 05059 template<typename eT> 05060 inline 05061 void 05062 Mat<eT>::row_iterator::operator--(int) 05063 { 05064 operator--(); 05065 } 05066 05067 05068 05069 template<typename eT> 05070 inline 05071 bool 05072 Mat<eT>::row_iterator::operator!=(const typename Mat<eT>::row_iterator& X) const 05073 { 05074 return ( (row != X.row) || (col != X.col) ) ? true : false; 05075 } 05076 05077 05078 05079 template<typename eT> 05080 inline 05081 bool 05082 Mat<eT>::row_iterator::operator==(const typename Mat<eT>::row_iterator& X) const 05083 { 05084 return ( (row == X.row) && (col == X.col) ) ? true : false; 05085 } 05086 05087 05088 05089 template<typename eT> 05090 inline 05091 Mat<eT>::const_row_iterator::const_row_iterator(const Mat<eT>& in_M, const uword in_row) 05092 : M (in_M ) 05093 , row(in_row) 05094 , col(0 ) 05095 { 05096 arma_extra_debug_sigprint(); 05097 } 05098 05099 05100 05101 template<typename eT> 05102 inline 05103 Mat<eT>::const_row_iterator::const_row_iterator(const typename Mat<eT>::row_iterator& X) 05104 : M (X.M) 05105 , row(X.row) 05106 , col(X.col) 05107 { 05108 arma_extra_debug_sigprint(); 05109 } 05110 05111 05112 05113 template<typename eT> 05114 inline 05115 eT 05116 Mat<eT>::const_row_iterator::operator*() const 05117 { 05118 return M.at(row,col); 05119 } 05120 05121 05122 05123 template<typename eT> 05124 inline 05125 typename Mat<eT>::const_row_iterator& 05126 Mat<eT>::const_row_iterator::operator++() 05127 { 05128 ++col; 05129 05130 if(col >= M.n_cols) 05131 { 05132 col = 0; 05133 ++row; 05134 } 05135 05136 return *this; 05137 } 05138 05139 05140 05141 template<typename eT> 05142 inline 05143 void 05144 Mat<eT>::const_row_iterator::operator++(int) 05145 { 05146 operator++(); 05147 } 05148 05149 05150 05151 template<typename eT> 05152 inline 05153 typename Mat<eT>::const_row_iterator& 05154 Mat<eT>::const_row_iterator::operator--() 05155 { 05156 if(col > 0) 05157 { 05158 --col; 05159 } 05160 else 05161 { 05162 if(row > 0) 05163 { 05164 col = M.n_cols - 1; 05165 --row; 05166 } 05167 } 05168 05169 return *this; 05170 } 05171 05172 05173 05174 template<typename eT> 05175 inline 05176 void 05177 Mat<eT>::const_row_iterator::operator--(int) 05178 { 05179 operator--(); 05180 } 05181 05182 05183 05184 template<typename eT> 05185 inline 05186 bool 05187 Mat<eT>::const_row_iterator::operator!=(const typename Mat<eT>::const_row_iterator& X) const 05188 { 05189 return ( (row != X.row) || (col != X.col) ) ? true : false; 05190 } 05191 05192 05193 05194 template<typename eT> 05195 inline 05196 bool 05197 Mat<eT>::const_row_iterator::operator==(const typename Mat<eT>::const_row_iterator& X) const 05198 { 05199 return ( (row == X.row) && (col == X.col) ) ? true : false; 05200 } 05201 05202 05203 05204 template<typename eT> 05205 inline 05206 typename Mat<eT>::iterator 05207 Mat<eT>::begin() 05208 { 05209 arma_extra_debug_sigprint(); 05210 05211 return memptr(); 05212 } 05213 05214 05215 05216 template<typename eT> 05217 inline 05218 typename Mat<eT>::const_iterator 05219 Mat<eT>::begin() const 05220 { 05221 arma_extra_debug_sigprint(); 05222 05223 return memptr(); 05224 } 05225 05226 05227 05228 template<typename eT> 05229 inline 05230 typename Mat<eT>::iterator 05231 Mat<eT>::end() 05232 { 05233 arma_extra_debug_sigprint(); 05234 05235 return memptr() + n_elem; 05236 } 05237 05238 05239 05240 template<typename eT> 05241 inline 05242 typename Mat<eT>::const_iterator 05243 Mat<eT>::end() const 05244 { 05245 arma_extra_debug_sigprint(); 05246 05247 return memptr() + n_elem; 05248 } 05249 05250 05251 05252 template<typename eT> 05253 inline 05254 typename Mat<eT>::col_iterator 05255 Mat<eT>::begin_col(const uword col_num) 05256 { 05257 arma_extra_debug_sigprint(); 05258 05259 arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds"); 05260 05261 return colptr(col_num); 05262 } 05263 05264 05265 05266 template<typename eT> 05267 inline 05268 typename Mat<eT>::const_col_iterator 05269 Mat<eT>::begin_col(const uword col_num) const 05270 { 05271 arma_extra_debug_sigprint(); 05272 05273 arma_debug_check( (col_num >= n_cols), "begin_col(): index out of bounds"); 05274 05275 return colptr(col_num); 05276 } 05277 05278 05279 05280 template<typename eT> 05281 inline 05282 typename Mat<eT>::col_iterator 05283 Mat<eT>::end_col(const uword col_num) 05284 { 05285 arma_extra_debug_sigprint(); 05286 05287 arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds"); 05288 05289 return colptr(col_num) + n_rows; 05290 } 05291 05292 05293 05294 template<typename eT> 05295 inline 05296 typename Mat<eT>::const_col_iterator 05297 Mat<eT>::end_col(const uword col_num) const 05298 { 05299 arma_extra_debug_sigprint(); 05300 05301 arma_debug_check( (col_num >= n_cols), "end_col(): index out of bounds"); 05302 05303 return colptr(col_num) + n_rows; 05304 } 05305 05306 05307 05308 template<typename eT> 05309 inline 05310 typename Mat<eT>::row_iterator 05311 Mat<eT>::begin_row(const uword row_num) 05312 { 05313 arma_extra_debug_sigprint(); 05314 05315 arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" ); 05316 05317 return typename Mat<eT>::row_iterator(*this, row_num); 05318 } 05319 05320 05321 05322 template<typename eT> 05323 inline 05324 typename Mat<eT>::const_row_iterator 05325 Mat<eT>::begin_row(const uword row_num) const 05326 { 05327 arma_extra_debug_sigprint(); 05328 05329 arma_debug_check( (row_num >= n_rows), "Mat::begin_row(): index out of bounds" ); 05330 05331 return typename Mat<eT>::const_row_iterator(*this, row_num); 05332 } 05333 05334 05335 05336 template<typename eT> 05337 inline 05338 typename Mat<eT>::row_iterator 05339 Mat<eT>::end_row(const uword row_num) 05340 { 05341 arma_extra_debug_sigprint(); 05342 05343 arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" ); 05344 05345 return typename Mat<eT>::row_iterator(*this, row_num + 1); 05346 } 05347 05348 05349 05350 template<typename eT> 05351 inline 05352 typename Mat<eT>::const_row_iterator 05353 Mat<eT>::end_row(const uword row_num) const 05354 { 05355 arma_extra_debug_sigprint(); 05356 05357 arma_debug_check( (row_num >= n_rows), "Mat::end_row(): index out of bounds" ); 05358 05359 return typename Mat<eT>::const_row_iterator(*this, row_num + 1); 05360 } 05361 05362 05363 05365 template<typename eT> 05366 inline 05367 void 05368 Mat<eT>::clear() 05369 { 05370 reset(); 05371 } 05372 05373 05374 05376 template<typename eT> 05377 inline 05378 bool 05379 Mat<eT>::empty() const 05380 { 05381 return (n_elem == 0); 05382 } 05383 05384 05385 05387 template<typename eT> 05388 inline 05389 uword 05390 Mat<eT>::size() const 05391 { 05392 return n_elem; 05393 } 05394 05395 05396 05397 template<typename eT> 05398 template<uword fixed_n_rows, uword fixed_n_cols> 05399 arma_inline 05400 void 05401 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::mem_setup() 05402 { 05403 arma_extra_debug_sigprint(); 05404 05405 access::rw(Mat<eT>::n_rows) = fixed_n_rows; 05406 access::rw(Mat<eT>::n_cols) = fixed_n_cols; 05407 access::rw(Mat<eT>::n_elem) = fixed_n_elem; 05408 access::rw(Mat<eT>::vec_state) = 0; 05409 access::rw(Mat<eT>::mem_state) = 3; 05410 access::rw(Mat<eT>::mem) = (use_extra) ? mem_local_extra : mem_local; 05411 } 05412 05413 05414 05415 template<typename eT> 05416 template<uword fixed_n_rows, uword fixed_n_cols> 05417 arma_inline 05418 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed() 05419 { 05420 arma_extra_debug_sigprint_this(this); 05421 05422 mem_setup(); 05423 } 05424 05425 05426 05427 template<typename eT> 05428 template<uword fixed_n_rows, uword fixed_n_cols> 05429 arma_inline 05430 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const fixed<fixed_n_rows, fixed_n_cols>& X) 05431 { 05432 arma_extra_debug_sigprint_this(this); 05433 05434 mem_setup(); 05435 05436 eT* dest = (use_extra) ? mem_local_extra : mem_local; 05437 05438 arrayops::copy( dest, X.mem, fixed_n_elem ); 05439 } 05440 05441 05442 05443 template<typename eT> 05444 template<uword fixed_n_rows, uword fixed_n_cols> 05445 template<typename T1> 05446 inline 05447 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const Base<eT,T1>& A) 05448 { 05449 arma_extra_debug_sigprint_this(this); 05450 05451 mem_setup(); 05452 05453 Mat<eT>::operator=(A.get_ref()); 05454 } 05455 05456 05457 05458 template<typename eT> 05459 template<uword fixed_n_rows, uword fixed_n_cols> 05460 template<typename T1, typename T2> 05461 inline 05462 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const Base<pod_type,T1>& A, const Base<pod_type,T2>& B) 05463 { 05464 arma_extra_debug_sigprint_this(this); 05465 05466 mem_setup(); 05467 05468 Mat<eT>::init(A,B); 05469 } 05470 05471 05472 05473 template<typename eT> 05474 template<uword fixed_n_rows, uword fixed_n_cols> 05475 inline 05476 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(eT* aux_mem, const bool copy_aux_mem) 05477 { 05478 arma_extra_debug_sigprint_this(this); 05479 05480 access::rw(Mat<eT>::n_rows) = fixed_n_rows; 05481 access::rw(Mat<eT>::n_cols) = fixed_n_cols; 05482 access::rw(Mat<eT>::n_elem) = fixed_n_elem; 05483 access::rw(Mat<eT>::vec_state) = 0; 05484 access::rw(Mat<eT>::mem_state) = 3; 05485 05486 if(copy_aux_mem == true) 05487 { 05488 eT* dest = (use_extra) ? mem_local_extra : mem_local; 05489 05490 access::rw(Mat<eT>::mem) = dest; 05491 05492 arrayops::copy( dest, aux_mem, fixed_n_elem ); 05493 } 05494 else 05495 { 05496 access::rw(Mat<eT>::mem) = aux_mem; 05497 } 05498 } 05499 05500 05501 05502 template<typename eT> 05503 template<uword fixed_n_rows, uword fixed_n_cols> 05504 inline 05505 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const eT* aux_mem) 05506 { 05507 arma_extra_debug_sigprint_this(this); 05508 05509 mem_setup(); 05510 05511 arrayops::copy( const_cast<eT*>(Mat<eT>::mem), aux_mem, fixed_n_elem ); 05512 } 05513 05514 05515 05516 template<typename eT> 05517 template<uword fixed_n_rows, uword fixed_n_cols> 05518 inline 05519 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const char* text) 05520 { 05521 arma_extra_debug_sigprint_this(this); 05522 05523 mem_setup(); 05524 05525 Mat<eT>::operator=(text); 05526 } 05527 05528 05529 05530 template<typename eT> 05531 template<uword fixed_n_rows, uword fixed_n_cols> 05532 inline 05533 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const std::string& text) 05534 { 05535 arma_extra_debug_sigprint_this(this); 05536 05537 mem_setup(); 05538 05539 Mat<eT>::operator=(text); 05540 } 05541 05542 05543 05544 template<typename eT> 05545 template<uword fixed_n_rows, uword fixed_n_cols> 05546 template<typename T1> 05547 inline 05548 const Mat<eT>& 05549 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const Base<eT,T1>& A) 05550 { 05551 Mat<eT>::operator=(A.get_ref()); 05552 05553 return *this; 05554 } 05555 05556 05557 05558 template<typename eT> 05559 template<uword fixed_n_rows, uword fixed_n_cols> 05560 inline 05561 const Mat<eT>& 05562 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const eT val) 05563 { 05564 arma_extra_debug_sigprint(); 05565 05566 Mat<eT>::operator=(val); 05567 05568 return *this; 05569 } 05570 05571 05572 05573 template<typename eT> 05574 template<uword fixed_n_rows, uword fixed_n_cols> 05575 inline 05576 const Mat<eT>& 05577 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const char* text) 05578 { 05579 arma_extra_debug_sigprint(); 05580 05581 Mat<eT>::operator=(text); 05582 05583 return *this; 05584 } 05585 05586 05587 05588 template<typename eT> 05589 template<uword fixed_n_rows, uword fixed_n_cols> 05590 inline 05591 const Mat<eT>& 05592 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const std::string& text) 05593 { 05594 arma_extra_debug_sigprint(); 05595 05596 Mat<eT>::operator=(text); 05597 05598 return *this; 05599 } 05600 05601 05602 05603 template<typename eT> 05604 template<uword fixed_n_rows, uword fixed_n_cols> 05605 inline 05606 subview_row<eT> 05607 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const uword row_num, const span& col_span) 05608 { 05609 arma_extra_debug_sigprint(); 05610 05611 return Mat<eT>::operator()(row_num, col_span); 05612 } 05613 05614 05615 05616 template<typename eT> 05617 template<uword fixed_n_rows, uword fixed_n_cols> 05618 inline 05619 const subview_row<eT> 05620 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const uword row_num, const span& col_span) const 05621 { 05622 arma_extra_debug_sigprint(); 05623 05624 return Mat<eT>::operator()(row_num, col_span); 05625 } 05626 05627 05628 05629 template<typename eT> 05630 template<uword fixed_n_rows, uword fixed_n_cols> 05631 inline 05632 subview_col<eT> 05633 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span, const uword col_num) 05634 { 05635 arma_extra_debug_sigprint(); 05636 05637 return Mat<eT>::operator()(row_span, col_num); 05638 } 05639 05640 05641 05642 template<typename eT> 05643 template<uword fixed_n_rows, uword fixed_n_cols> 05644 inline 05645 const subview_col<eT> 05646 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span, const uword col_num) const 05647 { 05648 arma_extra_debug_sigprint(); 05649 05650 return Mat<eT>::operator()(row_span, col_num); 05651 } 05652 05653 05654 05655 template<typename eT> 05656 template<uword fixed_n_rows, uword fixed_n_cols> 05657 inline 05658 subview<eT> 05659 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span, const span& col_span) 05660 { 05661 arma_extra_debug_sigprint(); 05662 05663 return Mat<eT>::operator()(row_span, col_span); 05664 } 05665 05666 05667 05668 template<typename eT> 05669 template<uword fixed_n_rows, uword fixed_n_cols> 05670 inline 05671 const subview<eT> 05672 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span, const span& col_span) const 05673 { 05674 arma_extra_debug_sigprint(); 05675 05676 return Mat<eT>::operator()(row_span, col_span); 05677 } 05678 05679 05680 05681 template<typename eT> 05682 template<uword fixed_n_rows, uword fixed_n_cols> 05683 arma_inline 05684 arma_warn_unused 05685 eT& 05686 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator[] (const uword i) 05687 { 05688 return access::rw( Mat<eT>::mem[i] ); 05689 } 05690 05691 05692 05693 template<typename eT> 05694 template<uword fixed_n_rows, uword fixed_n_cols> 05695 arma_inline 05696 arma_warn_unused 05697 eT 05698 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator[] (const uword i) const 05699 { 05700 return ( Mat<eT>::mem[i] ); 05701 } 05702 05703 05704 05705 template<typename eT> 05706 template<uword fixed_n_rows, uword fixed_n_cols> 05707 arma_inline 05708 arma_warn_unused 05709 eT& 05710 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword i) 05711 { 05712 return access::rw( Mat<eT>::mem[i] ); 05713 } 05714 05715 05716 05717 template<typename eT> 05718 template<uword fixed_n_rows, uword fixed_n_cols> 05719 arma_inline 05720 arma_warn_unused 05721 eT 05722 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword i) const 05723 { 05724 return ( Mat<eT>::mem[i] ); 05725 } 05726 05727 05728 05729 template<typename eT> 05730 template<uword fixed_n_rows, uword fixed_n_cols> 05731 arma_inline 05732 arma_warn_unused 05733 eT& 05734 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword i) 05735 { 05736 arma_debug_check( (i >= fixed_n_elem), "Mat::fixed::operator(): out of bounds"); 05737 05738 return access::rw( Mat<eT>::mem[i] ); 05739 } 05740 05741 05742 05743 template<typename eT> 05744 template<uword fixed_n_rows, uword fixed_n_cols> 05745 arma_inline 05746 arma_warn_unused 05747 eT 05748 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword i) const 05749 { 05750 arma_debug_check( (i >= fixed_n_elem), "Mat::fixed::operator(): out of bounds"); 05751 05752 return ( Mat<eT>::mem[i] ); 05753 } 05754 05755 05756 05757 template<typename eT> 05758 template<uword fixed_n_rows, uword fixed_n_cols> 05759 arma_inline 05760 arma_warn_unused 05761 eT& 05762 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword in_row, const uword in_col) 05763 { 05764 const uword i = in_row + in_col*fixed_n_rows; 05765 05766 return access::rw( Mat<eT>::mem[i] ); 05767 } 05768 05769 05770 05771 template<typename eT> 05772 template<uword fixed_n_rows, uword fixed_n_cols> 05773 arma_inline 05774 arma_warn_unused 05775 eT 05776 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword in_row, const uword in_col) const 05777 { 05778 const uword i = in_row + in_col*fixed_n_rows; 05779 05780 return ( Mat<eT>::mem[i] ); 05781 } 05782 05783 05784 05785 template<typename eT> 05786 template<uword fixed_n_rows, uword fixed_n_cols> 05787 arma_inline 05788 arma_warn_unused 05789 eT& 05790 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword in_row, const uword in_col) 05791 { 05792 arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::fixed::operator(): out of bounds"); 05793 05794 const uword i = in_row + in_col*fixed_n_rows; 05795 05796 return access::rw( Mat<eT>::mem[i] ); 05797 } 05798 05799 05800 05801 template<typename eT> 05802 template<uword fixed_n_rows, uword fixed_n_cols> 05803 arma_inline 05804 arma_warn_unused 05805 eT 05806 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword in_row, const uword in_col) const 05807 { 05808 arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)), "Mat::fixed::operator(): out of bounds"); 05809 05810 const uword i = in_row + in_col*fixed_n_rows; 05811 05812 return ( Mat<eT>::mem[i] ); 05813 } 05814 05815 05816 05817 template<typename eT> 05818 template<uword fixed_n_rows, uword fixed_n_cols> 05819 arma_hot 05820 inline 05821 const Mat<eT>& 05822 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fill(const eT val) 05823 { 05824 arma_extra_debug_sigprint(); 05825 05826 arrayops::inplace_set( const_cast<eT*>(Mat<eT>::mem), val, fixed_n_elem ); 05827 05828 return *this; 05829 } 05830 05831 05832 05833 template<typename eT> 05834 template<uword fixed_n_rows, uword fixed_n_cols> 05835 arma_hot 05836 inline 05837 const Mat<eT>& 05838 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::zeros() 05839 { 05840 arma_extra_debug_sigprint(); 05841 05842 arrayops::inplace_set( const_cast<eT*>(Mat<eT>::mem), eT(0), fixed_n_elem ); 05843 05844 return *this; 05845 } 05846 05847 05848 05849 template<typename eT> 05850 template<uword fixed_n_rows, uword fixed_n_cols> 05851 arma_hot 05852 inline 05853 const Mat<eT>& 05854 Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::ones() 05855 { 05856 arma_extra_debug_sigprint(); 05857 05858 arrayops::inplace_set( const_cast<eT*>(Mat<eT>::mem), eT(1), fixed_n_elem ); 05859 05860 return *this; 05861 } 05862 05863 05864 05866 template<typename eT> 05867 arma_inline 05868 void 05869 Mat_aux::prefix_pp(Mat<eT>& x) 05870 { 05871 eT* memptr = x.memptr(); 05872 const uword n_elem = x.n_elem; 05873 05874 uword i,j; 05875 05876 for(i=0, j=1; j<n_elem; i+=2, j+=2) 05877 { 05878 ++(memptr[i]); 05879 ++(memptr[j]); 05880 } 05881 05882 if(i < n_elem) 05883 { 05884 ++(memptr[i]); 05885 } 05886 } 05887 05888 05889 05891 template<typename T> 05892 arma_inline 05893 void 05894 Mat_aux::prefix_pp(Mat< std::complex<T> >& x) 05895 { 05896 x += T(1); 05897 } 05898 05899 05900 05902 template<typename eT> 05903 arma_inline 05904 void 05905 Mat_aux::postfix_pp(Mat<eT>& x) 05906 { 05907 eT* memptr = x.memptr(); 05908 const uword n_elem = x.n_elem; 05909 05910 uword i,j; 05911 05912 for(i=0, j=1; j<n_elem; i+=2, j+=2) 05913 { 05914 (memptr[i])++; 05915 (memptr[j])++; 05916 } 05917 05918 if(i < n_elem) 05919 { 05920 (memptr[i])++; 05921 } 05922 } 05923 05924 05925 05927 template<typename T> 05928 arma_inline 05929 void 05930 Mat_aux::postfix_pp(Mat< std::complex<T> >& x) 05931 { 05932 x += T(1); 05933 } 05934 05935 05936 05938 template<typename eT> 05939 arma_inline 05940 void 05941 Mat_aux::prefix_mm(Mat<eT>& x) 05942 { 05943 eT* memptr = x.memptr(); 05944 const uword n_elem = x.n_elem; 05945 05946 uword i,j; 05947 05948 for(i=0, j=1; j<n_elem; i+=2, j+=2) 05949 { 05950 --(memptr[i]); 05951 --(memptr[j]); 05952 } 05953 05954 if(i < n_elem) 05955 { 05956 --(memptr[i]); 05957 } 05958 } 05959 05960 05961 05963 template<typename T> 05964 arma_inline 05965 void 05966 Mat_aux::prefix_mm(Mat< std::complex<T> >& x) 05967 { 05968 x -= T(1); 05969 } 05970 05971 05972 05974 template<typename eT> 05975 arma_inline 05976 void 05977 Mat_aux::postfix_mm(Mat<eT>& x) 05978 { 05979 eT* memptr = x.memptr(); 05980 const uword n_elem = x.n_elem; 05981 05982 uword i,j; 05983 05984 for(i=0, j=1; j<n_elem; i+=2, j+=2) 05985 { 05986 (memptr[i])--; 05987 (memptr[j])--; 05988 } 05989 05990 if(i < n_elem) 05991 { 05992 (memptr[i])--; 05993 } 05994 } 05995 05996 05997 05999 template<typename T> 06000 arma_inline 06001 void 06002 Mat_aux::postfix_mm(Mat< std::complex<T> >& x) 06003 { 06004 x -= T(1); 06005 } 06006 06007 06008 06009 template<typename eT, typename T1> 06010 inline 06011 void 06012 Mat_aux::set_real(Mat<eT>& out, const Base<eT,T1>& X) 06013 { 06014 arma_extra_debug_sigprint(); 06015 06016 const unwrap<T1> tmp(X.get_ref()); 06017 const Mat<eT>& A = tmp.M; 06018 06019 arma_debug_assert_same_size( out, A, "Mat::set_real()" ); 06020 06021 out = A; 06022 } 06023 06024 06025 06026 template<typename eT, typename T1> 06027 inline 06028 void 06029 Mat_aux::set_imag(Mat<eT>& out, const Base<eT,T1>& X) 06030 { 06031 arma_extra_debug_sigprint(); 06032 } 06033 06034 06035 06036 template<typename T, typename T1> 06037 inline 06038 void 06039 Mat_aux::set_real(Mat< std::complex<T> >& out, const Base<T,T1>& X) 06040 { 06041 arma_extra_debug_sigprint(); 06042 06043 typedef typename std::complex<T> eT; 06044 typedef typename Proxy<T1>::ea_type ea_type; 06045 06046 const Proxy<T1> A(X.get_ref()); 06047 06048 arma_debug_assert_same_size( out, A, "Mat::set_real()" ); 06049 06050 const uword n_elem = out.n_elem; 06051 eT* out_mem = out.memptr(); 06052 ea_type PA = A.get_ea(); 06053 06054 for(uword i=0; i<n_elem; ++i) 06055 { 06056 //out_mem[i].real() = PA[i]; 06057 out_mem[i] = std::complex<T>( PA[i], out_mem[i].imag() ); 06058 } 06059 } 06060 06061 06062 06063 template<typename T, typename T1> 06064 inline 06065 void 06066 Mat_aux::set_imag(Mat< std::complex<T> >& out, const Base<T,T1>& X) 06067 { 06068 arma_extra_debug_sigprint(); 06069 06070 typedef typename std::complex<T> eT; 06071 typedef typename Proxy<T1>::ea_type ea_type; 06072 06073 const Proxy<T1> A(X.get_ref()); 06074 06075 arma_debug_assert_same_size( out, A, "Mat::set_imag()" ); 06076 06077 const uword n_elem = out.n_elem; 06078 eT* out_mem = out.memptr(); 06079 ea_type PA = A.get_ea(); 06080 06081 for(uword i=0; i<n_elem; ++i) 06082 { 06083 //out_mem[i].imag() = PA[i]; 06084 out_mem[i] = std::complex<T>( out_mem[i].real(), PA[i] ); 06085 } 06086 } 06087 06088 06089 06090 #ifdef ARMA_EXTRA_MAT_MEAT 06091 #include ARMA_INCFILE_WRAP(ARMA_EXTRA_MAT_MEAT) 06092 #endif 06093 06094 06095