Fix SparseNormalCholeskySolver with dynamic sparsity.

The previous implementation incorrectly cached the outer product matrix
pattern even when `dynamic_sparsity = true`.

Change-Id: I1e58315a9b44f2f457d07c56b203ab2668bfb8a2
diff --git a/internal/ceres/sparse_normal_cholesky_solver.cc b/internal/ceres/sparse_normal_cholesky_solver.cc
index 495ed87..ef9bcc7 100644
--- a/internal/ceres/sparse_normal_cholesky_solver.cc
+++ b/internal/ceres/sparse_normal_cholesky_solver.cc
@@ -203,7 +203,7 @@
   //
   // TODO(sameeragarwal): See note about how this maybe a bad idea for
   // dynamic sparsity.
-  if (outer_product_.get() == NULL) {
+  if (outer_product_.get() == NULL || options_.dynamic_sparsity) {
     outer_product_.reset(
         CompressedRowSparseMatrix::CreateOuterProductMatrixAndProgram(
             *A, &pattern_));
@@ -306,7 +306,7 @@
   // TODO(sameeragarwal): If dynamic sparsity is enabled, then this is
   // not a good idea performance wise, since the jacobian has far too
   // many entries and the program will go crazy with memory.
-  if (outer_product_.get() == NULL) {
+  if (outer_product_.get() == NULL || options_.dynamic_sparsity) {
     outer_product_.reset(
         CompressedRowSparseMatrix::CreateOuterProductMatrixAndProgram(
             *A, &pattern_));