inline void subview_elem2<eT,T1,T2>::extract(Mat<eT>& actual_out, const subview_elem2<eT,T1,T2>& in) { arma_extra_debug_sigprint(); Mat<eT>& m_local = const_cast< Mat<eT>& >(in.m); const uword m_n_rows = m_local.n_rows; const uword m_n_cols = m_local.n_cols; const bool alias = (&actual_out == &m_local); arma_extra_debug_warn(alias, "subview_elem2::extract(): aliasing detected"); Mat<eT>* tmp_out = alias ? new Mat<eT>() : 0; Mat<eT>& out = alias ? *tmp_out : actual_out; if( (in.all_rows == false) && (in.all_cols == false) ) { const unwrap_check_mixed<T1> tmp1(in.base_ri.get_ref(), actual_out); const unwrap_check_mixed<T2> tmp2(in.base_ci.get_ref(), actual_out); const umat& ri = tmp1.M; const umat& ci = tmp2.M; arma_debug_check ( ( ri.is_vec() == false ) || ( ci.is_vec() == false ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; out.set_size(ri_n_elem, ci_n_elem); eT* out_mem = out.memptr(); uword out_count = 0; for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col > m_n_cols), "Mat::elem(): index out of bounds" ); for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row > m_n_rows), "Mat::elem(): index out of bounds" ); out_mem[out_count] = m_local.at(row,col); ++out_count; } } } else if( (in.all_rows == true) && (in.all_cols == false) ) { const unwrap_check_mixed<T2> tmp2(in.base_ci.get_ref(), m_local); const umat& ci = tmp2.M; arma_debug_check ( ( ci.is_vec() == false ), "Mat::elem(): given object is not a vector" ); const uword* ci_mem = ci.memptr(); const uword ci_n_elem = ci.n_elem; out.set_size(m_n_rows, ci_n_elem); for(uword ci_count=0; ci_count < ci_n_elem; ++ci_count) { const uword col = ci_mem[ci_count]; arma_debug_check( (col > m_n_cols), "Mat::elem(): index out of bounds" ); arrayops::copy( out.colptr(ci_count), m_local.colptr(col), m_n_rows ); } } else if( (in.all_rows == false) && (in.all_cols == true) ) { const unwrap_check_mixed<T1> tmp1(in.base_ri.get_ref(), m_local); const umat& ri = tmp1.M; arma_debug_check ( ( ri.is_vec() == false ), "Mat::elem(): given object is not a vector" ); const uword* ri_mem = ri.memptr(); const uword ri_n_elem = ri.n_elem; out.set_size(ri_n_elem, m_n_cols); for(uword col=0; col < m_n_cols; ++col) { for(uword ri_count=0; ri_count < ri_n_elem; ++ri_count) { const uword row = ri_mem[ri_count]; arma_debug_check( (row > m_n_rows), "Mat::elem(): index out of bounds" ); out.at(ri_count,col) = m_local.at(row,col); } } } if(alias) { actual_out.steal_mem(out); delete tmp_out; } }
inline void subview_elem1<eT,T1>::extract(Mat<eT>& actual_out, const subview_elem1<eT,T1>& in) { arma_extra_debug_sigprint(); const unwrap_check_mixed<T1> tmp1(in.a.get_ref(), actual_out); const umat& aa = tmp1.M; arma_debug_check ( ( (aa.is_vec() == false) && (aa.is_empty() == false) ), "Mat::elem(): given object is not a vector" ); const uword* aa_mem = aa.memptr(); const uword aa_n_elem = aa.n_elem; const Mat<eT>& m_local = in.m; const eT* m_mem = m_local.memptr(); const uword m_n_elem = m_local.n_elem; const bool alias = (&actual_out == &m_local); arma_extra_debug_warn(alias, "subview_elem1::extract(): aliasing detected"); Mat<eT>* tmp_out = alias ? new Mat<eT>() : 0; Mat<eT>& out = alias ? *tmp_out : actual_out; out.set_size(aa_n_elem, 1); eT* out_mem = out.memptr(); uword i,j; for(i=0, j=1; j<aa_n_elem; i+=2, j+=2) { const uword ii = aa_mem[i]; const uword jj = aa_mem[j]; arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(): index out of bounds" ); out_mem[i] = m_mem[ii]; out_mem[j] = m_mem[jj]; } if(i < aa_n_elem) { const uword ii = aa_mem[i]; arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds" ); out_mem[i] = m_mem[ii]; } if(alias == true) { actual_out.steal_mem(out); delete tmp_out; } }
inline void diagview<eT>::operator/=(const Base<eT,T1>& o) { arma_extra_debug_sigprint(); diagview<eT>& d = *this; Mat<eT>& d_m = const_cast< Mat<eT>& >(d.m); const uword d_n_elem = d.n_elem; const uword d_row_offset = d.row_offset; const uword d_col_offset = d.col_offset; const Proxy<T1> P( o.get_ref() ); arma_debug_check ( ( (d_n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_cols() != 1)) ), "diagview: given object has incompatible size" ); const bool is_alias = P.is_alias(d_m); arma_extra_debug_warn(is_alias, "aliasing detected"); if( (is_Mat<typename Proxy<T1>::stored_type>::value) || (Proxy<T1>::prefer_at_accessor) || (is_alias) ) { const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); const Mat<eT>& x = tmp.M; const eT* x_mem = x.memptr(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = x_mem[ii]; const eT tmp_j = x_mem[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) /= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) /= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) /= x_mem[ii]; } } else { typename Proxy<T1>::ea_type Pea = P.get_ea(); uword ii,jj; for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) { const eT tmp_i = Pea[ii]; const eT tmp_j = Pea[jj]; d_m.at( ii + d_row_offset, ii + d_col_offset) /= tmp_i; d_m.at( jj + d_row_offset, jj + d_col_offset) /= tmp_j; } if(ii < d_n_elem) { d_m.at( ii + d_row_offset, ii + d_col_offset) /= Pea[ii]; } } }