| diagview_meat.hpp | | diagview_meat.hpp | |
| | | | |
| skipping to change at line 64 | | skipping to change at line 64 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| diagview<eT>& t = *this; | | diagview<eT>& t = *this; | |
| | | | |
| arma_debug_check( (t.n_elem != x.n_elem), "diagview: diagonals have incom
patible lengths"); | | arma_debug_check( (t.n_elem != x.n_elem), "diagview: diagonals have incom
patible lengths"); | |
| | | | |
| Mat<eT>& t_m = *(t.m_ptr); | | Mat<eT>& t_m = *(t.m_ptr); | |
| const Mat<eT>& x_m = x.m; | | const Mat<eT>& x_m = x.m; | |
| | | | |
|
| const uword t_n_elem = t.n_elem; | | if(&t_m != &x_m) | |
| const uword t_row_offset = t.row_offset; | | { | |
| const uword t_col_offset = t.col_offset; | | const uword t_n_elem = t.n_elem; | |
| | | const uword t_row_offset = t.row_offset; | |
| | | const uword t_col_offset = t.col_offset; | |
| | | | |
|
| const uword x_row_offset = x.row_offset; | | const uword x_row_offset = x.row_offset; | |
| const uword x_col_offset = x.col_offset; | | const uword x_col_offset = x.col_offset; | |
| | | | |
|
| for(uword i=0; i<t_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | |
| | | { | |
| | | const eT tmp_i = x_m.at(i + x_row_offset, i + x_col_offset); | |
| | | const eT tmp_j = x_m.at(j + x_row_offset, j + x_col_offset); | |
| | | | |
| | | t_m.at(i + t_row_offset, i + t_col_offset) = tmp_i; | |
| | | t_m.at(j + t_row_offset, j + t_col_offset) = tmp_j; | |
| | | } | |
| | | | |
| | | if(i < t_n_elem) | |
| | | { | |
| | | t_m.at(i + t_row_offset, i + t_col_offset) = x_m.at(i + x_row_offset, | |
| | | i + x_col_offset); | |
| | | } | |
| | | } | |
| | | else | |
| { | | { | |
|
| t_m.at(i + t_row_offset, i + t_col_offset) = x_m.at(i + x_row_offset, i | | const Mat<eT> tmp = x; | |
| + x_col_offset); | | | |
| | | (*this).operator=(tmp); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::operator+=(const eT val) | | diagview<eT>::operator+=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 181 | | skipping to change at line 200 | |
| ); | | ); | |
| | | | |
| Mat<eT>& t_m = *(t.m_ptr); | | Mat<eT>& t_m = *(t.m_ptr); | |
| | | | |
| const uword t_n_elem = t.n_elem; | | const uword t_n_elem = t.n_elem; | |
| const uword t_row_offset = t.row_offset; | | const uword t_row_offset = t.row_offset; | |
| const uword t_col_offset = t.col_offset; | | const uword t_col_offset = t.col_offset; | |
| | | | |
| const eT* x_mem = x.memptr(); | | const eT* x_mem = x.memptr(); | |
| | | | |
|
| for(uword i=0; i<t_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | |
| | | { | |
| | | const eT tmp_i = x_mem[i]; | |
| | | const eT tmp_j = x_mem[j]; | |
| | | | |
| | | t_m.at( i + t_row_offset, i + t_col_offset) = tmp_i; | |
| | | t_m.at( j + t_row_offset, j + t_col_offset) = tmp_j; | |
| | | } | |
| | | | |
| | | if(i < t_n_elem) | |
| { | | { | |
| t_m.at( i + t_row_offset, i + t_col_offset) = x_mem[i]; | | t_m.at( i + t_row_offset, i + t_col_offset) = x_mem[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::operator+=(const Base<eT,T1>& o) | | diagview<eT>::operator+=(const Base<eT,T1>& o) | |
| | | | |
| skipping to change at line 214 | | skipping to change at line 243 | |
| ); | | ); | |
| | | | |
| Mat<eT>& t_m = *(t.m_ptr); | | Mat<eT>& t_m = *(t.m_ptr); | |
| | | | |
| const uword t_n_elem = t.n_elem; | | const uword t_n_elem = t.n_elem; | |
| const uword t_row_offset = t.row_offset; | | const uword t_row_offset = t.row_offset; | |
| const uword t_col_offset = t.col_offset; | | const uword t_col_offset = t.col_offset; | |
| | | | |
| const eT* x_mem = x.memptr(); | | const eT* x_mem = x.memptr(); | |
| | | | |
|
| for(uword i=0; i<t_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | |
| | | { | |
| | | const eT tmp_i = x_mem[i]; | |
| | | const eT tmp_j = x_mem[j]; | |
| | | | |
| | | t_m.at( i + t_row_offset, i + t_col_offset) += tmp_i; | |
| | | t_m.at( j + t_row_offset, j + t_col_offset) += tmp_j; | |
| | | } | |
| | | | |
| | | if(i < t_n_elem) | |
| { | | { | |
| t_m.at( i + t_row_offset, i + t_col_offset) += x_mem[i]; | | t_m.at( i + t_row_offset, i + t_col_offset) += x_mem[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::operator-=(const Base<eT,T1>& o) | | diagview<eT>::operator-=(const Base<eT,T1>& o) | |
| | | | |
| skipping to change at line 247 | | skipping to change at line 286 | |
| ); | | ); | |
| | | | |
| Mat<eT>& t_m = *(t.m_ptr); | | Mat<eT>& t_m = *(t.m_ptr); | |
| | | | |
| const uword t_n_elem = t.n_elem; | | const uword t_n_elem = t.n_elem; | |
| const uword t_row_offset = t.row_offset; | | const uword t_row_offset = t.row_offset; | |
| const uword t_col_offset = t.col_offset; | | const uword t_col_offset = t.col_offset; | |
| | | | |
| const eT* x_mem = x.memptr(); | | const eT* x_mem = x.memptr(); | |
| | | | |
|
| for(uword i=0; i<t_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | |
| | | { | |
| | | const eT tmp_i = x_mem[i]; | |
| | | const eT tmp_j = x_mem[j]; | |
| | | | |
| | | t_m.at( i + t_row_offset, i + t_col_offset) -= tmp_i; | |
| | | t_m.at( j + t_row_offset, j + t_col_offset) -= tmp_j; | |
| | | } | |
| | | | |
| | | if(i < t_n_elem) | |
| { | | { | |
| t_m.at( i + t_row_offset, i + t_col_offset) -= x_mem[i]; | | t_m.at( i + t_row_offset, i + t_col_offset) -= x_mem[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::operator%=(const Base<eT,T1>& o) | | diagview<eT>::operator%=(const Base<eT,T1>& o) | |
| | | | |
| skipping to change at line 280 | | skipping to change at line 329 | |
| ); | | ); | |
| | | | |
| Mat<eT>& t_m = *(t.m_ptr); | | Mat<eT>& t_m = *(t.m_ptr); | |
| | | | |
| const uword t_n_elem = t.n_elem; | | const uword t_n_elem = t.n_elem; | |
| const uword t_row_offset = t.row_offset; | | const uword t_row_offset = t.row_offset; | |
| const uword t_col_offset = t.col_offset; | | const uword t_col_offset = t.col_offset; | |
| | | | |
| const eT* x_mem = x.memptr(); | | const eT* x_mem = x.memptr(); | |
| | | | |
|
| for(uword i=0; i<t_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | |
| | | { | |
| | | const eT tmp_i = x_mem[i]; | |
| | | const eT tmp_j = x_mem[j]; | |
| | | | |
| | | t_m.at( i + t_row_offset, i + t_col_offset) *= tmp_i; | |
| | | t_m.at( j + t_row_offset, j + t_col_offset) *= tmp_j; | |
| | | } | |
| | | | |
| | | if(i < t_n_elem) | |
| { | | { | |
| t_m.at( i + t_row_offset, i + t_col_offset) *= x_mem[i]; | | t_m.at( i + t_row_offset, i + t_col_offset) *= x_mem[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::operator/=(const Base<eT,T1>& o) | | diagview<eT>::operator/=(const Base<eT,T1>& o) | |
| | | | |
| skipping to change at line 313 | | skipping to change at line 372 | |
| ); | | ); | |
| | | | |
| Mat<eT>& t_m = *(t.m_ptr); | | Mat<eT>& t_m = *(t.m_ptr); | |
| | | | |
| const uword t_n_elem = t.n_elem; | | const uword t_n_elem = t.n_elem; | |
| const uword t_row_offset = t.row_offset; | | const uword t_row_offset = t.row_offset; | |
| const uword t_col_offset = t.col_offset; | | const uword t_col_offset = t.col_offset; | |
| | | | |
| const eT* x_mem = x.memptr(); | | const eT* x_mem = x.memptr(); | |
| | | | |
|
| for(uword i=0; i<t_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | |
| | | { | |
| | | const eT tmp_i = x_mem[i]; | |
| | | const eT tmp_j = x_mem[j]; | |
| | | | |
| | | t_m.at( i + t_row_offset, i + t_col_offset) /= tmp_i; | |
| | | t_m.at( j + t_row_offset, j + t_col_offset) /= tmp_j; | |
| | | } | |
| | | | |
| | | if(i < t_n_elem) | |
| { | | { | |
| t_m.at( i + t_row_offset, i + t_col_offset) /= x_mem[i]; | | t_m.at( i + t_row_offset, i + t_col_offset) /= x_mem[i]; | |
| } | | } | |
| } | | } | |
| | | | |
| //! extract a diagonal and store it as a column vector | | //! extract a diagonal and store it as a column vector | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::extract(Mat<eT>& out, const diagview<eT>& in) | | diagview<eT>::extract(Mat<eT>& out, const diagview<eT>& in) | |
| | | | |
| skipping to change at line 338 | | skipping to change at line 407 | |
| // size setting and alias checking is done by either the Mat contructor o
r operator=() | | // size setting and alias checking is done by either the Mat contructor o
r operator=() | |
| | | | |
| const Mat<eT>& in_m = in.m; | | const Mat<eT>& in_m = in.m; | |
| | | | |
| const uword in_n_elem = in.n_elem; | | const uword in_n_elem = in.n_elem; | |
| const uword in_row_offset = in.row_offset; | | const uword in_row_offset = in.row_offset; | |
| const uword in_col_offset = in.col_offset; | | const uword in_col_offset = in.col_offset; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| for(uword i=0; i<in_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < in_n_elem; i+=2, j+=2) | |
| { | | { | |
|
| out_mem[i] = in_m.at(i+in_row_offset, i+in_col_offset); | | const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); | |
| | | const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); | |
| | | | |
| | | out_mem[i] = tmp_i; | |
| | | out_mem[j] = tmp_j; | |
| | | } | |
| | | | |
| | | if(i < in_n_elem) | |
| | | { | |
| | | out_mem[i] = in_m.at( i + in_row_offset, i + in_col_offset ); | |
| } | | } | |
| } | | } | |
| | | | |
|
| //! X += Y.diagview(...) | | //! X += Y.diag() | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::plus_inplace(Mat<eT>& out, const diagview<eT>& in) | | diagview<eT>::plus_inplace(Mat<eT>& out, const diagview<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols,
"addition"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols,
"addition"); | |
| | | | |
| const Mat<eT>& in_m = in.m; | | const Mat<eT>& in_m = in.m; | |
| | | | |
| const uword in_n_elem = in.n_elem; | | const uword in_n_elem = in.n_elem; | |
| const uword in_row_offset = in.row_offset; | | const uword in_row_offset = in.row_offset; | |
| const uword in_col_offset = in.col_offset; | | const uword in_col_offset = in.col_offset; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| for(uword i=0; i<in_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < in_n_elem; i+=2, j+=2) | |
| { | | { | |
|
| out_mem[i] += in_m.at(i+in_row_offset, i+in_col_offset); | | const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); | |
| | | const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); | |
| | | | |
| | | out_mem[i] += tmp_i; | |
| | | out_mem[j] += tmp_j; | |
| | | } | |
| | | | |
| | | if(i < in_n_elem) | |
| | | { | |
| | | out_mem[i] += in_m.at( i + in_row_offset, i + in_col_offset ); | |
| } | | } | |
| } | | } | |
| | | | |
|
| //! X -= Y.diagview(...) | | //! X -= Y.diag() | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::minus_inplace(Mat<eT>& out, const diagview<eT>& in) | | diagview<eT>::minus_inplace(Mat<eT>& out, const diagview<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols,
"subtraction"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols,
"subtraction"); | |
| | | | |
| const Mat<eT>& in_m = in.m; | | const Mat<eT>& in_m = in.m; | |
| | | | |
| const uword in_n_elem = in.n_elem; | | const uword in_n_elem = in.n_elem; | |
| const uword in_row_offset = in.row_offset; | | const uword in_row_offset = in.row_offset; | |
| const uword in_col_offset = in.col_offset; | | const uword in_col_offset = in.col_offset; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| for(uword i=0; i<in_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < in_n_elem; i+=2, j+=2) | |
| { | | { | |
|
| out_mem[i] -= in_m.at(i+in_row_offset, i+in_col_offset); | | const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); | |
| | | const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); | |
| | | | |
| | | out_mem[i] -= tmp_i; | |
| | | out_mem[j] -= tmp_j; | |
| | | } | |
| | | | |
| | | if(i < in_n_elem) | |
| | | { | |
| | | out_mem[i] -= in_m.at( i + in_row_offset, i + in_col_offset ); | |
| } | | } | |
| } | | } | |
| | | | |
|
| //! X %= Y.submat(...) | | //! X %= Y.diag() | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::schur_inplace(Mat<eT>& out, const diagview<eT>& in) | | diagview<eT>::schur_inplace(Mat<eT>& out, const diagview<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols,
"element-wise multiplication"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols,
"element-wise multiplication"); | |
| | | | |
| const Mat<eT>& in_m = in.m; | | const Mat<eT>& in_m = in.m; | |
| | | | |
| const uword in_n_elem = in.n_elem; | | const uword in_n_elem = in.n_elem; | |
| const uword in_row_offset = in.row_offset; | | const uword in_row_offset = in.row_offset; | |
| const uword in_col_offset = in.col_offset; | | const uword in_col_offset = in.col_offset; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| for(uword i=0; i<in_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < in_n_elem; i+=2, j+=2) | |
| { | | { | |
|
| out_mem[i] *= in_m.at(i+in_row_offset, i+in_col_offset); | | const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); | |
| | | const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); | |
| | | | |
| | | out_mem[i] *= tmp_i; | |
| | | out_mem[j] *= tmp_j; | |
| | | } | |
| | | | |
| | | if(i < in_n_elem) | |
| | | { | |
| | | out_mem[i] *= in_m.at( i + in_row_offset, i + in_col_offset ); | |
| } | | } | |
| } | | } | |
| | | | |
|
| //! X /= Y.diagview(...) | | //! X /= Y.diag() | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::div_inplace(Mat<eT>& out, const diagview<eT>& in) | | diagview<eT>::div_inplace(Mat<eT>& out, const diagview<eT>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols,
"element-wise division"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, in.n_rows, in.n_cols,
"element-wise division"); | |
| | | | |
| const Mat<eT>& in_m = in.m; | | const Mat<eT>& in_m = in.m; | |
| | | | |
| const uword in_n_elem = in.n_elem; | | const uword in_n_elem = in.n_elem; | |
| const uword in_row_offset = in.row_offset; | | const uword in_row_offset = in.row_offset; | |
| const uword in_col_offset = in.col_offset; | | const uword in_col_offset = in.col_offset; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
|
| for(uword i=0; i<in_n_elem; ++i) | | uword i,j; | |
| | | for(i=0, j=1; j < in_n_elem; i+=2, j+=2) | |
| | | { | |
| | | const eT tmp_i = in_m.at( i + in_row_offset, i + in_col_offset ); | |
| | | const eT tmp_j = in_m.at( j + in_row_offset, j + in_col_offset ); | |
| | | | |
| | | out_mem[i] /= tmp_i; | |
| | | out_mem[j] /= tmp_j; | |
| | | } | |
| | | | |
| | | if(i < in_n_elem) | |
| { | | { | |
|
| out_mem[i] /= in_m.at(i+in_row_offset, i+in_col_offset); | | out_mem[i] /= in_m.at( i + in_row_offset, i + in_col_offset ); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
| diagview<eT>::operator[](const uword i) | | diagview<eT>::operator[](const uword i) | |
| { | | { | |
| return (*m_ptr).at(i+row_offset, i+col_offset); | | return (*m_ptr).at(i+row_offset, i+col_offset); | |
| } | | } | |
| | | | |
End of changes. 23 change blocks. |
| 27 lines changed or deleted | | 146 lines changed or added | |
|