Squashed 'third_party/ceres/' changes from e51e9b46f..399cda773

399cda773 Update build documentation to reflect detection of Eigen via config mode
bb127272f Fix typos.
a0ec5c32a Update version history for 2.0.0RC2
3f6d27367 Unify symbol visibility configuration for all compilers
29c2912ee Unbreak the bazel build some more
bf47e1a36 Fix the Bazel build.
600e8c529 fix minor typos
bdcdcc78a update docs for changed cmake usage
3f69e5b36 Corrections from William Rucklidge
8bfdb02fb Rewrite uses of VLOG_IF and LOG_IF.
d1b35ffc1 Corrections from William Rucklidge
f34e80e91 Add dividers between licenses.
65c397dae Fix formatting
f63b1fea9 Add the MIT license text corresponding to the libmv derived files.
542613c13 minor formatting fix for trust_region_minimizer.cc
6d9e9843d Remove inclusion of ceres/eigen.h
eafeca5dc Fix a logging bug in TrustRegionMinimizer.
1fd0be916 Fix default initialisation of IterationCallback::cost
137bbe845 add info about clang-format to contributing docs
d3f66d77f fix formatting generated files (best effort)
a9c7361c8 minor formatting fix (wrongly updated in earlier commit)
7b8f675bf fix formatting for (non-generated) internal source files
921368ce3 Fix a number of typos in covariance.h
7b6b2491c fix formatting for examples
82275d8a4 some fixes for Linux and macOS install docs
9d762d74f fix formatting for public header files
c76478c48 gitignore *.pyc
4e69a475c Fix potential for mismatched release/debug TBB libraries
8e1d8e32a A number of small changes.
368a738e5 AutoDiffCostFunction: optional ownership
8cbd721c1 Add erf and erfc to jet.h, including tests in jet_test.cc
31366cff2 Benchmarks for dynamic autodiff.
29fb08aea Use CMAKE_PREFIX_PATH to pass Homebrew install location
242c703b5 Minor fixes to the documentation
79bbf9510 Add changelog for 2.0.0
41d05f13d Fix lint errors in evaluation_callback_test.cc
4b67903c1 Remove unused variables from problem_test.cc
10449fc36 Add Apache license to the LICENSE file for FixedArray
8c3ecec6d Fix some minor errors in IterationCallback docs
7d3ffcb42 Remove forced CONFIG from find_package(Eigen3)
a029fc0f9 Use latest FindTBB.cmake from VTK project
aa1abbc57 Replace use of GFLAGS_LIBRARIES with export gflags target
db2af1be8 Add Problem::EvaluateResidualBlockAssumingParametersUnchanged
ab4ed32cd Replace NULL with nullptr in the documentation.
ee280e27a Allow SubsetParameterization to accept an empty vector of constant parameters.
4b8c731d8 Fix a bug in DynamicAutoDiffCostFunction
5cb5b35a9 Fixed incorrect argument name in RotationMatrixToQuaternion()
e39d9ed1d Add a missing term and remove a superfluous word
27cab77b6 Reformulate some sentences
8ac6655ce Fix documentation formatting issues
7ef83e075 Update minimum required C++ version for Ceres to C++14
1d75e7568 Improve documentation for LocalParameterization
763398ca4 Update the section on Preconditioners
a614f788a Call EvaluationCallback before evaluating the fixed cost.
70308f7bb Simplify documentation generation.
e886d7e65 Reduce the number of minimizer iterations in evaluation_callback_test.cc
9483e6f2f Simplify DynamicCompressedRowJacobianWriter::Write
323cc55bb Update the version in package.xml to 2.0.0.
303b078b5 Fix few typos and alter a NULL to nullptr.
cca93fed6 Bypass Ceres' FindGlog.cmake in CeresConfig.cmake if possible
77fc1d0fc Use build_depend for private dependencies in Catkin package.xml
a09682f00 Fix MSVC version check to support use of clang-cl front-end
b70687fcc Add namespace qualified Ceres::ceres CMake target
99efa54bd Replace type aliases deprecated/removed in C++17/C++20 from FixedArray
adb973e4a NULL -> nullptr
27b717951 Respect FIND_QUIETLY flag in cmake config file
646959ef1 Do not export class template LineParameterization
1f128d070 Change the type of parameter index/offset to match their getter/setter
072c8f070 Initialize integer variables with integer instead of double
8c36bcc81 Use inline & -inlinehint-threshold in auto-diff benchmarks
57cf20aa5 static const -> static constexpr where we can.
40b27482a Add std::numeric_limit specialization for Jets
e751d6e4f Remove AutodiffCodegen
e9eb76f8e Remove AutodiffCodegen CMake integration
9435e08a7 More clang-tidy and wjr@ comment fixes
d93fac4b7 Remove AutodiffCodegen Tests
2281c6ed2 Fixes for comments from William Rucklidge
d797a87a4 Use Ridders' method in GradientChecker.
41675682d Fix a MSVC type deduction bug in ComputeHouseholderVector
947ec0c1f Remove AutodiffCodegen autodiff benchmarks
27183d661 Allow LocalParameterizations to have zero local size.
7ac7d79dc Remove HelloWorldCodegen example
8c8738bf8 Add photometric and relative-pose residuals to autodiff benchmarks
9f7fb66d6 Add a constant cost function to the autodiff benchmarks
ab0d373e4 Fix a comment in autodiff.h
27bb99714 Change SVD algorithm in covariance computation.
84fdac38e Add const to GetCovarianceMatrix*
6bde61d6b Add line local parameterization.
2c1c0932e Update documentation in autodiff.h
8904fa488 Inline Jet initialization in Autodiff
18a464d4e Remove an errant CR from local_parameterization.cc
5c85f2179 Use ArraySelector in Autodiff
80477ff07 Add class ArraySelector
e7a30359e Pass kNumResiduals to Autodiff
f339d71dd Refactor the automatic differentiation benchmarks.
d37b4cb15 Fix some include headers in codegen/test_utils.cc/h
550766e6d Add Autodiff Brdf Benchmark
8da9876e7 Add more autodiff benchmarks
6da364713 Fix Tukey loss function
cf4185c4e Add Codegen BA Benchmark
75dd30fae Simplify GenerateCodeForFunctor
9049688c6 Default Initialize ExpressionRef to Zero
bf1aff2f0 Fix 3+ nested Jet constructor
92d6541c7 Move Codegen files into codegen/ directory
8e962f37d Add Autodiff Codegen Tests
13c7a22ce Codegen Optimizer API
90799e29e Fix install and unnecessary string copy
032d5844c AutoDiff Code Generation - CMake Integration
d82de91b8 Add ExpressionGraph::Erase(ExpressionId)
c8e35e19f Add namespaces to generated functions and constants
75e575cae Fix use of incomplete type in defaulted Problem methods
8def19616 Remove ExpressionRef Move Constructor
f26f95410 Fix windows MSVC build.
fdf9cfd32 Add functions to find the matching ELSE, ENDIF expressions
678c05b28 Fix invert PSD matrix.
a384a7e96 Remove not used using declaration
a60136b7a Add COMMENT ExpressionType
f212c9295 Let Problem::SetParameterization be called more than once.
a3696835b use CMake function to create CeresConfigVersion
67fcff918 Make Problem movable.
19728e72d Add documentation for Problem::IsParameterBlockConstant
ba6e5fb4a Make the custom uninstall target optional
8547cbd55 Make EventLogger more efficient.
edb8322bd Update the minimum required version of Eigen to 3.3.
aa6ef417f Specify Eigen3_DIR in iOS and Android Travis CI builds
4655f2549 Use find_package() instead of find_dependency() in CeresConfig.cmake
a548766d1 Use glfags target
33dd469a5 Use Eigen3::Eigen target
47e784bb4 NULL-jacobians are handled correctly in generated autodiff code
edd54b83e Update Jet.h and rotation.h to use the new IF/ELSE macros
848c1f90c Update return type in code generator and add tests for logical functions
5010421bb Add the expression return type as a member to Expression
f4dc670ee Improve testing of the codegen system
572ec4a5a Rework Expression creation and insertion
c7337154e Disable the code generation module by default
7fa0f3db4 Explicitly state PUBLIC/PRIVATE when linking
4362a2169 Run clang-format on the public headers. Also update copyright year.
c56702aac Fix installation of codegen headers
0d03e74dc Fix the include in the autodiff codegen example
d16026440 Autodiff Codegen Part 4: Public API
d1703db45 Moved AutoDiffCodeGen macros to a separate (public) header
5ce6c063d Fix ExpressionRef copy constructor and add a move constructor
a90b5a12c Pass ExpressionRef by const reference instead of by value
ea057678c Remove MakeFunctionCall() and add test for Ternary
1084c5460 Quote all configure-expanded paths
3d756b07c Test Expressions with 'insert' instead of a macro
486d81812 Add ExpressionGraph::InsertExpression
3831a1dd3 Expression and ExpressionGraph comparison
9bb1dcb84 Remove definition of ExpressionRef::ExpressionRef(double&);
5be2e4883 Autodiff Codegen Part 3: CodeGenerator
6cd633043 Remove unused ExpressionTypes
7d0d69a4d Fix ExpressionRef
6ba8c57d2 Fix expression_test IsArithmetic
2b494cfb3 Update Travis CI to Bionic & Xcode 11.2
a3dde6877 Require Xcode >= 11.2 on macOS 10.15 (Catalina)
6fd4f072d Autodiff Codegen Part 2: Conditionals
52d6477a4 Detect and disable -fstack-check on macOS 10.15 with Xcode 11
46ca461b7 Fix `gradient_check_relative_precision` docs typo
4247d420f Autodiff Codegen Part 1: Expressions
ba62397d8 Run clang-format on jet.h
667062dcc Introduce BlockSparseMatrixData
17becf461 Remove a CHECK failure from covariance_impl.cc
d7f428e5c Add a missing cast in rotation.h
ea4d66e7e clang-tidy fixes.
be15b842a Integrate the SchurEliminatorForOneFBlock for the case <2,3,6>
087b28f1b Remove use of SetUsage as it creates compilation problems.
573046d7f Protect declarations of lapack functions under CERES_NO_LAPACK
71d638ef3 Add a specialized schur eliminator.
2ffddaccf Use override & final instead of just using virtual.
e4577dd6d Use override instead of virtual for subclasses.
3e5db5bc2 Fixing documentation typo.
82d325b73 Avoid memory allocations in Accelerate Sparse[Refactor/Solve]().
f66b51382 Fix some clang-tidy warnings.
0428e2dd0 Fix missing #include of <memory>
487c1aa51 Expose SubsetPreconditioner in the API
bf709ecac Move EvaluationCallback from Solver::Options to Problem::Options.
059bcb7f8 Drop ROS dependency on catkin
c4dbc927d Default to any other sparse libraries over Accelerate
db1f5b57a Allow some methods in Problem to use const double*.
a60c14525 Explicitly delete the copy constructor and copy assignment operator
084042c25 Lint changes from William Rucklidge
93d869020 Use selfAdjoingView<Upper> in InvertPSDMatrix.
a0cd0854a Speed up InvertPSDMatrix
7b53262b7 Allow Solver::Options::max_num_line_search_step_size_iterations = 0.
3e2cdca54 Make LineSearchMinizer work correctly with negative valued functions.
3ff12a878 Fix a clang-tidy warning in problem_test.cc
57441fe90 Fix two bugs.
1b852c57e Add Problem::EvaluateResidualBlock.
54ba6c27b Fix missing declaration warnings in Ceres code
fac46d50e Modernize ProductParameterization.
53dc6213f Add some missing string-to-enum-to-string convertors.
c0aa9a263 Add checks in rotation.h for inplace operations.
0f57fa82d Update Bazel WORKSPACE for newest Bazel
f8e5fba7b TripletSparseMatrix: guard against self-assignment
939253c20 Fix Eigen alignment issues.
bf67daf79 Add the missing <array> header to fixed_array.h
25e1cdbb6 Switch to FixedArray implementation from abseil.
d467a627b IdentityTransformation -> IdentityParameterization
eaec6a9d0 Fix more typos in CostFunctionToFunctor documentation.
99b5aa4aa Fix typos in CostFunctionToFunctor documentation.
ee7e2cb3c Set Homebrew paths via HINTS not CMAKE_PREFIX_PATH
4f8a01853 Revert "Fix custom Eigen on macos (EIGEN_INCLUDE_DIR_HINTS)"
e6c5c7226 Fix custom Eigen on macos (EIGEN_INCLUDE_DIR_HINTS)
5a56d522e Add the 3,3,3 template specialization.
df5c23116 Reorder initializer list to make -Wreorder happy
0fcfdb0b4 Fix the build breakage caused by the last commit.
9b9e9f0dc Reduce machoness of macro definition in cost_functor_to_function_test.cc
21d40daa0 Remove UTF-8 chars
9350e57a4 Enable optional use of sanitizers
0456edffb Update Travis CI Linux distro to 16.04 (Xenial)
bef0dfe35 Fix a typo in cubic_interpolation.h
056ba9bb1 Add AutoDiffFirstOrderFunction
6e527392d Update googletest/googlemock to db9b85e2.
1b2940749 Clarify documentation of BiCubicInterpolator::Evaluate for out-of-bounds values

