Parameterize the Schur complement solver tests

The tests repeat the same comparison for a hand-picked subset of solver
configurations and only three of the available problems. Run a single
value-parameterized test over all available solver configurations and
all Schur structured problems, including random ones.

Fixes #277

Change-Id: I201f2612da0abc3bdbfad1f7b5f9eeb4ba31ac01
diff --git a/internal/ceres/schur_complement_solver_test.cc b/internal/ceres/schur_complement_solver_test.cc
index 349f6b1..34205c8 100644
--- a/internal/ceres/schur_complement_solver_test.cc
+++ b/internal/ceres/schur_complement_solver_test.cc
@@ -30,183 +30,341 @@
 
 #include "ceres/schur_complement_solver.h"
 
-#include <cstddef>
+#include <algorithm>
+#include <cmath>
+#include <cstdint>
+#include <functional>
+#include <initializer_list>
 #include <memory>
+#include <ostream>
+#include <random>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <vector>
 
+#include "absl/strings/str_format.h"
 #include "ceres/block_sparse_matrix.h"
 #include "ceres/block_structure.h"
 #include "ceres/casts.h"
 #include "ceres/context_impl.h"
+#include "ceres/dense_sparse_matrix.h"
 #include "ceres/detect_structure.h"
+#include "ceres/eigen.h"
+#include "ceres/internal/config.h"
 #include "ceres/linear_least_squares_problems.h"
 #include "ceres/linear_solver.h"
+#include "ceres/test_util.h"
 #include "ceres/triplet_sparse_matrix.h"
 #include "ceres/types.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 namespace ceres::internal {
