Commit 114de952 authored by Davis King's avatar Davis King

Refactored code slightly to avoid getting this warning from gcc when certain

optimizations are enabled "warning: assuming signed overflow does not occur
when assuming that (X + c) < X is always false"
parent c24f1d67
...@@ -533,15 +533,18 @@ namespace dlib ...@@ -533,15 +533,18 @@ namespace dlib
assignable_sub_matrix( assignable_sub_matrix(
matrix<T,NR,NC,mm,l>& m_, matrix<T,NR,NC,mm,l>& m_,
const rectangle& rect_ long top_,
) : m(m_), rect(rect_) {} long left_,
long height_,
long width_
) : m(m_), left(left_), top(top_), width(width_), height(height_) {}
T& operator() ( T& operator() (
long r, long r,
long c long c
) )
{ {
return m(r+rect.top(),c+rect.left()); return m(r+top,c+left);
} }
const T& operator() ( const T& operator() (
...@@ -549,24 +552,24 @@ namespace dlib ...@@ -549,24 +552,24 @@ namespace dlib
long c long c
) const ) const
{ {
return m(r+rect.top(),c+rect.left()); return m(r+top,c+left);
} }
long nr() const { return rect.height(); } long nr() const { return height; }
long nc() const { return rect.width(); } long nc() const { return 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
) )
{ {
DLIB_ASSERT( exp.nr() == (long)rect.height() && exp.nc() == (long)rect.width(), DLIB_ASSERT( exp.nr() == height && exp.nc() == width,
"\tassignable_matrix_expression set_subm()" "\tassignable_matrix_expression set_subm()"
<< "\n\tYou have tried to assign to this object using a matrix that isn't the right size" << "\n\tYou have tried to assign to this object using a matrix that isn't the right size"
<< "\n\texp.nr() (source matrix): " << exp.nr() << "\n\texp.nr() (source matrix): " << exp.nr()
<< "\n\texp.nc() (source matrix): " << exp.nc() << "\n\texp.nc() (source matrix): " << exp.nc()
<< "\n\trect.width() (target matrix): " << rect.width() << "\n\twidth (target matrix): " << width
<< "\n\trect.height() (target matrix): " << rect.height() << "\n\theight (target matrix): " << height
); );
if (exp.destructively_aliases(m) == false) if (exp.destructively_aliases(m) == false)
...@@ -588,18 +591,18 @@ namespace dlib ...@@ -588,18 +591,18 @@ namespace dlib
const matrix_exp<EXP>& exp const matrix_exp<EXP>& exp
) )
{ {
DLIB_ASSERT( exp.nr() == (long)rect.height() && exp.nc() == (long)rect.width(), DLIB_ASSERT( exp.nr() == height && exp.nc() == width,
"\tassignable_matrix_expression set_subm()" "\tassignable_matrix_expression set_subm()"
<< "\n\tYou have tried to assign to this object using a matrix that isn't the right size" << "\n\tYou have tried to assign to this object using a matrix that isn't the right size"
<< "\n\texp.nr() (source matrix): " << exp.nr() << "\n\texp.nr() (source matrix): " << exp.nr()
<< "\n\texp.nc() (source matrix): " << exp.nc() << "\n\texp.nc() (source matrix): " << exp.nc()
<< "\n\trect.width() (target matrix): " << rect.width() << "\n\twidth (target matrix): " << width
<< "\n\trect.height() (target matrix): " << rect.height() << "\n\theight (target matrix): " << height
); );
if (exp.destructively_aliases(m) == false) if (exp.destructively_aliases(m) == false)
{ {
matrix_assign(*this, subm(m,rect)+exp); matrix_assign(*this, subm(m,top,left,height,width)+exp);
} }
else else
{ {
...@@ -616,18 +619,18 @@ namespace dlib ...@@ -616,18 +619,18 @@ namespace dlib
const matrix_exp<EXP>& exp const matrix_exp<EXP>& exp
) )
{ {
DLIB_ASSERT( exp.nr() == (long)rect.height() && exp.nc() == (long)rect.width(), DLIB_ASSERT( exp.nr() == height && exp.nc() == width,
"\tassignable_matrix_expression set_subm()" "\tassignable_matrix_expression set_subm()"
<< "\n\tYou have tried to assign to this object using a matrix that isn't the right size" << "\n\tYou have tried to assign to this object using a matrix that isn't the right size"
<< "\n\texp.nr() (source matrix): " << exp.nr() << "\n\texp.nr() (source matrix): " << exp.nr()
<< "\n\texp.nc() (source matrix): " << exp.nc() << "\n\texp.nc() (source matrix): " << exp.nc()
<< "\n\trect.width() (target matrix): " << rect.width() << "\n\twidth (target matrix): " << width
<< "\n\trect.height() (target matrix): " << rect.height() << "\n\theight (target matrix): " << height
); );
if (exp.destructively_aliases(m) == false) if (exp.destructively_aliases(m) == false)
{ {
matrix_assign(*this, subm(m,rect)-exp); matrix_assign(*this, subm(m,top,left,height,width)-exp);
} }
else else
{ {
...@@ -643,9 +646,11 @@ namespace dlib ...@@ -643,9 +646,11 @@ namespace dlib
const T& value const T& value
) )
{ {
for (long r = rect.top(); r <= rect.bottom(); ++r) const long bottom = top+height-1;
const long right = left+width-1;
for (long r = top; r <= bottom; ++r)
{ {
for (long c = rect.left(); c <= rect.right(); ++c) for (long c = left; c <= right; ++c)
{ {
m(r,c) = value; m(r,c) = value;
} }
...@@ -658,9 +663,11 @@ namespace dlib ...@@ -658,9 +663,11 @@ namespace dlib
const T& value const T& value
) )
{ {
for (long r = rect.top(); r <= rect.bottom(); ++r) const long bottom = top+height-1;
const long right = left+width-1;
for (long r = top; r <= bottom; ++r)
{ {
for (long c = rect.left(); c <= rect.right(); ++c) for (long c = left; c <= right; ++c)
{ {
m(r,c) += value; m(r,c) += value;
} }
...@@ -673,9 +680,11 @@ namespace dlib ...@@ -673,9 +680,11 @@ namespace dlib
const T& value const T& value
) )
{ {
for (long r = rect.top(); r <= rect.bottom(); ++r) const long bottom = top+height-1;
const long right = left+width-1;
for (long r = top; r <= bottom; ++r)
{ {
for (long c = rect.left(); c <= rect.right(); ++c) for (long c = left; c <= right; ++c)
{ {
m(r,c) -= value; m(r,c) -= value;
} }
...@@ -686,7 +695,7 @@ namespace dlib ...@@ -686,7 +695,7 @@ namespace dlib
matrix<T,NR,NC,mm,l>& m; matrix<T,NR,NC,mm,l>& m;
const rectangle rect; const long left, top, width, height;
}; };
...@@ -708,7 +717,7 @@ namespace dlib ...@@ -708,7 +717,7 @@ namespace dlib
); );
return assignable_sub_matrix<T,NR,NC,mm,l>(m,rect); return assignable_sub_matrix<T,NR,NC,mm,l>(m,rect.top(), rect.left(), rect.height(), rect.width());
} }
...@@ -732,7 +741,7 @@ namespace dlib ...@@ -732,7 +741,7 @@ namespace dlib
<< "\n\tnc: " << nc << "\n\tnc: " << nc
); );
return assignable_sub_matrix<T,NR,NC,mm,l>(m,rectangle(c,r, c+nc-1, r+nr-1)); return assignable_sub_matrix<T,NR,NC,mm,l>(m,r,c, nr, nc);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment