Better error checking and reporting for linear solvers.

A lot of error checking cruft has accumulated over the years
in the various linear solvers. This change makes the error reporting
more robust and consistent across the various solvers.

Preconditioners are not covered by this change and will be the
subject of a future change.

Change-Id: Ibeb2572a1e67758953dde8d12e3abc6d1df9052d
diff --git a/internal/ceres/dense_normal_cholesky_solver.cc b/internal/ceres/dense_normal_cholesky_solver.cc
index fbf3cbe..e0fe86e 100644
--- a/internal/ceres/dense_normal_cholesky_solver.cc
+++ b/internal/ceres/dense_normal_cholesky_solver.cc
@@ -96,8 +96,17 @@
   LinearSolver::Summary summary;
   summary.num_iterations = 1;
   summary.termination_type = TOLERANCE;
-  VectorRef(x, num_cols) =
-      lhs.selfadjointView<Eigen::Upper>().llt().solve(rhs);
+  Eigen::LLT<Matrix, Eigen::Upper> llt = lhs.selfadjointView<Eigen::Upper>().llt();
+
+  if (llt.info() != Eigen::Success) {
+    summary.termination_type = FAILURE;
+    summary.status = "Eigen LLT decomposition failed.";
+  } else {
+    summary.termination_type = TOLERANCE;
+    summary.status = "Success.";
+  }
+
+  VectorRef(x, num_cols) = llt.solve(rhs);
   event_logger.AddEvent("Solve");
   return summary;
 }
@@ -142,14 +151,13 @@
       A->matrix().transpose() * ConstVectorRef(b, A->num_rows());
   event_logger.AddEvent("Product");
 
-  const int info = LAPACK::SolveInPlaceUsingCholesky(num_cols, lhs.data(), x);
-  event_logger.AddEvent("Solve");
-
   LinearSolver::Summary summary;
   summary.num_iterations = 1;
-  summary.termination_type = info == 0 ? TOLERANCE : FAILURE;
-
-  event_logger.AddEvent("TearDown");
+  summary.termination_type = LAPACK::SolveInPlaceUsingCholesky(num_cols,
+                                                               lhs.data(),
+                                                               x,
+                                                               &summary.status);
+  event_logger.AddEvent("Solve");
   return summary;
 }
 }   // namespace internal