Fixed an invalid DCHECK in suitesparse.cc
There was a overzealous DCHECK in suitesparse.cc when converting
a scalar matrix into a block matrix. This stemmed from my poor
understanding of how lower_bound works.
The test for this function was not stringent enough, and was
not run in debug mode for this to get triggered. The test
has been updated, it fails without the fix and runs correctly
with it.
Thanks to Markus Moll for reporting this and suggesting the
fix.
Change-Id: Ide6b971fd4c618ef5e240f500f514c4b78d7b6e3
diff --git a/internal/ceres/suitesparse.cc b/internal/ceres/suitesparse.cc
index c02d305..96c1d6c 100644
--- a/internal/ceres/suitesparse.cc
+++ b/internal/ceres/suitesparse.cc
@@ -224,7 +224,7 @@
vector<int>::const_iterator it = lower_bound(row_block_starts.begin(),
row_block_starts.end(),
scalar_rows[idx]);
- DCHECK(it != row_block_starts.end());
+
// Only consider the first row of each row block.
if (*it != scalar_rows[idx]) {
continue;
diff --git a/internal/ceres/suitesparse_test.cc b/internal/ceres/suitesparse_test.cc
index 0dc418f..7e688d9 100644
--- a/internal/ceres/suitesparse_test.cc
+++ b/internal/ceres/suitesparse_test.cc
@@ -115,7 +115,7 @@
// [1 2 3 2]
// [1] x x
// [2] x x
- // [1] x x
+ // [2] x x
// num_nonzeros = 1 + 3 + 4 + 4 + 1 + 2 = 15
vector<int> col_blocks;
@@ -127,12 +127,12 @@
vector<int> row_blocks;
row_blocks.push_back(1);
row_blocks.push_back(2);
- row_blocks.push_back(1);
+ row_blocks.push_back(2);
- TripletSparseMatrix tsm(4, 8, 15);
+ TripletSparseMatrix tsm(5, 8, 18);
int* rows = tsm.mutable_rows();
int* cols = tsm.mutable_cols();
- fill(tsm.mutable_values(), tsm.mutable_values() + 15, 1.0);
+ fill(tsm.mutable_values(), tsm.mutable_values() + 18, 1.0);
int offset = 0;
#define CERES_TEST_FILL_BLOCK(row_block_id, col_block_id) \