Commit 10dec05a authored by Davis King's avatar Davis King

Added compile time checks that make it so the user gets a much more informative

error message if they mistakenly use matrices that are not column vectors with
the general purpose optimizers.
parent 7eadede7
......@@ -181,6 +181,9 @@ namespace dlib
)
{
COMPILE_TIME_ASSERT(is_matrix<T>::value);
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
DLIB_ASSERT (
is_col_vector(x),
"\tdouble find_min()"
......@@ -238,6 +241,9 @@ namespace dlib
)
{
COMPILE_TIME_ASSERT(is_matrix<T>::value);
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
DLIB_ASSERT (
is_col_vector(x),
"\tdouble find_max()"
......@@ -302,6 +308,9 @@ namespace dlib
)
{
COMPILE_TIME_ASSERT(is_matrix<T>::value);
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
DLIB_ASSERT (
is_col_vector(x) && derivative_eps > 0,
"\tdouble find_min_using_approximate_derivatives()"
......@@ -362,6 +371,9 @@ namespace dlib
)
{
COMPILE_TIME_ASSERT(is_matrix<T>::value);
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
DLIB_ASSERT (
is_col_vector(x) && derivative_eps > 0,
"\tdouble find_max_using_approximate_derivatives()"
......@@ -463,6 +475,9 @@ namespace dlib
// make sure the requires clause is not violated
COMPILE_TIME_ASSERT(is_matrix<T>::value);
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
DLIB_ASSERT (
is_col_vector(x) && is_col_vector(x_lower) && is_col_vector(x_upper) &&
x.size() == x_lower.size() && x.size() == x_upper.size(),
......@@ -548,6 +563,9 @@ namespace dlib
double x_upper
)
{
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
typedef typename T::type scalar_type;
return find_min_box_constrained(search_strategy,
stop_strategy,
......@@ -581,6 +599,9 @@ namespace dlib
{
// make sure the requires clause is not violated
COMPILE_TIME_ASSERT(is_matrix<T>::value);
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
DLIB_ASSERT (
is_col_vector(x) && is_col_vector(x_lower) && is_col_vector(x_upper) &&
x.size() == x_lower.size() && x.size() == x_upper.size(),
......@@ -673,6 +694,9 @@ namespace dlib
double x_upper
)
{
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
typedef typename T::type scalar_type;
return find_max_box_constrained(search_strategy,
stop_strategy,
......
......@@ -3353,6 +3353,9 @@ L210:
const long max_f_evals
)
{
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
// check the requirements. Also split the assert up so that the error message isn't huge.
DLIB_CASSERT(is_col_vector(x) && is_col_vector(x_lower) && is_col_vector(x_upper) &&
x.size() == x_lower.size() && x_lower.size() == x_upper.size() &&
......@@ -3405,6 +3408,9 @@ L210:
const long max_f_evals
)
{
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
return -find_min_bobyqa(negate_function(f), x, npt, x_lower, x_upper, rho_begin, rho_end, max_f_evals);
}
......
......@@ -190,6 +190,9 @@ namespace dlib
double radius = 1
)
{
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
// make sure requires clause is not broken
DLIB_ASSERT(is_vector(mat(list)) && list.size() > 0 &&
is_col_vector(x) && radius > 0,
......@@ -313,6 +316,9 @@ namespace dlib
double radius = 1
)
{
// The starting point (i.e. x) must be a column vector.
COMPILE_TIME_ASSERT(T::NC <= 1);
// make sure requires clause is not broken
DLIB_ASSERT(is_vector(mat(list)) && list.size() > 0 &&
is_col_vector(x) && radius > 0,
......
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