00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 template<typename eT>
00021 inline
00022 subview<eT>::~subview()
00023 {
00024 arma_extra_debug_sigprint();
00025 }
00026
00027
00028 template<typename eT>
00029 arma_inline
00030 subview<eT>::subview(const Mat<eT>& in_m, const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2)
00031 : m(in_m)
00032 , m_ptr(0)
00033 , aux_row1(in_row1)
00034 , aux_col1(in_col1)
00035 , aux_row2(in_row2)
00036 , aux_col2(in_col2)
00037 , n_rows(1 + in_row2 - in_row1)
00038 , n_cols(1 + in_col2 - in_col1)
00039 , n_elem(n_rows*n_cols)
00040 {
00041 arma_extra_debug_sigprint();
00042 }
00043
00044
00045
00046 template<typename eT>
00047 arma_inline
00048 subview<eT>::subview(Mat<eT>& in_m, const u32 in_row1, const u32 in_col1, const u32 in_row2, const u32 in_col2)
00049 : m(in_m)
00050 , m_ptr(&in_m)
00051 , aux_row1(in_row1)
00052 , aux_col1(in_col1)
00053 , aux_row2(in_row2)
00054 , aux_col2(in_col2)
00055 , n_rows(1 + in_row2 - in_row1)
00056 , n_cols(1 + in_col2 - in_col1)
00057 , n_elem(n_rows*n_cols)
00058 {
00059 arma_extra_debug_sigprint();
00060 }
00061
00062
00063
00064 template<typename eT>
00065 inline
00066 void
00067 subview<eT>::fill(const eT val)
00068 {
00069 arma_extra_debug_sigprint();
00070
00071 for(u32 col = 0; col<n_cols; ++col)
00072 {
00073 eT* coldata = colptr(col);
00074
00075 for(u32 row = 0; row != n_rows; ++row)
00076 {
00077 coldata[row] = val;
00078 }
00079 }
00080
00081
00082 }
00083
00084
00085
00086 template<typename eT>
00087 inline
00088 void
00089 subview<eT>::operator+= (const eT val)
00090 {
00091 arma_extra_debug_sigprint();
00092
00093 for(u32 col = 0; col<n_cols; ++col)
00094 {
00095 eT* coldata = colptr(col);
00096
00097 for(u32 row = 0; row<n_rows; ++row)
00098 {
00099 coldata[row] += val;
00100 }
00101
00102 }
00103
00104 }
00105
00106
00107
00108 template<typename eT>
00109 inline
00110 void
00111 subview<eT>::operator-= (const eT val)
00112 {
00113 arma_extra_debug_sigprint();
00114
00115 for(u32 col = 0; col<n_cols; ++col)
00116 {
00117 eT* coldata = colptr(col);
00118
00119 for(u32 row = 0; row<n_rows; ++row)
00120 {
00121 coldata[row] -= val;
00122 }
00123
00124 }
00125
00126 }
00127
00128
00129
00130 template<typename eT>
00131 inline
00132 void
00133 subview<eT>::operator*= (const eT val)
00134 {
00135 arma_extra_debug_sigprint();
00136
00137 for(u32 col = 0; col<n_cols; ++col)
00138 {
00139 eT* coldata = colptr(col);
00140
00141 for(u32 row = 0; row<n_rows; ++row)
00142 {
00143 coldata[row] *= val;
00144 }
00145
00146 }
00147
00148 }
00149
00150
00151
00152 template<typename eT>
00153 inline
00154 void
00155 subview<eT>::operator/= (const eT val)
00156 {
00157 arma_extra_debug_sigprint();
00158
00159 for(u32 col = 0; col<n_cols; ++col)
00160 {
00161 eT* coldata = colptr(col);
00162
00163 for(u32 row = 0; row<n_rows; ++row)
00164 {
00165 coldata[row] /= val;
00166 }
00167
00168 }
00169
00170 }
00171
00172
00173
00174 template<typename eT>
00175 template<typename T1>
00176 inline
00177 void
00178 subview<eT>::operator= (const Base<eT,T1>& in)
00179 {
00180 arma_extra_debug_sigprint();
00181
00182 const unwrap<T1> tmp(in.get_ref());
00183
00184 const Mat<eT>& x = tmp.M;
00185 subview<eT>& t = *this;
00186
00187 arma_debug_assert_same_size(t, x, "insert into submatrix");
00188
00189
00190 for(u32 col = 0; col<t.n_cols; ++col)
00191 {
00192 eT* t_coldata = t.colptr(col);
00193 const eT* x_coldata = x.colptr(col);
00194
00195 for(u32 row = 0; row<t.n_rows; ++row)
00196 {
00197 t_coldata[row] = x_coldata[row];
00198 }
00199
00200 }
00201 }
00202
00203
00204
00205 template<typename eT>
00206 template<typename T1>
00207 inline
00208 void
00209 subview<eT>::operator+= (const Base<eT,T1>& in)
00210 {
00211 arma_extra_debug_sigprint();
00212
00213 const unwrap<T1> tmp(in.get_ref());
00214
00215 const Mat<eT>& x = tmp.M;
00216 subview<eT>& t = *this;
00217
00218 arma_debug_assert_same_size(t, x, "matrix addition");
00219
00220
00221 for(u32 col = 0; col<t.n_cols; ++col)
00222 {
00223 eT* t_coldata = t.colptr(col);
00224 const eT* x_coldata = x.colptr(col);
00225
00226 for(u32 row = 0; row<t.n_rows; ++row)
00227 {
00228 t_coldata[row] += x_coldata[row];
00229 }
00230 }
00231
00232 }
00233
00234
00235
00236 template<typename eT>
00237 template<typename T1>
00238 inline
00239 void
00240 subview<eT>::operator-= (const Base<eT,T1>& in)
00241 {
00242 arma_extra_debug_sigprint();
00243
00244 const unwrap<T1> tmp(in.get_ref());
00245
00246 const Mat<eT>& x = tmp.M;
00247 subview<eT>& t = *this;
00248
00249 arma_debug_assert_same_size(t, x, "matrix subtraction");
00250
00251
00252 for(u32 col = 0; col<t.n_cols; ++col)
00253 {
00254 eT* t_coldata = t.colptr(col);
00255 const eT* x_coldata = x.colptr(col);
00256
00257 for(u32 row = 0; row<t.n_rows; ++row)
00258 {
00259 t_coldata[row] -= x_coldata[row];
00260 }
00261 }
00262
00263 }
00264
00265
00266
00267 template<typename eT>
00268 template<typename T1>
00269 inline
00270 void
00271 subview<eT>::operator%= (const Base<eT,T1>& in)
00272 {
00273 arma_extra_debug_sigprint();
00274
00275 const unwrap<T1> tmp(in.get_ref());
00276
00277 const Mat<eT>& x = tmp.M;
00278 subview<eT>& t = *this;
00279
00280 arma_debug_assert_same_size(t, x, "matrix schur product");
00281
00282
00283 for(u32 col = 0; col<t.n_cols; ++col)
00284 {
00285 eT* t_coldata = t.colptr(col);
00286 const eT* x_coldata = x.colptr(col);
00287
00288 for(u32 row = 0; row<t.n_rows; ++row)
00289 {
00290 t_coldata[row] *= x_coldata[row];
00291 }
00292 }
00293
00294 }
00295
00296
00297
00298 template<typename eT>
00299 template<typename T1>
00300 inline
00301 void
00302 subview<eT>::operator/= (const Base<eT,T1>& in)
00303 {
00304 arma_extra_debug_sigprint();
00305
00306 const unwrap<T1> tmp(in.get_ref());
00307
00308 const Mat<eT>& x = tmp.M;
00309 subview<eT>& t = *this;
00310
00311 arma_debug_assert_same_size(t, x, "element-wise matrix division");
00312
00313
00314 for(u32 col = 0; col<t.n_cols; ++col)
00315 {
00316 eT* t_coldata = t.colptr(col);
00317 const eT* x_coldata = x.colptr(col);
00318
00319 for(u32 row = 0; row<t.n_rows; ++row)
00320 {
00321 t_coldata[row] /= x_coldata[row];
00322 }
00323 }
00324
00325 }
00326
00327
00328
00329
00330 template<typename eT>
00331 inline
00332 void
00333 subview<eT>::operator= (const subview<eT>& x_in)
00334 {
00335 arma_extra_debug_sigprint();
00336
00337 const bool overlap = check_overlap(x_in);
00338
00339 Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
00340 const subview<eT>* tmp_subview = overlap ? new subview<eT>(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00341 const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
00342
00343 subview<eT>& t = *this;
00344
00345 arma_debug_assert_same_size(t, x, "insert into submatrix");
00346
00347
00348 for(u32 col = 0; col<t.n_cols; ++col)
00349 {
00350 eT* t_coldata = t.colptr(col);
00351 const eT* x_coldata = x.colptr(col);
00352
00353 for(u32 row = 0; row<t.n_rows; ++row)
00354 {
00355 t_coldata[row] = x_coldata[row];
00356 }
00357
00358 }
00359
00360 if(overlap)
00361 {
00362 delete tmp_subview;
00363 delete tmp_mat;
00364 }
00365
00366 }
00367
00368
00369
00370 template<typename eT>
00371 inline
00372 void
00373 subview<eT>::operator+= (const subview<eT>& x_in)
00374 {
00375 arma_extra_debug_sigprint();
00376
00377 const bool overlap = check_overlap(x_in);
00378
00379 Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
00380 const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00381 const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
00382
00383
00384 subview<eT>& t = *this;
00385
00386 arma_debug_assert_same_size(t, x, "matrix addition");
00387
00388
00389 for(u32 col = 0; col<t.n_cols; ++col)
00390 {
00391 eT* t_coldata = t.colptr(col);
00392 const eT* x_coldata = x.colptr(col);
00393
00394 for(u32 row = 0; row<t.n_rows; ++row)
00395 {
00396 t_coldata[row] += x_coldata[row];
00397 }
00398
00399 }
00400
00401 }
00402
00403
00404
00405 template<typename eT>
00406 inline
00407 void
00408 subview<eT>::operator-= (const subview<eT>& x_in)
00409 {
00410 arma_extra_debug_sigprint();
00411
00412 const bool overlap = check_overlap(x_in);
00413
00414 Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
00415 const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00416 const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
00417
00418 subview<eT>& t = *this;
00419
00420 arma_debug_assert_same_size(t, x, "matrix subtraction");
00421
00422
00423 for(u32 col = 0; col<t.n_cols; ++col)
00424 {
00425 eT* t_coldata = t.colptr(col);
00426 const eT* x_coldata = x.colptr(col);
00427
00428 for(u32 row = 0; row<t.n_rows; ++row)
00429 {
00430 t_coldata[row] -= x_coldata[row];
00431 }
00432
00433 }
00434
00435 }
00436
00437
00438
00439 template<typename eT>
00440 inline
00441 void
00442 subview<eT>::operator%= (const subview& x_in)
00443 {
00444 arma_extra_debug_sigprint();
00445
00446 const bool overlap = check_overlap(x_in);
00447
00448 Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
00449 const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00450 const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
00451
00452 subview<eT>& t = *this;
00453
00454 arma_debug_assert_same_size(t, x, "matrix schur product");
00455
00456
00457 for(u32 col = 0; col<t.n_cols; ++col)
00458 {
00459 eT* t_coldata = t.colptr(col);
00460 const eT* x_coldata = x.colptr(col);
00461
00462 for(u32 row = 0; row<t.n_rows; ++row)
00463 {
00464 t_coldata[row] *= x_coldata[row];
00465 }
00466
00467 }
00468
00469 }
00470
00471
00472
00473 template<typename eT>
00474 inline
00475 void
00476 subview<eT>::operator/= (const subview& x_in)
00477 {
00478 arma_extra_debug_sigprint();
00479
00480 const bool overlap = check_overlap(x_in);
00481
00482 Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0;
00483 const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.aux_row2, x_in.aux_col2) : 0;
00484 const subview<eT>& x = overlap ? (*tmp_subview) : x_in;
00485
00486 subview<eT>& t = *this;
00487
00488 arma_debug_assert_same_size(t, x, "element-wise matrix division");
00489
00490
00491 for(u32 col = 0; col<t.n_cols; ++col)
00492 {
00493 eT* t_coldata = t.colptr(col);
00494 const eT* x_coldata = x.colptr(col);
00495
00496 for(u32 row = 0; row<t.n_rows; ++row)
00497 {
00498 t_coldata[row] /= x_coldata[row];
00499 }
00500
00501 }
00502
00503 }
00504
00505
00506
00507 template<typename eT>
00508 inline
00509 void
00510 subview<eT>::zeros()
00511 {
00512 arma_extra_debug_sigprint();
00513
00514 subview<eT>& t = *this;
00515
00516 for(u32 col = 0; col<t.n_cols; ++col)
00517 {
00518 eT* t_coldata = t.colptr(col);
00519
00520 for(u32 row = 0; row<t.n_rows; ++row)
00521 {
00522 t_coldata[row] = eT(0);
00523 }
00524
00525 }
00526
00527 }
00528
00529
00530
00531 template<typename eT>
00532 arma_inline
00533 eT&
00534 subview<eT>::operator[](const u32 i)
00535 {
00536 arma_check( (m_ptr == 0), "subview::operator[]: matrix is read-only");
00537
00538 const u32 in_col = i / n_rows;
00539 const u32 in_row = i % n_rows;
00540
00541 const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00542 return access::rw( (*m_ptr).mem[index] );
00543 }
00544
00545
00546
00547 template<typename eT>
00548 arma_inline
00549 eT
00550 subview<eT>::operator[](const u32 i) const
00551 {
00552 const u32 in_col = i / n_rows;
00553 const u32 in_row = i % n_rows;
00554
00555 const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00556 return m.mem[index];
00557 }
00558
00559
00560
00561 template<typename eT>
00562 arma_inline
00563 eT&
00564 subview<eT>::operator()(const u32 i)
00565 {
00566 arma_check( (m_ptr == 0), "subview::operator(): matrix is read-only");
00567 arma_debug_check( (i >= n_elem), "subview::operator(): index out of bounds");
00568
00569 const u32 in_col = i / n_rows;
00570 const u32 in_row = i % n_rows;
00571
00572 const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00573 return access::rw( (*m_ptr).mem[index] );
00574 }
00575
00576
00577
00578 template<typename eT>
00579 arma_inline
00580 eT
00581 subview<eT>::operator()(const u32 i) const
00582 {
00583 arma_debug_check( (i >= n_elem), "subview::operator(): index out of bounds");
00584
00585 const u32 in_col = i / n_rows;
00586 const u32 in_row = i % n_rows;
00587
00588 const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00589 return m.mem[index];
00590 }
00591
00592
00593
00594 template<typename eT>
00595 arma_inline
00596 eT&
00597 subview<eT>::operator()(const u32 in_row, const u32 in_col)
00598 {
00599 arma_check( (m_ptr == 0), "subview::operator(): matrix is read-only");
00600 arma_debug_check( ( (n_elem == 0) || (in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds");
00601
00602 const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00603 return access::rw( (*m_ptr).mem[index] );
00604 }
00605
00606
00607
00608 template<typename eT>
00609 arma_inline
00610 eT
00611 subview<eT>::operator()(const u32 in_row, const u32 in_col) const
00612 {
00613 arma_debug_check( ( (n_elem == 0) || (in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds");
00614
00615 const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00616 return m.mem[index];
00617 }
00618
00619
00620
00621 template<typename eT>
00622 arma_inline
00623 eT&
00624 subview<eT>::at(const u32 in_row, const u32 in_col)
00625 {
00626 arma_check( (m_ptr == 0), "subview::at(): matrix is read-only");
00627
00628 const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00629 return access::rw( (*m_ptr).mem[index] );
00630 }
00631
00632
00633
00634 template<typename eT>
00635 arma_inline
00636 eT
00637 subview<eT>::at(const u32 in_row, const u32 in_col) const
00638 {
00639 const u32 index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row;
00640 return m.mem[index];
00641 }
00642
00643
00644
00645 template<typename eT>
00646 arma_inline
00647 eT*
00648 subview<eT>::colptr(const u32 in_col)
00649 {
00650 arma_check( (m_ptr == 0), "subview::colptr(): matrix is read-only");
00651
00652 return & access::rw((*m_ptr).mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]);
00653 }
00654
00655
00656
00657 template<typename eT>
00658 arma_inline
00659 const eT*
00660 subview<eT>::colptr(const u32 in_col) const
00661 {
00662 return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ];
00663 }
00664
00665
00666
00667 template<typename eT>
00668 inline
00669 bool
00670 subview<eT>::check_overlap(const subview<eT>& x) const
00671 {
00672 const subview<eT>& t = *this;
00673
00674 if(&t.m != &x.m)
00675 {
00676 return false;
00677 }
00678 else
00679 {
00680 const bool row_overlap =
00681 (
00682 ( (x.aux_row1 >= t.aux_row1) && (x.aux_row1 <= t.aux_row2) )
00683 ||
00684 ( (x.aux_row2 >= t.aux_row1) && (x.aux_row2 <= t.aux_row2) )
00685 );
00686
00687 const bool col_overlap =
00688 (
00689 ( (x.aux_col1 >= t.aux_col1) && (x.aux_col1 <= t.aux_col2) )
00690 ||
00691 ( (x.aux_col2 >= t.aux_col1) && (x.aux_col2 <= t.aux_col2) )
00692 );
00693
00694
00695 return (row_overlap & col_overlap);
00696 }
00697 }
00698
00699
00700
00701
00702 template<typename eT>
00703 inline
00704 void
00705 subview<eT>::extract(Mat<eT>& actual_out, const subview<eT>& in)
00706 {
00707 arma_extra_debug_sigprint();
00708
00709
00710 const bool alias = (&actual_out == &in.m);
00711
00712 Mat<eT>* tmp = (alias) ? new Mat<eT> : 0;
00713 Mat<eT>& out = (alias) ? (*tmp) : actual_out;
00714
00715
00716
00717 const u32 n_rows = in.n_rows;
00718 const u32 n_cols = in.n_cols;
00719
00720 out.set_size(n_rows, n_cols);
00721
00722 arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols = %d in.m.n_rows = %d in.m.n_cols = %d") % out.n_rows % out.n_cols % in.m.n_rows % in.m.n_cols );
00723
00724
00725 if((n_rows == 1) && (n_cols != 1))
00726 {
00727 arma_extra_debug_print("subview::apply(): copying row (going across columns)");
00728
00729 for(u32 col = 0; col<n_cols; ++col)
00730 {
00731 out[col] = in.m.at(in.aux_row1, col);
00732 }
00733 }
00734 else
00735 if((n_rows != 1) && (n_cols == 1))
00736 {
00737 arma_extra_debug_print("subview::apply(): copying col (going across n_rows)");
00738
00739 const eT* in_coldata = in.colptr(0);
00740
00741 for(u32 row = 0; row<n_rows; ++row)
00742 {
00743 out[row] = in_coldata[row];
00744 }
00745
00746 }
00747 else
00748 for(u32 col = 0; col<n_cols; ++col)
00749 {
00750 eT* out_coldata = out.colptr(col);
00751 const eT* in_coldata = in.colptr(col);
00752
00753 for(u32 row = 0; row<n_rows; ++row)
00754 {
00755 out_coldata[row] = in_coldata[row];
00756 }
00757
00758 }
00759
00760
00761 if(alias)
00762 {
00763 actual_out = out;
00764 delete tmp;
00765 }
00766
00767 }
00768
00769
00770
00771
00772 template<typename eT>
00773 inline
00774 void
00775 subview<eT>::plus_inplace(Mat<eT>& out, const subview<eT>& in)
00776 {
00777 arma_extra_debug_sigprint();
00778
00779 arma_debug_assert_same_size(out, in, "matrix addition");
00780
00781 if(&out != &in.m)
00782 {
00783 const u32 n_rows = out.n_rows;
00784 const u32 n_cols = out.n_cols;
00785
00786 for(u32 col = 0; col<n_cols; ++col)
00787 {
00788 eT* out_coldata = out.colptr(col);
00789 const eT* in_coldata = in.colptr(col);
00790
00791 for(u32 row = 0; row<n_rows; ++row)
00792 {
00793 out_coldata[row] += in_coldata[row];
00794 }
00795 }
00796 }
00797 else
00798 {
00799
00800
00801
00802 eT* out_mem = out.memptr();
00803
00804 for(u32 i=0; i<out.n_elem; ++i)
00805 {
00806 out_mem[i] *= eT(2);
00807 }
00808 }
00809
00810 }
00811
00812
00813
00814
00815 template<typename eT>
00816 inline
00817 void
00818 subview<eT>::minus_inplace(Mat<eT>& out, const subview<eT>& in)
00819 {
00820 arma_extra_debug_sigprint();
00821
00822 arma_debug_assert_same_size(out, in, "matrix subtraction");
00823
00824 if(&out != &in.m)
00825 {
00826 const u32 n_rows = out.n_rows;
00827 const u32 n_cols = out.n_cols;
00828
00829 for(u32 col = 0; col<n_cols; ++col)
00830 {
00831 eT* out_coldata = out.colptr(col);
00832 const eT* in_coldata = in.colptr(col);
00833
00834 for(u32 row = 0; row<n_rows; ++row)
00835 {
00836 out_coldata[row] -= in_coldata[row];
00837 }
00838 }
00839 }
00840 else
00841 {
00842 out.zeros();
00843 }
00844
00845 }
00846
00847
00848
00849
00850 template<typename eT>
00851 inline
00852 void
00853 subview<eT>::times_inplace(Mat<eT>& out, const subview<eT>& in)
00854 {
00855 arma_extra_debug_sigprint();
00856
00857 arma_debug_assert_mul_size(out, in, "matrix multiply");
00858
00859 if(&out != &in.m)
00860 {
00861 glue_times::apply_inplace(out, Mat<eT>(in));
00862 }
00863 else
00864 {
00865 glue_times::apply_inplace(out, out);
00866 }
00867
00868 }
00869
00870
00871
00872
00873 template<typename eT>
00874 inline
00875 void
00876 subview<eT>::schur_inplace(Mat<eT>& out, const subview<eT>& in)
00877 {
00878 arma_extra_debug_sigprint();
00879
00880 arma_debug_assert_same_size(out, in, "matrix schur product");
00881
00882 if(&out != &in.m)
00883 {
00884 const u32 n_rows = out.n_rows;
00885 const u32 n_cols = out.n_cols;
00886
00887 for(u32 col = 0; col<n_cols; ++col)
00888 {
00889 eT* out_coldata = out.colptr(col);
00890 const eT* in_coldata = in.colptr(col);
00891
00892 for(u32 row = 0; row<n_rows; ++row)
00893 {
00894 out_coldata[row] *= in_coldata[row];
00895 }
00896 }
00897 }
00898 else
00899 {
00900 eT* out_mem = out.memptr();
00901
00902 for(u32 i=0; i<out.n_elem; ++i)
00903 {
00904 const eT tmp = out_mem[i];
00905 out_mem[i] = tmp*tmp;
00906 }
00907 }
00908
00909 }
00910
00911
00912
00913
00914 template<typename eT>
00915 inline
00916 void
00917 subview<eT>::div_inplace(Mat<eT>& out, const subview<eT>& in)
00918 {
00919 arma_extra_debug_sigprint();
00920
00921 arma_debug_assert_same_size(out, in, "element-wise matrix division");
00922
00923 if(&out != &in.m)
00924 {
00925 const u32 n_rows = out.n_rows;
00926 const u32 n_cols = out.n_cols;
00927
00928 for(u32 col = 0; col<n_cols; ++col)
00929 {
00930 eT* out_coldata = out.colptr(col);
00931 const eT* in_coldata = in.colptr(col);
00932
00933 for(u32 row = 0; row<n_rows; ++row)
00934 {
00935 out_coldata[row] /= in_coldata[row];
00936 }
00937 }
00938 }
00939 else
00940 {
00941 eT* out_mem = out.memptr();
00942
00943 for(u32 i=0; i<out.n_elem; ++i)
00944 {
00945 const eT tmp = out_mem[i];
00946 out_mem[i] = tmp*tmp;
00947 }
00948 }
00949
00950 }
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960 template<typename eT>
00961 arma_inline
00962 subview_col<eT>::subview_col(const Mat<eT>& in_m, const u32 in_col)
00963 : subview<eT>(in_m, 0, in_col, in_m.n_rows-1, in_col)
00964 {
00965 arma_extra_debug_sigprint();
00966 }
00967
00968
00969
00970 template<typename eT>
00971 arma_inline
00972 subview_col<eT>::subview_col(Mat<eT>& in_m, const u32 in_col)
00973 : subview<eT>(in_m, 0, in_col, in_m.n_rows-1, in_col)
00974 {
00975 arma_extra_debug_sigprint();
00976 }
00977
00978
00979
00980 template<typename eT>
00981 inline
00982 void
00983 subview_col<eT>::operator=(const subview<eT>& X)
00984 {
00985 arma_extra_debug_sigprint();
00986
00987 subview<eT>::operator=(X);
00988 arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
00989 }
00990
00991
00992
00993 template<typename eT>
00994 inline
00995 void
00996 subview_col<eT>::operator=(const subview_col<eT>& X)
00997 {
00998 arma_extra_debug_sigprint();
00999
01000 subview<eT>::operator=(X);
01001 arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
01002 }
01003
01004
01005
01006 template<typename eT>
01007 template<typename T1>
01008 inline
01009 void
01010 subview_col<eT>::operator=(const Base<eT,T1>& X)
01011 {
01012 arma_extra_debug_sigprint();
01013
01014 subview<eT>::operator=(X);
01015 arma_debug_check( (subview<eT>::n_cols > 1), "subview_col(): incompatible dimensions" );
01016 }
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027 template<typename eT>
01028 arma_inline
01029 subview_row<eT>::subview_row(const Mat<eT>& in_m, const u32 in_row)
01030 : subview<eT>(in_m, in_row, 0, in_row, in_m.n_cols-1)
01031 {
01032 arma_extra_debug_sigprint();
01033 }
01034
01035
01036
01037 template<typename eT>
01038 arma_inline
01039 subview_row<eT>::subview_row(Mat<eT>& in_m, const u32 in_row)
01040 : subview<eT>(in_m, in_row, 0, in_row, in_m.n_cols-1)
01041 {
01042 arma_extra_debug_sigprint();
01043 }
01044
01045
01046
01047 template<typename eT>
01048 inline
01049 void
01050 subview_row<eT>::operator=(const subview<eT>& X)
01051 {
01052 arma_extra_debug_sigprint();
01053
01054 subview<eT>::operator=(X);
01055 arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
01056 }
01057
01058
01059
01060 template<typename eT>
01061 inline
01062 void
01063 subview_row<eT>::operator=(const subview_row<eT>& X)
01064 {
01065 arma_extra_debug_sigprint();
01066
01067 subview<eT>::operator=(X);
01068 arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
01069 }
01070
01071
01072
01073 template<typename eT>
01074 template<typename T1>
01075 inline
01076 void
01077 subview_row<eT>::operator=(const Base<eT,T1>& X)
01078 {
01079 arma_extra_debug_sigprint();
01080
01081 subview<eT>::operator=(X);
01082 arma_debug_check( (subview<eT>::n_rows > 1), "subview_row(): incompatible dimensions" );
01083 }
01084
01085
01086
01087