| Mat_meat.hpp | | Mat_meat.hpp | |
| | | | |
| skipping to change at line 367 | | skipping to change at line 367 | |
| line_start = line_end+1; | | line_start = line_end+1; | |
| | | | |
| } | | } | |
| | | | |
| Mat<eT>& x = *this; | | Mat<eT>& x = *this; | |
| x.set_size(t_n_rows, t_n_cols); | | x.set_size(t_n_rows, t_n_cols); | |
| | | | |
| line_start = 0; | | line_start = 0; | |
| line_end = 0; | | line_end = 0; | |
| | | | |
|
| uword row = 0; | | uword urow = 0; | |
| | | | |
| while( line_start < text.length() ) | | while( line_start < text.length() ) | |
| { | | { | |
| | | | |
| line_end = text.find(';', line_start); | | line_end = text.find(';', line_start); | |
| | | | |
| if(line_end == std::string::npos) | | if(line_end == std::string::npos) | |
| line_end = text.length()-1; | | line_end = text.length()-1; | |
| | | | |
| std::string::size_type line_len = line_end - line_start + 1; | | std::string::size_type line_len = line_end - line_start + 1; | |
| std::stringstream line_stream( text.substr(line_start,line_len) ); | | std::stringstream line_stream( text.substr(line_start,line_len) ); | |
| | | | |
|
| // uword col = 0; | | // uword ucol = 0; | |
| // while(line_stream >> token) | | // while(line_stream >> token) | |
| // { | | // { | |
|
| // x.at(row,col) = strtod(token.c_str(), 0); | | // x.at(urow,ucol) = strtod(token.c_str(), 0); | |
| // ++col; | | // ++ucol; | |
| // } | | // } | |
| | | | |
|
| uword col = 0; | | uword ucol = 0; | |
| eT val; | | eT val; | |
| while(line_stream >> val) | | while(line_stream >> val) | |
| { | | { | |
|
| x.at(row,col) = val; | | x.at(urow,ucol) = val; | |
| ++col; | | ++ucol; | |
| } | | } | |
| | | | |
|
| ++row; | | ++urow; | |
| line_start = line_end+1; | | line_start = line_end+1; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| #if defined(ARMA_USE_CXX11) | | #if defined(ARMA_USE_CXX11) | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| Mat<eT>::Mat(const std::initializer_list<eT>& list) | | Mat<eT>::Mat(const std::initializer_list<eT>& list) | |
| | | | |
| skipping to change at line 596 | | skipping to change at line 596 | |
| if(prefer_at_accessor == false) | | if(prefer_at_accessor == false) | |
| { | | { | |
| typedef typename Proxy<T1>::ea_type ea_type1; | | typedef typename Proxy<T1>::ea_type ea_type1; | |
| typedef typename Proxy<T2>::ea_type ea_type2; | | typedef typename Proxy<T2>::ea_type ea_type2; | |
| | | | |
| const uword N = n_elem; | | const uword N = n_elem; | |
| | | | |
| ea_type1 A = PX.get_ea(); | | ea_type1 A = PX.get_ea(); | |
| ea_type2 B = PY.get_ea(); | | ea_type2 B = PY.get_ea(); | |
| | | | |
|
| for(uword i=0; i<N; ++i) | | for(uword ii=0; ii < N; ++ii) | |
| { | | { | |
|
| out_mem[i] = std::complex<T>(A[i], B[i]); | | out_mem[ii] = std::complex<T>(A[ii], B[ii]); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| uword i = 0; | | uword ii = 0; | |
| | | | |
|
| for(uword col=0; col < local_n_cols; ++col) | | for(uword ucol=0; ucol < local_n_cols; ++ucol) | |
| for(uword row=0; row < local_n_rows; ++row, ++i) | | for(uword urow=0; urow < local_n_rows; ++urow, ++ii) | |
| { | | { | |
|
| out_mem[i] = std::complex<T>(PX.at(row,col), PY.at(row,col)); | | out_mem[ii] = std::complex<T>(PX.at(urow,ucol), PY.at(urow,ucol)); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! try to steal the memory from a given matrix; | | //! try to steal the memory from a given matrix; | |
| //! if memory can't be stolen, copy the given matrix | | //! if memory can't be stolen, copy the given matrix | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::steal_mem(Mat<eT>& x) | | Mat<eT>::steal_mem(Mat<eT>& x) | |
| | | | |
| skipping to change at line 849 | | skipping to change at line 849 | |
| const uword in_n_rows = in.n_rows; | | const uword in_n_rows = in.n_rows; | |
| const uword in_n_cols = in.n_cols; | | const uword in_n_cols = in.n_cols; | |
| const uword in_n_slices = in.n_slices; | | const uword in_n_slices = in.n_slices; | |
| | | | |
| const uword out_vec_state = out.vec_state; | | const uword out_vec_state = out.vec_state; | |
| | | | |
| if(in_n_slices == 1) | | if(in_n_slices == 1) | |
| { | | { | |
| out.set_size(in_n_rows, in_n_cols); | | out.set_size(in_n_rows, in_n_cols); | |
| | | | |
|
| for(uword col=0; col < in_n_cols; ++col) | | for(uword ucol=0; ucol < in_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::copy( out.colptr(col), in.slice_colptr(0, col), in_n_rows )
; | | arrayops::copy( out.colptr(ucol), in.slice_colptr(0, ucol), in_n_rows
); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| if(out_vec_state == 0) | | if(out_vec_state == 0) | |
| { | | { | |
| if(in_n_cols == 1) | | if(in_n_cols == 1) | |
| { | | { | |
| out.set_size(in_n_rows, in_n_slices); | | out.set_size(in_n_rows, in_n_slices); | |
| | | | |
| | | | |
| skipping to change at line 934 | | skipping to change at line 934 | |
| const uword in_n_rows = in.n_rows; | | const uword in_n_rows = in.n_rows; | |
| const uword in_n_cols = in.n_cols; | | const uword in_n_cols = in.n_cols; | |
| const uword in_n_slices = in.n_slices; | | const uword in_n_slices = in.n_slices; | |
| | | | |
| const uword out_n_rows = out.n_rows; | | const uword out_n_rows = out.n_rows; | |
| const uword out_n_cols = out.n_cols; | | const uword out_n_cols = out.n_cols; | |
| const uword out_vec_state = out.vec_state; | | const uword out_vec_state = out.vec_state; | |
| | | | |
| if(in_n_slices == 1) | | if(in_n_slices == 1) | |
| { | | { | |
|
| for(uword col=0; col < in_n_cols; ++col) | | for(uword ucol=0; ucol < in_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_plus( out.colptr(col), in.slice_colptr(0, col), in_
n_rows ); | | arrayops::inplace_plus( out.colptr(ucol), in.slice_colptr(0, ucol), i
n_n_rows ); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| if(out_vec_state == 0) | | if(out_vec_state == 0) | |
| { | | { | |
| if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices ==
out_n_cols) ) | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices ==
out_n_cols) ) | |
| { | | { | |
| for(uword i=0; i < in_n_slices; ++i) | | for(uword i=0; i < in_n_slices; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 1013 | | skipping to change at line 1013 | |
| const uword in_n_rows = in.n_rows; | | const uword in_n_rows = in.n_rows; | |
| const uword in_n_cols = in.n_cols; | | const uword in_n_cols = in.n_cols; | |
| const uword in_n_slices = in.n_slices; | | const uword in_n_slices = in.n_slices; | |
| | | | |
| const uword out_n_rows = out.n_rows; | | const uword out_n_rows = out.n_rows; | |
| const uword out_n_cols = out.n_cols; | | const uword out_n_cols = out.n_cols; | |
| const uword out_vec_state = out.vec_state; | | const uword out_vec_state = out.vec_state; | |
| | | | |
| if(in_n_slices == 1) | | if(in_n_slices == 1) | |
| { | | { | |
|
| for(uword col=0; col < in_n_cols; ++col) | | for(uword ucol=0; ucol < in_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_minus( out.colptr(col), in.slice_colptr(0, col), in
_n_rows ); | | arrayops::inplace_minus( out.colptr(ucol), in.slice_colptr(0, ucol),
in_n_rows ); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| if(out_vec_state == 0) | | if(out_vec_state == 0) | |
| { | | { | |
| if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices ==
out_n_cols) ) | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices ==
out_n_cols) ) | |
| { | | { | |
| for(uword i=0; i < in_n_slices; ++i) | | for(uword i=0; i < in_n_slices; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 1107 | | skipping to change at line 1107 | |
| const uword in_n_rows = in.n_rows; | | const uword in_n_rows = in.n_rows; | |
| const uword in_n_cols = in.n_cols; | | const uword in_n_cols = in.n_cols; | |
| const uword in_n_slices = in.n_slices; | | const uword in_n_slices = in.n_slices; | |
| | | | |
| const uword out_n_rows = out.n_rows; | | const uword out_n_rows = out.n_rows; | |
| const uword out_n_cols = out.n_cols; | | const uword out_n_cols = out.n_cols; | |
| const uword out_vec_state = out.vec_state; | | const uword out_vec_state = out.vec_state; | |
| | | | |
| if(in_n_slices == 1) | | if(in_n_slices == 1) | |
| { | | { | |
|
| for(uword col=0; col < in_n_cols; ++col) | | for(uword ucol=0; ucol < in_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_mul( out.colptr(col), in.slice_colptr(0, col), in_n
_rows ); | | arrayops::inplace_mul( out.colptr(ucol), in.slice_colptr(0, ucol), in
_n_rows ); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| if(out_vec_state == 0) | | if(out_vec_state == 0) | |
| { | | { | |
| if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices ==
out_n_cols) ) | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices ==
out_n_cols) ) | |
| { | | { | |
| for(uword i=0; i < in_n_slices; ++i) | | for(uword i=0; i < in_n_slices; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 1186 | | skipping to change at line 1186 | |
| const uword in_n_rows = in.n_rows; | | const uword in_n_rows = in.n_rows; | |
| const uword in_n_cols = in.n_cols; | | const uword in_n_cols = in.n_cols; | |
| const uword in_n_slices = in.n_slices; | | const uword in_n_slices = in.n_slices; | |
| | | | |
| const uword out_n_rows = out.n_rows; | | const uword out_n_rows = out.n_rows; | |
| const uword out_n_cols = out.n_cols; | | const uword out_n_cols = out.n_cols; | |
| const uword out_vec_state = out.vec_state; | | const uword out_vec_state = out.vec_state; | |
| | | | |
| if(in_n_slices == 1) | | if(in_n_slices == 1) | |
| { | | { | |
|
| for(uword col=0; col < in_n_cols; ++col) | | for(uword ucol=0; ucol < in_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_div( out.colptr(col), in.slice_colptr(0, col), in_n
_rows ); | | arrayops::inplace_div( out.colptr(ucol), in.slice_colptr(0, ucol), in
_n_rows ); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| if(out_vec_state == 0) | | if(out_vec_state == 0) | |
| { | | { | |
| if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices ==
out_n_cols) ) | | if( (in_n_rows == out_n_rows) && (in_n_cols == 1) && (in_n_slices ==
out_n_cols) ) | |
| { | | { | |
| for(uword i=0; i < in_n_slices; ++i) | | for(uword i=0; i < in_n_slices; ++i) | |
| { | | { | |
| | | | |
| skipping to change at line 2361 | | skipping to change at line 2361 | |
| return diagview<eT>(*this, row_offset, col_offset, len); | | return diagview<eT>(*this, row_offset, col_offset, len); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::swap_rows(const uword in_row1, const uword in_row2) | | Mat<eT>::swap_rows(const uword in_row1, const uword in_row2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | const uword local_n_rows = n_rows; | |
| | | const uword local_n_cols = n_cols; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (in_row1 >= n_rows) || (in_row2 >= n_rows), | | (in_row1 >= local_n_rows) || (in_row2 >= local_n_rows), | |
| "Mat::swap_rows(): out of bounds" | | "Mat::swap_rows(): out of bounds" | |
| ); | | ); | |
| | | | |
|
| for(uword col=0; col<n_cols; ++col) | | if(n_elem > 0) | |
| { | | { | |
|
| const uword offset = col*n_rows; | | for(uword ucol=0; ucol < local_n_cols; ++ucol) | |
| const uword pos1 = in_row1 + offset; | | { | |
| const uword pos2 = in_row2 + offset; | | const uword offset = ucol * local_n_rows; | |
| | | const uword pos1 = in_row1 + offset; | |
| const eT tmp = mem[pos1]; | | const uword pos2 = in_row2 + offset; | |
| access::rw(mem[pos1]) = mem[pos2]; | | | |
| access::rw(mem[pos2]) = tmp; | | | |
| } | | | |
| | | | |
|
| | | std::swap( access::rw(mem[pos1]), access::rw(mem[pos2]) ); | |
| | | } | |
| | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
|
| Mat<eT>::swap_cols(const uword in_col1, const uword in_col2) | | Mat<eT>::swap_cols(const uword in_colA, const uword in_colB) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | const uword local_n_rows = n_rows; | |
| | | const uword local_n_cols = n_cols; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (in_col1 >= n_cols) || (in_col2 >= n_cols), | | (in_colA >= local_n_cols) || (in_colB >= local_n_cols), | |
| "Mat::swap_cols(): out of bounds" | | "Mat::swap_cols(): out of bounds" | |
| ); | | ); | |
| | | | |
| if(n_elem > 0) | | if(n_elem > 0) | |
| { | | { | |
|
| eT* ptr1 = colptr(in_col1); | | eT* ptrA = colptr(in_colA); | |
| eT* ptr2 = colptr(in_col2); | | eT* ptrB = colptr(in_colB); | |
| | | | |
| | | eT tmp_i; | |
| | | eT tmp_j; | |
| | | | |
| | | uword iq,jq; | |
| | | for(iq=0, jq=1; jq < local_n_rows; iq+=2, jq+=2) | |
| | | { | |
| | | tmp_i = ptrA[iq]; | |
| | | tmp_j = ptrA[jq]; | |
| | | | |
| | | ptrA[iq] = ptrB[iq]; | |
| | | ptrA[jq] = ptrB[jq]; | |
| | | | |
| | | ptrB[iq] = tmp_i; | |
| | | ptrB[jq] = tmp_j; | |
| | | } | |
| | | | |
|
| for(uword row=0; row<n_rows; ++row) | | if(iq < local_n_rows) | |
| { | | { | |
|
| const eT tmp = ptr1[row]; | | std::swap( ptrA[iq], ptrB[iq] ); | |
| ptr1[row] = ptr2[row]; | | | |
| ptr2[row] = tmp; | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! remove specified row | | //! remove specified row | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::shed_row(const uword row_num) | | Mat<eT>::shed_row(const uword row_num) | |
| { | | { | |
| | | | |
| skipping to change at line 2990 | | skipping to change at line 3010 | |
| const bool bad_alias = (eOp<T1, eop_type>::proxy_type::has_subview && X
.P.is_alias(*this)); | | const bool bad_alias = (eOp<T1, eop_type>::proxy_type::has_subview && X
.P.is_alias(*this)); | |
| | | | |
| if(bad_alias == false) | | if(bad_alias == false) | |
| { | | { | |
| init_warm(X.get_n_rows(), X.get_n_cols()); | | init_warm(X.get_n_rows(), X.get_n_cols()); | |
| | | | |
| eop_type::apply(*this, X); | | eop_type::apply(*this, X); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| | | arma_extra_debug_print("bad_alias = true"); | |
| | | | |
| Mat<eT> tmp(X); | | Mat<eT> tmp(X); | |
| | | | |
| steal_mem(tmp); | | steal_mem(tmp); | |
| } | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1, typename eop_type> | | template<typename T1, typename eop_type> | |
| | | | |
| skipping to change at line 3371 | | skipping to change at line 3393 | |
| ); | | ); | |
| | | | |
| if(bad_alias == false) | | if(bad_alias == false) | |
| { | | { | |
| init_warm(X.get_n_rows(), X.get_n_cols()); | | init_warm(X.get_n_rows(), X.get_n_cols()); | |
| | | | |
| eglue_type::apply(*this, X); | | eglue_type::apply(*this, X); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| | | arma_extra_debug_print("bad_alias = true"); | |
| | | | |
| Mat<eT> tmp(X); | | Mat<eT> tmp(X); | |
| | | | |
| steal_mem(tmp); | | steal_mem(tmp); | |
| } | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| //! in-place matrix addition, with the right-hand-side operands having dela
yed operations | | //! in-place matrix addition, with the right-hand-side operands having dela
yed operations | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 3566 | | skipping to change at line 3590 | |
| const Mat<eT> m(X); | | const Mat<eT> m(X); | |
| | | | |
| return (*this).operator/=(m); | | return (*this).operator/=(m); | |
| } | | } | |
| | | | |
| //! linear element accessor (treats the matrix as a vector); bounds checkin
g not done when ARMA_NO_DEBUG is defined | | //! linear element accessor (treats the matrix as a vector); bounds checkin
g not done when ARMA_NO_DEBUG is defined | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT& | | eT& | |
|
| Mat<eT>::operator() (const uword i) | | Mat<eT>::operator() (const uword ii) | |
| { | | { | |
|
| arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds"); | | arma_debug_check( (ii >= n_elem), "Mat::operator(): out of bounds"); | |
| return access::rw(mem[i]); | | return access::rw(mem[ii]); | |
| } | | } | |
| | | | |
| //! linear element accessor (treats the matrix as a vector); bounds checkin
g not done when ARMA_NO_DEBUG is defined | | //! linear element accessor (treats the matrix as a vector); bounds checkin
g not done when ARMA_NO_DEBUG is defined | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT | | eT | |
|
| Mat<eT>::operator() (const uword i) const | | Mat<eT>::operator() (const uword ii) const | |
| { | | { | |
|
| arma_debug_check( (i >= n_elem), "Mat::operator(): out of bounds"); | | arma_debug_check( (ii >= n_elem), "Mat::operator(): out of bounds"); | |
| return mem[i]; | | return mem[ii]; | |
| } | | } | |
| | | | |
| //! linear element accessor (treats the matrix as a vector); no bounds chec
k. | | //! linear element accessor (treats the matrix as a vector); no bounds chec
k. | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT& | | eT& | |
|
| Mat<eT>::operator[] (const uword i) | | Mat<eT>::operator[] (const uword ii) | |
| { | | { | |
|
| return access::rw(mem[i]); | | return access::rw(mem[ii]); | |
| } | | } | |
| | | | |
| //! linear element accessor (treats the matrix as a vector); no bounds chec
k | | //! linear element accessor (treats the matrix as a vector); no bounds chec
k | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT | | eT | |
|
| Mat<eT>::operator[] (const uword i) const | | Mat<eT>::operator[] (const uword ii) const | |
| { | | { | |
|
| return mem[i]; | | return mem[ii]; | |
| } | | } | |
| | | | |
| //! linear element accessor (treats the matrix as a vector); no bounds chec
k. | | //! linear element accessor (treats the matrix as a vector); no bounds chec
k. | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT& | | eT& | |
|
| Mat<eT>::at(const uword i) | | Mat<eT>::at(const uword ii) | |
| { | | { | |
|
| return access::rw(mem[i]); | | return access::rw(mem[ii]); | |
| } | | } | |
| | | | |
| //! linear element accessor (treats the matrix as a vector); no bounds chec
k | | //! linear element accessor (treats the matrix as a vector); no bounds chec
k | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT | | eT | |
|
| Mat<eT>::at(const uword i) const | | Mat<eT>::at(const uword ii) const | |
| { | | { | |
|
| return mem[i]; | | return mem[ii]; | |
| } | | } | |
| | | | |
| //! element accessor; bounds checking not done when ARMA_NO_DEBUG is define
d | | //! element accessor; bounds checking not done when ARMA_NO_DEBUG is define
d | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT& | | eT& | |
| Mat<eT>::operator() (const uword in_row, const uword in_col) | | Mat<eT>::operator() (const uword in_row, const uword in_col) | |
| { | | { | |
| arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::opera
tor(): out of bounds"); | | arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "Mat::opera
tor(): out of bounds"); | |
| | | | |
| skipping to change at line 3768 | | skipping to change at line 3792 | |
| Mat<eT>::is_finite() const | | Mat<eT>::is_finite() const | |
| { | | { | |
| return arrayops::is_finite( memptr(), n_elem ); | | return arrayops::is_finite( memptr(), n_elem ); | |
| } | | } | |
| | | | |
| //! returns true if the given index is currently in range | | //! returns true if the given index is currently in range | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| bool | | bool | |
|
| Mat<eT>::in_range(const uword i) const | | Mat<eT>::in_range(const uword ii) const | |
| { | | { | |
|
| return (i < n_elem); | | return (ii < n_elem); | |
| } | | } | |
| | | | |
| //! returns true if the given start and end indices are currently in range | | //! returns true if the given start and end indices are currently in range | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| bool | | bool | |
| Mat<eT>::in_range(const span& x) const | | Mat<eT>::in_range(const span& x) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 3953 | | skipping to change at line 3977 | |
| const std::streamsize orig_width = user_stream.width(); | | const std::streamsize orig_width = user_stream.width(); | |
| | | | |
| user_stream << extra_text << '\n'; | | user_stream << extra_text << '\n'; | |
| | | | |
| user_stream.width(orig_width); | | user_stream.width(orig_width); | |
| } | | } | |
| | | | |
| arma_ostream::print(user_stream, *this, true); | | arma_ostream::print(user_stream, *this, true); | |
| } | | } | |
| | | | |
|
| //! DEPRECATED FUNCTION | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Mat<eT>::impl_print_trans(const std::string& extra_text) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT> tmp; | | | |
| op_strans::apply_noalias(tmp, *this); | | | |
| | | | |
| tmp.impl_print(extra_text); | | | |
| } | | | |
| | | | |
| //! DEPRECATED FUNCTION | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Mat<eT>::impl_print_trans(std::ostream& user_stream, const std::string& ext | | | |
| ra_text) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT> tmp; | | | |
| op_strans::apply_noalias(tmp, *this); | | | |
| | | | |
| tmp.impl_print(user_stream, extra_text); | | | |
| } | | | |
| | | | |
| //! print contents of the matrix (to the cout stream), | | //! print contents of the matrix (to the cout stream), | |
| //! optionally preceding with a user specified line of text. | | //! optionally preceding with a user specified line of text. | |
| //! the stream's state are used as is and are not modified | | //! the stream's state are used as is and are not modified | |
| //! (i.e. the precision and cell width are not modified). | | //! (i.e. the precision and cell width are not modified). | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::impl_raw_print(const std::string& extra_text) const | | Mat<eT>::impl_raw_print(const std::string& extra_text) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 4027 | | skipping to change at line 4023 | |
| const std::streamsize orig_width = user_stream.width(); | | const std::streamsize orig_width = user_stream.width(); | |
| | | | |
| user_stream << extra_text << '\n'; | | user_stream << extra_text << '\n'; | |
| | | | |
| user_stream.width(orig_width); | | user_stream.width(orig_width); | |
| } | | } | |
| | | | |
| arma_ostream::print(user_stream, *this, false); | | arma_ostream::print(user_stream, *this, false); | |
| } | | } | |
| | | | |
|
| //! DEPRECATED FUNCTION | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Mat<eT>::impl_raw_print_trans(const std::string& extra_text) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT> tmp; | | | |
| op_strans::apply_noalias(tmp, *this); | | | |
| | | | |
| tmp.impl_raw_print(extra_text); | | | |
| } | | | |
| | | | |
| //! DEPRECATED FUNCTION | | | |
| template<typename eT> | | | |
| inline | | | |
| void | | | |
| Mat<eT>::impl_raw_print_trans(std::ostream& user_stream, const std::string& | | | |
| extra_text) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT> tmp; | | | |
| op_strans::apply_noalias(tmp, *this); | | | |
| | | | |
| tmp.impl_raw_print(user_stream, extra_text); | | | |
| } | | | |
| | | | |
| //! change the matrix to have user specified dimensions (data is not preser
ved) | | //! change the matrix to have user specified dimensions (data is not preser
ved) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| Mat<eT>::set_size(const uword in_elem) | | Mat<eT>::set_size(const uword in_elem) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| switch(vec_state) | | switch(vec_state) | |
| { | | { | |
| | | | |
| skipping to change at line 4245 | | skipping to change at line 4213 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::randu() | | Mat<eT>::randu() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const uword N = n_elem; | | const uword N = n_elem; | |
| eT* ptr = memptr(); | | eT* ptr = memptr(); | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | | |
|
| for(i=0, j=1; j<N; i+=2, j+=2) | | for(ii=0, jj=1; jj < N; ii+=2, jj+=2) | |
| { | | { | |
|
| const eT tmp_i = eT(eop_aux_randu<eT>()); | | const eT tmp_ii = eT(eop_aux_randu<eT>()); | |
| const eT tmp_j = eT(eop_aux_randu<eT>()); | | const eT tmp_jj = eT(eop_aux_randu<eT>()); | |
| | | | |
|
| ptr[i] = tmp_i; | | ptr[ii] = tmp_ii; | |
| ptr[j] = tmp_j; | | ptr[jj] = tmp_jj; | |
| } | | } | |
| | | | |
|
| if(i < N) | | if(ii < N) | |
| { | | { | |
|
| ptr[i] = eT(eop_aux_randu<eT>()); | | ptr[ii] = eT(eop_aux_randu<eT>()); | |
| } | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::randu(const uword in_elem) | | Mat<eT>::randu(const uword in_elem) | |
| { | | { | |
| | | | |
| skipping to change at line 4298 | | skipping to change at line 4266 | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::randn() | | Mat<eT>::randn() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const uword N = n_elem; | | const uword N = n_elem; | |
| eT* ptr = memptr(); | | eT* ptr = memptr(); | |
| | | | |
|
| for(uword i=0; i<N; ++i) | | for(uword ii=0; ii<N; ++ii) | |
| { | | { | |
|
| ptr[i] = eT(eop_aux_randn<eT>()); | | ptr[ii] = eT(eop_aux_randn<eT>()); | |
| } | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::randn(const uword in_elem) | | Mat<eT>::randn(const uword in_elem) | |
| { | | { | |
| | | | |
| skipping to change at line 4341 | | skipping to change at line 4309 | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::eye() | | Mat<eT>::eye() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| fill(eT(0)); | | fill(eT(0)); | |
| | | | |
| const uword N = (std::min)(n_rows, n_cols); | | const uword N = (std::min)(n_rows, n_cols); | |
| | | | |
|
| for(uword i=0; i<N; ++i) | | for(uword ii=0; ii<N; ++ii) | |
| { | | { | |
|
| at(i,i) = eT(1); | | at(ii,ii) = eT(1); | |
| } | | } | |
| | | | |
| return *this; | | return *this; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
| Mat<eT>::eye(const uword in_rows, const uword in_cols) | | Mat<eT>::eye(const uword in_rows, const uword in_cols) | |
| { | | { | |
| | | | |
| skipping to change at line 4465 | | skipping to change at line 4433 | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| Mat<eT>::min(uword& row_of_min_val, uword& col_of_min_val) const | | Mat<eT>::min(uword& row_of_min_val, uword& col_of_min_val) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (n_elem == 0), "min(): object has no elements" ); | | arma_debug_check( (n_elem == 0), "min(): object has no elements" ); | |
| | | | |
|
| uword i; | | uword iq; | |
| | | | |
|
| eT val = op_min::direct_min(memptr(), n_elem, i); | | eT val = op_min::direct_min(memptr(), n_elem, iq); | |
| | | | |
|
| row_of_min_val = i % n_rows; | | row_of_min_val = iq % n_rows; | |
| col_of_min_val = i / n_rows; | | col_of_min_val = iq / n_rows; | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
| Mat<eT>::max(uword& row_of_max_val, uword& col_of_max_val) const | | Mat<eT>::max(uword& row_of_max_val, uword& col_of_max_val) const | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check( (n_elem == 0), "max(): object has no elements" ); | | arma_debug_check( (n_elem == 0), "max(): object has no elements" ); | |
| | | | |
|
| uword i; | | uword iq; | |
| | | | |
|
| eT val = op_max::direct_max(memptr(), n_elem, i); | | eT val = op_max::direct_max(memptr(), n_elem, iq); | |
| | | | |
|
| row_of_max_val = i % n_rows; | | row_of_max_val = iq % n_rows; | |
| col_of_max_val = i / n_rows; | | col_of_max_val = iq / n_rows; | |
| | | | |
| return val; | | return val; | |
| } | | } | |
| | | | |
| //! save the matrix to a file | | //! save the matrix to a file | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| Mat<eT>::save(const std::string name, const file_type type, const bool prin
t_status) const | | Mat<eT>::save(const std::string name, const file_type type, const bool prin
t_status) const | |
| { | | { | |
| | | | |
| skipping to change at line 4530 | | skipping to change at line 4498 | |
| break; | | break; | |
| | | | |
| case arma_binary: | | case arma_binary: | |
| save_okay = diskio::save_arma_binary(*this, name); | | save_okay = diskio::save_arma_binary(*this, name); | |
| break; | | break; | |
| | | | |
| case pgm_binary: | | case pgm_binary: | |
| save_okay = diskio::save_pgm_binary(*this, name); | | save_okay = diskio::save_pgm_binary(*this, name); | |
| break; | | break; | |
| | | | |
|
| | | case hdf5_binary: | |
| | | save_okay = diskio::save_hdf5_binary(*this, name); | |
| | | break; | |
| | | | |
| default: | | default: | |
| arma_warn(print_status, "Mat::save(): unsupported file type"); | | arma_warn(print_status, "Mat::save(): unsupported file type"); | |
| save_okay = false; | | save_okay = false; | |
| } | | } | |
| | | | |
| arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't
write to ", name); | | arma_warn( (print_status && (save_okay == false)), "Mat::save(): couldn't
write to ", name); | |
| | | | |
| return save_okay; | | return save_okay; | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 4627 | | skipping to change at line 4599 | |
| break; | | break; | |
| | | | |
| case arma_binary: | | case arma_binary: | |
| load_okay = diskio::load_arma_binary(*this, name, err_msg); | | load_okay = diskio::load_arma_binary(*this, name, err_msg); | |
| break; | | break; | |
| | | | |
| case pgm_binary: | | case pgm_binary: | |
| load_okay = diskio::load_pgm_binary(*this, name, err_msg); | | load_okay = diskio::load_pgm_binary(*this, name, err_msg); | |
| break; | | break; | |
| | | | |
|
| | | case hdf5_binary: | |
| | | load_okay = diskio::load_hdf5_binary(*this, name, err_msg); | |
| | | break; | |
| | | | |
| default: | | default: | |
| arma_warn(print_status, "Mat::load(): unsupported file type"); | | arma_warn(print_status, "Mat::load(): unsupported file type"); | |
| load_okay = false; | | load_okay = false; | |
| } | | } | |
| | | | |
| if( (print_status == true) && (load_okay == false) ) | | if( (print_status == true) && (load_okay == false) ) | |
| { | | { | |
| if(err_msg.length() > 0) | | if(err_msg.length() > 0) | |
| { | | { | |
| arma_warn(true, "Mat::load(): ", err_msg, name); | | arma_warn(true, "Mat::load(): ", err_msg, name); | |
| | | | |
| skipping to change at line 5211 | | skipping to change at line 5187 | |
| inline | | inline | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const std::string& text) | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const std::string& text) | |
| { | | { | |
| arma_extra_debug_sigprint_this(this); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
| mem_setup(); | | mem_setup(); | |
| | | | |
| Mat<eT>::operator=(text); | | Mat<eT>::operator=(text); | |
| } | | } | |
| | | | |
|
| template<typename eT> | | #if defined(ARMA_USE_CXX11) | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | | |
| template<typename T1> | | | |
| inline | | | |
| const Mat<eT>& | | | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const Base<eT,T1>& A) | | | |
| { | | | |
| Mat<eT>::operator=(A.get_ref()); | | | |
| | | | |
| return *this; | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | | |
| inline | | | |
| const Mat<eT>& | | | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const eT val) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::operator=(val); | | | |
| | | | |
| return *this; | | | |
| } | | | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| inline | | inline | |
|
| const Mat<eT>& | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::fixed(const std::initializer_li | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const char* text) | | st<eT>& list) | |
| { | | { | |
|
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint_this(this); | |
| | | | |
|
| Mat<eT>::operator=(text); | | mem_setup(); | |
| | | | |
|
| return *this; | | (*this).operator=(list); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| inline | | inline | |
| const Mat<eT>& | | const Mat<eT>& | |
|
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const std::string& te | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator=(const std::initialize | |
| xt) | | r_list<eT>& list) | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| Mat<eT>::operator=(text); | | | |
| | | | |
| return *this; | | | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | | |
| inline | | | |
| subview_row<eT> | | | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const uword row_num, | | | |
| const span& col_span) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| return Mat<eT>::operator()(row_num, col_span); | | const uword N = list.size(); | |
| } | | | |
| | | | |
| template<typename eT> | | | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | | |
| inline | | | |
| const subview_row<eT> | | | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const uword row_num, | | | |
| const span& col_span) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| return Mat<eT>::operator()(row_num, col_span); | | | |
| } | | | |
| | | | |
|
| template<typename eT> | | arma_debug_check( (N > fixed_n_elem), "Mat::fixed: initialiser list is to | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | o long" ); | |
| inline | | | |
| subview_col<eT> | | | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span | | | |
| , const uword col_num) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| return Mat<eT>::operator()(row_span, col_num); | | eT* this_mem = (*this).memptr(); | |
| } | | | |
| | | | |
|
| template<typename eT> | | arrayops::copy( this_mem, list.begin(), N ); | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | | |
| inline | | | |
| const subview_col<eT> | | | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span | | | |
| , const uword col_num) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
|
| return Mat<eT>::operator()(row_span, col_num); | | for(uword iq=N; iq < fixed_n_elem; ++iq) { this_mem[iq] = eT(0); } | |
| } | | | |
| | | | |
|
| template<typename eT> | | return *this; | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | | |
| inline | | | |
| subview<eT> | | | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span | | | |
| , const span& col_span) | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| return Mat<eT>::operator()(row_span, col_span); | | | |
| } | | } | |
| | | | |
|
| template<typename eT> | | #endif | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | | |
| inline | | | |
| const subview<eT> | | | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator()(const span& row_span | | | |
| , const span& col_span) const | | | |
| { | | | |
| arma_extra_debug_sigprint(); | | | |
| | | | |
| return Mat<eT>::operator()(row_span, col_span); | | | |
| } | | | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT& | | eT& | |
|
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator[] (const uword i) | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator[] (const uword ii) | |
| { | | { | |
|
| return (use_extra) ? mem_local_extra[i] : mem_local[i]; | | return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT | | eT | |
|
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator[] (const uword i) cons
t | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator[] (const uword ii) con
st | |
| { | | { | |
|
| return (use_extra) ? mem_local_extra[i] : mem_local[i]; | | return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT& | | eT& | |
|
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword i) | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword ii) | |
| { | | { | |
|
| return (use_extra) ? mem_local_extra[i] : mem_local[i]; | | return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT | | eT | |
|
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword i) const | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword ii) const | |
| { | | { | |
|
| return (use_extra) ? mem_local_extra[i] : mem_local[i]; | | return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT& | | eT& | |
|
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword i) | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword ii) | |
| { | | { | |
|
| arma_debug_check( (i >= fixed_n_elem), "Mat::operator(): out of bounds"); | | arma_debug_check( (ii >= fixed_n_elem), "Mat::operator(): out of bounds")
; | |
| | | | |
|
| return (use_extra) ? mem_local_extra[i] : mem_local[i]; | | return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT | | eT | |
|
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword i) cons
t | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword ii) con
st | |
| { | | { | |
|
| arma_debug_check( (i >= fixed_n_elem), "Mat::operator(): out of bounds"); | | arma_debug_check( (ii >= fixed_n_elem), "Mat::operator(): out of bounds")
; | |
| | | | |
|
| return (use_extra) ? mem_local_extra[i] : mem_local[i]; | | return (use_extra) ? mem_local_extra[ii] : mem_local[ii]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT& | | eT& | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword in_row, const uw
ord in_col) | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword in_row, const uw
ord in_col) | |
| { | | { | |
|
| const uword i = in_row + in_col*fixed_n_rows; | | const uword iq = in_row + in_col*fixed_n_rows; | |
| | | | |
|
| return (use_extra) ? mem_local_extra[i] : mem_local[i]; | | return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT | | eT | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword in_row, const uw
ord in_col) const | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::at(const uword in_row, const uw
ord in_col) const | |
| { | | { | |
|
| const uword i = in_row + in_col*fixed_n_rows; | | const uword iq = in_row + in_col*fixed_n_rows; | |
| | | | |
|
| return (use_extra) ? mem_local_extra[i] : mem_local[i]; | | return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT& | | eT& | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword in_row,
const uword in_col) | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword in_row,
const uword in_col) | |
| { | | { | |
| arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)),
"Mat::operator(): out of bounds"); | | arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)),
"Mat::operator(): out of bounds"); | |
| | | | |
|
| const uword i = in_row + in_col*fixed_n_rows; | | const uword iq = in_row + in_col*fixed_n_rows; | |
| | | | |
|
| return (use_extra) ? mem_local_extra[i] : mem_local[i]; | | return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT | | eT | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword in_row,
const uword in_col) const | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::operator() (const uword in_row,
const uword in_col) const | |
| { | | { | |
| arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)),
"Mat::operator(): out of bounds"); | | arma_debug_check( ((in_row >= fixed_n_rows) || (in_col >= fixed_n_cols)),
"Mat::operator(): out of bounds"); | |
| | | | |
|
| const uword i = in_row + in_col*fixed_n_rows; | | const uword iq = in_row + in_col*fixed_n_rows; | |
| | | | |
|
| return (use_extra) ? mem_local_extra[i] : mem_local[i]; | | return (use_extra) ? mem_local_extra[iq] : mem_local[iq]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<uword fixed_n_rows, uword fixed_n_cols> | | template<uword fixed_n_rows, uword fixed_n_cols> | |
| arma_inline | | arma_inline | |
| arma_warn_unused | | arma_warn_unused | |
| eT* | | eT* | |
| Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::memptr() | | Mat<eT>::fixed<fixed_n_rows, fixed_n_cols>::memptr() | |
| { | | { | |
| return (use_extra) ? mem_local_extra : mem_local; | | return (use_extra) ? mem_local_extra : mem_local; | |
| | | | |
End of changes. 103 change blocks. |
| 258 lines changed or deleted | | 148 lines changed or added | |
|
| Proxy.hpp | | Proxy.hpp | |
| | | | |
| skipping to change at line 20 | | skipping to change at line 20 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| //! \addtogroup Proxy | | //! \addtogroup Proxy | |
| //! @{ | | //! @{ | |
| | | | |
| // ea_type is the "element accessor" type, | | // ea_type is the "element accessor" type, | |
| // which can provide access to elements via operator[] | | // which can provide access to elements via operator[] | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct Proxy_Mat_fixed | | struct Proxy_default | |
| | | { | |
| | | inline Proxy_default(const T1&) | |
| | | { | |
| | | arma_type_check(( is_arma_type<T1>::value == false )); | |
| | | } | |
| | | }; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_fixed | |
| { | | { | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef T1 stored_type; | | typedef T1 stored_type; | |
| typedef const elem_type* ea_type; | | typedef const elem_type* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = true; | |
| | | | |
| static const bool is_row = T1::is_row; | | static const bool is_row = T1::is_row; | |
| static const bool is_col = T1::is_col; | | static const bool is_col = T1::is_col; | |
| | | | |
| arma_aligned const T1& Q; | | arma_aligned const T1& Q; | |
| | | | |
|
| inline explicit Proxy_Mat_fixed(const T1& A) | | inline explicit Proxy_fixed(const T1& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_inline static uword get_n_rows() { return T1::n_rows; } | | arma_inline static uword get_n_rows() { return T1::n_rows; } | |
| arma_inline static uword get_n_cols() { return T1::n_cols; } | | arma_inline static uword get_n_cols() { return T1::n_cols; } | |
| arma_inline static uword get_n_elem() { return T1::n_elem; } | | arma_inline static uword get_n_elem() { return T1::n_elem; } | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const
{ return Q[i]; } | | arma_inline elem_type operator[] (const uword i) const
{ return Q[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | |
| | | | |
| arma_inline ea_type get_ea() const { return Q.memptr(); } | | arma_inline ea_type get_ea() const { return Q.memptr(); } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&Q)
== void_ptr(&X)); } | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&Q)
== void_ptr(&X)); } | |
| }; | | }; | |
| | | | |
|
| template<typename T1> | | | |
| struct Proxy_extra_empty | | | |
| { | | | |
| inline Proxy_extra_empty(const T1&) | | | |
| { | | | |
| arma_type_check(( is_arma_type<T1>::value == false )); | | | |
| } | | | |
| }; | | | |
| | | | |
| template<typename T1, bool condition> | | template<typename T1, bool condition> | |
|
| struct Proxy_extra {}; | | struct Proxy_redirect {}; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct Proxy_extra<T1, true> { typedef Proxy_Mat_fixed<T1> result; }; | | struct Proxy_redirect<T1, false> { typedef Proxy_default<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct Proxy_extra<T1, false> { typedef Proxy_extra_empty<T1> result; }; | | struct Proxy_redirect<T1, true> { typedef Proxy_fixed<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class Proxy : public Proxy_extra<T1, is_Mat_fixed<T1>::value >::result | | class Proxy : public Proxy_redirect<T1, is_Mat_fixed<T1>::value >::result | |
| { | | { | |
| public: | | public: | |
| inline Proxy(const T1& A) | | inline Proxy(const T1& A) | |
|
| : Proxy_extra<T1, is_Mat_fixed<T1>::value >::result(A) | | : Proxy_redirect< T1, is_Mat_fixed<T1>::value >::result(A) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class Proxy< Mat<eT> > | | class Proxy< Mat<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef Mat<eT> stored_type; | | typedef Mat<eT> stored_type; | |
| typedef const eT* ea_type; | | typedef const eT* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = false; | | static const bool is_row = false; | |
| static const bool is_col = false; | | static const bool is_col = false; | |
| | | | |
| arma_aligned const Mat<eT>& Q; | | arma_aligned const Mat<eT>& Q; | |
| | | | |
| inline explicit Proxy(const Mat<eT>& A) | | inline explicit Proxy(const Mat<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 131 | | skipping to change at line 133 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef Col<eT> stored_type; | | typedef Col<eT> stored_type; | |
| typedef const eT* ea_type; | | typedef const eT* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = false; | | static const bool is_row = false; | |
| static const bool is_col = true; | | static const bool is_col = true; | |
| | | | |
| arma_aligned const Col<eT>& Q; | | arma_aligned const Col<eT>& Q; | |
| | | | |
| inline explicit Proxy(const Col<eT>& A) | | inline explicit Proxy(const Col<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 168 | | skipping to change at line 171 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef Row<eT> stored_type; | | typedef Row<eT> stored_type; | |
| typedef const eT* ea_type; | | typedef const eT* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = true; | | static const bool is_row = true; | |
| static const bool is_col = false; | | static const bool is_col = false; | |
| | | | |
| arma_aligned const Row<eT>& Q; | | arma_aligned const Row<eT>& Q; | |
| | | | |
| inline explicit Proxy(const Row<eT>& A) | | inline explicit Proxy(const Row<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 205 | | skipping to change at line 209 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef Gen<T1, gen_type> stored_type; | | typedef Gen<T1, gen_type> stored_type; | |
| typedef const Gen<T1, gen_type>& ea_type; | | typedef const Gen<T1, gen_type>& ea_type; | |
| | | | |
| static const bool prefer_at_accessor = Gen<T1, gen_type>::prefer_at_acces
sor; | | static const bool prefer_at_accessor = Gen<T1, gen_type>::prefer_at_acces
sor; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = Gen<T1, gen_type>::is_row; | | static const bool is_row = Gen<T1, gen_type>::is_row; | |
| static const bool is_col = Gen<T1, gen_type>::is_col; | | static const bool is_col = Gen<T1, gen_type>::is_col; | |
| | | | |
| arma_aligned const Gen<T1, gen_type>& Q; | | arma_aligned const Gen<T1, gen_type>& Q; | |
| | | | |
| inline explicit Proxy(const Gen<T1, gen_type>& A) | | inline explicit Proxy(const Gen<T1, gen_type>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
|
| arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } | | arma_inline uword get_n_rows() const { return (is_row ? 1 : Q.n_rows); | |
| arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } | | } | |
| arma_inline uword get_n_elem() const { return Q.n_rows*Q.n_cols; } | | arma_inline uword get_n_cols() const { return (is_col ? 1 : Q.n_cols); | |
| | | } | |
| | | arma_inline uword get_n_elem() const { return (is_row ? 1 : Q.n_rows) * ( | |
| | | is_col ? 1 : Q.n_cols); } | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const
{ return Q[i]; } | | arma_inline elem_type operator[] (const uword i) const
{ return Q[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | |
| | | | |
| arma_inline ea_type get_ea() const { return Q; } | | arma_inline ea_type get_ea() const { return Q; } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const Mat<eT2>&) const { return false; } | | arma_inline bool is_alias(const Mat<eT2>&) const { return false; } | |
| }; | | }; | |
| | | | |
| | | | |
| skipping to change at line 242 | | skipping to change at line 247 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef Mat<elem_type> stored_type; | | typedef Mat<elem_type> stored_type; | |
| typedef const elem_type* ea_type; | | typedef const elem_type* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = Op<T1, op_type>::is_row; | | static const bool is_row = Op<T1, op_type>::is_row; | |
| static const bool is_col = Op<T1, op_type>::is_col; | | static const bool is_col = Op<T1, op_type>::is_col; | |
| | | | |
| arma_aligned const Mat<elem_type> Q; | | arma_aligned const Mat<elem_type> Q; | |
| | | | |
| inline explicit Proxy(const Op<T1, op_type>& A) | | inline explicit Proxy(const Op<T1, op_type>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 267 | | skipping to change at line 273 | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const
{ return Q[i]; } | | arma_inline elem_type operator[] (const uword i) const
{ return Q[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return Q.at(row, col); } | |
| | | | |
| arma_inline ea_type get_ea() const { return Q.memptr(); } | | arma_inline ea_type get_ea() const { return Q.memptr(); } | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| arma_inline bool is_alias(const Mat<eT2>&) const { return false; } | | arma_inline bool is_alias(const Mat<eT2>&) const { return false; } | |
| }; | | }; | |
| | | | |
|
| | | template<typename T1> | |
| | | struct Proxy_xtrans_default | |
| | | { | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = false; | |
| | | static const bool is_fixed = false; | |
| | | | |
| | | arma_aligned const Mat<eT> Q; | |
| | | | |
| | | arma_hot | |
| | | inline Proxy_xtrans_default(const T1& A) | |
| | | : Q(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>&) const { return false; } | |
| | | }; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_xtrans_vector | |
| | | { | |
| | | inline Proxy_xtrans_vector(const T1&) {} | |
| | | }; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_xtrans_vector< Op<T1, op_htrans> > | |
| | | { | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = quasi_unwrap<T1>::has_subview; | |
| | | static const bool is_fixed = false; | |
| | | | |
| | | arma_aligned const quasi_unwrap<T1> U; // avoid copy if T1 is a Row, Col | |
| | | or subview_col | |
| | | arma_aligned const Mat<eT> Q; | |
| | | | |
| | | inline Proxy_xtrans_vector(const Op<T1, op_htrans>& A) | |
| | | : U(A.m) | |
| | | , Q(const_cast<eT*>(U.M.memptr()), U.M.n_cols, U.M.n_rows, false, false | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return U.is_alias(X) | |
| | | ; } | |
| | | }; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_xtrans_vector< Op<T1, op_strans> > | |
| | | { | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | static const bool prefer_at_accessor = false; | |
| | | static const bool has_subview = quasi_unwrap<T1>::has_subview; | |
| | | static const bool is_fixed = false; | |
| | | | |
| | | arma_aligned const quasi_unwrap<T1> U; // avoid copy if T1 is a Row, Col | |
| | | or subview_col | |
| | | arma_aligned const Mat<eT> Q; | |
| | | | |
| | | inline Proxy_xtrans_vector(const Op<T1, op_strans>& A) | |
| | | : U(A.m) | |
| | | , Q(const_cast<eT*>(U.M.memptr()), U.M.n_cols, U.M.n_rows, false, false | |
| | | ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return U.is_alias(X) | |
| | | ; } | |
| | | }; | |
| | | | |
| | | template<typename T1, bool condition> | |
| | | struct Proxy_xtrans_redirect {}; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_xtrans_redirect<T1, false> { typedef Proxy_xtrans_default<T1> | |
| | | result; }; | |
| | | | |
| | | template<typename T1> | |
| | | struct Proxy_xtrans_redirect<T1, true> { typedef Proxy_xtrans_vector<T1> | |
| | | result; }; | |
| | | | |
| | | template<typename T1> | |
| | | class Proxy< Op<T1, op_htrans> > | |
| | | : public | |
| | | Proxy_xtrans_redirect | |
| | | < | |
| | | Op<T1, op_htrans>, | |
| | | ((is_complex<typename T1::elem_type>::value == false) && ((Op<T1, op_ | |
| | | htrans>::is_row) || (Op<T1, op_htrans>::is_col)) ) | |
| | | >::result | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef | |
| | | typename | |
| | | Proxy_xtrans_redirect | |
| | | < | |
| | | Op<T1, op_htrans>, | |
| | | ((is_complex<typename T1::elem_type>::value == false) && ((Op<T1, op_ht | |
| | | rans>::is_row) || (Op<T1, op_htrans>::is_col)) ) | |
| | | >::result | |
| | | Proxy_xtrans; | |
| | | | |
| | | typedef typename T1::elem_type elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | typedef Mat<elem_type> stored_type; | |
| | | typedef const elem_type* ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = Proxy_xtrans::prefer_at_accessor; | |
| | | static const bool has_subview = Proxy_xtrans::has_subview; | |
| | | static const bool is_fixed = Proxy_xtrans::is_fixed; | |
| | | | |
| | | // NOTE: the Op class takes care of swapping row and col for op_htrans | |
| | | static const bool is_row = Op<T1, op_htrans>::is_row; | |
| | | static const bool is_col = Op<T1, op_htrans>::is_col; | |
| | | | |
| | | using Proxy_xtrans::Q; | |
| | | | |
| | | inline explicit Proxy(const Op<T1, op_htrans>& A) | |
| | | : Proxy_xtrans(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } | |
| | | arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const | |
| | | { return Q[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword col) const | |
| | | { return Q.at(row, col); } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q.memptr(); } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return Proxy_xtrans: | |
| | | :is_alias(X); } | |
| | | }; | |
| | | | |
| | | template<typename T1> | |
| | | class Proxy< Op<T1, op_strans> > | |
| | | : public | |
| | | Proxy_xtrans_redirect | |
| | | < | |
| | | Op<T1, op_strans>, | |
| | | ( (Op<T1, op_strans>::is_row) || (Op<T1, op_strans>::is_col) ) | |
| | | >::result | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef | |
| | | typename | |
| | | Proxy_xtrans_redirect | |
| | | < | |
| | | Op<T1, op_strans>, | |
| | | ( (Op<T1, op_strans>::is_row) || (Op<T1, op_strans>::is_col) ) | |
| | | >::result | |
| | | Proxy_xtrans; | |
| | | | |
| | | typedef typename T1::elem_type elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | typedef Mat<elem_type> stored_type; | |
| | | typedef const elem_type* ea_type; | |
| | | | |
| | | static const bool prefer_at_accessor = Proxy_xtrans::prefer_at_accessor; | |
| | | static const bool has_subview = Proxy_xtrans::has_subview; | |
| | | static const bool is_fixed = Proxy_xtrans::is_fixed; | |
| | | | |
| | | // NOTE: the Op class takes care of swapping row and col for op_strans | |
| | | static const bool is_row = Op<T1, op_strans>::is_row; | |
| | | static const bool is_col = Op<T1, op_strans>::is_col; | |
| | | | |
| | | using Proxy_xtrans::Q; | |
| | | | |
| | | inline explicit Proxy(const Op<T1, op_strans>& A) | |
| | | : Proxy_xtrans(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline uword get_n_rows() const { return is_row ? 1 : Q.n_rows; } | |
| | | arma_inline uword get_n_cols() const { return is_col ? 1 : Q.n_cols; } | |
| | | arma_inline uword get_n_elem() const { return Q.n_elem; } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const | |
| | | { return Q[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword col) const | |
| | | { return Q.at(row, col); } | |
| | | | |
| | | arma_inline ea_type get_ea() const { return Q.memptr(); } | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return Proxy_xtrans: | |
| | | :is_alias(X); } | |
| | | }; | |
| | | | |
| template<typename T1, typename T2, typename glue_type> | | template<typename T1, typename T2, typename glue_type> | |
| class Proxy< Glue<T1, T2, glue_type> > | | class Proxy< Glue<T1, T2, glue_type> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef Mat<elem_type> stored_type; | | typedef Mat<elem_type> stored_type; | |
| typedef const elem_type* ea_type; | | typedef const elem_type* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = Glue<T1, T2, glue_type>::is_row; | | static const bool is_row = Glue<T1, T2, glue_type>::is_row; | |
| static const bool is_col = Glue<T1, T2, glue_type>::is_col; | | static const bool is_col = Glue<T1, T2, glue_type>::is_col; | |
| | | | |
| arma_aligned const Mat<elem_type> Q; | | arma_aligned const Mat<elem_type> Q; | |
| | | | |
| inline explicit Proxy(const Glue<T1, T2, glue_type>& A) | | inline explicit Proxy(const Glue<T1, T2, glue_type>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 316 | | skipping to change at line 514 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef subview<eT> stored_type; | | typedef subview<eT> stored_type; | |
| typedef const subview<eT>& ea_type; | | typedef const subview<eT>& ea_type; | |
| | | | |
| static const bool prefer_at_accessor = true; | | static const bool prefer_at_accessor = true; | |
| static const bool has_subview = true; | | static const bool has_subview = true; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = false; | | static const bool is_row = false; | |
| static const bool is_col = false; | | static const bool is_col = false; | |
| | | | |
| arma_aligned const subview<eT>& Q; | | arma_aligned const subview<eT>& Q; | |
| | | | |
| inline explicit Proxy(const subview<eT>& A) | | inline explicit Proxy(const subview<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 353 | | skipping to change at line 552 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef subview_col<eT> stored_type; | | typedef subview_col<eT> stored_type; | |
| typedef const eT* ea_type; | | typedef const eT* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = true; | | static const bool has_subview = true; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = false; | | static const bool is_row = false; | |
| static const bool is_col = true; | | static const bool is_col = true; | |
| | | | |
| arma_aligned const subview_col<eT>& Q; | | arma_aligned const subview_col<eT>& Q; | |
| | | | |
| inline explicit Proxy(const subview_col<eT>& A) | | inline explicit Proxy(const subview_col<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 390 | | skipping to change at line 590 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef subview_row<eT> stored_type; | | typedef subview_row<eT> stored_type; | |
| typedef const subview_row<eT>& ea_type; | | typedef const subview_row<eT>& ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = true; | | static const bool has_subview = true; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = true; | | static const bool is_row = true; | |
| static const bool is_col = false; | | static const bool is_col = false; | |
| | | | |
| arma_aligned const subview_row<eT>& Q; | | arma_aligned const subview_row<eT>& Q; | |
| | | | |
| inline explicit Proxy(const subview_row<eT>& A) | | inline explicit Proxy(const subview_row<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 427 | | skipping to change at line 628 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef Mat<eT> stored_type; | | typedef Mat<eT> stored_type; | |
| typedef const eT* ea_type; | | typedef const eT* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = false; | | static const bool is_row = false; | |
| static const bool is_col = true; | | static const bool is_col = true; | |
| | | | |
| arma_aligned const Mat<eT> Q; | | arma_aligned const Mat<eT> Q; | |
| | | | |
| inline explicit Proxy(const subview_elem1<eT,T1>& A) | | inline explicit Proxy(const subview_elem1<eT,T1>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 464 | | skipping to change at line 666 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef Mat<eT> stored_type; | | typedef Mat<eT> stored_type; | |
| typedef const eT* ea_type; | | typedef const eT* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = false; | | static const bool is_row = false; | |
| static const bool is_col = false; | | static const bool is_col = false; | |
| | | | |
| arma_aligned const Mat<eT> Q; | | arma_aligned const Mat<eT> Q; | |
| | | | |
| inline explicit Proxy(const subview_elem2<eT,T1,T2>& A) | | inline explicit Proxy(const subview_elem2<eT,T1,T2>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 501 | | skipping to change at line 704 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef diagview<eT> stored_type; | | typedef diagview<eT> stored_type; | |
| typedef const diagview<eT>& ea_type; | | typedef const diagview<eT>& ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = true; | | static const bool has_subview = true; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = false; | | static const bool is_row = false; | |
| static const bool is_col = true; | | static const bool is_col = true; | |
| | | | |
| arma_aligned const diagview<eT>& Q; | | arma_aligned const diagview<eT>& Q; | |
| | | | |
| inline explicit Proxy(const diagview<eT>& A) | | inline explicit Proxy(const diagview<eT>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 538 | | skipping to change at line 742 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef eOp<T1, eop_type> stored_type; | | typedef eOp<T1, eop_type> stored_type; | |
| typedef const eOp<T1, eop_type>& ea_type; | | typedef const eOp<T1, eop_type>& ea_type; | |
| | | | |
| static const bool prefer_at_accessor = eOp<T1, eop_type>::prefer_at_acces
sor; | | static const bool prefer_at_accessor = eOp<T1, eop_type>::prefer_at_acces
sor; | |
| static const bool has_subview = eOp<T1, eop_type>::has_subview; | | static const bool has_subview = eOp<T1, eop_type>::has_subview; | |
|
| | | static const bool is_fixed = eOp<T1, eop_type>::is_fixed; | |
| | | | |
| static const bool is_row = eOp<T1, eop_type>::is_row; | | static const bool is_row = eOp<T1, eop_type>::is_row; | |
| static const bool is_col = eOp<T1, eop_type>::is_col; | | static const bool is_col = eOp<T1, eop_type>::is_col; | |
| | | | |
| arma_aligned const eOp<T1, eop_type>& Q; | | arma_aligned const eOp<T1, eop_type>& Q; | |
| | | | |
| inline explicit Proxy(const eOp<T1, eop_type>& A) | | inline explicit Proxy(const eOp<T1, eop_type>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 575 | | skipping to change at line 780 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| typedef eGlue<T1, T2, eglue_type> stored_type; | | typedef eGlue<T1, T2, eglue_type> stored_type; | |
| typedef const eGlue<T1, T2, eglue_type>& ea_type; | | typedef const eGlue<T1, T2, eglue_type>& ea_type; | |
| | | | |
| static const bool prefer_at_accessor = eGlue<T1, T2, eglue_type>::prefer_
at_accessor; | | static const bool prefer_at_accessor = eGlue<T1, T2, eglue_type>::prefer_
at_accessor; | |
| static const bool has_subview = eGlue<T1, T2, eglue_type>::has_sub
view; | | static const bool has_subview = eGlue<T1, T2, eglue_type>::has_sub
view; | |
|
| | | static const bool is_fixed = eGlue<T1, T2, eglue_type>::is_fixe
d; | |
| | | | |
| static const bool is_row = eGlue<T1, T2, eglue_type>::is_row; | | static const bool is_row = eGlue<T1, T2, eglue_type>::is_row; | |
| static const bool is_col = eGlue<T1, T2, eglue_type>::is_col; | | static const bool is_col = eGlue<T1, T2, eglue_type>::is_col; | |
| | | | |
| arma_aligned const eGlue<T1, T2, eglue_type>& Q; | | arma_aligned const eGlue<T1, T2, eglue_type>& Q; | |
| | | | |
| inline explicit Proxy(const eGlue<T1, T2, eglue_type>& A) | | inline explicit Proxy(const eGlue<T1, T2, eglue_type>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 612 | | skipping to change at line 818 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef out_eT elem_type; | | typedef out_eT elem_type; | |
| typedef typename get_pod_type<out_eT>::result pod_type; | | typedef typename get_pod_type<out_eT>::result pod_type; | |
| typedef Mat<out_eT> stored_type; | | typedef Mat<out_eT> stored_type; | |
| typedef const elem_type* ea_type; | | typedef const elem_type* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = mtOp<out_eT, T1, op_type>::is_row; | | static const bool is_row = mtOp<out_eT, T1, op_type>::is_row; | |
| static const bool is_col = mtOp<out_eT, T1, op_type>::is_col; | | static const bool is_col = mtOp<out_eT, T1, op_type>::is_col; | |
| | | | |
| arma_aligned const Mat<out_eT> Q; | | arma_aligned const Mat<out_eT> Q; | |
| | | | |
| inline explicit Proxy(const mtOp<out_eT, T1, op_type>& A) | | inline explicit Proxy(const mtOp<out_eT, T1, op_type>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 649 | | skipping to change at line 856 | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef out_eT elem_type; | | typedef out_eT elem_type; | |
| typedef typename get_pod_type<out_eT>::result pod_type; | | typedef typename get_pod_type<out_eT>::result pod_type; | |
| typedef Mat<out_eT> stored_type; | | typedef Mat<out_eT> stored_type; | |
| typedef const elem_type* ea_type; | | typedef const elem_type* ea_type; | |
| | | | |
| static const bool prefer_at_accessor = false; | | static const bool prefer_at_accessor = false; | |
| static const bool has_subview = false; | | static const bool has_subview = false; | |
|
| | | static const bool is_fixed = false; | |
| | | | |
| static const bool is_row = mtGlue<out_eT, T1, T2, glue_type>::is_row; | | static const bool is_row = mtGlue<out_eT, T1, T2, glue_type>::is_row; | |
| static const bool is_col = mtGlue<out_eT, T1, T2, glue_type>::is_col; | | static const bool is_col = mtGlue<out_eT, T1, T2, glue_type>::is_col; | |
| | | | |
| arma_aligned const Mat<out_eT> Q; | | arma_aligned const Mat<out_eT> Q; | |
| | | | |
| inline explicit Proxy(const mtGlue<out_eT, T1, T2, glue_type>& A) | | inline explicit Proxy(const mtGlue<out_eT, T1, T2, glue_type>& A) | |
| : Q(A) | | : Q(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
End of changes. 27 change blocks. |
| 19 lines changed or deleted | | 246 lines changed or added | |
|
| auxlib_meat.hpp | | auxlib_meat.hpp | |
| // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | | // Copyright (C) 2008-2012 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2008-2012 Conrad Sanderson | | // Copyright (C) 2008-2012 Conrad Sanderson | |
| // Copyright (C) 2009 Edmund Highcock | | // Copyright (C) 2009 Edmund Highcock | |
| // Copyright (C) 2011 James Sanders | | // Copyright (C) 2011 James Sanders | |
| // Copyright (C) 2011 Stanislav Funiak | | // Copyright (C) 2011 Stanislav Funiak | |
|
| | | // Copyright (C) 2012 Eric Jon Sundstrom | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| | | | |
| skipping to change at line 1128 | | skipping to change at line 1129 | |
| Mat<eT> A(X.get_ref()); | | Mat<eT> A(X.get_ref()); | |
| | | | |
| arma_debug_check( (A.is_square() == false), "eig_sym(): given matrix is
not square"); | | arma_debug_check( (A.is_square() == false), "eig_sym(): given matrix is
not square"); | |
| | | | |
| if(A.is_empty()) | | if(A.is_empty()) | |
| { | | { | |
| eigval.reset(); | | eigval.reset(); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| // rudimentary "better-than-nothing" test for symmetry | | eigval.set_size(A.n_rows); | |
| //arma_debug_check( (A.at(A.n_rows-1, 0) != A.at(0, A.n_cols-1)), "auxl | | | |
| ib::eig(): given matrix is not symmetric" ); | | | |
| | | | |
| char jobz = 'N'; | | char jobz = 'N'; | |
| char uplo = 'U'; | | char uplo = 'U'; | |
| | | | |
|
| blas_int n_rows = A.n_rows; | | blas_int N = blas_int(A.n_rows); | |
| blas_int lwork = (std::max)(blas_int(1), 3*n_rows-1) + 2; // +2 for p | | blas_int lwork = 2*((std::max)(blas_int(1), 3*N-1)); | |
| aranoia: some versions of Lapack might be trashing memory | | blas_int info = 0; | |
| | | | |
|
| eigval.set_size( static_cast<uword>(n_rows) ); | | | |
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | | |
|
| blas_int info = 0; | | | |
| | | | |
| arma_extra_debug_print("lapack::syev()"); | | arma_extra_debug_print("lapack::syev()"); | |
|
| lapack::syev(&jobz, &uplo, &n_rows, A.memptr(), &n_rows, eigval.memptr(
), work.memptr(), &lwork, &info); | | lapack::syev(&jobz, &uplo, &N, A.memptr(), &N, eigval.memptr(), work.me
mptr(), &lwork, &info); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(eigval); | | arma_ignore(eigval); | |
| arma_ignore(X); | | arma_ignore(X); | |
| arma_stop("eig_sym(): use of LAPACK needs to be enabled"); | | arma_stop("eig_sym(): use of LAPACK needs to be enabled"); | |
| return false; | | return false; | |
| } | | } | |
| | | | |
| skipping to change at line 1170 | | skipping to change at line 1168 | |
| bool | | bool | |
| auxlib::eig_sym(Col<T>& eigval, const Base<std::complex<T>,T1>& X) | | auxlib::eig_sym(Col<T>& eigval, const Base<std::complex<T>,T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename std::complex<T> eT; | | typedef typename std::complex<T> eT; | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| Mat<eT> A(X.get_ref()); | | Mat<eT> A(X.get_ref()); | |
|
| arma_debug_check( (A.is_square() == false), "eig_sym(): given matrix is | | | |
| not hermitian"); | | arma_debug_check( (A.is_square() == false), "eig_sym(): given matrix is | |
| | | not square"); | |
| | | | |
| if(A.is_empty()) | | if(A.is_empty()) | |
| { | | { | |
| eigval.reset(); | | eigval.reset(); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| | | eigval.set_size(A.n_rows); | |
| | | | |
| char jobz = 'N'; | | char jobz = 'N'; | |
| char uplo = 'U'; | | char uplo = 'U'; | |
| | | | |
|
| blas_int n_rows = A.n_rows; | | blas_int N = blas_int(A.n_rows); | |
| blas_int lda = A.n_rows; | | blas_int lwork = 2*((std::max)(blas_int(1), 2*N-1)); | |
| blas_int lwork = (std::max)(blas_int(1), 2*n_rows - 1) + 2; // +2 for | | blas_int info = 0; | |
| paranoia: some versions of Lapack might be trashing memory | | | |
| // TODO: automatically find best size of lwork | | | |
| | | | |
| eigval.set_size( static_cast<uword>(n_rows) ); | | | |
| | | | |
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
|
| podarray<T> rwork( static_cast<uword>((std::max)(blas_int(1), 3*n_rows | | podarray<T> rwork( static_cast<uword>( (std::max)(blas_int(1), 3*N-2) | |
| - 2)) ); | | ) ); | |
| | | | |
| blas_int info = 0; | | | |
| | | | |
| arma_extra_debug_print("lapack::heev()"); | | arma_extra_debug_print("lapack::heev()"); | |
|
| lapack::heev(&jobz, &uplo, &n_rows, A.memptr(), &lda, eigval.memptr(),
work.memptr(), &lwork, rwork.memptr(), &info); | | lapack::heev(&jobz, &uplo, &N, A.memptr(), &N, eigval.memptr(), work.me
mptr(), &lwork, rwork.memptr(), &info); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(eigval); | | arma_ignore(eigval); | |
| arma_ignore(X); | | arma_ignore(X); | |
| arma_stop("eig_sym(): use of LAPACK needs to be enabled"); | | arma_stop("eig_sym(): use of LAPACK needs to be enabled"); | |
| return false; | | return false; | |
| } | | } | |
| | | | |
| skipping to change at line 1229 | | skipping to change at line 1225 | |
| | | | |
| arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matr
ix is not square" ); | | arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matr
ix is not square" ); | |
| | | | |
| if(eigvec.is_empty()) | | if(eigvec.is_empty()) | |
| { | | { | |
| eigval.reset(); | | eigval.reset(); | |
| eigvec.reset(); | | eigvec.reset(); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| // rudimentary "better-than-nothing" test for symmetry | | eigval.set_size(eigvec.n_rows); | |
| //arma_debug_check( (A.at(A.n_rows-1, 0) != A.at(0, A.n_cols-1)), "auxl | | | |
| ib::eig(): given matrix is not symmetric" ); | | | |
| | | | |
| char jobz = 'V'; | | char jobz = 'V'; | |
| char uplo = 'U'; | | char uplo = 'U'; | |
| | | | |
|
| blas_int n_rows = eigvec.n_rows; | | blas_int N = blas_int(eigvec.n_rows); | |
| blas_int lwork = (std::max)(blas_int(1), 3*n_rows-1) + 2; // +2 for p | | blas_int lwork = 2*((std::max)(blas_int(1), 3*N-1)); | |
| aranoia: some versions of Lapack might be trashing memory | | blas_int info = 0; | |
| | | | |
|
| eigval.set_size( static_cast<uword>(n_rows) ); | | | |
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | | |
|
| blas_int info = 0; | | | |
| | | | |
| arma_extra_debug_print("lapack::syev()"); | | arma_extra_debug_print("lapack::syev()"); | |
|
| lapack::syev(&jobz, &uplo, &n_rows, eigvec.memptr(), &n_rows, eigval.me
mptr(), work.memptr(), &lwork, &info); | | lapack::syev(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), wo
rk.memptr(), &lwork, &info); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(eigval); | | arma_ignore(eigval); | |
| arma_ignore(eigvec); | | arma_ignore(eigvec); | |
| arma_ignore(X); | | arma_ignore(X); | |
|
| | | | |
| arma_stop("eig_sym(): use of LAPACK needs to be enabled"); | | arma_stop("eig_sym(): use of LAPACK needs to be enabled"); | |
|
| | | | |
| return false; | | return false; | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| //! immediate eigenvalues and eigenvectors of a hermitian complex matrix us
ing LAPACK | | //! immediate eigenvalues and eigenvectors of a hermitian complex matrix us
ing LAPACK | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::eig_sym(Col<T>& eigval, Mat< std::complex<T> >& eigvec, const Base<
std::complex<T>,T1>& X) | | auxlib::eig_sym(Col<T>& eigval, Mat< std::complex<T> >& eigvec, const Base<
std::complex<T>,T1>& X) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename std::complex<T> eT; | | typedef typename std::complex<T> eT; | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| eigvec = X.get_ref(); | | eigvec = X.get_ref(); | |
| | | | |
|
| arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matr
ix is not hermitian" ); | | arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matr
ix is not square" ); | |
| | | | |
| if(eigvec.is_empty()) | | if(eigvec.is_empty()) | |
| { | | { | |
| eigval.reset(); | | eigval.reset(); | |
| eigvec.reset(); | | eigvec.reset(); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| | | eigval.set_size(eigvec.n_rows); | |
| | | | |
| char jobz = 'V'; | | char jobz = 'V'; | |
| char uplo = 'U'; | | char uplo = 'U'; | |
| | | | |
|
| blas_int n_rows = eigvec.n_rows; | | blas_int N = blas_int(eigvec.n_rows); | |
| blas_int lda = eigvec.n_rows; | | blas_int lwork = 2*((std::max)(blas_int(1), 2*N-1)); | |
| blas_int lwork = (std::max)(blas_int(1), 2*n_rows - 1) + 2; // +2 for | | blas_int info = 0; | |
| paranoia: some versions of Lapack might be trashing memory | | | |
| // TODO: automatically find best size of lwork | | | |
| | | | |
|
| eigval.set_size( static_cast<uword>(n_rows) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | podarray<T> rwork( static_cast<uword>((std::max)(blas_int(1), 3*N-2)) | |
| | | ); | |
| | | | |
|
| podarray<eT> work( static_cast<uword>(lwork) ); | | arma_extra_debug_print("lapack::heev()"); | |
| podarray<T> rwork( static_cast<uword>((std::max)(blas_int(1), 3*n_rows | | lapack::heev(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), wo | |
| - 2)) ); | | rk.memptr(), &lwork, rwork.memptr(), &info); | |
| | | | |
|
| blas_int info = 0; | | return (info == 0); | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_ignore(eigval); | |
| | | arma_ignore(eigvec); | |
| | | arma_ignore(X); | |
| | | arma_stop("eig_sym(): use of LAPACK needs to be enabled"); | |
| | | return false; | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
|
| arma_extra_debug_print("lapack::heev()"); | | //! immediate eigenvalues and eigenvectors of a symmetric real matrix using | |
| lapack::heev(&jobz, &uplo, &n_rows, eigvec.memptr(), &lda, eigval.mempt | | LAPACK (divide and conquer algorithm) | |
| r(), work.memptr(), &lwork, rwork.memptr(), &info); | | template<typename eT, typename T1> | |
| | | inline | |
| | | bool | |
| | | auxlib::eig_sym_dc(Col<eT>& eigval, Mat<eT>& eigvec, const Base<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_LAPACK) | |
| | | { | |
| | | eigvec = X.get_ref(); | |
| | | | |
| | | arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matr | |
| | | ix is not square" ); | |
| | | | |
| | | if(eigvec.is_empty()) | |
| | | { | |
| | | eigval.reset(); | |
| | | eigvec.reset(); | |
| | | return true; | |
| | | } | |
| | | | |
| | | eigval.set_size(eigvec.n_rows); | |
| | | | |
| | | char jobz = 'V'; | |
| | | char uplo = 'U'; | |
| | | | |
| | | blas_int N = blas_int(eigvec.n_rows); | |
| | | blas_int lwork = 2*(1 + 6*N + 2*(N*N)); | |
| | | blas_int liwork = 2*(3 + 5*N + 2); | |
| | | blas_int info = 0; | |
| | | | |
| | | podarray<eT> work( static_cast<uword>( lwork) ); | |
| | | podarray<blas_int> iwork( static_cast<uword>(liwork) ); | |
| | | | |
| | | arma_extra_debug_print("lapack::syevd()"); | |
| | | lapack::syevd(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), w | |
| | | ork.memptr(), &lwork, iwork.memptr(), &liwork, &info); | |
| | | | |
| | | return (info == 0); | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_ignore(eigval); | |
| | | arma_ignore(eigvec); | |
| | | arma_ignore(X); | |
| | | arma_stop("eig_sym(): use of LAPACK needs to be enabled"); | |
| | | return false; | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| | | //! immediate eigenvalues and eigenvectors of a hermitian complex matrix us | |
| | | ing LAPACK (divide and conquer algorithm) | |
| | | template<typename T, typename T1> | |
| | | inline | |
| | | bool | |
| | | auxlib::eig_sym_dc(Col<T>& eigval, Mat< std::complex<T> >& eigvec, const Ba | |
| | | se<std::complex<T>,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | typedef typename std::complex<T> eT; | |
| | | | |
| | | #if defined(ARMA_USE_LAPACK) | |
| | | { | |
| | | eigvec = X.get_ref(); | |
| | | | |
| | | arma_debug_check( (eigvec.is_square() == false), "eig_sym(): given matr | |
| | | ix is not square" ); | |
| | | | |
| | | if(eigvec.is_empty()) | |
| | | { | |
| | | eigval.reset(); | |
| | | eigvec.reset(); | |
| | | return true; | |
| | | } | |
| | | | |
| | | eigval.set_size(eigvec.n_rows); | |
| | | | |
| | | char jobz = 'V'; | |
| | | char uplo = 'U'; | |
| | | | |
| | | blas_int N = blas_int(eigvec.n_rows); | |
| | | blas_int lwork = 2*(2*N + N*N); | |
| | | blas_int lrwork = 2*(1 + 5*N + 2*(N*N)); | |
| | | blas_int liwork = 2*(3 + 5*N); | |
| | | blas_int info = 0; | |
| | | | |
| | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | podarray<T> rwork( static_cast<uword>(lrwork) ); | |
| | | podarray<blas_int> iwork( static_cast<uword>(liwork) ); | |
| | | | |
| | | arma_extra_debug_print("lapack::heevd()"); | |
| | | lapack::heevd(&jobz, &uplo, &N, eigvec.memptr(), &N, eigval.memptr(), w | |
| | | ork.memptr(), &lwork, rwork.memptr(), &lrwork, iwork.memptr(), &liwork, &in | |
| | | fo); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(eigval); | | arma_ignore(eigval); | |
| arma_ignore(eigvec); | | arma_ignore(eigvec); | |
| arma_ignore(X); | | arma_ignore(X); | |
| arma_stop("eig_sym(): use of LAPACK needs to be enabled"); | | arma_stop("eig_sym(): use of LAPACK needs to be enabled"); | |
| return false; | | return false; | |
| | | | |
| skipping to change at line 1323 | | skipping to change at line 1415 | |
| } | | } | |
| | | | |
| //! Eigenvalues and eigenvectors of a general square real matrix using LAPA
CK. | | //! Eigenvalues and eigenvectors of a general square real matrix using LAPA
CK. | |
| //! The argument 'side' specifies which eigenvectors should be calculated | | //! The argument 'side' specifies which eigenvectors should be calculated | |
| //! (see code for mode details). | | //! (see code for mode details). | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::eig_gen | | auxlib::eig_gen | |
| ( | | ( | |
|
| Col< std::complex<T> >& eigval, | | Col< std::complex<T> >& eigval, | |
| Mat<T>& l_eigvec, | | Mat<T>& l_eigvec, | |
| Mat<T>& r_eigvec, | | Mat<T>& r_eigvec, | |
| const Base<T,T1>& X, | | const Base<T,T1>& X, | |
| const char side | | const char side | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| char jobvl; | | char jobvl; | |
| char jobvr; | | char jobvr; | |
| | | | |
| switch(side) | | switch(side) | |
| | | | |
| skipping to change at line 1375 | | skipping to change at line 1467 | |
| arma_debug_check( (A.is_square() == false), "eig_gen(): given matrix is
not square" ); | | arma_debug_check( (A.is_square() == false), "eig_gen(): given matrix is
not square" ); | |
| | | | |
| if(A.is_empty()) | | if(A.is_empty()) | |
| { | | { | |
| eigval.reset(); | | eigval.reset(); | |
| l_eigvec.reset(); | | l_eigvec.reset(); | |
| r_eigvec.reset(); | | r_eigvec.reset(); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| | | | |
| blas_int n_rows = A_n_rows; | | | |
| blas_int lda = A_n_rows; | | | |
| blas_int lwork = (std::max)(blas_int(1), 4*n_rows) + 2; // +2 for par | | | |
| anoia: some versions of Lapack might be trashing memory | | | |
| // TODO: automatically find best size of lwork | | | |
| | | | |
| eigval.set_size(A_n_rows); | | eigval.set_size(A_n_rows); | |
|
| | | | |
| l_eigvec.set_size(A_n_rows, A_n_rows); | | l_eigvec.set_size(A_n_rows, A_n_rows); | |
| r_eigvec.set_size(A_n_rows, A_n_rows); | | r_eigvec.set_size(A_n_rows, A_n_rows); | |
| | | | |
|
| podarray<T> work( static_cast<uword>(lwork) ); | | blas_int N = blas_int(A_n_rows); | |
| podarray<T> rwork( static_cast<uword>((std::max)(blas_int(1), 3*n_rows) | | blas_int lwork = 2*((std::max)(blas_int(1), 4*N)); | |
| ) ); | | blas_int info = 0; | |
| | | | |
| | | podarray<T> work( static_cast<uword>(lwork) ); | |
| | | | |
| podarray<T> wr(A_n_rows); | | podarray<T> wr(A_n_rows); | |
| podarray<T> wi(A_n_rows); | | podarray<T> wi(A_n_rows); | |
| | | | |
|
| blas_int info = 0; | | | |
| | | | |
| arma_extra_debug_print("lapack::geev()"); | | arma_extra_debug_print("lapack::geev()"); | |
|
| lapack::geev(&jobvl, &jobvr, &n_rows, A.memptr(), &lda, wr.memptr(), wi
.memptr(), l_eigvec.memptr(), &n_rows, r_eigvec.memptr(), &n_rows, work.mem
ptr(), &lwork, &info); | | lapack::geev(&jobvl, &jobvr, &N, A.memptr(), &N, wr.memptr(), wi.memptr
(), l_eigvec.memptr(), &N, r_eigvec.memptr(), &N, work.memptr(), &lwork, &i
nfo); | |
| | | | |
| eigval.set_size(A_n_rows); | | eigval.set_size(A_n_rows); | |
| for(uword i=0; i<A_n_rows; ++i) | | for(uword i=0; i<A_n_rows; ++i) | |
| { | | { | |
| eigval[i] = std::complex<T>(wr[i], wi[i]); | | eigval[i] = std::complex<T>(wr[i], wi[i]); | |
| } | | } | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| | | | |
| skipping to change at line 1426 | | skipping to change at line 1515 | |
| } | | } | |
| | | | |
| //! Eigenvalues and eigenvectors of a general square complex matrix using L
APACK | | //! Eigenvalues and eigenvectors of a general square complex matrix using L
APACK | |
| //! The argument 'side' specifies which eigenvectors should be calculated | | //! The argument 'side' specifies which eigenvectors should be calculated | |
| //! (see code for mode details). | | //! (see code for mode details). | |
| template<typename T, typename T1> | | template<typename T, typename T1> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::eig_gen | | auxlib::eig_gen | |
| ( | | ( | |
|
| Col< std::complex<T> >& eigval, | | Col< std::complex<T> >& eigval, | |
| Mat< std::complex<T> >& l_eigvec, | | Mat< std::complex<T> >& l_eigvec, | |
| Mat< std::complex<T> >& r_eigvec, | | Mat< std::complex<T> >& r_eigvec, | |
| const Base< std::complex<T>, T1 >& X, | | const Base< std::complex<T>, T1 >& X, | |
|
| const char side | | const char side | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename std::complex<T> eT; | | typedef typename std::complex<T> eT; | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| char jobvl; | | char jobvl; | |
| char jobvr; | | char jobvr; | |
| | | | |
| skipping to change at line 1480 | | skipping to change at line 1569 | |
| arma_debug_check( (A.is_square() == false), "eig_gen(): given matrix is
not square" ); | | arma_debug_check( (A.is_square() == false), "eig_gen(): given matrix is
not square" ); | |
| | | | |
| if(A.is_empty()) | | if(A.is_empty()) | |
| { | | { | |
| eigval.reset(); | | eigval.reset(); | |
| l_eigvec.reset(); | | l_eigvec.reset(); | |
| r_eigvec.reset(); | | r_eigvec.reset(); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
|
| uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| | | | |
| blas_int n_rows = A_n_rows; | | | |
| blas_int lda = A_n_rows; | | | |
| blas_int lwork = (std::max)(blas_int(1), 4*n_rows) + 2; // +2 for par | | | |
| anoia: some versions of Lapack might be trashing memory | | | |
| // TODO: automatically find best size of lwork | | | |
| | | | |
| eigval.set_size(A_n_rows); | | eigval.set_size(A_n_rows); | |
|
| | | | |
| l_eigvec.set_size(A_n_rows, A_n_rows); | | l_eigvec.set_size(A_n_rows, A_n_rows); | |
| r_eigvec.set_size(A_n_rows, A_n_rows); | | r_eigvec.set_size(A_n_rows, A_n_rows); | |
| | | | |
|
| podarray<eT> work( static_cast<uword>(lwork) ); | | blas_int N = blas_int(A_n_rows); | |
| podarray<T> rwork( static_cast<uword>((std::max)(blas_int(1), 3*n_rows | | blas_int lwork = 2*((std::max)(blas_int(1), 2*N)); | |
| )) ); // was 2,3 | | blas_int info = 0; | |
| | | | |
|
| blas_int info = 0; | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | podarray<T> rwork( static_cast<uword>(2*N) ); | |
| | | | |
| arma_extra_debug_print("lapack::cx_geev()"); | | arma_extra_debug_print("lapack::cx_geev()"); | |
|
| lapack::cx_geev(&jobvl, &jobvr, &n_rows, A.memptr(), &lda, eigval.mempt
r(), l_eigvec.memptr(), &n_rows, r_eigvec.memptr(), &n_rows, work.memptr(),
&lwork, rwork.memptr(), &info); | | lapack::cx_geev(&jobvl, &jobvr, &N, A.memptr(), &N, eigval.memptr(), l_
eigvec.memptr(), &N, r_eigvec.memptr(), &N, work.memptr(), &lwork, rwork.me
mptr(), &info); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(eigval); | | arma_ignore(eigval); | |
| arma_ignore(l_eigvec); | | arma_ignore(l_eigvec); | |
| arma_ignore(r_eigvec); | | arma_ignore(r_eigvec); | |
| arma_ignore(X); | | arma_ignore(X); | |
| arma_ignore(side); | | arma_ignore(side); | |
| | | | |
| skipping to change at line 1536 | | skipping to change at line 1623 | |
| | | | |
| if(out.is_empty()) | | if(out.is_empty()) | |
| { | | { | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| const uword out_n_rows = out.n_rows; | | const uword out_n_rows = out.n_rows; | |
| | | | |
| char uplo = 'U'; | | char uplo = 'U'; | |
| blas_int n = out_n_rows; | | blas_int n = out_n_rows; | |
|
| blas_int info; | | blas_int info = 0; | |
| | | | |
| lapack::potrf(&uplo, &n, out.memptr(), &n, &info); | | lapack::potrf(&uplo, &n, out.memptr(), &n, &info); | |
| | | | |
| for(uword col=0; col<out_n_rows; ++col) | | for(uword col=0; col<out_n_rows; ++col) | |
| { | | { | |
| eT* colptr = out.colptr(col); | | eT* colptr = out.colptr(col); | |
| | | | |
| for(uword row=(col+1); row < out_n_rows; ++row) | | for(uword row=(col+1); row < out_n_rows; ++row) | |
| { | | { | |
| colptr[row] = eT(0); | | colptr[row] = eT(0); | |
| | | | |
| skipping to change at line 1791 | | skipping to change at line 1878 | |
| blas_int m = A.n_rows; | | blas_int m = A.n_rows; | |
| blas_int n = A.n_cols; | | blas_int n = A.n_cols; | |
| blas_int lda = A.n_rows; | | blas_int lda = A.n_rows; | |
| blas_int ldu = U.n_rows; | | blas_int ldu = U.n_rows; | |
| blas_int ldvt = V.n_rows; | | blas_int ldvt = V.n_rows; | |
| blas_int lwork = 2 * (std::max)(blas_int(1), 2*(std::min)(m,n)+(std::m
ax)(m,n) ); | | blas_int lwork = 2 * (std::max)(blas_int(1), 2*(std::min)(m,n)+(std::m
ax)(m,n) ); | |
| blas_int info = 0; | | blas_int info = 0; | |
| | | | |
| S.set_size( static_cast<uword>((std::min)(m,n)) ); | | S.set_size( static_cast<uword>((std::min)(m,n)) ); | |
| | | | |
|
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| podarray<T> rwork( static_cast<uword>(5*(std::min)(m,n)) ); | | podarray< T> rwork( static_cast<uword>(5*(std::min)(m,n)) ); | |
| | | | |
| // let gesvd_() calculate the optimum size of the workspace | | // let gesvd_() calculate the optimum size of the workspace | |
| blas_int lwork_tmp = -1; | | blas_int lwork_tmp = -1; | |
| | | | |
| lapack::cx_gesvd<T> | | lapack::cx_gesvd<T> | |
| ( | | ( | |
| &jobu, &jobvt, | | &jobu, &jobvt, | |
| &m, &n, | | &m, &n, | |
| A.memptr(), &lda, | | A.memptr(), &lda, | |
| S.memptr(), | | S.memptr(), | |
| | | | |
| skipping to change at line 1895 | | skipping to change at line 1982 | |
| V.eye(A.n_cols, A.n_cols); | | V.eye(A.n_cols, A.n_cols); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| U.set_size(A.n_rows, A.n_rows); | | U.set_size(A.n_rows, A.n_rows); | |
| V.set_size(A.n_cols, A.n_cols); | | V.set_size(A.n_cols, A.n_cols); | |
| | | | |
| char jobu = 'A'; | | char jobu = 'A'; | |
| char jobvt = 'A'; | | char jobvt = 'A'; | |
| | | | |
|
| blas_int m = A.n_rows; | | blas_int m = blas_int(A.n_rows); | |
| blas_int n = A.n_cols; | | blas_int n = blas_int(A.n_cols); | |
| blas_int lda = A.n_rows; | | blas_int lda = blas_int(A.n_rows); | |
| blas_int ldu = U.n_rows; | | blas_int ldu = blas_int(U.n_rows); | |
| blas_int ldvt = V.n_rows; | | blas_int ldvt = blas_int(V.n_rows); | |
| blas_int lwork = 2 * (std::max)(blas_int(1), (std::max)( (3*(std::min)
(m,n) + (std::max)(m,n)), 5*(std::min)(m,n) ) ); | | blas_int lwork = 2 * (std::max)(blas_int(1), (std::max)( (3*(std::min)
(m,n) + (std::max)(m,n)), 5*(std::min)(m,n) ) ); | |
| blas_int info = 0; | | blas_int info = 0; | |
| | | | |
| S.set_size( static_cast<uword>((std::min)(m,n)) ); | | S.set_size( static_cast<uword>((std::min)(m,n)) ); | |
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | | |
| // let gesvd_() calculate the optimum size of the workspace | | // let gesvd_() calculate the optimum size of the workspace | |
| blas_int lwork_tmp = -1; | | blas_int lwork_tmp = -1; | |
| | | | |
| lapack::gesvd<eT> | | lapack::gesvd<eT> | |
| | | | |
| skipping to change at line 1986 | | skipping to change at line 2073 | |
| V.eye(A.n_cols, A.n_cols); | | V.eye(A.n_cols, A.n_cols); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| U.set_size(A.n_rows, A.n_rows); | | U.set_size(A.n_rows, A.n_rows); | |
| V.set_size(A.n_cols, A.n_cols); | | V.set_size(A.n_cols, A.n_cols); | |
| | | | |
| char jobu = 'A'; | | char jobu = 'A'; | |
| char jobvt = 'A'; | | char jobvt = 'A'; | |
| | | | |
|
| blas_int m = A.n_rows; | | blas_int m = blas_int(A.n_rows); | |
| blas_int n = A.n_cols; | | blas_int n = blas_int(A.n_cols); | |
| blas_int lda = A.n_rows; | | blas_int lda = blas_int(A.n_rows); | |
| blas_int ldu = U.n_rows; | | blas_int ldu = blas_int(U.n_rows); | |
| blas_int ldvt = V.n_rows; | | blas_int ldvt = blas_int(V.n_rows); | |
| blas_int lwork = 2 * (std::max)(blas_int(1), 2*(std::min)(m,n)+(std::m
ax)(m,n) ); | | blas_int lwork = 2 * (std::max)(blas_int(1), 2*(std::min)(m,n)+(std::m
ax)(m,n) ); | |
| blas_int info = 0; | | blas_int info = 0; | |
| | | | |
| S.set_size( static_cast<uword>((std::min)(m,n)) ); | | S.set_size( static_cast<uword>((std::min)(m,n)) ); | |
| | | | |
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| podarray<T> rwork( static_cast<uword>(5*(std::min)(m,n)) ); | | podarray<T> rwork( static_cast<uword>(5*(std::min)(m,n)) ); | |
| | | | |
| // let gesvd_() calculate the optimum size of the workspace | | // let gesvd_() calculate the optimum size of the workspace | |
| blas_int lwork_tmp = -1; | | blas_int lwork_tmp = -1; | |
| | | | |
| skipping to change at line 2065 | | skipping to change at line 2152 | |
| inline | | inline | |
| bool | | bool | |
| auxlib::svd_econ(Mat<eT>& U, Col<eT>& S, Mat<eT>& V, const Base<eT,T1>& X,
const char mode) | | auxlib::svd_econ(Mat<eT>& U, Col<eT>& S, Mat<eT>& V, const Base<eT,T1>& X,
const char mode) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| Mat<eT> A(X.get_ref()); | | Mat<eT> A(X.get_ref()); | |
| | | | |
|
| blas_int m = A.n_rows; | | blas_int m = blas_int(A.n_rows); | |
| blas_int n = A.n_cols; | | blas_int n = blas_int(A.n_cols); | |
| blas_int lda = A.n_rows; | | blas_int lda = blas_int(A.n_rows); | |
| | | | |
| S.set_size( static_cast<uword>((std::min)(m,n)) ); | | S.set_size( static_cast<uword>((std::min)(m,n)) ); | |
| | | | |
| blas_int ldu = 0; | | blas_int ldu = 0; | |
| blas_int ldvt = 0; | | blas_int ldvt = 0; | |
| | | | |
| char jobu; | | char jobu; | |
| char jobvt; | | char jobvt; | |
| | | | |
| switch(mode) | | switch(mode) | |
| | | | |
| skipping to change at line 2202 | | skipping to change at line 2289 | |
| auxlib::svd_econ(Mat< std::complex<T> >& U, Col<T>& S, Mat< std::complex<T>
>& V, const Base< std::complex<T>, T1>& X, const char mode) | | auxlib::svd_econ(Mat< std::complex<T> >& U, Col<T>& S, Mat< std::complex<T>
>& V, const Base< std::complex<T>, T1>& X, const char mode) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef std::complex<T> eT; | | typedef std::complex<T> eT; | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
| Mat<eT> A(X.get_ref()); | | Mat<eT> A(X.get_ref()); | |
| | | | |
|
| blas_int m = A.n_rows; | | blas_int m = blas_int(A.n_rows); | |
| blas_int n = A.n_cols; | | blas_int n = blas_int(A.n_cols); | |
| blas_int lda = A.n_rows; | | blas_int lda = blas_int(A.n_rows); | |
| | | | |
| S.set_size( static_cast<uword>((std::min)(m,n)) ); | | S.set_size( static_cast<uword>((std::min)(m,n)) ); | |
| | | | |
| blas_int ldu = 0; | | blas_int ldu = 0; | |
| blas_int ldvt = 0; | | blas_int ldvt = 0; | |
| | | | |
| char jobu; | | char jobu; | |
| char jobvt; | | char jobvt; | |
| | | | |
| switch(mode) | | switch(mode) | |
| | | | |
| skipping to change at line 2338 | | skipping to change at line 2425 | |
| | | | |
| //! Solve a system of linear equations. | | //! Solve a system of linear equations. | |
| //! Assumes that A.n_rows = A.n_cols and B.n_rows = A.n_rows | | //! Assumes that A.n_rows = A.n_cols and B.n_rows = A.n_rows | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::solve(Mat<eT>& out, Mat<eT>& A, const Mat<eT>& B, const bool slow) | | auxlib::solve(Mat<eT>& out, Mat<eT>& A, const Mat<eT>& B, const bool slow) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| | | const uword A_n_rows = A.n_rows; | |
| | | const uword B_n_cols = B.n_cols; | |
| | | | |
| if(A.is_empty() || B.is_empty()) | | if(A.is_empty() || B.is_empty()) | |
| { | | { | |
|
| out.zeros(A.n_cols, B.n_cols); | | out.zeros(A.n_cols, B_n_cols); | |
| return true; | | return true; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| const uword A_n_rows = A.n_rows; | | | |
| | | | |
| bool status = false; | | bool status = false; | |
| | | | |
| if( (A_n_rows <= 4) && (slow == false) ) | | if( (A_n_rows <= 4) && (slow == false) ) | |
| { | | { | |
| Mat<eT> A_inv; | | Mat<eT> A_inv; | |
| | | | |
| status = auxlib::inv_noalias_tinymat(A_inv, A, A_n_rows); | | status = auxlib::inv_noalias_tinymat(A_inv, A, A_n_rows); | |
| | | | |
| if(status == true) | | if(status == true) | |
| { | | { | |
|
| out.set_size(A_n_rows, B.n_cols); | | out.set_size(A_n_rows, B_n_cols); | |
| | | | |
| gemm_emul<false,false,false,false>::apply(out, A_inv, B); | | gemm_emul<false,false,false,false>::apply(out, A_inv, B); | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| } | | } | |
| | | | |
| if( (A_n_rows > 4) || (status == false) ) | | if( (A_n_rows > 4) || (status == false) ) | |
| { | | { | |
| #if defined(ARMA_USE_ATLAS) | | #if defined(ARMA_USE_ATLAS) | |
| { | | { | |
| out = B; | | out = B; | |
| | | | |
| podarray<int> ipiv(A_n_rows + 2); // +2 for paranoia: old versions
of Atlas might be trashing memory | | podarray<int> ipiv(A_n_rows + 2); // +2 for paranoia: old versions
of Atlas might be trashing memory | |
| | | | |
|
| int info = atlas::clapack_gesv<eT>(atlas::CblasColMajor, A_n_rows,
B.n_cols, A.memptr(), A_n_rows, ipiv.memptr(), out.memptr(), A_n_rows); | | int info = atlas::clapack_gesv<eT>(atlas::CblasColMajor, A_n_rows,
B_n_cols, A.memptr(), A_n_rows, ipiv.memptr(), out.memptr(), A_n_rows); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #elif defined(ARMA_USE_LAPACK) | | #elif defined(ARMA_USE_LAPACK) | |
| { | | { | |
|
| blas_int n = A_n_rows; // assuming A is square | | | |
| blas_int lda = A_n_rows; | | | |
| blas_int ldb = A_n_rows; | | | |
| blas_int nrhs = B.n_cols; | | | |
| blas_int info = 0; | | | |
| | | | |
| out = B; | | out = B; | |
| | | | |
|
| | | blas_int n = blas_int(A_n_rows); // assuming A is square | |
| | | blas_int lda = blas_int(A_n_rows); | |
| | | blas_int ldb = blas_int(A_n_rows); | |
| | | blas_int nrhs = blas_int(B_n_cols); | |
| | | blas_int info = 0; | |
| | | | |
| podarray<blas_int> ipiv(A_n_rows + 2); // +2 for paranoia: some ve
rsions of Lapack might be trashing memory | | podarray<blas_int> ipiv(A_n_rows + 2); // +2 for paranoia: some ve
rsions of Lapack might be trashing memory | |
| | | | |
|
| | | arma_extra_debug_print("lapack::gesv()"); | |
| lapack::gesv<eT>(&n, &nrhs, A.memptr(), &lda, ipiv.memptr(), out.me
mptr(), &ldb, &info); | | lapack::gesv<eT>(&n, &nrhs, A.memptr(), &lda, ipiv.memptr(), out.me
mptr(), &ldb, &info); | |
| | | | |
|
| | | arma_extra_debug_print("lapack::gesv() -- finished"); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_stop("solve(): use of ATLAS or LAPACK needs to be enabled"); | | arma_stop("solve(): use of ATLAS or LAPACK needs to be enabled"); | |
| return false; | | return false; | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| } | | } | |
| | | | |
| skipping to change at line 2416 | | skipping to change at line 2507 | |
| //! Assumes that A.n_rows > A.n_cols and B.n_rows = A.n_rows | | //! Assumes that A.n_rows > A.n_cols and B.n_rows = A.n_rows | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::solve_od(Mat<eT>& out, Mat<eT>& A, const Mat<eT>& B) | | auxlib::solve_od(Mat<eT>& out, Mat<eT>& A, const Mat<eT>& B) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
|
| | | const uword A_n_rows = A.n_rows; | |
| | | const uword A_n_cols = A.n_cols; | |
| | | | |
| | | const uword B_n_rows = B.n_rows; | |
| | | const uword B_n_cols = B.n_cols; | |
| | | | |
| | | out.set_size(A_n_cols, B_n_cols); | |
| | | | |
| if(A.is_empty() || B.is_empty()) | | if(A.is_empty() || B.is_empty()) | |
| { | | { | |
|
| out.zeros(A.n_cols, B.n_cols); | | out.zeros(); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| char trans = 'N'; | | char trans = 'N'; | |
| | | | |
|
| blas_int m = A.n_rows; | | blas_int m = blas_int(A_n_rows); | |
| blas_int n = A.n_cols; | | blas_int n = blas_int(A_n_cols); | |
| blas_int lda = A.n_rows; | | blas_int lda = blas_int(A_n_rows); | |
| blas_int ldb = A.n_rows; | | blas_int ldb = blas_int(A_n_rows); | |
| blas_int nrhs = B.n_cols; | | blas_int nrhs = blas_int(B_n_cols); | |
| blas_int lwork = n + (std::max)(n, nrhs) + 2; // +2 for paranoia: som | | blas_int lwork = 2*((std::max)(blas_int(1), n + (std::max)(n, nrhs))); | |
| e versions of Lapack might be trashing memory | | | |
| blas_int info = 0; | | blas_int info = 0; | |
| | | | |
| Mat<eT> tmp = B; | | Mat<eT> tmp = B; | |
| | | | |
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | | |
|
| arma_extra_debug_print("lapack::gels()"); | | | |
| | | | |
| // NOTE: the dgels() function in the lapack library supplied by ATLAS 3
.6 seems to have problems | | // NOTE: the dgels() function in the lapack library supplied by ATLAS 3
.6 seems to have problems | |
|
| | | arma_extra_debug_print("lapack::gels()"); | |
| lapack::gels<eT> | | lapack::gels<eT>( &trans, &m, &n, &nrhs, A.memptr(), &lda, tmp.memptr() | |
| ( | | , &ldb, work.memptr(), &lwork, &info ); | |
| &trans, &m, &n, &nrhs, | | | |
| A.memptr(), &lda, | | | |
| tmp.memptr(), &ldb, | | | |
| work.memptr(), &lwork, | | | |
| &info | | | |
| ); | | | |
| | | | |
| arma_extra_debug_print("lapack::gels() -- finished"); | | arma_extra_debug_print("lapack::gels() -- finished"); | |
| | | | |
|
| out.set_size(A.n_cols, B.n_cols); | | for(uword col=0; col<B_n_cols; ++col) | |
| | | | |
| for(uword col=0; col<B.n_cols; ++col) | | | |
| { | | { | |
|
| arrayops::copy( out.colptr(col), tmp.colptr(col), A.n_cols ); | | arrayops::copy( out.colptr(col), tmp.colptr(col), A_n_cols ); | |
| } | | } | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(out); | | arma_ignore(out); | |
| arma_ignore(A); | | arma_ignore(A); | |
| arma_ignore(B); | | arma_ignore(B); | |
| arma_stop("solve(): use of LAPACK needs to be enabled"); | | arma_stop("solve(): use of LAPACK needs to be enabled"); | |
| | | | |
| skipping to change at line 2482 | | skipping to change at line 2570 | |
| //! Assumes that A.n_rows < A.n_cols and B.n_rows = A.n_rows | | //! Assumes that A.n_rows < A.n_cols and B.n_rows = A.n_rows | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| auxlib::solve_ud(Mat<eT>& out, Mat<eT>& A, const Mat<eT>& B) | | auxlib::solve_ud(Mat<eT>& out, Mat<eT>& A, const Mat<eT>& B) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| #if defined(ARMA_USE_LAPACK) | | #if defined(ARMA_USE_LAPACK) | |
| { | | { | |
|
| | | const uword A_n_rows = A.n_rows; | |
| | | const uword A_n_cols = A.n_cols; | |
| | | | |
| | | const uword B_n_rows = B.n_rows; | |
| | | const uword B_n_cols = B.n_cols; | |
| | | | |
| | | out.set_size(A_n_cols, B_n_cols); | |
| | | | |
| if(A.is_empty() || B.is_empty()) | | if(A.is_empty() || B.is_empty()) | |
| { | | { | |
|
| out.zeros(A.n_cols, B.n_cols); | | out.zeros(); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| char trans = 'N'; | | char trans = 'N'; | |
| | | | |
|
| blas_int m = A.n_rows; | | blas_int m = blas_int(A_n_rows); | |
| blas_int n = A.n_cols; | | blas_int n = blas_int(A_n_cols); | |
| blas_int lda = A.n_rows; | | blas_int lda = blas_int(A_n_rows); | |
| blas_int ldb = A.n_cols; | | blas_int ldb = blas_int(A_n_cols); | |
| blas_int nrhs = B.n_cols; | | blas_int nrhs = blas_int(B_n_cols); | |
| blas_int lwork = m + (std::max)(m,nrhs) + 2; // +2 for paranoia: some | | blas_int lwork = 2*((std::max)(blas_int(1), m + (std::max)(m,nrhs))); | |
| versions of Lapack might be trashing memory | | | |
| blas_int info = 0; | | blas_int info = 0; | |
| | | | |
|
| Mat<eT> tmp; | | Mat<eT> tmp(A_n_cols, B_n_cols); | |
| tmp.zeros(A.n_cols, B.n_cols); | | tmp.zeros(); | |
| | | | |
|
| for(uword col=0; col<B.n_cols; ++col) | | for(uword col=0; col<B_n_cols; ++col) | |
| { | | { | |
| eT* tmp_colmem = tmp.colptr(col); | | eT* tmp_colmem = tmp.colptr(col); | |
| | | | |
|
| arrayops::copy( tmp_colmem, B.colptr(col), B.n_rows ); | | arrayops::copy( tmp_colmem, B.colptr(col), B_n_rows ); | |
| | | | |
|
| for(uword row=B.n_rows; row<A.n_cols; ++row) | | for(uword row=B_n_rows; row<A_n_cols; ++row) | |
| { | | { | |
| tmp_colmem[row] = eT(0); | | tmp_colmem[row] = eT(0); | |
| } | | } | |
| } | | } | |
| | | | |
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | | |
|
| | | // NOTE: the dgels() function in the lapack library supplied by ATLAS 3
.6 seems to have problems | |
| arma_extra_debug_print("lapack::gels()"); | | arma_extra_debug_print("lapack::gels()"); | |
|
| | | lapack::gels<eT>( &trans, &m, &n, &nrhs, A.memptr(), &lda, tmp.memptr() | |
| | | , &ldb, work.memptr(), &lwork, &info ); | |
| | | | |
| | | arma_extra_debug_print("lapack::gels() -- finished"); | |
| | | | |
| | | for(uword col=0; col<B_n_cols; ++col) | |
| | | { | |
| | | arrayops::copy( out.colptr(col), tmp.colptr(col), A_n_cols ); | |
| | | } | |
| | | | |
| | | return (info == 0); | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_ignore(out); | |
| | | arma_ignore(A); | |
| | | arma_ignore(B); | |
| | | arma_stop("solve(): use of LAPACK needs to be enabled"); | |
| | | return false; | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| | | //! Solve a system of linear equations. | |
| | | //! Assumes that A.n_rows = A.n_cols and B.n_rows = A.n_rows | |
| | | template<typename eT, typename T1> | |
| | | inline | |
| | | bool | |
| | | auxlib::solve_new(Mat<eT>& out, Mat<eT>& A, const Base<eT,T1>& X, const boo | |
| | | l slow) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | bool status = false; | |
| | | | |
| | | const uword A_n_rows = A.n_rows; | |
| | | | |
| | | if( (A_n_rows <= 4) && (slow == false) ) | |
| | | { | |
| | | Mat<eT> A_inv; | |
| | | | |
| | | status = auxlib::inv_noalias_tinymat(A_inv, A, A_n_rows); | |
| | | | |
| | | if(status == true) | |
| | | { | |
| | | const unwrap_check<T1> Y( X.get_ref(), out ); | |
| | | const Mat<eT>& B = Y.M; | |
| | | | |
| | | const uword B_n_rows = B.n_rows; | |
| | | const uword B_n_cols = B.n_cols; | |
| | | | |
| | | arma_debug_check( (A_n_rows != B_n_rows), "solve(): number of rows in | |
| | | the given objects must be the same" ); | |
| | | | |
| | | if(A.is_empty() || B.is_empty()) | |
| | | { | |
| | | out.zeros(A.n_cols, B_n_cols); | |
| | | return true; | |
| | | } | |
| | | | |
| | | out.set_size(A_n_rows, B_n_cols); | |
| | | | |
| | | gemm_emul<false,false,false,false>::apply(out, A_inv, B); | |
| | | | |
| | | return true; | |
| | | } | |
| | | } | |
| | | | |
| | | if( (A_n_rows > 4) || (status == false) ) | |
| | | { | |
| | | out = X.get_ref(); | |
| | | | |
| | | const uword B_n_rows = out.n_rows; | |
| | | const uword B_n_cols = out.n_cols; | |
| | | | |
| | | arma_debug_check( (A_n_rows != B_n_rows), "solve(): number of rows in t | |
| | | he given objects must be the same" ); | |
| | | | |
| | | if(A.is_empty() || out.is_empty()) | |
| | | { | |
| | | out.zeros(A.n_cols, B_n_cols); | |
| | | return true; | |
| | | } | |
| | | | |
| | | #if defined(ARMA_USE_ATLAS) | |
| | | { | |
| | | podarray<int> ipiv(A_n_rows + 2); // +2 for paranoia: old versions o | |
| | | f Atlas might be trashing memory | |
| | | | |
| | | int info = atlas::clapack_gesv<eT>(atlas::CblasColMajor, A_n_rows, B_ | |
| | | n_cols, A.memptr(), A_n_rows, ipiv.memptr(), out.memptr(), A_n_rows); | |
| | | | |
| | | return (info == 0); | |
| | | } | |
| | | #elif defined(ARMA_USE_LAPACK) | |
| | | { | |
| | | blas_int n = blas_int(A_n_rows); // assuming A is square | |
| | | blas_int lda = blas_int(A_n_rows); | |
| | | blas_int ldb = blas_int(A_n_rows); | |
| | | blas_int nrhs = blas_int(B_n_cols); | |
| | | blas_int info = 0; | |
| | | | |
| | | podarray<blas_int> ipiv(A_n_rows + 2); // +2 for paranoia: some vers | |
| | | ions of Lapack might be trashing memory | |
| | | | |
| | | arma_extra_debug_print("lapack::gesv()"); | |
| | | lapack::gesv<eT>(&n, &nrhs, A.memptr(), &lda, ipiv.memptr(), out.memp | |
| | | tr(), &ldb, &info); | |
| | | | |
| | | arma_extra_debug_print("lapack::gesv() -- finished"); | |
| | | | |
| | | return (info == 0); | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_stop("solve(): use of ATLAS or LAPACK needs to be enabled"); | |
| | | return false; | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| | | return true; | |
| | | } | |
| | | | |
| | | //! Solve an over-determined system. | |
| | | //! Assumes that A.n_rows > A.n_cols and B.n_rows = A.n_rows | |
| | | template<typename eT, typename T1> | |
| | | inline | |
| | | bool | |
| | | auxlib::solve_new_od(Mat<eT>& out, Mat<eT>& A, const Base<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_LAPACK) | |
| | | { | |
| | | Mat<eT> tmp = X.get_ref(); | |
| | | | |
| | | const uword A_n_rows = A.n_rows; | |
| | | const uword A_n_cols = A.n_cols; | |
| | | | |
| | | const uword B_n_rows = tmp.n_rows; | |
| | | const uword B_n_cols = tmp.n_cols; | |
| | | | |
| | | arma_debug_check( (A_n_rows != B_n_rows), "solve(): number of rows in t | |
| | | he given objects must be the same" ); | |
| | | | |
| | | out.set_size(A_n_cols, B_n_cols); | |
| | | | |
| | | if(A.is_empty() || tmp.is_empty()) | |
| | | { | |
| | | out.zeros(); | |
| | | return true; | |
| | | } | |
| | | | |
| | | char trans = 'N'; | |
| | | | |
| | | blas_int m = blas_int(A_n_rows); | |
| | | blas_int n = blas_int(A_n_cols); | |
| | | blas_int lda = blas_int(A_n_rows); | |
| | | blas_int ldb = blas_int(A_n_rows); | |
| | | blas_int nrhs = blas_int(B_n_cols); | |
| | | blas_int lwork = 2*((std::max)(blas_int(1), n + (std::max)(n, nrhs))); | |
| | | blas_int info = 0; | |
| | | | |
| | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | | |
| // NOTE: the dgels() function in the lapack library supplied by ATLAS 3
.6 seems to have problems | | // NOTE: the dgels() function in the lapack library supplied by ATLAS 3
.6 seems to have problems | |
|
| | | arma_extra_debug_print("lapack::gels()"); | |
| | | lapack::gels<eT>( &trans, &m, &n, &nrhs, A.memptr(), &lda, tmp.memptr() | |
| | | , &ldb, work.memptr(), &lwork, &info ); | |
| | | | |
|
| lapack::gels<eT> | | arma_extra_debug_print("lapack::gels() -- finished"); | |
| ( | | | |
| &trans, &m, &n, &nrhs, | | for(uword col=0; col<B_n_cols; ++col) | |
| A.memptr(), &lda, | | { | |
| tmp.memptr(), &ldb, | | arrayops::copy( out.colptr(col), tmp.colptr(col), A_n_cols ); | |
| work.memptr(), &lwork, | | } | |
| &info | | | |
| ); | | return (info == 0); | |
| | | } | |
| | | #else | |
| | | { | |
| | | arma_ignore(out); | |
| | | arma_ignore(A); | |
| | | arma_ignore(X); | |
| | | arma_stop("solve(): use of LAPACK needs to be enabled"); | |
| | | return false; | |
| | | } | |
| | | #endif | |
| | | } | |
| | | | |
| | | //! Solve an under-determined system. | |
| | | //! Assumes that A.n_rows < A.n_cols and B.n_rows = A.n_rows | |
| | | template<typename eT, typename T1> | |
| | | inline | |
| | | bool | |
| | | auxlib::solve_new_ud(Mat<eT>& out, Mat<eT>& A, const Base<eT,T1>& X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | #if defined(ARMA_USE_LAPACK) | |
| | | { | |
| | | const unwrap<T1> Y( X.get_ref() ); | |
| | | const Mat<eT>& B = Y.M; | |
| | | | |
| | | const uword A_n_rows = A.n_rows; | |
| | | const uword A_n_cols = A.n_cols; | |
| | | | |
| | | const uword B_n_rows = B.n_rows; | |
| | | const uword B_n_cols = B.n_cols; | |
| | | | |
| | | arma_debug_check( (A_n_rows != B_n_rows), "solve(): number of rows in t | |
| | | he given objects must be the same" ); | |
| | | | |
| | | // B could be an alias of "out", hence we need to check whether B is em | |
| | | pty before setting the size of "out" | |
| | | if(A.is_empty() || B.is_empty()) | |
| | | { | |
| | | out.zeros(A_n_cols, B_n_cols); | |
| | | return true; | |
| | | } | |
| | | | |
| | | char trans = 'N'; | |
| | | | |
| | | blas_int m = blas_int(A_n_rows); | |
| | | blas_int n = blas_int(A_n_cols); | |
| | | blas_int lda = blas_int(A_n_rows); | |
| | | blas_int ldb = blas_int(A_n_cols); | |
| | | blas_int nrhs = blas_int(B_n_cols); | |
| | | blas_int lwork = 2*((std::max)(blas_int(1), m + (std::max)(m,nrhs))); | |
| | | blas_int info = 0; | |
| | | | |
| | | Mat<eT> tmp(A_n_cols, B_n_cols); | |
| | | tmp.zeros(); | |
| | | | |
| | | for(uword col=0; col<B_n_cols; ++col) | |
| | | { | |
| | | eT* tmp_colmem = tmp.colptr(col); | |
| | | | |
| | | arrayops::copy( tmp_colmem, B.colptr(col), B_n_rows ); | |
| | | | |
| | | for(uword row=B_n_rows; row<A_n_cols; ++row) | |
| | | { | |
| | | tmp_colmem[row] = eT(0); | |
| | | } | |
| | | } | |
| | | | |
| | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| | | | |
| | | // NOTE: the dgels() function in the lapack library supplied by ATLAS 3 | |
| | | .6 seems to have problems | |
| | | arma_extra_debug_print("lapack::gels()"); | |
| | | lapack::gels<eT>( &trans, &m, &n, &nrhs, A.memptr(), &lda, tmp.memptr() | |
| | | , &ldb, work.memptr(), &lwork, &info ); | |
| | | | |
| arma_extra_debug_print("lapack::gels() -- finished"); | | arma_extra_debug_print("lapack::gels() -- finished"); | |
| | | | |
|
| out.set_size(A.n_cols, B.n_cols); | | out.set_size(A_n_cols, B_n_cols); | |
| | | | |
|
| for(uword col=0; col<B.n_cols; ++col) | | for(uword col=0; col<B_n_cols; ++col) | |
| { | | { | |
|
| arrayops::copy( out.colptr(col), tmp.colptr(col), A.n_cols ); | | arrayops::copy( out.colptr(col), tmp.colptr(col), A_n_cols ); | |
| } | | } | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(out); | | arma_ignore(out); | |
| arma_ignore(A); | | arma_ignore(A); | |
|
| arma_ignore(B); | | arma_ignore(X); | |
| arma_stop("solve(): use of LAPACK needs to be enabled"); | | arma_stop("solve(): use of LAPACK needs to be enabled"); | |
| return false; | | return false; | |
| } | | } | |
| #endif | | #endif | |
| } | | } | |
| | | | |
| // | | // | |
| // solve_tr | | // solve_tr | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| | | | |
| skipping to change at line 2616 | | skipping to change at line 2942 | |
| | | | |
| if(A.is_empty()) | | if(A.is_empty()) | |
| { | | { | |
| Z.reset(); | | Z.reset(); | |
| T.reset(); | | T.reset(); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| const uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| | | | |
|
| | | Z.set_size(A_n_rows, A_n_rows); | |
| | | T = A; | |
| | | | |
| char jobvs = 'V'; // get Schur vectors (Z) | | char jobvs = 'V'; // get Schur vectors (Z) | |
| char sort = 'N'; // do not sort eigenvalues/vecto
rs | | char sort = 'N'; // do not sort eigenvalues/vecto
rs | |
| blas_int* select = 0; // pointer to sorting function | | blas_int* select = 0; // pointer to sorting function | |
| blas_int n = blas_int(A_n_rows); | | blas_int n = blas_int(A_n_rows); | |
| blas_int sdim = 0; // output for sorting | | blas_int sdim = 0; // output for sorting | |
|
| | | blas_int lwork = 2*((std::max)(blas_int(1), 3*n)); | |
| blas_int lwork = 3 * n; // workspace must be at least 3 | | blas_int info = 0; | |
| * n (if set to -1, optimal size is output in work(0) and nothing else is do | | | |
| ne | | | |
| | | | |
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| podarray<blas_int> bwork(A_n_rows); | | podarray<blas_int> bwork(A_n_rows); | |
| | | | |
|
| blas_int info = 0; | | | |
| | | | |
| Z.set_size(A_n_rows, A_n_rows); | | | |
| T = A; | | | |
| | | | |
| podarray<eT> wr(A_n_rows); // output for eigenvalues | | podarray<eT> wr(A_n_rows); // output for eigenvalues | |
| podarray<eT> wi(A_n_rows); // output for eigenvalues | | podarray<eT> wi(A_n_rows); // output for eigenvalues | |
| | | | |
| lapack::gees(&jobvs, &sort, select, &n, T.memptr(), &n, &sdim, wr.mempt
r(), wi.memptr(), Z.memptr(), &n, work.memptr(), &lwork, bwork.memptr(), &i
nfo); | | lapack::gees(&jobvs, &sort, select, &n, T.memptr(), &n, &sdim, wr.mempt
r(), wi.memptr(), Z.memptr(), &n, work.memptr(), &lwork, bwork.memptr(), &i
nfo); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(Z); | | arma_ignore(Z); | |
| | | | |
| skipping to change at line 2673 | | skipping to change at line 2997 | |
| { | | { | |
| Z.reset(); | | Z.reset(); | |
| T.reset(); | | T.reset(); | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| typedef std::complex<cT> eT; | | typedef std::complex<cT> eT; | |
| | | | |
| const uword A_n_rows = A.n_rows; | | const uword A_n_rows = A.n_rows; | |
| | | | |
|
| | | Z.set_size(A_n_rows, A_n_rows); | |
| | | T = A; | |
| | | | |
| char jobvs = 'V'; // get Schur vectors (Z) | | char jobvs = 'V'; // get Schur vectors (Z) | |
| char sort = 'N'; // do not sort eigenvalues/vect
ors | | char sort = 'N'; // do not sort eigenvalues/vect
ors | |
| blas_int* select = 0; // pointer to sorting function | | blas_int* select = 0; // pointer to sorting function | |
| blas_int n = blas_int(A_n_rows); | | blas_int n = blas_int(A_n_rows); | |
| blas_int sdim = 0; // output for sorting | | blas_int sdim = 0; // output for sorting | |
|
| | | blas_int lwork = 2*((std::max)(blas_int(1), 2*n)); | |
| blas_int lwork = 3 * n; // workspace must be at least 3 | | blas_int info = 0; | |
| * n (if set to -1, optimal size is output in work(0) and nothing else is d | | | |
| one | | | |
| | | | |
| podarray<eT> work( static_cast<uword>(lwork) ); | | podarray<eT> work( static_cast<uword>(lwork) ); | |
| podarray<blas_int> bwork(A_n_rows); | | podarray<blas_int> bwork(A_n_rows); | |
| | | | |
|
| blas_int info = 0; | | | |
| | | | |
| Z.set_size(A_n_rows, A_n_rows); | | | |
| T = A; | | | |
| | | | |
| podarray<eT> w(A_n_rows); // output for eigenvalues | | podarray<eT> w(A_n_rows); // output for eigenvalues | |
| podarray<cT> rwork(A_n_rows); | | podarray<cT> rwork(A_n_rows); | |
| | | | |
| lapack::cx_gees(&jobvs, &sort, select, &n, T.memptr(), &n, &sdim, w.mem
ptr(), Z.memptr(), &n, work.memptr(), &lwork, rwork.memptr(), bwork.memptr(
), &info); | | lapack::cx_gees(&jobvs, &sort, select, &n, T.memptr(), &n, &sdim, w.mem
ptr(), Z.memptr(), &n, work.memptr(), &lwork, rwork.memptr(), bwork.memptr(
), &info); | |
| | | | |
| return (info == 0); | | return (info == 0); | |
| } | | } | |
| #else | | #else | |
| { | | { | |
| arma_ignore(Z); | | arma_ignore(Z); | |
| | | | |
End of changes. 81 change blocks. |
| 180 lines changed or deleted | | 509 lines changed or added | |
|
| diagmat_proxy.hpp | | diagmat_proxy.hpp | |
| | | | |
| skipping to change at line 17 | | skipping to change at line 17 | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| //! \addtogroup diagmat_proxy | | //! \addtogroup diagmat_proxy | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class diagmat_proxy | | class diagmat_proxy_default | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
|
| inline diagmat_proxy(const T1& X) | | inline | |
| | | diagmat_proxy_default(const T1& X) | |
| : P ( X ) | | : P ( X ) | |
|
| , P_is_vec( (P.get_n_rows() == 1) || (P.get_n_cols() == 1) ) | | , P_is_vec( (resolves_to_vector<T1>::value) || (P.get_n_rows() == 1) || | |
| , P_is_col( P.get_n_cols() == 1 ) | | (P.get_n_cols() == 1) ) | |
| | | , P_is_col( T1::is_col || (P.get_n_cols() == 1) ) | |
| , n_elem ( P_is_vec ? P.get_n_elem() : (std::min)(P.get_n_elem(), P.ge
t_n_rows()) ) | | , n_elem ( P_is_vec ? P.get_n_elem() : (std::min)(P.get_n_elem(), P.ge
t_n_rows()) ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (P_is_vec == false) && (P.get_n_rows() != P.get_n_cols()), | | (P_is_vec == false) && (P.get_n_rows() != P.get_n_cols()), | |
| "diagmat(): only vectors and square matrices are accepted" | | "diagmat(): only vectors and square matrices are accepted" | |
| ); | | ); | |
| } | | } | |
| | | | |
| skipping to change at line 94 | | skipping to change at line 95 | |
| return elem_type(0); | | return elem_type(0); | |
| } | | } | |
| } | | } | |
| | | | |
| const Proxy<T1> P; | | const Proxy<T1> P; | |
| const bool P_is_vec; | | const bool P_is_vec; | |
| const bool P_is_col; | | const bool P_is_col; | |
| const uword n_elem; | | const uword n_elem; | |
| }; | | }; | |
| | | | |
|
| | | template<typename T1> | |
| | | class diagmat_proxy_fixed | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef typename T1::elem_type elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
| | | inline | |
| | | diagmat_proxy_fixed(const T1& X) | |
| | | : P(X) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (P_is_vec == false) && (T1::n_rows != T1::n_cols), | |
| | | "diagmat(): only vectors and square matrices are accepted" | |
| | | ); | |
| | | } | |
| | | | |
| | | arma_inline | |
| | | elem_type | |
| | | operator[](const uword i) const | |
| | | { | |
| | | return (P_is_vec) ? P[i] : P.at(i,i); | |
| | | } | |
| | | | |
| | | arma_inline | |
| | | elem_type | |
| | | at(const uword row, const uword col) const | |
| | | { | |
| | | if(row == col) | |
| | | { | |
| | | return (P_is_vec) ? P[row] : P.at(row,row); | |
| | | } | |
| | | else | |
| | | { | |
| | | return elem_type(0); | |
| | | } | |
| | | } | |
| | | | |
| | | const T1& P; | |
| | | | |
| | | static const bool P_is_vec = (T1::n_rows == 1) || (T1::n_cols == 1); | |
| | | static const uword n_elem = P_is_vec ? T1::n_elem : ( (T1::n_elem < T1: | |
| | | :n_rows) ? T1::n_elem : T1::n_rows ); | |
| | | }; | |
| | | | |
| | | template<typename T1, bool condition> | |
| | | struct diagmat_proxy_redirect {}; | |
| | | | |
| | | template<typename T1> | |
| | | struct diagmat_proxy_redirect<T1, false> { typedef diagmat_proxy_default<T1 | |
| | | > result; }; | |
| | | | |
| | | template<typename T1> | |
| | | struct diagmat_proxy_redirect<T1, true> { typedef diagmat_proxy_fixed<T1> | |
| | | result; }; | |
| | | | |
| | | template<typename T1> | |
| | | class diagmat_proxy : public diagmat_proxy_redirect<T1, is_Mat_fixed<T1>::v | |
| | | alue >::result | |
| | | { | |
| | | public: | |
| | | inline diagmat_proxy(const T1& X) | |
| | | : diagmat_proxy_redirect< T1, is_Mat_fixed<T1>::value >::result(X) | |
| | | { | |
| | | } | |
| | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class diagmat_proxy< Mat<eT> > | | class diagmat_proxy< Mat<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
|
| inline diagmat_proxy(const Mat<eT>& X) | | inline | |
| : P(X) | | diagmat_proxy(const Mat<eT>& X) | |
| , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) ) | | : P ( X ) | |
| , n_elem( P_is_vec ? P.n_elem : (std::min)(P.n_elem, P.n_rows) ) | | , P_is_vec( (X.n_rows == 1) || (X.n_cols == 1) ) | |
| | | , n_elem ( P_is_vec ? X.n_elem : (std::min)(X.n_elem, X.n_rows) ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (P_is_vec == false) && (P.n_rows != P.n_cols), | | (P_is_vec == false) && (P.n_rows != P.n_cols), | |
| "diagmat(): only vectors and square matrices are accepted" | | "diagmat(): only vectors and square matrices are accepted" | |
| ); | | ); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 132 | | skipping to change at line 201 | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class diagmat_proxy< Row<eT> > | | class diagmat_proxy< Row<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
|
| inline diagmat_proxy(const Row<eT>& X) | | inline | |
| | | diagmat_proxy(const Row<eT>& X) | |
| : P(X) | | : P(X) | |
|
| , P_is_vec(true) | | , n_elem(X.n_elem) | |
| , n_elem(P.n_elem) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const
{ return P[i];
} | | arma_inline elem_type operator[] (const uword i) const
{ return P[i];
} | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? P[row] : elem_type(0); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? P[row] : elem_type(0); } | |
| | | | |
|
| | | static const bool P_is_vec = true; | |
| | | | |
| const Row<eT>& P; | | const Row<eT>& P; | |
|
| const bool P_is_vec; | | | |
| const uword n_elem; | | const uword n_elem; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class diagmat_proxy< Col<eT> > | | class diagmat_proxy< Col<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
|
| inline diagmat_proxy(const Col<eT>& X) | | inline | |
| | | diagmat_proxy(const Col<eT>& X) | |
| : P(X) | | : P(X) | |
|
| , P_is_vec(true) | | , n_elem(X.n_elem) | |
| , n_elem(P.n_elem) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const
{ return P[i]; } | | arma_inline elem_type operator[] (const uword i) const
{ return P[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? P[row] : elem_type(0); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? P[row] : elem_type(0); } | |
| | | | |
|
| | | static const bool P_is_vec = true; | |
| | | | |
| const Col<eT>& P; | | const Col<eT>& P; | |
|
| const bool P_is_vec; | | | |
| const uword n_elem; | | const uword n_elem; | |
| }; | | }; | |
| | | | |
|
| | | template<typename eT> | |
| | | class diagmat_proxy< subview_row<eT> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef eT elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
| | | inline | |
| | | diagmat_proxy(const subview_row<eT>& X) | |
| | | : P(X) | |
| | | , n_elem(X.n_elem) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const | |
| | | { return P[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword col) const | |
| | | { return (row == col) ? P[row] : elem_type(0); } | |
| | | | |
| | | static const bool P_is_vec = true; | |
| | | | |
| | | const subview_row<eT>& P; | |
| | | const uword n_elem; | |
| | | }; | |
| | | | |
| | | template<typename eT> | |
| | | class diagmat_proxy< subview_col<eT> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef eT elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
| | | inline | |
| | | diagmat_proxy(const subview_col<eT>& X) | |
| | | : P(X) | |
| | | , n_elem(X.n_elem) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const | |
| | | { return P[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword col) const | |
| | | { return (row == col) ? P[row] : elem_type(0); } | |
| | | | |
| | | static const bool P_is_vec = true; | |
| | | | |
| | | const subview_col<eT>& P; | |
| | | const uword n_elem; | |
| | | }; | |
| | | | |
| | | // | |
| | | // | |
| | | // | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class diagmat_proxy_check | | class diagmat_proxy_check_default | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef typename T1::elem_type elem_type; | | typedef typename T1::elem_type elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
|
| inline diagmat_proxy_check(const T1& X, const Mat<typename T1::elem_type> | | inline | |
| & out) | | diagmat_proxy_check_default(const T1& X, const Mat<typename T1::elem_type | |
| | | >&) | |
| : P(X) | | : P(X) | |
|
| , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) ) | | , P_is_vec( (resolves_to_vector<T1>::value) || (P.n_rows == 1) || (P.n_
cols == 1) ) | |
| , n_elem( P_is_vec ? P.n_elem : (std::min)(P.n_elem, P.n_rows) ) | | , n_elem( P_is_vec ? P.n_elem : (std::min)(P.n_elem, P.n_rows) ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| arma_ignore(out); | | | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (P_is_vec == false) && (P.n_rows != P.n_cols), | | (P_is_vec == false) && (P.n_rows != P.n_cols), | |
| "diagmat(): only vectors and square matrices are accepted" | | "diagmat(): only vectors and square matrices are accepted" | |
| ); | | ); | |
| } | | } | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const
{ return P_is_vec ? P[i] : P.at(i,i);
} | | arma_inline elem_type operator[] (const uword i) const
{ return P_is_vec ? P[i] : P.at(i,i);
} | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(
0); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(
0); } | |
| | | | |
| const Mat<elem_type> P; | | const Mat<elem_type> P; | |
| const bool P_is_vec; | | const bool P_is_vec; | |
| const uword n_elem; | | const uword n_elem; | |
| }; | | }; | |
| | | | |
|
| | | template<typename T1> | |
| | | class diagmat_proxy_check_fixed | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | typedef typename T1::elem_type elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
| | | inline | |
| | | diagmat_proxy_check_fixed(const T1& X, const Mat<eT>& out) | |
| | | : P( const_cast<eT*>(X.memptr()), T1::n_rows, T1::n_cols, (&X == &out), | |
| | | false ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | arma_debug_check | |
| | | ( | |
| | | (P_is_vec == false) && (T1::n_rows != T1::n_cols), | |
| | | "diagmat(): only vectors and square matrices are accepted" | |
| | | ); | |
| | | } | |
| | | | |
| | | arma_inline eT operator[] (const uword i) const { retu | |
| | | rn P_is_vec ? P[i] : P.at(i,i); } | |
| | | arma_inline eT at (const uword row, const uword col) const { retu | |
| | | rn (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); } | |
| | | | |
| | | const Mat<eT> P; // TODO: why not just store X directly as T1& ? test w | |
| | | ith fixed size vectors and matrices | |
| | | | |
| | | static const bool P_is_vec = (T1::n_rows == 1) || (T1::n_cols == 1); | |
| | | static const uword n_elem = P_is_vec ? T1::n_elem : ( (T1::n_elem < T1: | |
| | | :n_rows) ? T1::n_elem : T1::n_rows ); | |
| | | }; | |
| | | | |
| | | template<typename T1, bool condition> | |
| | | struct diagmat_proxy_check_redirect {}; | |
| | | | |
| | | template<typename T1> | |
| | | struct diagmat_proxy_check_redirect<T1, false> { typedef diagmat_proxy_chec | |
| | | k_default<T1> result; }; | |
| | | | |
| | | template<typename T1> | |
| | | struct diagmat_proxy_check_redirect<T1, true> { typedef diagmat_proxy_chec | |
| | | k_fixed<T1> result; }; | |
| | | | |
| | | template<typename T1> | |
| | | class diagmat_proxy_check : public diagmat_proxy_check_redirect<T1, is_Mat_ | |
| | | fixed<T1>::value >::result | |
| | | { | |
| | | public: | |
| | | inline diagmat_proxy_check(const T1& X, const Mat<typename T1::elem_type> | |
| | | & out) | |
| | | : diagmat_proxy_check_redirect< T1, is_Mat_fixed<T1>::value >::result(X | |
| | | , out) | |
| | | { | |
| | | } | |
| | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class diagmat_proxy_check< Mat<eT> > | | class diagmat_proxy_check< Mat<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
|
| inline diagmat_proxy_check(const Mat<eT>& X, const Mat<eT>& out) | | inline | |
| | | diagmat_proxy_check(const Mat<eT>& X, const Mat<eT>& out) | |
| : P_local ( (&X == &out) ? new Mat<eT>(X) : 0 ) | | : P_local ( (&X == &out) ? new Mat<eT>(X) : 0 ) | |
| , P ( (&X == &out) ? (*P_local) : X ) | | , P ( (&X == &out) ? (*P_local) : X ) | |
| , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) ) | | , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) ) | |
| , n_elem ( P_is_vec ? P.n_elem : (std::min)(P.n_elem, P.n_rows) ) | | , n_elem ( P_is_vec ? P.n_elem : (std::min)(P.n_elem, P.n_rows) ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (P_is_vec == false) && (P.n_rows != P.n_cols), | | (P_is_vec == false) && (P.n_rows != P.n_cols), | |
| "diagmat(): only vectors and square matrices are accepted" | | "diagmat(): only vectors and square matrices are accepted" | |
| ); | | ); | |
| } | | } | |
| | | | |
| inline ~diagmat_proxy_check() | | inline ~diagmat_proxy_check() | |
| { | | { | |
|
| if(P_local) | | if(P_local) { delete P_local; } | |
| { | | | |
| delete P_local; | | | |
| } | | | |
| } | | } | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const
{ return P_is_vec ? P[i] : P.at(i,i);
} | | arma_inline elem_type operator[] (const uword i) const
{ return P_is_vec ? P[i] : P.at(i,i);
} | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(
0); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(
0); } | |
| | | | |
| const Mat<eT>* P_local; | | const Mat<eT>* P_local; | |
| const Mat<eT>& P; | | const Mat<eT>& P; | |
| const bool P_is_vec; | | const bool P_is_vec; | |
| const uword n_elem; | | const uword n_elem; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class diagmat_proxy_check< Row<eT> > | | class diagmat_proxy_check< Row<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
|
| inline diagmat_proxy_check(const Row<eT>& X, const Mat<eT>& out) | | inline | |
| | | diagmat_proxy_check(const Row<eT>& X, const Mat<eT>& out) | |
| : P_local ( (&X == reinterpret_cast<const Row<eT>*>(&out)) ? new Row<eT
>(X) : 0 ) | | : P_local ( (&X == reinterpret_cast<const Row<eT>*>(&out)) ? new Row<eT
>(X) : 0 ) | |
| , P ( (&X == reinterpret_cast<const Row<eT>*>(&out)) ? (*P_local)
: X ) | | , P ( (&X == reinterpret_cast<const Row<eT>*>(&out)) ? (*P_local)
: X ) | |
|
| , P_is_vec(true) | | , n_elem (X.n_elem) | |
| , n_elem (P.n_elem) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline ~diagmat_proxy_check() | | inline ~diagmat_proxy_check() | |
| { | | { | |
|
| if(P_local) | | if(P_local) { delete P_local; } | |
| { | | | |
| delete P_local; | | | |
| } | | | |
| } | | } | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const
{ return P[i]; } | | arma_inline elem_type operator[] (const uword i) const
{ return P[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? P[row] : elem_type(0); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? P[row] : elem_type(0); } | |
| | | | |
|
| | | static const bool P_is_vec = true; | |
| | | | |
| const Row<eT>* P_local; | | const Row<eT>* P_local; | |
| const Row<eT>& P; | | const Row<eT>& P; | |
|
| const bool P_is_vec; | | | |
| const uword n_elem; | | const uword n_elem; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| class diagmat_proxy_check< Col<eT> > | | class diagmat_proxy_check< Col<eT> > | |
| { | | { | |
| public: | | public: | |
| | | | |
| typedef eT elem_type; | | typedef eT elem_type; | |
| typedef typename get_pod_type<elem_type>::result pod_type; | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
|
| inline diagmat_proxy_check(const Col<eT>& X, const Mat<eT>& out) | | inline | |
| | | diagmat_proxy_check(const Col<eT>& X, const Mat<eT>& out) | |
| : P_local ( (&X == reinterpret_cast<const Col<eT>*>(&out)) ? new Col<eT
>(X) : 0 ) | | : P_local ( (&X == reinterpret_cast<const Col<eT>*>(&out)) ? new Col<eT
>(X) : 0 ) | |
| , P ( (&X == reinterpret_cast<const Col<eT>*>(&out)) ? (*P_local)
: X ) | | , P ( (&X == reinterpret_cast<const Col<eT>*>(&out)) ? (*P_local)
: X ) | |
|
| , P_is_vec(true) | | , n_elem (X.n_elem) | |
| , n_elem (P.n_elem) | | | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline ~diagmat_proxy_check() | | inline ~diagmat_proxy_check() | |
| { | | { | |
|
| if(P_local) | | if(P_local) { delete P_local; } | |
| { | | | |
| delete P_local; | | | |
| } | | | |
| } | | } | |
| | | | |
| arma_inline elem_type operator[] (const uword i) const
{ return P[i]; } | | arma_inline elem_type operator[] (const uword i) const
{ return P[i]; } | |
| arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? P[row] : elem_type(0); } | | arma_inline elem_type at (const uword row, const uword col) const
{ return (row == col) ? P[row] : elem_type(0); } | |
| | | | |
|
| | | static const bool P_is_vec = true; | |
| | | | |
| const Col<eT>* P_local; | | const Col<eT>* P_local; | |
| const Col<eT>& P; | | const Col<eT>& P; | |
|
| const bool P_is_vec; | | | |
| const uword n_elem; | | const uword n_elem; | |
| }; | | }; | |
| | | | |
|
| | | template<typename eT> | |
| | | class diagmat_proxy_check< subview_row<eT> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef eT elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
| | | inline | |
| | | diagmat_proxy_check(const subview_row<eT>& X, const Mat<eT>&) | |
| | | : P ( X ) | |
| | | , n_elem ( X.n_elem ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const | |
| | | { return P[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword col) const | |
| | | { return (row == col) ? P[row] : elem_type(0); } | |
| | | | |
| | | static const bool P_is_vec = true; | |
| | | | |
| | | const Row<eT> P; | |
| | | const uword n_elem; | |
| | | }; | |
| | | | |
| | | template<typename eT> | |
| | | class diagmat_proxy_check< subview_col<eT> > | |
| | | { | |
| | | public: | |
| | | | |
| | | typedef eT elem_type; | |
| | | typedef typename get_pod_type<elem_type>::result pod_type; | |
| | | | |
| | | inline | |
| | | diagmat_proxy_check(const subview_col<eT>& X, const Mat<eT>& out) | |
| | | : P ( const_cast<eT*>(X.colptr(0)), X.n_rows, (&(X.m) == &out), fal | |
| | | se ) | |
| | | , n_elem( X.n_elem ) | |
| | | //, X_ref ( X ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | arma_inline elem_type operator[] (const uword i) const | |
| | | { return P[i]; } | |
| | | arma_inline elem_type at (const uword row, const uword col) const | |
| | | { return (row == col) ? P[row] : elem_type(0); } | |
| | | | |
| | | static const bool P_is_vec = true; | |
| | | | |
| | | const Col<eT> P; | |
| | | const uword n_elem; | |
| | | | |
| | | //const subview_col<eT>& X_ref; // prevents the compiler from potential | |
| | | ly deleting X before we're done with it | |
| | | }; | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 32 change blocks. |
| 42 lines changed or deleted | | 289 lines changed or added | |
|
| diagview_meat.hpp | | diagview_meat.hpp | |
| | | | |
| skipping to change at line 43 | | skipping to change at line 43 | |
| } | | } | |
| | | | |
| //! set a diagonal of our matrix using a diagonal from a foreign matrix | | //! set a diagonal of our matrix using a diagonal from a foreign matrix | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::operator= (const diagview<eT>& x) | | diagview<eT>::operator= (const diagview<eT>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| diagview<eT>& t = *this; | | diagview<eT>& d = *this; | |
| | | | |
|
| arma_debug_check( (t.n_elem != x.n_elem), "diagview: diagonals have incom
patible lengths"); | | arma_debug_check( (d.n_elem != x.n_elem), "diagview: diagonals have incom
patible lengths"); | |
| | | | |
|
| Mat<eT>& t_m = const_cast< Mat<eT>& >(t.m); | | Mat<eT>& d_m = const_cast< Mat<eT>& >(d.m); | |
| const Mat<eT>& x_m = x.m; | | const Mat<eT>& x_m = x.m; | |
| | | | |
|
| if(&t_m != &x_m) | | if(&d_m != &x_m) | |
| { | | { | |
|
| const uword t_n_elem = t.n_elem; | | const uword d_n_elem = d.n_elem; | |
| const uword t_row_offset = t.row_offset; | | const uword d_row_offset = d.row_offset; | |
| const uword t_col_offset = t.col_offset; | | const uword d_col_offset = d.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; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | | for(ii=0, jj=1; jj < d_n_elem; ii+=2, jj+=2) | |
| { | | { | |
|
| const eT tmp_i = x_m.at(i + x_row_offset, i + x_col_offset); | | const eT tmp_i = x_m.at(ii + x_row_offset, ii + x_col_offset); | |
| const eT tmp_j = x_m.at(j + x_row_offset, j + x_col_offset); | | const eT tmp_j = x_m.at(jj + x_row_offset, jj + x_col_offset); | |
| | | | |
|
| t_m.at(i + t_row_offset, i + t_col_offset) = tmp_i; | | d_m.at(ii + d_row_offset, ii + d_col_offset) = tmp_i; | |
| t_m.at(j + t_row_offset, j + t_col_offset) = tmp_j; | | d_m.at(jj + d_row_offset, jj + d_col_offset) = tmp_j; | |
| } | | } | |
| | | | |
|
| if(i < t_n_elem) | | if(ii < d_n_elem) | |
| { | | { | |
|
| t_m.at(i + t_row_offset, i + t_col_offset) = x_m.at(i + x_row_offset,
i + x_col_offset); | | d_m.at(ii + d_row_offset, ii + d_col_offset) = x_m.at(ii + x_row_offs
et, ii + x_col_offset); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Mat<eT> tmp = x; | | const Mat<eT> tmp = x; | |
| | | | |
| (*this).operator=(tmp); | | (*this).operator=(tmp); | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 95 | | skipping to change at line 95 | |
| diagview<eT>::operator+=(const eT val) | | diagview<eT>::operator+=(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>& t_m = const_cast< Mat<eT>& >(m); | | Mat<eT>& t_m = const_cast< Mat<eT>& >(m); | |
| | | | |
| const uword t_n_elem = n_elem; | | const uword t_n_elem = n_elem; | |
| const uword t_row_offset = row_offset; | | const uword t_row_offset = row_offset; | |
| const uword t_col_offset = col_offset; | | const uword t_col_offset = col_offset; | |
| | | | |
|
| for(uword i=0; i<t_n_elem; ++i) | | for(uword ii=0; ii < t_n_elem; ++ii) | |
| { | | { | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) += val; | | t_m.at( ii + t_row_offset, ii + t_col_offset) += val; | |
| } | | } | |
| } | | } | |
| | | | |
| 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(); | |
| | | | |
| Mat<eT>& t_m = const_cast< Mat<eT>& >(m); | | Mat<eT>& t_m = const_cast< Mat<eT>& >(m); | |
| | | | |
| const uword t_n_elem = n_elem; | | const uword t_n_elem = n_elem; | |
| const uword t_row_offset = row_offset; | | const uword t_row_offset = row_offset; | |
| const uword t_col_offset = col_offset; | | const uword t_col_offset = col_offset; | |
| | | | |
|
| for(uword i=0; i<t_n_elem; ++i) | | for(uword ii=0; ii < t_n_elem; ++ii) | |
| { | | { | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) -= val; | | t_m.at( ii + t_row_offset, ii + t_col_offset) -= val; | |
| } | | } | |
| } | | } | |
| | | | |
| 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(); | |
| | | | |
| Mat<eT>& t_m = const_cast< Mat<eT>& >(m); | | Mat<eT>& t_m = const_cast< Mat<eT>& >(m); | |
| | | | |
| const uword t_n_elem = n_elem; | | const uword t_n_elem = n_elem; | |
| const uword t_row_offset = row_offset; | | const uword t_row_offset = row_offset; | |
| const uword t_col_offset = col_offset; | | const uword t_col_offset = col_offset; | |
| | | | |
|
| for(uword i=0; i<t_n_elem; ++i) | | for(uword ii=0; ii < t_n_elem; ++ii) | |
| { | | { | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) *= val; | | t_m.at( ii + t_row_offset, ii + t_col_offset) *= val; | |
| } | | } | |
| } | | } | |
| | | | |
| 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(); | |
| | | | |
| Mat<eT>& t_m = const_cast< Mat<eT>& >(m); | | Mat<eT>& t_m = const_cast< Mat<eT>& >(m); | |
| | | | |
| const uword t_n_elem = n_elem; | | const uword t_n_elem = n_elem; | |
| const uword t_row_offset = row_offset; | | const uword t_row_offset = row_offset; | |
| const uword t_col_offset = col_offset; | | const uword t_col_offset = col_offset; | |
| | | | |
|
| for(uword i=0; i<t_n_elem; ++i) | | for(uword ii=0; ii < t_n_elem; ++ii) | |
| { | | { | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) /= val; | | t_m.at( ii + t_row_offset, ii + t_col_offset) /= val; | |
| } | | } | |
| } | | } | |
| | | | |
| //! set a diagonal of our matrix using data from a foreign object | | //! set a diagonal of our matrix using data from a foreign object | |
| 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) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const unwrap<T1> tmp(o.get_ref()); | | diagview<eT>& d = *this; | |
| const Mat<eT>& x = tmp.M; | | | |
| | | | |
|
| diagview<eT>& t = *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 | | arma_debug_check | |
| ( | | ( | |
|
| ( (t.n_elem != x.n_elem) || (x.is_vec() == false) ), | | ( (d.n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_co
ls() != 1)) ), | |
| "diagview: given object has incompatible size" | | "diagview: given object has incompatible size" | |
| ); | | ); | |
| | | | |
|
| Mat<eT>& t_m = const_cast< Mat<eT>& >(t.m); | | const bool is_alias = P.is_alias(d_m); | |
| | | | |
|
| const uword t_n_elem = t.n_elem; | | arma_extra_debug_warn(is_alias, "aliasing detected"); | |
| const uword t_row_offset = t.row_offset; | | | |
| const uword t_col_offset = t.col_offset; | | | |
| | | | |
|
| const eT* x_mem = x.memptr(); | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) || (Proxy<T1 | |
| | | >::prefer_at_accessor == true) || (is_alias == true) ) | |
| uword i,j; | | | |
| for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp_i = x_mem[i]; | | const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); | |
| const eT tmp_j = x_mem[j]; | | const Mat<eT>& x = tmp.M; | |
| | | | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) = tmp_i; | | const eT* x_mem = x.memptr(); | |
| t_m.at( j + t_row_offset, j + t_col_offset) = tmp_j; | | | |
| } | | 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]; | |
| | | | |
|
| if(i < t_n_elem) | | 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 | |
| { | | { | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) = x_mem[i]; | | 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]; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| 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) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const unwrap<T1> tmp(o.get_ref()); | | diagview<eT>& d = *this; | |
| const Mat<eT>& x = tmp.M; | | | |
| | | 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; | |
| | | | |
|
| diagview<eT>& t = *this; | | const Proxy<T1> P( o.get_ref() ); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| ( (t.n_elem != x.n_elem) || (x.is_vec() == false) ), | | ( (d.n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_co
ls() != 1)) ), | |
| "diagview: given object has incompatible size" | | "diagview: given object has incompatible size" | |
| ); | | ); | |
| | | | |
|
| Mat<eT>& t_m = const_cast< Mat<eT>& >(t.m); | | const bool is_alias = P.is_alias(d_m); | |
| | | | |
|
| const uword t_n_elem = t.n_elem; | | arma_extra_debug_warn(is_alias, "aliasing detected"); | |
| const uword t_row_offset = t.row_offset; | | | |
| const uword t_col_offset = t.col_offset; | | | |
| | | | |
|
| const eT* x_mem = x.memptr(); | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) || (Proxy<T1 | |
| | | >::prefer_at_accessor == true) || (is_alias == true) ) | |
| uword i,j; | | | |
| for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp_i = x_mem[i]; | | const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); | |
| const eT tmp_j = x_mem[j]; | | const Mat<eT>& x = tmp.M; | |
| | | | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) += tmp_i; | | const eT* x_mem = x.memptr(); | |
| t_m.at( j + t_row_offset, j + t_col_offset) += tmp_j; | | | |
| } | | | |
| | | | |
|
| if(i < t_n_elem) | | 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 | |
| { | | { | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) += x_mem[i]; | | 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]; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| 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) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const unwrap<T1> tmp(o.get_ref()); | | diagview<eT>& d = *this; | |
| const Mat<eT>& x = tmp.M; | | | |
| | | Mat<eT>& d_m = const_cast< Mat<eT>& >(d.m); | |
| | | | |
|
| diagview<eT>& t = *this; | | 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 | | arma_debug_check | |
| ( | | ( | |
|
| ( (t.n_elem != x.n_elem) || (x.is_vec() == false) ), | | ( (d.n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_co
ls() != 1)) ), | |
| "diagview: given object has incompatible size" | | "diagview: given object has incompatible size" | |
| ); | | ); | |
| | | | |
|
| Mat<eT>& t_m = const_cast< Mat<eT>& >(t.m); | | const bool is_alias = P.is_alias(d_m); | |
| | | | |
| 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 eT* x_mem = x.memptr(); | | arma_extra_debug_warn(is_alias, "aliasing detected"); | |
| | | | |
|
| uword i,j; | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) || (Proxy<T1 | |
| for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | | >::prefer_at_accessor == true) || (is_alias == true) ) | |
| { | | { | |
|
| const eT tmp_i = x_mem[i]; | | const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); | |
| const eT tmp_j = x_mem[j]; | | const Mat<eT>& x = tmp.M; | |
| | | | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) -= tmp_i; | | const eT* x_mem = x.memptr(); | |
| t_m.at( j + t_row_offset, j + t_col_offset) -= tmp_j; | | | |
| } | | 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]; | |
| | | | |
|
| if(i < t_n_elem) | | 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 | |
| { | | { | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) -= x_mem[i]; | | 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]; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| 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) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const unwrap<T1> tmp(o.get_ref()); | | diagview<eT>& d = *this; | |
| const Mat<eT>& x = tmp.M; | | | |
| | | | |
|
| diagview<eT>& t = *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 | | arma_debug_check | |
| ( | | ( | |
|
| ( (t.n_elem != x.n_elem) || (x.is_vec() == false) ), | | ( (d.n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_co
ls() != 1)) ), | |
| "diagview: given object has incompatible size" | | "diagview: given object has incompatible size" | |
| ); | | ); | |
| | | | |
|
| Mat<eT>& t_m = const_cast< Mat<eT>& >(t.m); | | const bool is_alias = P.is_alias(d_m); | |
| | | | |
| 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 eT* x_mem = x.memptr(); | | arma_extra_debug_warn(is_alias, "aliasing detected"); | |
| | | | |
|
| uword i,j; | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) || (Proxy<T1 | |
| for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | | >::prefer_at_accessor == true) || (is_alias == true) ) | |
| { | | { | |
|
| const eT tmp_i = x_mem[i]; | | const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); | |
| const eT tmp_j = x_mem[j]; | | const Mat<eT>& x = tmp.M; | |
| | | | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) *= tmp_i; | | const eT* x_mem = x.memptr(); | |
| t_m.at( j + t_row_offset, j + t_col_offset) *= tmp_j; | | | |
| } | | 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(i < t_n_elem) | | if(ii < d_n_elem) | |
| | | { | |
| | | d_m.at( ii + d_row_offset, ii + d_col_offset) *= x_mem[ii]; | |
| | | } | |
| | | } | |
| | | else | |
| { | | { | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) *= x_mem[i]; | | 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]; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| 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) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| const unwrap<T1> tmp(o.get_ref()); | | diagview<eT>& d = *this; | |
| const Mat<eT>& x = tmp.M; | | | |
| | | 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; | |
| | | | |
|
| diagview<eT>& t = *this; | | const Proxy<T1> P( o.get_ref() ); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| ( (t.n_elem != x.n_elem) || (x.is_vec() == false) ), | | ( (d.n_elem != P.get_n_elem()) || ((P.get_n_rows() != 1) && (P.get_n_co
ls() != 1)) ), | |
| "diagview: given object has incompatible size" | | "diagview: given object has incompatible size" | |
| ); | | ); | |
| | | | |
|
| Mat<eT>& t_m = const_cast< Mat<eT>& >(t.m); | | const bool is_alias = P.is_alias(d_m); | |
| | | | |
|
| const uword t_n_elem = t.n_elem; | | arma_extra_debug_warn(is_alias, "aliasing detected"); | |
| const uword t_row_offset = t.row_offset; | | | |
| const uword t_col_offset = t.col_offset; | | | |
| | | | |
|
| const eT* x_mem = x.memptr(); | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) || (Proxy<T1 | |
| | | >::prefer_at_accessor == true) || (is_alias == true) ) | |
| uword i,j; | | | |
| for(i=0, j=1; j < t_n_elem; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp_i = x_mem[i]; | | const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); | |
| const eT tmp_j = x_mem[j]; | | const Mat<eT>& x = tmp.M; | |
| | | | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) /= tmp_i; | | const eT* x_mem = x.memptr(); | |
| t_m.at( j + t_row_offset, j + t_col_offset) /= tmp_j; | | | |
| } | | | |
| | | | |
|
| if(i < t_n_elem) | | 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 | |
| { | | { | |
|
| t_m.at( i + t_row_offset, i + t_col_offset) /= x_mem[i]; | | 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]; | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! 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) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 548 | | skipping to change at line 688 | |
| | | | |
| if(i < in_n_elem) | | 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 ii) | |
| { | | { | |
|
| return (const_cast< Mat<eT>& >(m)).at(i+row_offset, i+col_offset); | | return (const_cast< Mat<eT>& >(m)).at(ii+row_offset, ii+col_offset); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT | | eT | |
|
| diagview<eT>::operator[](const uword i) const | | diagview<eT>::operator[](const uword ii) const | |
| { | | { | |
|
| return m.at(i+row_offset, i+col_offset); | | return m.at(ii+row_offset, ii+col_offset); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
|
| diagview<eT>::at(const uword i) | | diagview<eT>::at(const uword ii) | |
| { | | { | |
|
| return (const_cast< Mat<eT>& >(m)).at(i+row_offset, i+col_offset); | | return (const_cast< Mat<eT>& >(m)).at(ii+row_offset, ii+col_offset); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT | | eT | |
|
| diagview<eT>::at(const uword i) const | | diagview<eT>::at(const uword ii) const | |
| { | | { | |
|
| return m.at(i+row_offset, i+col_offset); | | return m.at(ii+row_offset, ii+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 ii) | |
| { | | { | |
|
| arma_debug_check( (i >= n_elem), "diagview::operator(): out of bounds" ); | | arma_debug_check( (ii >= n_elem), "diagview::operator(): out of bounds" )
; | |
| | | | |
|
| return (const_cast< Mat<eT>& >(m)).at(i+row_offset, i+col_offset); | | return (const_cast< Mat<eT>& >(m)).at(ii+row_offset, ii+col_offset); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT | | eT | |
|
| diagview<eT>::operator()(const uword i) const | | diagview<eT>::operator()(const uword ii) const | |
| { | | { | |
|
| arma_debug_check( (i >= n_elem), "diagview::operator(): out of bounds" ); | | arma_debug_check( (ii >= n_elem), "diagview::operator(): out of bounds" )
; | |
| | | | |
|
| return m.at(i+row_offset, i+col_offset); | | return m.at(ii+row_offset, ii+col_offset); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| arma_inline | | arma_inline | |
| eT& | | eT& | |
| diagview<eT>::at(const uword row, const uword) | | diagview<eT>::at(const uword row, const uword) | |
| { | | { | |
| return (const_cast< Mat<eT>& >(m)).at(row+row_offset, row+col_offset); | | return (const_cast< Mat<eT>& >(m)).at(row+row_offset, row+col_offset); | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 666 | | skipping to change at line 806 | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::fill(const eT val) | | diagview<eT>::fill(const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>& x = const_cast< Mat<eT>& >(m); | | Mat<eT>& x = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| for(uword i=0; i<n_elem; ++i) | | for(uword ii=0; ii < n_elem; ++ii) | |
| { | | { | |
|
| x.at(i+row_offset, i+col_offset) = val; | | x.at(ii+row_offset, ii+col_offset) = val; | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| diagview<eT>::zeros() | | diagview<eT>::zeros() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
End of changes. 84 change blocks. |
| 134 lines changed or deleted | | 279 lines changed or added | |
|
| eglue_core_meat.hpp | | eglue_core_meat.hpp | |
| | | | |
| skipping to change at line 178 | | skipping to change at line 178 | |
| const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T
2>::prefer_at_accessor); | | const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T
2>::prefer_at_accessor); | |
| | | | |
| // NOTE: we're assuming that the matrix has already been set to the corre
ct size and there is no aliasing; | | // NOTE: we're assuming that the matrix has already been set to the corre
ct size and there is no aliasing; | |
| // 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=() | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| if(prefer_at_accessor == false) | | if(prefer_at_accessor == false) | |
| { | | { | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
|
| | | //const uword n_elem = x.get_n_elem(); // for fixed-sized matrices this
causes a mis-optimisation (slowdown) of the loop under GCC 4.4 | |
| | | | |
| typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | | typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | |
| typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | | typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(=, +); } | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(=, +); } | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(=, -); } | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(=, -); } | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(=, /); } | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(=, /); } | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(=, *); } | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(=, *); } | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 225 | | skipping to change at line 226 | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T
2>::prefer_at_accessor); | | const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T
2>::prefer_at_accessor); | |
| | | | |
| if(prefer_at_accessor == false) | | if(prefer_at_accessor == false) | |
| { | | { | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
|
| | | //const uword n_elem = x.get_n_elem(); // for fixed-sized matrices this
causes a mis-optimisation (slowdown) of the loop under GCC 4.4 | |
| | | | |
| typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | | typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | |
| typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | | typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(+=, +); } | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(+=, +); } | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(+=, -); } | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(+=, -); } | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(+=, /); } | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(+=, /); } | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(+=, *); } | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(+=, *); } | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 269 | | skipping to change at line 271 | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T
2>::prefer_at_accessor); | | const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T
2>::prefer_at_accessor); | |
| | | | |
| if(prefer_at_accessor == false) | | if(prefer_at_accessor == false) | |
| { | | { | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
|
| | | //const uword n_elem = x.get_n_elem(); // for fixed-sized matrices this
causes a mis-optimisation (slowdown) of the loop under GCC 4.4 | |
| | | | |
| typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | | typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | |
| typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | | typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(-=, +); } | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(-=, +); } | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(-=, -); } | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(-=, -); } | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(-=, /); } | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(-=, /); } | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(-=, *); } | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(-=, *); } | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 313 | | skipping to change at line 316 | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T
2>::prefer_at_accessor); | | const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T
2>::prefer_at_accessor); | |
| | | | |
| if(prefer_at_accessor == false) | | if(prefer_at_accessor == false) | |
| { | | { | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
|
| | | //const uword n_elem = x.get_n_elem(); // for fixed-sized matrices this
causes a mis-optimisation (slowdown) of the loop under GCC 4.4 | |
| | | | |
| typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | | typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | |
| typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | | typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(*=, +); } | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(*=, +); } | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(*=, -); } | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(*=, -); } | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(*=, /); } | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(*=, /); } | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(*=, *); } | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(*=, *); } | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 357 | | skipping to change at line 361 | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T
2>::prefer_at_accessor); | | const bool prefer_at_accessor = (Proxy<T1>::prefer_at_accessor || Proxy<T
2>::prefer_at_accessor); | |
| | | | |
| if(prefer_at_accessor == false) | | if(prefer_at_accessor == false) | |
| { | | { | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
|
| | | //const uword n_elem = x.get_n_elem(); // for fixed-sized matrices this
causes a mis-optimisation (slowdown) of the loop under GCC 4.4 | |
| | | | |
| typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | | typename Proxy<T1>::ea_type P1 = x.P1.get_ea(); | |
| typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | | typename Proxy<T2>::ea_type P2 = x.P2.get_ea(); | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(/=, +); } | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(/=, +); } | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(/=, -); } | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(/=, -); } | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(/=, /); } | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(/=, /); } | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(/=, *); } | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(/=, *); } | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 450 | | skipping to change at line 455 | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "addition"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "addition"); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || Pro
xyCube<T2>::prefer_at_accessor); | | const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || Pro
xyCube<T2>::prefer_at_accessor); | |
| | | | |
| if(prefer_at_accessor == false) | | if(prefer_at_accessor == false) | |
| { | | { | |
|
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
| | | | |
| typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | | typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | |
| typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | | typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(+=, +); } | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(+=, +); } | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(+=, -); } | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(+=, -); } | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(+=, /); } | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(+=, /); } | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(+=, *); } | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(+=, *); } | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 495 | | skipping to change at line 500 | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "subtraction"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "subtraction"); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || Pro
xyCube<T2>::prefer_at_accessor); | | const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || Pro
xyCube<T2>::prefer_at_accessor); | |
| | | | |
| if(prefer_at_accessor == false) | | if(prefer_at_accessor == false) | |
| { | | { | |
|
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
| | | | |
| typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | | typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | |
| typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | | typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(-=, +); } | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(-=, +); } | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(-=, -); } | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(-=, -); } | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(-=, /); } | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(-=, /); } | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(-=, *); } | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(-=, *); } | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 540 | | skipping to change at line 545 | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise multiplication"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise multiplication"); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || Pro
xyCube<T2>::prefer_at_accessor); | | const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || Pro
xyCube<T2>::prefer_at_accessor); | |
| | | | |
| if(prefer_at_accessor == false) | | if(prefer_at_accessor == false) | |
| { | | { | |
|
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
| | | | |
| typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | | typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | |
| typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | | typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(*=, +); } | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(*=, +); } | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(*=, -); } | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(*=, -); } | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(*=, /); } | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(*=, /); } | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(*=, *); } | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(*=, *); } | |
| } | | } | |
| else | | else | |
| | | | |
| skipping to change at line 585 | | skipping to change at line 590 | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise division"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise division"); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || Pro
xyCube<T2>::prefer_at_accessor); | | const bool prefer_at_accessor = (ProxyCube<T1>::prefer_at_accessor || Pro
xyCube<T2>::prefer_at_accessor); | |
| | | | |
| if(prefer_at_accessor == false) | | if(prefer_at_accessor == false) | |
| { | | { | |
|
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
| | | | |
| typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | | typename ProxyCube<T1>::ea_type P1 = x.P1.get_ea(); | |
| typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | | typename ProxyCube<T2>::ea_type P2 = x.P2.get_ea(); | |
| | | | |
| if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(/=, +); } | | if(is_same_type<eglue_type, eglue_plus >::value == true) { arma_ap
plier_1(/=, +); } | |
| else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(/=, -); } | | else if(is_same_type<eglue_type, eglue_minus>::value == true) { arma_ap
plier_1(/=, -); } | |
| else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(/=, /); } | | else if(is_same_type<eglue_type, eglue_div >::value == true) { arma_ap
plier_1(/=, /); } | |
| else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(/=, *); } | | else if(is_same_type<eglue_type, eglue_schur>::value == true) { arma_ap
plier_1(/=, *); } | |
| } | | } | |
| else | | else | |
| | | | |
End of changes. 9 change blocks. |
| 4 lines changed or deleted | | 9 lines changed or added | |
|
| eop_core_meat.hpp | | eop_core_meat.hpp | |
| | | | |
| skipping to change at line 135 | | skipping to change at line 135 | |
| | | | |
| // NOTE: we're assuming that the matrix has already been set to the corre
ct size and there is no aliasing; | | // NOTE: we're assuming that the matrix has already been set to the corre
ct size and there is no aliasing; | |
| // 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 eT k = x.aux; | | const eT k = x.aux; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| if(Proxy<T1>::prefer_at_accessor == false) | | if(Proxy<T1>::prefer_at_accessor == false) | |
| { | | { | |
| const uword n_elem = out.n_elem; | | const uword n_elem = out.n_elem; | |
|
| | | //const uword n_elem = x.get_n_elem(); // for fixed-sized matrices this
causes a mis-optimisation (slowdown) of the loop under GCC 4.4 | |
| | | | |
| typename Proxy<T1>::ea_type P = x.P.get_ea(); | | typename Proxy<T1>::ea_type P = x.P.get_ea(); | |
| | | | |
| arma_applier_1(=); | | arma_applier_1(=); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const uword n_rows = x.get_n_rows(); | | const uword n_rows = x.get_n_rows(); | |
| const uword n_cols = x.get_n_cols(); | | const uword n_cols = x.get_n_cols(); | |
| | | | |
| | | | |
| skipping to change at line 167 | | skipping to change at line 168 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const uword n_rows = x.get_n_rows(); | | const uword n_rows = x.get_n_rows(); | |
| const uword n_cols = x.get_n_cols(); | | const uword n_cols = x.get_n_cols(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addi
tion"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "addi
tion"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | const eT k = x.aux; | |
| const uword n_elem = out.n_elem; | | eT* out_mem = out.memptr(); | |
| | | | |
| const eT k = x.aux; | | | |
| | | | |
| if(Proxy<T1>::prefer_at_accessor == false) | | if(Proxy<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| | | const uword n_elem = out.n_elem; | |
| | | //const uword n_elem = x.get_n_elem(); // for fixed-sized matrices this | |
| | | causes a mis-optimisation (slowdown) of the loop under GCC 4.4 | |
| | | | |
| typename Proxy<T1>::ea_type P = x.P.get_ea(); | | typename Proxy<T1>::ea_type P = x.P.get_ea(); | |
| | | | |
| arma_applier_1(+=); | | arma_applier_1(+=); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Proxy<T1>& P = x.P; | | const Proxy<T1>& P = x.P; | |
| | | | |
| arma_applier_2(+=); | | arma_applier_2(+=); | |
| } | | } | |
| | | | |
| skipping to change at line 202 | | skipping to change at line 204 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const uword n_rows = x.get_n_rows(); | | const uword n_rows = x.get_n_rows(); | |
| const uword n_cols = x.get_n_cols(); | | const uword n_cols = x.get_n_cols(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subt
raction"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "subt
raction"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | const eT k = x.aux; | |
| const uword n_elem = out.n_elem; | | eT* out_mem = out.memptr(); | |
| | | | |
| const eT k = x.aux; | | | |
| | | | |
| if(Proxy<T1>::prefer_at_accessor == false) | | if(Proxy<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| | | const uword n_elem = out.n_elem; | |
| | | //const uword n_elem = x.get_n_elem(); // for fixed-sized matrices this | |
| | | causes a mis-optimisation (slowdown) of the loop under GCC 4.4 | |
| | | | |
| typename Proxy<T1>::ea_type P = x.P.get_ea(); | | typename Proxy<T1>::ea_type P = x.P.get_ea(); | |
| | | | |
| arma_applier_1(-=); | | arma_applier_1(-=); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Proxy<T1>& P = x.P; | | const Proxy<T1>& P = x.P; | |
| | | | |
| arma_applier_2(-=); | | arma_applier_2(-=); | |
| } | | } | |
| | | | |
| skipping to change at line 237 | | skipping to change at line 240 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const uword n_rows = x.get_n_rows(); | | const uword n_rows = x.get_n_rows(); | |
| const uword n_cols = x.get_n_cols(); | | const uword n_cols = x.get_n_cols(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "elem
ent-wise multiplication"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "elem
ent-wise multiplication"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | const eT k = x.aux; | |
| const uword n_elem = out.n_elem; | | eT* out_mem = out.memptr(); | |
| | | | |
| const eT k = x.aux; | | | |
| | | | |
| if(Proxy<T1>::prefer_at_accessor == false) | | if(Proxy<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| | | const uword n_elem = out.n_elem; | |
| | | //const uword n_elem = x.get_n_elem(); // for fixed-sized matrices this | |
| | | causes a mis-optimisation (slowdown) of the loop under GCC 4.4 | |
| | | | |
| typename Proxy<T1>::ea_type P = x.P.get_ea(); | | typename Proxy<T1>::ea_type P = x.P.get_ea(); | |
| | | | |
| arma_applier_1(*=); | | arma_applier_1(*=); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Proxy<T1>& P = x.P; | | const Proxy<T1>& P = x.P; | |
| | | | |
| arma_applier_2(*=); | | arma_applier_2(*=); | |
| } | | } | |
| | | | |
| skipping to change at line 272 | | skipping to change at line 276 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const uword n_rows = x.get_n_rows(); | | const uword n_rows = x.get_n_rows(); | |
| const uword n_cols = x.get_n_cols(); | | const uword n_cols = x.get_n_cols(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "elem
ent-wise division"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, n_rows, n_cols, "elem
ent-wise division"); | |
| | | | |
|
| | | const eT k = x.aux; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
|
| const uword n_elem = out.n_elem; | | | |
| | | | |
| const eT k = x.aux; | | | |
| | | | |
| if(Proxy<T1>::prefer_at_accessor == false) | | if(Proxy<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| | | const uword n_elem = out.n_elem; | |
| | | //const uword n_elem = x.get_n_elem(); // for fixed-sized matrices this | |
| | | causes a mis-optimisation (slowdown) of the loop under GCC 4.4 | |
| | | | |
| typename Proxy<T1>::ea_type P = x.P.get_ea(); | | typename Proxy<T1>::ea_type P = x.P.get_ea(); | |
| | | | |
| arma_applier_1(/=); | | arma_applier_1(/=); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const Proxy<T1>& P = x.P; | | const Proxy<T1>& P = x.P; | |
| | | | |
| arma_applier_2(/=); | | arma_applier_2(/=); | |
| } | | } | |
| | | | |
| skipping to change at line 305 | | skipping to change at line 310 | |
| template<typename T1> | | template<typename T1> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| void | | void | |
| eop_core<eop_type>::apply(Cube<typename T1::elem_type>& out, const eOpCube<
T1, eop_type>& x) | | eop_core<eop_type>::apply(Cube<typename T1::elem_type>& out, const eOpCube<
T1, eop_type>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| const uword n_rows = out.n_rows; | | | |
| const uword n_cols = out.n_cols; | | | |
| const uword n_slices = out.n_slices; | | | |
| const uword n_elem = out.n_elem; | | | |
| | | | |
| // NOTE: we're assuming that the matrix has already been set to the corre
ct size and there is no aliasing; | | // NOTE: we're assuming that the matrix has already been set to the corre
ct size and there is no aliasing; | |
| // 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 eT k = x.aux; | | const eT k = x.aux; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
| | | | |
| if(ProxyCube<T1>::prefer_at_accessor == false) | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| | | const uword n_elem = out.n_elem; | |
| | | | |
| typename ProxyCube<T1>::ea_type P = x.P.get_ea(); | | typename ProxyCube<T1>::ea_type P = x.P.get_ea(); | |
| | | | |
| arma_applier_1(=); | | arma_applier_1(=); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| | | const uword n_rows = x.get_n_rows(); | |
| | | const uword n_cols = x.get_n_cols(); | |
| | | const uword n_slices = x.get_n_slices(); | |
| | | | |
| const ProxyCube<T1>& P = x.P; | | const ProxyCube<T1>& P = x.P; | |
| | | | |
| arma_applier_3(=); | | arma_applier_3(=); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eop_type> | | template<typename eop_type> | |
| template<typename T1> | | template<typename T1> | |
| arma_hot | | arma_hot | |
| inline | | inline | |
| | | | |
| skipping to change at line 347 | | skipping to change at line 353 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const uword n_rows = x.get_n_rows(); | | const uword n_rows = x.get_n_rows(); | |
| const uword n_cols = x.get_n_cols(); | | const uword n_cols = x.get_n_cols(); | |
| const uword n_slices = x.get_n_slices(); | | const uword n_slices = x.get_n_slices(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "addition"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "addition"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | const eT k = x.aux; | |
| const uword n_elem = out.n_elem; | | eT* out_mem = out.memptr(); | |
| | | | |
| const eT k = x.aux; | | | |
| | | | |
| if(ProxyCube<T1>::prefer_at_accessor == false) | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| | | const uword n_elem = out.n_elem; | |
| | | | |
| typename ProxyCube<T1>::ea_type P = x.P.get_ea(); | | typename ProxyCube<T1>::ea_type P = x.P.get_ea(); | |
| | | | |
| arma_applier_1(+=); | | arma_applier_1(+=); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const ProxyCube<T1>& P = x.P; | | const ProxyCube<T1>& P = x.P; | |
| | | | |
| arma_applier_3(+=); | | arma_applier_3(+=); | |
| } | | } | |
| | | | |
| skipping to change at line 383 | | skipping to change at line 389 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const uword n_rows = x.get_n_rows(); | | const uword n_rows = x.get_n_rows(); | |
| const uword n_cols = x.get_n_cols(); | | const uword n_cols = x.get_n_cols(); | |
| const uword n_slices = x.get_n_slices(); | | const uword n_slices = x.get_n_slices(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "subtraction"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "subtraction"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | const eT k = x.aux; | |
| const uword n_elem = out.n_elem; | | eT* out_mem = out.memptr(); | |
| | | | |
| const eT k = x.aux; | | | |
| | | | |
| if(ProxyCube<T1>::prefer_at_accessor == false) | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| | | const uword n_elem = out.n_elem; | |
| | | | |
| typename ProxyCube<T1>::ea_type P = x.P.get_ea(); | | typename ProxyCube<T1>::ea_type P = x.P.get_ea(); | |
| | | | |
| arma_applier_1(-=); | | arma_applier_1(-=); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const ProxyCube<T1>& P = x.P; | | const ProxyCube<T1>& P = x.P; | |
| | | | |
| arma_applier_3(-=); | | arma_applier_3(-=); | |
| } | | } | |
| | | | |
| skipping to change at line 419 | | skipping to change at line 425 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const uword n_rows = x.get_n_rows(); | | const uword n_rows = x.get_n_rows(); | |
| const uword n_cols = x.get_n_cols(); | | const uword n_cols = x.get_n_cols(); | |
| const uword n_slices = x.get_n_slices(); | | const uword n_slices = x.get_n_slices(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise multiplication"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise multiplication"); | |
| | | | |
|
| eT* out_mem = out.memptr(); | | const eT k = x.aux; | |
| const uword n_elem = out.n_elem; | | eT* out_mem = out.memptr(); | |
| | | | |
| const eT k = x.aux; | | | |
| | | | |
| if(ProxyCube<T1>::prefer_at_accessor == false) | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| | | const uword n_elem = out.n_elem; | |
| | | | |
| typename ProxyCube<T1>::ea_type P = x.P.get_ea(); | | typename ProxyCube<T1>::ea_type P = x.P.get_ea(); | |
| | | | |
| arma_applier_1(*=); | | arma_applier_1(*=); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const ProxyCube<T1>& P = x.P; | | const ProxyCube<T1>& P = x.P; | |
| | | | |
| arma_applier_3(*=); | | arma_applier_3(*=); | |
| } | | } | |
| | | | |
| skipping to change at line 455 | | skipping to change at line 461 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| const uword n_rows = x.get_n_rows(); | | const uword n_rows = x.get_n_rows(); | |
| const uword n_cols = x.get_n_cols(); | | const uword n_cols = x.get_n_cols(); | |
| const uword n_slices = x.get_n_slices(); | | const uword n_slices = x.get_n_slices(); | |
| | | | |
| arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise division"); | | arma_debug_assert_same_size(out.n_rows, out.n_cols, out.n_slices, n_rows,
n_cols, n_slices, "element-wise division"); | |
| | | | |
|
| | | const eT k = x.aux; | |
| eT* out_mem = out.memptr(); | | eT* out_mem = out.memptr(); | |
|
| const uword n_elem = out.n_elem; | | | |
| | | | |
| const eT k = x.aux; | | | |
| | | | |
| if(ProxyCube<T1>::prefer_at_accessor == false) | | if(ProxyCube<T1>::prefer_at_accessor == false) | |
| { | | { | |
|
| | | const uword n_elem = out.n_elem; | |
| | | | |
| typename ProxyCube<T1>::ea_type P = x.P.get_ea(); | | typename ProxyCube<T1>::ea_type P = x.P.get_ea(); | |
| | | | |
| arma_applier_1(/=); | | arma_applier_1(/=); | |
| } | | } | |
| else | | else | |
| { | | { | |
| const ProxyCube<T1>& P = x.P; | | const ProxyCube<T1>& P = x.P; | |
| | | | |
| arma_applier_3(/=); | | arma_applier_3(/=); | |
| } | | } | |
| | | | |
| skipping to change at line 483 | | skipping to change at line 489 | |
| | | | |
| // | | // | |
| // common | | // common | |
| | | | |
| template<typename eop_type> | | template<typename eop_type> | |
| template<typename eT> | | template<typename eT> | |
| arma_hot | | arma_hot | |
| arma_pure | | arma_pure | |
| arma_inline | | arma_inline | |
| eT | | eT | |
|
| eop_core<eop_type>::process(const eT val, const eT k) | | eop_core<eop_type>::process(const eT, const eT) | |
| { | | { | |
|
| arma_ignore(val); | | | |
| arma_ignore(k); | | | |
| | | | |
| arma_stop("eop_core::process(): unhandled eop_type"); | | arma_stop("eop_core::process(): unhandled eop_type"); | |
| return eT(0); | | return eT(0); | |
| } | | } | |
| | | | |
| template<> template<typename eT> arma_hot arma_const arma_inline eT | | template<> template<typename eT> arma_hot arma_const arma_inline eT | |
| eop_core<eop_scalar_plus >::process(const eT val, const eT k) { return
val + k; } | | eop_core<eop_scalar_plus >::process(const eT val, const eT k) { return
val + k; } | |
| | | | |
| template<> template<typename eT> arma_hot arma_const arma_inline eT | | template<> template<typename eT> arma_hot arma_const arma_inline eT | |
| eop_core<eop_scalar_minus_pre >::process(const eT val, const eT k) { return
k - val; } | | eop_core<eop_scalar_minus_pre >::process(const eT val, const eT k) { return
k - val; } | |
| | | | |
| | | | |
End of changes. 24 change blocks. |
| 39 lines changed or deleted | | 46 lines changed or added | |
|
| op_princomp_meat.hpp | | op_princomp_meat.hpp | |
|
| // Copyright (C) 2010-2011 NICTA (www.nicta.com.au) | | // Copyright (C) 2010-2012 NICTA (www.nicta.com.au) | |
| // Copyright (C) 2010-2011 Conrad Sanderson | | // Copyright (C) 2010-2012 Conrad Sanderson | |
| // Copyright (C) 2010 Dimitrios Bouzas | | // Copyright (C) 2010 Dimitrios Bouzas | |
| // Copyright (C) 2011 Stanislav Funiak | | // Copyright (C) 2011 Stanislav Funiak | |
| // | | // | |
| // This file is part of the Armadillo C++ library. | | // This file is part of the Armadillo C++ library. | |
| // It is provided without any warranty of fitness | | // It is provided without any warranty of fitness | |
| // for any purpose. You can redistribute this file | | // for any purpose. You can redistribute this file | |
| // and/or modify it under the terms of the GNU | | // and/or modify it under the terms of the GNU | |
| // Lesser General Public License (LGPL) as published | | // Lesser General Public License (LGPL) as published | |
| // by the Free Software Foundation, either version 3 | | // by the Free Software Foundation, either version 3 | |
| // of the License or (at your option) any later version. | | // of the License or (at your option) any later version. | |
| | | | |
| skipping to change at line 25 | | skipping to change at line 25 | |
| //! \addtogroup op_princomp | | //! \addtogroup op_princomp | |
| //! @{ | | //! @{ | |
| | | | |
| //! \brief | | //! \brief | |
| //! principal component analysis -- 4 arguments version | | //! principal component analysis -- 4 arguments version | |
| //! computation is done via singular value decomposition | | //! computation is done via singular value decomposition | |
| //! coeff_out -> principal component coefficients | | //! coeff_out -> principal component coefficients | |
| //! score_out -> projected samples | | //! score_out -> projected samples | |
| //! latent_out -> eigenvalues of principal vectors | | //! latent_out -> eigenvalues of principal vectors | |
| //! tsquared_out -> Hotelling's T^2 statistic | | //! tsquared_out -> Hotelling's T^2 statistic | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| op_princomp::direct_princomp | | op_princomp::direct_princomp | |
| ( | | ( | |
|
| Mat<eT>& coeff_out, | | Mat<typename T1::elem_type>& coeff_out, | |
| Mat<eT>& score_out, | | Mat<typename T1::elem_type>& score_out, | |
| Col<eT>& latent_out, | | Col<typename T1::elem_type>& latent_out, | |
| Col<eT>& tsquared_out, | | Col<typename T1::elem_type>& tsquared_out, | |
| const Mat<eT>& in | | const Base<typename T1::elem_type, T1>& X, | |
| | | const typename arma_not_cx<typename T1::elem_type>::result* junk | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in - repmat(mean(in), n_rows, 1); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| | | | |
| skipping to change at line 116 | | skipping to change at line 123 | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| //! \brief | | //! \brief | |
| //! principal component analysis -- 3 arguments version | | //! principal component analysis -- 3 arguments version | |
| //! computation is done via singular value decomposition | | //! computation is done via singular value decomposition | |
| //! coeff_out -> principal component coefficients | | //! coeff_out -> principal component coefficients | |
| //! score_out -> projected samples | | //! score_out -> projected samples | |
| //! latent_out -> eigenvalues of principal vectors | | //! latent_out -> eigenvalues of principal vectors | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| op_princomp::direct_princomp | | op_princomp::direct_princomp | |
| ( | | ( | |
|
| Mat<eT>& coeff_out, | | Mat<typename T1::elem_type>& coeff_out, | |
| Mat<eT>& score_out, | | Mat<typename T1::elem_type>& score_out, | |
| Col<eT>& latent_out, | | Col<typename T1::elem_type>& latent_out, | |
| const Mat<eT>& in | | const Base<typename T1::elem_type, T1>& X, | |
| | | const typename arma_not_cx<typename T1::elem_type>::result* junk | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in - repmat(mean(in), n_rows, 1); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| | | | |
| skipping to change at line 188 | | skipping to change at line 202 | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| //! \brief | | //! \brief | |
| //! principal component analysis -- 2 arguments version | | //! principal component analysis -- 2 arguments version | |
| //! computation is done via singular value decomposition | | //! computation is done via singular value decomposition | |
| //! coeff_out -> principal component coefficients | | //! coeff_out -> principal component coefficients | |
| //! score_out -> projected samples | | //! score_out -> projected samples | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| op_princomp::direct_princomp | | op_princomp::direct_princomp | |
| ( | | ( | |
|
| Mat<eT>& coeff_out, | | Mat<typename T1::elem_type>& coeff_out, | |
| Mat<eT>& score_out, | | Mat<typename T1::elem_type>& score_out, | |
| const Mat<eT>& in | | const Base<typename T1::elem_type, T1>& X, | |
| | | const typename arma_not_cx<typename T1::elem_type>::result* junk | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in - repmat(mean(in), n_rows, 1); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| | | | |
| skipping to change at line 250 | | skipping to change at line 271 | |
| score_out.zeros(); | | score_out.zeros(); | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| //! \brief | | //! \brief | |
| //! principal component analysis -- 1 argument version | | //! principal component analysis -- 1 argument version | |
| //! computation is done via singular value decomposition | | //! computation is done via singular value decomposition | |
| //! coeff_out -> principal component coefficients | | //! coeff_out -> principal component coefficients | |
|
| template<typename eT> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| op_princomp::direct_princomp | | op_princomp::direct_princomp | |
| ( | | ( | |
|
| Mat<eT>& coeff_out, | | Mat<typename T1::elem_type>& coeff_out, | |
| const Mat<eT>& in | | const Base<typename T1::elem_type, T1>& X, | |
| | | const typename arma_not_cx<typename T1::elem_type>::result* junk | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | const unwrap<T1> Y( X.get_ref() ); | |
| | | const Mat<eT>& in = Y.M; | |
| | | | |
| if(in.n_elem != 0) | | if(in.n_elem != 0) | |
| { | | { | |
| // singular value decomposition | | // singular value decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
| Col<eT> s; | | Col<eT> s; | |
| | | | |
| const Mat<eT> tmp = in - repmat(mean(in), in.n_rows, 1); | | const Mat<eT> tmp = in - repmat(mean(in), in.n_rows, 1); | |
| | | | |
| const bool svd_ok = svd(U,s,coeff_out, tmp); | | const bool svd_ok = svd(U,s,coeff_out, tmp); | |
| | | | |
| skipping to change at line 291 | | skipping to change at line 319 | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| //! \brief | | //! \brief | |
| //! principal component analysis -- 4 arguments complex version | | //! principal component analysis -- 4 arguments complex version | |
| //! computation is done via singular value decomposition | | //! computation is done via singular value decomposition | |
| //! coeff_out -> principal component coefficients | | //! coeff_out -> principal component coefficients | |
| //! score_out -> projected samples | | //! score_out -> projected samples | |
| //! latent_out -> eigenvalues of principal vectors | | //! latent_out -> eigenvalues of principal vectors | |
| //! tsquared_out -> Hotelling's T^2 statistic | | //! tsquared_out -> Hotelling's T^2 statistic | |
|
| template<typename T> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| op_princomp::direct_princomp | | op_princomp::direct_princomp | |
| ( | | ( | |
|
| Mat< std::complex<T> >& coeff_out, | | Mat< std::complex<typename T1::pod_type> >& coeff_out, | |
| Mat< std::complex<T> >& score_out, | | Mat< std::complex<typename T1::pod_type> >& score_out, | |
| Col<T>& latent_out, | | Col< typename T1::pod_type >& latent_out, | |
| Col< std::complex<T> >& tsquared_out, | | Col< std::complex<typename T1::pod_type> >& tsquared_out, | |
| const Mat< std::complex<T> >& in | | const Base< std::complex<typename T1::pod_type>, T1 >& X, | |
| | | const typename arma_cx_only<typename T1::elem_type>::result* junk | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename T1::pod_type T; | |
| | | typedef std::complex<T> eT; | |
| | | | |
|
| typedef std::complex<T> eT; | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in - repmat(mean(in), n_rows, 1); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| | | | |
| skipping to change at line 381 | | skipping to change at line 415 | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| //! \brief | | //! \brief | |
| //! principal component analysis -- 3 arguments complex version | | //! principal component analysis -- 3 arguments complex version | |
| //! computation is done via singular value decomposition | | //! computation is done via singular value decomposition | |
| //! coeff_out -> principal component coefficients | | //! coeff_out -> principal component coefficients | |
| //! score_out -> projected samples | | //! score_out -> projected samples | |
| //! latent_out -> eigenvalues of principal vectors | | //! latent_out -> eigenvalues of principal vectors | |
|
| template<typename T> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| op_princomp::direct_princomp | | op_princomp::direct_princomp | |
| ( | | ( | |
|
| Mat< std::complex<T> >& coeff_out, | | Mat< std::complex<typename T1::pod_type> >& coeff_out, | |
| Mat< std::complex<T> >& score_out, | | Mat< std::complex<typename T1::pod_type> >& score_out, | |
| Col<T>& latent_out, | | Col< typename T1::pod_type >& latent_out, | |
| const Mat< std::complex<T> >& in | | const Base< std::complex<typename T1::pod_type>, T1 >& X, | |
| | | const typename arma_cx_only<typename T1::elem_type>::result* junk | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
|
| typedef std::complex<T> eT; | | typedef typename T1::pod_type T; | |
| | | typedef std::complex<T> eT; | |
| | | | |
| | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in - repmat(mean(in), n_rows, 1); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| | | | |
| skipping to change at line 455 | | skipping to change at line 495 | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| //! \brief | | //! \brief | |
| //! principal component analysis -- 2 arguments complex version | | //! principal component analysis -- 2 arguments complex version | |
| //! computation is done via singular value decomposition | | //! computation is done via singular value decomposition | |
| //! coeff_out -> principal component coefficients | | //! coeff_out -> principal component coefficients | |
| //! score_out -> projected samples | | //! score_out -> projected samples | |
|
| template<typename T> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| op_princomp::direct_princomp | | op_princomp::direct_princomp | |
| ( | | ( | |
|
| Mat< std::complex<T> >& coeff_out, | | Mat< std::complex<typename T1::pod_type> >& coeff_out, | |
| Mat< std::complex<T> >& score_out, | | Mat< std::complex<typename T1::pod_type> >& score_out, | |
| const Mat< std::complex<T> >& in | | const Base< std::complex<typename T1::pod_type>, T1 >& X, | |
| | | const typename arma_cx_only<typename T1::elem_type>::result* junk | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename T1::pod_type T; | |
| | | typedef std::complex<T> eT; | |
| | | | |
|
| typedef std::complex<T> eT; | | const unwrap_check<T1> Y( X.get_ref(), score_out ); | |
| | | const Mat<eT>& in = Y.M; | |
| | | | |
| const uword n_rows = in.n_rows; | | const uword n_rows = in.n_rows; | |
| const uword n_cols = in.n_cols; | | const uword n_cols = in.n_cols; | |
| | | | |
| if(n_rows > 1) // more than one sample | | if(n_rows > 1) // more than one sample | |
| { | | { | |
| // subtract the mean - use score_out as temporary matrix | | // subtract the mean - use score_out as temporary matrix | |
| score_out = in - repmat(mean(in), n_rows, 1); | | score_out = in - repmat(mean(in), n_rows, 1); | |
| | | | |
| // singular value decomposition | | // singular value decomposition | |
| | | | |
| skipping to change at line 517 | | skipping to change at line 563 | |
| score_out.zeros(); | | score_out.zeros(); | |
| } | | } | |
| | | | |
| return true; | | return true; | |
| } | | } | |
| | | | |
| //! \brief | | //! \brief | |
| //! principal component analysis -- 1 argument complex version | | //! principal component analysis -- 1 argument complex version | |
| //! computation is done via singular value decomposition | | //! computation is done via singular value decomposition | |
| //! coeff_out -> principal component coefficients | | //! coeff_out -> principal component coefficients | |
|
| template<typename T> | | template<typename T1> | |
| inline | | inline | |
| bool | | bool | |
| op_princomp::direct_princomp | | op_princomp::direct_princomp | |
| ( | | ( | |
|
| Mat< std::complex<T> >& coeff_out, | | Mat< std::complex<typename T1::pod_type> >& coeff_out, | |
| const Mat< std::complex<T> >& in | | const Base< std::complex<typename T1::pod_type>, T1 >& X, | |
| | | const typename arma_cx_only<typename T1::elem_type>::result* junk | |
| ) | | ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
|
| | | arma_ignore(junk); | |
| | | | |
| | | typedef typename T1::pod_type T; | |
| | | typedef std::complex<T> eT; | |
| | | | |
|
| typedef typename std::complex<T> eT; | | const unwrap<T1> Y( X.get_ref() ); | |
| | | const Mat<eT>& in = Y.M; | |
| | | | |
| if(in.n_elem != 0) | | if(in.n_elem != 0) | |
| { | | { | |
| // singular value decomposition | | // singular value decomposition | |
| Mat<eT> U; | | Mat<eT> U; | |
| Col< T> s; | | Col< T> s; | |
| | | | |
| const Mat<eT> tmp = in - repmat(mean(in), in.n_rows, 1); | | const Mat<eT> tmp = in - repmat(mean(in), in.n_rows, 1); | |
| | | | |
| const bool svd_ok = svd(U,s,coeff_out, tmp); | | const bool svd_ok = svd(U,s,coeff_out, tmp); | |
| | | | |
End of changes. 29 change blocks. |
| 42 lines changed or deleted | | 94 lines changed or added | |
|
| subview_elem1_meat.hpp | | subview_elem1_meat.hpp | |
| | | | |
| skipping to change at line 57 | | skipping to change at line 57 | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| ( aa.is_vec() == false ), | | ( aa.is_vec() == false ), | |
| "Mat::elem(): given object is not a vector" | | "Mat::elem(): given object is not a vector" | |
| ); | | ); | |
| | | | |
| const uword* aa_mem = aa.memptr(); | | const uword* aa_mem = aa.memptr(); | |
| const uword aa_n_elem = aa.n_elem; | | const uword aa_n_elem = aa.n_elem; | |
| | | | |
|
| uword i,j; | | uword iq,jq; | |
| for(i=0, j=1; j<aa_n_elem; i+=2, j+=2) | | for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) | |
| { | | { | |
|
| const uword ii = aa_mem[i]; | | const uword ii = aa_mem[iq]; | |
| const uword jj = aa_mem[j]; | | const uword jj = aa_mem[jq]; | |
| | | | |
| arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(
): index out of bounds" ); | | arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::elem(
): index out of bounds" ); | |
| | | | |
| if(is_same_type<op_type, op_subview_elem_equ >::value ==
true) { m_mem[ii] = val; m_mem[jj] = val; } | | if(is_same_type<op_type, op_subview_elem_equ >::value ==
true) { m_mem[ii] = val; m_mem[jj] = val; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value ==
true) { m_mem[ii] += val; m_mem[jj] += val; } | | else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value ==
true) { m_mem[ii] += val; m_mem[jj] += val; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value ==
true) { m_mem[ii] -= val; m_mem[jj] -= val; } | | else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value ==
true) { m_mem[ii] -= val; m_mem[jj] -= val; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value ==
true) { m_mem[ii] *= val; m_mem[jj] *= val; } | | else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value ==
true) { m_mem[ii] *= val; m_mem[jj] *= val; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_div >::value ==
true) { m_mem[ii] /= val; m_mem[jj] /= val; } | | else if(is_same_type<op_type, op_subview_elem_inplace_div >::value ==
true) { m_mem[ii] /= val; m_mem[jj] /= val; } | |
| } | | } | |
| | | | |
|
| if(i < aa_n_elem) | | if(iq < aa_n_elem) | |
| { | | { | |
|
| const uword ii = aa_mem[i]; | | const uword ii = aa_mem[iq]; | |
| | | | |
| arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds"
); | | arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bounds"
); | |
| | | | |
| if(is_same_type<op_type, op_subview_elem_equ >::value ==
true) { m_mem[ii] = val; } | | if(is_same_type<op_type, op_subview_elem_equ >::value ==
true) { m_mem[ii] = val; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value ==
true) { m_mem[ii] += val; } | | else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value ==
true) { m_mem[ii] += val; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value ==
true) { m_mem[ii] -= val; } | | else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value ==
true) { m_mem[ii] -= val; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value ==
true) { m_mem[ii] *= val; } | | else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value ==
true) { m_mem[ii] *= val; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_div >::value ==
true) { m_mem[ii] /= val; } | | else if(is_same_type<op_type, op_subview_elem_inplace_div >::value ==
true) { m_mem[ii] /= val; } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT, typename T1> | | template<typename eT, typename T1> | |
| template<typename op_type, typename T2> | | template<typename op_type, typename T2> | |
| inline | | inline | |
| void | | void | |
| subview_elem1<eT,T1>::inplace_op(const subview_elem1<eT,T2>& x) | | subview_elem1<eT,T1>::inplace_op(const subview_elem1<eT,T2>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
|
| subview_elem1<eT,T1>& t = *this; | | subview_elem1<eT,T1>& s = *this; | |
| | | | |
|
| if(&(t.m) == &(x.m)) | | if(&(s.m) == &(x.m)) | |
| { | | { | |
| arma_extra_debug_print("subview_elem1::inplace_op(): aliasing detected"
); | | arma_extra_debug_print("subview_elem1::inplace_op(): aliasing detected"
); | |
| | | | |
| const Mat<eT> tmp(x); | | const Mat<eT> tmp(x); | |
| | | | |
|
| if(is_same_type<op_type, op_subview_elem_equ >::value == | | if(is_same_type<op_type, op_subview_elem_equ >::value == | |
| true) { t.operator= (tmp); } | | true) { s.operator= (tmp); } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == | | else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value == | |
| true) { t.operator+=(tmp); } | | true) { s.operator+=(tmp); } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == | | else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value == | |
| true) { t.operator-=(tmp); } | | true) { s.operator-=(tmp); } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == | | else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value == | |
| true) { t.operator%=(tmp); } | | true) { s.operator%=(tmp); } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == | | else if(is_same_type<op_type, op_subview_elem_inplace_div >::value == | |
| true) { t.operator/=(tmp); } | | true) { s.operator/=(tmp); } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| Mat<eT>& t_m_local = const_cast< Mat<eT>& >(t.m); | | Mat<eT>& s_m_local = const_cast< Mat<eT>& >(s.m); | |
| const Mat<eT>& x_m_local = x.m; | | const Mat<eT>& x_m_local = x.m; | |
| | | | |
|
| const unwrap_check_mixed<T1> t_tmp(t.a.get_ref(), t_m_local); | | const unwrap_check_mixed<T1> s_tmp(s.a.get_ref(), s_m_local); | |
| const unwrap_check_mixed<T2> x_tmp(x.a.get_ref(), t_m_local); | | const unwrap_check_mixed<T2> x_tmp(x.a.get_ref(), s_m_local); | |
| | | | |
|
| const umat& t_aa = t_tmp.M; | | const umat& s_aa = s_tmp.M; | |
| const umat& x_aa = x_tmp.M; | | const umat& x_aa = x_tmp.M; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| ( (t_aa.is_vec() == false) || (x_aa.is_vec() == false) ), | | ( (s_aa.is_vec() == false) || (x_aa.is_vec() == false) ), | |
| "Mat::elem(): given object is not a vector" | | "Mat::elem(): given object is not a vector" | |
| ); | | ); | |
| | | | |
|
| const uword* t_aa_mem = t_aa.memptr(); | | const uword* s_aa_mem = s_aa.memptr(); | |
| const uword* x_aa_mem = x_aa.memptr(); | | const uword* x_aa_mem = x_aa.memptr(); | |
| | | | |
|
| const uword t_aa_n_elem = t_aa.n_elem; | | const uword s_aa_n_elem = s_aa.n_elem; | |
| | | | |
|
| arma_debug_check( (t_aa_n_elem != x_aa.n_elem), "Mat::elem(): size mism
atch" ); | | arma_debug_check( (s_aa_n_elem != x_aa.n_elem), "Mat::elem(): size mism
atch" ); | |
| | | | |
|
| eT* t_m_mem = t_m_local.memptr(); | | eT* s_m_mem = s_m_local.memptr(); | |
| const uword t_m_n_elem = t_m_local.n_elem; | | const uword s_m_n_elem = s_m_local.n_elem; | |
| | | | |
| const eT* x_m_mem = x_m_local.memptr(); | | const eT* x_m_mem = x_m_local.memptr(); | |
| const uword x_m_n_elem = x_m_local.n_elem; | | const uword x_m_n_elem = x_m_local.n_elem; | |
| | | | |
|
| uword i,j; | | uword iq,jq; | |
| for(i=0, j=1; j<t_aa_n_elem; i+=2, j+=2) | | for(iq=0, jq=1; jq < s_aa_n_elem; iq+=2, jq+=2) | |
| { | | { | |
|
| const uword t_ii = t_aa_mem[i]; | | const uword s_ii = s_aa_mem[iq]; | |
| const uword t_jj = t_aa_mem[j]; | | const uword s_jj = s_aa_mem[jq]; | |
| | | | |
|
| const uword x_ii = x_aa_mem[i]; | | const uword x_ii = x_aa_mem[iq]; | |
| const uword x_jj = x_aa_mem[j]; | | const uword x_jj = x_aa_mem[jq]; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| (t_ii >= t_m_n_elem) || (t_jj >= t_m_n_elem) || (x_ii >= x_m_n_elem
) || (x_jj >= x_m_n_elem), | | (s_ii >= s_m_n_elem) || (s_jj >= s_m_n_elem) || (x_ii >= x_m_n_elem
) || (x_jj >= x_m_n_elem), | |
| "Mat::elem(): index out of bounds" | | "Mat::elem(): index out of bounds" | |
| ); | | ); | |
| | | | |
|
| if(is_same_type<op_type, op_subview_elem_equ >::value = | | if(is_same_type<op_type, op_subview_elem_equ >::value = | |
| = true) { t_m_mem[t_ii] = x_m_mem[x_ii]; t_m_mem[t_jj] = x_m_mem[x_jj]; } | | = true) { s_m_mem[s_ii] = x_m_mem[x_ii]; s_m_mem[s_jj] = x_m_mem[x_jj]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | |
| = true) { t_m_mem[t_ii] += x_m_mem[x_ii]; t_m_mem[t_jj] += x_m_mem[x_jj]; } | | = true) { s_m_mem[s_ii] += x_m_mem[x_ii]; s_m_mem[s_jj] += x_m_mem[x_jj]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | |
| = true) { t_m_mem[t_ii] -= x_m_mem[x_ii]; t_m_mem[t_jj] -= x_m_mem[x_jj]; } | | = true) { s_m_mem[s_ii] -= x_m_mem[x_ii]; s_m_mem[s_jj] -= x_m_mem[x_jj]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | |
| = true) { t_m_mem[t_ii] *= x_m_mem[x_ii]; t_m_mem[t_jj] *= x_m_mem[x_jj]; } | | = true) { s_m_mem[s_ii] *= x_m_mem[x_ii]; s_m_mem[s_jj] *= x_m_mem[x_jj]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | |
| = true) { t_m_mem[t_ii] /= x_m_mem[x_ii]; t_m_mem[t_jj] /= x_m_mem[x_jj]; } | | = true) { s_m_mem[s_ii] /= x_m_mem[x_ii]; s_m_mem[s_jj] /= x_m_mem[x_jj]; } | |
| } | | } | |
| | | | |
|
| if(i < t_aa_n_elem) | | if(iq < s_aa_n_elem) | |
| { | | { | |
|
| const uword t_ii = t_aa_mem[i]; | | const uword s_ii = s_aa_mem[iq]; | |
| const uword x_ii = x_aa_mem[i]; | | const uword x_ii = x_aa_mem[iq]; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
|
| ( (t_ii >= t_m_n_elem) || (x_ii >= x_m_n_elem) ), | | ( (s_ii >= s_m_n_elem) || (x_ii >= x_m_n_elem) ), | |
| "Mat::elem(): index out of bounds" | | "Mat::elem(): index out of bounds" | |
| ); | | ); | |
| | | | |
|
| if(is_same_type<op_type, op_subview_elem_equ >::value = | | if(is_same_type<op_type, op_subview_elem_equ >::value = | |
| = true) { t_m_mem[t_ii] = x_m_mem[x_ii]; } | | = true) { s_m_mem[s_ii] = x_m_mem[x_ii]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | |
| = true) { t_m_mem[t_ii] += x_m_mem[x_ii]; } | | = true) { s_m_mem[s_ii] += x_m_mem[x_ii]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | |
| = true) { t_m_mem[t_ii] -= x_m_mem[x_ii]; } | | = true) { s_m_mem[s_ii] -= x_m_mem[x_ii]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | |
| = true) { t_m_mem[t_ii] *= x_m_mem[x_ii]; } | | = true) { s_m_mem[s_ii] *= x_m_mem[x_ii]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | |
| = true) { t_m_mem[t_ii] /= x_m_mem[x_ii]; } | | = true) { s_m_mem[s_ii] /= x_m_mem[x_ii]; } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT, typename T1> | | template<typename eT, typename T1> | |
| template<typename op_type, typename T2> | | template<typename op_type, typename T2> | |
| inline | | inline | |
| void | | void | |
| subview_elem1<eT,T1>::inplace_op(const Base<eT,T2>& x) | | subview_elem1<eT,T1>::inplace_op(const Base<eT,T2>& x) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| Mat<eT>& m_local = const_cast< Mat<eT>& >(m); | | Mat<eT>& m_local = const_cast< Mat<eT>& >(m); | |
| | | | |
| eT* m_mem = m_local.memptr(); | | eT* m_mem = m_local.memptr(); | |
| const uword m_n_elem = m_local.n_elem; | | const uword m_n_elem = m_local.n_elem; | |
| | | | |
|
| const unwrap_check_mixed<T1> tmp(a.get_ref(), m_local); | | const unwrap_check_mixed<T1> aa_tmp(a.get_ref(), m_local); | |
| const umat& aa = tmp.M; | | const umat& aa = aa_tmp.M; | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| ( aa.is_vec() == false ), | | ( aa.is_vec() == false ), | |
| "Mat::elem(): given object is not a vector" | | "Mat::elem(): given object is not a vector" | |
| ); | | ); | |
| | | | |
| const uword* aa_mem = aa.memptr(); | | const uword* aa_mem = aa.memptr(); | |
| const uword aa_n_elem = aa.n_elem; | | const uword aa_n_elem = aa.n_elem; | |
| | | | |
| const Proxy<T2> P(x.get_ref()); | | const Proxy<T2> P(x.get_ref()); | |
| | | | |
| arma_debug_check( (aa_n_elem != P.get_n_elem()), "Mat::elem(): size misma
tch" ); | | arma_debug_check( (aa_n_elem != P.get_n_elem()), "Mat::elem(): size misma
tch" ); | |
| | | | |
|
| if( (P.is_alias(m) == false) && (Proxy<T2>::prefer_at_accessor == false) | | const bool is_alias = P.is_alias(m); | |
| ) | | | |
| | | if( (is_alias == false) && (Proxy<T2>::prefer_at_accessor == false) ) | |
| { | | { | |
| typename Proxy<T2>::ea_type X = P.get_ea(); | | typename Proxy<T2>::ea_type X = P.get_ea(); | |
| | | | |
|
| uword i,j; | | uword iq,jq; | |
| for(i=0, j=1; j<aa_n_elem; i+=2, j+=2) | | for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) | |
| { | | { | |
|
| const uword ii = aa_mem[i]; | | const uword ii = aa_mem[iq]; | |
| const uword jj = aa_mem[j]; | | const uword jj = aa_mem[jq]; | |
| | | | |
| arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::ele
m(): index out of bounds" ); | | arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::ele
m(): index out of bounds" ); | |
| | | | |
|
| if(is_same_type<op_type, op_subview_elem_equ >::value = | | if(is_same_type<op_type, op_subview_elem_equ >::value = | |
| = true) { m_mem[ii] = X[i]; m_mem[jj] = X[j]; } | | = true) { m_mem[ii] = X[iq]; m_mem[jj] = X[jq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | |
| = true) { m_mem[ii] += X[i]; m_mem[jj] += X[j]; } | | = true) { m_mem[ii] += X[iq]; m_mem[jj] += X[jq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | |
| = true) { m_mem[ii] -= X[i]; m_mem[jj] -= X[j]; } | | = true) { m_mem[ii] -= X[iq]; m_mem[jj] -= X[jq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | |
| = true) { m_mem[ii] *= X[i]; m_mem[jj] *= X[j]; } | | = true) { m_mem[ii] *= X[iq]; m_mem[jj] *= X[jq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | |
| = true) { m_mem[ii] /= X[i]; m_mem[jj] /= X[j]; } | | = true) { m_mem[ii] /= X[iq]; m_mem[jj] /= X[jq]; } | |
| } | | } | |
| | | | |
|
| if(i < aa_n_elem) | | if(iq < aa_n_elem) | |
| { | | { | |
|
| const uword ii = aa_mem[i]; | | const uword ii = aa_mem[iq]; | |
| | | | |
| arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bound
s" ); | | arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bound
s" ); | |
| | | | |
|
| if(is_same_type<op_type, op_subview_elem_equ >::value = | | if(is_same_type<op_type, op_subview_elem_equ >::value = | |
| = true) { m_mem[ii] = X[i]; } | | = true) { m_mem[ii] = X[iq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | |
| = true) { m_mem[ii] += X[i]; } | | = true) { m_mem[ii] += X[iq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | |
| = true) { m_mem[ii] -= X[i]; } | | = true) { m_mem[ii] -= X[iq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | |
| = true) { m_mem[ii] *= X[i]; } | | = true) { m_mem[ii] *= X[iq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | |
| = true) { m_mem[ii] /= X[i]; } | | = true) { m_mem[ii] /= X[iq]; } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
| arma_extra_debug_print("subview_elem1::inplace_op(): aliasing or prefer
_at_accessor detected"); | | arma_extra_debug_print("subview_elem1::inplace_op(): aliasing or prefer
_at_accessor detected"); | |
| | | | |
|
| const unwrap_check<typename Proxy<T2>::stored_type> tmp(P.Q, m_local); | | const unwrap_check<typename Proxy<T2>::stored_type> tmp(P.Q, is_alias); | |
| const Mat<eT>& M = tmp.M; | | const Mat<eT>& M = tmp.M; | |
| | | | |
| const eT* X = M.memptr(); | | const eT* X = M.memptr(); | |
| | | | |
|
| uword i,j; | | uword iq,jq; | |
| for(i=0, j=1; j<aa_n_elem; i+=2, j+=2) | | for(iq=0, jq=1; jq < aa_n_elem; iq+=2, jq+=2) | |
| { | | { | |
|
| const uword ii = aa_mem[i]; | | const uword ii = aa_mem[iq]; | |
| const uword jj = aa_mem[j]; | | const uword jj = aa_mem[jq]; | |
| | | | |
| arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::ele
m(): index out of bounds" ); | | arma_debug_check( ( (ii >= m_n_elem) || (jj >= m_n_elem) ), "Mat::ele
m(): index out of bounds" ); | |
| | | | |
|
| if(is_same_type<op_type, op_subview_elem_equ >::value = | | if(is_same_type<op_type, op_subview_elem_equ >::value = | |
| = true) { m_mem[ii] = X[i]; m_mem[jj] = X[j]; } | | = true) { m_mem[ii] = X[iq]; m_mem[jj] = X[jq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | |
| = true) { m_mem[ii] += X[i]; m_mem[jj] += X[j]; } | | = true) { m_mem[ii] += X[iq]; m_mem[jj] += X[jq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | |
| = true) { m_mem[ii] -= X[i]; m_mem[jj] -= X[j]; } | | = true) { m_mem[ii] -= X[iq]; m_mem[jj] -= X[jq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | |
| = true) { m_mem[ii] *= X[i]; m_mem[jj] *= X[j]; } | | = true) { m_mem[ii] *= X[iq]; m_mem[jj] *= X[jq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | |
| = true) { m_mem[ii] /= X[i]; m_mem[jj] /= X[j]; } | | = true) { m_mem[ii] /= X[iq]; m_mem[jj] /= X[jq]; } | |
| } | | } | |
| | | | |
|
| if(i < aa_n_elem) | | if(iq < aa_n_elem) | |
| { | | { | |
|
| const uword ii = aa_mem[i]; | | const uword ii = aa_mem[iq]; | |
| | | | |
| arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bound
s" ); | | arma_debug_check( (ii >= m_n_elem) , "Mat::elem(): index out of bound
s" ); | |
| | | | |
|
| if(is_same_type<op_type, op_subview_elem_equ >::value = | | if(is_same_type<op_type, op_subview_elem_equ >::value = | |
| = true) { m_mem[ii] = X[i]; } | | = true) { m_mem[ii] = X[iq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_plus >::value = | |
| = true) { m_mem[ii] += X[i]; } | | = true) { m_mem[ii] += X[iq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_minus>::value = | |
| = true) { m_mem[ii] -= X[i]; } | | = true) { m_mem[ii] -= X[iq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_schur>::value = | |
| = true) { m_mem[ii] *= X[i]; } | | = true) { m_mem[ii] *= X[iq]; } | |
| else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | | else if(is_same_type<op_type, op_subview_elem_inplace_div >::value = | |
| = true) { m_mem[ii] /= X[i]; } | | = true) { m_mem[ii] /= X[iq]; } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| // | | // | |
| // | | // | |
| | | | |
| template<typename eT, typename T1> | | template<typename eT, typename T1> | |
| arma_inline | | arma_inline | |
| const Op<subview_elem1<eT,T1>,op_htrans> | | const Op<subview_elem1<eT,T1>,op_htrans> | |
| | | | |
End of changes. 39 change blocks. |
| 116 lines changed or deleted | | 117 lines changed or added | |
|
| subview_meat.hpp | | subview_meat.hpp | |
| | | | |
| skipping to change at line 51 | | skipping to change at line 51 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const uword local_n_cols = n_cols; | | const uword local_n_cols = n_cols; | |
| const uword local_n_rows = n_rows; | | const uword local_n_rows = n_rows; | |
| | | | |
| if(local_n_rows == 1) | | if(local_n_rows == 1) | |
| { | | { | |
| Mat<eT>& X = const_cast< Mat<eT>& >(m); | | Mat<eT>& X = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| const uword end_col_plus1 = start_col + local_n_cols; | | const uword end_col_plus1 = start_col + local_n_cols; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=start_col, jj=start_col+1; jj < end_col_plus1; ii+=2, jj+=2) | |
| for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2) | | | |
| { | | { | |
|
| X.at(row, i) += val; | | X.at(urow, ii) += val; | |
| X.at(row, j) += val; | | X.at(urow, jj) += val; | |
| } | | } | |
| | | | |
|
| if(i < end_col_plus1) | | if(ii < end_col_plus1) | |
| { | | { | |
|
| X.at(row, i) += val; | | X.at(urow, ii) += val; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<local_n_cols; ++col) | | for(uword ucol=0; ucol < local_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_plus( colptr(col), val, local_n_rows ); | | arrayops::inplace_plus( colptr(ucol), val, local_n_rows ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator-= (const eT val) | | subview<eT>::operator-= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const uword local_n_cols = n_cols; | | const uword local_n_cols = n_cols; | |
| const uword local_n_rows = n_rows; | | const uword local_n_rows = n_rows; | |
| | | | |
| if(local_n_rows == 1) | | if(local_n_rows == 1) | |
| { | | { | |
| Mat<eT>& X = const_cast< Mat<eT>& >(m); | | Mat<eT>& X = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| const uword end_col_plus1 = start_col + local_n_cols; | | const uword end_col_plus1 = start_col + local_n_cols; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=start_col, jj=start_col+1; jj < end_col_plus1; ii+=2, jj+=2) | |
| for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2) | | | |
| { | | { | |
|
| X.at(row, i) -= val; | | X.at(urow, ii) -= val; | |
| X.at(row, j) -= val; | | X.at(urow, jj) -= val; | |
| } | | } | |
| | | | |
|
| if(i < end_col_plus1) | | if(ii < end_col_plus1) | |
| { | | { | |
|
| X.at(row, i) -= val; | | X.at(urow, ii) -= val; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<local_n_cols; ++col) | | for(uword ucol=0; ucol < local_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_minus( colptr(col), val, local_n_rows ); | | arrayops::inplace_minus( colptr(ucol), val, local_n_rows ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator*= (const eT val) | | subview<eT>::operator*= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const uword local_n_cols = n_cols; | | const uword local_n_cols = n_cols; | |
| const uword local_n_rows = n_rows; | | const uword local_n_rows = n_rows; | |
| | | | |
| if(local_n_rows == 1) | | if(local_n_rows == 1) | |
| { | | { | |
| Mat<eT>& X = const_cast< Mat<eT>& >(m); | | Mat<eT>& X = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| const uword end_col_plus1 = start_col + local_n_cols; | | const uword end_col_plus1 = start_col + local_n_cols; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=start_col, jj=start_col+1; jj < end_col_plus1; ii+=2, jj+=2) | |
| for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2) | | | |
| { | | { | |
|
| X.at(row, i) *= val; | | X.at(urow, ii) *= val; | |
| X.at(row, j) *= val; | | X.at(urow, jj) *= val; | |
| } | | } | |
| | | | |
|
| if(i < end_col_plus1) | | if(ii < end_col_plus1) | |
| { | | { | |
|
| X.at(row, i) *= val; | | X.at(urow, ii) *= val; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<local_n_cols; ++col) | | for(uword ucol=0; ucol < local_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_mul( colptr(col), val, local_n_rows ); | | arrayops::inplace_mul( colptr(ucol), val, local_n_rows ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator/= (const eT val) | | subview<eT>::operator/= (const eT val) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const uword local_n_cols = n_cols; | | const uword local_n_cols = n_cols; | |
| const uword local_n_rows = n_rows; | | const uword local_n_rows = n_rows; | |
| | | | |
| if(local_n_rows == 1) | | if(local_n_rows == 1) | |
| { | | { | |
| Mat<eT>& X = const_cast< Mat<eT>& >(m); | | Mat<eT>& X = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| const uword end_col_plus1 = start_col + local_n_cols; | | const uword end_col_plus1 = start_col + local_n_cols; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=start_col, jj=start_col+1; jj < end_col_plus1; ii+=2, jj+=2) | |
| for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2) | | | |
| { | | { | |
|
| X.at(row, i) /= val; | | X.at(urow, ii) /= val; | |
| X.at(row, j) /= val; | | X.at(urow, jj) /= val; | |
| } | | } | |
| | | | |
|
| if(i < end_col_plus1) | | if(ii < end_col_plus1) | |
| { | | { | |
|
| X.at(row, i) /= val; | | X.at(urow, ii) /= val; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<local_n_cols; ++col) | | for(uword ucol=0; ucol < local_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_div( colptr(col), val, local_n_rows ); | | arrayops::inplace_div( colptr(ucol), val, local_n_rows ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator= (const Base<eT,T1>& in) | | subview<eT>::operator= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const Proxy<T1> P(in.get_ref()); | | const Proxy<T1> P(in.get_ref()); | |
| | | | |
|
| subview<eT>& t = *this; | | subview<eT>& s = *this; | |
| | | | |
|
| const uword t_n_rows = t.n_rows; | | const uword s_n_rows = s.n_rows; | |
| const uword t_n_cols = t.n_cols; | | const uword s_n_cols = s.n_cols; | |
| | | | |
|
| arma_debug_assert_same_size(t, P, "copy into submatrix"); | | arma_debug_assert_same_size(s, P, "copy into submatrix"); | |
| | | | |
|
| const bool alias = P.is_alias(t.m); | | const bool is_alias = P.is_alias(s.m); | |
| | | | |
|
| arma_extra_debug_warn(alias, "aliasing detected"); | | arma_extra_debug_warn(is_alias, "aliasing detected"); | |
| | | | |
|
| if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value ==
true) ) | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) || (is_alias
== true) ) | |
| { | | { | |
|
| const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m); | | const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); | |
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| | | | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
| const eT* x_mem = x.memptr(); | | const eT* x_mem = x.memptr(); | |
| | | | |
| Mat<eT>& A = const_cast< Mat<eT>& >(m); | | Mat<eT>& A = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| A.at(row, start_col+i) = x_mem[i]; | | A.at(urow, start_col+ii) = x_mem[ii]; | |
| A.at(row, start_col+j) = x_mem[j]; | | A.at(urow, start_col+jj) = x_mem[jj]; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row, start_col+i) = x_mem[i]; | | A.at(urow, start_col+ii) = x_mem[ii]; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col < t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::copy( t.colptr(col), x.colptr(col), t_n_rows ); | | arrayops::copy( s.colptr(ucol), x.colptr(ucol), s_n_rows ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
| Mat<eT>& A = const_cast< Mat<eT>& >(m); | | Mat<eT>& A = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i]; | | const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,ii) : P[ii | |
| const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j]; | | ]; | |
| | | const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,jj) : P[jj | |
| | | ]; | |
| | | | |
|
| A.at(row, start_col+i) = tmp1; | | A.at(urow, start_col+ii) = tmp1; | |
| A.at(row, start_col+j) = tmp2; | | A.at(urow, start_col+jj) = tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row, start_col+i) = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i
) : P[i]; | | A.at(urow, start_col+ii) = (Proxy<T1>::prefer_at_accessor) ? P.at(0
,ii) : P[ii]; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| eT* t_col_data = t.colptr(col); | | eT* s_col_data = s.colptr(ucol); | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| for(i=0, j=1; j<t_n_rows; i+=2, j+=2) | | for(ii=0, jj=1; jj < s_n_rows; ii+=2, jj+=2) | |
| { | | { | |
|
| const eT tmp1 = P.at(i,col); | | const eT tmp1 = P.at(ii,ucol); | |
| const eT tmp2 = P.at(j,col); | | const eT tmp2 = P.at(jj,ucol); | |
| | | | |
|
| t_col_data[i] = tmp1; | | s_col_data[ii] = tmp1; | |
| t_col_data[j] = tmp2; | | s_col_data[jj] = tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_rows) | | if(ii < s_n_rows) | |
| { | | { | |
|
| t_col_data[i] = P.at(i,col); | | s_col_data[ii] = P.at(ii,ucol); | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator+= (const Base<eT,T1>& in) | | subview<eT>::operator+= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const Proxy<T1> P(in.get_ref()); | | const Proxy<T1> P(in.get_ref()); | |
| | | | |
|
| subview<eT>& t = *this; | | subview<eT>& s = *this; | |
| | | | |
|
| const uword t_n_rows = t.n_rows; | | const uword s_n_rows = s.n_rows; | |
| const uword t_n_cols = t.n_cols; | | const uword s_n_cols = s.n_cols; | |
| | | | |
|
| arma_debug_assert_same_size(t, P, "addition"); | | arma_debug_assert_same_size(s, P, "addition"); | |
| | | | |
|
| const bool alias = P.is_alias(t.m); | | const bool is_alias = P.is_alias(s.m); | |
| | | | |
|
| arma_extra_debug_warn(alias, "aliasing detected"); | | arma_extra_debug_warn(is_alias, "aliasing detected"); | |
| | | | |
|
| if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value ==
true) ) | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) || (is_alias
== true) ) | |
| { | | { | |
|
| const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m); | | const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); | |
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| | | | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
| const eT* x_mem = x.memptr(); | | const eT* x_mem = x.memptr(); | |
| | | | |
| Mat<eT>& A = const_cast< Mat<eT>& >(m); | | Mat<eT>& A = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| A.at(row, start_col+i) += x_mem[i]; | | A.at(urow, start_col+ii) += x_mem[ii]; | |
| A.at(row, start_col+j) += x_mem[j]; | | A.at(urow, start_col+jj) += x_mem[jj]; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row, start_col+i) += x_mem[i]; | | A.at(urow, start_col+ii) += x_mem[ii]; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col < t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_plus( t.colptr(col), x.colptr(col), t_n_rows ); | | arrayops::inplace_plus( s.colptr(ucol), x.colptr(ucol), s_n_rows ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
| Mat<eT>& A = const_cast< Mat<eT>& >(m); | | Mat<eT>& A = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i]; | | const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,ii) : P[ii | |
| const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j]; | | ]; | |
| | | const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,jj) : P[jj | |
| | | ]; | |
| | | | |
|
| A.at(row, start_col+i) += tmp1; | | A.at(urow, start_col+ii) += tmp1; | |
| A.at(row, start_col+j) += tmp2; | | A.at(urow, start_col+jj) += tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row, start_col+i) += (Proxy<T1>::prefer_at_accessor) ? P.at(0,
i) : P[i]; | | A.at(urow, start_col+ii) += (Proxy<T1>::prefer_at_accessor) ? P.at(
0,ii) : P[ii]; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| eT* t_col_data = t.colptr(col); | | eT* s_col_data = s.colptr(ucol); | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| for(i=0, j=1; j<t_n_rows; i+=2, j+=2) | | for(ii=0, jj=1; jj < s_n_rows; ii+=2, jj+=2) | |
| { | | { | |
|
| const eT val1 = P.at(i,col); | | const eT val1 = P.at(ii,ucol); | |
| const eT val2 = P.at(j,col); | | const eT val2 = P.at(jj,ucol); | |
| | | | |
|
| t_col_data[i] += val1; | | s_col_data[ii] += val1; | |
| t_col_data[j] += val2; | | s_col_data[jj] += val2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_rows) | | if(ii < s_n_rows) | |
| { | | { | |
|
| t_col_data[i] += P.at(i,col); | | s_col_data[ii] += P.at(ii,ucol); | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator-= (const Base<eT,T1>& in) | | subview<eT>::operator-= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const Proxy<T1> P(in.get_ref()); | | const Proxy<T1> P(in.get_ref()); | |
| | | | |
|
| subview<eT>& t = *this; | | subview<eT>& s = *this; | |
| | | | |
| | | const uword s_n_rows = s.n_rows; | |
| | | const uword s_n_cols = s.n_cols; | |
| | | | |
|
| const uword t_n_rows = t.n_rows; | | arma_debug_assert_same_size(s, P, "subtraction"); | |
| const uword t_n_cols = t.n_cols; | | | |
| | | | |
|
| arma_debug_assert_same_size(t, P, "subtraction"); | | const bool is_alias = P.is_alias(s.m); | |
| | | | |
|
| const bool alias = P.is_alias(t.m); | | arma_extra_debug_warn(is_alias, "aliasing detected"); | |
| | | | |
|
| if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value ==
true) ) | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) || (is_alias
== true) ) | |
| { | | { | |
|
| const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m); | | const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); | |
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| | | | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
| const eT* x_mem = x.memptr(); | | const eT* x_mem = x.memptr(); | |
| | | | |
| Mat<eT>& A = const_cast< Mat<eT>& >(m); | | Mat<eT>& A = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| A.at(row, start_col+i) -= x_mem[i]; | | A.at(urow, start_col+ii) -= x_mem[ii]; | |
| A.at(row, start_col+j) -= x_mem[j]; | | A.at(urow, start_col+jj) -= x_mem[jj]; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row, start_col+i) -= x_mem[i]; | | A.at(urow, start_col+ii) -= x_mem[ii]; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col < t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_minus( t.colptr(col), x.colptr(col), t_n_rows ); | | arrayops::inplace_minus( s.colptr(ucol), x.colptr(ucol), s_n_rows )
; | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
| Mat<eT>& A = const_cast< Mat<eT>& >(m); | | Mat<eT>& A = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i]; | | const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,ii) : P[ii | |
| const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j]; | | ]; | |
| | | const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,jj) : P[jj | |
| | | ]; | |
| | | | |
|
| A.at(row, start_col+i) -= tmp1; | | A.at(urow, start_col+ii) -= tmp1; | |
| A.at(row, start_col+j) -= tmp2; | | A.at(urow, start_col+jj) -= tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row, start_col+i) -= (Proxy<T1>::prefer_at_accessor) ? P.at(0,
i) : P[i]; | | A.at(urow, start_col+ii) -= (Proxy<T1>::prefer_at_accessor) ? P.at(
0,ii) : P[ii]; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| eT* t_col_data = t.colptr(col); | | eT* s_col_data = s.colptr(ucol); | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| for(i=0, j=1; j<t_n_rows; i+=2, j+=2) | | for(ii=0, jj=1; jj < s_n_rows; ii+=2, jj+=2) | |
| { | | { | |
|
| const eT val1 = P.at(i,col); | | const eT val1 = P.at(ii,ucol); | |
| const eT val2 = P.at(j,col); | | const eT val2 = P.at(jj,ucol); | |
| | | | |
|
| t_col_data[i] -= val1; | | s_col_data[ii] -= val1; | |
| t_col_data[j] -= val2; | | s_col_data[jj] -= val2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_rows) | | if(ii < s_n_rows) | |
| { | | { | |
|
| t_col_data[i] -= P.at(i,col); | | s_col_data[ii] -= P.at(ii,ucol); | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator%= (const Base<eT,T1>& in) | | subview<eT>::operator%= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const Proxy<T1> P(in.get_ref()); | | const Proxy<T1> P(in.get_ref()); | |
| | | | |
|
| subview<eT>& t = *this; | | subview<eT>& s = *this; | |
| | | | |
|
| const uword t_n_rows = t.n_rows; | | const uword s_n_rows = s.n_rows; | |
| const uword t_n_cols = t.n_cols; | | const uword s_n_cols = s.n_cols; | |
| | | | |
|
| arma_debug_assert_same_size(t, P, "element-wise multiplication"); | | arma_debug_assert_same_size(s, P, "element-wise multiplication"); | |
| | | | |
|
| const bool alias = P.is_alias(t.m); | | const bool is_alias = P.is_alias(s.m); | |
| | | | |
|
| arma_extra_debug_warn(alias, "aliasing detected"); | | arma_extra_debug_warn(is_alias, "aliasing detected"); | |
| | | | |
|
| if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value ==
true) ) | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) || (is_alias
== true) ) | |
| { | | { | |
|
| const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m); | | const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); | |
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| | | | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
| const eT* x_mem = x.memptr(); | | const eT* x_mem = x.memptr(); | |
| | | | |
| Mat<eT>& A = const_cast< Mat<eT>& >(m); | | Mat<eT>& A = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| A.at(row, start_col+i) *= x_mem[i]; | | A.at(urow, start_col+ii) *= x_mem[ii]; | |
| A.at(row, start_col+j) *= x_mem[j]; | | A.at(urow, start_col+jj) *= x_mem[jj]; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row, start_col+i) *= x_mem[i]; | | A.at(urow, start_col+ii) *= x_mem[ii]; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col < t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_mul( t.colptr(col), x.colptr(col), t_n_rows ); | | arrayops::inplace_mul( s.colptr(ucol), x.colptr(ucol), s_n_rows ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
| Mat<eT>& A = const_cast< Mat<eT>& >(m); | | Mat<eT>& A = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i]; | | const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,ii) : P[ii | |
| const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j]; | | ]; | |
| | | const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,jj) : P[jj | |
| | | ]; | |
| | | | |
|
| A.at(row, start_col+i) *= tmp1; | | A.at(urow, start_col+ii) *= tmp1; | |
| A.at(row, start_col+j) *= tmp2; | | A.at(urow, start_col+jj) *= tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row, start_col+i) *= (Proxy<T1>::prefer_at_accessor) ? P.at(0,
i) : P[i]; | | A.at(urow, start_col+ii) *= (Proxy<T1>::prefer_at_accessor) ? P.at(
0,ii) : P[ii]; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| eT* t_col_data = t.colptr(col); | | eT* s_col_data = s.colptr(ucol); | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| for(i=0, j=1; j<t_n_rows; i+=2, j+=2) | | for(ii=0, jj=1; jj < s_n_rows; ii+=2, jj+=2) | |
| { | | { | |
|
| const eT val1 = P.at(i,col); | | const eT val1 = P.at(ii,ucol); | |
| const eT val2 = P.at(j,col); | | const eT val2 = P.at(jj,ucol); | |
| | | | |
|
| t_col_data[i] *= val1; | | s_col_data[ii] *= val1; | |
| t_col_data[j] *= val2; | | s_col_data[jj] *= val2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_rows) | | if(ii < s_n_rows) | |
| { | | { | |
|
| t_col_data[i] *= P.at(i,col); | | s_col_data[ii] *= P.at(ii,ucol); | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| template<typename T1> | | template<typename T1> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator/= (const Base<eT,T1>& in) | | subview<eT>::operator/= (const Base<eT,T1>& in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const Proxy<T1> P(in.get_ref()); | | const Proxy<T1> P(in.get_ref()); | |
| | | | |
|
| subview<eT>& t = *this; | | subview<eT>& s = *this; | |
| | | | |
|
| const uword t_n_rows = t.n_rows; | | const uword s_n_rows = s.n_rows; | |
| const uword t_n_cols = t.n_cols; | | const uword s_n_cols = s.n_cols; | |
| | | | |
|
| arma_debug_assert_same_size(t, P, "element-wise division"); | | arma_debug_assert_same_size(s, P, "element-wise division"); | |
| | | | |
|
| const bool alias = P.is_alias(t.m); | | const bool is_alias = P.is_alias(s.m); | |
| | | | |
|
| arma_extra_debug_warn(alias, "aliasing detected"); | | arma_extra_debug_warn(is_alias, "aliasing detected"); | |
| | | | |
|
| if( (alias == true) || (is_Mat<typename Proxy<T1>::stored_type>::value ==
true) ) | | if( (is_Mat<typename Proxy<T1>::stored_type>::value == true) || (is_alias
== true) ) | |
| { | | { | |
|
| const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, t.m); | | const unwrap_check<typename Proxy<T1>::stored_type> tmp(P.Q, is_alias); | |
| const Mat<eT>& x = tmp.M; | | const Mat<eT>& x = tmp.M; | |
| | | | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
| const eT* x_mem = x.memptr(); | | const eT* x_mem = x.memptr(); | |
| | | | |
| Mat<eT>& A = const_cast< Mat<eT>& >(m); | | Mat<eT>& A = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| A.at(row, start_col+i) /= x_mem[i]; | | A.at(urow, start_col+ii) /= x_mem[ii]; | |
| A.at(row, start_col+j) /= x_mem[j]; | | A.at(urow, start_col+jj) /= x_mem[jj]; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row, start_col+i) /= x_mem[i]; | | A.at(urow, start_col+ii) /= x_mem[ii]; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col < t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_div( t.colptr(col), x.colptr(col), t_n_rows ); | | arrayops::inplace_div( s.colptr(ucol), x.colptr(ucol), s_n_rows ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
| Mat<eT>& A = const_cast< Mat<eT>& >(m); | | Mat<eT>& A = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,i) : P[i]; | | const eT tmp1 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,ii) : P[ii | |
| const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,j) : P[j]; | | ]; | |
| | | const eT tmp2 = (Proxy<T1>::prefer_at_accessor) ? P.at(0,jj) : P[jj | |
| | | ]; | |
| | | | |
|
| A.at(row, start_col+i) /= tmp1; | | A.at(urow, start_col+ii) /= tmp1; | |
| A.at(row, start_col+j) /= tmp2; | | A.at(urow, start_col+jj) /= tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row, start_col+i) /= (Proxy<T1>::prefer_at_accessor) ? P.at(0,
i) : P[i]; | | A.at(urow, start_col+ii) /= (Proxy<T1>::prefer_at_accessor) ? P.at(
0,ii) : P[ii]; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| eT* t_col_data = t.colptr(col); | | eT* s_col_data = s.colptr(ucol); | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| for(i=0, j=1; j<t_n_rows; i+=2, j+=2) | | for(ii=0, jj=1; jj < s_n_rows; ii+=2, jj+=2) | |
| { | | { | |
|
| const eT val1 = P.at(i,col); | | const eT val1 = P.at(ii,ucol); | |
| const eT val2 = P.at(j,col); | | const eT val2 = P.at(jj,ucol); | |
| | | | |
|
| t_col_data[i] /= val1; | | s_col_data[ii] /= val1; | |
| t_col_data[j] /= val2; | | s_col_data[jj] /= val2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_rows) | | if(ii < s_n_rows) | |
| { | | { | |
|
| t_col_data[i] /= P.at(i,col); | | s_col_data[ii] /= P.at(ii,ucol); | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| //! x.submat(...) = y.submat(...) | | //! x.submat(...) = y.submat(...) | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::operator= (const subview<eT>& x_in) | | subview<eT>::operator= (const subview<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
| const subview<eT>* tmp_subview = overlap ? new subview<eT>(*tmp_mat, x_in
.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview<eT>(*tmp_mat, x_in
.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
|
| subview<eT>& t = *this; | | subview<eT>& s = *this; | |
| | | | |
|
| arma_debug_assert_same_size(t, x, "copy into submatrix"); | | arma_debug_assert_same_size(s, x, "copy into submatrix"); | |
| | | | |
|
| const uword t_n_cols = t.n_cols; | | const uword s_n_cols = s.n_cols; | |
| const uword t_n_rows = t.n_rows; | | const uword s_n_rows = s.n_rows; | |
| | | | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
|
| Mat<eT>& A = const_cast< Mat<eT>& >(t.m); | | Mat<eT>& A = const_cast< Mat<eT>& >(s.m); | |
| const Mat<eT>& B = x.m; | | const Mat<eT>& B = x.m; | |
| | | | |
|
| const uword row_A = t.aux_row1; | | const uword row_A = s.aux_row1; | |
| const uword row_B = x.aux_row1; | | const uword row_B = x.aux_row1; | |
| | | | |
|
| const uword start_col_A = t.aux_col1; | | const uword start_col_A = s.aux_col1; | |
| const uword start_col_B = x.aux_col1; | | const uword start_col_B = x.aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp1 = B.at(row_B, start_col_B + i); | | const eT tmp1 = B.at(row_B, start_col_B + ii); | |
| const eT tmp2 = B.at(row_B, start_col_B + j); | | const eT tmp2 = B.at(row_B, start_col_B + jj); | |
| | | | |
|
| A.at(row_A, start_col_A + i) = tmp1; | | A.at(row_A, start_col_A + ii) = tmp1; | |
| A.at(row_A, start_col_A + j) = tmp2; | | A.at(row_A, start_col_A + jj) = tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row_A, start_col_A + i) = B.at(row_B, start_col_B + i); | | A.at(row_A, start_col_A + ii) = B.at(row_B, start_col_B + ii); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::copy( t.colptr(col), x.colptr(col), t_n_rows ); | | arrayops::copy( s.colptr(ucol), x.colptr(ucol), s_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview; | | delete tmp_subview; | |
| delete tmp_mat; | | delete tmp_mat; | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 801 | | skipping to change at line 788 | |
| subview<eT>::operator+= (const subview<eT>& x_in) | | subview<eT>::operator+= (const subview<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
| const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
|
| subview<eT>& t = *this; | | subview<eT>& s = *this; | |
| | | | |
|
| arma_debug_assert_same_size(t, x, "addition"); | | arma_debug_assert_same_size(s, x, "addition"); | |
| | | | |
|
| const uword t_n_rows = t.n_rows; | | const uword s_n_rows = s.n_rows; | |
| const uword t_n_cols = t.n_cols; | | const uword s_n_cols = s.n_cols; | |
| | | | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
|
| Mat<eT>& A = const_cast< Mat<eT>& >(t.m); | | Mat<eT>& A = const_cast< Mat<eT>& >(s.m); | |
| const Mat<eT>& B = x.m; | | const Mat<eT>& B = x.m; | |
| | | | |
|
| const uword row_A = t.aux_row1; | | const uword row_A = s.aux_row1; | |
| const uword row_B = x.aux_row1; | | const uword row_B = x.aux_row1; | |
| | | | |
|
| const uword start_col_A = t.aux_col1; | | const uword start_col_A = s.aux_col1; | |
| const uword start_col_B = x.aux_col1; | | const uword start_col_B = x.aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | | |
|
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| { | | { | |
|
| const eT tmp1 = B.at(row_B, start_col_B + i); | | const eT tmp1 = B.at(row_B, start_col_B + ii); | |
| const eT tmp2 = B.at(row_B, start_col_B + j); | | const eT tmp2 = B.at(row_B, start_col_B + jj); | |
| | | | |
|
| A.at(row_A, start_col_A + i) += tmp1; | | A.at(row_A, start_col_A + ii) += tmp1; | |
| A.at(row_A, start_col_A + j) += tmp2; | | A.at(row_A, start_col_A + jj) += tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row_A, start_col_A + i) += B.at(row_B, start_col_B + i); | | A.at(row_A, start_col_A + ii) += B.at(row_B, start_col_B + ii); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_plus( t.colptr(col), x.colptr(col), t_n_rows ); | | arrayops::inplace_plus( s.colptr(ucol), x.colptr(ucol), s_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview; | | delete tmp_subview; | |
| delete tmp_mat; | | delete tmp_mat; | |
| } | | } | |
| } | | } | |
| | | | |
| | | | |
| skipping to change at line 863 | | skipping to change at line 850 | |
| subview<eT>::operator-= (const subview<eT>& x_in) | | subview<eT>::operator-= (const subview<eT>& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
| const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
|
| subview<eT>& t = *this; | | subview<eT>& s = *this; | |
| | | | |
|
| arma_debug_assert_same_size(t, x, "subtraction"); | | arma_debug_assert_same_size(s, x, "subtraction"); | |
| | | | |
|
| const uword t_n_rows = t.n_rows; | | const uword s_n_rows = s.n_rows; | |
| const uword t_n_cols = t.n_cols; | | const uword s_n_cols = s.n_cols; | |
| | | | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
|
| Mat<eT>& A = const_cast< Mat<eT>& >(t.m); | | Mat<eT>& A = const_cast< Mat<eT>& >(s.m); | |
| const Mat<eT>& B = x.m; | | const Mat<eT>& B = x.m; | |
| | | | |
|
| const uword row_A = t.aux_row1; | | const uword row_A = s.aux_row1; | |
| const uword row_B = x.aux_row1; | | const uword row_B = x.aux_row1; | |
| | | | |
|
| const uword start_col_A = t.aux_col1; | | const uword start_col_A = s.aux_col1; | |
| const uword start_col_B = x.aux_col1; | | const uword start_col_B = x.aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp1 = B.at(row_B, start_col_B + i); | | const eT tmp1 = B.at(row_B, start_col_B + ii); | |
| const eT tmp2 = B.at(row_B, start_col_B + j); | | const eT tmp2 = B.at(row_B, start_col_B + jj); | |
| | | | |
|
| A.at(row_A, start_col_A + i) -= tmp1; | | A.at(row_A, start_col_A + ii) -= tmp1; | |
| A.at(row_A, start_col_A + j) -= tmp2; | | A.at(row_A, start_col_A + jj) -= tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row_A, start_col_A + i) -= B.at(row_B, start_col_B + i); | | A.at(row_A, start_col_A + ii) -= B.at(row_B, start_col_B + ii); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_minus( t.colptr(col), x.colptr(col), t_n_rows ); | | arrayops::inplace_minus( s.colptr(ucol), x.colptr(ucol), s_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview; | | delete tmp_subview; | |
| delete tmp_mat; | | delete tmp_mat; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 926 | | skipping to change at line 912 | |
| subview<eT>::operator%= (const subview& x_in) | | subview<eT>::operator%= (const subview& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
| const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
|
| subview<eT>& t = *this; | | subview<eT>& s = *this; | |
| | | | |
|
| arma_debug_assert_same_size(t, x, "element-wise multiplication"); | | arma_debug_assert_same_size(s, x, "element-wise multiplication"); | |
| | | | |
|
| const uword t_n_rows = t.n_rows; | | const uword s_n_rows = s.n_rows; | |
| const uword t_n_cols = t.n_cols; | | const uword s_n_cols = s.n_cols; | |
| | | | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
|
| Mat<eT>& A = const_cast< Mat<eT>& >(t.m); | | Mat<eT>& A = const_cast< Mat<eT>& >(s.m); | |
| const Mat<eT>& B = x.m; | | const Mat<eT>& B = x.m; | |
| | | | |
|
| const uword row_A = t.aux_row1; | | const uword row_A = s.aux_row1; | |
| const uword row_B = x.aux_row1; | | const uword row_B = x.aux_row1; | |
| | | | |
|
| const uword start_col_A = t.aux_col1; | | const uword start_col_A = s.aux_col1; | |
| const uword start_col_B = x.aux_col1; | | const uword start_col_B = x.aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp1 = B.at(row_B, start_col_B + i); | | const eT tmp1 = B.at(row_B, start_col_B + ii); | |
| const eT tmp2 = B.at(row_B, start_col_B + j); | | const eT tmp2 = B.at(row_B, start_col_B + jj); | |
| | | | |
|
| A.at(row_A, start_col_A + i) *= tmp1; | | A.at(row_A, start_col_A + ii) *= tmp1; | |
| A.at(row_A, start_col_A + j) *= tmp2; | | A.at(row_A, start_col_A + jj) *= tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row_A, start_col_A + i) *= B.at(row_B, start_col_B + i); | | A.at(row_A, start_col_A + ii) *= B.at(row_B, start_col_B + ii); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_mul( t.colptr(col), x.colptr(col), t_n_rows ); | | arrayops::inplace_mul( s.colptr(ucol), x.colptr(ucol), s_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview; | | delete tmp_subview; | |
| delete tmp_mat; | | delete tmp_mat; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 989 | | skipping to change at line 974 | |
| subview<eT>::operator/= (const subview& x_in) | | subview<eT>::operator/= (const subview& x_in) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const bool overlap = check_overlap(x_in); | | const bool overlap = check_overlap(x_in); | |
| | | | |
| Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | | Mat<eT>* tmp_mat = overlap ? new Mat<eT>(x_in.m) : 0; | |
| const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | | const subview<eT>* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux
_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; | |
| const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | | const subview<eT>& x = overlap ? (*tmp_subview) : x_in; | |
| | | | |
|
| subview<eT>& t = *this; | | subview<eT>& s = *this; | |
| | | | |
|
| arma_debug_assert_same_size(t, x, "element-wise division"); | | arma_debug_assert_same_size(s, x, "element-wise division"); | |
| | | | |
|
| const uword t_n_rows = t.n_rows; | | const uword s_n_rows = s.n_rows; | |
| const uword t_n_cols = t.n_cols; | | const uword s_n_cols = s.n_cols; | |
| | | | |
|
| if(t_n_rows == 1) | | if(s_n_rows == 1) | |
| { | | { | |
|
| Mat<eT>& A = const_cast< Mat<eT>& >(t.m); | | Mat<eT>& A = const_cast< Mat<eT>& >(s.m); | |
| const Mat<eT>& B = x.m; | | const Mat<eT>& B = x.m; | |
| | | | |
|
| const uword row_A = t.aux_row1; | | const uword row_A = s.aux_row1; | |
| const uword row_B = x.aux_row1; | | const uword row_B = x.aux_row1; | |
| | | | |
|
| const uword start_col_A = t.aux_col1; | | const uword start_col_A = s.aux_col1; | |
| const uword start_col_B = x.aux_col1; | | const uword start_col_B = x.aux_col1; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=0, jj=1; jj < s_n_cols; ii+=2, jj+=2) | |
| for(i=0, j=1; j < t_n_cols; i+=2, j+=2) | | | |
| { | | { | |
|
| const eT tmp1 = B.at(row_B, start_col_B + i); | | const eT tmp1 = B.at(row_B, start_col_B + ii); | |
| const eT tmp2 = B.at(row_B, start_col_B + j); | | const eT tmp2 = B.at(row_B, start_col_B + jj); | |
| | | | |
|
| A.at(row_A, start_col_A + i) /= tmp1; | | A.at(row_A, start_col_A + ii) /= tmp1; | |
| A.at(row_A, start_col_A + j) /= tmp2; | | A.at(row_A, start_col_A + jj) /= tmp2; | |
| } | | } | |
| | | | |
|
| if(i < t_n_cols) | | if(ii < s_n_cols) | |
| { | | { | |
|
| A.at(row_A, start_col_A + i) /= B.at(row_B, start_col_B + i); | | A.at(row_A, start_col_A + ii) /= B.at(row_B, start_col_B + ii); | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col<t_n_cols; ++col) | | for(uword ucol=0; ucol < s_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_div( t.colptr(col), x.colptr(col), t_n_rows ); | | arrayops::inplace_div( s.colptr(ucol), x.colptr(ucol), s_n_rows ); | |
| } | | } | |
| } | | } | |
| | | | |
| if(overlap) | | if(overlap) | |
| { | | { | |
| delete tmp_subview; | | delete tmp_subview; | |
| delete tmp_mat; | | delete tmp_mat; | |
| } | | } | |
| | | | |
| } | | } | |
| | | | |
| skipping to change at line 1053 | | skipping to change at line 1037 | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| const uword local_n_cols = n_cols; | | const uword local_n_cols = n_cols; | |
| const uword local_n_rows = n_rows; | | const uword local_n_rows = n_rows; | |
| | | | |
| if(local_n_rows == 1) | | if(local_n_rows == 1) | |
| { | | { | |
| Mat<eT>& X = const_cast< Mat<eT>& >(m); | | Mat<eT>& X = const_cast< Mat<eT>& >(m); | |
| | | | |
|
| const uword row = aux_row1; | | const uword urow = aux_row1; | |
| const uword start_col = aux_col1; | | const uword start_col = aux_col1; | |
| const uword end_col_plus1 = start_col + local_n_cols; | | const uword end_col_plus1 = start_col + local_n_cols; | |
| | | | |
|
| uword i,j; | | uword ii,jj; | |
| | | for(ii=start_col, jj=start_col+1; jj < end_col_plus1; ii+=2, jj+=2) | |
| for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2) | | | |
| { | | { | |
|
| X.at(row, i) = val; | | X.at(urow, ii) = val; | |
| X.at(row, j) = val; | | X.at(urow, jj) = val; | |
| } | | } | |
| | | | |
|
| if(i < end_col_plus1) | | if(ii < end_col_plus1) | |
| { | | { | |
|
| X.at(row, i) = val; | | X.at(urow, ii) = val; | |
| } | | } | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| for(uword col=0; col < local_n_cols; ++col) | | for(uword ucol=0; ucol < local_n_cols; ++ucol) | |
| { | | { | |
|
| arrayops::inplace_set( colptr(col), val, local_n_rows ); | | arrayops::inplace_set( colptr(ucol), val, local_n_rows ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::zeros() | | subview<eT>::zeros() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| skipping to change at line 1110 | | skipping to change at line 1093 | |
| inline | | inline | |
| void | | void | |
| subview<eT>::eye() | | subview<eT>::eye() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| fill(eT(0)); | | fill(eT(0)); | |
| | | | |
| const uword N = (std::min)(n_rows, n_cols); | | const uword N = (std::min)(n_rows, n_cols); | |
| | | | |
|
| for(uword i=0; i<N; ++i) | | for(uword ii=0; ii < N; ++ii) | |
| { | | { | |
|
| at(i,i) = eT(1); | | at(ii,ii) = eT(1); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT& | | eT& | |
|
| subview<eT>::operator[](const uword i) | | subview<eT>::operator[](const uword ii) | |
| { | | { | |
|
| const uword in_col = i / n_rows; | | const uword in_col = ii / n_rows; | |
| const uword in_row = i % n_rows; | | const uword in_row = ii % n_rows; | |
| | | | |
| const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| | | | |
| return access::rw( (const_cast< Mat<eT>& >(m)).mem[index] ); | | return access::rw( (const_cast< Mat<eT>& >(m)).mem[index] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| subview<eT>::operator[](const uword i) const | | subview<eT>::operator[](const uword ii) const | |
| { | | { | |
|
| const uword in_col = i / n_rows; | | const uword in_col = ii / n_rows; | |
| const uword in_row = i % n_rows; | | const uword in_row = ii % n_rows; | |
| | | | |
| const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| | | | |
| return m.mem[index]; | | return m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT& | | eT& | |
|
| subview<eT>::operator()(const uword i) | | subview<eT>::operator()(const uword ii) | |
| { | | { | |
|
| arma_debug_check( (i >= n_elem), "subview::operator(): index out of bound
s"); | | arma_debug_check( (ii >= n_elem), "subview::operator(): index out of boun
ds"); | |
| | | | |
|
| const uword in_col = i / n_rows; | | const uword in_col = ii / n_rows; | |
| const uword in_row = i % n_rows; | | const uword in_row = ii % n_rows; | |
| | | | |
| const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| | | | |
| return access::rw( (const_cast< Mat<eT>& >(m)).mem[index] ); | | return access::rw( (const_cast< Mat<eT>& >(m)).mem[index] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| subview<eT>::operator()(const uword i) const | | subview<eT>::operator()(const uword ii) const | |
| { | | { | |
|
| arma_debug_check( (i >= n_elem), "subview::operator(): index out of bound
s"); | | arma_debug_check( (ii >= n_elem), "subview::operator(): index out of boun
ds"); | |
| | | | |
|
| const uword in_col = i / n_rows; | | const uword in_col = ii / n_rows; | |
| const uword in_row = i % n_rows; | | const uword in_row = ii % n_rows; | |
| | | | |
| const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | | const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; | |
| | | | |
| return m.mem[index]; | | return m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT& | | eT& | |
| subview<eT>::operator()(const uword in_row, const uword in_col) | | subview<eT>::operator()(const uword in_row, const uword in_col) | |
| | | | |
| skipping to change at line 1237 | | skipping to change at line 1220 | |
| subview<eT>::colptr(const uword in_col) const | | subview<eT>::colptr(const uword in_col) const | |
| { | | { | |
| return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]; | | return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| subview<eT>::check_overlap(const subview<eT>& x) const | | subview<eT>::check_overlap(const subview<eT>& x) const | |
| { | | { | |
|
| const subview<eT>& t = *this; | | const subview<eT>& s = *this; | |
| | | | |
|
| if(&t.m != &x.m) | | if(&s.m != &x.m) | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| if( (t.n_elem == 0) || (x.n_elem == 0) ) | | if( (s.n_elem == 0) || (x.n_elem == 0) ) | |
| { | | { | |
| return false; | | return false; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| const uword t_row_start = t.aux_row1; | | const uword s_row_start = s.aux_row1; | |
| const uword t_row_end_p1 = t_row_start + t.n_rows; | | const uword s_row_end_p1 = s_row_start + s.n_rows; | |
| | | | |
|
| const uword t_col_start = t.aux_col1; | | const uword s_col_start = s.aux_col1; | |
| const uword t_col_end_p1 = t_col_start + t.n_cols; | | const uword s_col_end_p1 = s_col_start + s.n_cols; | |
| | | | |
| const uword x_row_start = x.aux_row1; | | const uword x_row_start = x.aux_row1; | |
| const uword x_row_end_p1 = x_row_start + x.n_rows; | | const uword x_row_end_p1 = x_row_start + x.n_rows; | |
| | | | |
| const uword x_col_start = x.aux_col1; | | const uword x_col_start = x.aux_col1; | |
| const uword x_col_end_p1 = x_col_start + x.n_cols; | | const uword x_col_end_p1 = x_col_start + x.n_cols; | |
| | | | |
|
| const bool outside_rows = ( (x_row_start >= t_row_end_p1) || (t_row_s | | const bool outside_rows = ( (x_row_start >= s_row_end_p1) || (s_row_s | |
| tart >= x_row_end_p1) ); | | tart >= x_row_end_p1) ); | |
| const bool outside_cols = ( (x_col_start >= t_col_end_p1) || (t_col_s | | const bool outside_cols = ( (x_col_start >= s_col_end_p1) || (s_col_s | |
| tart >= x_col_end_p1) ); | | tart >= x_col_end_p1) ); | |
| | | | |
| return ( (outside_rows == false) && (outside_cols == false) ); | | return ( (outside_rows == false) && (outside_cols == false) ); | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| bool | | bool | |
| subview<eT>::is_vec() const | | subview<eT>::is_vec() const | |
| | | | |
| skipping to change at line 2026 | | skipping to change at line 2009 | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| arma_debug_check | | arma_debug_check | |
| ( | | ( | |
| (in_row1 >= n_rows) || (in_row2 >= n_rows), | | (in_row1 >= n_rows) || (in_row2 >= n_rows), | |
| "subview::swap_rows(): out of bounds" | | "subview::swap_rows(): out of bounds" | |
| ); | | ); | |
| | | | |
| eT* mem = (const_cast< Mat<eT>& >(m)).memptr(); | | eT* mem = (const_cast< Mat<eT>& >(m)).memptr(); | |
| | | | |
|
| for(uword col=0; col<n_cols; ++col) | | if(n_elem > 0) | |
| { | | { | |
|
| const uword offset = (aux_col1 + col) * m.n_rows; | | const uword m_n_rows = m.n_rows; | |
| const uword pos1 = aux_row1 + in_row1 + offset; | | | |
| const uword pos2 = aux_row1 + in_row2 + offset; | | for(uword ucol=0; ucol < n_cols; ++ucol) | |
| | | { | |
| const eT tmp = mem[pos1]; | | const uword offset = (aux_col1 + ucol) * m_n_rows; | |
| access::rw(mem[pos1]) = mem[pos2]; | | const uword pos1 = aux_row1 + in_row1 + offset; | |
| access::rw(mem[pos2]) = tmp; | | const uword pos2 = aux_row1 + in_row2 + offset; | |
| | | | |
| | | std::swap( access::rw(mem[pos1]), access::rw(mem[pos2]) ); | |
| | | } | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| void | | void | |
| subview<eT>::swap_cols(const uword in_col1, const uword in_col2) | | subview<eT>::swap_cols(const uword in_col1, const uword in_col2) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| | | | |
| skipping to change at line 2056 | | skipping to change at line 2042 | |
| ( | | ( | |
| (in_col1 >= n_cols) || (in_col2 >= n_cols), | | (in_col1 >= n_cols) || (in_col2 >= n_cols), | |
| "subview::swap_cols(): out of bounds" | | "subview::swap_cols(): out of bounds" | |
| ); | | ); | |
| | | | |
| if(n_elem > 0) | | if(n_elem > 0) | |
| { | | { | |
| eT* ptr1 = colptr(in_col1); | | eT* ptr1 = colptr(in_col1); | |
| eT* ptr2 = colptr(in_col2); | | eT* ptr2 = colptr(in_col2); | |
| | | | |
|
| for(uword row=0; row<n_rows; ++row) | | for(uword urow=0; urow < n_rows; ++urow) | |
| { | | { | |
|
| const eT tmp = ptr1[row]; | | std::swap( ptr1[urow], ptr2[urow] ); | |
| ptr1[row] = ptr2[row]; | | | |
| ptr2[row] = tmp; | | | |
| } | | } | |
| } | | } | |
| } | | } | |
| | | | |
| // template<typename eT> | | // template<typename eT> | |
| // inline | | // inline | |
| // subview<eT>::iter::iter(const subview<eT>& S) | | // subview<eT>::iter::iter(const subview<eT>& S) | |
| // : mem (S.m.mem) | | // : mem (S.m.mem) | |
| // , n_rows (S.m.n_rows) | | // , n_rows (S.m.n_rows) | |
| // , row_start (S.aux_row1) | | // , row_start (S.aux_row1) | |
| | | | |
| skipping to change at line 2213 | | skipping to change at line 2197 | |
| arma_inline | | arma_inline | |
| const Op<subview_col<eT>,op_strans> | | const Op<subview_col<eT>,op_strans> | |
| subview_col<eT>::st() const | | subview_col<eT>::st() const | |
| { | | { | |
| return Op<subview_col<eT>,op_strans>(*this); | | return Op<subview_col<eT>,op_strans>(*this); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT& | | eT& | |
|
| subview_col<eT>::operator[](const uword i) | | subview_col<eT>::operator[](const uword ii) | |
| { | | { | |
|
| return access::rw( colmem[i] ); | | return access::rw( colmem[ii] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| subview_col<eT>::operator[](const uword i) const | | subview_col<eT>::operator[](const uword ii) const | |
| { | | { | |
|
| return colmem[i]; | | return colmem[ii]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT& | | eT& | |
|
| subview_col<eT>::operator()(const uword i) | | subview_col<eT>::operator()(const uword ii) | |
| { | | { | |
|
| arma_debug_check( (i >= subview<eT>::n_elem), "subview::operator(): index
out of bounds"); | | arma_debug_check( (ii >= subview<eT>::n_elem), "subview::operator(): inde
x out of bounds"); | |
| | | | |
|
| return access::rw( colmem[i] ); | | return access::rw( colmem[ii] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| subview_col<eT>::operator()(const uword i) const | | subview_col<eT>::operator()(const uword ii) const | |
| { | | { | |
|
| arma_debug_check( (i >= subview<eT>::n_elem), "subview::operator(): index
out of bounds"); | | arma_debug_check( (ii >= subview<eT>::n_elem), "subview::operator(): inde
x out of bounds"); | |
| | | | |
|
| return colmem[i]; | | return colmem[ii]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT& | | eT& | |
| subview_col<eT>::operator()(const uword in_row, const uword in_col) | | subview_col<eT>::operator()(const uword in_row, const uword in_col) | |
| { | | { | |
| arma_debug_check( ((in_row >= subview<eT>::n_rows) || (in_col > 0)), "sub
view::operator(): index out of bounds"); | | arma_debug_check( ((in_row >= subview<eT>::n_rows) || (in_col > 0)), "sub
view::operator(): index out of bounds"); | |
| | | | |
| return access::rw( colmem[in_row] ); | | return access::rw( colmem[in_row] ); | |
| | | | |
| skipping to change at line 2443 | | skipping to change at line 2427 | |
| arma_inline | | arma_inline | |
| const Op<subview_row<eT>,op_strans> | | const Op<subview_row<eT>,op_strans> | |
| subview_row<eT>::st() const | | subview_row<eT>::st() const | |
| { | | { | |
| return Op<subview_row<eT>,op_strans>(*this); | | return Op<subview_row<eT>,op_strans>(*this); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT& | | eT& | |
|
| subview_row<eT>::operator[](const uword i) | | subview_row<eT>::operator[](const uword ii) | |
| { | | { | |
|
| const uword index = (i + (subview<eT>::aux_col1))*(subview<eT>::m).n_rows
+ (subview<eT>::aux_row1); | | const uword index = (ii + (subview<eT>::aux_col1))*(subview<eT>::m).n_row
s + (subview<eT>::aux_row1); | |
| | | | |
| return access::rw( (const_cast< Mat<eT>& >(subview<eT>::m)).mem[index] ); | | return access::rw( (const_cast< Mat<eT>& >(subview<eT>::m)).mem[index] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| subview_row<eT>::operator[](const uword i) const | | subview_row<eT>::operator[](const uword ii) const | |
| { | | { | |
|
| const uword index = (i + (subview<eT>::aux_col1))*(subview<eT>::m).n_rows
+ (subview<eT>::aux_row1); | | const uword index = (ii + (subview<eT>::aux_col1))*(subview<eT>::m).n_row
s + (subview<eT>::aux_row1); | |
| | | | |
| return subview<eT>::m.mem[index]; | | return subview<eT>::m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT& | | eT& | |
|
| subview_row<eT>::operator()(const uword i) | | subview_row<eT>::operator()(const uword ii) | |
| { | | { | |
|
| arma_debug_check( (i >= subview<eT>::n_elem), "subview::operator(): index
out of bounds"); | | arma_debug_check( (ii >= subview<eT>::n_elem), "subview::operator(): inde
x out of bounds"); | |
| | | | |
|
| const uword index = (i + (subview<eT>::aux_col1))*(subview<eT>::m).n_rows
+ (subview<eT>::aux_row1); | | const uword index = (ii + (subview<eT>::aux_col1))*(subview<eT>::m).n_row
s + (subview<eT>::aux_row1); | |
| | | | |
| return access::rw( (const_cast< Mat<eT>& >(subview<eT>::m)).mem[index] ); | | return access::rw( (const_cast< Mat<eT>& >(subview<eT>::m)).mem[index] ); | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT | | eT | |
|
| subview_row<eT>::operator()(const uword i) const | | subview_row<eT>::operator()(const uword ii) const | |
| { | | { | |
|
| arma_debug_check( (i >= subview<eT>::n_elem), "subview::operator(): index
out of bounds"); | | arma_debug_check( (ii >= subview<eT>::n_elem), "subview::operator(): inde
x out of bounds"); | |
| | | | |
|
| const uword index = (i + (subview<eT>::aux_col1))*(subview<eT>::m).n_rows
+ (subview<eT>::aux_row1); | | const uword index = (ii + (subview<eT>::aux_col1))*(subview<eT>::m).n_row
s + (subview<eT>::aux_row1); | |
| | | | |
| return subview<eT>::m.mem[index]; | | return subview<eT>::m.mem[index]; | |
| } | | } | |
| | | | |
| template<typename eT> | | template<typename eT> | |
| inline | | inline | |
| eT& | | eT& | |
| subview_row<eT>::operator()(const uword in_row, const uword in_col) | | subview_row<eT>::operator()(const uword in_row, const uword in_col) | |
| { | | { | |
| arma_debug_check( ((in_row > 0) || (in_col >= subview<eT>::n_cols)), "sub
view::operator(): index out of bounds"); | | arma_debug_check( ((in_row > 0) || (in_col >= subview<eT>::n_cols)), "sub
view::operator(): index out of bounds"); | |
| | | | |
End of changes. 292 change blocks. |
| 402 lines changed or deleted | | 396 lines changed or added | |
|
| unwrap.hpp | | unwrap.hpp | |
| | | | |
| skipping to change at line 21 | | skipping to change at line 21 | |
| // (see http://www.opensource.org/licenses for more info) | | // (see http://www.opensource.org/licenses for more info) | |
| | | | |
| //! \addtogroup unwrap | | //! \addtogroup unwrap | |
| //! @{ | | //! @{ | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| struct unwrap_default | | struct unwrap_default | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline unwrap_default(const T1& A) // TODO: change this to Base ? | | inline | |
| | | unwrap_default(const T1& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| const Mat<eT> M; | | const Mat<eT> M; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct unwrap_Mat_fixed | | struct unwrap_fixed | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline explicit unwrap_Mat_fixed(const T1& A) | | inline explicit | |
| | | unwrap_fixed(const T1& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename T1, bool condition> | | template<typename T1, bool condition> | |
| struct unwrap_redirect {}; | | struct unwrap_redirect {}; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct unwrap_redirect<T1, false> { typedef unwrap_default<T1> result; }; | | struct unwrap_redirect<T1, false> { typedef unwrap_default<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct unwrap_redirect<T1, true> { typedef unwrap_Mat_fixed<T1> result; }; | | struct unwrap_redirect<T1, true> { typedef unwrap_fixed<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class unwrap : public unwrap_redirect<T1, is_Mat_fixed<T1>::value >::result | | struct unwrap : public unwrap_redirect<T1, is_Mat_fixed<T1>::value >::resul
t | |
| { | | { | |
|
| public: | | inline | |
| | | unwrap(const T1& A) | |
| inline unwrap(const T1& A) | | | |
| : unwrap_redirect< T1, is_Mat_fixed<T1>::value >::result(A) | | : unwrap_redirect< T1, is_Mat_fixed<T1>::value >::result(A) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class unwrap< Mat<eT> > | | struct unwrap< Mat<eT> > | |
| | | { | |
| | | inline | |
| | | unwrap(const Mat<eT>& A) | |
| | | : M(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | const Mat<eT>& M; | |
| | | }; | |
| | | | |
| | | template<typename eT> | |
| | | struct unwrap< Row<eT> > | |
| | | { | |
| | | inline | |
| | | unwrap(const Row<eT>& A) | |
| | | : M(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | const Row<eT>& M; | |
| | | }; | |
| | | | |
| | | template<typename eT> | |
| | | struct unwrap< Col<eT> > | |
| | | { | |
| | | inline | |
| | | unwrap(const Col<eT>& A) | |
| | | : M(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | const Col<eT>& M; | |
| | | }; | |
| | | | |
| | | template<typename out_eT, typename T1, typename T2, typename glue_type> | |
| | | struct unwrap< mtGlue<out_eT, T1, T2, glue_type> > | |
| { | | { | |
|
| public: | | inline | |
| | | unwrap(const mtGlue<out_eT, T1, T2, glue_type>& A) | |
| | | : M(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | const Mat<out_eT> M; | |
| | | }; | |
| | | | |
| | | template<typename out_eT, typename T1, typename op_type> | |
| | | struct unwrap< mtOp<out_eT, T1, op_type> > | |
| | | { | |
| | | inline | |
| | | unwrap(const mtOp<out_eT, T1, op_type>& A) | |
| | | : M(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | const Mat<out_eT> M; | |
| | | }; | |
| | | | |
| | | // | |
| | | // | |
| | | // | |
| | | | |
| | | template<typename T1> | |
| | | struct quasi_unwrap_default | |
| | | { | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline unwrap(const Mat<eT>& A) | | static const bool has_subview = false; | |
| | | | |
| | | inline | |
| | | quasi_unwrap_default(const T1& A) | |
| | | : M(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | // NOTE: DO NOT DIRECTLY CHECK FOR ALIASING BY TAKING THE ADDRESS OF THE | |
| | | "M" OBJECT IN ANY quasi_unwrap CLASS !!! | |
| | | const Mat<eT> M; | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>&) const { return false; } | |
| | | }; | |
| | | | |
| | | template<typename T1> | |
| | | struct quasi_unwrap_fixed | |
| | | { | |
| | | typedef typename T1::elem_type eT; | |
| | | | |
| | | static const bool has_subview = false; | |
| | | | |
| | | inline explicit | |
| | | quasi_unwrap_fixed(const T1& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
|
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&M) | |
| | | == void_ptr(&X)); } | |
| | | }; | |
| | | | |
| | | template<typename T1, bool condition> | |
| | | struct quasi_unwrap_redirect {}; | |
| | | | |
| | | template<typename T1> | |
| | | struct quasi_unwrap_redirect<T1, false> { typedef quasi_unwrap_default<T1> | |
| | | result; }; | |
| | | | |
| | | template<typename T1> | |
| | | struct quasi_unwrap_redirect<T1, true> { typedef quasi_unwrap_fixed<T1> | |
| | | result; }; | |
| | | | |
| | | template<typename T1> | |
| | | struct quasi_unwrap : public quasi_unwrap_redirect<T1, is_Mat_fixed<T1>::va | |
| | | lue >::result | |
| | | { | |
| | | typedef typename quasi_unwrap_redirect<T1, is_Mat_fixed<T1>::value >::res | |
| | | ult quasi_unwrap_extra; | |
| | | | |
| | | static const bool has_subview = quasi_unwrap_extra::has_subview; | |
| | | | |
| | | inline | |
| | | quasi_unwrap(const T1& A) | |
| | | : quasi_unwrap_extra(A) | |
| | | { | |
| | | } | |
| | | | |
| | | using quasi_unwrap_extra::M; | |
| | | using quasi_unwrap_extra::is_alias; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class unwrap< Row<eT> > | | struct quasi_unwrap< Mat<eT> > | |
| { | | { | |
|
| public: | | static const bool has_subview = false; | |
| | | | |
|
| inline unwrap(const Row<eT>& A) | | inline | |
| | | quasi_unwrap(const Mat<eT>& A) | |
| | | : M(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | const Mat<eT>& M; | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&M) | |
| | | == void_ptr(&X)); } | |
| | | }; | |
| | | | |
| | | template<typename eT> | |
| | | struct quasi_unwrap< Row<eT> > | |
| | | { | |
| | | static const bool has_subview = false; | |
| | | | |
| | | inline | |
| | | quasi_unwrap(const Row<eT>& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| const Row<eT>& M; | | const Row<eT>& M; | |
|
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&M) | |
| | | == void_ptr(&X)); } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class unwrap< Col<eT> > | | struct quasi_unwrap< Col<eT> > | |
| { | | { | |
|
| public: | | static const bool has_subview = false; | |
| | | | |
|
| inline unwrap(const Col<eT>& A) | | inline | |
| | | quasi_unwrap(const Col<eT>& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| const Col<eT>& M; | | const Col<eT>& M; | |
|
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&M) | |
| | | == void_ptr(&X)); } | |
| | | }; | |
| | | | |
| | | template<typename eT> | |
| | | struct quasi_unwrap< subview_col<eT> > | |
| | | { | |
| | | static const bool has_subview = true; | |
| | | | |
| | | inline | |
| | | quasi_unwrap(const subview_col<eT>& A) | |
| | | : M ( const_cast<eT*>( A.colptr(0) ), A.n_rows, 1, false, false ) | |
| | | , src( A.m ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | const Mat<eT> M; | |
| | | const Mat<eT>& src; | |
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>& X) const { return (void_ptr(&sr | |
| | | c) == void_ptr(&X)); } | |
| }; | | }; | |
| | | | |
| template<typename out_eT, typename T1, typename T2, typename glue_type> | | template<typename out_eT, typename T1, typename T2, typename glue_type> | |
|
| class unwrap< mtGlue<out_eT, T1, T2, glue_type> > | | struct quasi_unwrap< mtGlue<out_eT, T1, T2, glue_type> > | |
| { | | { | |
|
| public: | | static const bool has_subview = false; | |
| | | | |
|
| inline unwrap(const mtGlue<out_eT, T1, T2, glue_type>& A) | | inline | |
| | | quasi_unwrap(const mtGlue<out_eT, T1, T2, glue_type>& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| const Mat<out_eT> M; | | const Mat<out_eT> M; | |
|
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>&) const { return false; } | |
| }; | | }; | |
| | | | |
| template<typename out_eT, typename T1, typename op_type> | | template<typename out_eT, typename T1, typename op_type> | |
|
| class unwrap< mtOp<out_eT, T1, op_type> > | | struct quasi_unwrap< mtOp<out_eT, T1, op_type> > | |
| { | | { | |
|
| public: | | static const bool has_subview = false; | |
| | | | |
|
| inline unwrap(const mtOp<out_eT, T1, op_type>& A) | | inline | |
| | | quasi_unwrap(const mtOp<out_eT, T1, op_type>& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| const Mat<out_eT> M; | | const Mat<out_eT> M; | |
|
| | | | |
| | | template<typename eT2> | |
| | | arma_inline bool is_alias(const Mat<eT2>&) const { return false; } | |
| }; | | }; | |
| | | | |
| // | | // | |
| // | | // | |
| // | | // | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class unwrap_check | | struct unwrap_check_default | |
| { | | { | |
|
| public: | | | |
| | | | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
| inline | | inline | |
|
| unwrap_check(const T1& A, const Mat<eT>&) | | unwrap_check_default(const T1& A, const Mat<eT>&) | |
| | | : M(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | inline | |
| | | unwrap_check_default(const T1& A, const bool) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| const Mat<eT> M; | | const Mat<eT> M; | |
| }; | | }; | |
| | | | |
|
| template<typename eT> | | template<typename T1> | |
| class unwrap_check< Mat<eT> > | | struct unwrap_check_fixed | |
| { | | { | |
|
| public: | | typedef typename T1::elem_type eT; | |
| | | | |
| | | inline | |
| | | unwrap_check_fixed(const T1& A, const Mat<eT>& B) | |
| | | : M_local( (&A == &B) ? new Mat<eT>(A) : 0 ) | |
| | | , M ( (&A == &B) ? *M_local : A ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| inline | | inline | |
|
| | | unwrap_check_fixed(const T1& A, const bool is_alias) | |
| | | : M_local( is_alias ? new Mat<eT>(A) : 0 ) | |
| | | , M ( is_alias ? *M_local : A ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | inline | |
| | | ~unwrap_check_fixed() | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | | |
| | | if(M_local) { delete M_local; } | |
| | | } | |
| | | | |
| | | // the order below is important | |
| | | const Mat<eT>* M_local; | |
| | | const Mat<eT>& M; | |
| | | }; | |
| | | | |
| | | template<typename T1, bool condition> | |
| | | struct unwrap_check_redirect {}; | |
| | | | |
| | | template<typename T1> | |
| | | struct unwrap_check_redirect<T1, false> { typedef unwrap_check_default<T1> | |
| | | result; }; | |
| | | | |
| | | template<typename T1> | |
| | | struct unwrap_check_redirect<T1, true> { typedef unwrap_check_fixed<T1> | |
| | | result; }; | |
| | | | |
| | | template<typename T1> | |
| | | struct unwrap_check : public unwrap_check_redirect<T1, is_Mat_fixed<T1>::va | |
| | | lue >::result | |
| | | { | |
| | | inline unwrap_check(const T1& A, const Mat<typename T1::elem_type>& B) | |
| | | : unwrap_check_redirect< T1, is_Mat_fixed<T1>::value >::result(A, B) | |
| | | { | |
| | | } | |
| | | | |
| | | inline unwrap_check(const T1& A, const bool is_alias) | |
| | | : unwrap_check_redirect< T1, is_Mat_fixed<T1>::value >::result(A, is_al | |
| | | ias) | |
| | | { | |
| | | } | |
| | | }; | |
| | | | |
| | | template<typename eT> | |
| | | struct unwrap_check< Mat<eT> > | |
| | | { | |
| | | inline | |
| unwrap_check(const Mat<eT>& A, const Mat<eT>& B) | | unwrap_check(const Mat<eT>& A, const Mat<eT>& B) | |
| : M_local( (&A == &B) ? new Mat<eT>(A) : 0 ) | | : M_local( (&A == &B) ? new Mat<eT>(A) : 0 ) | |
| , M ( (&A == &B) ? (*M_local) : A ) | | , M ( (&A == &B) ? (*M_local) : A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
|
| | | unwrap_check(const Mat<eT>& A, const bool is_alias) | |
| | | : M_local( is_alias ? new Mat<eT>(A) : 0 ) | |
| | | , M ( is_alias ? (*M_local) : A ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| inline | | inline | |
| ~unwrap_check() | | ~unwrap_check() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(M_local) { delete M_local; } | | if(M_local) { delete M_local; } | |
| } | | } | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class unwrap_check< Row<eT> > | | struct unwrap_check< Row<eT> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| unwrap_check(const Row<eT>& A, const Mat<eT>& B) | | unwrap_check(const Row<eT>& A, const Mat<eT>& B) | |
|
| : M_local( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? new Row<eT>(A | | : M_local( (&A == &B) ? new Row<eT>(A) : 0 ) | |
| ) : 0 ) | | , M ( (&A == &B) ? (*M_local) : A ) | |
| , M ( (&A == reinterpret_cast<const Row<eT>*>(&B)) ? (*M_local) | | { | |
| : A ) | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | unwrap_check(const Row<eT>& A, const bool is_alias) | |
| | | : M_local( is_alias ? new Row<eT>(A) : 0 ) | |
| | | , M ( is_alias ? (*M_local) : A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| ~unwrap_check() | | ~unwrap_check() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(M_local) { delete M_local; } | | if(M_local) { delete M_local; } | |
| } | | } | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Row<eT>* M_local; | | const Row<eT>* M_local; | |
| const Row<eT>& M; | | const Row<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class unwrap_check< Col<eT> > | | struct unwrap_check< Col<eT> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| unwrap_check(const Col<eT>& A, const Mat<eT>& B) | | unwrap_check(const Col<eT>& A, const Mat<eT>& B) | |
|
| : M_local( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? new Col<eT>(A | | : M_local( (&A == &B) ? new Col<eT>(A) : 0 ) | |
| ) : 0 ) | | , M ( (&A == &B) ? (*M_local) : A ) | |
| , M ( (&A == reinterpret_cast<const Col<eT>*>(&B)) ? (*M_local) | | { | |
| : A ) | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| | | unwrap_check(const Col<eT>& A, const bool is_alias) | |
| | | : M_local( is_alias ? new Col<eT>(A) : 0 ) | |
| | | , M ( is_alias ? (*M_local) : A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| ~unwrap_check() | | ~unwrap_check() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(M_local) { delete M_local; } | | if(M_local) { delete M_local; } | |
| } | | } | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Col<eT>* M_local; | | const Col<eT>* M_local; | |
| const Col<eT>& M; | | const Col<eT>& M; | |
|
| | | | |
| }; | | }; | |
| | | | |
| // | | // | |
| // | | // | |
| // | | // | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class unwrap_check_mixed | | struct unwrap_check_mixed | |
| { | | { | |
|
| public: | | | |
| | | | |
| typedef typename T1::elem_type eT1; | | typedef typename T1::elem_type eT1; | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| inline | | inline | |
| unwrap_check_mixed(const T1& A, const Mat<eT2>&) | | unwrap_check_mixed(const T1& A, const Mat<eT2>&) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
|
| | | template<typename eT2> | |
| | | inline | |
| | | unwrap_check_mixed(const T1& A, const bool) | |
| | | : M(A) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| const Mat<eT1> M; | | const Mat<eT1> M; | |
| }; | | }; | |
| | | | |
| template<typename eT1> | | template<typename eT1> | |
|
| class unwrap_check_mixed< Mat<eT1> > | | struct unwrap_check_mixed< Mat<eT1> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| inline | | inline | |
| unwrap_check_mixed(const Mat<eT1>& A, const Mat<eT2>& B) | | unwrap_check_mixed(const Mat<eT1>& A, const Mat<eT2>& B) | |
| : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Mat<eT1>(A) : 0 ) | | : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Mat<eT1>(A) : 0 ) | |
| , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) | | , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
|
| | | template<typename eT2> | |
| | | inline | |
| | | unwrap_check_mixed(const Mat<eT1>& A, const bool is_alias) | |
| | | : M_local( is_alias ? new Mat<eT1>(A) : 0 ) | |
| | | , M ( is_alias ? (*M_local) : A ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| inline | | inline | |
| ~unwrap_check_mixed() | | ~unwrap_check_mixed() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(M_local) { delete M_local; } | | if(M_local) { delete M_local; } | |
| } | | } | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Mat<eT1>* M_local; | | const Mat<eT1>* M_local; | |
| const Mat<eT1>& M; | | const Mat<eT1>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT1> | | template<typename eT1> | |
|
| class unwrap_check_mixed< Row<eT1> > | | struct unwrap_check_mixed< Row<eT1> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| inline | | inline | |
| unwrap_check_mixed(const Row<eT1>& A, const Mat<eT2>& B) | | unwrap_check_mixed(const Row<eT1>& A, const Mat<eT2>& B) | |
| : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Row<eT1>(A) : 0 ) | | : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Row<eT1>(A) : 0 ) | |
| , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) | | , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
|
| | | template<typename eT2> | |
| | | inline | |
| | | unwrap_check_mixed(const Row<eT1>& A, const bool is_alias) | |
| | | : M_local( is_alias ? new Row<eT1>(A) : 0 ) | |
| | | , M ( is_alias ? (*M_local) : A ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| inline | | inline | |
| ~unwrap_check_mixed() | | ~unwrap_check_mixed() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(M_local) { delete M_local; } | | if(M_local) { delete M_local; } | |
| } | | } | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Row<eT1>* M_local; | | const Row<eT1>* M_local; | |
| const Row<eT1>& M; | | const Row<eT1>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT1> | | template<typename eT1> | |
|
| class unwrap_check_mixed< Col<eT1> > | | struct unwrap_check_mixed< Col<eT1> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| template<typename eT2> | | template<typename eT2> | |
| inline | | inline | |
| unwrap_check_mixed(const Col<eT1>& A, const Mat<eT2>& B) | | unwrap_check_mixed(const Col<eT1>& A, const Mat<eT2>& B) | |
| : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Col<eT1>(A) : 0 ) | | : M_local( (void_ptr(&A) == void_ptr(&B)) ? new Col<eT1>(A) : 0 ) | |
| , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) | | , M ( (void_ptr(&A) == void_ptr(&B)) ? (*M_local) : A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
|
| | | template<typename eT2> | |
| | | inline | |
| | | unwrap_check_mixed(const Col<eT1>& A, const bool is_alias) | |
| | | : M_local( is_alias ? new Col<eT1>(A) : 0 ) | |
| | | , M ( is_alias ? (*M_local) : A ) | |
| | | { | |
| | | arma_extra_debug_sigprint(); | |
| | | } | |
| | | | |
| inline | | inline | |
| ~unwrap_check_mixed() | | ~unwrap_check_mixed() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(M_local) { delete M_local; } | | if(M_local) { delete M_local; } | |
| } | | } | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Col<eT1>* M_local; | | const Col<eT1>* M_local; | |
| const Col<eT1>& M; | | const Col<eT1>& M; | |
| }; | | }; | |
| | | | |
| // | | // | |
|
| | | // | |
| | | // | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| struct partial_unwrap_default | | struct partial_unwrap_default | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline partial_unwrap_default(const T1& A) | | inline | |
| | | partial_unwrap_default(const T1& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT> M; | | const Mat<eT> M; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_Mat_fixed | | struct partial_unwrap_fixed | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline explicit partial_unwrap_Mat_fixed(const T1& A) | | inline explicit | |
| | | partial_unwrap_fixed(const T1& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename T1, bool condition> | | template<typename T1, bool condition> | |
| struct partial_unwrap_redirect {}; | | struct partial_unwrap_redirect {}; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_redirect<T1, false> { typedef partial_unwrap_default<
T1> result; }; | | struct partial_unwrap_redirect<T1, false> { typedef partial_unwrap_default<
T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_redirect<T1, true> { typedef partial_unwrap_Mat_fixe
d<T1> result; }; | | struct partial_unwrap_redirect<T1, true> { typedef partial_unwrap_fixed<T1
> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class partial_unwrap : public partial_unwrap_redirect<T1, is_Mat_fixed<T1>:
:value >::result | | struct partial_unwrap : public partial_unwrap_redirect<T1, is_Mat_fixed<T1>
::value >::result | |
| { | | { | |
|
| public: | | inline | |
| | | partial_unwrap(const T1& A) | |
| inline partial_unwrap(const T1& A) | | | |
| : partial_unwrap_redirect< T1, is_Mat_fixed<T1>::value >::result(A) | | : partial_unwrap_redirect< T1, is_Mat_fixed<T1>::value >::result(A) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Mat<eT> > | | struct partial_unwrap< Mat<eT> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Mat<eT>& A) | | partial_unwrap(const Mat<eT>& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return eT(1); } | | inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Row<eT> > | | struct partial_unwrap< Row<eT> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Row<eT>& A) | | partial_unwrap(const Row<eT>& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return eT(1); } | | inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Col<eT> > | | struct partial_unwrap< Col<eT> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Col<eT>& A) | | partial_unwrap(const Col<eT>& A) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return eT(1); } | | inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
|
| | | // NOTE: we can get away with this shortcut as the partial_unwrap class is | |
| | | only used by as_scalar(), | |
| | | // NOTE: which doesn't need to check for aliasing (ie. it doesn't need to c | |
| | | ompare the address of M with another matrix) | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< subview_col<eT> > | | struct partial_unwrap< subview_col<eT> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const subview_col<eT>& A) | | partial_unwrap(const subview_col<eT>& A) | |
|
| : M( const_cast<eT*>( A.colptr(0) ), A.n_rows, 1, false, false ) | | : M ( const_cast<eT*>( A.colptr(0) ), A.n_rows, 1, false, false ) | |
| | | //, ref( A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return eT(1); } | | inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT> M; | | const Mat<eT> M; | |
|
| | | | |
| | | //// prevents the compiler from potentially deleting the subview object b | |
| | | efore we're done with it | |
| | | //const subview_col<eT>& ref; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| struct partial_unwrap_htrans_default | | struct partial_unwrap_htrans_default | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline partial_unwrap_htrans_default(const Op<T1, op_htrans>& A) | | inline | |
| | | partial_unwrap_htrans_default(const Op<T1, op_htrans>& A) | |
| : M(A.m) | | : M(A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT> M; | | const Mat<eT> M; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_htrans_Mat_fixed | | struct partial_unwrap_htrans_fixed | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline explicit partial_unwrap_htrans_Mat_fixed(const Op<T1, op_htrans>& | | inline explicit | |
| A) | | partial_unwrap_htrans_fixed(const Op<T1, op_htrans>& A) | |
| : M(A.m) | | : M(A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename T1, bool condition> | | template<typename T1, bool condition> | |
| struct partial_unwrap_htrans_redirect {}; | | struct partial_unwrap_htrans_redirect {}; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_htrans_redirect<T1, false> { typedef partial_unwrap_h
trans_default<T1> result; }; | | struct partial_unwrap_htrans_redirect<T1, false> { typedef partial_unwrap_h
trans_default<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_htrans_redirect<T1, true> { typedef partial_unwrap_h
trans_Mat_fixed<T1> result; }; | | struct partial_unwrap_htrans_redirect<T1, true> { typedef partial_unwrap_h
trans_fixed<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class partial_unwrap< Op<T1, op_htrans> > : public partial_unwrap_htrans_re
direct<T1, is_Mat_fixed<T1>::value >::result | | struct partial_unwrap< Op<T1, op_htrans> > : public partial_unwrap_htrans_r
edirect<T1, is_Mat_fixed<T1>::value >::result | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline partial_unwrap(const Op<T1, op_htrans>& A) | | inline partial_unwrap(const Op<T1, op_htrans>& A) | |
| : partial_unwrap_htrans_redirect< T1, is_Mat_fixed<T1>::value >::result
(A) | | : partial_unwrap_htrans_redirect< T1, is_Mat_fixed<T1>::value >::result
(A) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Op< Mat<eT>, op_htrans> > | | struct partial_unwrap< Op< Mat<eT>, op_htrans> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Op< Mat<eT>, op_htrans>& A) | | partial_unwrap(const Op< Mat<eT>, op_htrans>& A) | |
| : M(A.m) | | : M(A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_inline eT get_val() const { return eT(1); } | | arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Op< Row<eT>, op_htrans> > | | struct partial_unwrap< Op< Row<eT>, op_htrans> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Op< Row<eT>, op_htrans>& A) | | partial_unwrap(const Op< Row<eT>, op_htrans>& A) | |
| : M(A.m) | | : M(A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_inline eT get_val() const { return eT(1); } | | arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Op< Col<eT>, op_htrans> > | | struct partial_unwrap< Op< Col<eT>, op_htrans> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Op< Col<eT>, op_htrans>& A) | | partial_unwrap(const Op< Col<eT>, op_htrans>& A) | |
| : M(A.m) | | : M(A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_inline eT get_val() const { return eT(1); } | | arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
|
| | | // NOTE: we can get away with this shortcut as the partial_unwrap class is | |
| | | only used by as_scalar(), | |
| | | // NOTE: which doesn't need to check for aliasing (ie. it doesn't need to c | |
| | | ompare the address of M with another matrix) | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Op< subview_col<eT>, op_htrans> > | | struct partial_unwrap< Op< subview_col<eT>, op_htrans> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Op< subview_col<eT>, op_htrans>& A) | | partial_unwrap(const Op< subview_col<eT>, op_htrans>& A) | |
|
| : M( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, false, false ) | | : M ( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, false, false ) | |
| | | //, ref( A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_inline eT get_val() const { return eT(1); } | | arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT> M; | | const Mat<eT> M; | |
|
| | | | |
| | | //// prevents the compiler from potentially deleting the subview object b | |
| | | efore we're done with it | |
| | | //const Op< subview_col<eT>, op_htrans>& ref; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| struct partial_unwrap_htrans2_default | | struct partial_unwrap_htrans2_default | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline partial_unwrap_htrans2_default(const Op<T1, op_htrans2>& A) | | inline | |
| | | partial_unwrap_htrans2_default(const Op<T1, op_htrans2>& A) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.m) | | , M (A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_inline eT get_val() const { return val; } | | arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT> M; | | const Mat<eT> M; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_htrans2_Mat_fixed | | struct partial_unwrap_htrans2_fixed | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline explicit partial_unwrap_htrans2_Mat_fixed(const Op<T1, op_htrans2> | | inline explicit | |
| & A) | | partial_unwrap_htrans2_fixed(const Op<T1, op_htrans2>& A) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.m) | | , M (A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_inline eT get_val() const { return val; } | | arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename T1, bool condition> | | template<typename T1, bool condition> | |
| struct partial_unwrap_htrans2_redirect {}; | | struct partial_unwrap_htrans2_redirect {}; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_htrans2_redirect<T1, false> { typedef partial_unwrap_
htrans2_default<T1> result; }; | | struct partial_unwrap_htrans2_redirect<T1, false> { typedef partial_unwrap_
htrans2_default<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_htrans2_redirect<T1, true> { typedef partial_unwrap_
htrans2_Mat_fixed<T1> result; }; | | struct partial_unwrap_htrans2_redirect<T1, true> { typedef partial_unwrap_
htrans2_fixed<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class partial_unwrap< Op<T1, op_htrans2> > : public partial_unwrap_htrans2_
redirect<T1, is_Mat_fixed<T1>::value >::result | | struct partial_unwrap< Op<T1, op_htrans2> > : public partial_unwrap_htrans2
_redirect<T1, is_Mat_fixed<T1>::value >::result | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline partial_unwrap(const Op<T1, op_htrans2>& A) | | inline partial_unwrap(const Op<T1, op_htrans2>& A) | |
| : partial_unwrap_htrans2_redirect< T1, is_Mat_fixed<T1>::value >::resul
t(A) | | : partial_unwrap_htrans2_redirect< T1, is_Mat_fixed<T1>::value >::resul
t(A) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Op< Mat<eT>, op_htrans2> > | | struct partial_unwrap< Op< Mat<eT>, op_htrans2> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Op< Mat<eT>, op_htrans2>& A) | | partial_unwrap(const Op< Mat<eT>, op_htrans2>& A) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.m) | | , M (A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return val; } | | inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Op< Row<eT>, op_htrans2> > | | struct partial_unwrap< Op< Row<eT>, op_htrans2> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Op< Row<eT>, op_htrans2>& A) | | partial_unwrap(const Op< Row<eT>, op_htrans2>& A) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.m) | | , M (A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return val; } | | inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Op< Col<eT>, op_htrans2> > | | struct partial_unwrap< Op< Col<eT>, op_htrans2> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Op< Col<eT>, op_htrans2>& A) | | partial_unwrap(const Op< Col<eT>, op_htrans2>& A) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.m) | | , M (A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return val; } | | inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
|
| | | // NOTE: we can get away with this shortcut as the partial_unwrap class is | |
| | | only used by as_scalar(), | |
| | | // NOTE: which doesn't need to check for aliasing (ie. it doesn't need to c | |
| | | ompare the address of M with another matrix) | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< Op< subview_col<eT>, op_htrans2> > | | struct partial_unwrap< Op< subview_col<eT>, op_htrans2> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const Op< subview_col<eT>, op_htrans2>& A) | | partial_unwrap(const Op< subview_col<eT>, op_htrans2>& A) | |
| : val( A.aux ) | | : val( A.aux ) | |
| , M ( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, false, false ) | | , M ( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, false, false ) | |
|
| | | //, ref( A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return val; } | | inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT> M; | | const Mat<eT> M; | |
|
| | | | |
| | | //// prevents the compiler from potentially deleting the subview object b | |
| | | efore we're done with it | |
| | | //const Op< subview_col<eT>, op_htrans2>& ref; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| struct partial_unwrap_scalar_times_default | | struct partial_unwrap_scalar_times_default | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline partial_unwrap_scalar_times_default(const eOp<T1, eop_scalar_times | | inline | |
| >& A) | | partial_unwrap_scalar_times_default(const eOp<T1, eop_scalar_times>& A) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.P.Q) | | , M (A.P.Q) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return val; } | | arma_hot arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT> M; | | const Mat<eT> M; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_scalar_times_Mat_fixed | | struct partial_unwrap_scalar_times_fixed | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline explicit partial_unwrap_scalar_times_Mat_fixed(const eOp<T1, eop_s | | inline explicit | |
| calar_times>& A) | | partial_unwrap_scalar_times_fixed(const eOp<T1, eop_scalar_times>& A) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.P.Q) | | , M (A.P.Q) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return val; } | | arma_hot arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename T1, bool condition> | | template<typename T1, bool condition> | |
| struct partial_unwrap_scalar_times_redirect {}; | | struct partial_unwrap_scalar_times_redirect {}; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_scalar_times_redirect<T1, false> { typedef partial_un
wrap_scalar_times_default<T1> result; }; | | struct partial_unwrap_scalar_times_redirect<T1, false> { typedef partial_un
wrap_scalar_times_default<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_scalar_times_redirect<T1, true> { typedef partial_un
wrap_scalar_times_Mat_fixed<T1> result; }; | | struct partial_unwrap_scalar_times_redirect<T1, true> { typedef partial_un
wrap_scalar_times_fixed<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class partial_unwrap< eOp<T1, eop_scalar_times> > : public partial_unwrap_s
calar_times_redirect<T1, is_Mat_fixed<T1>::value >::result | | struct partial_unwrap< eOp<T1, eop_scalar_times> > : public partial_unwrap_
scalar_times_redirect<T1, is_Mat_fixed<T1>::value >::result | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| public: | | inline | |
| inline partial_unwrap(const eOp<T1, eop_scalar_times>& A) | | partial_unwrap(const eOp<T1, eop_scalar_times>& A) | |
| : partial_unwrap_scalar_times_redirect< T1, is_Mat_fixed<T1>::value >::
result(A) | | : partial_unwrap_scalar_times_redirect< T1, is_Mat_fixed<T1>::value >::
result(A) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< eOp<Mat<eT>, eop_scalar_times> > | | struct partial_unwrap< eOp<Mat<eT>, eop_scalar_times> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const eOp<Mat<eT>,eop_scalar_times>& A) | | partial_unwrap(const eOp<Mat<eT>,eop_scalar_times>& A) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.P.Q) | | , M (A.P.Q) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return val; } | | inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< eOp<Row<eT>, eop_scalar_times> > | | struct partial_unwrap< eOp<Row<eT>, eop_scalar_times> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const eOp<Row<eT>,eop_scalar_times>& A) | | partial_unwrap(const eOp<Row<eT>,eop_scalar_times>& A) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.P.Q) | | , M (A.P.Q) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return val; } | | inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap< eOp<Col<eT>, eop_scalar_times> > | | struct partial_unwrap< eOp<Col<eT>, eop_scalar_times> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| inline | | inline | |
| partial_unwrap(const eOp<Col<eT>,eop_scalar_times>& A) | | partial_unwrap(const eOp<Col<eT>,eop_scalar_times>& A) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.P.Q) | | , M (A.P.Q) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline eT get_val() const { return val; } | | inline eT get_val() const { return val; } | |
| | | | |
| | | | |
| skipping to change at line 901 | | skipping to change at line 1174 | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| // | | // | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| struct partial_unwrap_check_default | | struct partial_unwrap_check_default | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline partial_unwrap_check_default(const T1& A, const Mat<eT>&) | | inline | |
| | | partial_unwrap_check_default(const T1& A, const Mat<eT>&) | |
| : M(A) | | : M(A) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT> M; | | const Mat<eT> M; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_Mat_fixed | | struct partial_unwrap_check_fixed | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline explicit partial_unwrap_check_Mat_fixed(const T1& A, const Mat<eT> | | inline explicit | |
| & B) | | partial_unwrap_check_fixed(const T1& A, const Mat<eT>& B) | |
| : M_local( (&A == &B) ? new Mat<eT>(A) : 0 ) | | : M_local( (&A == &B) ? new Mat<eT>(A) : 0 ) | |
| , M ( (&A == &B) ? (*M_local) : A ) | | , M ( (&A == &B) ? (*M_local) : A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
|
| ~partial_unwrap_check_Mat_fixed() | | ~partial_unwrap_check_fixed() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(M_local) { delete M_local; } | | if(M_local) { delete M_local; } | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename T1, bool condition> | | template<typename T1, bool condition> | |
| struct partial_unwrap_check_redirect {}; | | struct partial_unwrap_check_redirect {}; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_redirect<T1, false> { typedef partial_unwrap_ch
eck_default<T1> result; }; | | struct partial_unwrap_check_redirect<T1, false> { typedef partial_unwrap_ch
eck_default<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_redirect<T1, true> { typedef partial_unwrap_ch
eck_Mat_fixed<T1> result; }; | | struct partial_unwrap_check_redirect<T1, true> { typedef partial_unwrap_ch
eck_fixed<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class partial_unwrap_check : public partial_unwrap_check_redirect<T1, is_Ma
t_fixed<T1>::value >::result | | struct partial_unwrap_check : public partial_unwrap_check_redirect<T1, is_M
at_fixed<T1>::value >::result | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| public: | | | |
| inline partial_unwrap_check(const T1& A, const Mat<eT>& B) | | inline partial_unwrap_check(const T1& A, const Mat<eT>& B) | |
| : partial_unwrap_check_redirect< T1, is_Mat_fixed<T1>::value >::result(
A, B) | | : partial_unwrap_check_redirect< T1, is_Mat_fixed<T1>::value >::result(
A, B) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Mat<eT> > | | struct partial_unwrap_check< Mat<eT> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Mat<eT>& A, const Mat<eT>& B) | | partial_unwrap_check(const Mat<eT>& A, const Mat<eT>& B) | |
| : M_local ( (&A == &B) ? new Mat<eT>(A) : 0 ) | | : M_local ( (&A == &B) ? new Mat<eT>(A) : 0 ) | |
| , M ( (&A == &B) ? (*M_local) : A ) | | , M ( (&A == &B) ? (*M_local) : A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| ~partial_unwrap_check() | | ~partial_unwrap_check() | |
| | | | |
| skipping to change at line 997 | | skipping to change at line 1269 | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Row<eT> > | | struct partial_unwrap_check< Row<eT> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Row<eT>& A, const Mat<eT>& B) | | partial_unwrap_check(const Row<eT>& A, const Mat<eT>& B) | |
| : M_local ( (&A == &B) ? new Mat<eT>(A) : 0 ) | | : M_local ( (&A == &B) ? new Mat<eT>(A) : 0 ) | |
| , M ( (&A == &B) ? (*M_local) : A ) | | , M ( (&A == &B) ? (*M_local) : A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| ~partial_unwrap_check() | | ~partial_unwrap_check() | |
| | | | |
| skipping to change at line 1028 | | skipping to change at line 1298 | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Col<eT> > | | struct partial_unwrap_check< Col<eT> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Col<eT>& A, const Mat<eT>& B) | | partial_unwrap_check(const Col<eT>& A, const Mat<eT>& B) | |
| : M_local ( (&A == &B) ? new Mat<eT>(A) : 0 ) | | : M_local ( (&A == &B) ? new Mat<eT>(A) : 0 ) | |
| , M ( (&A == &B) ? (*M_local) : A ) | | , M ( (&A == &B) ? (*M_local) : A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| ~partial_unwrap_check() | | ~partial_unwrap_check() | |
| | | | |
| skipping to change at line 1058 | | skipping to change at line 1326 | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
|
| | | // NOTE: we can get away with this shortcut as the partial_unwrap_check cla | |
| | | ss is only used by the glue_times class, | |
| | | // NOTE: which relies on partial_unwrap_check to check for aliasing | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< subview_col<eT> > | | struct partial_unwrap_check< subview_col<eT> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const subview_col<eT>& A, const Mat<eT>& B) | | partial_unwrap_check(const subview_col<eT>& A, const Mat<eT>& B) | |
|
| : M( const_cast<eT*>( A.colptr(0) ), A.n_rows, 1, (&(A.m) == &B), false | | : M ( const_cast<eT*>( A.colptr(0) ), A.n_rows, 1, (&(A.m) == &B), fal | |
| ) | | se ) | |
| | | //, ref( A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT> M; | | const Mat<eT> M; | |
|
| | | | |
| | | //// prevents the compiler from potentially deleting the subview object b | |
| | | efore we're done with it | |
| | | //const subview_col<eT>& ref; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| struct partial_unwrap_check_htrans_default | | struct partial_unwrap_check_htrans_default | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline partial_unwrap_check_htrans_default(const Op<T1, op_htrans>& A, co | | inline | |
| nst Mat<eT>&) | | partial_unwrap_check_htrans_default(const Op<T1, op_htrans>& A, const Mat | |
| | | <eT>&) | |
| : M(A.m) | | : M(A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT> M; | | const Mat<eT> M; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_htrans_Mat_fixed | | struct partial_unwrap_check_htrans_fixed | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline explicit partial_unwrap_check_htrans_Mat_fixed(const Op<T1, op_htr | | inline explicit | |
| ans>& A, const Mat<eT>& B) | | partial_unwrap_check_htrans_fixed(const Op<T1, op_htrans>& A, const Mat<e | |
| | | T>& B) | |
| : M_local( (&(A.m) == &B) ? new Mat<eT>(A.m) : 0 ) | | : M_local( (&(A.m) == &B) ? new Mat<eT>(A.m) : 0 ) | |
| , M ( (&(A.m) == &B) ? (*M_local) : A.m ) | | , M ( (&(A.m) == &B) ? (*M_local) : A.m ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
|
| ~partial_unwrap_check_htrans_Mat_fixed() | | ~partial_unwrap_check_htrans_fixed() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(M_local) { delete M_local; } | | if(M_local) { delete M_local; } | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename T1, bool condition> | | template<typename T1, bool condition> | |
| struct partial_unwrap_check_htrans_redirect {}; | | struct partial_unwrap_check_htrans_redirect {}; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_htrans_redirect<T1, false> { typedef partial_un
wrap_check_htrans_default<T1> result; }; | | struct partial_unwrap_check_htrans_redirect<T1, false> { typedef partial_un
wrap_check_htrans_default<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_htrans_redirect<T1, true> { typedef partial_un
wrap_check_htrans_Mat_fixed<T1> result; }; | | struct partial_unwrap_check_htrans_redirect<T1, true> { typedef partial_un
wrap_check_htrans_fixed<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class partial_unwrap_check< Op<T1, op_htrans> > : public partial_unwrap_che
ck_htrans_redirect<T1, is_Mat_fixed<T1>::value >::result | | struct partial_unwrap_check< Op<T1, op_htrans> > : public partial_unwrap_ch
eck_htrans_redirect<T1, is_Mat_fixed<T1>::value >::result | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| public: | | | |
| inline partial_unwrap_check(const Op<T1, op_htrans>& A, const Mat<eT>& B) | | inline partial_unwrap_check(const Op<T1, op_htrans>& A, const Mat<eT>& B) | |
| : partial_unwrap_check_htrans_redirect< T1, is_Mat_fixed<T1>::value >::
result(A, B) | | : partial_unwrap_check_htrans_redirect< T1, is_Mat_fixed<T1>::value >::
result(A, B) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Op< Mat<eT>, op_htrans> > | | struct partial_unwrap_check< Op< Mat<eT>, op_htrans> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Op< Mat<eT>, op_htrans>& A, const Mat<eT>& B) | | partial_unwrap_check(const Op< Mat<eT>, op_htrans>& A, const Mat<eT>& B) | |
| : M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | | : M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | |
| , M ( (&A.m == &B) ? (*M_local) : A.m ) | | , M ( (&A.m == &B) ? (*M_local) : A.m ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| ~partial_unwrap_check() | | ~partial_unwrap_check() | |
| | | | |
| skipping to change at line 1179 | | skipping to change at line 1450 | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Op< Row<eT>, op_htrans> > | | struct partial_unwrap_check< Op< Row<eT>, op_htrans> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Op< Row<eT>, op_htrans>& A, const Mat<eT>& B) | | partial_unwrap_check(const Op< Row<eT>, op_htrans>& A, const Mat<eT>& B) | |
| : M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | | : M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | |
| , M ( (&A.m == &B) ? (*M_local) : A.m ) | | , M ( (&A.m == &B) ? (*M_local) : A.m ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| ~partial_unwrap_check() | | ~partial_unwrap_check() | |
| | | | |
| skipping to change at line 1210 | | skipping to change at line 1479 | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Op< Col<eT>, op_htrans> > | | struct partial_unwrap_check< Op< Col<eT>, op_htrans> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Op< Col<eT>, op_htrans>& A, const Mat<eT>& B) | | partial_unwrap_check(const Op< Col<eT>, op_htrans>& A, const Mat<eT>& B) | |
| : M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | | : M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | |
| , M ( (&A.m == &B) ? (*M_local) : A.m ) | | , M ( (&A.m == &B) ? (*M_local) : A.m ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| ~partial_unwrap_check() | | ~partial_unwrap_check() | |
| | | | |
| skipping to change at line 1240 | | skipping to change at line 1507 | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| // the order below is important | | // the order below is important | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
|
| | | // NOTE: we can get away with this shortcut as the partial_unwrap_check cla | |
| | | ss is only used by the glue_times class, | |
| | | // NOTE: which relies on partial_unwrap_check to check for aliasing | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Op< subview_col<eT>, op_htrans> > | | struct partial_unwrap_check< Op< subview_col<eT>, op_htrans> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Op< subview_col<eT>, op_htrans>& A, const Mat<
eT>& B) | | partial_unwrap_check(const Op< subview_col<eT>, op_htrans>& A, const Mat<
eT>& B) | |
|
| : M( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, (&(A.m.m) == &B), | | : M ( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, (&(A.m.m) == &B | |
| false ) | | ), false ) | |
| | | //, ref( A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return eT(1); } | | arma_hot arma_inline eT get_val() const { return eT(1); } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = false; | | static const bool do_times = false; | |
| | | | |
| const Mat<eT> M; | | const Mat<eT> M; | |
|
| | | | |
| | | //// prevents the compiler from potentially deleting the subview object b | |
| | | efore we're done with it | |
| | | //const Op< subview_col<eT>, op_htrans>& ref; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| struct partial_unwrap_check_htrans2_default | | struct partial_unwrap_check_htrans2_default | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline partial_unwrap_check_htrans2_default(const Op<T1, op_htrans2>& A, | | inline | |
| const Mat<eT>&) | | partial_unwrap_check_htrans2_default(const Op<T1, op_htrans2>& A, const M | |
| | | at<eT>&) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.m) | | , M (A.m) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return val; } | | arma_hot arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT> M; | | const Mat<eT> M; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_htrans2_Mat_fixed | | struct partial_unwrap_check_htrans2_fixed | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline explicit partial_unwrap_check_htrans2_Mat_fixed(const Op<T1, op_ht | | inline explicit | |
| rans2>& A, const Mat<eT>& B) | | partial_unwrap_check_htrans2_fixed(const Op<T1, op_htrans2>& A, const Mat | |
| | | <eT>& B) | |
| : val (A.aux) | | : val (A.aux) | |
| , M_local( (&(A.m) == &B) ? new Mat<eT>(A.m) : 0 ) | | , M_local( (&(A.m) == &B) ? new Mat<eT>(A.m) : 0 ) | |
| , M ( (&(A.m) == &B) ? (*M_local) : A.m ) | | , M ( (&(A.m) == &B) ? (*M_local) : A.m ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
|
| ~partial_unwrap_check_htrans2_Mat_fixed() | | ~partial_unwrap_check_htrans2_fixed() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(M_local) { delete M_local; } | | if(M_local) { delete M_local; } | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return val; } | | arma_hot arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename T1, bool condition> | | template<typename T1, bool condition> | |
| struct partial_unwrap_check_htrans2_redirect {}; | | struct partial_unwrap_check_htrans2_redirect {}; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_htrans2_redirect<T1, false> { typedef partial_u
nwrap_check_htrans2_default<T1> result; }; | | struct partial_unwrap_check_htrans2_redirect<T1, false> { typedef partial_u
nwrap_check_htrans2_default<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_htrans2_redirect<T1, true> { typedef partial_u
nwrap_check_htrans2_Mat_fixed<T1> result; }; | | struct partial_unwrap_check_htrans2_redirect<T1, true> { typedef partial_u
nwrap_check_htrans2_fixed<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class partial_unwrap_check< Op<T1, op_htrans2> > : public partial_unwrap_ch
eck_htrans2_redirect<T1, is_Mat_fixed<T1>::value >::result | | struct partial_unwrap_check< Op<T1, op_htrans2> > : public partial_unwrap_c
heck_htrans2_redirect<T1, is_Mat_fixed<T1>::value >::result | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| public: | | | |
| inline partial_unwrap_check(const Op<T1, op_htrans2>& A, const Mat<eT>& B
) | | inline partial_unwrap_check(const Op<T1, op_htrans2>& A, const Mat<eT>& B
) | |
| : partial_unwrap_check_htrans2_redirect< T1, is_Mat_fixed<T1>::value >:
:result(A, B) | | : partial_unwrap_check_htrans2_redirect< T1, is_Mat_fixed<T1>::value >:
:result(A, B) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Op< Mat<eT>, op_htrans2> > | | struct partial_unwrap_check< Op< Mat<eT>, op_htrans2> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Op< Mat<eT>, op_htrans2>& A, const Mat<eT>& B) | | partial_unwrap_check(const Op< Mat<eT>, op_htrans2>& A, const Mat<eT>& B) | |
| : val (A.aux) | | : val (A.aux) | |
| , M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | | , M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | |
| , M ( (&A.m == &B) ? (*M_local) : A.m ) | | , M ( (&A.m == &B) ? (*M_local) : A.m ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| | | | |
| skipping to change at line 1367 | | skipping to change at line 1637 | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| // the order below is important | | // the order below is important | |
| const eT val; | | const eT val; | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Op< Row<eT>, op_htrans2> > | | struct partial_unwrap_check< Op< Row<eT>, op_htrans2> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Op< Row<eT>, op_htrans2>& A, const Mat<eT>& B) | | partial_unwrap_check(const Op< Row<eT>, op_htrans2>& A, const Mat<eT>& B) | |
| : val (A.aux) | | : val (A.aux) | |
| , M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | | , M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | |
| , M ( (&A.m == &B) ? (*M_local) : A.m ) | | , M ( (&A.m == &B) ? (*M_local) : A.m ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| | | | |
| skipping to change at line 1400 | | skipping to change at line 1668 | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| // the order below is important | | // the order below is important | |
| const eT val; | | const eT val; | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Op< Col<eT>, op_htrans2> > | | struct partial_unwrap_check< Op< Col<eT>, op_htrans2> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Op< Col<eT>, op_htrans2>& A, const Mat<eT>& B) | | partial_unwrap_check(const Op< Col<eT>, op_htrans2>& A, const Mat<eT>& B) | |
| : val (A.aux) | | : val (A.aux) | |
| , M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | | , M_local ( (&A.m == &B) ? new Mat<eT>(A.m) : 0 ) | |
| , M ( (&A.m == &B) ? (*M_local) : A.m ) | | , M ( (&A.m == &B) ? (*M_local) : A.m ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| | | | |
| skipping to change at line 1432 | | skipping to change at line 1698 | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| // the order below is important | | // the order below is important | |
| const eT val; | | const eT val; | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
|
| | | // NOTE: we can get away with this shortcut as the partial_unwrap_check cla | |
| | | ss is only used by the glue_times class, | |
| | | // NOTE: which relies on partial_unwrap_check to check for aliasing | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< Op< subview_col<eT>, op_htrans2> > | | struct partial_unwrap_check< Op< subview_col<eT>, op_htrans2> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const Op< subview_col<eT>, op_htrans2>& A, const Mat
<eT>& B) | | partial_unwrap_check(const Op< subview_col<eT>, op_htrans2>& A, const Mat
<eT>& B) | |
| : val( A.aux ) | | : val( A.aux ) | |
| , M ( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, (&(A.m.m) == &B
), false ) | | , M ( const_cast<eT*>( A.m.colptr(0) ), A.m.n_rows, 1, (&(A.m.m) == &B
), false ) | |
|
| | | //, ref( A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return val; } | | arma_hot arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = true; | | static const bool do_trans = true; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT> M; | | const Mat<eT> M; | |
|
| | | | |
| | | //// prevents the compiler from potentially deleting the subview object b | |
| | | efore we're done with it | |
| | | //const Op< subview_col<eT>, op_htrans2>& ref; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
| struct partial_unwrap_check_scalar_times_default | | struct partial_unwrap_check_scalar_times_default | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline partial_unwrap_check_scalar_times_default(const eOp<T1, eop_scalar | | inline | |
| _times>& A, const Mat<eT>&) | | partial_unwrap_check_scalar_times_default(const eOp<T1, eop_scalar_times> | |
| | | & A, const Mat<eT>&) | |
| : val(A.aux) | | : val(A.aux) | |
| , M (A.P.Q) | | , M (A.P.Q) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return val; } | | arma_hot arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT> M; | | const Mat<eT> M; | |
| }; | | }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_scalar_times_Mat_fixed | | struct partial_unwrap_check_scalar_times_fixed | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| inline explicit partial_unwrap_check_scalar_times_Mat_fixed(const eOp<T1, | | inline explicit | |
| eop_scalar_times>& A, const Mat<eT>& B) | | partial_unwrap_check_scalar_times_fixed(const eOp<T1, eop_scalar_times>& | |
| | | A, const Mat<eT>& B) | |
| : val ( A.aux ) | | : val ( A.aux ) | |
| , M_local( (&(A.P.Q) == &B) ? new Mat<eT>(A.P.Q) : 0 ) | | , M_local( (&(A.P.Q) == &B) ? new Mat<eT>(A.P.Q) : 0 ) | |
| , M ( (&(A.P.Q) == &B) ? (*M_local) : A.P.Q ) | | , M ( (&(A.P.Q) == &B) ? (*M_local) : A.P.Q ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
|
| ~partial_unwrap_check_scalar_times_Mat_fixed() | | ~partial_unwrap_check_scalar_times_fixed() | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| | | | |
| if(M_local) { delete M_local; } | | if(M_local) { delete M_local; } | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return val; } | | arma_hot arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename T1, bool condition> | | template<typename T1, bool condition> | |
| struct partial_unwrap_check_scalar_times_redirect {}; | | struct partial_unwrap_check_scalar_times_redirect {}; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_scalar_times_redirect<T1, false> { typedef part
ial_unwrap_check_scalar_times_default<T1> result; }; | | struct partial_unwrap_check_scalar_times_redirect<T1, false> { typedef part
ial_unwrap_check_scalar_times_default<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| struct partial_unwrap_check_scalar_times_redirect<T1, true> { typedef part
ial_unwrap_check_scalar_times_Mat_fixed<T1> result; }; | | struct partial_unwrap_check_scalar_times_redirect<T1, true> { typedef part
ial_unwrap_check_scalar_times_fixed<T1> result; }; | |
| | | | |
| template<typename T1> | | template<typename T1> | |
|
| class partial_unwrap_check< eOp<T1, eop_scalar_times> > : public partial_un
wrap_check_scalar_times_redirect<T1, is_Mat_fixed<T1>::value >::result | | struct partial_unwrap_check< eOp<T1, eop_scalar_times> > : public partial_u
nwrap_check_scalar_times_redirect<T1, is_Mat_fixed<T1>::value >::result | |
| { | | { | |
| typedef typename T1::elem_type eT; | | typedef typename T1::elem_type eT; | |
| | | | |
|
| public: | | | |
| inline partial_unwrap_check(const eOp<T1, eop_scalar_times>& A, const Mat
<eT>& B) | | inline partial_unwrap_check(const eOp<T1, eop_scalar_times>& A, const Mat
<eT>& B) | |
| : partial_unwrap_check_scalar_times_redirect< T1, is_Mat_fixed<T1>::val
ue >::result(A, B) | | : partial_unwrap_check_scalar_times_redirect< T1, is_Mat_fixed<T1>::val
ue >::result(A, B) | |
| { | | { | |
| } | | } | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< eOp<Mat<eT>, eop_scalar_times> > | | struct partial_unwrap_check< eOp<Mat<eT>, eop_scalar_times> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const eOp<Mat<eT>,eop_scalar_times>& A, const Mat<eT
>& B) | | partial_unwrap_check(const eOp<Mat<eT>,eop_scalar_times>& A, const Mat<eT
>& B) | |
| : val (A.aux) | | : val (A.aux) | |
| , M_local( (&(A.P.Q) == &B) ? new Mat<eT>(A.P.Q) : 0 ) | | , M_local( (&(A.P.Q) == &B) ? new Mat<eT>(A.P.Q) : 0 ) | |
| , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) | | , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| | | | |
| skipping to change at line 1560 | | skipping to change at line 1829 | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< eOp<Row<eT>, eop_scalar_times> > | | struct partial_unwrap_check< eOp<Row<eT>, eop_scalar_times> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const eOp<Row<eT>,eop_scalar_times>& A, const Mat<eT
>& B) | | partial_unwrap_check(const eOp<Row<eT>,eop_scalar_times>& A, const Mat<eT
>& B) | |
| : val(A.aux) | | : val(A.aux) | |
| , M_local( (&(A.P.Q) == &B) ? new Mat<eT>(A.P.Q) : 0 ) | | , M_local( (&(A.P.Q) == &B) ? new Mat<eT>(A.P.Q) : 0 ) | |
| , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) | | , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| | | | |
| skipping to change at line 1592 | | skipping to change at line 1859 | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< eOp<Col<eT>, eop_scalar_times> > | | struct partial_unwrap_check< eOp<Col<eT>, eop_scalar_times> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const eOp<Col<eT>,eop_scalar_times>& A, const Mat<eT
>& B) | | partial_unwrap_check(const eOp<Col<eT>,eop_scalar_times>& A, const Mat<eT
>& B) | |
| : val ( A.aux ) | | : val ( A.aux ) | |
| , M_local( (&(A.P.Q) == &B) ? new Mat<eT>(A.P.Q) : 0 ) | | , M_local( (&(A.P.Q) == &B) ? new Mat<eT>(A.P.Q) : 0 ) | |
| , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) | | , M ( (&(A.P.Q) == &B) ? *M_local : A.P.Q ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| inline | | inline | |
| | | | |
| skipping to change at line 1623 | | skipping to change at line 1888 | |
| arma_hot arma_inline eT get_val() const { return val; } | | arma_hot arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT>* M_local; | | const Mat<eT>* M_local; | |
| const Mat<eT>& M; | | const Mat<eT>& M; | |
| }; | | }; | |
| | | | |
|
| | | // NOTE: we can get away with this shortcut as the partial_unwrap_check cla | |
| | | ss is only used by the glue_times class, | |
| | | // NOTE: which relies on partial_unwrap_check to check for aliasing | |
| template<typename eT> | | template<typename eT> | |
|
| class partial_unwrap_check< eOp<subview_col<eT>, eop_scalar_times> > | | struct partial_unwrap_check< eOp<subview_col<eT>, eop_scalar_times> > | |
| { | | { | |
|
| public: | | | |
| | | | |
| arma_hot inline | | arma_hot inline | |
| partial_unwrap_check(const eOp<subview_col<eT>,eop_scalar_times>& A, cons
t Mat<eT>& B) | | partial_unwrap_check(const eOp<subview_col<eT>,eop_scalar_times>& A, cons
t Mat<eT>& B) | |
| : val( A.aux ) | | : val( A.aux ) | |
| , M ( const_cast<eT*>( A.P.Q.colptr(0) ), A.P.Q.n_rows, 1, (&(A.P.Q.m)
== &B), false ) | | , M ( const_cast<eT*>( A.P.Q.colptr(0) ), A.P.Q.n_rows, 1, (&(A.P.Q.m)
== &B), false ) | |
|
| | | //, ref( A ) | |
| { | | { | |
| arma_extra_debug_sigprint(); | | arma_extra_debug_sigprint(); | |
| } | | } | |
| | | | |
| arma_hot arma_inline eT get_val() const { return val; } | | arma_hot arma_inline eT get_val() const { return val; } | |
| | | | |
| static const bool do_trans = false; | | static const bool do_trans = false; | |
| static const bool do_times = true; | | static const bool do_times = true; | |
| | | | |
| const eT val; | | const eT val; | |
| const Mat<eT> M; | | const Mat<eT> M; | |
|
| | | | |
| | | //// prevents the compiler from potentially deleting the subview object b | |
| | | efore we're done with it | |
| | | //const eOp<subview_col<eT>,eop_scalar_times>& ref; | |
| }; | | }; | |
| | | | |
| //! @} | | //! @} | |
| | | | |
End of changes. 197 change blocks. |
| 233 lines changed or deleted | | 524 lines changed or added | |
|