max@0: // Copyright (C) 2008-2011 NICTA (www.nicta.com.au) max@0: // Copyright (C) 2008-2011 Conrad Sanderson max@0: // Copyright (C) 2011 James Sanders max@0: // max@0: // This file is part of the Armadillo C++ library. max@0: // It is provided without any warranty of fitness max@0: // for any purpose. You can redistribute this file max@0: // and/or modify it under the terms of the GNU max@0: // Lesser General Public License (LGPL) as published max@0: // by the Free Software Foundation, either version 3 max@0: // of the License or (at your option) any later version. max@0: // (see http://www.opensource.org/licenses for more info) max@0: max@0: max@0: //! \addtogroup subview max@0: //! @{ max@0: max@0: max@0: template max@0: inline max@0: subview::~subview() max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: template max@0: inline max@0: subview::subview(const Mat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols) max@0: : m(in_m) max@0: , m_ptr(0) max@0: , aux_row1(in_row1) max@0: , aux_col1(in_col1) max@0: , n_rows(in_n_rows) max@0: , n_cols(in_n_cols) max@0: , n_elem(in_n_rows*in_n_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview::subview(Mat& in_m, const uword in_row1, const uword in_col1, const uword in_n_rows, const uword in_n_cols) max@0: : m(in_m) max@0: , m_ptr(&in_m) max@0: , aux_row1(in_row1) max@0: , aux_col1(in_col1) max@0: , n_rows(in_n_rows) max@0: , n_cols(in_n_cols) max@0: , n_elem(in_n_rows*in_n_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview::operator+= (const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword local_n_cols = n_cols; max@0: const uword local_n_rows = n_rows; max@0: max@0: if(local_n_rows == 1) max@0: { max@0: Mat& X = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: const uword end_col_plus1 = start_col + local_n_cols; max@0: max@0: uword i,j; max@0: max@0: for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2) max@0: { max@0: X.at(row, i) += val; max@0: X.at(row, j) += val; max@0: } max@0: max@0: if(i < end_col_plus1) max@0: { max@0: X.at(row, i) += val; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::operator-= (const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword local_n_cols = n_cols; max@0: const uword local_n_rows = n_rows; max@0: max@0: if(local_n_rows == 1) max@0: { max@0: Mat& X = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: const uword end_col_plus1 = start_col + local_n_cols; max@0: max@0: uword i,j; max@0: max@0: for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2) max@0: { max@0: X.at(row, i) -= val; max@0: X.at(row, j) -= val; max@0: } max@0: max@0: if(i < end_col_plus1) max@0: { max@0: X.at(row, i) -= val; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::operator*= (const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword local_n_cols = n_cols; max@0: const uword local_n_rows = n_rows; max@0: max@0: if(local_n_rows == 1) max@0: { max@0: Mat& X = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: const uword end_col_plus1 = start_col + local_n_cols; max@0: max@0: uword i,j; max@0: max@0: for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2) max@0: { max@0: X.at(row, i) *= val; max@0: X.at(row, j) *= val; max@0: } max@0: max@0: if(i < end_col_plus1) max@0: { max@0: X.at(row, i) *= val; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::operator/= (const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword local_n_cols = n_cols; max@0: const uword local_n_rows = n_rows; max@0: max@0: if(local_n_rows == 1) max@0: { max@0: Mat& X = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: const uword end_col_plus1 = start_col + local_n_cols; max@0: max@0: uword i,j; max@0: max@0: for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2) max@0: { max@0: X.at(row, i) /= val; max@0: X.at(row, j) /= val; max@0: } max@0: max@0: if(i < end_col_plus1) max@0: { max@0: X.at(row, i) /= val; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: template max@0: inline max@0: void max@0: subview::operator= (const Base& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Proxy P(in.get_ref()); max@0: max@0: subview& t = *this; max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: max@0: arma_debug_assert_same_size(t, P, "insert into submatrix"); max@0: max@0: const bool alias = P.is_alias(t.m); max@0: max@0: arma_extra_debug_warn(alias, "aliasing detected"); max@0: max@0: if( (alias == true) || (is_Mat::stored_type>::value == true) ) max@0: { max@0: const unwrap_check::stored_type> tmp(P.Q, t.m); max@0: const Mat& x = tmp.M; max@0: max@0: if(t_n_rows == 1) max@0: { max@0: const eT* x_mem = x.memptr(); max@0: max@0: Mat& A = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: A.at(row, start_col+i) = x_mem[i]; max@0: A.at(row, start_col+j) = x_mem[j]; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row, start_col+i) = x_mem[i]; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col& A = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,i) : P[i]; max@0: const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,j) : P[j]; max@0: max@0: A.at(row, start_col+i) = tmp1; max@0: A.at(row, start_col+j) = tmp2; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row, start_col+i) = (Proxy::prefer_at_accessor) ? P.at(0,i) : P[i]; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: template max@0: inline max@0: void max@0: subview::operator+= (const Base& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Proxy P(in.get_ref()); max@0: max@0: subview& t = *this; max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: max@0: arma_debug_assert_same_size(t, P, "addition"); max@0: max@0: const bool alias = P.is_alias(t.m); max@0: max@0: arma_extra_debug_warn(alias, "aliasing detected"); max@0: max@0: if( (alias == true) || (is_Mat::stored_type>::value == true) ) max@0: { max@0: const unwrap_check::stored_type> tmp(P.Q, t.m); max@0: const Mat& x = tmp.M; max@0: max@0: if(t_n_rows == 1) max@0: { max@0: const eT* x_mem = x.memptr(); max@0: max@0: Mat& A = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: A.at(row, start_col+i) += x_mem[i]; max@0: A.at(row, start_col+j) += x_mem[j]; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row, start_col+i) += x_mem[i]; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col& A = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,i) : P[i]; max@0: const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,j) : P[j]; max@0: max@0: A.at(row, start_col+i) += tmp1; max@0: A.at(row, start_col+j) += tmp2; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row, start_col+i) += (Proxy::prefer_at_accessor) ? P.at(0,i) : P[i]; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: template max@0: inline max@0: void max@0: subview::operator-= (const Base& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Proxy P(in.get_ref()); max@0: max@0: subview& t = *this; max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: max@0: arma_debug_assert_same_size(t, P, "subtraction"); max@0: max@0: const bool alias = P.is_alias(t.m); max@0: max@0: if( (alias == true) || (is_Mat::stored_type>::value == true) ) max@0: { max@0: const unwrap_check::stored_type> tmp(P.Q, t.m); max@0: const Mat& x = tmp.M; max@0: max@0: if(t_n_rows == 1) max@0: { max@0: const eT* x_mem = x.memptr(); max@0: max@0: Mat& A = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: A.at(row, start_col+i) -= x_mem[i]; max@0: A.at(row, start_col+j) -= x_mem[j]; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row, start_col+i) -= x_mem[i]; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col& A = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,i) : P[i]; max@0: const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,j) : P[j]; max@0: max@0: A.at(row, start_col+i) -= tmp1; max@0: A.at(row, start_col+j) -= tmp2; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row, start_col+i) -= (Proxy::prefer_at_accessor) ? P.at(0,i) : P[i]; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: template max@0: inline max@0: void max@0: subview::operator%= (const Base& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Proxy P(in.get_ref()); max@0: max@0: subview& t = *this; max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: max@0: arma_debug_assert_same_size(t, P, "element-wise multiplication"); max@0: max@0: const bool alias = P.is_alias(t.m); max@0: max@0: arma_extra_debug_warn(alias, "aliasing detected"); max@0: max@0: if( (alias == true) || (is_Mat::stored_type>::value == true) ) max@0: { max@0: const unwrap_check::stored_type> tmp(P.Q, t.m); max@0: const Mat& x = tmp.M; max@0: max@0: if(t_n_rows == 1) max@0: { max@0: const eT* x_mem = x.memptr(); max@0: max@0: Mat& A = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: A.at(row, start_col+i) *= x_mem[i]; max@0: A.at(row, start_col+j) *= x_mem[j]; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row, start_col+i) *= x_mem[i]; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col& A = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,i) : P[i]; max@0: const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,j) : P[j]; max@0: max@0: A.at(row, start_col+i) *= tmp1; max@0: A.at(row, start_col+j) *= tmp2; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row, start_col+i) *= (Proxy::prefer_at_accessor) ? P.at(0,i) : P[i]; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: template max@0: inline max@0: void max@0: subview::operator/= (const Base& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const Proxy P(in.get_ref()); max@0: max@0: subview& t = *this; max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: max@0: arma_debug_assert_same_size(t, P, "element-wise division"); max@0: max@0: const bool alias = P.is_alias(t.m); max@0: max@0: arma_extra_debug_warn(alias, "aliasing detected"); max@0: max@0: if( (alias == true) || (is_Mat::stored_type>::value == true) ) max@0: { max@0: const unwrap_check::stored_type> tmp(P.Q, t.m); max@0: const Mat& x = tmp.M; max@0: max@0: if(t_n_rows == 1) max@0: { max@0: const eT* x_mem = x.memptr(); max@0: max@0: Mat& A = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: A.at(row, start_col+i) /= x_mem[i]; max@0: A.at(row, start_col+j) /= x_mem[j]; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row, start_col+i) /= x_mem[i]; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col& A = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = (Proxy::prefer_at_accessor) ? P.at(0,i) : P[i]; max@0: const eT tmp2 = (Proxy::prefer_at_accessor) ? P.at(0,j) : P[j]; max@0: max@0: A.at(row, start_col+i) /= tmp1; max@0: A.at(row, start_col+j) /= tmp2; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row, start_col+i) /= (Proxy::prefer_at_accessor) ? P.at(0,i) : P[i]; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::operator= (const subview& x_in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool overlap = check_overlap(x_in); max@0: max@0: Mat* tmp_mat = overlap ? new Mat(x_in.m) : 0; max@0: const subview* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; max@0: const subview& x = overlap ? (*tmp_subview) : x_in; max@0: max@0: subview& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "insert into submatrix"); max@0: max@0: const uword t_n_cols = t.n_cols; max@0: const uword t_n_rows = t.n_rows; max@0: max@0: if(t_n_rows == 1) max@0: { max@0: Mat& A = *(t.m_ptr); max@0: const Mat& B = x.m; max@0: max@0: const uword row_A = t.aux_row1; max@0: const uword row_B = x.aux_row1; max@0: max@0: const uword start_col_A = t.aux_col1; max@0: const uword start_col_B = x.aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = B.at(row_B, start_col_B + i); max@0: const eT tmp2 = B.at(row_B, start_col_B + j); max@0: max@0: A.at(row_A, start_col_A + i) = tmp1; max@0: A.at(row_A, start_col_A + j) = tmp2; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row_A, start_col_A + i) = B.at(row_B, start_col_B + i); max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::operator+= (const subview& x_in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool overlap = check_overlap(x_in); max@0: max@0: Mat* tmp_mat = overlap ? new Mat(x_in.m) : 0; max@0: const subview* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; max@0: const subview& x = overlap ? (*tmp_subview) : x_in; max@0: max@0: subview& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "addition"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: max@0: if(t_n_rows == 1) max@0: { max@0: Mat& A = *(t.m_ptr); max@0: const Mat& B = x.m; max@0: max@0: const uword row_A = t.aux_row1; max@0: const uword row_B = x.aux_row1; max@0: max@0: const uword start_col_A = t.aux_col1; max@0: const uword start_col_B = x.aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = B.at(row_B, start_col_B + i); max@0: const eT tmp2 = B.at(row_B, start_col_B + j); max@0: max@0: A.at(row_A, start_col_A + i) += tmp1; max@0: A.at(row_A, start_col_A + j) += tmp2; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row_A, start_col_A + i) += B.at(row_B, start_col_B + i); max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::operator-= (const subview& x_in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool overlap = check_overlap(x_in); max@0: max@0: Mat* tmp_mat = overlap ? new Mat(x_in.m) : 0; max@0: const subview* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; max@0: const subview& x = overlap ? (*tmp_subview) : x_in; max@0: max@0: subview& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "subtraction"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: max@0: if(t_n_rows == 1) max@0: { max@0: Mat& A = *(t.m_ptr); max@0: const Mat& B = x.m; max@0: max@0: const uword row_A = t.aux_row1; max@0: const uword row_B = x.aux_row1; max@0: max@0: const uword start_col_A = t.aux_col1; max@0: const uword start_col_B = x.aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = B.at(row_B, start_col_B + i); max@0: const eT tmp2 = B.at(row_B, start_col_B + j); max@0: max@0: A.at(row_A, start_col_A + i) -= tmp1; max@0: A.at(row_A, start_col_A + j) -= tmp2; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row_A, start_col_A + i) -= B.at(row_B, start_col_B + i); max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::operator%= (const subview& x_in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool overlap = check_overlap(x_in); max@0: max@0: Mat* tmp_mat = overlap ? new Mat(x_in.m) : 0; max@0: const subview* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; max@0: const subview& x = overlap ? (*tmp_subview) : x_in; max@0: max@0: subview& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "element-wise multiplication"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: max@0: if(t_n_rows == 1) max@0: { max@0: Mat& A = *(t.m_ptr); max@0: const Mat& B = x.m; max@0: max@0: const uword row_A = t.aux_row1; max@0: const uword row_B = x.aux_row1; max@0: max@0: const uword start_col_A = t.aux_col1; max@0: const uword start_col_B = x.aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = B.at(row_B, start_col_B + i); max@0: const eT tmp2 = B.at(row_B, start_col_B + j); max@0: max@0: A.at(row_A, start_col_A + i) *= tmp1; max@0: A.at(row_A, start_col_A + j) *= tmp2; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row_A, start_col_A + i) *= B.at(row_B, start_col_B + i); max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::operator/= (const subview& x_in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool overlap = check_overlap(x_in); max@0: max@0: Mat* tmp_mat = overlap ? new Mat(x_in.m) : 0; max@0: const subview* tmp_subview = overlap ? new subview(*tmp_mat, x_in.aux_row1, x_in.aux_col1, x_in.n_rows, x_in.n_cols) : 0; max@0: const subview& x = overlap ? (*tmp_subview) : x_in; max@0: max@0: subview& t = *this; max@0: max@0: arma_debug_assert_same_size(t, x, "element-wise division"); max@0: max@0: const uword t_n_rows = t.n_rows; max@0: const uword t_n_cols = t.n_cols; max@0: max@0: if(t_n_rows == 1) max@0: { max@0: Mat& A = *(t.m_ptr); max@0: const Mat& B = x.m; max@0: max@0: const uword row_A = t.aux_row1; max@0: const uword row_B = x.aux_row1; max@0: max@0: const uword start_col_A = t.aux_col1; max@0: const uword start_col_B = x.aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < t_n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = B.at(row_B, start_col_B + i); max@0: const eT tmp2 = B.at(row_B, start_col_B + j); max@0: max@0: A.at(row_A, start_col_A + i) /= tmp1; max@0: A.at(row_A, start_col_A + j) /= tmp2; max@0: } max@0: max@0: if(i < t_n_cols) max@0: { max@0: A.at(row_A, start_col_A + i) /= B.at(row_B, start_col_B + i); max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::fill(const eT val) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword local_n_cols = n_cols; max@0: const uword local_n_rows = n_rows; max@0: max@0: if(local_n_rows == 1) max@0: { max@0: Mat& X = (*m_ptr); max@0: max@0: const uword row = aux_row1; max@0: const uword start_col = aux_col1; max@0: const uword end_col_plus1 = start_col + local_n_cols; max@0: max@0: uword i,j; max@0: max@0: for(i=start_col, j=start_col+1; j < end_col_plus1; i+=2, j+=2) max@0: { max@0: X.at(row, i) = val; max@0: X.at(row, j) = val; max@0: } max@0: max@0: if(i < end_col_plus1) max@0: { max@0: X.at(row, i) = val; max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::zeros() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: (*this).fill(eT(0)); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview::ones() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: (*this).fill(eT(1)); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview::eye() max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: fill(eT(0)); max@0: max@0: const uword N = (std::min)(n_rows, n_cols); max@0: max@0: for(uword i=0; i max@0: inline max@0: eT& max@0: subview::operator[](const uword i) max@0: { max@0: const uword in_col = i / n_rows; max@0: const uword in_row = i % n_rows; max@0: max@0: const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return access::rw( (*m_ptr).mem[index] ); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: subview::operator[](const uword i) const max@0: { max@0: const uword in_col = i / n_rows; max@0: const uword in_row = i % n_rows; max@0: max@0: const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return m.mem[index]; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT& max@0: subview::operator()(const uword i) max@0: { max@0: arma_debug_check( (i >= n_elem), "subview::operator(): index out of bounds"); max@0: max@0: const uword in_col = i / n_rows; max@0: const uword in_row = i % n_rows; max@0: max@0: const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return access::rw( (*m_ptr).mem[index] ); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: subview::operator()(const uword i) const max@0: { max@0: arma_debug_check( (i >= n_elem), "subview::operator(): index out of bounds"); max@0: max@0: const uword in_col = i / n_rows; max@0: const uword in_row = i % n_rows; max@0: max@0: const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return m.mem[index]; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT& max@0: subview::operator()(const uword in_row, const uword in_col) max@0: { max@0: arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds"); max@0: max@0: const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return access::rw( (*m_ptr).mem[index] ); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: subview::operator()(const uword in_row, const uword in_col) const max@0: { max@0: arma_debug_check( ((in_row >= n_rows) || (in_col >= n_cols)), "subview::operator(): index out of bounds"); max@0: max@0: const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return m.mem[index]; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT& max@0: subview::at(const uword in_row, const uword in_col) max@0: { max@0: const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return access::rw( (*m_ptr).mem[index] ); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: eT max@0: subview::at(const uword in_row, const uword in_col) const max@0: { max@0: const uword index = (in_col + aux_col1)*m.n_rows + aux_row1 + in_row; max@0: return m.mem[index]; max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: eT* max@0: subview::colptr(const uword in_col) max@0: { max@0: return & access::rw((*m_ptr).mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]); max@0: } max@0: max@0: max@0: max@0: template max@0: arma_inline max@0: const eT* max@0: subview::colptr(const uword in_col) const max@0: { max@0: return & m.mem[ (in_col + aux_col1)*m.n_rows + aux_row1 ]; max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: bool max@0: subview::check_overlap(const subview& x) const max@0: { max@0: const subview& t = *this; max@0: max@0: if(&t.m != &x.m) max@0: { max@0: return false; max@0: } max@0: else max@0: { max@0: if( (t.n_elem == 0) || (x.n_elem == 0) ) max@0: { max@0: return false; max@0: } max@0: else max@0: { max@0: const uword t_row_start = t.aux_row1; max@0: const uword t_row_end_p1 = t_row_start + t.n_rows; max@0: max@0: const uword t_col_start = t.aux_col1; max@0: const uword t_col_end_p1 = t_col_start + t.n_cols; max@0: max@0: max@0: const uword x_row_start = x.aux_row1; max@0: const uword x_row_end_p1 = x_row_start + x.n_rows; max@0: max@0: const uword x_col_start = x.aux_col1; max@0: const uword x_col_end_p1 = x_col_start + x.n_cols; max@0: max@0: max@0: const bool outside_rows = ( (x_row_start >= t_row_end_p1) || (t_row_start >= x_row_end_p1) ); max@0: const bool outside_cols = ( (x_col_start >= t_col_end_p1) || (t_col_start >= x_col_end_p1) ); max@0: max@0: return ( (outside_rows == false) && (outside_cols == false) ); max@0: } max@0: } max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: bool max@0: subview::is_vec() const max@0: { max@0: return ( (n_rows == 1) || (n_cols == 1) ); max@0: } max@0: max@0: max@0: max@0: //! X = Y.submat(...) max@0: template max@0: inline max@0: void max@0: subview::extract(Mat& out, const subview& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: // NOTE: we're assuming that the matrix has already been set to the correct size and there is no aliasing; max@0: // size setting and alias checking is done by either the Mat contructor or operator=() max@0: max@0: const uword n_rows = in.n_rows; // number of rows in the subview max@0: const uword n_cols = in.n_cols; // number of columns in the subview max@0: max@0: arma_extra_debug_print(arma_boost::format("out.n_rows = %d out.n_cols = %d in.m.n_rows = %d in.m.n_cols = %d") % out.n_rows % out.n_cols % in.m.n_rows % in.m.n_cols ); max@0: max@0: max@0: if(in.is_vec() == true) max@0: { max@0: if(n_cols == 1) // a column vector max@0: { max@0: arma_extra_debug_print("subview::extract(): copying col (going across rows)"); max@0: max@0: // in.colptr(0) the first column of the subview, taking into account any row offset max@0: arrayops::copy( out.memptr(), in.colptr(0), n_rows ); max@0: } max@0: else // a row vector (possibly empty) max@0: { max@0: arma_extra_debug_print("subview::extract(): copying row (going across columns)"); max@0: max@0: const Mat& X = in.m; max@0: max@0: eT* out_mem = out.memptr(); max@0: max@0: const uword row = in.aux_row1; max@0: const uword start_col = in.aux_col1; max@0: max@0: uword i,j; max@0: max@0: for(i=0, j=1; j < n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = X.at(row, start_col+i); max@0: const eT tmp2 = X.at(row, start_col+j); max@0: max@0: out_mem[i] = tmp1; max@0: out_mem[j] = tmp2; max@0: } max@0: max@0: if(i < n_cols) max@0: { max@0: out_mem[i] = X.at(row, start_col+i); max@0: } max@0: } max@0: } max@0: else // general submatrix max@0: { max@0: arma_extra_debug_print("subview::extract(): general submatrix"); max@0: max@0: for(uword col = 0; col max@0: inline max@0: void max@0: subview::plus_inplace(Mat& out, const subview& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(out, in, "addition"); max@0: max@0: const uword n_rows = in.n_rows; max@0: const uword n_cols = in.n_cols; max@0: max@0: if(n_rows == 1) max@0: { max@0: eT* out_mem = out.memptr(); max@0: max@0: const Mat& X = in.m; max@0: max@0: const uword row = in.aux_row1; max@0: const uword start_col = in.aux_col1; max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = X.at(row, start_col+i); max@0: const eT tmp2 = X.at(row, start_col+j); max@0: max@0: out_mem[i] += tmp1; max@0: out_mem[j] += tmp2; max@0: } max@0: max@0: if(i < n_cols) max@0: { max@0: out_mem[i] += X.at(row, start_col+i); max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::minus_inplace(Mat& out, const subview& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(out, in, "subtraction"); max@0: max@0: const uword n_rows = in.n_rows; max@0: const uword n_cols = in.n_cols; max@0: max@0: if(n_rows == 1) max@0: { max@0: eT* out_mem = out.memptr(); max@0: max@0: const Mat& X = in.m; max@0: max@0: const uword row = in.aux_row1; max@0: const uword start_col = in.aux_col1; max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = X.at(row, start_col+i); max@0: const eT tmp2 = X.at(row, start_col+j); max@0: max@0: out_mem[i] -= tmp1; max@0: out_mem[j] -= tmp2; max@0: } max@0: max@0: if(i < n_cols) max@0: { max@0: out_mem[i] -= X.at(row, start_col+i); max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::schur_inplace(Mat& out, const subview& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(out, in, "element-wise multiplication"); max@0: max@0: const uword n_rows = in.n_rows; max@0: const uword n_cols = in.n_cols; max@0: max@0: if(n_rows == 1) max@0: { max@0: eT* out_mem = out.memptr(); max@0: max@0: const Mat& X = in.m; max@0: max@0: const uword row = in.aux_row1; max@0: const uword start_col = in.aux_col1; max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = X.at(row, start_col+i); max@0: const eT tmp2 = X.at(row, start_col+j); max@0: max@0: out_mem[i] *= tmp1; max@0: out_mem[j] *= tmp2; max@0: } max@0: max@0: if(i < n_cols) max@0: { max@0: out_mem[i] *= X.at(row, start_col+i); max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::div_inplace(Mat& out, const subview& in) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_assert_same_size(out, in, "element-wise division"); max@0: max@0: const uword n_rows = in.n_rows; max@0: const uword n_cols = in.n_cols; max@0: max@0: if(n_rows == 1) max@0: { max@0: eT* out_mem = out.memptr(); max@0: max@0: const Mat& X = in.m; max@0: max@0: const uword row = in.aux_row1; max@0: const uword start_col = in.aux_col1; max@0: max@0: uword i,j; max@0: for(i=0, j=1; j < n_cols; i+=2, j+=2) max@0: { max@0: const eT tmp1 = X.at(row, start_col+i); max@0: const eT tmp2 = X.at(row, start_col+j); max@0: max@0: out_mem[i] /= tmp1; max@0: out_mem[j] /= tmp2; max@0: } max@0: max@0: if(i < n_cols) max@0: { max@0: out_mem[i] /= X.at(row, start_col+i); max@0: } max@0: } max@0: else max@0: { max@0: for(uword col=0; col max@0: inline max@0: subview_row max@0: subview::row(const uword row_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( row_num >= n_rows, "subview::row(): out of bounds" ); max@0: max@0: const uword base_row = aux_row1 + row_num; max@0: max@0: return subview_row(*m_ptr, base_row, aux_col1, n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (row vector) max@0: template max@0: inline max@0: const subview_row max@0: subview::row(const uword row_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( row_num >= n_rows, "subview::row(): out of bounds" ); max@0: max@0: const uword base_row = aux_row1 + row_num; max@0: max@0: return subview_row(m, base_row, aux_col1, n_cols); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_row max@0: subview::operator()(const uword row_num, const span& col_span) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool col_all = col_span.whole; max@0: max@0: const uword local_n_cols = n_cols; max@0: max@0: const uword in_col1 = col_all ? 0 : col_span.a; max@0: const uword in_col2 = col_span.b; max@0: const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; max@0: max@0: const uword base_col1 = aux_col1 + in_col1; max@0: const uword base_row = aux_row1 + row_num; max@0: max@0: arma_debug_check max@0: ( max@0: (row_num >= n_rows) max@0: || max@0: ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) max@0: , max@0: "subview::operator(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: return subview_row(*m_ptr, base_row, base_col1, submat_n_cols); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const subview_row max@0: subview::operator()(const uword row_num, const span& col_span) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool col_all = col_span.whole; max@0: max@0: const uword local_n_cols = n_cols; max@0: max@0: const uword in_col1 = col_all ? 0 : col_span.a; max@0: const uword in_col2 = col_span.b; max@0: const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; max@0: max@0: const uword base_col1 = aux_col1 + in_col1; max@0: const uword base_row = aux_row1 + row_num; max@0: max@0: arma_debug_check max@0: ( max@0: (row_num >= n_rows) max@0: || max@0: ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) max@0: , max@0: "subview::operator(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: return subview_row(m, base_row, base_col1, submat_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (column vector) max@0: template max@0: inline max@0: subview_col max@0: subview::col(const uword col_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( col_num >= n_cols, "subview::col(): out of bounds"); max@0: max@0: const uword base_col = aux_col1 + col_num; max@0: max@0: return subview_col(*m_ptr, base_col, aux_row1, n_rows); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (column vector) max@0: template max@0: inline max@0: const subview_col max@0: subview::col(const uword col_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( col_num >= n_cols, "subview::col(): out of bounds"); max@0: max@0: const uword base_col = aux_col1 + col_num; max@0: max@0: return subview_col(m, base_col, aux_row1, n_rows); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_col max@0: subview::operator()(const span& row_span, const uword col_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool row_all = row_span.whole; max@0: max@0: const uword local_n_rows = n_rows; max@0: max@0: const uword in_row1 = row_all ? 0 : row_span.a; max@0: const uword in_row2 = row_span.b; max@0: const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; max@0: max@0: const uword base_row1 = aux_row1 + in_row1; max@0: const uword base_col = aux_col1 + col_num; max@0: max@0: arma_debug_check max@0: ( max@0: (col_num >= n_cols) max@0: || max@0: ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) max@0: , max@0: "subview::operator(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: return subview_col(*m_ptr, base_col, base_row1, submat_n_rows); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const subview_col max@0: subview::operator()(const span& row_span, const uword col_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool row_all = row_span.whole; max@0: max@0: const uword local_n_rows = n_rows; max@0: max@0: const uword in_row1 = row_all ? 0 : row_span.a; max@0: const uword in_row2 = row_span.b; max@0: const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; max@0: max@0: const uword base_row1 = aux_row1 + in_row1; max@0: const uword base_col = aux_col1 + col_num; max@0: max@0: arma_debug_check max@0: ( max@0: (col_num >= n_cols) max@0: || max@0: ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) max@0: , max@0: "subview::operator(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: return subview_col(m, base_col, base_row1, submat_n_rows); max@0: } max@0: max@0: max@0: max@0: //! create a Col object which uses memory from an existing matrix object. max@0: //! this approach is currently not alias safe max@0: //! and does not take into account that the parent matrix object could be deleted. max@0: //! if deleted memory is accessed by the created Col object, max@0: //! it will cause memory corruption and/or a crash max@0: template max@0: inline max@0: Col max@0: subview::unsafe_col(const uword col_num) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( col_num >= n_cols, "subview::unsafe_col(): out of bounds"); max@0: max@0: return Col(colptr(col_num), n_rows, false, true); max@0: } max@0: max@0: max@0: max@0: //! create a Col object which uses memory from an existing matrix object. max@0: //! this approach is currently not alias safe max@0: //! and does not take into account that the parent matrix object could be deleted. max@0: //! if deleted memory is accessed by the created Col object, max@0: //! it will cause memory corruption and/or a crash max@0: template max@0: inline max@0: const Col max@0: subview::unsafe_col(const uword col_num) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( col_num >= n_cols, "subview::unsafe_col(): out of bounds"); max@0: max@0: return Col(const_cast(colptr(col_num)), n_rows, false, true); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix comprised of specified row vectors) max@0: template max@0: inline max@0: subview max@0: subview::rows(const uword in_row1, const uword in_row2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 > in_row2) || (in_row2 >= n_rows), max@0: "subview::rows(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: const uword base_row1 = aux_row1 + in_row1; max@0: max@0: return subview(*m_ptr, base_row1, aux_col1, subview_n_rows, n_cols ); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix comprised of specified row vectors) max@0: template max@0: inline max@0: const subview max@0: subview::rows(const uword in_row1, const uword in_row2) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 > in_row2) || (in_row2 >= n_rows), max@0: "subview::rows(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: const uword base_row1 = aux_row1 + in_row1; max@0: max@0: return subview(m, base_row1, aux_col1, subview_n_rows, n_cols ); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix comprised of specified column vectors) max@0: template max@0: inline max@0: subview max@0: subview::cols(const uword in_col1, const uword in_col2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_col1 > in_col2) || (in_col2 >= n_cols), max@0: "subview::cols(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: const uword base_col1 = aux_col1 + in_col1; max@0: max@0: return subview(*m_ptr, aux_row1, base_col1, n_rows, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix comprised of specified column vectors) max@0: template max@0: inline max@0: const subview max@0: subview::cols(const uword in_col1, const uword in_col2) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_col1 > in_col2) || (in_col2 >= n_cols), max@0: "subview::cols(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: const uword base_col1 = aux_col1 + in_col1; max@0: max@0: return subview(m, aux_row1, base_col1, n_rows, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix) max@0: template max@0: inline max@0: subview max@0: subview::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), max@0: "subview::submat(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: max@0: const uword base_row1 = aux_row1 + in_row1; max@0: const uword base_col1 = aux_col1 + in_col1; max@0: max@0: return subview(*m_ptr, base_row1, base_col1, subview_n_rows, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (generic submatrix) max@0: template max@0: inline max@0: const subview max@0: subview::submat(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 > in_row2) || (in_col1 > in_col2) || (in_row2 >= n_rows) || (in_col2 >= n_cols), max@0: "subview::submat(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: max@0: const uword base_row1 = aux_row1 + in_row1; max@0: const uword base_col1 = aux_col1 + in_col1; max@0: max@0: return subview(m, base_row1, base_col1, subview_n_rows, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (submatrix) max@0: template max@0: inline max@0: subview max@0: subview::submat(const span& row_span, const span& col_span) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool row_all = row_span.whole; max@0: const bool col_all = col_span.whole; max@0: max@0: const uword local_n_rows = n_rows; max@0: const uword local_n_cols = n_cols; max@0: max@0: const uword in_row1 = row_all ? 0 : row_span.a; max@0: const uword in_row2 = row_span.b; max@0: const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; max@0: max@0: const uword in_col1 = col_all ? 0 : col_span.a; max@0: const uword in_col2 = col_span.b; max@0: const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; max@0: max@0: arma_debug_check max@0: ( max@0: ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) max@0: || max@0: ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) max@0: , max@0: "subview::submat(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword base_row1 = aux_row1 + in_row1; max@0: const uword base_col1 = aux_col1 + in_col1; max@0: max@0: return subview(*m_ptr, base_row1, base_col1, submat_n_rows, submat_n_cols); max@0: } max@0: max@0: max@0: max@0: //! creation of subview (generic submatrix) max@0: template max@0: inline max@0: const subview max@0: subview::submat(const span& row_span, const span& col_span) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const bool row_all = row_span.whole; max@0: const bool col_all = col_span.whole; max@0: max@0: const uword local_n_rows = n_rows; max@0: const uword local_n_cols = n_cols; max@0: max@0: const uword in_row1 = row_all ? 0 : row_span.a; max@0: const uword in_row2 = row_span.b; max@0: const uword submat_n_rows = row_all ? local_n_rows : in_row2 - in_row1 + 1; max@0: max@0: const uword in_col1 = col_all ? 0 : col_span.a; max@0: const uword in_col2 = col_span.b; max@0: const uword submat_n_cols = col_all ? local_n_cols : in_col2 - in_col1 + 1; max@0: max@0: arma_debug_check max@0: ( max@0: ( row_all ? false : ((in_row1 > in_row2) || (in_row2 >= local_n_rows)) ) max@0: || max@0: ( col_all ? false : ((in_col1 > in_col2) || (in_col2 >= local_n_cols)) ) max@0: , max@0: "subview::submat(): indices out of bounds or incorrectly used" max@0: ); max@0: max@0: const uword base_row1 = aux_row1 + in_row1; max@0: const uword base_col1 = aux_col1 + in_col1; max@0: max@0: return subview(m, base_row1, base_col1, submat_n_rows, submat_n_cols); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview max@0: subview::operator()(const span& row_span, const span& col_span) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return (*this).submat(row_span, col_span); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const subview max@0: subview::operator()(const span& row_span, const span& col_span) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: return (*this).submat(row_span, col_span); max@0: } max@0: max@0: max@0: max@0: //! creation of diagview (diagonal) max@0: template max@0: inline max@0: diagview max@0: subview::diag(const sword in_id) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword row_offset = (in_id < 0) ? uword(-in_id) : 0; max@0: const uword col_offset = (in_id > 0) ? uword( in_id) : 0; max@0: max@0: arma_debug_check max@0: ( max@0: ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), max@0: "subview::diag(): requested diagonal out of bounds" max@0: ); max@0: max@0: const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); max@0: max@0: const uword base_row_offset = aux_row1 + row_offset; max@0: const uword base_col_offset = aux_col1 + col_offset; max@0: max@0: return diagview(*m_ptr, base_row_offset, base_col_offset, len); max@0: } max@0: max@0: max@0: max@0: //! creation of diagview (diagonal) max@0: template max@0: inline max@0: const diagview max@0: subview::diag(const sword in_id) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: const uword row_offset = (in_id < 0) ? -in_id : 0; max@0: const uword col_offset = (in_id > 0) ? in_id : 0; max@0: max@0: arma_debug_check max@0: ( max@0: ((row_offset > 0) && (row_offset >= n_rows)) || ((col_offset > 0) && (col_offset >= n_cols)), max@0: "subview::diag(): requested diagonal out of bounds" max@0: ); max@0: max@0: const uword len = (std::min)(n_rows - row_offset, n_cols - col_offset); max@0: max@0: const uword base_row_offset = aux_row1 + row_offset; max@0: const uword base_col_offset = aux_col1 + col_offset; max@0: max@0: return diagview(m, base_row_offset, base_col_offset, len); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview::swap_rows(const uword in_row1, const uword in_row2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_row1 >= n_rows) || (in_row2 >= n_rows), max@0: "subview::swap_rows(): out of bounds" max@0: ); max@0: max@0: eT* mem = (*m_ptr).memptr(); max@0: max@0: for(uword col=0; col max@0: inline max@0: void max@0: subview::swap_cols(const uword in_col1, const uword in_col2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check max@0: ( max@0: (in_col1 >= n_cols) || (in_col2 >= n_cols), max@0: "subview::swap_cols(): out of bounds" max@0: ); max@0: max@0: if(n_elem > 0) max@0: { max@0: eT* ptr1 = colptr(in_col1); max@0: eT* ptr2 = colptr(in_col2); max@0: max@0: for(uword row=0; row max@0: // inline max@0: // subview::iter::iter(const subview& S) max@0: // : mem (S.m.mem) max@0: // , n_rows (S.m.n_rows) max@0: // , row_start (S.aux_row1) max@0: // , row_end_p1(row_start + S.n_rows) max@0: // , row (row_start) max@0: // , col (S.aux_col1) max@0: // , i (row + col*n_rows) max@0: // { max@0: // arma_extra_debug_sigprint(); max@0: // } max@0: // max@0: // max@0: // max@0: // template max@0: // arma_inline max@0: // eT max@0: // subview::iter::operator*() const max@0: // { max@0: // return mem[i]; max@0: // } max@0: // max@0: // max@0: // max@0: // template max@0: // inline max@0: // void max@0: // subview::iter::operator++() max@0: // { max@0: // ++row; max@0: // max@0: // if(row < row_end_p1) max@0: // { max@0: // ++i; max@0: // } max@0: // else max@0: // { max@0: // row = row_start; max@0: // ++col; max@0: // max@0: // i = row + col*n_rows; max@0: // } max@0: // } max@0: // max@0: // max@0: // max@0: // template max@0: // inline max@0: // void max@0: // subview::iter::operator++(int) max@0: // { max@0: // operator++(); max@0: // } max@0: max@0: max@0: max@0: // max@0: // max@0: // max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_col::subview_col(const Mat& in_m, const uword in_col) max@0: : subview(in_m, 0, in_col, in_m.n_rows, 1) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_col::subview_col(Mat& in_m, const uword in_col) max@0: : subview(in_m, 0, in_col, in_m.n_rows, 1) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_col::subview_col(const Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows) max@0: : subview(in_m, in_row1, in_col, in_n_rows, 1) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_col::subview_col(Mat& in_m, const uword in_col, const uword in_row1, const uword in_n_rows) max@0: : subview(in_m, in_row1, in_col, in_n_rows, 1) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_col::operator=(const subview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview::operator=(X); max@0: arma_debug_check( (subview::n_cols > 1), "subview_col(): incompatible dimensions" ); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_col::operator=(const subview_col& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview::operator=(X); // interprets 'subview_col' as 'subview' max@0: arma_debug_check( (subview::n_cols > 1), "subview_col(): incompatible dimensions" ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_col::operator=(const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview::operator=(X); max@0: arma_debug_check( (subview::n_cols > 1), "subview_col(): incompatible dimensions" ); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_col max@0: subview_col::rows(const uword in_row1, const uword in_row2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::rows(): indices out of bounds or incorrectly used"); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: max@0: const uword base_row1 = this->aux_row1 + in_row1; max@0: max@0: return subview_col(*(this->m_ptr), this->aux_col1, base_row1, subview_n_rows); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const subview_col max@0: subview_col::rows(const uword in_row1, const uword in_row2) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::rows(): indices out of bounds or incorrectly used"); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: max@0: const uword base_row1 = this->aux_row1 + in_row1; max@0: max@0: return subview_col(this->m, this->aux_col1, base_row1, subview_n_rows); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_col max@0: subview_col::subvec(const uword in_row1, const uword in_row2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::subvec(): indices out of bounds or incorrectly used"); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: max@0: const uword base_row1 = this->aux_row1 + in_row1; max@0: max@0: return subview_col(*(this->m_ptr), this->aux_col1, base_row1, subview_n_rows); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const subview_col max@0: subview_col::subvec(const uword in_row1, const uword in_row2) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( ( (in_row1 > in_row2) || (in_row2 >= subview::n_rows) ), "subview_col::subvec(): indices out of bounds or incorrectly used"); max@0: max@0: const uword subview_n_rows = in_row2 - in_row1 + 1; max@0: max@0: const uword base_row1 = this->aux_row1 + in_row1; max@0: max@0: return subview_col(this->m, this->aux_col1, base_row1, subview_n_rows); max@0: } max@0: max@0: max@0: max@0: // max@0: // max@0: // max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_row::subview_row(const Mat& in_m, const uword in_row) max@0: : subview(in_m, in_row, 0, 1, in_m.n_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_row::subview_row(Mat& in_m, const uword in_row) max@0: : subview(in_m, in_row, 0, 1, in_m.n_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_row::subview_row(const Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols) max@0: : subview(in_m, in_row, in_col1, 1, in_n_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_row::subview_row(Mat& in_m, const uword in_row, const uword in_col1, const uword in_n_cols) max@0: : subview(in_m, in_row, in_col1, 1, in_n_cols) max@0: { max@0: arma_extra_debug_sigprint(); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_row::operator=(const subview& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview::operator=(X); max@0: arma_debug_check( (subview::n_rows > 1), "subview_row(): incompatible dimensions" ); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: void max@0: subview_row::operator=(const subview_row& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview::operator=(X); // interprets 'subview_row' as 'subview' max@0: arma_debug_check( (subview::n_rows > 1), "subview_row(): incompatible dimensions" ); max@0: } max@0: max@0: max@0: max@0: template max@0: template max@0: inline max@0: void max@0: subview_row::operator=(const Base& X) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: subview::operator=(X); max@0: arma_debug_check( (subview::n_rows > 1), "subview_row(): incompatible dimensions" ); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_row max@0: subview_row::cols(const uword in_col1, const uword in_col2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::cols(): indices out of bounds or incorrectly used" ); max@0: max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: max@0: const uword base_col1 = this->aux_col1 + in_col1; max@0: max@0: return subview_row(*(this->m_ptr), this->aux_row1, base_col1, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const subview_row max@0: subview_row::cols(const uword in_col1, const uword in_col2) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::cols(): indices out of bounds or incorrectly used"); max@0: max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: max@0: const uword base_col1 = this->aux_col1 + in_col1; max@0: max@0: return subview_row(this->m, this->aux_row1, base_col1, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: subview_row max@0: subview_row::subvec(const uword in_col1, const uword in_col2) max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::subvec(): indices out of bounds or incorrectly used"); max@0: max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: max@0: const uword base_col1 = this->aux_col1 + in_col1; max@0: max@0: return subview_row(*(this->m_ptr), this->aux_row1, base_col1, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: template max@0: inline max@0: const subview_row max@0: subview_row::subvec(const uword in_col1, const uword in_col2) const max@0: { max@0: arma_extra_debug_sigprint(); max@0: max@0: arma_debug_check( ( (in_col1 > in_col2) || (in_col2 >= subview::n_cols) ), "subview_row::subvec(): indices out of bounds or incorrectly used"); max@0: max@0: const uword subview_n_cols = in_col2 - in_col1 + 1; max@0: max@0: const uword base_col1 = this->aux_col1 + in_col1; max@0: max@0: return subview_row(this->m, this->aux_row1, base_col1, subview_n_cols); max@0: } max@0: max@0: max@0: max@0: //! @}