"...text-generation-inference.git" did not exist on "2ce80194806f73c1b7ced1d686ce01efd3aefdc7"
Commit 114de952 authored by Davis King's avatar Davis King
Browse files

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
assignable_sub_matrix(
matrix<T,NR,NC,mm,l>& m_,
const rectangle& rect_
) : m(m_), rect(rect_) {}
long top_,
long left_,
long height_,
long width_
) : m(m_), left(left_), top(top_), width(width_), height(height_) {}
T& operator() (
long r,
long c
)
{
return m(r+rect.top(),c+rect.left());
return m(r+top,c+left);
}
const T& operator() (
......@@ -549,24 +552,24 @@ namespace dlib
long c
) const
{
return m(r+rect.top(),c+rect.left());
return m(r+top,c+left);
}
long nr() const { return rect.height(); }
long nc() const { return rect.width(); }
long nr() const { return height; }
long nc() const { return width; }
template <typename EXP>
assignable_sub_matrix& operator= (
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()"
<< "\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.nc() (source matrix): " << exp.nc()
<< "\n\trect.width() (target matrix): " << rect.width()
<< "\n\trect.height() (target matrix): " << rect.height()
<< "\n\twidth (target matrix): " << width
<< "\n\theight (target matrix): " << height
);
if (exp.destructively_aliases(m) == false)
......@@ -588,18 +591,18 @@ namespace dlib
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()"
<< "\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.nc() (source matrix): " << exp.nc()
<< "\n\trect.width() (target matrix): " << rect.width()
<< "\n\trect.height() (target matrix): " << rect.height()
<< "\n\twidth (target matrix): " << width
<< "\n\theight (target matrix): " << height
);
if (exp.destructively_aliases(m) == false)
{
matrix_assign(*this, subm(m,rect)+exp);
matrix_assign(*this, subm(m,top,left,height,width)+exp);
}
else
{
......@@ -616,18 +619,18 @@ namespace dlib
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()"
<< "\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.nc() (source matrix): " << exp.nc()
<< "\n\trect.width() (target matrix): " << rect.width()
<< "\n\trect.height() (target matrix): " << rect.height()
<< "\n\twidth (target matrix): " << width
<< "\n\theight (target matrix): " << height
);
if (exp.destructively_aliases(m) == false)
{
matrix_assign(*this, subm(m,rect)-exp);
matrix_assign(*this, subm(m,top,left,height,width)-exp);
}
else
{
......@@ -643,9 +646,11 @@ namespace dlib
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;
}
......@@ -658,9 +663,11 @@ namespace dlib
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;
}
......@@ -673,9 +680,11 @@ namespace dlib
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;
}
......@@ -686,7 +695,7 @@ namespace dlib
matrix<T,NR,NC,mm,l>& m;
const rectangle rect;
const long left, top, width, height;
};
......@@ -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
<< "\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