Change-Id: Id61dd832e8fbe286deb0799aa1399d4017031dae
git-subtree-dir: third_party/ceres
git-subtree-split: 399cda773035d99eaf1f4a129a666b3c4df9d1b1
diff --git a/internal/ceres/rotation_test.cc b/internal/ceres/rotation_test.cc
index d980ba2..fc39b31 100644
--- a/internal/ceres/rotation_test.cc
+++ b/internal/ceres/rotation_test.cc
@@ -28,14 +28,16 @@
 //
 // Author: sameeragarwal@google.com (Sameer Agarwal)
 
+#include "ceres/rotation.h"
+
 #include <cmath>
 #include <limits>
 #include <string>
+
 #include "ceres/internal/eigen.h"
-#include "ceres/is_close.h"
 #include "ceres/internal/port.h"
+#include "ceres/is_close.h"
 #include "ceres/jet.h"
-#include "ceres/rotation.h"
 #include "ceres/stringprintf.h"
 #include "ceres/test_util.h"
 #include "glog/logging.h"
@@ -45,8 +47,8 @@
 namespace ceres {
 namespace internal {
 
-using std::min;
 using std::max;
+using std::min;
 using std::numeric_limits;
 using std::string;
 using std::swap;
@@ -54,7 +56,7 @@
 const double kPi = 3.14159265358979323846;
 const double kHalfSqrt2 = 0.707106781186547524401;
 
-double RandDouble() {
+static double RandDouble() {
   double r = rand();
   return r / RAND_MAX;
 }
@@ -74,8 +76,8 @@
     return false;
   }
 
-  double norm2 = arg[0] * arg[0] + arg[1] * arg[1] +
-      arg[2] * arg[2] + arg[3] * arg[3];
+  double norm2 =
+      arg[0] * arg[0] + arg[1] * arg[1] + arg[2] * arg[2] + arg[3] * arg[3];
   if (fabs(norm2 - 1.0) > kTolerance) {
     *result_listener << "squared norm is " << norm2;
     return false;
@@ -120,6 +122,7 @@
     return true;
   }
 
+  // clang-format off
   *result_listener << "expected : "
                    << expected[0] << " "
                    << expected[1] << " "
@@ -130,6 +133,7 @@
                    << arg[1] << " "
                    << arg[2] << " "
                    << arg[3];
+  // clang-format on
   return false;
 }
 
@@ -164,6 +168,7 @@
     return true;
   }
 
