Fix three out of bounds errors in CompressedRowSparseMatrix.

All three errors are of the form where, the vector storing
the columns array for a CompressedRowSparseMatrix is being
accessed out of bounds. But in each case, the access is innocuous
because there are other tests which prevent it from being used.

However, if one compiles with debug mode on, the bounds checking
in the underlying std::vector triggers an error.

More details:

1. FromTripletSparseMatrix tried accessing the col vector of
   a matrix with zero rows, but the following code was a no-op
   because there was nothing to copy.

   Adding an early return which deals with this case fixes this.

2. RightMultiply and SquaredColumnNorm had the following loop

   while (r > cols_[idx] && idx < idx_end) {
        ++idx;
   }

   where cols_ was being accessed out of bounds, before idx < idx_end
   was being checked. Swapping the order of the comparisons fixes this
   error.

@richmattes reported this error.

https://github.com/ceres-solver/ceres-solver/issues/383

Change-Id: I2dbc90ef24ecaffc6f46f1622339d6053b43db45
1 file changed
tree: a6325af5094d9d638420775960dc2a0c1f07e4b2
  1. bazel/
  2. cmake/
  3. config/
  4. data/
  5. docs/
  6. examples/
  7. include/
  8. internal/
  9. scripts/
  10. travis/
  11. .gitignore
  12. .travis.yml
  13. BUILD
  14. CMakeLists.txt
  15. CONTRIBUTING.md
  16. LICENSE
  17. package.xml
  18. README.md
  19. WORKSPACE
README.md

Build Status

Ceres Solver

Ceres Solver is an open source C++ library for modeling and solving large, complicated optimization problems. It is a feature rich, mature and performant library which has been used in production at Google since 2010. Ceres Solver can solve two kinds of problems.

  1. Non-linear Least Squares problems with bounds constraints.
  2. General unconstrained optimization problems.

Please see ceres-solver.org for more information.