Refactor the automatic differentiation benchmarks.

1. Merge them into a single binary.
2. All benchmarks now do the Residual and the Residual + Jacobian
evaluation.
3. Re-organize and simplify the CMake file in this directory.
4. Fix a bug in the file where the Clang compiler was not being matched.

autodiff_benchmarks
---------------------------------------------------------------------------
Benchmark                                 Time             CPU   Iterations
---------------------------------------------------------------------------
BM_Linear1CodeGen/0                    3.02 ns         3.01 ns    233870456
BM_Linear1CodeGen/1                    3.02 ns         3.01 ns    233059100
BM_Linear1AutoDiff/0                   3.78 ns         3.77 ns    185791712
BM_Linear1AutoDiff/1                   14.0 ns         13.8 ns     53927875
BM_Linear10CodeGen/0                   5.10 ns         5.10 ns    126745007
BM_Linear10CodeGen/1                   29.1 ns         29.1 ns     23949310
BM_Linear10AutoDiff/0                  6.50 ns         6.49 ns    107516972
BM_Linear10AutoDiff/1                   169 ns          169 ns      4153218
BM_Rat43AutoDiff/0                     52.7 ns         51.2 ns     16444586
BM_Rat43AutoDiff/1                     91.8 ns         91.5 ns      7302316
BM_SnavelyReprojectionCodeGen/0        38.0 ns         36.2 ns     21131501
BM_SnavelyReprojectionCodeGen/1         113 ns          112 ns      5627779
BM_SnavelyReprojectionAutoDiff/0       34.4 ns         34.3 ns     20476937
BM_SnavelyReprojectionAutoDiff/1        242 ns          240 ns      2930611
BM_BrdfCodeGen/0                       53.9 ns         53.7 ns     11950083
BM_BrdfCodeGen/1                        507 ns          505 ns      1396732
BM_BrdfAutoDiff/0                      58.3 ns         57.8 ns     12220670
BM_BrdfAutoDiff/1                      2034 ns         1999 ns       257003

autodiff_benchmarks_fast_math
---------------------------------------------------------------------------
Benchmark                                 Time             CPU   Iterations
---------------------------------------------------------------------------
BM_Linear1CodeGen/0                    3.19 ns         3.16 ns    215313065
BM_Linear1CodeGen/1                    2.78 ns         2.76 ns    201497994
BM_Linear1AutoDiff/0                   3.27 ns         3.26 ns    206154598
BM_Linear1AutoDiff/1                   13.2 ns         13.1 ns     57257840
BM_Linear10CodeGen/0                   5.70 ns         5.51 ns    121849325
BM_Linear10CodeGen/1                   33.9 ns         33.3 ns     21829295
BM_Linear10AutoDiff/0                  6.85 ns         6.78 ns    106813153
BM_Linear10AutoDiff/1                   173 ns          171 ns      3849877
BM_Rat43AutoDiff/0                     44.8 ns         44.2 ns     15577017
BM_Rat43AutoDiff/1                     96.2 ns         94.6 ns      7374864
BM_SnavelyReprojectionCodeGen/0        33.9 ns         33.5 ns     20508373
BM_SnavelyReprojectionCodeGen/1        89.7 ns         88.4 ns      7620624
BM_SnavelyReprojectionAutoDiff/0       36.5 ns         35.8 ns     20546176
BM_SnavelyReprojectionAutoDiff/1        257 ns          252 ns      3044325
BM_BrdfCodeGen/0                       61.1 ns         58.5 ns     11334013
BM_BrdfCodeGen/1                        265 ns          265 ns      2625459
BM_BrdfAutoDiff/0                      52.5 ns         52.5 ns     12938763
BM_BrdfAutoDiff/1                      1560 ns         1560 ns       440909

Change-Id: I2d1a4293d3245a50f73af6cf5e5138084321ae6f
diff --git a/internal/ceres/autodiff_benchmarks/CMakeLists.txt b/internal/ceres/autodiff_benchmarks/CMakeLists.txt
index 29a238c..454e04b 100644
--- a/internal/ceres/autodiff_benchmarks/CMakeLists.txt
+++ b/internal/ceres/autodiff_benchmarks/CMakeLists.txt
@@ -1,3 +1,21 @@
+# TODO: Add support for other compilers
+if(CODE_GENERATION)
+  list(APPEND CERES_BENCHMARK_FLAGS "-DWITH_CODE_GENERATION")
+endif()
+
+if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+  list(APPEND CERES_BENCHMARK_FLAGS "-mllvm" "-inline-threshold=1000000")
+endif()
+
+add_executable(autodiff_benchmarks autodiff_benchmarks.cc)
+add_dependencies_to_benchmark(autodiff_benchmarks)
+target_compile_options(autodiff_benchmarks PRIVATE ${CERES_BENCHMARK_FLAGS})
+
+# All other flags + fast-math
+list(APPEND CERES_BENCHMARK_FAST_MATH_FLAGS ${CERES_BENCHMARK_FLAGS} "-ffast-math")
+add_executable(autodiff_benchmarks_fast_math autodiff_benchmarks.cc)
+add_dependencies_to_benchmark(autodiff_benchmarks_fast_math)
+target_compile_options(autodiff_benchmarks_fast_math PRIVATE ${CERES_BENCHMARK_FAST_MATH_FLAGS})
 
 if(CODE_GENERATION)
   macro (generate_benchmark_functor FUNCTOR_NAME FUNCTOR_FILE)
