Simplified the matrix_assign() function a bit.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402711
This commit is contained in:
Davis King 2008-12-08 01:42:49 +00:00
parent 13f0b4338a
commit b556ebf587
3 changed files with 56 additions and 22 deletions

View File

@ -895,17 +895,13 @@ namespace dlib
> >
void matrix_assign ( void matrix_assign (
matrix_dest_type& dest, matrix_dest_type& dest,
const matrix_exp<src_exp>& src, const matrix_exp<src_exp>& src
const long row_offset = 0,
const long col_offset = 0
) )
/*! /*!
requires requires
- src.destructively_aliases(dest) == false - src.destructively_aliases(dest) == false
- dest.nr() == src.nr()-row_offset
- dest.nc() == src.nc()-col_offset
ensures 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 - 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) for (long c = 0; c < src.nc(); ++c)
{ {
dest(r+row_offset,c+col_offset) = src(r,c); dest(r,c) = src(r,c);
} }
} }
} }

View File

@ -56,9 +56,7 @@ namespace dlib
inline typename disable_if_c<ma::matrix_is_vector<EXP1>::value || ma::matrix_is_vector<EXP2>::value || inline typename disable_if_c<ma::matrix_is_vector<EXP1>::value || ma::matrix_is_vector<EXP2>::value ||
ma::is_small_matrix<EXP1>::value || ma::is_small_matrix<EXP2>::value >::type matrix_assign ( ma::is_small_matrix<EXP1>::value || ma::is_small_matrix<EXP2>::value >::type matrix_assign (
matrix_dest_type& dest, matrix_dest_type& dest,
const matrix_exp<matrix_multiply_exp<EXP1,EXP2,count> >& src, const matrix_exp<matrix_multiply_exp<EXP1,EXP2,count> >& src
const long row_offset = 0,
const long col_offset = 0
) )
/*! /*!
This overload catches assignments like: This overload catches assignments like:
@ -78,7 +76,7 @@ namespace dlib
{ {
for (long c = 0; c < src.nc(); ++c) 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 // make a target rect in res
rectangle res_block(rhs_block.left(),lhs_block.top(), rhs_block.right(), lhs_block.bottom()); 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) if (c != 0)
set_subm(dest, res_block) = subm(dest,res_block) + subm(lhs,lhs_block)*subm(rhs, rhs_block); set_subm(dest, res_block) = subm(dest,res_block) + subm(lhs,lhs_block)*subm(rhs, rhs_block);
else else

View File

@ -2304,6 +2304,17 @@ convergence:
const rectangle& rect_ const rectangle& rect_
) : m(m_), rect(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 <typename EXP> template <typename EXP>
assignable_sub_matrix& operator= ( assignable_sub_matrix& operator= (
const matrix_exp<EXP>& exp const matrix_exp<EXP>& exp
@ -2320,7 +2331,7 @@ convergence:
if (exp.destructively_aliases(m) == false) if (exp.destructively_aliases(m) == false)
{ {
matrix_assign(m, exp, rect.top(), rect.left()); matrix_assign(*this, exp);
} }
else else
{ {
@ -2411,6 +2422,18 @@ convergence:
const EXPc& cols_ const EXPc& cols_
) : m(m_), rows(rows_), cols(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 <typename EXP> template <typename EXP>
assignable_sub_range_matrix& operator= ( assignable_sub_range_matrix& operator= (
const matrix_exp<EXP>& exp const matrix_exp<EXP>& exp
@ -2427,13 +2450,7 @@ convergence:
if (exp.destructively_aliases(m) == false) if (exp.destructively_aliases(m) == false)
{ {
for (long r = 0; r < rows.size(); ++r) matrix_assign(*this, exp);
{
for (long c = 0; c < cols.size(); ++c)
{
m(rows(r),cols(c)) = exp(r,c);
}
}
} }
else else
{ {
@ -2504,6 +2521,17 @@ convergence:
const long col_ const long col_
) : m(m_), col(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 <typename EXP> template <typename EXP>
assignable_col_matrix& operator= ( assignable_col_matrix& operator= (
const matrix_exp<EXP>& exp const matrix_exp<EXP>& exp
@ -2519,7 +2547,7 @@ convergence:
if (exp.destructively_aliases(m) == false) if (exp.destructively_aliases(m) == false)
{ {
matrix_assign(m, exp, 0, col); matrix_assign(*this, exp);
} }
else else
{ {
@ -2580,6 +2608,19 @@ convergence:
const long row_ const long row_
) : m(m_), row(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 <typename EXP> template <typename EXP>
assignable_row_matrix& operator= ( assignable_row_matrix& operator= (
const matrix_exp<EXP>& exp const matrix_exp<EXP>& exp
@ -2595,7 +2636,7 @@ convergence:
if (exp.destructively_aliases(m) == false) if (exp.destructively_aliases(m) == false)
{ {
matrix_assign(m, exp, row, 0); matrix_assign(*this, exp);
} }
else else
{ {