Skip to content

Commit f323fe3

Browse files
authored
Merge pull request #433 from Lucas-Haubert/fix/test_maros_meszaros_eigen5
Unit tests, Maros Meszaros: Redefine function load_qp
2 parents 17da7c2 + f7185f8 commit f323fe3

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1010
- Recursive stub generation for Python bindings ([#419](https://github.com/Simple-Robotics/proxsuite/pull/419))
1111

1212
### Changed
13+
- Redefine the `load_qp` function in the Maros-Meszaros unit tests ([#433])(https://github.com/Simple-Robotics/proxsuite/pull/433)
1314
- Change the default branch to `devel` ([#395](https://github.com/Simple-Robotics/proxsuite/pull/395))
1415
- Change `dual_feasibility` test threshold in `sparse_maros_meszaros` unit test ([#403](https://github.com/Simple-Robotics/proxsuite/pull/403))
1516
- replace `std::numeric_limits<T>::infinity()` by `std::numeric_limits<T>::max()` ([#413](https://github.com/Simple-Robotics/proxsuite/pull/413))

test/include/maros_meszaros.hpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ struct MarosMeszarosQp
1616
Mat A;
1717
Vec l;
1818
Vec u;
19+
20+
bool skip = false;
1921
};
2022

2123
auto
22-
load_qp(char const* filename) -> MarosMeszarosQp
24+
load_qp(char const* filename, bool check_size = false) -> MarosMeszarosQp
2325
{
2426
using Mat = MarosMeszarosQp::Mat;
2527
using Vec = MarosMeszarosQp::Vec;
@@ -30,6 +32,8 @@ load_qp(char const* filename) -> MarosMeszarosQp
3032
proxsuite::linalg::veg::defer([&] { Mat_Close(mat_fp); });
3133
proxsuite::linalg::veg::unused(_mat_fp_cleanup);
3234

35+
bool skip = false;
36+
3337
auto load_mat = [&](char const* name) -> Mat {
3438
matvar_t* mat_var = Mat_VarRead(mat_fp, name);
3539
VEG_ASSERT(mat_var != nullptr);
@@ -44,27 +48,30 @@ load_qp(char const* filename) -> MarosMeszarosQp
4448

4549
isize nrows = isize(mat_var->dims[0]);
4650
isize ncols = isize(mat_var->dims[1]);
51+
Mat out;
4752

48-
auto optr = reinterpret_cast<mat_int32_t const*>(ptr->jc); // NOLINT
49-
auto iptr = reinterpret_cast<mat_int32_t const*>(ptr->ir); // NOLINT
50-
auto vptr = static_cast<double const*>(ptr->data); // NOLINT
53+
if (!check_size || (nrows <= 1000 && ncols <= 1000)) {
54+
auto optr = reinterpret_cast<mat_int32_t const*>(ptr->jc); // NOLINT
55+
auto iptr = reinterpret_cast<mat_int32_t const*>(ptr->ir); // NOLINT
56+
auto vptr = static_cast<double const*>(ptr->data); // NOLINT
5157

52-
Mat out;
53-
out.resize(nrows, ncols);
54-
out.reserve(ptr->nzmax);
55-
for (isize j = 0; j < ncols; ++j) {
56-
isize col_start = optr[j];
57-
isize col_end = optr[j + 1];
58+
out.resize(nrows, ncols);
59+
out.reserve(ptr->nzmax);
60+
for (isize j = 0; j < ncols; ++j) {
61+
isize col_start = optr[j];
62+
isize col_end = optr[j + 1];
5863

59-
for (isize p = col_start; p < col_end; ++p) {
64+
for (isize p = col_start; p < col_end; ++p) {
6065

61-
isize i = iptr[p];
62-
double v = vptr[p];
66+
isize i = iptr[p];
67+
double v = vptr[p];
6368

64-
out.insert(i, j) = v;
69+
out.insert(i, j) = v;
70+
}
6571
}
72+
} else {
73+
skip = true;
6674
}
67-
6875
return out;
6976
};
7077

@@ -86,8 +93,8 @@ load_qp(char const* filename) -> MarosMeszarosQp
8693
};
8794

8895
return {
89-
filename, load_mat("P"), load_vec("q"),
90-
load_mat("A"), load_vec("l"), load_vec("u"),
96+
filename, load_mat("P"), load_vec("q"), load_mat("A"),
97+
load_vec("l"), load_vec("u"), skip,
9198
};
9299
}
93100

test/src/dense_maros_meszaros.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,19 @@ TEST_CASE("dense maros meszaros using the api")
9090
T elapsed_time = 0.0;
9191

9292
for (auto const* file : files) {
93-
auto qp = load_qp(file);
93+
auto qp = load_qp(file, true);
9494
isize n = qp.P.rows();
9595
isize n_eq_in = qp.A.rows();
9696

97-
const bool skip = n > 1000 || n_eq_in > 1000;
98-
if (skip) {
97+
if (qp.skip) {
9998
std::cout << " path: " << qp.filename << " n: " << n
10099
<< " n_eq+n_in: " << n_eq_in << " - skipping" << std::endl;
101100
} else {
102101
std::cout << " path: " << qp.filename << " n: " << n
103102
<< " n_eq+n_in: " << n_eq_in << std::endl;
104103
}
105104

106-
if (!skip) {
105+
if (!qp.skip) {
107106

108107
auto preprocessed = preprocess_qp(qp);
109108
auto& H = preprocessed.H;

test/src/sparse_maros_meszaros.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,19 @@ TEST_CASE("sparse maros meszaros using the API")
117117
const T eps_abs_with_duality_gap = 1e-5;
118118

119119
for (auto const* file : files) {
120-
auto qp_raw = load_qp(file);
120+
auto qp_raw = load_qp(file, true);
121121
isize n = qp_raw.P.rows();
122122
isize n_eq_in = qp_raw.A.rows();
123123

124-
bool skip = (n > 1000 || n_eq_in > 1000);
125-
if (skip) {
124+
if (qp_raw.skip) {
126125
std::cout << " path: " << qp_raw.filename << " n: " << n
127126
<< " n_eq+n_in: " << n_eq_in << " - SKIPPING" << std::endl;
128127
} else {
129128
std::cout << " path: " << qp_raw.filename << " n: " << n
130129
<< " n_eq+n_in: " << n_eq_in << std::endl;
131130
}
132131

133-
if (!skip) {
132+
if (!qp_raw.skip) {
134133

135134
auto preprocessed = preprocess_qp_sparse(VEG_FWD(qp_raw));
136135
auto& H = preprocessed.H;

0 commit comments

Comments
 (0)