@@ -100,40 +100,45 @@ struct Model
100100
101101 bool is_valid (const bool box_constraints)
102102 {
103- #define PROXSUITE_CHECK_SIZE (size, expected_size ) \
104- if (size != 0 ) { \
105- if (!(size == expected_size)) \
106- return false ; \
107- }
108-
109103 // check that all matrices and vectors of qpmodel have the correct size
110104 // and that H and C have expected properties
111- PROXSUITE_CHECK_SIZE (g.size (), dim);
112- PROXSUITE_CHECK_SIZE (b.size (), n_eq);
113- PROXSUITE_CHECK_SIZE (u.size (), n_in);
114- PROXSUITE_CHECK_SIZE (l.size (), n_in);
105+ PROXSUITE_CHECK_ARGUMENT_SIZE (g.size (), dim, " g has not the expected size." )
106+ PROXSUITE_CHECK_ARGUMENT_SIZE (
107+ b.size (), n_eq, " b has not the expected size." )
108+ PROXSUITE_CHECK_ARGUMENT_SIZE (
109+ l.size (), n_in, " l has not the expected size." )
110+ PROXSUITE_CHECK_ARGUMENT_SIZE (
111+ u.size (), n_in, " u has not the expected size." )
115112 if (box_constraints) {
116- PROXSUITE_CHECK_SIZE (u_box.size (), dim);
117- PROXSUITE_CHECK_SIZE (l_box.size (), dim);
113+ PROXSUITE_CHECK_ARGUMENT_SIZE (
114+ u_box.size (), dim, " u_box has not the expected size" );
115+ PROXSUITE_CHECK_ARGUMENT_SIZE (
116+ l_box.size (), dim, " l_box has not the expected size" );
118117 }
119118 if (H.size ()) {
120- PROXSUITE_CHECK_SIZE (H.rows (), dim);
121- PROXSUITE_CHECK_SIZE (H.cols (), dim);
122- if (!H.isApprox (H.transpose (), 0.0 ))
123- return false ;
119+ PROXSUITE_CHECK_ARGUMENT_SIZE (
120+ H.rows (), dim, " H has not the expected number of rows." );
121+ PROXSUITE_CHECK_ARGUMENT_SIZE (
122+ H.cols (), dim, " H has not the expected number of cols." );
123+ PROXSUITE_THROW_PRETTY ((!H.isApprox (H.transpose (), 0.0 )),
124+ std::invalid_argument,
125+ " H is not symmetric." );
124126 }
125127 if (A.size ()) {
126- PROXSUITE_CHECK_SIZE (A.rows (), n_eq);
127- PROXSUITE_CHECK_SIZE (A.cols (), dim);
128+ PROXSUITE_CHECK_ARGUMENT_SIZE (
129+ A.rows (), n_eq, " A has not the expected number of rows." );
130+ PROXSUITE_CHECK_ARGUMENT_SIZE (
131+ A.cols (), dim, " A has not the expected number of cols." );
128132 }
129133 if (C.size ()) {
130- PROXSUITE_CHECK_SIZE (C.rows (), n_in);
131- PROXSUITE_CHECK_SIZE (C.cols (), dim);
132- if (C.isZero ())
133- return false ;
134+ PROXSUITE_CHECK_ARGUMENT_SIZE (
135+ C.rows (), n_in, " C has not the expected number of rows." );
136+ PROXSUITE_CHECK_ARGUMENT_SIZE (
137+ C.cols (), dim, " C has not the expected number of cols." );
138+ PROXSUITE_THROW_PRETTY (
139+ C.isZero (), std::invalid_argument, " C is zero, while n_in != 0." );
134140 }
135141 return true ;
136- #undef PROXSUITE_CHECK_SIZE
137142 }
138143};
139144
0 commit comments