@@ -15,52 +33,6 @@
   generate_benchmark_functor(Linear10CostFunction linear_cost_functions.h)
   generate_benchmark_functor(Brdf brdf_cost_function.h)
 
-  list(APPEND CERES_BENCHMARK_FLAGS "-DWITH_CODE_GENERATION")
+  target_link_libraries(autodiff_benchmarks PUBLIC SnavelyReprojectionError Linear1CostFunction Linear10CostFunction Brdf)
+  target_link_libraries(autodiff_benchmarks_fast_math PUBLIC SnavelyReprojectionError Linear1CostFunction Linear10CostFunction Brdf)
 endif()
-
-
-# TODO: Add support for other compilers
-if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
-  list(APPEND CERES_BENCHMARK_FLAGS "-mllvm" "-inline-threshold=1000000")
-
-  # All other flags + fast-math
-  list(APPEND CERES_BENCHMARK_FAST_MATH_FLAGS ${CERES_BENCHMARK_FLAGS} "-ffast-math")
-endif()
-
-add_executable(rat43_benchmark rat43_benchmark.cc)
-add_dependencies_to_benchmark(rat43_benchmark)
-
-
-add_executable(snavely_reprojection_error_benchmark snavely_reprojection_error_benchmark.cc)
-add_dependencies_to_benchmark(snavely_reprojection_error_benchmark)
-target_compile_options(snavely_reprojection_error_benchmark PRIVATE ${CERES_BENCHMARK_FLAGS})
-
-add_executable(snavely_reprojection_error_benchmark_fast_math snavely_reprojection_error_benchmark.cc)
-add_dependencies_to_benchmark(snavely_reprojection_error_benchmark_fast_math)
-target_compile_options(snavely_reprojection_error_benchmark_fast_math PRIVATE ${CERES_BENCHMARK_FAST_MATH_FLAGS})
-
-add_executable(linear_benchmark linear_benchmark.cc)
-add_dependencies_to_benchmark(linear_benchmark)
-target_compile_options(linear_benchmark PRIVATE ${CERES_BENCHMARK_FLAGS})
-
-add_executable(linear_benchmark_fast_math linear_benchmark.cc)
-add_dependencies_to_benchmark(linear_benchmark_fast_math)
-target_compile_options(linear_benchmark_fast_math PRIVATE ${CERES_BENCHMARK_FAST_MATH_FLAGS})
-
-add_executable(brdf_benchmark brdf_benchmark.cc)
-add_dependencies_to_benchmark(brdf_benchmark)
-target_compile_options(brdf_benchmark PRIVATE ${CERES_BENCHMARK_FLAGS})
-
-add_executable(brdf_benchmark_fast_math brdf_benchmark.cc)
-add_dependencies_to_benchmark(brdf_benchmark_fast_math)
-target_compile_options(brdf_benchmark_fast_math PRIVATE ${CERES_BENCHMARK_FAST_MATH_FLAGS})
-
-if(CODE_GENERATION)
-  target_link_libraries(snavely_reprojection_error_benchmark PUBLIC SnavelyReprojectionError)
-  target_link_libraries(snavely_reprojection_error_benchmark_fast_math PUBLIC SnavelyReprojectionError)
-  target_link_libraries(linear_benchmark PUBLIC Linear1CostFunction Linear10CostFunction)
-  target_link_libraries(linear_benchmark_fast_math PUBLIC Linear1CostFunction Linear10CostFunction)
-  target_link_libraries(brdf_benchmark PUBLIC Brdf)
-  target_link_libraries(brdf_benchmark_fast_math PUBLIC Brdf)
-endif()
-
diff --git a/internal/ceres/autodiff_benchmarks/autodiff_benchmarks.cc b/internal/ceres/autodiff_benchmarks/autodiff_benchmarks.cc
new file mode 100644
index 0000000..89f56df
--- /dev/null
+++ b/internal/ceres/autodiff_benchmarks/autodiff_benchmarks.cc
@@ -0,0 +1,299 @@
+// Ceres Solver - A fast non-linear least squares minimizer
+// Copyright 2020 Google Inc. All rights reserved.
+// http://ceres-solver.org/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+//   this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright notice,
+//   this list of conditions and the following disclaimer in the documentation
+//   and/or other materials provided with the distribution.
+// * Neither the name of Google Inc. nor the names of its contributors may be
+//   used to endorse or promote products derived from this software without
+//   specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+//
+// Author: darius.rueckert@fau.de (Darius Rueckert)
+
+#include <memory>
+
+#include "benchmark/benchmark.h"
+#include "ceres/autodiff_benchmarks/brdf_cost_function.h"
+#include "ceres/autodiff_benchmarks/linear_cost_functions.h"
+#include "ceres/autodiff_benchmarks/snavely_reprojection_error.h"
+#include "ceres/ceres.h"
+#include "ceres/codegen/test_utils.h"
+
+namespace ceres {
+
+#ifdef WITH_CODE_GENERATION
+static void BM_Linear1CodeGen(benchmark::State& state) {
+  double parameter_block1[] = {1.};
+  double* parameters[] = {parameter_block1};
+
+  double jacobian1[1];
+  double residuals[1];
+  double* jacobians[] = {jacobian1};
+
+  std::unique_ptr<ceres::CostFunction> cost_function(new Linear1CostFunction());
+
+  for (auto _ : state) {
+    cost_function->Evaluate(
+        parameters, residuals, state.range(0) ? jacobians : nullptr);
+  }
+}
+BENCHMARK(BM_Linear1CodeGen)->Arg(0)->Arg(1);
+#endif
+
+static void BM_Linear1AutoDiff(benchmark::State& state) {
+  using FunctorType =
+      ceres::internal::CostFunctionToFunctor<Linear1CostFunction>;
+
+  double parameter_block1[] = {1.};
+  double* parameters[] = {parameter_block1};
+
+  double jacobian1[1];
+  double residuals[1];
+  double* jacobians[] = {jacobian1};
+
+  std::unique_ptr<ceres::CostFunction> cost_function(
+      new ceres::AutoDiffCostFunction<FunctorType, 1, 1>(new FunctorType()));
+
+  for (auto _ : state) {
+    cost_function->Evaluate(
+        parameters, residuals, state.range(0) ? jacobians : nullptr);
+  }
+}
+BENCHMARK(BM_Linear1AutoDiff)->Arg(0)->Arg(1);
+;
+
+#ifdef WITH_CODE_GENERATION
+static void BM_Linear10CodeGen(benchmark::State& state) {
+  double parameter_block1[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
+  double* parameters[] = {parameter_block1};
+
+  double jacobian1[10 * 10];
+  double residuals[10];
+  double* jacobians[] = {jacobian1};
+
+  std::unique_ptr<ceres::CostFunction> cost_function(
+      new Linear10CostFunction());
+
+  for (auto _ : state) {
+    cost_function->Evaluate(
+        parameters, residuals, state.range(0) ? jacobians : nullptr);
+  }
+}
+BENCHMARK(BM_Linear10CodeGen)->Arg(0)->Arg(1);
+;
+#endif
+
+static void BM_Linear10AutoDiff(benchmark::State& state) {
+  using FunctorType =
+      ceres::internal::CostFunctionToFunctor<Linear10CostFunction>;
+
+  double parameter_block1[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
+  double* parameters[] = {parameter_block1};
+
+  double jacobian1[10 * 10];
+  double residuals[10];
+  double* jacobians[] = {jacobian1};
+
+  std::unique_ptr<ceres::CostFunction> cost_function(
+      new ceres::AutoDiffCostFunction<FunctorType, 10, 10>(new FunctorType()));
+
+  for (auto _ : state) {
+    cost_function->Evaluate(
+        parameters, residuals, state.range(0) ? jacobians : nullptr);
+  }
+}
+BENCHMARK(BM_Linear10AutoDiff)->Arg(0)->Arg(1);
+;
+
+// From the NIST problem collection.
+struct Rat43CostFunctor {
+  Rat43CostFunctor(const double x, const double y) : x_(x), y_(y) {}
+
+  template <typename T>
+  bool operator()(const T* parameters, T* residuals) const {
+    const T& b1 = parameters[0];
+    const T& b2 = parameters[1];
+    const T& b3 = parameters[2];
+    const T& b4 = parameters[3];
+    residuals[0] = b1 * pow(1.0 + exp(b2 - b3 * x_), -1.0 / b4) - y_;
+    return true;
+  }
+
+ private:
+  const double x_;
+  const double y_;
+};
+
+static void BM_Rat43AutoDiff(benchmark::State& state) {
+  double parameter_block1[] = {1., 2., 3., 4.};
+  double* parameters[] = {parameter_block1};
+
+  double jacobian1[] = {0.0, 0.0, 0.0, 0.0};
+  double residuals;
+  double* jacobians[] = {jacobian1};
+  const double x = 0.2;
+  const double y = 0.3;
+  std::unique_ptr<ceres::CostFunction> cost_function(
+      new ceres::AutoDiffCostFunction<Rat43CostFunctor, 1, 4>(
+          new Rat43CostFunctor(x, y)));
+
+  for (auto _ : state) {
+    cost_function->Evaluate(
+        parameters, &residuals, state.range(0) ? jacobians : nullptr);
+  }
+}
+BENCHMARK(BM_Rat43AutoDiff)->Arg(0)->Arg(1);
+
+#ifdef WITH_CODE_GENERATION
+static void BM_SnavelyReprojectionCodeGen(benchmark::State& state) {
+  double parameter_block1[] = {1., 2., 3., 4., 5., 6., 7., 8., 9.};
+  double parameter_block2[] = {1., 2., 3.};
+  double* parameters[] = {parameter_block1, parameter_block2};
+
+  double jacobian1[2 * 9];
+  double jacobian2[2 * 3];
+  double residuals[2];
+  double* jacobians[] = {jacobian1, jacobian2};
+
+  const double x = 0.2;
+  const double y = 0.3;
+
+  std::unique_ptr<ceres::CostFunction> cost_function(
+      new SnavelyReprojectionError(x, y));
+
+  for (auto _ : state) {
+    cost_function->Evaluate(
+        parameters, residuals, state.range(0) ? jacobians : nullptr);
+  }
+}
+BENCHMARK(BM_SnavelyReprojectionCodeGen)->Arg(0)->Arg(1);
+;
+#endif
+
+static void BM_SnavelyReprojectionAutoDiff(benchmark::State& state) {
+  using FunctorType =
+      ceres::internal::CostFunctionToFunctor<SnavelyReprojectionError>;
+
+  double parameter_block1[] = {1., 2., 3., 4., 5., 6., 7., 8., 9.};
+  double parameter_block2[] = {1., 2., 3.};
+  double* parameters[] = {parameter_block1, parameter_block2};
+
+  double jacobian1[2 * 9];
+  double jacobian2[2 * 3];
+  double residuals[2];
+  double* jacobians[] = {jacobian1, jacobian2};
+
+  const double x = 0.2;
+  const double y = 0.3;
+  std::unique_ptr<ceres::CostFunction> cost_function(
+      new ceres::AutoDiffCostFunction<FunctorType, 2, 9, 3>(
+          new FunctorType(x, y)));
+
+  for (auto _ : state) {
+    cost_function->Evaluate(
+        parameters, residuals, state.range(0) ? jacobians : nullptr);
+  }
+}
+
+BENCHMARK(BM_SnavelyReprojectionAutoDiff)->Arg(0)->Arg(1);
+;
+
+#ifdef WITH_CODE_GENERATION
+static void BM_BrdfCodeGen(benchmark::State& state) {
+  using FunctorType = ceres::internal::CostFunctionToFunctor<Brdf>;
+
+  double material[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
+  auto c = Eigen::Vector3d(0.1, 0.2, 0.3);
+  auto n = Eigen::Vector3d(-0.1, 0.5, 0.2).normalized();
+  auto v = Eigen::Vector3d(0.5, -0.2, 0.9).normalized();
+  auto l = Eigen::Vector3d(-0.3, 0.4, -0.3).normalized();
+  auto x = Eigen::Vector3d(0.5, 0.7, -0.1).normalized();
+  auto y = Eigen::Vector3d(0.2, -0.2, -0.2).normalized();
+
+  double* parameters[7] = {
+      material, c.data(), n.data(), v.data(), l.data(), x.data(), y.data()};
+
+  double jacobian[(10 + 6 * 3) * 3];
+  double residuals[3];
+  double* jacobians[7] = {
+      jacobian + 0,
+      jacobian + 10 * 3,
+      jacobian + 13 * 3,
+      jacobian + 16 * 3,
+      jacobian + 19 * 3,
+      jacobian + 22 * 3,
+      jacobian + 25 * 3,
+  };
+
+  std::unique_ptr<ceres::CostFunction> cost_function(new Brdf());
+
+  for (auto _ : state) {
+    cost_function->Evaluate(
+        parameters, residuals, state.range(0) ? jacobians : nullptr);
+  }
+}
+
+BENCHMARK(BM_BrdfCodeGen)->Arg(0)->Arg(1);
+;
+#endif
+
+static void BM_BrdfAutoDiff(benchmark::State& state) {
+  using FunctorType = ceres::internal::CostFunctionToFunctor<Brdf>;
+
+  double material[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
+  auto c = Eigen::Vector3d(0.1, 0.2, 0.3);
+  auto n = Eigen::Vector3d(-0.1, 0.5, 0.2).normalized();
+  auto v = Eigen::Vector3d(0.5, -0.2, 0.9).normalized();
+  auto l = Eigen::Vector3d(-0.3, 0.4, -0.3).normalized();
+  auto x = Eigen::Vector3d(0.5, 0.7, -0.1).normalized();
+  auto y = Eigen::Vector3d(0.2, -0.2, -0.2).normalized();
+
+  double* parameters[7] = {
+      material, c.data(), n.data(), v.data(), l.data(), x.data(), y.data()};
+
+  double jacobian[(10 + 6 * 3) * 3];
+  double residuals[3];
+  double* jacobians[7] = {
+      jacobian + 0,
+      jacobian + 10 * 3,
+      jacobian + 13 * 3,
+      jacobian + 16 * 3,
+      jacobian + 19 * 3,
+      jacobian + 22 * 3,
+      jacobian + 25 * 3,
+  };
+
+  std::unique_ptr<ceres::CostFunction> cost_function(
+      new ceres::AutoDiffCostFunction<FunctorType, 3, 10, 3, 3, 3, 3, 3, 3>(
+          new FunctorType));
+
+  for (auto _ : state) {
+    cost_function->Evaluate(
+        parameters, residuals, state.range(0) ? jacobians : nullptr);
+  }
+}
+
+BENCHMARK(BM_BrdfAutoDiff)->Arg(0)->Arg(1);
+;
+
+}  // namespace ceres
+
+BENCHMARK_MAIN();
diff --git a/internal/ceres/autodiff_benchmarks/brdf_benchmark.cc b/internal/ceres/autodiff_benchmarks/brdf_benchmark.cc
deleted file mode 100644
index b66ecf3..0000000
--- a/internal/ceres/autodiff_benchmarks/brdf_benchmark.cc
+++ /dev/null
@@ -1,116 +0,0 @@
-// Ceres Solver - A fast non-linear least squares minimizer
-// Copyright 2020 Google Inc. All rights reserved.
-// http://ceres-solver.org/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// * Redistributions of source code must retain the above copyright notice,
-//   this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright notice,
-//   this list of conditions and the following disclaimer in the documentation
-//   and/or other materials provided with the distribution.
-// * Neither the name of Google Inc. nor the names of its contributors may be
-//   used to endorse or promote products derived from this software without
-//   specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: darius.rueckert@fau.de (Darius Rueckert)
-
-#include <memory>
-
-#include "benchmark/benchmark.h"
-#include "brdf_cost_function.h"
-#include "ceres/ceres.h"
-#include "codegen/test_utils.h"
-
-namespace ceres {
-
-#ifdef WITH_CODE_GENERATION
-static void BM_BrdfCodeGen(benchmark::State& state) {
-  using FunctorType = ceres::internal::CostFunctionToFunctor<Brdf>;
-
-  double material[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
-  auto c = Eigen::Vector3d(0.1, 0.2, 0.3);
-  auto n = Eigen::Vector3d(-0.1, 0.5, 0.2).normalized();
-  auto v = Eigen::Vector3d(0.5, -0.2, 0.9).normalized();
-  auto l = Eigen::Vector3d(-0.3, 0.4, -0.3).normalized();
-  auto x = Eigen::Vector3d(0.5, 0.7, -0.1).normalized();
-  auto y = Eigen::Vector3d(0.2, -0.2, -0.2).normalized();
-
-  double* parameters[7] = {
-      material, c.data(), n.data(), v.data(), l.data(), x.data(), y.data()};
-
-  double jacobian[(10 + 6 * 3) * 3];
-  double residuals[3];
-  double* jacobians[7] = {
-      jacobian + 0,
-      jacobian + 10 * 3,
-      jacobian + 13 * 3,
-      jacobian + 16 * 3,
-      jacobian + 19 * 3,
-      jacobian + 22 * 3,
-      jacobian + 25 * 3,
-  };
-
-  std::unique_ptr<ceres::CostFunction> cost_function(new Brdf());
-
-  while (state.KeepRunning()) {
-    cost_function->Evaluate(parameters, residuals, jacobians);
-  }
-}
-
-BENCHMARK(BM_BrdfCodeGen);
-#endif
-
-static void BM_BrdfAutoDiff(benchmark::State& state) {
-  using FunctorType = ceres::internal::CostFunctionToFunctor<Brdf>;
-
-  double material[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
-  auto c = Eigen::Vector3d(0.1, 0.2, 0.3);
-  auto n = Eigen::Vector3d(-0.1, 0.5, 0.2).normalized();
-  auto v = Eigen::Vector3d(0.5, -0.2, 0.9).normalized();
-  auto l = Eigen::Vector3d(-0.3, 0.4, -0.3).normalized();
-  auto x = Eigen::Vector3d(0.5, 0.7, -0.1).normalized();
-  auto y = Eigen::Vector3d(0.2, -0.2, -0.2).normalized();
-
-  double* parameters[7] = {
-      material, c.data(), n.data(), v.data(), l.data(), x.data(), y.data()};
-
-  double jacobian[(10 + 6 * 3) * 3];
-  double residuals[3];
-  double* jacobians[7] = {
-      jacobian + 0,
-      jacobian + 10 * 3,
-      jacobian + 13 * 3,
-      jacobian + 16 * 3,
-      jacobian + 19 * 3,
-      jacobian + 22 * 3,
-      jacobian + 25 * 3,
-  };
-
-  std::unique_ptr<ceres::CostFunction> cost_function(
-      new ceres::AutoDiffCostFunction<FunctorType, 3, 10, 3, 3, 3, 3, 3, 3>(
-          new FunctorType));
-
-  while (state.KeepRunning()) {
-    cost_function->Evaluate(parameters, residuals, jacobians);
-  }
-}
-
-BENCHMARK(BM_BrdfAutoDiff);
-
-}  // namespace ceres
-
-BENCHMARK_MAIN();
diff --git a/internal/ceres/autodiff_benchmarks/brdf_cost_function.h b/internal/ceres/autodiff_benchmarks/brdf_cost_function.h
index 287c409..de69cdd 100644
--- a/internal/ceres/autodiff_benchmarks/brdf_cost_function.h
+++ b/internal/ceres/autodiff_benchmarks/brdf_cost_function.h
@@ -58,7 +58,6 @@
                   const T* const y_ptr,
                   T* residual) const {
     using ceres::Ternary;
-    using Vec2 = Eigen::Matrix<T, 2, 1>;
     using Vec3 = Eigen::Matrix<T, 3, 1>;
 
     T metallic = material[0];
diff --git a/internal/ceres/autodiff_benchmarks/linear_benchmark.cc b/internal/ceres/autodiff_benchmarks/linear_benchmark.cc
deleted file mode 100644
index 25f6bd6..0000000
--- a/internal/ceres/autodiff_benchmarks/linear_benchmark.cc
+++ /dev/null
@@ -1,119 +0,0 @@
-// Ceres Solver - A fast non-linear least squares minimizer
-// Copyright 2020 Google Inc. All rights reserved.
-// http://ceres-solver.org/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// * Redistributions of source code must retain the above copyright notice,
-//   this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright notice,
-//   this list of conditions and the following disclaimer in the documentation
-//   and/or other materials provided with the distribution.
-// * Neither the name of Google Inc. nor the names of its contributors may be
-//   used to endorse or promote products derived from this software without
-//   specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: darius.rueckert@fau.de (Darius Rueckert)
-
-#include <memory>
-
-#include "benchmark/benchmark.h"
-#include "ceres/ceres.h"
-#include "codegen/test_utils.h"
-#include "linear_cost_functions.h"
-
-namespace ceres {
-
-#ifdef WITH_CODE_GENERATION
-static void BM_Linear1CodeGen(benchmark::State& state) {
-  double parameter_block1[] = {1.};
-  double* parameters[] = {parameter_block1};
-
-  double jacobian1[1];
-  double residuals[1];
-  double* jacobians[] = {jacobian1};
-
-  std::unique_ptr<ceres::CostFunction> cost_function(new Linear1CostFunction());
-
-  while (state.KeepRunning()) {
-    cost_function->Evaluate(parameters, residuals, jacobians);
-  }
-}
-BENCHMARK(BM_Linear1CodeGen);
-#endif
-
-static void BM_Linear1AutoDiff(benchmark::State& state) {
-  using FunctorType =
-      ceres::internal::CostFunctionToFunctor<Linear1CostFunction>;
-
-  double parameter_block1[] = {1.};
-  double* parameters[] = {parameter_block1};
-
-  double jacobian1[1];
-  double residuals[1];
-  double* jacobians[] = {jacobian1};
-
-  std::unique_ptr<ceres::CostFunction> cost_function(
-      new ceres::AutoDiffCostFunction<FunctorType, 1, 1>(new FunctorType()));
-
-  while (state.KeepRunning()) {
-    cost_function->Evaluate(parameters, residuals, jacobians);
-  }
-}
-BENCHMARK(BM_Linear1AutoDiff);
-
-#ifdef WITH_CODE_GENERATION
-static void BM_Linear10CodeGen(benchmark::State& state) {
-  double parameter_block1[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
-  double* parameters[] = {parameter_block1};
-
-  double jacobian1[10 * 10];
-  double residuals[10];
-  double* jacobians[] = {jacobian1};
-
-  std::unique_ptr<ceres::CostFunction> cost_function(
-      new Linear10CostFunction());
-
-  while (state.KeepRunning()) {
-    cost_function->Evaluate(parameters, residuals, jacobians);
-  }
-}
-BENCHMARK(BM_Linear10CodeGen);
-#endif
-
-static void BM_Linear10AutoDiff(benchmark::State& state) {
-  using FunctorType =
-      ceres::internal::CostFunctionToFunctor<Linear10CostFunction>;
-
-  double parameter_block1[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.};
-  double* parameters[] = {parameter_block1};
-
-  double jacobian1[10 * 10];
-  double residuals[10];
-  double* jacobians[] = {jacobian1};
-
-  std::unique_ptr<ceres::CostFunction> cost_function(
-      new ceres::AutoDiffCostFunction<FunctorType, 10, 10>(new FunctorType()));
-
-  while (state.KeepRunning()) {
-    cost_function->Evaluate(parameters, residuals, jacobians);
-  }
-}
-BENCHMARK(BM_Linear10AutoDiff);
-
-}  // namespace ceres
-
-BENCHMARK_MAIN();
diff --git a/internal/ceres/autodiff_benchmarks/linear_cost_functions.h b/internal/ceres/autodiff_benchmarks/linear_cost_functions.h
index 2a9c06c..e009ee2 100644
--- a/internal/ceres/autodiff_benchmarks/linear_cost_functions.h
+++ b/internal/ceres/autodiff_benchmarks/linear_cost_functions.h
@@ -34,6 +34,7 @@
 
 #include "ceres/codegen/codegen_cost_function.h"
 #include "ceres/rotation.h"
+
 namespace ceres {
 
 struct Linear1CostFunction : public ceres::CodegenCostFunction<1, 1> {
@@ -71,5 +72,6 @@
   }
 #endif
 };
-}
+}  // namespace ceres
+
 #endif  // CERES_INTERNAL_AUTODIFF_BENCHMARKS_LINEAR_COST_FUNCTIONS_H_
diff --git a/internal/ceres/autodiff_benchmarks/rat43_benchmark.cc b/internal/ceres/autodiff_benchmarks/rat43_benchmark.cc
deleted file mode 100644
index d9a1e57..0000000
--- a/internal/ceres/autodiff_benchmarks/rat43_benchmark.cc
+++ /dev/null
@@ -1,116 +0,0 @@
-// Ceres Solver - A fast non-linear least squares minimizer
-// Copyright 2018 Google Inc. All rights reserved.
-// http://ceres-solver.org/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// * Redistributions of source code must retain the above copyright notice,
-//   this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright notice,
-//   this list of conditions and the following disclaimer in the documentation
-//   and/or other materials provided with the distribution.
-// * Neither the name of Google Inc. nor the names of its contributors may be
-//   used to endorse or promote products derived from this software without
-//   specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-// Authors: sameeragarwal@google.com (Sameer Agarwal)
-
-#include <memory>
-
-#include "benchmark/benchmark.h"
-#include "ceres/ceres.h"
-#include "ceres/jet.h"
-
-namespace ceres {
-
-// From the NIST problem collection.
-struct Rat43CostFunctor {
-  Rat43CostFunctor(const double x, const double y) : x_(x), y_(y) {}
-
-  template <typename T>
-  bool operator()(const T* parameters, T* residuals) const {
-    const T& b1 = parameters[0];
-    const T& b2 = parameters[1];
-    const T& b3 = parameters[2];
-    const T& b4 = parameters[3];
-    residuals[0] = b1 * pow(1.0 + exp(b2 - b3 * x_), -1.0 / b4) - y_;
-    return true;
-  }
-
- private:
-  const double x_;
-  const double y_;
-};
-
-// Simple implementation of autodiff using Jets directly instead of
-// going through the machinery of AutoDiffCostFunction, which does
-// the same thing, but much more generically.
-class Rat43Automatic : public ceres::SizedCostFunction<1, 4> {
- public:
-  Rat43Automatic(const Rat43CostFunctor* functor) : functor_(functor) {}
-  virtual ~Rat43Automatic() {}
-  bool Evaluate(double const* const* parameters,
-                double* residuals,
-                double** jacobians) const final {
-    if (!jacobians) {
-      return (*functor_)(parameters[0], residuals);
-    }
-
-    typedef ceres::Jet<double, 4> JetT;
-    JetT jets[4];
-    for (int i = 0; i < 4; ++i) {
-      jets[i].a = parameters[0][i];
-      jets[i].v.setZero();
-      jets[i].v[i] = 1.0;
-    }
-
-    JetT result;
-    (*functor_)(jets, &result);
-
-    residuals[0] = result.a;
-    for (int i = 0; i < 4; ++i) {
-      jacobians[0][i] = result.v[i];
-    }
-    return true;
-  }
-
- private:
-  std::unique_ptr<const Rat43CostFunctor> functor_;
-};
-
-static void BM_Rat43AutoDiff(benchmark::State& state) {
-  double parameter_block1[] = {1., 2., 3., 4.};
-  double* parameters[] = {parameter_block1};
-
-  double jacobian1[] = {0.0, 0.0, 0.0, 0.0};
-  double residuals;
-  double* jacobians[] = {jacobian1};
-  const double x = 0.2;
-  const double y = 0.3;
-  std::unique_ptr<ceres::CostFunction> cost_function(
-      new ceres::AutoDiffCostFunction<Rat43CostFunctor, 1, 4>(
-          new Rat43CostFunctor(x, y)));
-
-  while (state.KeepRunning()) {
-    cost_function->Evaluate(
-        parameters, &residuals, state.range(0) ? jacobians : nullptr);
-  }
-}
-BENCHMARK(BM_Rat43AutoDiff)->Arg(0)->Arg(1);
-
-}  // namespace ceres
-
-BENCHMARK_MAIN();
diff --git a/internal/ceres/autodiff_benchmarks/snavely_reprojection_error_benchmark.cc b/internal/ceres/autodiff_benchmarks/snavely_reprojection_error_benchmark.cc
deleted file mode 100644
index 4a58db2..0000000
--- a/internal/ceres/autodiff_benchmarks/snavely_reprojection_error_benchmark.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// Ceres Solver - A fast non-linear least squares minimizer
-// Copyright 2020 Google Inc. All rights reserved.
-// http://ceres-solver.org/
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// * Redistributions of source code must retain the above copyright notice,
-//   this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright notice,
-//   this list of conditions and the following disclaimer in the documentation
-//   and/or other materials provided with the distribution.
-// * Neither the name of Google Inc. nor the names of its contributors may be
-//   used to endorse or promote products derived from this software without
-//   specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-// Author: darius.rueckert@fau.de (Darius Rueckert)
-
-#include <memory>
-
-#include "benchmark/benchmark.h"
-#include "ceres/ceres.h"
-#include "codegen/test_utils.h"
-#include "snavely_reprojection_error.h"
-
-namespace ceres {
-
-#ifdef WITH_CODE_GENERATION
-static void BM_SnavelyReprojectionCodeGen(benchmark::State& state) {
-  double parameter_block1[] = {1., 2., 3., 4., 5., 6., 7., 8., 9.};
-  double parameter_block2[] = {1., 2., 3.};
-  double* parameters[] = {parameter_block1, parameter_block2};
-
-  double jacobian1[2 * 9];
-  double jacobian2[2 * 3];
-  double residuals[2];
-  double* jacobians[] = {jacobian1, jacobian2};
-
-  const double x = 0.2;
-  const double y = 0.3;
-
-  std::unique_ptr<ceres::CostFunction> cost_function(
-      new SnavelyReprojectionError(x, y));
-
-  while (state.KeepRunning()) {
-    cost_function->Evaluate(parameters, residuals, jacobians);
-  }
-}
-BENCHMARK(BM_SnavelyReprojectionCodeGen);
-#endif
-
-static void BM_SnavelyReprojectionAutoDiff(benchmark::State& state) {
-  using FunctorType =
-      ceres::internal::CostFunctionToFunctor<SnavelyReprojectionError>;
-
-  double parameter_block1[] = {1., 2., 3., 4., 5., 6., 7., 8., 9.};
-  double parameter_block2[] = {1., 2., 3.};
-  double* parameters[] = {parameter_block1, parameter_block2};
-
-  double jacobian1[2 * 9];
-  double jacobian2[2 * 3];
-  double residuals[2];
-  double* jacobians[] = {jacobian1, jacobian2};
-
-  const double x = 0.2;
-  const double y = 0.3;
-  std::unique_ptr<ceres::CostFunction> cost_function(
-      new ceres::AutoDiffCostFunction<FunctorType, 2, 9, 3>(
-          new FunctorType(x, y)));
-
-  while (state.KeepRunning()) {
-    cost_function->Evaluate(parameters, residuals, jacobians);
-  }
-}
-
-BENCHMARK(BM_SnavelyReprojectionAutoDiff);
-
-}  // namespace ceres
-
-BENCHMARK_MAIN();