diff --git a/dlib/matrix/matrix.h b/dlib/matrix/matrix.h index 06e4240d2..d62007bca 100644 --- a/dlib/matrix/matrix.h +++ b/dlib/matrix/matrix.h @@ -895,17 +895,13 @@ namespace dlib > void matrix_assign ( matrix_dest_type& dest, - const matrix_exp& src, - const long row_offset = 0, - const long col_offset = 0 + const matrix_exp& src ) /*! requires - src.destructively_aliases(dest) == false - - dest.nr() == src.nr()-row_offset - - dest.nc() == src.nc()-col_offset ensures - - #subm(dest, row_offset, col_offset, src.nr(), src.nc()) == src + - #dest == src - the part of dest outside the above sub matrix remains unchanged !*/ { @@ -913,7 +909,7 @@ namespace dlib { for (long c = 0; c < src.nc(); ++c) { - dest(r+row_offset,c+col_offset) = src(r,c); + dest(r,c) = src(r,c); } } } diff --git a/dlib/matrix/matrix_assign.h b/dlib/matrix/matrix_assign.h index 23bfb7b43..51b1858a6 100644 --- a/dlib/matrix/matrix_assign.h +++ b/dlib/matrix/matrix_assign.h @@ -56,9 +56,7 @@ namespace dlib inline typename disable_if_c::value || ma::matrix_is_vector::value || ma::is_small_matrix::value || ma::is_small_matrix::value >::type matrix_assign ( matrix_dest_type& dest, - const matrix_exp >& src, - const long row_offset = 0, - const long col_offset = 0 + const matrix_exp >& src ) /*! This overload catches assignments like: @@ -78,7 +76,7 @@ namespace dlib { for (long c = 0; c < src.nc(); ++c) { - dest(r+row_offset,c+col_offset) = src(r,c); + dest(r,c) = src(r,c); } } } @@ -103,7 +101,6 @@ namespace dlib // make a target rect in res rectangle res_block(rhs_block.left(),lhs_block.top(), rhs_block.right(), lhs_block.bottom()); - res_block = translate_rect(res_block,col_offset, row_offset); if (c != 0) set_subm(dest, res_block) = subm(dest,res_block) + subm(lhs,lhs_block)*subm(rhs, rhs_block); else diff --git a/dlib/matrix/matrix_utilities.h b/dlib/matrix/matrix_utilities.h index 1ce268c7a..56e54a34b 100644 --- a/dlib/matrix/matrix_utilities.h +++ b/dlib/matrix/matrix_utilities.h @@ -2304,6 +2304,17 @@ convergence: const rectangle& rect_ ) : m(m_), rect(rect_) {} + T& operator() ( + long r, + long c + ) + { + return m(r+rect.top(),c+rect.left()); + } + + long nr() const { return rect.height(); } + long nc() const { return rect.width(); } + template assignable_sub_matrix& operator= ( const matrix_exp& exp @@ -2320,7 +2331,7 @@ convergence: if (exp.destructively_aliases(m) == false) { - matrix_assign(m, exp, rect.top(), rect.left()); + matrix_assign(*this, exp); } else { @@ -2411,6 +2422,18 @@ convergence: const EXPc& cols_ ) : m(m_), rows(rows_), cols(cols_) {} + T& operator() ( + long r, + long c + ) + { + return m(rows(r),cols(c)); + } + + long nr() const { return rows.size(); } + long nc() const { return cols.size(); } + + template assignable_sub_range_matrix& operator= ( const matrix_exp& exp @@ -2427,13 +2450,7 @@ convergence: if (exp.destructively_aliases(m) == false) { - for (long r = 0; r < rows.size(); ++r) - { - for (long c = 0; c < cols.size(); ++c) - { - m(rows(r),cols(c)) = exp(r,c); - } - } + matrix_assign(*this, exp); } else { @@ -2504,6 +2521,17 @@ convergence: const long col_ ) : m(m_), col(col_) {} + T& operator() ( + long r, + long c + ) + { + return m(r,col); + } + + long nr() const { return m.nr(); } + long nc() const { return 1; } + template assignable_col_matrix& operator= ( const matrix_exp& exp @@ -2519,7 +2547,7 @@ convergence: if (exp.destructively_aliases(m) == false) { - matrix_assign(m, exp, 0, col); + matrix_assign(*this, exp); } else { @@ -2580,6 +2608,19 @@ convergence: const long row_ ) : m(m_), row(row_) {} + + T& operator() ( + long r, + long c + ) + { + return m(row,c); + } + + long nr() const { return 1; } + long nc() const { return m.nc(); } + + template assignable_row_matrix& operator= ( const matrix_exp& exp @@ -2595,7 +2636,7 @@ convergence: if (exp.destructively_aliases(m) == false) { - matrix_assign(m, exp, row, 0); + matrix_assign(*this, exp); } else {