+  // clang-format off
   *result_listener << " arg:"
                    << " " << arg[0]
                    << " " << arg[1]
@@ -172,6 +177,7 @@
                    << " " << expected[0]
                    << " " << expected[1]
                    << " " << expected[2];
+  // clang-format on
   return false;
 }
 
@@ -225,9 +231,9 @@
 
 // Transforms a zero axis/angle to a quaternion.
 TEST(Rotation, ZeroAngleAxisToQuaternion) {
-  double axis_angle[3] = { 0, 0, 0 };
+  double axis_angle[3] = {0, 0, 0};
   double quaternion[4];
-  double expected[4] = { 1, 0, 0, 0 };
+  double expected[4] = {1, 0, 0, 0};
   AngleAxisToQuaternion(axis_angle, quaternion);
   EXPECT_THAT(quaternion, IsNormalizedQuaternion());
   EXPECT_THAT(quaternion, IsNearQuaternion(expected));
@@ -237,9 +243,9 @@
 TEST(Rotation, SmallAngleAxisToQuaternion) {
   // Small, finite value to test.
   double theta = 1.0e-2;
-  double axis_angle[3] = { theta, 0, 0 };
+  double axis_angle[3] = {theta, 0, 0};
   double quaternion[4];
-  double expected[4] = { cos(theta/2), sin(theta/2.0), 0, 0 };
+  double expected[4] = {cos(theta / 2), sin(theta / 2.0), 0, 0};
   AngleAxisToQuaternion(axis_angle, quaternion);
   EXPECT_THAT(quaternion, IsNormalizedQuaternion());
   EXPECT_THAT(quaternion, IsNearQuaternion(expected));
@@ -249,9 +255,9 @@
 TEST(Rotation, TinyAngleAxisToQuaternion) {
   // Very small value that could potentially cause underflow.
   double theta = pow(numeric_limits<double>::min(), 0.75);
-  double axis_angle[3] = { theta, 0, 0 };
+  double axis_angle[3] = {theta, 0, 0};
   double quaternion[4];
-  double expected[4] = { cos(theta/2), sin(theta/2.0), 0, 0 };
+  double expected[4] = {cos(theta / 2), sin(theta / 2.0), 0, 0};
   AngleAxisToQuaternion(axis_angle, quaternion);
   EXPECT_THAT(quaternion, IsNormalizedQuaternion());
   EXPECT_THAT(quaternion, IsNearQuaternion(expected));
@@ -259,9 +265,9 @@
 
 // Transforms a rotation by pi/2 around X to a quaternion.
 TEST(Rotation, XRotationToQuaternion) {
-  double axis_angle[3] = { kPi / 2, 0, 0 };
+  double axis_angle[3] = {kPi / 2, 0, 0};
   double quaternion[4];
-  double expected[4] = { kHalfSqrt2, kHalfSqrt2, 0, 0 };
+  double expected[4] = {kHalfSqrt2, kHalfSqrt2, 0, 0};
   AngleAxisToQuaternion(axis_angle, quaternion);
   EXPECT_THAT(quaternion, IsNormalizedQuaternion());
   EXPECT_THAT(quaternion, IsNearQuaternion(expected));
@@ -269,18 +275,18 @@
 
 // Transforms a unit quaternion to an axis angle.
 TEST(Rotation, UnitQuaternionToAngleAxis) {
-  double quaternion[4] = { 1, 0, 0, 0 };
+  double quaternion[4] = {1, 0, 0, 0};
   double axis_angle[3];
-  double expected[3] = { 0, 0, 0 };
+  double expected[3] = {0, 0, 0};
   QuaternionToAngleAxis(quaternion, axis_angle);
   EXPECT_THAT(axis_angle, IsNearAngleAxis(expected));
 }
 
 // Transforms a quaternion that rotates by pi about the Y axis to an axis angle.
 TEST(Rotation, YRotationQuaternionToAngleAxis) {
-  double quaternion[4] = { 0, 0, 1, 0 };
+  double quaternion[4] = {0, 0, 1, 0};
   double axis_angle[3];
-  double expected[3] = { 0, kPi, 0 };
+  double expected[3] = {0, kPi, 0};
   QuaternionToAngleAxis(quaternion, axis_angle);
   EXPECT_THAT(axis_angle, IsNearAngleAxis(expected));
 }
@@ -288,9 +294,9 @@
 // Transforms a quaternion that rotates by pi/3 about the Z axis to an axis
 // angle.
 TEST(Rotation, ZRotationQuaternionToAngleAxis) {
-  double quaternion[4] = { sqrt(3) / 2, 0, 0, 0.5 };
+  double quaternion[4] = {sqrt(3) / 2, 0, 0, 0.5};
   double axis_angle[3];
-  double expected[3] = { 0, 0, kPi / 3 };
+  double expected[3] = {0, 0, kPi / 3};
   QuaternionToAngleAxis(quaternion, axis_angle);
   EXPECT_THAT(axis_angle, IsNearAngleAxis(expected));
 }
@@ -299,9 +305,9 @@
 TEST(Rotation, SmallQuaternionToAngleAxis) {
   // Small, finite value to test.
   double theta = 1.0e-2;
-  double quaternion[4] = { cos(theta/2), sin(theta/2.0), 0, 0 };
+  double quaternion[4] = {cos(theta / 2), sin(theta / 2.0), 0, 0};
   double axis_angle[3];
-  double expected[3] = { theta, 0, 0 };
+  double expected[3] = {theta, 0, 0};
   QuaternionToAngleAxis(quaternion, axis_angle);
   EXPECT_THAT(axis_angle, IsNearAngleAxis(expected));
 }
@@ -310,9 +316,9 @@
 TEST(Rotation, TinyQuaternionToAngleAxis) {
   // Very small value that could potentially cause underflow.
   double theta = pow(numeric_limits<double>::min(), 0.75);
-  double quaternion[4] = { cos(theta/2), sin(theta/2.0), 0, 0 };
+  double quaternion[4] = {cos(theta / 2), sin(theta / 2.0), 0, 0};
   double axis_angle[3];
-  double expected[3] = { theta, 0, 0 };
+  double expected[3] = {theta, 0, 0};
   QuaternionToAngleAxis(quaternion, axis_angle);
   EXPECT_THAT(axis_angle, IsNearAngleAxis(expected));
 }
@@ -328,13 +334,13 @@
   quaternion[2] = 0.0;
   quaternion[3] = 0.0;
   QuaternionToAngleAxis(quaternion, angle_axis);
-  const double angle = sqrt(angle_axis[0] * angle_axis[0] +
-                            angle_axis[1] * angle_axis[1] +
-                            angle_axis[2] * angle_axis[2]);
+  const double angle =
+      sqrt(angle_axis[0] * angle_axis[0] + angle_axis[1] * angle_axis[1] +
+           angle_axis[2] * angle_axis[2]);
   EXPECT_LE(angle, kPi);
 }
 
-static const int kNumTrials = 10000;
+static constexpr int kNumTrials = 10000;
 
 // Takes a bunch of random axis/angle values, converts them to quaternions,
 // and back again.
@@ -398,18 +404,18 @@
 
 // Transforms a zero axis/angle to a rotation matrix.
 TEST(Rotation, ZeroAngleAxisToRotationMatrix) {
-  double axis_angle[3] = { 0, 0, 0 };
+  double axis_angle[3] = {0, 0, 0};
   double matrix[9];
-  double expected[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
+  double expected[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1};
   AngleAxisToRotationMatrix(axis_angle, matrix);
   EXPECT_THAT(matrix, IsOrthonormal());
   EXPECT_THAT(matrix, IsNear3x3Matrix(expected));
 }
 
 TEST(Rotation, NearZeroAngleAxisToRotationMatrix) {
-  double axis_angle[3] = { 1e-24, 2e-24, 3e-24 };
+  double axis_angle[3] = {1e-24, 2e-24, 3e-24};
   double matrix[9];
-  double expected[9] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
+  double expected[9] = {1, 0, 0, 0, 1, 0, 0, 0, 1};
   AngleAxisToRotationMatrix(axis_angle, matrix);
   EXPECT_THAT(matrix, IsOrthonormal());
   EXPECT_THAT(matrix, IsNear3x3Matrix(expected));
@@ -417,10 +423,10 @@
 
 // Transforms a rotation by pi/2 around X to a rotation matrix and back.
 TEST(Rotation, XRotationToRotationMatrix) {
-  double axis_angle[3] = { kPi / 2, 0, 0 };
+  double axis_angle[3] = {kPi / 2, 0, 0};
   double matrix[9];
   // The rotation matrices are stored column-major.
-  double expected[9] = { 1, 0, 0, 0, 0, 1, 0, -1, 0 };
+  double expected[9] = {1, 0, 0, 0, 0, 1, 0, -1, 0};
   AngleAxisToRotationMatrix(axis_angle, matrix);
   EXPECT_THAT(matrix, IsOrthonormal());
   EXPECT_THAT(matrix, IsNear3x3Matrix(expected));
@@ -432,9 +438,9 @@
 // Transforms an axis angle that rotates by pi about the Y axis to a
 // rotation matrix and back.
 TEST(Rotation, YRotationToRotationMatrix) {
-  double axis_angle[3] = { 0, kPi, 0 };
+  double axis_angle[3] = {0, kPi, 0};
   double matrix[9];
-  double expected[9] = { -1, 0, 0, 0, 1, 0, 0, 0, -1 };
+  double expected[9] = {-1, 0, 0, 0, 1, 0, 0, 0, -1};
   AngleAxisToRotationMatrix(axis_angle, matrix);
   EXPECT_THAT(matrix, IsOrthonormal());
   EXPECT_THAT(matrix, IsNear3x3Matrix(expected));
@@ -475,29 +481,31 @@
 
 TEST(Rotation, AtPiAngleAxisRoundTrip) {
   // A rotation of kPi about the X axis;
-  static const double kMatrix[3][3] = {
+  // clang-format off
+  static constexpr double kMatrix[3][3] = {
     {1.0,  0.0,  0.0},
     {0.0,  -1.0,  0.0},
     {0.0,  0.0,  -1.0}
   };
+  // clang-format on
 
   double in_matrix[9];
   // Fill it from kMatrix in col-major order.
   for (int j = 0, k = 0; j < 3; ++j) {
-     for (int i = 0; i < 3; ++i, ++k) {
-       in_matrix[k] = kMatrix[i][j];
-     }
+    for (int i = 0; i < 3; ++i, ++k) {
+      in_matrix[k] = kMatrix[i][j];
+    }
   }
 
-  const double expected_axis_angle[3] = { kPi, 0, 0 };
+  const double expected_axis_angle[3] = {kPi, 0, 0};
 
   double out_matrix[9];
   double axis_angle[3];
   RotationMatrixToAngleAxis(in_matrix, axis_angle);
   AngleAxisToRotationMatrix(axis_angle, out_matrix);
 
-  LOG(INFO) << "AngleAxis = " << axis_angle[0] << " " << axis_angle[1]
-            << " " << axis_angle[2];
+  LOG(INFO) << "AngleAxis = " << axis_angle[0] << " " << axis_angle[1] << " "
+            << axis_angle[2];
   LOG(INFO) << "Expected AngleAxis = " << kPi << " 0 0";
   double out_rowmajor[3][3];
   for (int j = 0, k = 0; j < 3; ++j) {
@@ -526,13 +534,15 @@
 // Transforms an axis angle that rotates by pi/3 about the Z axis to a
 // rotation matrix.
 TEST(Rotation, ZRotationToRotationMatrix) {
-  double axis_angle[3] =  { 0, 0, kPi / 3 };
+  double axis_angle[3] = {0, 0, kPi / 3};
   double matrix[9];
   // This is laid-out row-major on the screen but is actually stored
   // column-major.
+  // clang-format off
   double expected[9] = { 0.5, sqrt(3) / 2, 0,   // Column 1
                          -sqrt(3) / 2, 0.5, 0,  // Column 2
                          0, 0, 1 };             // Column 3
+  // clang-format on
   AngleAxisToRotationMatrix(axis_angle, matrix);
   EXPECT_THAT(matrix, IsOrthonormal());
   EXPECT_THAT(matrix, IsNear3x3Matrix(expected));
@@ -602,13 +612,12 @@
     RotationMatrixToAngleAxis(matrix, round_trip);
 
     for (int i = 0; i < 3; ++i) {
-      EXPECT_NEAR(round_trip[i], axis_angle[i],
-                  numeric_limits<double>::epsilon());
+      EXPECT_NEAR(
+          round_trip[i], axis_angle[i], numeric_limits<double>::epsilon());
     }
   }
 }
 
-
 // Transposes a 3x3 matrix.
 static void Transpose3x3(double m[9]) {
   swap(m[1], m[3]);
@@ -647,8 +656,7 @@
   for (double x = -1.0; x <= 1.0; x += 1.0) {
     for (double y = -1.0; y <= 1.0; y += 1.0) {
       for (double z = -1.0; z <= 1.0; z += 1.0) {
-        if ((x != 0) + (y != 0) + (z != 0) > 1)
-          continue;
+        if ((x != 0) + (y != 0) + (z != 0) > 1) continue;
         double axis_angle[3] = {x, y, z};
         double euler_angles[3] = {x, y, z};
         CompareEulerToAngleAxis(axis_angle, euler_angles);
@@ -680,6 +688,8 @@
 typedef Jet<double, 3> J3;
 typedef Jet<double, 4> J4;
 
+namespace {
+
 J3 MakeJ3(double a, double v0, double v1, double v2) {
   J3 j;
   j.a = a;
@@ -705,8 +715,10 @@
   return internal::IsClose(x, y, kTolerance, NULL, NULL);
 }
 
+}  // namespace
+
 template <int N>
-bool IsClose(const Jet<double, N> &x, const Jet<double, N> &y) {
+bool IsClose(const Jet<double, N>& x, const Jet<double, N>& y) {
   if (!IsClose(x.a, y.a)) {
     return false;
   }
@@ -719,7 +731,7 @@
 }
 
 template <int M, int N>
-void ExpectJetArraysClose(const Jet<double, N> *x, const Jet<double, N> *y) {
+void ExpectJetArraysClose(const Jet<double, N>* x, const Jet<double, N>* y) {
   for (int i = 0; i < M; i++) {
     if (!IsClose(x[i], y[i])) {
       LOG(ERROR) << "Jet " << i << "/" << M << " not equal";
@@ -738,11 +750,11 @@
 
 // Log-10 of a value well below machine precision.
 static const int kSmallTinyCutoff =
-    static_cast<int>(2 * log(numeric_limits<double>::epsilon())/log(10.0));
+    static_cast<int>(2 * log(numeric_limits<double>::epsilon()) / log(10.0));
 
 // Log-10 of a value just below values representable by double.
-static const int kTinyZeroLimit   =
-    static_cast<int>(1 + log(numeric_limits<double>::min())/log(10.0));
+static const int kTinyZeroLimit =
+    static_cast<int>(1 + log(numeric_limits<double>::min()) / log(10.0));
 
 // Test that exact conversion works for small angles when jets are used.
 TEST(Rotation, SmallAngleAxisToQuaternionForJets) {
@@ -750,27 +762,26 @@
   // to be well within the range represented by doubles.
   for (int i = -2; i >= kSmallTinyCutoff; i--) {
     double theta = pow(10.0, i);
-    J3 axis_angle[3] = { J3(theta, 0), J3(0, 1), J3(0, 2) };
+    J3 axis_angle[3] = {J3(theta, 0), J3(0, 1), J3(0, 2)};
     J3 quaternion[4];
     J3 expected[4] = {
-        MakeJ3(cos(theta/2), -sin(theta/2)/2, 0, 0),
-        MakeJ3(sin(theta/2), cos(theta/2)/2, 0, 0),
-        MakeJ3(0, 0, sin(theta/2)/theta, 0),
-        MakeJ3(0, 0, 0, sin(theta/2)/theta),
+        MakeJ3(cos(theta / 2), -sin(theta / 2) / 2, 0, 0),
+        MakeJ3(sin(theta / 2), cos(theta / 2) / 2, 0, 0),
+        MakeJ3(0, 0, sin(theta / 2) / theta, 0),
+        MakeJ3(0, 0, 0, sin(theta / 2) / theta),
     };
     AngleAxisToQuaternion(axis_angle, quaternion);
     ExpectJetArraysClose<4, 3>(quaternion, expected);
   }
 }
 
-
 // Test that conversion works for very small angles when jets are used.
 TEST(Rotation, TinyAngleAxisToQuaternionForJets) {
   // Examine tiny x rotations that extend all the way to where
   // underflow occurs.
   for (int i = kSmallTinyCutoff; i >= kTinyZeroLimit; i--) {
     double theta = pow(10.0, i);
-    J3 axis_angle[3] = { J3(theta, 0), J3(0, 1), J3(0, 2) };
+    J3 axis_angle[3] = {J3(theta, 0), J3(0, 1), J3(0, 2)};
     J3 quaternion[4];
     // To avoid loss of precision in the test itself,
     // a finite expansion is used here, which will
@@ -788,7 +799,7 @@
 
 // Test that derivatives are correct for zero rotation.
 TEST(Rotation, ZeroAngleAxisToQuaternionForJets) {
-  J3 axis_angle[3] = { J3(0, 0), J3(0, 1), J3(0, 2) };
+  J3 axis_angle[3] = {J3(0, 0), J3(0, 1), J3(0, 2)};
   J3 quaternion[4];
   J3 expected[4] = {
       MakeJ3(1.0, 0, 0, 0),
@@ -808,13 +819,15 @@
     double theta = pow(10.0, i);
     double s = sin(theta);
     double c = cos(theta);
-    J4 quaternion[4] = { J4(c, 0), J4(s, 1), J4(0, 2), J4(0, 3) };
+    J4 quaternion[4] = {J4(c, 0), J4(s, 1), J4(0, 2), J4(0, 3)};
     J4 axis_angle[3];
+    // clang-format off
     J4 expected[3] = {
         MakeJ4(2*theta, -2*s, 2*c,  0,         0),
         MakeJ4(0,        0,   0,    2*theta/s, 0),
         MakeJ4(0,        0,   0,    0,         2*theta/s),
     };
+    // clang-format on
     QuaternionToAngleAxis(quaternion, axis_angle);
     ExpectJetArraysClose<3, 4>(axis_angle, expected);
   }
@@ -828,16 +841,18 @@
     double theta = pow(10.0, i);
     double s = sin(theta);
     double c = cos(theta);
-    J4 quaternion[4] = { J4(c, 0), J4(s, 1), J4(0, 2), J4(0, 3) };
+    J4 quaternion[4] = {J4(c, 0), J4(s, 1), J4(0, 2), J4(0, 3)};
     J4 axis_angle[3];
     // To avoid loss of precision in the test itself,
     // a finite expansion is used here, which will
     // be exact up to machine precision for the test values used.
+    // clang-format off
     J4 expected[3] = {
         MakeJ4(2*theta, -2*s, 2.0, 0,   0),
         MakeJ4(0,        0,   0,   2.0, 0),
         MakeJ4(0,        0,   0,   0,   2.0),
     };
+    // clang-format on
     QuaternionToAngleAxis(quaternion, axis_angle);
     ExpectJetArraysClose<3, 4>(axis_angle, expected);
   }
@@ -845,7 +860,7 @@
 
 // Test that conversion works for no rotation.
 TEST(Rotation, ZeroQuaternionToAngleAxisForJets) {
-  J4 quaternion[4] = { J4(1, 0), J4(0, 1), J4(0, 2), J4(0, 3) };
+  J4 quaternion[4] = {J4(1, 0), J4(0, 1), J4(0, 2), J4(0, 3)};
   J4 axis_angle[3];
   J4 expected[3] = {
       MakeJ4(0, 0, 2.0, 0, 0),
@@ -859,20 +874,22 @@
 TEST(Quaternion, RotatePointGivesSameAnswerAsRotationByMatrixCanned) {
   // Canned data generated in octave.
   double const q[4] = {
-    +0.1956830471754074,
-    -0.0150618562474847,
-    +0.7634572982788086,
-    -0.3019454777240753,
+      +0.1956830471754074,
+      -0.0150618562474847,
+      +0.7634572982788086,
+      -0.3019454777240753,
   };
-  double const Q[3][3] = {  // Scaled rotation matrix.
-    { -0.6355194033477252,  0.0951730541682254,  0.3078870197911186 },
-    { -0.1411693904792992,  0.5297609702153905, -0.4551502574482019 },
-    { -0.2896955822708862, -0.4669396571547050, -0.4536309793389248 },
+  double const Q[3][3] = {
+      // Scaled rotation matrix.
+      {-0.6355194033477252, +0.0951730541682254, +0.3078870197911186},
+      {-0.1411693904792992, +0.5297609702153905, -0.4551502574482019},
+      {-0.2896955822708862, -0.4669396571547050, -0.4536309793389248},
   };
-  double const R[3][3] = {  // With unit rows and columns.
-    { -0.8918859164053080,  0.1335655625725649,  0.4320876677394745 },
-    { -0.1981166751680096,  0.7434648665444399, -0.6387564287225856 },
-    { -0.4065578619806013, -0.6553016349046693, -0.6366242786393164 },
+  double const R[3][3] = {
+      // With unit rows and columns.
+      {-0.8918859164053080, +0.1335655625725649, +0.4320876677394745},
+      {-0.1981166751680096, +0.7434648665444399, -0.6387564287225856},
+      {-0.4065578619806013, -0.6553016349046693, -0.6366242786393164},
   };
 
   // Compute R from q and compare to known answer.
@@ -885,19 +902,18 @@
   ExpectArraysClose(9, R[0], Rq[0], kTolerance);
 }
 
-
 TEST(Quaternion, RotatePointGivesSameAnswerAsRotationByMatrix) {
   // Rotation defined by a unit quaternion.
   double const q[4] = {
-    0.2318160216097109,
-    -0.0178430356832060,
-    0.9044300776717159,
-    -0.3576998641394597,
+      +0.2318160216097109,
+      -0.0178430356832060,
+      +0.9044300776717159,
+      -0.3576998641394597,
   };
   double const p[3] = {
-    +0.11,
-    -13.15,
-    1.17,
+      +0.11,
+      -13.15,
+      1.17,
   };
 
   double R[3 * 3];
@@ -907,11 +923,10 @@
   UnitQuaternionRotatePoint(q, p, result1);
 
   double result2[3];
-  VectorRef(result2, 3) = ConstMatrixRef(R, 3, 3)* ConstVectorRef(p, 3);
+  VectorRef(result2, 3) = ConstMatrixRef(R, 3, 3) * ConstVectorRef(p, 3);
   ExpectArraysClose(3, result1, result2, kTolerance);
 }
 
-
 // Verify that (a * b) * c == a * (b * c).
 TEST(Quaternion, MultiplicationIsAssociative) {
   double a[4];
@@ -939,7 +954,6 @@
   ASSERT_NEAR(ab_c[3], a_bc[3], kTolerance);
 }
 
-
 TEST(AngleAxis, RotatePointGivesSameAnswerAsRotationMatrix) {
   double angle_axis[3];
   double R[9];
@@ -969,6 +983,7 @@
 
       AngleAxisRotatePoint(angle_axis, p, angle_axis_rotated_p);
       for (int k = 0; k < 3; ++k) {
+        // clang-format off
         EXPECT_NEAR(rotation_matrix_rotated_p[k],
                     angle_axis_rotated_p[k],
                     kTolerance) << "p: " << p[0]
@@ -977,6 +992,7 @@
                                 << " angle_axis: " << angle_axis[0]
                                 << " " << angle_axis[1]
                                 << " " << angle_axis[2];
+        // clang-format on
       }
     }
   }
@@ -997,7 +1013,7 @@
       norm2 = angle_axis[k] * angle_axis[k];
     }
 
-    double theta = (2.0 * i * 0.0001  - 1.0) * 1e-16;
+    double theta = (2.0 * i * 0.0001 - 1.0) * 1e-16;
     const double inv_norm = theta / sqrt(norm2);
     for (int k = 0; k < 3; ++k) {
       angle_axis[k] *= inv_norm;
@@ -1010,6 +1026,7 @@
 
     AngleAxisRotatePoint(angle_axis, p, angle_axis_rotated_p);
     for (int k = 0; k < 3; ++k) {
+      // clang-format off
       EXPECT_NEAR(rotation_matrix_rotated_p[k],
                   angle_axis_rotated_p[k],
                   kTolerance) << "p: " << p[0]
@@ -1018,14 +1035,15 @@
                               << " angle_axis: " << angle_axis[0]
                               << " " << angle_axis[1]
                               << " " << angle_axis[2];
+      // clang-format on
     }
   }
 }
 
 TEST(MatrixAdapter, RowMajor3x3ReturnTypeAndAccessIsCorrect) {
-  double array[9] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
-  const float const_array[9] =
-      { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f };
+  double array[9] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
+  const float const_array[9] = {
+      1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f};
   MatrixAdapter<double, 3, 1> A = RowMajorAdapter3x3(array);
   MatrixAdapter<const float, 3, 1> B = RowMajorAdapter3x3(const_array);
 
@@ -1033,16 +1051,16 @@
     for (int j = 0; j < 3; ++j) {
       // The values are integers from 1 to 9, so equality tests are appropriate
       // even for float and double values.
-      EXPECT_EQ(A(i, j), array[3*i+j]);
-      EXPECT_EQ(B(i, j), const_array[3*i+j]);
+      EXPECT_EQ(A(i, j), array[3 * i + j]);
+      EXPECT_EQ(B(i, j), const_array[3 * i + j]);
     }
   }
 }
 
 TEST(MatrixAdapter, ColumnMajor3x3ReturnTypeAndAccessIsCorrect) {
-  double array[9] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
-  const float const_array[9] =
-      { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f };
+  double array[9] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
+  const float const_array[9] = {
+      1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f};
   MatrixAdapter<double, 1, 3> A = ColumnMajorAdapter3x3(array);
   MatrixAdapter<const float, 1, 3> B = ColumnMajorAdapter3x3(const_array);
 
@@ -1050,29 +1068,33 @@
     for (int j = 0; j < 3; ++j) {
       // The values are integers from 1 to 9, so equality tests are
       // appropriate even for float and double values.
-      EXPECT_EQ(A(i, j), array[3*j+i]);
-      EXPECT_EQ(B(i, j), const_array[3*j+i]);
+      EXPECT_EQ(A(i, j), array[3 * j + i]);
+      EXPECT_EQ(B(i, j), const_array[3 * j + i]);
     }
   }
 }
 
 TEST(MatrixAdapter, RowMajor2x4IsCorrect) {
-  const int expected[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
+  const int expected[8] = {1, 2, 3, 4, 5, 6, 7, 8};
   int array[8];
   MatrixAdapter<int, 4, 1> M(array);
+  // clang-format off
   M(0, 0) = 1; M(0, 1) = 2; M(0, 2) = 3; M(0, 3) = 4;
   M(1, 0) = 5; M(1, 1) = 6; M(1, 2) = 7; M(1, 3) = 8;
+  // clang-format on
   for (int k = 0; k < 8; ++k) {
     EXPECT_EQ(array[k], expected[k]);
   }
 }
 
 TEST(MatrixAdapter, ColumnMajor2x4IsCorrect) {
-  const int expected[8] = { 1, 5, 2, 6, 3, 7, 4, 8 };
+  const int expected[8] = {1, 5, 2, 6, 3, 7, 4, 8};
   int array[8];
   MatrixAdapter<int, 1, 2> M(array);
+  // clang-format off
   M(0, 0) = 1; M(0, 1) = 2; M(0, 2) = 3; M(0, 3) = 4;
   M(1, 0) = 5; M(1, 1) = 6; M(1, 2) = 7; M(1, 3) = 8;
+  // clang-format on
   for (int k = 0; k < 8; ++k) {
     EXPECT_EQ(array[k], expected[k]);
   }
@@ -1080,11 +1102,13 @@
 
 TEST(RotationMatrixToAngleAxis, NearPiExampleOneFromTobiasStrauss) {
   // Example from Tobias Strauss
+  // clang-format off
   const double rotation_matrix[] = {
     -0.999807135425239,    -0.0128154391194470,   -0.0148814136745799,
     -0.0128154391194470,   -0.148441438622958,     0.988838158557669,
     -0.0148814136745799,    0.988838158557669,     0.148248574048196
   };
+  // clang-format on
 
   double angle_axis[3];
   RotationMatrixToAngleAxis(RowMajorAdapter3x3(rotation_matrix), angle_axis);
@@ -1093,9 +1117,9 @@
   EXPECT_THAT(rotation_matrix, IsNear3x3Matrix(round_trip));
 }
 
-void CheckRotationMatrixToAngleAxisRoundTrip(const double theta,
-                                             const double phi,
-                                             const double angle) {
+static void CheckRotationMatrixToAngleAxisRoundTrip(const double theta,
+                                                    const double phi,
+                                                    const double angle) {
   double angle_axis[3];
   angle_axis[0] = angle * sin(phi) * cos(theta);
   angle_axis[1] = angle * sin(phi) * sin(theta);