Commit ad06153a authored by Davis King's avatar Davis King

- Fixed some issues with the requires clause of the removerc function.

  - Added the remove_row and remove_col functions.  Also made all
    three of the above functions capable of taking arguments at
    run time as well as compile time.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402307
parent 881c2b09
This diff is collapsed.
......@@ -369,13 +369,99 @@ namespace dlib
);
/*!
requires
- m.nr() > 1
- m.nc() > 1
- m.nr() > R
- m.nc() > C
ensures
- returns a matrix R such that:
- R.nr() == m.nr() - 1
- R.nc() == m.nc() - 1
- R == m with its R row and C column removed
- returns a matrix M such that:
- M.nr() == m.nr() - 1
- M.nc() == m.nc() - 1
- M == m with its R row and C column removed
!*/
// ----------------------------------------------------------------------------------------
const matrix_exp removerc (
const matrix_exp& m,
long R,
long C
);
/*!
requires
- m.nr() > R
- m.nc() > C
ensures
- returns a matrix M such that:
- M.nr() == m.nr() - 1
- M.nc() == m.nc() - 1
- M == m with its R row and C column removed
!*/
// ----------------------------------------------------------------------------------------
template <
long R
>
const matrix_exp remove_row (
const matrix_exp& m
);
/*!
requires
- m.nr() > R
ensures
- returns a matrix M such that:
- M.nr() == m.nr() - 1
- M.nc() == m.nc()
- M == m with its R row removed
!*/
// ----------------------------------------------------------------------------------------
const matrix_exp remove_row (
const matrix_exp& m,
long R
);
/*!
requires
- m.nr() > R
ensures
- returns a matrix M such that:
- M.nr() == m.nr() - 1
- M.nc() == m.nc()
- M == m with its R row removed
!*/
// ----------------------------------------------------------------------------------------
template <
long C
>
const matrix_exp remove_col (
const matrix_exp& m
);
/*!
requires
- m.nc() > C
ensures
- returns a matrix M such that:
- M.nr() == m.nr()
- M.nc() == m.nc() - 1
- M == m with its C column removed
!*/
// ----------------------------------------------------------------------------------------
const matrix_exp remove_col (
const matrix_exp& m,
long C
);
/*!
requires
- m.nc() > C
ensures
- returns a matrix M such that:
- M.nr() == m.nr()
- M.nc() == m.nc() - 1
- M == m with its C column removed
!*/
// ----------------------------------------------------------------------------------------
......
......@@ -122,6 +122,7 @@ namespace
matrix<double,2,3> mrc2;
set_all_elements(mrc2,1);
DLIB_CASSERT((removerc<1,1>(mrc) == mrc2),"");
DLIB_CASSERT((removerc(mrc,1,1) == mrc2),"");
matrix<int,3,3> m4, m5, m6;
set_all_elements(m4, 4);
......@@ -1240,9 +1241,40 @@ namespace
4, 4, 4, 4, 4,
9, 0, 3, 3, 0
};
long res_vals_c3[] = {
9, 0, 3, 0,
9, 2, 2, 0,
9, 2, 2, 0,
4, 4, 4, 4,
9, 0, 3, 0
};
long res_vals_r2[] = {
9, 0, 3, 3, 0,
9, 2, 2, 2, 0,
4, 4, 4, 4, 4,
9, 0, 3, 3, 0
};
matrix<long> temp;
res = res_vals;
temp = matrix<long,4,5>(res_vals_r2);
DLIB_CASSERT(remove_row<2>(res) == temp,"");
DLIB_CASSERT(remove_row<2>(res)(3,3) == 3,"");
DLIB_CASSERT(remove_row<2>(res).nr() == 4,"");
DLIB_CASSERT(remove_row<2>(res).nc() == 5,"");
DLIB_CASSERT(remove_row(res,2) == temp,"");
DLIB_CASSERT(remove_row(res,2)(3,3) == 3,"");
DLIB_CASSERT(remove_row(res,2).nr() == 4,"");
DLIB_CASSERT(remove_row(res,2).nc() == 5,"");
temp = matrix<long,5,4>(res_vals_c3);
DLIB_CASSERT(remove_col(res,3) == temp,"");
DLIB_CASSERT(remove_col(res,3)(2,3) == 0,"");
DLIB_CASSERT(remove_col(res,3).nr() == 5,"");
DLIB_CASSERT(remove_col(res,3).nc() == 4,"");
set_all_elements(m2, 1);
set_subm(m1, rectangle(1,1,3,2)) = 2;
set_all_elements(m2, 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