diff --git a/include/armadillo_bits/subview_bones.hpp b/include/armadillo_bits/subview_bones.hpp index 68f51004..30cbc933 100644 --- a/include/armadillo_bits/subview_bones.hpp +++ b/include/armadillo_bits/subview_bones.hpp @@ -400,6 +400,8 @@ class subview_col : public subview inline void fill(const eT val); inline void zeros(); inline void ones(); + inline void randu(); + inline void randn(); arma_warn_unused inline bool is_finite() const; arma_warn_unused inline bool is_zero(const pod_type tol = 0) const; @@ -563,6 +565,8 @@ class subview_row : public subview inline void fill(const eT val); inline void zeros(); inline void ones(); + inline void randu(); + inline void randn(); arma_warn_unused inline bool is_finite() const; arma_warn_unused inline bool is_zero(const pod_type tol = 0) const; diff --git a/include/armadillo_bits/subview_meat.hpp b/include/armadillo_bits/subview_meat.hpp index 2d3fd487..c09e9f56 100644 --- a/include/armadillo_bits/subview_meat.hpp +++ b/include/armadillo_bits/subview_meat.hpp @@ -1151,30 +1151,17 @@ subview::randu() const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; - if( (s_n_rows == 0) || (s_n_cols == 0) ) { return; } + if(s_n_rows == 0) { return; } - if(s_n_rows == 1) + if( (s.aux_row1 == 0) && (s_n_rows == s.m.n_rows) ) { - podarray tmp(s_n_cols); - - eT* tmp_mem = tmp.memptr(); - - arma_rng::randu::fill( tmp_mem, s_n_cols ); - - for(uword ii=0; ii < s_n_cols; ++ii) { at(0,ii) = tmp_mem[ii]; } + arma_rng::randu::fill( s.colptr(0), s.n_elem ); } else { - if( (s.aux_row1 == 0) && (s_n_rows == s.m.n_rows) ) + for(uword ii=0; ii < s_n_cols; ++ii) { - arma_rng::randu::fill( s.colptr(0), s.n_elem ); - } - else - { - for(uword ii=0; ii < s_n_cols; ++ii) - { - arma_rng::randu::fill( s.colptr(ii), s_n_rows ); - } + arma_rng::randu::fill( s.colptr(ii), s_n_rows ); } } } @@ -1193,30 +1180,17 @@ subview::randn() const uword s_n_rows = s.n_rows; const uword s_n_cols = s.n_cols; - if( (s_n_rows == 0) || (s_n_cols == 0) ) { return; } + if(s_n_rows == 0) { return; } - if(s_n_rows == 1) + if( (s.aux_row1 == 0) && (s_n_rows == s.m.n_rows) ) { - podarray tmp(s_n_cols); - - eT* tmp_mem = tmp.memptr(); - - arma_rng::randn::fill( tmp_mem, s_n_cols ); - - for(uword ii=0; ii < s_n_cols; ++ii) { at(0,ii) = tmp_mem[ii]; } + arma_rng::randn::fill( s.colptr(0), s.n_elem ); } else { - if( (s.aux_row1 == 0) && (s_n_rows == s.m.n_rows) ) + for(uword ii=0; ii < s_n_cols; ++ii) { - arma_rng::randn::fill( s.colptr(0), s.n_elem ); - } - else - { - for(uword ii=0; ii < s_n_cols; ++ii) - { - arma_rng::randn::fill( s.colptr(ii), s_n_rows ); - } + arma_rng::randn::fill( s.colptr(ii), s_n_rows ); } } } @@ -3561,6 +3535,30 @@ subview_col::ones() +template +inline +void +subview_col::randu() + { + arma_debug_sigprint(); + + arma_rng::randu::fill( access::rwp(colmem), subview::n_rows ); + } + + + +template +inline +void +subview_col::randn() + { + arma_debug_sigprint(); + + arma_rng::randn::fill( access::rwp(colmem), subview::n_rows ); + } + + + template inline bool @@ -4650,6 +4648,58 @@ subview_row::ones() +template +inline +void +subview_row::randu() + { + arma_debug_sigprint(); + + const uword local_s_n_cols = subview::n_cols; + const uword local_m_n_rows = subview::m.n_rows; + + podarray tmp(local_s_n_cols); + + eT* tmp_mem = tmp.memptr(); + + arma_rng::randu::fill( tmp_mem, local_s_n_cols ); + + eT* mem_ptr = access::rwp(rowmem); + + for(uword ii=0; ii < local_s_n_cols; ++ii) + { + (*mem_ptr) = tmp_mem[ii]; mem_ptr += local_m_n_rows; + } + } + + + +template +inline +void +subview_row::randn() + { + arma_debug_sigprint(); + + const uword local_s_n_cols = subview::n_cols; + const uword local_m_n_rows = subview::m.n_rows; + + podarray tmp(local_s_n_cols); + + eT* tmp_mem = tmp.memptr(); + + arma_rng::randn::fill( tmp_mem, local_s_n_cols ); + + eT* mem_ptr = access::rwp(rowmem); + + for(uword ii=0; ii < local_s_n_cols; ++ii) + { + (*mem_ptr) = tmp_mem[ii]; mem_ptr += local_m_n_rows; + } + } + + + template inline bool