$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 subview_cube<eT>::~subview_cube() 00021 { 00022 arma_extra_debug_sigprint(); 00023 } 00024 00025 00026 00027 template<typename eT> 00028 arma_inline 00029 subview_cube<eT>::subview_cube 00030 ( 00031 const Cube<eT>& in_m, 00032 const uword in_row1, 00033 const uword in_col1, 00034 const uword in_slice1, 00035 const uword in_n_rows, 00036 const uword in_n_cols, 00037 const uword in_n_slices 00038 ) 00039 : m (in_m) 00040 , m_ptr (0) 00041 , aux_row1 (in_row1) 00042 , aux_col1 (in_col1) 00043 , aux_slice1 (in_slice1) 00044 , n_rows (in_n_rows) 00045 , n_cols (in_n_cols) 00046 , n_elem_slice(in_n_rows * in_n_cols) 00047 , n_slices (in_n_slices) 00048 , n_elem (n_elem_slice * in_n_slices) 00049 { 00050 arma_extra_debug_sigprint(); 00051 } 00052 00053 00054 00055 template<typename eT> 00056 arma_inline 00057 subview_cube<eT>::subview_cube 00058 ( 00059 Cube<eT>& in_m, 00060 const uword in_row1, 00061 const uword in_col1, 00062 const uword in_slice1, 00063 const uword in_n_rows, 00064 const uword in_n_cols, 00065 const uword in_n_slices 00066 ) 00067 : m (in_m) 00068 , m_ptr (&in_m) 00069 , aux_row1 (in_row1) 00070 , aux_col1 (in_col1) 00071 , aux_slice1 (in_slice1) 00072 , n_rows (in_n_rows) 00073 , n_cols (in_n_cols) 00074 , n_elem_slice(in_n_rows * in_n_cols) 00075 , n_slices (in_n_slices) 00076 , n_elem (n_elem_slice * in_n_slices) 00077 { 00078 arma_extra_debug_sigprint(); 00079 } 00080 00081 00082 00083 template<typename eT> 00084 inline 00085 void 00086 subview_cube<eT>::operator+= (const eT val) 00087 { 00088 arma_extra_debug_sigprint(); 00089 00090 const uword local_n_rows = n_rows; 00091 const uword local_n_cols = n_cols; 00092 const uword local_n_slices = n_slices; 00093 00094 for(uword slice = 0; slice < local_n_slices; ++slice) 00095 { 00096 for(uword col = 0; col < local_n_cols; ++col) 00097 { 00098 arrayops::inplace_plus( slice_colptr(slice,col), val, local_n_rows ); 00099 } 00100 } 00101 } 00102 00103 00104 00105 template<typename eT> 00106 inline 00107 void 00108 subview_cube<eT>::operator-= (const eT val) 00109 { 00110 arma_extra_debug_sigprint(); 00111 00112 const uword local_n_rows = n_rows; 00113 const uword local_n_cols = n_cols; 00114 const uword local_n_slices = n_slices; 00115 00116 for(uword slice = 0; slice < local_n_slices; ++slice) 00117 { 00118 for(uword col = 0; col < local_n_cols; ++col) 00119 { 00120 arrayops::inplace_minus( slice_colptr(slice,col), val, local_n_rows ); 00121 } 00122 } 00123 } 00124 00125 00126 00127 template<typename eT> 00128 inline 00129 void 00130 subview_cube<eT>::operator*= (const eT val) 00131 { 00132 arma_extra_debug_sigprint(); 00133 00134 const uword local_n_rows = n_rows; 00135 const uword local_n_cols = n_cols; 00136 const uword local_n_slices = n_slices; 00137 00138 for(uword slice = 0; slice < local_n_slices; ++slice) 00139 { 00140 for(uword col = 0; col < local_n_cols; ++col) 00141 { 00142 arrayops::inplace_mul( slice_colptr(slice,col), val, local_n_rows ); 00143 } 00144 } 00145 } 00146 00147 00148 00149 template<typename eT> 00150 inline 00151 void 00152 subview_cube<eT>::operator/= (const eT val) 00153 { 00154 arma_extra_debug_sigprint(); 00155 00156 const uword local_n_rows = n_rows; 00157 const uword local_n_cols = n_cols; 00158 const uword local_n_slices = n_slices; 00159 00160 for(uword slice = 0; slice < local_n_slices; ++slice) 00161 { 00162 for(uword col = 0; col < local_n_cols; ++col) 00163 { 00164 arrayops::inplace_div( slice_colptr(slice,col), val, local_n_rows ); 00165 } 00166 } 00167 } 00168 00169 00170 00171 template<typename eT> 00172 template<typename T1> 00173 inline 00174 void 00175 subview_cube<eT>::operator= (const BaseCube<eT,T1>& in) 00176 { 00177 arma_extra_debug_sigprint(); 00178 00179 const unwrap_cube<T1> tmp(in.get_ref()); 00180 00181 const Cube<eT>& x = tmp.M; 00182 subview_cube<eT>& t = *this; 00183 00184 arma_debug_assert_same_size(t, x, "copy into subcube"); 00185 00186 const uword t_n_rows = t.n_rows; 00187 const uword t_n_cols = t.n_cols; 00188 const uword t_n_slices = t.n_slices; 00189 00190 for(uword slice = 0; slice < t_n_slices; ++slice) 00191 { 00192 for(uword col = 0; col < t_n_cols; ++col) 00193 { 00194 arrayops::copy( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); 00195 } 00196 } 00197 } 00198 00199 00200 00201 template<typename eT> 00202 template<typename T1> 00203 inline 00204 void 00205 subview_cube<eT>::operator+= (const BaseCube<eT,T1>& in) 00206 { 00207 arma_extra_debug_sigprint(); 00208 00209 const unwrap_cube<T1> tmp(in.get_ref()); 00210 00211 const Cube<eT>& x = tmp.M; 00212 subview_cube<eT>& t = *this; 00213 00214 arma_debug_assert_same_size(t, x, "addition"); 00215 00216 const uword t_n_rows = t.n_rows; 00217 const uword t_n_cols = t.n_cols; 00218 const uword t_n_slices = t.n_slices; 00219 00220 for(uword slice = 0; slice < t_n_slices; ++slice) 00221 { 00222 for(uword col = 0; col < t_n_cols; ++col) 00223 { 00224 arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); 00225 } 00226 } 00227 } 00228 00229 00230 00231 template<typename eT> 00232 template<typename T1> 00233 inline 00234 void 00235 subview_cube<eT>::operator-= (const BaseCube<eT,T1>& in) 00236 { 00237 arma_extra_debug_sigprint(); 00238 00239 const unwrap_cube<T1> tmp(in.get_ref()); 00240 00241 const Cube<eT>& x = tmp.M; 00242 subview_cube<eT>& t = *this; 00243 00244 arma_debug_assert_same_size(t, x, "subtraction"); 00245 00246 const uword t_n_rows = t.n_rows; 00247 const uword t_n_cols = t.n_cols; 00248 const uword t_n_slices = t.n_slices; 00249 00250 for(uword slice = 0; slice < t_n_slices; ++slice) 00251 { 00252 for(uword col = 0; col < t_n_cols; ++col) 00253 { 00254 arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); 00255 } 00256 } 00257 } 00258 00259 00260 00261 template<typename eT> 00262 template<typename T1> 00263 inline 00264 void 00265 subview_cube<eT>::operator%= (const BaseCube<eT,T1>& in) 00266 { 00267 arma_extra_debug_sigprint(); 00268 00269 const unwrap_cube<T1> tmp(in.get_ref()); 00270 00271 const Cube<eT>& x = tmp.M; 00272 subview_cube<eT>& t = *this; 00273 00274 arma_debug_assert_same_size(t, x, "element-wise multiplication"); 00275 00276 const uword t_n_rows = t.n_rows; 00277 const uword t_n_cols = t.n_cols; 00278 const uword t_n_slices = t.n_slices; 00279 00280 for(uword slice = 0; slice < t_n_slices; ++slice) 00281 { 00282 for(uword col = 0; col < t_n_cols; ++col) 00283 { 00284 arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); 00285 } 00286 } 00287 } 00288 00289 00290 00291 template<typename eT> 00292 template<typename T1> 00293 inline 00294 void 00295 subview_cube<eT>::operator/= (const BaseCube<eT,T1>& in) 00296 { 00297 arma_extra_debug_sigprint(); 00298 00299 const unwrap_cube<T1> tmp(in.get_ref()); 00300 00301 const Cube<eT>& x = tmp.M; 00302 subview_cube<eT>& t = *this; 00303 00304 arma_debug_assert_same_size(t, x, "element-wise division"); 00305 00306 const uword t_n_rows = t.n_rows; 00307 const uword t_n_cols = t.n_cols; 00308 const uword t_n_slices = t.n_slices; 00309 00310 for(uword slice = 0; slice < t_n_slices; ++slice) 00311 { 00312 for(uword col = 0; col < t_n_cols; ++col) 00313 { 00314 arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); 00315 } 00316 } 00317 } 00318 00319 00320 00322 template<typename eT> 00323 inline 00324 void 00325 subview_cube<eT>::operator= (const subview_cube<eT>& x_in) 00326 { 00327 arma_extra_debug_sigprint(); 00328 00329 const bool overlap = check_overlap(x_in); 00330 00331 Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0; 00332 const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; 00333 const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in; 00334 00335 subview_cube<eT>& t = *this; 00336 00337 arma_debug_assert_same_size(t, x, "copy into subcube"); 00338 00339 const uword t_n_rows = t.n_rows; 00340 const uword t_n_cols = t.n_cols; 00341 const uword t_n_slices = t.n_slices; 00342 00343 for(uword slice = 0; slice < t_n_slices; ++slice) 00344 { 00345 for(uword col = 0; col < t_n_cols; ++col) 00346 { 00347 arrayops::copy( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); 00348 } 00349 } 00350 00351 if(overlap) 00352 { 00353 delete tmp_subview_cube; 00354 delete tmp_cube; 00355 } 00356 00357 } 00358 00359 00360 00361 template<typename eT> 00362 inline 00363 void 00364 subview_cube<eT>::operator+= (const subview_cube<eT>& x_in) 00365 { 00366 arma_extra_debug_sigprint(); 00367 00368 const bool overlap = check_overlap(x_in); 00369 00370 Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0; 00371 const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; 00372 const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in; 00373 00374 subview_cube<eT>& t = *this; 00375 00376 arma_debug_assert_same_size(t, x, "addition"); 00377 00378 const uword t_n_rows = t.n_rows; 00379 const uword t_n_cols = t.n_cols; 00380 const uword t_n_slices = t.n_slices; 00381 00382 for(uword slice = 0; slice < t_n_slices; ++slice) 00383 { 00384 for(uword col = 0; col < t_n_cols; ++col) 00385 { 00386 arrayops::inplace_plus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); 00387 } 00388 } 00389 00390 if(overlap) 00391 { 00392 delete tmp_subview_cube; 00393 delete tmp_cube; 00394 } 00395 00396 } 00397 00398 00399 00400 template<typename eT> 00401 inline 00402 void 00403 subview_cube<eT>::operator-= (const subview_cube<eT>& x_in) 00404 { 00405 arma_extra_debug_sigprint(); 00406 00407 const bool overlap = check_overlap(x_in); 00408 00409 Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0; 00410 const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; 00411 const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in; 00412 00413 subview_cube<eT>& t = *this; 00414 00415 arma_debug_assert_same_size(t, x, "subtraction"); 00416 00417 const uword t_n_rows = t.n_rows; 00418 const uword t_n_cols = t.n_cols; 00419 const uword t_n_slices = t.n_slices; 00420 00421 for(uword slice = 0; slice < t_n_slices; ++slice) 00422 { 00423 for(uword col = 0; col < t_n_cols; ++col) 00424 { 00425 arrayops::inplace_minus( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); 00426 } 00427 } 00428 00429 if(overlap) 00430 { 00431 delete tmp_subview_cube; 00432 delete tmp_cube; 00433 } 00434 00435 } 00436 00437 00438 00439 template<typename eT> 00440 inline 00441 void 00442 subview_cube<eT>::operator%= (const subview_cube<eT>& x_in) 00443 { 00444 arma_extra_debug_sigprint(); 00445 00446 const bool overlap = check_overlap(x_in); 00447 00448 Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0; 00449 const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; 00450 const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in; 00451 00452 subview_cube<eT>& t = *this; 00453 00454 arma_debug_assert_same_size(t, x, "element-wise multiplication"); 00455 00456 const uword t_n_rows = t.n_rows; 00457 const uword t_n_cols = t.n_cols; 00458 const uword t_n_slices = t.n_slices; 00459 00460 for(uword slice = 0; slice < t_n_slices; ++slice) 00461 { 00462 for(uword col = 0; col < t_n_cols; ++col) 00463 { 00464 arrayops::inplace_mul( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); 00465 } 00466 } 00467 00468 if(overlap) 00469 { 00470 delete tmp_subview_cube; 00471 delete tmp_cube; 00472 } 00473 00474 } 00475 00476 00477 00478 template<typename eT> 00479 inline 00480 void 00481 subview_cube<eT>::operator/= (const subview_cube<eT>& x_in) 00482 { 00483 arma_extra_debug_sigprint(); 00484 00485 const bool overlap = check_overlap(x_in); 00486 00487 Cube<eT>* tmp_cube = overlap ? new Cube<eT>(x_in.m) : 0; 00488 const subview_cube<eT>* tmp_subview_cube = overlap ? new subview_cube<eT>(*tmp_cube, x_in.aux_row1, x_in.aux_col1, x_in.aux_slice1, x_in.n_rows, x_in.n_cols, x_in.n_slices) : 0; 00489 const subview_cube<eT>& x = overlap ? (*tmp_subview_cube) : x_in; 00490 00491 subview_cube<eT>& t = *this; 00492 00493 arma_debug_assert_same_size(t, x, "element-wise division"); 00494 00495 const uword t_n_rows = t.n_rows; 00496 const uword t_n_cols = t.n_cols; 00497 const uword t_n_slices = t.n_slices; 00498 00499 for(uword slice = 0; slice < t_n_slices; ++slice) 00500 { 00501 for(uword col = 0; col < t_n_cols; ++col) 00502 { 00503 arrayops::inplace_div( t.slice_colptr(slice,col), x.slice_colptr(slice,col), t_n_rows ); 00504 } 00505 } 00506 00507 if(overlap) 00508 { 00509 delete tmp_subview_cube; 00510 delete tmp_cube; 00511 } 00512 00513 } 00514 00515 00516 00517 template<typename eT> 00518 template<typename T1> 00519 inline 00520 void 00521 subview_cube<eT>::operator= (const Base<eT,T1>& in) 00522 { 00523 arma_extra_debug_sigprint(); 00524 00525 const unwrap<T1> tmp(in.get_ref()); 00526 00527 const Mat<eT>& x = tmp.M; 00528 subview_cube<eT>& t = *this; 00529 00530 const uword t_n_rows = t.n_rows; 00531 const uword t_n_cols = t.n_cols; 00532 const uword t_n_slices = t.n_slices; 00533 00534 const uword x_n_rows = x.n_rows; 00535 const uword x_n_cols = x.n_cols; 00536 00537 if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) 00538 { 00539 // interpret the matrix as a cube with one slice 00540 00541 for(uword col = 0; col < t_n_cols; ++col) 00542 { 00543 arrayops::copy( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); 00544 } 00545 } 00546 else 00547 if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) 00548 { 00549 for(uword i=0; i < t_n_slices; ++i) 00550 { 00551 arrayops::copy( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); 00552 } 00553 } 00554 else 00555 if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) 00556 { 00557 Cube<eT>& Q = *(t.m_ptr); 00558 00559 const uword t_aux_row1 = t.aux_row1; 00560 const uword t_aux_col1 = t.aux_col1; 00561 const uword t_aux_slice1 = t.aux_slice1; 00562 00563 for(uword slice=0; slice < t_n_slices; ++slice) 00564 { 00565 const uword mod_slice = t_aux_slice1 + slice; 00566 00567 const eT* x_colptr = x.colptr(slice); 00568 00569 uword i,j; 00570 for(i=0, j=1; j < t_n_cols; i+=2, j+=2) 00571 { 00572 const eT tmp_i = x_colptr[i]; 00573 const eT tmp_j = x_colptr[j]; 00574 00575 Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) = tmp_i; 00576 Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) = tmp_j; 00577 } 00578 00579 if(i < t_n_cols) 00580 { 00581 Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) = x_colptr[i]; 00582 } 00583 } 00584 } 00585 else 00586 { 00587 if(arma_config::debug == true) 00588 { 00589 arma_stop( arma_incompat_size_string(t, x, "copy into subcube") ); 00590 } 00591 } 00592 } 00593 00594 00595 00596 template<typename eT> 00597 template<typename T1> 00598 inline 00599 void 00600 subview_cube<eT>::operator+= (const Base<eT,T1>& in) 00601 { 00602 arma_extra_debug_sigprint(); 00603 00604 const unwrap<T1> tmp(in.get_ref()); 00605 00606 const Mat<eT>& x = tmp.M; 00607 subview_cube<eT>& t = *this; 00608 00609 const uword t_n_rows = t.n_rows; 00610 const uword t_n_cols = t.n_cols; 00611 const uword t_n_slices = t.n_slices; 00612 00613 const uword x_n_rows = x.n_rows; 00614 const uword x_n_cols = x.n_cols; 00615 00616 if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) 00617 { 00618 for(uword col = 0; col < t_n_cols; ++col) 00619 { 00620 arrayops::inplace_plus( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); 00621 } 00622 } 00623 else 00624 if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) 00625 { 00626 for(uword i=0; i < t_n_slices; ++i) 00627 { 00628 arrayops::inplace_plus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); 00629 } 00630 } 00631 else 00632 if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) 00633 { 00634 Cube<eT>& Q = *(t.m_ptr); 00635 00636 const uword t_aux_row1 = t.aux_row1; 00637 const uword t_aux_col1 = t.aux_col1; 00638 const uword t_aux_slice1 = t.aux_slice1; 00639 00640 for(uword slice=0; slice < t_n_slices; ++slice) 00641 { 00642 const uword mod_slice = t_aux_slice1 + slice; 00643 00644 const eT* x_colptr = x.colptr(slice); 00645 00646 uword i,j; 00647 for(i=0, j=1; j < t_n_cols; i+=2, j+=2) 00648 { 00649 const eT tmp_i = x_colptr[i]; 00650 const eT tmp_j = x_colptr[j]; 00651 00652 Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) += tmp_i; 00653 Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) += tmp_j; 00654 } 00655 00656 if(i < t_n_cols) 00657 { 00658 Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) += x_colptr[i]; 00659 } 00660 } 00661 } 00662 else 00663 { 00664 if(arma_config::debug == true) 00665 { 00666 arma_stop( arma_incompat_size_string(t, x, "addition") ); 00667 } 00668 } 00669 } 00670 00671 00672 00673 template<typename eT> 00674 template<typename T1> 00675 inline 00676 void 00677 subview_cube<eT>::operator-= (const Base<eT,T1>& in) 00678 { 00679 arma_extra_debug_sigprint(); 00680 00681 const unwrap<T1> tmp(in.get_ref()); 00682 00683 const Mat<eT>& x = tmp.M; 00684 subview_cube<eT>& t = *this; 00685 00686 const uword t_n_rows = t.n_rows; 00687 const uword t_n_cols = t.n_cols; 00688 const uword t_n_slices = t.n_slices; 00689 00690 const uword x_n_rows = x.n_rows; 00691 const uword x_n_cols = x.n_cols; 00692 00693 if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) 00694 { 00695 for(uword col = 0; col < t_n_cols; ++col) 00696 { 00697 arrayops::inplace_minus( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); 00698 } 00699 } 00700 else 00701 if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) 00702 { 00703 for(uword i=0; i < t_n_slices; ++i) 00704 { 00705 arrayops::inplace_minus( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); 00706 } 00707 } 00708 else 00709 if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) 00710 { 00711 Cube<eT>& Q = *(t.m_ptr); 00712 00713 const uword t_aux_row1 = t.aux_row1; 00714 const uword t_aux_col1 = t.aux_col1; 00715 const uword t_aux_slice1 = t.aux_slice1; 00716 00717 for(uword slice=0; slice < t_n_slices; ++slice) 00718 { 00719 const uword mod_slice = t_aux_slice1 + slice; 00720 00721 const eT* x_colptr = x.colptr(slice); 00722 00723 uword i,j; 00724 for(i=0, j=1; j < t_n_cols; i+=2, j+=2) 00725 { 00726 const eT tmp_i = x_colptr[i]; 00727 const eT tmp_j = x_colptr[j]; 00728 00729 Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) -= tmp_i; 00730 Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) -= tmp_j; 00731 } 00732 00733 if(i < t_n_cols) 00734 { 00735 Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) -= x_colptr[i]; 00736 } 00737 } 00738 } 00739 else 00740 { 00741 if(arma_config::debug == true) 00742 { 00743 arma_stop( arma_incompat_size_string(t, x, "subtraction") ); 00744 } 00745 } 00746 } 00747 00748 00749 00750 template<typename eT> 00751 template<typename T1> 00752 inline 00753 void 00754 subview_cube<eT>::operator%= (const Base<eT,T1>& in) 00755 { 00756 arma_extra_debug_sigprint(); 00757 00758 const unwrap<T1> tmp(in.get_ref()); 00759 00760 const Mat<eT>& x = tmp.M; 00761 subview_cube<eT>& t = *this; 00762 00763 const uword t_n_rows = t.n_rows; 00764 const uword t_n_cols = t.n_cols; 00765 const uword t_n_slices = t.n_slices; 00766 00767 const uword x_n_rows = x.n_rows; 00768 const uword x_n_cols = x.n_cols; 00769 00770 if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) 00771 { 00772 for(uword col = 0; col < t_n_cols; ++col) 00773 { 00774 arrayops::inplace_mul( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); 00775 } 00776 } 00777 else 00778 if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) 00779 { 00780 for(uword i=0; i < t_n_slices; ++i) 00781 { 00782 arrayops::inplace_mul( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); 00783 } 00784 } 00785 else 00786 if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) 00787 { 00788 Cube<eT>& Q = *(t.m_ptr); 00789 00790 const uword t_aux_row1 = t.aux_row1; 00791 const uword t_aux_col1 = t.aux_col1; 00792 const uword t_aux_slice1 = t.aux_slice1; 00793 00794 for(uword slice=0; slice < t_n_slices; ++slice) 00795 { 00796 const uword mod_slice = t_aux_slice1 + slice; 00797 00798 const eT* x_colptr = x.colptr(slice); 00799 00800 uword i,j; 00801 for(i=0, j=1; j < t_n_cols; i+=2, j+=2) 00802 { 00803 const eT tmp_i = x_colptr[i]; 00804 const eT tmp_j = x_colptr[j]; 00805 00806 Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) *= tmp_i; 00807 Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) *= tmp_j; 00808 } 00809 00810 if(i < t_n_cols) 00811 { 00812 Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) *= x_colptr[i]; 00813 } 00814 } 00815 } 00816 else 00817 { 00818 if(arma_config::debug == true) 00819 { 00820 arma_stop( arma_incompat_size_string(t, x, "element-wise multiplication") ); 00821 } 00822 } 00823 } 00824 00825 00826 00827 template<typename eT> 00828 template<typename T1> 00829 inline 00830 void 00831 subview_cube<eT>::operator/= (const Base<eT,T1>& in) 00832 { 00833 arma_extra_debug_sigprint(); 00834 00835 const unwrap<T1> tmp(in.get_ref()); 00836 00837 const Mat<eT>& x = tmp.M; 00838 subview_cube<eT>& t = *this; 00839 00840 const uword t_n_rows = t.n_rows; 00841 const uword t_n_cols = t.n_cols; 00842 const uword t_n_slices = t.n_slices; 00843 00844 const uword x_n_rows = x.n_rows; 00845 const uword x_n_cols = x.n_cols; 00846 00847 if( (t_n_rows == x_n_rows) && (t_n_cols == x_n_cols) && (t_n_slices == 1) ) 00848 { 00849 for(uword col = 0; col < t_n_cols; ++col) 00850 { 00851 arrayops::inplace_div( t.slice_colptr(0, col), x.colptr(col), t_n_rows ); 00852 } 00853 } 00854 else 00855 if( (t_n_rows == x_n_rows) && (t_n_cols == 1) && (t_n_slices == x_n_cols) ) 00856 { 00857 for(uword i=0; i < t_n_slices; ++i) 00858 { 00859 arrayops::inplace_div( t.slice_colptr(i, 0), x.colptr(i), t_n_rows ); 00860 } 00861 } 00862 else 00863 if( (t_n_rows == 1) && (t_n_cols == x_n_rows) && (t_n_slices == x_n_cols) ) 00864 { 00865 Cube<eT>& Q = *(t.m_ptr); 00866 00867 const uword t_aux_row1 = t.aux_row1; 00868 const uword t_aux_col1 = t.aux_col1; 00869 const uword t_aux_slice1 = t.aux_slice1; 00870 00871 for(uword slice=0; slice < t_n_slices; ++slice) 00872 { 00873 const uword mod_slice = t_aux_slice1 + slice; 00874 00875 const eT* x_colptr = x.colptr(slice); 00876 00877 uword i,j; 00878 for(i=0, j=1; j < t_n_cols; i+=2, j+=2) 00879 { 00880 const eT tmp_i = x_colptr[i]; 00881 const eT tmp_j = x_colptr[j]; 00882 00883 Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) /= tmp_i; 00884 Q.at(t_aux_row1, t_aux_col1 + j, mod_slice) /= tmp_j; 00885 } 00886 00887 if(i < t_n_cols) 00888 { 00889 Q.at(t_aux_row1, t_aux_col1 + i, mod_slice) /= x_colptr[i]; 00890 } 00891 } 00892 } 00893 else 00894 { 00895 if(arma_config::debug == true) 00896 { 00897 arma_stop( arma_incompat_size_string(t, x, "element-wise division") ); 00898 } 00899 } 00900 } 00901 00902 00903 00904 template<typename eT> 00905 inline 00906 void 00907 subview_cube<eT>::fill(const eT val) 00908 { 00909 arma_extra_debug_sigprint(); 00910 00911 const uword local_n_rows = n_rows; 00912 const uword local_n_cols = n_cols; 00913 const uword local_n_slices = n_slices; 00914 00915 for(uword slice = 0; slice < local_n_slices; ++slice) 00916 { 00917 for(uword col = 0; col < local_n_cols; ++col) 00918 { 00919 arrayops::inplace_set( slice_colptr(slice,col), val, local_n_rows ); 00920 } 00921 } 00922 00923 } 00924 00925 00926 00927 template<typename eT> 00928 inline 00929 void 00930 subview_cube<eT>::zeros() 00931 { 00932 arma_extra_debug_sigprint(); 00933 00934 fill(eT(0)); 00935 } 00936 00937 00938 00939 template<typename eT> 00940 inline 00941 void 00942 subview_cube<eT>::ones() 00943 { 00944 arma_extra_debug_sigprint(); 00945 00946 fill(eT(1)); 00947 } 00948 00949 00950 00951 template<typename eT> 00952 inline 00953 eT& 00954 subview_cube<eT>::operator[](const uword i) 00955 { 00956 const uword in_slice = i / n_elem_slice; 00957 const uword offset = in_slice * n_elem_slice; 00958 const uword j = i - offset; 00959 00960 const uword in_col = j / n_rows; 00961 const uword in_row = j % n_rows; 00962 00963 const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; 00964 return access::rw( (*m_ptr).mem[index] ); 00965 } 00966 00967 00968 00969 template<typename eT> 00970 inline 00971 eT 00972 subview_cube<eT>::operator[](const uword i) const 00973 { 00974 const uword in_slice = i / n_elem_slice; 00975 const uword offset = in_slice * n_elem_slice; 00976 const uword j = i - offset; 00977 00978 const uword in_col = j / n_rows; 00979 const uword in_row = j % n_rows; 00980 00981 const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; 00982 return m.mem[index]; 00983 } 00984 00985 00986 00987 template<typename eT> 00988 inline 00989 eT& 00990 subview_cube<eT>::operator()(const uword i) 00991 { 00992 arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of bounds"); 00993 00994 const uword in_slice = i / n_elem_slice; 00995 const uword offset = in_slice * n_elem_slice; 00996 const uword j = i - offset; 00997 00998 const uword in_col = j / n_rows; 00999 const uword in_row = j % n_rows; 01000 01001 const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; 01002 return access::rw( (*m_ptr).mem[index] ); 01003 } 01004 01005 01006 01007 template<typename eT> 01008 inline 01009 eT 01010 subview_cube<eT>::operator()(const uword i) const 01011 { 01012 arma_debug_check( (i >= n_elem), "subview_cube::operator(): index out of bounds"); 01013 01014 const uword in_slice = i / n_elem_slice; 01015 const uword offset = in_slice * n_elem_slice; 01016 const uword j = i - offset; 01017 01018 const uword in_col = j / n_rows; 01019 const uword in_row = j % n_rows; 01020 01021 const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; 01022 return m.mem[index]; 01023 } 01024 01025 01026 01027 template<typename eT> 01028 arma_inline 01029 eT& 01030 subview_cube<eT>::operator()(const uword in_row, const uword in_col, const uword in_slice) 01031 { 01032 arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) ), "subview_cube::operator(): location out of bounds"); 01033 01034 const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; 01035 return access::rw( (*m_ptr).mem[index] ); 01036 } 01037 01038 01039 01040 template<typename eT> 01041 arma_inline 01042 eT 01043 subview_cube<eT>::operator()(const uword in_row, const uword in_col, const uword in_slice) const 01044 { 01045 arma_debug_check( ( (in_row >= n_rows) || (in_col >= n_cols) || (in_slice >= n_slices) ), "subview_cube::operator(): location out of bounds"); 01046 01047 const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; 01048 return m.mem[index]; 01049 } 01050 01051 01052 01053 template<typename eT> 01054 arma_inline 01055 eT& 01056 subview_cube<eT>::at(const uword in_row, const uword in_col, const uword in_slice) 01057 { 01058 const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; 01059 return access::rw( (*m_ptr).mem[index] ); 01060 } 01061 01062 01063 01064 template<typename eT> 01065 arma_inline 01066 eT 01067 subview_cube<eT>::at(const uword in_row, const uword in_col, const uword in_slice) const 01068 { 01069 const uword index = (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; 01070 return m.mem[index]; 01071 } 01072 01073 01074 01075 template<typename eT> 01076 arma_inline 01077 eT* 01078 subview_cube<eT>::slice_colptr(const uword in_slice, const uword in_col) 01079 { 01080 return & access::rw((*m_ptr).mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 ]); 01081 } 01082 01083 01084 01085 template<typename eT> 01086 arma_inline 01087 const eT* 01088 subview_cube<eT>::slice_colptr(const uword in_slice, const uword in_col) const 01089 { 01090 return & m.mem[ (in_slice + aux_slice1)*m.n_elem_slice + (in_col + aux_col1)*m.n_rows + aux_row1 ]; 01091 } 01092 01093 01094 01095 template<typename eT> 01096 inline 01097 bool 01098 subview_cube<eT>::check_overlap(const subview_cube<eT>& x) const 01099 { 01100 const subview_cube<eT>& t = *this; 01101 01102 if(&t.m != &x.m) 01103 { 01104 return false; 01105 } 01106 else 01107 { 01108 if( (t.n_elem == 0) || (x.n_elem == 0) ) 01109 { 01110 return false; 01111 } 01112 else 01113 { 01114 const uword t_row_start = t.aux_row1; 01115 const uword t_row_end_p1 = t_row_start + t.n_rows; 01116 01117 const uword t_col_start = t.aux_col1; 01118 const uword t_col_end_p1 = t_col_start + t.n_cols; 01119 01120 const uword t_slice_start = t.aux_slice1; 01121 const uword t_slice_end_p1 = t_slice_start + t.n_slices; 01122 01123 01124 const uword x_row_start = x.aux_row1; 01125 const uword x_row_end_p1 = x_row_start + x.n_rows; 01126 01127 const uword x_col_start = x.aux_col1; 01128 const uword x_col_end_p1 = x_col_start + x.n_cols; 01129 01130 const uword x_slice_start = x.aux_slice1; 01131 const uword x_slice_end_p1 = x_slice_start + x.n_slices; 01132 01133 01134 const bool outside_rows = ( (x_row_start >= t_row_end_p1 ) || (t_row_start >= x_row_end_p1 ) ); 01135 const bool outside_cols = ( (x_col_start >= t_col_end_p1 ) || (t_col_start >= x_col_end_p1 ) ); 01136 const bool outside_slices = ( (x_slice_start >= t_slice_end_p1) || (t_slice_start >= x_slice_end_p1) ); 01137 01138 return ( (outside_rows == false) && (outside_cols == false) && (outside_slices == false) ); 01139 } 01140 } 01141 } 01142 01143 01144 01145 template<typename eT> 01146 inline 01147 bool 01148 subview_cube<eT>::check_overlap(const Mat<eT>& x) const 01149 { 01150 const subview_cube<eT>& t = *this; 01151 01152 const uword t_aux_slice1 = t.aux_slice1; 01153 const uword t_aux_slice2_plus_1 = t_aux_slice1 + t.n_slices; 01154 01155 for(uword slice = t_aux_slice1; slice < t_aux_slice2_plus_1; ++slice) 01156 { 01157 const Mat<eT>& y = *(t.m.mat_ptrs[slice]); 01158 01159 if( x.memptr() == y.memptr() ) 01160 { 01161 return true; 01162 } 01163 } 01164 01165 return false; 01166 } 01167 01168 01169 01171 template<typename eT> 01172 inline 01173 void 01174 subview_cube<eT>::extract(Cube<eT>& out, const subview_cube<eT>& in) 01175 { 01176 arma_extra_debug_sigprint(); 01177 01178 // NOTE: we're assuming that the cube has already been set to the correct size and there is no aliasing; 01179 // size setting and alias checking is done by either the Cube contructor or operator=() 01180 01181 const uword n_rows = in.n_rows; 01182 const uword n_cols = in.n_cols; 01183 const uword n_slices = in.n_slices; 01184 01185 arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols = %d out.n_slices = %d in.m.n_rows = %d in.m.n_cols = %d in.m.n_slices = %d") % out.n_rows % out.n_cols % out.n_slices % in.m.n_rows % in.m.n_cols % in.m.n_slices); 01186 01187 01188 for(uword slice = 0; slice < n_slices; ++slice) 01189 { 01190 for(uword col = 0; col < n_cols; ++col) 01191 { 01192 arrayops::copy( out.slice_colptr(slice,col), in.slice_colptr(slice,col), n_rows ); 01193 } 01194 } 01195 } 01196 01197 01198 01200 template<typename eT> 01201 inline 01202 void 01203 subview_cube<eT>::plus_inplace(Cube<eT>& out, const subview_cube<eT>& in) 01204 { 01205 arma_extra_debug_sigprint(); 01206 01207 arma_debug_assert_same_size(out, in, "addition"); 01208 01209 const uword n_rows = out.n_rows; 01210 const uword n_cols = out.n_cols; 01211 const uword n_slices = out.n_slices; 01212 01213 for(uword slice = 0; slice<n_slices; ++slice) 01214 { 01215 for(uword col = 0; col<n_cols; ++col) 01216 { 01217 arrayops::inplace_plus( out.slice_colptr(slice,col), in.slice_colptr(slice,col), n_rows ); 01218 } 01219 } 01220 } 01221 01222 01223 01225 template<typename eT> 01226 inline 01227 void 01228 subview_cube<eT>::minus_inplace(Cube<eT>& out, const subview_cube<eT>& in) 01229 { 01230 arma_extra_debug_sigprint(); 01231 01232 arma_debug_assert_same_size(out, in, "subtraction"); 01233 01234 const uword n_rows = out.n_rows; 01235 const uword n_cols = out.n_cols; 01236 const uword n_slices = out.n_slices; 01237 01238 for(uword slice = 0; slice<n_slices; ++slice) 01239 { 01240 for(uword col = 0; col<n_cols; ++col) 01241 { 01242 arrayops::inplace_minus( out.slice_colptr(slice,col), in.slice_colptr(slice,col), n_rows ); 01243 } 01244 } 01245 } 01246 01247 01248 01250 template<typename eT> 01251 inline 01252 void 01253 subview_cube<eT>::schur_inplace(Cube<eT>& out, const subview_cube<eT>& in) 01254 { 01255 arma_extra_debug_sigprint(); 01256 01257 arma_debug_assert_same_size(out, in, "element-wise multiplication"); 01258 01259 const uword n_rows = out.n_rows; 01260 const uword n_cols = out.n_cols; 01261 const uword n_slices = out.n_slices; 01262 01263 for(uword slice = 0; slice<n_slices; ++slice) 01264 { 01265 for(uword col = 0; col<n_cols; ++col) 01266 { 01267 arrayops::inplace_mul( out.slice_colptr(slice,col), in.slice_colptr(slice,col), n_rows ); 01268 } 01269 } 01270 } 01271 01272 01273 01275 template<typename eT> 01276 inline 01277 void 01278 subview_cube<eT>::div_inplace(Cube<eT>& out, const subview_cube<eT>& in) 01279 { 01280 arma_extra_debug_sigprint(); 01281 01282 arma_debug_assert_same_size(out, in, "element-wise division"); 01283 01284 const uword n_rows = out.n_rows; 01285 const uword n_cols = out.n_cols; 01286 const uword n_slices = out.n_slices; 01287 01288 for(uword slice = 0; slice<n_slices; ++slice) 01289 { 01290 for(uword col = 0; col<n_cols; ++col) 01291 { 01292 arrayops::inplace_div( out.slice_colptr(slice,col), in.slice_colptr(slice,col), n_rows ); 01293 } 01294 } 01295 } 01296 01297 01298 01300 template<typename eT> 01301 inline 01302 void 01303 subview_cube<eT>::extract(Mat<eT>& out, const subview_cube<eT>& in) 01304 { 01305 arma_extra_debug_sigprint(); 01306 01307 arma_debug_assert_cube_as_mat(out, in, "copy into matrix", false); 01308 01309 const uword in_n_rows = in.n_rows; 01310 const uword in_n_cols = in.n_cols; 01311 const uword in_n_slices = in.n_slices; 01312 01313 const uword out_vec_state = out.vec_state; 01314 01315 if(in_n_slices == 1) 01316 { 01317 out.set_size(in_n_rows, in_n_cols); 01318 01319 for(uword col=0; col < in_n_cols; ++col) 01320 { 01321 arrayops::copy( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); 01322 } 01323 } 01324 else 01325 { 01326 if(out_vec_state == 0) 01327 { 01328 if(in_n_cols == 1) 01329 { 01330 out.set_size(in_n_rows, in_n_slices); 01331 01332 for(uword i=0; i < in_n_slices; ++i) 01333 { 01334 arrayops::copy( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); 01335 } 01336 } 01337 else 01338 if(in_n_rows == 1) 01339 { 01340 const Cube<eT>& Q = in.m; 01341 01342 const uword in_aux_row1 = in.aux_row1; 01343 const uword in_aux_col1 = in.aux_col1; 01344 const uword in_aux_slice1 = in.aux_slice1; 01345 01346 out.set_size(in_n_cols, in_n_slices); 01347 01348 for(uword slice=0; slice < in_n_slices; ++slice) 01349 { 01350 const uword mod_slice = in_aux_slice1 + slice; 01351 01352 eT* out_colptr = out.colptr(slice); 01353 01354 uword i,j; 01355 for(i=0, j=1; j < in_n_cols; i+=2, j+=2) 01356 { 01357 const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); 01358 const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); 01359 01360 out_colptr[i] = tmp_i; 01361 out_colptr[j] = tmp_j; 01362 } 01363 01364 if(i < in_n_cols) 01365 { 01366 out_colptr[i] = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); 01367 } 01368 } 01369 } 01370 } 01371 else 01372 { 01373 out.set_size(in_n_slices); 01374 01375 eT* out_mem = out.memptr(); 01376 01377 const Cube<eT>& Q = in.m; 01378 01379 const uword in_aux_row1 = in.aux_row1; 01380 const uword in_aux_col1 = in.aux_col1; 01381 const uword in_aux_slice1 = in.aux_slice1; 01382 01383 for(uword i=0; i<in_n_slices; ++i) 01384 { 01385 out_mem[i] = Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i); 01386 } 01387 } 01388 } 01389 } 01390 01391 01392 01394 template<typename eT> 01395 inline 01396 void 01397 subview_cube<eT>::plus_inplace(Mat<eT>& out, const subview_cube<eT>& in) 01398 { 01399 arma_extra_debug_sigprint(); 01400 01401 arma_debug_assert_cube_as_mat(out, in, "addition", true); 01402 01403 const uword in_n_rows = in.n_rows; 01404 const uword in_n_cols = in.n_cols; 01405 const uword in_n_slices = in.n_slices; 01406 01407 const uword out_n_rows = out.n_rows; 01408 const uword out_n_cols = out.n_cols; 01409 const uword out_vec_state = out.vec_state; 01410 01411 if(in_n_slices == 1) 01412 { 01413 for(uword col=0; col < in_n_cols; ++col) 01414 { 01415 arrayops::inplace_plus( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); 01416 } 01417 } 01418 else 01419 { 01420 if(out_vec_state == 0) 01421 { 01422 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) 01423 { 01424 for(uword i=0; i < in_n_slices; ++i) 01425 { 01426 arrayops::inplace_plus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); 01427 } 01428 } 01429 else 01430 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) 01431 { 01432 const Cube<eT>& Q = in.m; 01433 01434 const uword in_aux_row1 = in.aux_row1; 01435 const uword in_aux_col1 = in.aux_col1; 01436 const uword in_aux_slice1 = in.aux_slice1; 01437 01438 for(uword slice=0; slice < in_n_slices; ++slice) 01439 { 01440 const uword mod_slice = in_aux_slice1 + slice; 01441 01442 eT* out_colptr = out.colptr(slice); 01443 01444 uword i,j; 01445 for(i=0, j=1; j < in_n_cols; i+=2, j+=2) 01446 { 01447 const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); 01448 const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); 01449 01450 out_colptr[i] += tmp_i; 01451 out_colptr[j] += tmp_j; 01452 } 01453 01454 if(i < in_n_cols) 01455 { 01456 out_colptr[i] += Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); 01457 } 01458 } 01459 } 01460 } 01461 else 01462 { 01463 eT* out_mem = out.memptr(); 01464 01465 const Cube<eT>& Q = in.m; 01466 01467 const uword in_aux_row1 = in.aux_row1; 01468 const uword in_aux_col1 = in.aux_col1; 01469 const uword in_aux_slice1 = in.aux_slice1; 01470 01471 for(uword i=0; i<in_n_slices; ++i) 01472 { 01473 out_mem[i] += Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i); 01474 } 01475 } 01476 } 01477 } 01478 01479 01480 01482 template<typename eT> 01483 inline 01484 void 01485 subview_cube<eT>::minus_inplace(Mat<eT>& out, const subview_cube<eT>& in) 01486 { 01487 arma_extra_debug_sigprint(); 01488 01489 arma_debug_assert_cube_as_mat(out, in, "subtraction", true); 01490 01491 const uword in_n_rows = in.n_rows; 01492 const uword in_n_cols = in.n_cols; 01493 const uword in_n_slices = in.n_slices; 01494 01495 const uword out_n_rows = out.n_rows; 01496 const uword out_n_cols = out.n_cols; 01497 const uword out_vec_state = out.vec_state; 01498 01499 if(in_n_slices == 1) 01500 { 01501 for(uword col=0; col < in_n_cols; ++col) 01502 { 01503 arrayops::inplace_minus( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); 01504 } 01505 } 01506 else 01507 { 01508 if(out_vec_state == 0) 01509 { 01510 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) 01511 { 01512 for(uword i=0; i < in_n_slices; ++i) 01513 { 01514 arrayops::inplace_minus( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); 01515 } 01516 } 01517 else 01518 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) 01519 { 01520 const Cube<eT>& Q = in.m; 01521 01522 const uword in_aux_row1 = in.aux_row1; 01523 const uword in_aux_col1 = in.aux_col1; 01524 const uword in_aux_slice1 = in.aux_slice1; 01525 01526 for(uword slice=0; slice < in_n_slices; ++slice) 01527 { 01528 const uword mod_slice = in_aux_slice1 + slice; 01529 01530 eT* out_colptr = out.colptr(slice); 01531 01532 uword i,j; 01533 for(i=0, j=1; j < in_n_cols; i+=2, j+=2) 01534 { 01535 const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); 01536 const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); 01537 01538 out_colptr[i] -= tmp_i; 01539 out_colptr[j] -= tmp_j; 01540 } 01541 01542 if(i < in_n_cols) 01543 { 01544 out_colptr[i] -= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); 01545 } 01546 } 01547 } 01548 } 01549 else 01550 { 01551 eT* out_mem = out.memptr(); 01552 01553 const Cube<eT>& Q = in.m; 01554 01555 const uword in_aux_row1 = in.aux_row1; 01556 const uword in_aux_col1 = in.aux_col1; 01557 const uword in_aux_slice1 = in.aux_slice1; 01558 01559 for(uword i=0; i<in_n_slices; ++i) 01560 { 01561 out_mem[i] -= Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i); 01562 } 01563 } 01564 } 01565 } 01566 01567 01568 01570 template<typename eT> 01571 inline 01572 void 01573 subview_cube<eT>::schur_inplace(Mat<eT>& out, const subview_cube<eT>& in) 01574 { 01575 arma_extra_debug_sigprint(); 01576 01577 arma_debug_assert_cube_as_mat(out, in, "element-wise multiplication", true); 01578 01579 const uword in_n_rows = in.n_rows; 01580 const uword in_n_cols = in.n_cols; 01581 const uword in_n_slices = in.n_slices; 01582 01583 const uword out_n_rows = out.n_rows; 01584 const uword out_n_cols = out.n_cols; 01585 const uword out_vec_state = out.vec_state; 01586 01587 if(in_n_slices == 1) 01588 { 01589 for(uword col=0; col < in_n_cols; ++col) 01590 { 01591 arrayops::inplace_mul( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); 01592 } 01593 } 01594 else 01595 { 01596 if(out_vec_state == 0) 01597 { 01598 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) 01599 { 01600 for(uword i=0; i < in_n_slices; ++i) 01601 { 01602 arrayops::inplace_mul( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); 01603 } 01604 } 01605 else 01606 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) 01607 { 01608 const Cube<eT>& Q = in.m; 01609 01610 const uword in_aux_row1 = in.aux_row1; 01611 const uword in_aux_col1 = in.aux_col1; 01612 const uword in_aux_slice1 = in.aux_slice1; 01613 01614 for(uword slice=0; slice < in_n_slices; ++slice) 01615 { 01616 const uword mod_slice = in_aux_slice1 + slice; 01617 01618 eT* out_colptr = out.colptr(slice); 01619 01620 uword i,j; 01621 for(i=0, j=1; j < in_n_cols; i+=2, j+=2) 01622 { 01623 const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); 01624 const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); 01625 01626 out_colptr[i] *= tmp_i; 01627 out_colptr[j] *= tmp_j; 01628 } 01629 01630 if(i < in_n_cols) 01631 { 01632 out_colptr[i] *= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); 01633 } 01634 } 01635 } 01636 } 01637 else 01638 { 01639 eT* out_mem = out.memptr(); 01640 01641 const Cube<eT>& Q = in.m; 01642 01643 const uword in_aux_row1 = in.aux_row1; 01644 const uword in_aux_col1 = in.aux_col1; 01645 const uword in_aux_slice1 = in.aux_slice1; 01646 01647 for(uword i=0; i<in_n_slices; ++i) 01648 { 01649 out_mem[i] *= Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i); 01650 } 01651 } 01652 } 01653 } 01654 01655 01656 01658 template<typename eT> 01659 inline 01660 void 01661 subview_cube<eT>::div_inplace(Mat<eT>& out, const subview_cube<eT>& in) 01662 { 01663 arma_extra_debug_sigprint(); 01664 01665 arma_debug_assert_cube_as_mat(out, in, "element-wise division", true); 01666 01667 const uword in_n_rows = in.n_rows; 01668 const uword in_n_cols = in.n_cols; 01669 const uword in_n_slices = in.n_slices; 01670 01671 const uword out_n_rows = out.n_rows; 01672 const uword out_n_cols = out.n_cols; 01673 const uword out_vec_state = out.vec_state; 01674 01675 if(in_n_slices == 1) 01676 { 01677 for(uword col=0; col < in_n_cols; ++col) 01678 { 01679 arrayops::inplace_div( out.colptr(col), in.slice_colptr(0, col), in_n_rows ); 01680 } 01681 } 01682 else 01683 { 01684 if(out_vec_state == 0) 01685 { 01686 if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices == out_n_cols) ) 01687 { 01688 for(uword i=0; i < in_n_slices; ++i) 01689 { 01690 arrayops::inplace_div( out.colptr(i), in.slice_colptr(i, 0), in_n_rows ); 01691 } 01692 } 01693 else 01694 if( (in_n_rows == 1) && (in_n_cols == out_n_rows) && (in_n_slices == out_n_cols) ) 01695 { 01696 const Cube<eT>& Q = in.m; 01697 01698 const uword in_aux_row1 = in.aux_row1; 01699 const uword in_aux_col1 = in.aux_col1; 01700 const uword in_aux_slice1 = in.aux_slice1; 01701 01702 for(uword slice=0; slice < in_n_slices; ++slice) 01703 { 01704 const uword mod_slice = in_aux_slice1 + slice; 01705 01706 eT* out_colptr = out.colptr(slice); 01707 01708 uword i,j; 01709 for(i=0, j=1; j < in_n_cols; i+=2, j+=2) 01710 { 01711 const eT tmp_i = Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); 01712 const eT tmp_j = Q.at(in_aux_row1, in_aux_col1 + j, mod_slice); 01713 01714 out_colptr[i] /= tmp_i; 01715 out_colptr[j] /= tmp_j; 01716 } 01717 01718 if(i < in_n_cols) 01719 { 01720 out_colptr[i] /= Q.at(in_aux_row1, in_aux_col1 + i, mod_slice); 01721 } 01722 } 01723 } 01724 } 01725 else 01726 { 01727 eT* out_mem = out.memptr(); 01728 01729 const Cube<eT>& Q = in.m; 01730 01731 const uword in_aux_row1 = in.aux_row1; 01732 const uword in_aux_col1 = in.aux_col1; 01733 const uword in_aux_slice1 = in.aux_slice1; 01734 01735 for(uword i=0; i<in_n_slices; ++i) 01736 { 01737 out_mem[i] /= Q.at(in_aux_row1, in_aux_col1, in_aux_slice1 + i); 01738 } 01739 } 01740 } 01741 } 01742 01743 01744