Include what the public headers use Several public headers include headers they do not use, such as Eigen/Dense, while relying on transitive includes for symbols they do use. This exposes users to dependencies they may come to rely on and makes IWYU attribute symbols to unrelated headers. Remove the unused includes, forward declare types used only through pointers and references, and include the remaining dependencies directly. Change-Id: Ic8d44bf4d3d3cc00f030199d7207e06e77e2397c
diff --git a/include/ceres/accurate_norm.h b/include/ceres/accurate_norm.h index 63536ac..c9a8a6f 100644 --- a/include/ceres/accurate_norm.h +++ b/include/ceres/accurate_norm.h
@@ -59,7 +59,6 @@ #ifndef CERES_PUBLIC_ACCURATE_NORM_H_ #define CERES_PUBLIC_ACCURATE_NORM_H_ -#include <algorithm> #include <cmath> #include <limits> #include <type_traits>
diff --git a/include/ceres/autodiff_cost_function.h b/include/ceres/autodiff_cost_function.h index c10556c..68d7b66 100644 --- a/include/ceres/autodiff_cost_function.h +++ b/include/ceres/autodiff_cost_function.h
@@ -130,8 +130,11 @@ #include <memory> #include <type_traits> +#include <utility> +#include "absl/log/check.h" #include "ceres/internal/autodiff.h" +#include "ceres/internal/variadic_evaluate.h" #include "ceres/sized_cost_function.h" #include "ceres/types.h"
diff --git a/include/ceres/autodiff_first_order_function.h b/include/ceres/autodiff_first_order_function.h index 26ed414..fbd669a 100644 --- a/include/ceres/autodiff_first_order_function.h +++ b/include/ceres/autodiff_first_order_function.h
@@ -33,7 +33,9 @@ #include <memory> #include <type_traits> +#include <utility> +#include "Eigen/Core" #include "absl/container/fixed_array.h" #include "ceres/eigen.h" #include "ceres/first_order_function.h"
diff --git a/include/ceres/autodiff_manifold.h b/include/ceres/autodiff_manifold.h index 93cbba5..5ab8566 100644 --- a/include/ceres/autodiff_manifold.h +++ b/include/ceres/autodiff_manifold.h
@@ -34,6 +34,7 @@ #include <memory> #include "ceres/internal/autodiff.h" +#include "ceres/internal/parameter_dims.h" #include "ceres/manifold.h" namespace ceres {
diff --git a/include/ceres/conditioned_cost_function.h b/include/ceres/conditioned_cost_function.h index a2647c9..be63bf5 100644 --- a/include/ceres/conditioned_cost_function.h +++ b/include/ceres/conditioned_cost_function.h
@@ -39,6 +39,7 @@ #include "ceres/cost_function.h" #include "ceres/internal/disable_warnings.h" +#include "ceres/internal/export.h" #include "ceres/types.h" namespace ceres {
diff --git a/include/ceres/cost_function_to_functor.h b/include/ceres/cost_function_to_functor.h index f8aeba6..04c0f3e 100644 --- a/include/ceres/cost_function_to_functor.h +++ b/include/ceres/cost_function_to_functor.h
@@ -86,9 +86,10 @@ #ifndef CERES_PUBLIC_COST_FUNCTION_TO_FUNCTOR_H_ #define CERES_PUBLIC_COST_FUNCTION_TO_FUNCTOR_H_ +#include <array> #include <cstdint> +#include <memory> #include <numeric> -#include <tuple> #include <utility> #include <vector>
diff --git a/include/ceres/dynamic_autodiff_cost_function.h b/include/ceres/dynamic_autodiff_cost_function.h index b9912be..2efb4c0 100644 --- a/include/ceres/dynamic_autodiff_cost_function.h +++ b/include/ceres/dynamic_autodiff_cost_function.h
@@ -36,6 +36,7 @@ #include <memory> #include <numeric> #include <type_traits> +#include <utility> #include <vector> #include "absl/container/fixed_array.h"
diff --git a/include/ceres/dynamic_cost_function.h b/include/ceres/dynamic_cost_function.h index 02ce1e9..b0d6ca2 100644 --- a/include/ceres/dynamic_cost_function.h +++ b/include/ceres/dynamic_cost_function.h
@@ -31,8 +31,11 @@ #ifndef CERES_PUBLIC_DYNAMIC_COST_FUNCTION_H_ #define CERES_PUBLIC_DYNAMIC_COST_FUNCTION_H_ +#include <vector> + #include "ceres/cost_function.h" #include "ceres/internal/disable_warnings.h" +#include "ceres/internal/export.h" namespace ceres {
diff --git a/include/ceres/dynamic_cost_function_to_functor.h b/include/ceres/dynamic_cost_function_to_functor.h index 8030eff..875b644 100644 --- a/include/ceres/dynamic_cost_function_to_functor.h +++ b/include/ceres/dynamic_cost_function_to_functor.h
@@ -32,13 +32,13 @@ #ifndef CERES_PUBLIC_DYNAMIC_COST_FUNCTION_TO_FUNCTOR_H_ #define CERES_PUBLIC_DYNAMIC_COST_FUNCTION_TO_FUNCTOR_H_ +#include <cstdint> #include <memory> #include <numeric> #include <vector> #include "absl/container/fixed_array.h" -#include "absl/log/check.h" -#include "ceres/dynamic_cost_function.h" +#include "ceres/cost_function.h" #include "ceres/internal/disable_warnings.h" #include "ceres/internal/export.h"
diff --git a/include/ceres/dynamic_numeric_diff_cost_function.h b/include/ceres/dynamic_numeric_diff_cost_function.h index bfba17e..9bc855b 100644 --- a/include/ceres/dynamic_numeric_diff_cost_function.h +++ b/include/ceres/dynamic_numeric_diff_cost_function.h
@@ -34,18 +34,21 @@ #ifndef CERES_PUBLIC_DYNAMIC_NUMERIC_DIFF_COST_FUNCTION_H_ #define CERES_PUBLIC_DYNAMIC_NUMERIC_DIFF_COST_FUNCTION_H_ -#include <cmath> +#include <algorithm> +#include <cstddef> +#include <cstdint> #include <memory> #include <numeric> #include <type_traits> +#include <utility> #include <vector> #include "absl/container/fixed_array.h" #include "absl/log/check.h" #include "ceres/dynamic_cost_function.h" -#include "ceres/eigen.h" #include "ceres/internal/numeric_diff.h" #include "ceres/internal/parameter_dims.h" +#include "ceres/internal/variadic_evaluate.h" #include "ceres/numeric_diff_options.h" #include "ceres/types.h"
diff --git a/include/ceres/gradient_checker.h b/include/ceres/gradient_checker.h index b078942..8f37f10 100644 --- a/include/ceres/gradient_checker.h +++ b/include/ceres/gradient_checker.h
@@ -37,15 +37,17 @@ #include <string> #include <vector> +#include "Eigen/Core" #include "ceres/cost_function.h" -#include "ceres/dynamic_numeric_diff_cost_function.h" #include "ceres/eigen.h" #include "ceres/internal/disable_warnings.h" #include "ceres/internal/export.h" -#include "ceres/manifold.h" namespace ceres { +class Manifold; +struct NumericDiffOptions; + // GradientChecker compares the Jacobians returned by a cost function against // derivatives estimated using finite differencing. //
diff --git a/include/ceres/gradient_problem.h b/include/ceres/gradient_problem.h index e6e1364..0349da8 100644 --- a/include/ceres/gradient_problem.h +++ b/include/ceres/gradient_problem.h
@@ -40,8 +40,6 @@ namespace ceres { -class FirstOrderFunction; - // Instances of GradientProblem represent general non-linear // optimization problems that must be solved using just the value of // the objective function and its gradient.
diff --git a/include/ceres/gradient_problem_solver.h b/include/ceres/gradient_problem_solver.h index e9ae6f5..886b3dc 100644 --- a/include/ceres/gradient_problem_solver.h +++ b/include/ceres/gradient_problem_solver.h
@@ -31,7 +31,6 @@ #ifndef CERES_PUBLIC_GRADIENT_PROBLEM_SOLVER_H_ #define CERES_PUBLIC_GRADIENT_PROBLEM_SOLVER_H_ -#include <cmath> #include <string> #include <vector>
diff --git a/include/ceres/internal/householder_vector.h b/include/ceres/internal/householder_vector.h index 0d35ccd..b9bef0a 100644 --- a/include/ceres/internal/householder_vector.h +++ b/include/ceres/internal/householder_vector.h
@@ -33,6 +33,8 @@ // IWYU pragma: private +#include <limits> + #include "Eigen/Core" #include "absl/log/check.h"
diff --git a/include/ceres/internal/integer_sequence_algorithm.h b/include/ceres/internal/integer_sequence_algorithm.h index 267a1d2..dd7d8d1 100644 --- a/include/ceres/internal/integer_sequence_algorithm.h +++ b/include/ceres/internal/integer_sequence_algorithm.h
@@ -38,6 +38,7 @@ // IWYU pragma: private +#include <type_traits> #include <utility> #include "ceres/jet_fwd.h"
diff --git a/include/ceres/internal/numeric_diff.h b/include/ceres/internal/numeric_diff.h index 07d1c70..626b292 100644 --- a/include/ceres/internal/numeric_diff.h +++ b/include/ceres/internal/numeric_diff.h
@@ -37,7 +37,11 @@ // IWYU pragma: private +#include <algorithm> +#include <cmath> +#include <cstddef> #include <cstring> +#include <limits> #include <utility> #include "Eigen/Dense"
diff --git a/include/ceres/internal/sphere_manifold_functions.h b/include/ceres/internal/sphere_manifold_functions.h index ee39c89..4d4de5d 100644 --- a/include/ceres/internal/sphere_manifold_functions.h +++ b/include/ceres/internal/sphere_manifold_functions.h
@@ -34,6 +34,9 @@ // IWYU pragma: private +#include <cmath> + +#include "Eigen/Core" #include "ceres/constants.h" #include "ceres/internal/householder_vector.h"
diff --git a/include/ceres/jet.h b/include/ceres/jet.h index 4768693..180e5ab 100644 --- a/include/ceres/jet.h +++ b/include/ceres/jet.h
@@ -163,7 +163,6 @@ #include <iostream> // NOLINT #include <limits> #include <numeric> -#include <string> #include <type_traits> #include "Eigen/Core"
diff --git a/include/ceres/line_manifold.h b/include/ceres/line_manifold.h index dae98d8..a98d923 100644 --- a/include/ceres/line_manifold.h +++ b/include/ceres/line_manifold.h
@@ -33,10 +33,6 @@ #define CERES_PUBLIC_LINE_MANIFOLD_H_ #include <Eigen/Core> -#include <algorithm> -#include <array> -#include <memory> -#include <vector> #include "absl/log/check.h" #include "ceres/internal/disable_warnings.h"
diff --git a/include/ceres/manifold.h b/include/ceres/manifold.h index b82c3b0..3e70e5d 100644 --- a/include/ceres/manifold.h +++ b/include/ceres/manifold.h
@@ -33,9 +33,6 @@ #include <Eigen/Core> #include <algorithm> -#include <array> -#include <memory> -#include <utility> #include <vector> #include "absl/log/check.h"
diff --git a/include/ceres/manifold_test_utils.h b/include/ceres/manifold_test_utils.h index eb513cc..f89b806 100644 --- a/include/ceres/manifold_test_utils.h +++ b/include/ceres/manifold_test_utils.h
@@ -32,9 +32,6 @@ #define CERES_PUBLIC_MANIFOLD_TEST_UTILS_H_ #include <algorithm> -#include <cmath> -#include <limits> -#include <memory> #include <type_traits> #include "Eigen/Core"
diff --git a/include/ceres/normal_prior.h b/include/ceres/normal_prior.h index beeac53..5196781 100644 --- a/include/ceres/normal_prior.h +++ b/include/ceres/normal_prior.h
@@ -34,9 +34,11 @@ #ifndef CERES_PUBLIC_NORMAL_PRIOR_H_ #define CERES_PUBLIC_NORMAL_PRIOR_H_ +#include "Eigen/Core" #include "ceres/cost_function.h" #include "ceres/eigen.h" #include "ceres/internal/disable_warnings.h" +#include "ceres/internal/export.h" namespace ceres {
diff --git a/include/ceres/numeric_diff_cost_function.h b/include/ceres/numeric_diff_cost_function.h index 9866d36..3347fbc 100644 --- a/include/ceres/numeric_diff_cost_function.h +++ b/include/ceres/numeric_diff_cost_function.h
@@ -165,11 +165,13 @@ #include <array> #include <memory> #include <type_traits> +#include <utility> -#include "Eigen/Dense" -#include "ceres/cost_function.h" +#include "absl/container/fixed_array.h" +#include "absl/log/check.h" #include "ceres/internal/numeric_diff.h" #include "ceres/internal/parameter_dims.h" +#include "ceres/internal/variadic_evaluate.h" #include "ceres/numeric_diff_options.h" #include "ceres/sized_cost_function.h" #include "ceres/types.h"
diff --git a/include/ceres/numeric_diff_first_order_function.h b/include/ceres/numeric_diff_first_order_function.h index 0bd2d82..038c0a4 100644 --- a/include/ceres/numeric_diff_first_order_function.h +++ b/include/ceres/numeric_diff_first_order_function.h
@@ -38,7 +38,6 @@ #include "absl/container/fixed_array.h" #include "absl/log/check.h" -#include "ceres/eigen.h" #include "ceres/first_order_function.h" #include "ceres/internal/numeric_diff.h" #include "ceres/internal/parameter_dims.h"
diff --git a/include/ceres/problem.h b/include/ceres/problem.h index 3d98158..3107045 100644 --- a/include/ceres/problem.h +++ b/include/ceres/problem.h
@@ -35,13 +35,9 @@ #define CERES_PUBLIC_PROBLEM_H_ #include <array> -#include <cstddef> -#include <map> #include <memory> -#include <set> #include <vector> -#include "ceres/context.h" #include "ceres/internal/disable_warnings.h" #include "ceres/internal/export.h" #include "ceres/internal/port.h" @@ -49,17 +45,15 @@ namespace ceres { +class Context; class CostFunction; class EvaluationCallback; class LossFunction; class Manifold; -class Solver; struct CRSMatrix; namespace internal { -class Preprocessor; class ProblemImpl; -class ParameterBlock; class ResidualBlock; } // namespace internal
diff --git a/include/ceres/product_manifold.h b/include/ceres/product_manifold.h index 41fe258..2fa30e9 100644 --- a/include/ceres/product_manifold.h +++ b/include/ceres/product_manifold.h
@@ -42,6 +42,7 @@ #include <type_traits> #include <utility> +#include "Eigen/Core" #include "absl/container/fixed_array.h" #include "ceres/eigen.h" #include "ceres/internal/port.h"
diff --git a/include/ceres/rotation.h b/include/ceres/rotation.h index 8647fbf..f9020ce 100644 --- a/include/ceres/rotation.h +++ b/include/ceres/rotation.h
@@ -45,7 +45,6 @@ #ifndef CERES_PUBLIC_ROTATION_H_ #define CERES_PUBLIC_ROTATION_H_ -#include <algorithm> #include <array> #include <cmath> #include <type_traits>
diff --git a/include/ceres/sized_cost_function.h b/include/ceres/sized_cost_function.h index a956ebd..3bc0511 100644 --- a/include/ceres/sized_cost_function.h +++ b/include/ceres/sized_cost_function.h
@@ -38,6 +38,7 @@ #ifndef CERES_PUBLIC_SIZED_COST_FUNCTION_H_ #define CERES_PUBLIC_SIZED_COST_FUNCTION_H_ +#include <cstdint> #include <initializer_list> #include "ceres/cost_function.h"
diff --git a/include/ceres/solver.h b/include/ceres/solver.h index 97ab583..baa6fa6 100644 --- a/include/ceres/solver.h +++ b/include/ceres/solver.h
@@ -31,13 +31,11 @@ #ifndef CERES_PUBLIC_SOLVER_H_ #define CERES_PUBLIC_SOLVER_H_ -#include <cmath> #include <memory> #include <string> #include <unordered_set> #include <vector> -#include "ceres/crs_matrix.h" #include "ceres/internal/config.h" #include "ceres/internal/disable_warnings.h" #include "ceres/internal/export.h"
diff --git a/include/ceres/sphere_manifold.h b/include/ceres/sphere_manifold.h index fa1228f..3cadab4 100644 --- a/include/ceres/sphere_manifold.h +++ b/include/ceres/sphere_manifold.h
@@ -33,10 +33,6 @@ #define CERES_PUBLIC_SPHERE_MANIFOLD_H_ #include <Eigen/Core> -#include <algorithm> -#include <array> -#include <memory> -#include <vector> #include "absl/log/check.h" #include "ceres/internal/disable_warnings.h"
diff --git a/include/ceres/tiny_solver.h b/include/ceres/tiny_solver.h index b2b1ba1..bf82d76 100644 --- a/include/ceres/tiny_solver.h +++ b/include/ceres/tiny_solver.h
@@ -54,9 +54,10 @@ #include <algorithm> #include <cassert> #include <cmath> +#include <limits> +#include "Eigen/Cholesky" #include "Eigen/Core" -#include "Eigen/Dense" namespace ceres {
diff --git a/include/ceres/tiny_solver_autodiff_function.h b/include/ceres/tiny_solver_autodiff_function.h index 045ea43..3a76baa 100644 --- a/include/ceres/tiny_solver_autodiff_function.h +++ b/include/ceres/tiny_solver_autodiff_function.h
@@ -35,9 +35,6 @@ #ifndef CERES_PUBLIC_TINY_SOLVER_AUTODIFF_FUNCTION_H_ #define CERES_PUBLIC_TINY_SOLVER_AUTODIFF_FUNCTION_H_ -#include <memory> -#include <type_traits> - #include "Eigen/Core" #include "ceres/jet.h" #include "ceres/types.h" // For kImpossibleValue.
diff --git a/include/ceres/tiny_solver_cost_function_adapter.h b/include/ceres/tiny_solver_cost_function_adapter.h index 92d78d2..f53693a 100644 --- a/include/ceres/tiny_solver_cost_function_adapter.h +++ b/include/ceres/tiny_solver_cost_function_adapter.h
@@ -31,6 +31,8 @@ #ifndef CERES_PUBLIC_TINY_SOLVER_COST_FUNCTION_ADAPTER_H_ #define CERES_PUBLIC_TINY_SOLVER_COST_FUNCTION_ADAPTER_H_ +#include <vector> + #include "Eigen/Core" #include "absl/log/check.h" #include "ceres/cost_function.h"
diff --git a/internal/ceres/gradient_checker.cc b/internal/ceres/gradient_checker.cc index dffbba2..d08b568 100644 --- a/internal/ceres/gradient_checker.cc +++ b/internal/ceres/gradient_checker.cc
@@ -43,7 +43,10 @@ #include "absl/log/log.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" +#include "ceres/dynamic_numeric_diff_cost_function.h" #include "ceres/is_close.h" +#include "ceres/manifold.h" +#include "ceres/numeric_diff_options.h" #include "ceres/types.h" namespace ceres {
diff --git a/internal/ceres/gradient_checker_test.cc b/internal/ceres/gradient_checker_test.cc index 0b9f3a6..e82f77f 100644 --- a/internal/ceres/gradient_checker_test.cc +++ b/internal/ceres/gradient_checker_test.cc
@@ -41,6 +41,8 @@ #include "absl/log/check.h" #include "absl/log/log.h" #include "ceres/cost_function.h" +#include "ceres/manifold.h" +#include "ceres/numeric_diff_options.h" #include "ceres/problem.h" #include "ceres/solver.h" #include "ceres/test_util.h"
diff --git a/internal/ceres/gradient_checking_cost_function.cc b/internal/ceres/gradient_checking_cost_function.cc index 94afa94..228c42c 100644 --- a/internal/ceres/gradient_checking_cost_function.cc +++ b/internal/ceres/gradient_checking_cost_function.cc
@@ -47,6 +47,7 @@ #include "ceres/dynamic_numeric_diff_cost_function.h" #include "ceres/eigen.h" #include "ceres/gradient_checker.h" +#include "ceres/numeric_diff_options.h" #include "ceres/parameter_block.h" #include "ceres/problem.h" #include "ceres/problem_impl.h"
diff --git a/internal/ceres/problem_impl.h b/internal/ceres/problem_impl.h index c366f0e..d292c4f 100644 --- a/internal/ceres/problem_impl.h +++ b/internal/ceres/problem_impl.h
@@ -64,6 +64,7 @@ namespace internal { +class ParameterBlock; class Program; class ResidualBlock;