Commit 3401b969 authored by Davis King's avatar Davis King

It's actually fine to call rowm() or colm() with an empty index set.

parent ec63baa7
......@@ -386,16 +386,20 @@ namespace dlib
// the rows matrix must contain integer elements
COMPILE_TIME_ASSERT(std::numeric_limits<typename EXP2::type>::is_integer);
DLIB_ASSERT(0 <= min(rows) && max(rows) < m.nr() && (rows.nr() == 1 || rows.nc() == 1),
"\tconst matrix_exp rowm(const matrix_exp& m, const matrix_exp& rows)"
<< "\n\tYou have given invalid arguments to this function"
<< "\n\tm.nr(): " << m.nr()
<< "\n\tm.nc(): " << m.nc()
<< "\n\tmin(rows): " << min(rows)
<< "\n\tmax(rows): " << max(rows)
<< "\n\trows.nr(): " << rows.nr()
<< "\n\trows.nc(): " << rows.nc()
#ifdef ENABLE_ASSERTS
if (rows.size() != 0) {
DLIB_ASSERT(0 <= min(rows) && max(rows) < m.nr() && (rows.nr() == 1 || rows.nc() == 1),
"\tconst matrix_exp rowm(const matrix_exp& m, const matrix_exp& rows)"
<< "\n\tYou have given invalid arguments to this function"
<< "\n\tm.nr(): " << m.nr()
<< "\n\tm.nc(): " << m.nc()
<< "\n\tmin(rows): " << min(rows)
<< "\n\tmax(rows): " << max(rows)
<< "\n\trows.nr(): " << rows.nr()
<< "\n\trows.nc(): " << rows.nc()
);
}
#endif // ENABLE_ASSERTS
typedef op_rowm_range<EXP1,EXP2> op;
return matrix_op<op>(op(m.ref(),rows.ref()));
......@@ -541,16 +545,20 @@ namespace dlib
// the rows matrix must contain integer elements
COMPILE_TIME_ASSERT(std::numeric_limits<typename EXP2::type>::is_integer);
DLIB_ASSERT(0 <= min(cols) && max(cols) < m.nc() && (cols.nr() == 1 || cols.nc() == 1),
"\tconst matrix_exp colm(const matrix_exp& m, const matrix_exp& cols)"
<< "\n\tYou have given invalid arguments to this function"
<< "\n\tm.nr(): " << m.nr()
<< "\n\tm.nc(): " << m.nc()
<< "\n\tmin(cols): " << min(cols)
<< "\n\tmax(cols): " << max(cols)
<< "\n\tcols.nr(): " << cols.nr()
<< "\n\tcols.nc(): " << cols.nc()
#ifdef ENABLE_ASSERTS
if (cols.size() != 0) {
DLIB_ASSERT(0 <= min(cols) && max(cols) < m.nc() && (cols.nr() == 1 || cols.nc() == 1),
"\tconst matrix_exp colm(const matrix_exp& m, const matrix_exp& cols)"
<< "\n\tYou have given invalid arguments to this function"
<< "\n\tm.nr(): " << m.nr()
<< "\n\tm.nc(): " << m.nc()
<< "\n\tmin(cols): " << min(cols)
<< "\n\tmax(cols): " << max(cols)
<< "\n\tcols.nr(): " << cols.nr()
<< "\n\tcols.nc(): " << cols.nc()
);
}
#endif // ENABLE_ASSERTS
typedef op_colm_range<EXP1,EXP2> op;
return matrix_op<op>(op(m.ref(),cols.ref()));
......
......@@ -239,8 +239,8 @@ namespace dlib
requires
- rows contains integral elements (e.g. int, long)
- 0 <= min(rows) && max(rows) < m.nr()
- rows.nr() == 1 || rows.nc() == 1
(i.e. rows must be a vector)
- rows.nr() == 1 || rows.nc() == 1 || rows.size() == 0
(i.e. rows must be a vector, or just empty)
ensures
- returns a matrix R such that:
- R::type == the same type that was in m
......@@ -326,8 +326,8 @@ namespace dlib
requires
- cols contains integral elements (e.g. int, long)
- 0 <= min(cols) && max(cols) < m.nc()
- cols.nr() == 1 || cols.nc() == 1
(i.e. cols must be a vector)
- cols.nr() == 1 || cols.nc() == 1 || cols.size() == 0
(i.e. cols must be a vector, or just empty)
ensures
- returns a matrix R such that:
- R::type == the same type that was in m
......
......@@ -1060,6 +1060,8 @@ namespace
DLIB_TEST(subm(m,range(1,1),range(0,2)) == rowm(m,1));
DLIB_TEST(subm(m,range(2,2),range(0,2)) == rowm(m,2));
DLIB_TEST(subm(m,range(3,3),range(0,2)) == rowm(m,3));
DLIB_TEST(rowm(m,matrix<long>()).size()==0);
DLIB_TEST(colm(m,matrix<long>()).size()==0);
DLIB_TEST(subm(m,0,0,2,2) == subm(m,range(0,1),range(0,1)));
DLIB_TEST(subm(m,1,1,2,2) == subm(m,range(1,2),range(1,2)));
......
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