Commit c88568fc authored by Davis King's avatar Davis King

Added asserts to catch a common user error.

parent d9638f22
......@@ -1435,6 +1435,9 @@ namespace dlib
}
else
{
DLIB_ASSERT(size() == 0,
"\t const matrix::operator+=(m)"
<< "\n\t You are trying to add two matrices that have incompatible dimensions.");
*this = m;
}
return *this;
......@@ -1469,6 +1472,9 @@ namespace dlib
}
else
{
DLIB_ASSERT(size() == 0,
"\t const matrix::operator-=(m)"
<< "\n\t You are trying to subtract two matrices that have incompatible dimensions.");
*this = -m;
}
return *this;
......@@ -1495,6 +1501,10 @@ namespace dlib
}
else
{
DLIB_ASSERT(this->size() == 0,
"\t const matrix::operator+=(m)"
<< "\n\t You are trying to add two matrices that have incompatible dimensions.");
set_size(m.nr(), m.nc());
for (long i = 0; i < size; ++i)
data(i) = m.data(i);
......@@ -1514,6 +1524,9 @@ namespace dlib
}
else
{
DLIB_ASSERT(this->size() == 0,
"\t const matrix::operator-=(m)"
<< "\n\t You are trying to subtract two matrices that have incompatible dimensions.");
set_size(m.nr(), m.nc());
for (long i = 0; i < size; ++i)
data(i) = -m.data(i);
......
......@@ -492,6 +492,10 @@ namespace dlib
/*!
requires
- matrix_exp<EXP>::type == T
- One of the following is true:
- nr() == m.nr() && nc() == m.nc()
- size() == 0
(i.e. this matrix must have matching dimensions or it must be empty)
ensures
- if (nr() == m.nr() && nc() == m.nc()) then
- #(*this) == *this + m
......@@ -509,6 +513,10 @@ namespace dlib
/*!
requires
- matrix_exp<EXP>::type == T
- One of the following is true:
- nr() == m.nr() && nc() == m.nc()
- size() == 0
(i.e. this matrix must have matching dimensions or it must be empty)
ensures
- if (nr() == m.nr() && nc() == m.nc()) then
- #(*this) == *this - m
......
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