+namespace {
 
-class SchurComplementSolverTest : public ::testing::Test {
- protected:
-  void SetUpFromProblemId(int problem_id) {
-    std::unique_ptr<LinearLeastSquaresProblem> problem =
-        CreateLinearLeastSquaresProblemFromId(problem_id);
-
-    ASSERT_TRUE(problem != nullptr);
-    A.reset(down_cast<BlockSparseMatrix*>(problem->A.release()));
-    b = std::move(problem->b);
-    D = std::move(problem->D);
-
-    num_cols = A->num_cols();
-    num_rows = A->num_rows();
-    num_eliminate_blocks = problem->num_eliminate_blocks;
-
-    x.resize(num_cols);
-    sol.resize(num_cols);
-    sol_d.resize(num_cols);
-
-    LinearSolver::Options options;
-    options.type = DENSE_QR;
-    ContextImpl context;
-    options.context = &context;
-
-    std::unique_ptr<LinearSolver> qr(LinearSolver::Create(options));
-
-    TripletSparseMatrix triplet_A(
-        A->num_rows(), A->num_cols(), A->num_nonzeros());
-    A->ToTripletSparseMatrix(&triplet_A);
-
-    // Gold standard solutions using dense QR factorization.
-    DenseSparseMatrix dense_A(triplet_A);
-    LinearSolver::Summary summary = qr->Solve(
-        &dense_A, b.get(), LinearSolver::PerSolveOptions(), sol.data());
-    ASSERT_EQ(summary.termination_type, LinearSolverTerminationType::SUCCESS);
-
-    // Gold standard solution with appended diagonal.
-    LinearSolver::PerSolveOptions per_solve_options;
-    per_solve_options.D = D.get();
-    summary = qr->Solve(&dense_A, b.get(), per_solve_options, sol_d.data());
-    ASSERT_EQ(summary.termination_type, LinearSolverTerminationType::SUCCESS);
-  }
-
-  void ComputeAndCompareSolutions(
-      int problem_id,
-      bool regularization,
-      ceres::LinearSolverType linear_solver_type,
-      ceres::DenseLinearAlgebraLibraryType dense_linear_algebra_library_type,
-      ceres::SparseLinearAlgebraLibraryType sparse_linear_algebra_library_type,
-      ceres::internal::OrderingType ordering_type) {
-    SetUpFromProblemId(problem_id);
-    LinearSolver::Options options;
-    options.elimination_groups.push_back(num_eliminate_blocks);
-    options.elimination_groups.push_back(A->block_structure()->cols.size() -
-                                         num_eliminate_blocks);
-    options.type = linear_solver_type;
-    options.dense_linear_algebra_library_type =
-        dense_linear_algebra_library_type;
-    options.sparse_linear_algebra_library_type =
-        sparse_linear_algebra_library_type;
-    options.ordering_type = ordering_type;
-    options.use_explicit_schur_complement = true;
-    options.preconditioner_type = SCHUR_JACOBI;
-    options.max_num_iterations = num_cols;
-    ContextImpl context;
-    options.context = &context;
-    DetectStructure(*A->block_structure(),
-                    num_eliminate_blocks,
-                    &options.row_block_size,
-                    &options.e_block_size,
-                    &options.f_block_size);
-
-    std::unique_ptr<LinearSolver> solver(LinearSolver::Create(options));
-
-    LinearSolver::PerSolveOptions per_solve_options;
-    per_solve_options.r_tolerance = 1e-12;
-    LinearSolver::Summary summary;
-    if (regularization) {
-      per_solve_options.D = D.get();
-    }
-
-    summary = solver->Solve(A.get(), b.get(), per_solve_options, x.data());
-    EXPECT_EQ(summary.termination_type, LinearSolverTerminationType::SUCCESS);
-
-    if (regularization) {
-      ASSERT_NEAR((sol_d - x).norm() / num_cols, 0, 1e-10)
-          << "Regularized Expected solution: " << sol_d.transpose()
-          << " Actual solution: " << x.transpose();
-    } else {
-      ASSERT_NEAR((sol - x).norm() / num_cols, 0, 1e-10)
-          << "Unregularized Expected solution: " << sol.transpose()
-          << " Actual solution: " << x.transpose();
-    }
-  }
-
-  int num_rows;
-  int num_cols;
-  int num_eliminate_blocks;
-
-  std::unique_ptr<BlockSparseMatrix> A;
-  std::unique_ptr<double[]> b;
-  std::unique_ptr<double[]> D;
-  Vector x;
-  Vector sol;
-  Vector sol_d;
+// The configuration of a Schur complement based linear solver.
+struct SolverConfig {
+  LinearSolverType type;
+  DenseLinearAlgebraLibraryType dense_linear_algebra_library_type;
+  SparseLinearAlgebraLibraryType sparse_linear_algebra_library_type;
+  OrderingType ordering_type;
 };
 
-// TODO(sameeragarwal): Refactor these using value parameterized tests.
-// TODO(sameeragarwal): More extensive tests using random matrices.
-TEST_F(SchurComplementSolverTest, DenseSchurWithEigenSmallProblem) {
-  ComputeAndCompareSolutions(
-      2, false, DENSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NATURAL);
-  ComputeAndCompareSolutions(
-      2, true, DENSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NATURAL);
+void PrintTo(const SolverConfig& config, std::ostream* os) {
+  if (config.type == ITERATIVE_SCHUR) {
+    *os << absl::StrFormat("%s_EXPLICIT",
+                           LinearSolverTypeToString(config.type));
+  } else if (config.type == DENSE_SCHUR) {
+    *os << absl::StrFormat("%s_%s",
+                           LinearSolverTypeToString(config.type),
+                           DenseLinearAlgebraLibraryTypeToString(
+                               config.dense_linear_algebra_library_type));
+  } else {
+    *os << absl::StrFormat("%s_%s_",
+                           LinearSolverTypeToString(config.type),
+                           SparseLinearAlgebraLibraryTypeToString(
+                               config.sparse_linear_algebra_library_type))
+        << config.ordering_type;
+  }
 }
 
-TEST_F(SchurComplementSolverTest, DenseSchurWithEigenLargeProblem) {
-  ComputeAndCompareSolutions(
-      3, false, DENSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NATURAL);
-  ComputeAndCompareSolutions(
-      3, true, DENSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NATURAL);
+// Returns the configurations of the Schur complement solvers available in the
+// current build. The ITERATIVE_SCHUR configuration solves the explicit Schur
+// complement.
+std::vector<SolverConfig> SolverConfigs() {
+  std::vector<SolverConfig> configs{
+      {DENSE_SCHUR, EIGEN, NO_SPARSE, OrderingType::NATURAL},
+#ifndef CERES_NO_LAPACK
+      {DENSE_SCHUR, LAPACK, NO_SPARSE, OrderingType::NATURAL},
+#endif  // CERES_NO_LAPACK
+      {ITERATIVE_SCHUR, EIGEN, NO_SPARSE, OrderingType::NATURAL},
+  };
+
+  const auto add_sparse_configs =
+      [&configs](SparseLinearAlgebraLibraryType library,
+                 std::initializer_list<OrderingType> ordering_types) {
+        for (const OrderingType ordering_type : ordering_types) {
+          configs.push_back({SPARSE_SCHUR, EIGEN, library, ordering_type});
+        }
+      };
+#ifndef CERES_NO_SUITESPARSE
+  add_sparse_configs(SUITE_SPARSE,
+                     {
+                         OrderingType::NATURAL,
+                         OrderingType::AMD,
+#ifndef CERES_NO_CHOLMOD_PARTITION
+                         OrderingType::NESDIS,
+#endif  // CERES_NO_CHOLMOD_PARTITION
+                     });
+#endif  // CERES_NO_SUITESPARSE
+#ifndef CERES_NO_ACCELERATE_SPARSE
+  add_sparse_configs(ACCELERATE_SPARSE,
+                     {OrderingType::AMD, OrderingType::NESDIS});
+#endif  // CERES_NO_ACCELERATE_SPARSE
+#ifdef CERES_USE_EIGEN_SPARSE
+  add_sparse_configs(EIGEN_SPARSE,
+                     {
+                         OrderingType::NATURAL,
+                         OrderingType::AMD,
+#ifndef CERES_NO_EIGEN_METIS
+                         OrderingType::NESDIS,
+#endif  // CERES_NO_EIGEN_METIS
+                     });
+#endif  // CERES_USE_EIGEN_SPARSE
+  return configs;
 }
 
-TEST_F(SchurComplementSolverTest, DenseSchurWithEigenVaryingFBlockSize) {
-  ComputeAndCompareSolutions(
-      4, true, DENSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NATURAL);
+// Creates a random problem with the block structure required by the Schur
+// complement solvers. Each row block contains at most one cell in the first
+// num_e_blocks column blocks, which precedes its remaining cells, and the
+// row blocks containing such a cell precede the remaining row blocks. Every
+// column block is covered by more rows than columns, so the matrix has full
+// column rank almost surely.
+std::unique_ptr<LinearLeastSquaresProblem> CreateRandomSchurProblem(
+    int num_e_blocks, int num_f_blocks, std::uint32_t seed) {
+  constexpr int kMinBlockSize = 1;
+  constexpr int kMaxBlockSize = 3;
+  constexpr double kFBlockProbability = 0.5;
+  std::mt19937 prng(seed);
+  std::uniform_int_distribution<int> block_size(kMinBlockSize, kMaxBlockSize);
+  std::bernoulli_distribution has_f_cell(kFBlockProbability);
+  std::uniform_real_distribution<double> value(-1.0, 1.0);
+
+  auto* bs = new CompressedRowBlockStructure;
+  int num_cols = 0;
+  for (int i = 0; i < num_e_blocks + num_f_blocks; ++i) {
+    bs->cols.emplace_back(block_size(prng), num_cols);
+    num_cols += bs->cols.back().size;
+  }
+
+  int num_rows = 0;
+  int num_nonzeros = 0;
+  // Appends row blocks containing the given column block until it is covered
+  // by more rows than columns. Every row block also contains a random subset
+  // of the F blocks. The cells are ordered by their column block.
+  const auto add_row_blocks = [&](int col_block_id) {
+    const int col_block_size = bs->cols[col_block_id].size;
+    for (int covered_rows = 0; covered_rows <= col_block_size;) {
+      CompressedRow row;
+      row.block = Block(block_size(prng), num_rows);
+      const auto add_cell = [&row, &num_nonzeros, bs](int cell_block_id) {
+        row.cells.emplace_back(cell_block_id, num_nonzeros);
+        num_nonzeros += row.block.size * bs->cols[cell_block_id].size;
+      };
+      if (col_block_id < num_e_blocks) {
+        add_cell(col_block_id);
+      }
+      for (int f = num_e_blocks; f < num_e_blocks + num_f_blocks; ++f) {
+        if (f == col_block_id || has_f_cell(prng)) {
+          add_cell(f);
+        }
+      }
+      num_rows += row.block.size;
+      covered_rows += row.block.size;
+      bs->rows.push_back(std::move(row));
+    }
+  };
+  for (int col_block_id = 0; col_block_id < num_e_blocks + num_f_blocks;
+       ++col_block_id) {
+    add_row_blocks(col_block_id);
+  }
+
+  auto A = std::make_unique<BlockSparseMatrix>(bs);
+  std::generate_n(A->mutable_values(), A->num_nonzeros(), [&value, &prng] {
+    return value(prng);
+  });
+
+  auto problem = std::make_unique<LinearLeastSquaresProblem>();
+  problem->A = std::move(A);
+  problem->b = std::make_unique<double[]>(num_rows);
+  std::generate_n(
+      problem->b.get(), num_rows, [&value, &prng] { return value(prng); });
+  problem->D = std::make_unique<double[]>(num_cols);
+  std::generate_n(problem->D.get(), num_cols, [&value, &prng] {
+    return 1.0 + std::abs(value(prng));
+  });
+  problem->num_eliminate_blocks = num_e_blocks;
+  return problem;
 }
 
-TEST_F(SchurComplementSolverTest, ExplicitSchurSmallProblem) {
-  ComputeAndCompareSolutions(
-      2, false, ITERATIVE_SCHUR, EIGEN, NO_SPARSE, OrderingType::NATURAL);
-  ComputeAndCompareSolutions(
-      2, true, ITERATIVE_SCHUR, EIGEN, NO_SPARSE, OrderingType::NATURAL);
+// A linear least squares problem and whether to regularize it.
+struct ProblemConfig {
+  std::string name;
+  std::function<std::unique_ptr<LinearLeastSquaresProblem>()> create;
+  bool regularization;
+};
+
+void PrintTo(const ProblemConfig& config, std::ostream* os) {
+  *os << absl::StrFormat(
+      "%s_%s",
+      config.name,
+      config.regularization ? "Regularized" : "Unregularized");
 }
 
-TEST_F(SchurComplementSolverTest, ExplicitSchurLargeProblem) {
-  ComputeAndCompareSolutions(
-      3, false, ITERATIVE_SCHUR, EIGEN, NO_SPARSE, OrderingType::NATURAL);
-  ComputeAndCompareSolutions(
-      3, true, ITERATIVE_SCHUR, EIGEN, NO_SPARSE, OrderingType::NATURAL);
+std::vector<ProblemConfig> ProblemConfigs() {
+  std::vector<ProblemConfig> configs;
+  const auto add_problem =
+      [&configs](
+          const std::string& name,
+          const std::function<std::unique_ptr<LinearLeastSquaresProblem>()>&
+              create,
+          bool full_rank) {
+        if (full_rank) {
+          configs.push_back({name, create, /*regularization=*/false});
+        }
+        configs.push_back({name, create, /*regularization=*/true});
+      };
+
+  // Problems 4 and 6 are rank deficient without the regularization.
+  for (const auto& [id, full_rank] : {std::pair{2, true},
+                                      std::pair{3, true},
+                                      std::pair{4, false},
+                                      std::pair{5, true},
+                                      std::pair{6, false}}) {
+    add_problem(
+        absl::StrFormat("Problem%d", id),
+        [id = id] { return CreateLinearLeastSquaresProblemFromId(id); },
+        full_rank);
+  }
+
+  constexpr int kNumRandomProblems = 3;
+  for (std::uint32_t seed = 0; seed < kNumRandomProblems; ++seed) {
+    const int num_e_blocks = 2 + 3 * seed;
+    const int num_f_blocks = 1 + 2 * seed;
+    add_problem(
+        absl::StrFormat("Random%dx%d", num_e_blocks, num_f_blocks),
+        [num_e_blocks, num_f_blocks, seed] {
+          return CreateRandomSchurProblem(num_e_blocks, num_f_blocks, seed);
+        },
+        /*full_rank=*/true);
+  }
+  return configs;
 }
 
-TEST_F(SchurComplementSolverTest, ExplicitSchurVaryingFBlockSize) {
-  ComputeAndCompareSolutions(
-      4, true, ITERATIVE_SCHUR, EIGEN, NO_SPARSE, OrderingType::NATURAL);
+using Param = std::tuple<SolverConfig, ProblemConfig>;
+
+std::string ParamInfoToString(const ::testing::TestParamInfo<Param>& info) {
+  return absl::StrFormat("%s_%s",
+                         ::testing::PrintToString(std::get<0>(info.param)),
+                         ::testing::PrintToString(std::get<1>(info.param)));
 }
 
-TEST_F(SchurComplementSolverTest,
-       ExplicitIterativeSchurBackSubstitutesOnNoConvergence) {
-  SetUpFromProblemId(2);
+class SchurComplementSolverTest : public ::testing::TestWithParam<Param> {};
+
+// Compares the solution of the Schur complement solver to the one of the dense
+// QR solver.
+TEST_P(SchurComplementSolverTest, MatchesDenseQR) {
+  const auto& [solver_config, problem_config] = GetParam();
+  std::unique_ptr<LinearLeastSquaresProblem> problem = problem_config.create();
+  ASSERT_NE(problem, nullptr);
+  auto* A = down_cast<BlockSparseMatrix*>(problem->A.get());
+  const int num_cols = A->num_cols();
+
+  LinearSolver::PerSolveOptions per_solve_options;
+  if (problem_config.regularization) {
+    per_solve_options.D = problem->D.get();
+  }
+
+  ContextImpl context;
+  LinearSolver::Options qr_options;
+  qr_options.type = DENSE_QR;
+  qr_options.context = &context;
+  std::unique_ptr<LinearSolver> qr(LinearSolver::Create(qr_options));
+  TripletSparseMatrix triplet_A(
+      A->num_rows(), A->num_cols(), A->num_nonzeros());
+  A->ToTripletSparseMatrix(&triplet_A);
+  DenseSparseMatrix dense_A(triplet_A);
+  Vector expected(num_cols);
+  ASSERT_EQ(
+      qr->Solve(&dense_A, problem->b.get(), per_solve_options, expected.data())
+          .termination_type,
+      LinearSolverTerminationType::SUCCESS);
+
   LinearSolver::Options options;
-  options.elimination_groups.push_back(num_eliminate_blocks);
+  options.type = solver_config.type;
+  options.dense_linear_algebra_library_type =
+      solver_config.dense_linear_algebra_library_type;
+  options.sparse_linear_algebra_library_type =
+      solver_config.sparse_linear_algebra_library_type;
+  options.ordering_type = solver_config.ordering_type;
+  // Conjugate gradients converges in at most as many iterations as the Schur
+  // complement has columns, which are fewer than the columns of A.
+  options.use_explicit_schur_complement = true;
+  options.preconditioner_type = SCHUR_JACOBI;
+  options.max_num_iterations = num_cols;
+  options.context = &context;
+  options.elimination_groups.push_back(problem->num_eliminate_blocks);
   options.elimination_groups.push_back(A->block_structure()->cols.size() -
-                                       num_eliminate_blocks);
+                                       problem->num_eliminate_blocks);
+  DetectStructure(*A->block_structure(),
+                  problem->num_eliminate_blocks,
+                  &options.row_block_size,
+                  &options.e_block_size,
+                  &options.f_block_size);
+  std::unique_ptr<LinearSolver> solver(LinearSolver::Create(options));
+
+  constexpr double kResidualTolerance = 1e-12;
+  per_solve_options.r_tolerance = kResidualTolerance;
+  Vector actual(num_cols);
+  const LinearSolver::Summary summary =
+      solver->Solve(A, problem->b.get(), per_solve_options, actual.data());
+  ASSERT_EQ(summary.termination_type, LinearSolverTerminationType::SUCCESS)
+      << summary.message;
+
+  // The tolerance applies to the norm of the difference divided by the number
+  // of columns.
+  constexpr double kTolerance = 1e-10;
+  EXPECT_THAT(actual, NormNear(expected, kTolerance * num_cols));
+}
+
+INSTANTIATE_TEST_SUITE_P(
+    SchurComplementSolver,
+    SchurComplementSolverTest,
+    ::testing::Combine(::testing::ValuesIn(SolverConfigs()),
+                       ::testing::ValuesIn(ProblemConfigs())),
+    ParamInfoToString);
+
+TEST(SchurComplementSolver,
+     ExplicitIterativeSchurBackSubstitutesOnNoConvergence) {
+  constexpr int kProblemId = 2;
+  std::unique_ptr<LinearLeastSquaresProblem> problem =
+      CreateLinearLeastSquaresProblemFromId(kProblemId);
+  ASSERT_NE(problem, nullptr);
+  auto* A = down_cast<BlockSparseMatrix*>(problem->A.get());
+  const int num_cols = A->num_cols();
+
+  ContextImpl context;
+  LinearSolver::Options options;
   options.type = ITERATIVE_SCHUR;
   options.preconditioner_type = SCHUR_JACOBI;
   options.max_num_iterations = 1;
-  ContextImpl context;
   options.context = &context;
+  options.elimination_groups.push_back(problem->num_eliminate_blocks);
+  options.elimination_groups.push_back(A->block_structure()->cols.size() -
+                                       problem->num_eliminate_blocks);
   DetectStructure(*A->block_structure(),
-                  num_eliminate_blocks,
+                  problem->num_eliminate_blocks,
                   &options.row_block_size,
                   &options.e_block_size,
                   &options.f_block_size);
@@ -214,176 +372,31 @@
   LinearSolver::PerSolveOptions per_solve_options;
   per_solve_options.r_tolerance = 0.0;
   per_solve_options.q_tolerance = 0.0;
-  per_solve_options.D = D.get();
+  per_solve_options.D = problem->D.get();
 
   options.use_explicit_schur_complement = false;
   std::unique_ptr<LinearSolver> implicit_solver(LinearSolver::Create(options));
   Vector x_implicit(num_cols);
-  LinearSolver::Summary implicit_summary = implicit_solver->Solve(
-      A.get(), b.get(), per_solve_options, x_implicit.data());
-  ASSERT_EQ(implicit_summary.termination_type,
-            LinearSolverTerminationType::NO_CONVERGENCE);
+  ASSERT_EQ(
+      implicit_solver
+          ->Solve(A, problem->b.get(), per_solve_options, x_implicit.data())
+          .termination_type,
+      LinearSolverTerminationType::NO_CONVERGENCE);
 
   options.use_explicit_schur_complement = true;
   std::unique_ptr<LinearSolver> explicit_solver(LinearSolver::Create(options));
   Vector x_explicit(num_cols);
-  LinearSolver::Summary explicit_summary = explicit_solver->Solve(
-      A.get(), b.get(), per_solve_options, x_explicit.data());
-  ASSERT_EQ(explicit_summary.termination_type,
-            LinearSolverTerminationType::NO_CONVERGENCE);
+  ASSERT_EQ(
+      explicit_solver
+          ->Solve(A, problem->b.get(), per_solve_options, x_explicit.data())
+          .termination_type,
+      LinearSolverTerminationType::NO_CONVERGENCE);
 
-  EXPECT_NEAR((x_implicit - x_explicit).norm() / num_cols, 0.0, 1e-10);
+  // The tolerance applies to the norm of the difference divided by the number
+  // of columns.
+  constexpr double kTolerance = 1e-10;
+  EXPECT_THAT(x_explicit, NormNear(x_implicit, kTolerance * num_cols));
 }
 
-#ifndef CERES_NO_LAPACK
-TEST_F(SchurComplementSolverTest, DenseSchurWithLAPACKSmallProblem) {
-  ComputeAndCompareSolutions(
-      2, false, DENSE_SCHUR, LAPACK, SUITE_SPARSE, OrderingType::NATURAL);
-  ComputeAndCompareSolutions(
-      2, true, DENSE_SCHUR, LAPACK, SUITE_SPARSE, OrderingType::NATURAL);
-}
-
-TEST_F(SchurComplementSolverTest, DenseSchurWithLAPACKLargeProblem) {
-  ComputeAndCompareSolutions(
-      3, false, DENSE_SCHUR, LAPACK, SUITE_SPARSE, OrderingType::NATURAL);
-  ComputeAndCompareSolutions(
-      3, true, DENSE_SCHUR, LAPACK, SUITE_SPARSE, OrderingType::NATURAL);
-}
-#endif
-
-#ifndef CERES_NO_SUITESPARSE
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithSuiteSparseSmallProblemNATURAL) {
-  ComputeAndCompareSolutions(
-      2, false, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NATURAL);
-  ComputeAndCompareSolutions(
-      2, true, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NATURAL);
-}
-
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithSuiteSparseLargeProblemNATURAL) {
-  ComputeAndCompareSolutions(
-      3, false, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NATURAL);
-  ComputeAndCompareSolutions(
-      3, true, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NATURAL);
-}
-
-TEST_F(SchurComplementSolverTest, SparseSchurWithSuiteSparseSmallProblemAMD) {
-  ComputeAndCompareSolutions(
-      2, false, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::AMD);
-  ComputeAndCompareSolutions(
-      2, true, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::AMD);
-}
-
-TEST_F(SchurComplementSolverTest, SparseSchurWithSuiteSparseLargeProblemAMD) {
-  ComputeAndCompareSolutions(
-      3, false, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::AMD);
-  ComputeAndCompareSolutions(
-      3, true, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::AMD);
-}
-
-#ifndef CERES_NO_CHOLMOD_PARTITION
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithSuiteSparseSmallProblemNESDIS) {
-  ComputeAndCompareSolutions(
-      2, false, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NESDIS);
-  ComputeAndCompareSolutions(
-      2, true, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NESDIS);
-}
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithSuiteSparseLargeProblemNESDIS) {
-  ComputeAndCompareSolutions(
-      3, false, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NESDIS);
-  ComputeAndCompareSolutions(
-      3, true, SPARSE_SCHUR, EIGEN, SUITE_SPARSE, OrderingType::NESDIS);
-}
-#endif  // CERES_NO_CHOLMOD_PARTITION
-#endif  // CERES_NO_SUITESPARSE
-
-#ifndef CERES_NO_ACCELERATE_SPARSE
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithAccelerateSparseSmallProblemAMD) {
-  ComputeAndCompareSolutions(
-      2, false, SPARSE_SCHUR, EIGEN, ACCELERATE_SPARSE, OrderingType::AMD);
-  ComputeAndCompareSolutions(
-      2, true, SPARSE_SCHUR, EIGEN, ACCELERATE_SPARSE, OrderingType::AMD);
-}
-
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithAccelerateSparseSmallProblemNESDIS) {
-  ComputeAndCompareSolutions(
-      2, false, SPARSE_SCHUR, EIGEN, ACCELERATE_SPARSE, OrderingType::NESDIS);
-  ComputeAndCompareSolutions(
-      2, true, SPARSE_SCHUR, EIGEN, ACCELERATE_SPARSE, OrderingType::NESDIS);
-}
-
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithAccelerateSparseLargeProblemAMD) {
-  ComputeAndCompareSolutions(
-      3, false, SPARSE_SCHUR, EIGEN, ACCELERATE_SPARSE, OrderingType::AMD);
-  ComputeAndCompareSolutions(
-      3, true, SPARSE_SCHUR, EIGEN, ACCELERATE_SPARSE, OrderingType::AMD);
-}
-
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithAccelerateSparseLargeProblemNESDIS) {
-  ComputeAndCompareSolutions(
-      3, false, SPARSE_SCHUR, EIGEN, ACCELERATE_SPARSE, OrderingType::NESDIS);
-  ComputeAndCompareSolutions(
-      3, true, SPARSE_SCHUR, EIGEN, ACCELERATE_SPARSE, OrderingType::NESDIS);
-}
-#endif  // CERES_NO_ACCELERATE_SPARSE
-
-#ifdef CERES_USE_EIGEN_SPARSE
-TEST_F(SchurComplementSolverTest, SparseSchurWithEigenSparseSmallProblemAMD) {
-  ComputeAndCompareSolutions(
-      2, false, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::AMD);
-  ComputeAndCompareSolutions(
-      2, true, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::AMD);
-}
-
-#ifndef CERES_NO_EIGEN_METIS
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithEigenSparseSmallProblemNESDIS) {
-  ComputeAndCompareSolutions(
-      2, false, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::NESDIS);
-  ComputeAndCompareSolutions(
-      2, true, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::NESDIS);
-}
-#endif
-
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithEigenSparseSmallProblemNATURAL) {
-  ComputeAndCompareSolutions(
-      2, false, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::NATURAL);
-  ComputeAndCompareSolutions(
-      2, true, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::NATURAL);
-}
-
-TEST_F(SchurComplementSolverTest, SparseSchurWithEigenSparseLargeProblemAMD) {
-  ComputeAndCompareSolutions(
-      3, false, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::AMD);
-  ComputeAndCompareSolutions(
-      3, true, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::AMD);
-}
-
-#ifndef CERES_NO_EIGEN_METIS
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithEigenSparseLargeProblemNESDIS) {
-  ComputeAndCompareSolutions(
-      3, false, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::NESDIS);
-  ComputeAndCompareSolutions(
-      3, true, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::NESDIS);
-}
-#endif
-
-TEST_F(SchurComplementSolverTest,
-       SparseSchurWithEigenSparseLargeProblemNATURAL) {
-  ComputeAndCompareSolutions(
-      3, false, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::NATURAL);
-  ComputeAndCompareSolutions(
-      3, true, SPARSE_SCHUR, EIGEN, EIGEN_SPARSE, OrderingType::NATURAL);
-}
-#endif  // CERES_USE_EIGEN_SPARSE
-
+}  // namespace
 }  // namespace ceres::internal