blob: 4b18cb9196225e8bc4138e7a21f41700075321c2 [file] [log] [blame]
Keir Mierle07f14052017-11-07 01:13:29 -08001# Ceres Solver - A fast non-linear least squares minimizer
Sameer Agarwal5a30cae2023-09-19 15:29:34 -07002# Copyright 2023 Google Inc. All rights reserved.
Keir Mierle07f14052017-11-07 01:13:29 -08003# http://ceres-solver.org/
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
7#
8# * Redistributions of source code must retain the above copyright notice,
9# this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above copyright notice,
11# this list of conditions and the following disclaimer in the documentation
12# and/or other materials provided with the distribution.
13# * Neither the name of Google Inc. nor the names of its contributors may be
14# used to endorse or promote products derived from this software without
15# specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28#
29# Author: mierle@gmail.com (Keir Mierle)
30#
31# These are Bazel rules to build Ceres. It's currently in Alpha state, and does
32# not support parameterization around threading choice or sparse backends.
33
Rodrigo Queiroc1075cd2018-01-15 14:07:47 +010034load("//:bazel/ceres.bzl", "ceres_library")
Keir Mierle07f14052017-11-07 01:13:29 -080035
Keir Mierle8549c882018-02-08 19:06:49 -080036ceres_library(
37 name = "ceres",
38 restrict_schur_specializations = False,
39)
Keir Mierle07f14052017-11-07 01:13:29 -080040
41cc_library(
Rodrigo Queiroac22a972018-01-15 12:55:57 +010042 name = "test_util",
43 srcs = ["internal/ceres/" + x for x in [
44 "evaluator_test_utils.cc",
45 "numeric_diff_test_utils.cc",
46 "test_util.cc",
47 "gmock_gtest_all.cc",
48 "gmock_main.cc",
Keir Mierle8549c882018-02-08 19:06:49 -080049 "gmock/gmock.h",
50 "gmock/mock-log.h",
51 "gtest/gtest.h",
Rodrigo Queiroac22a972018-01-15 12:55:57 +010052 ]],
Keir Mierle07f14052017-11-07 01:13:29 -080053 hdrs = [
Rodrigo Queiroac22a972018-01-15 12:55:57 +010054 "internal/ceres/gmock/gmock.h",
55 "internal/ceres/gmock/mock-log.h",
56 "internal/ceres/gtest/gtest.h",
57 ],
58 copts = [
59 "-Wno-sign-compare",
60 "-DCERES_TEST_SRCDIR_SUFFIX=\\\"data/\\\"",
61 ],
Rodrigo Queiroac22a972018-01-15 12:55:57 +010062 includes = [
63 "internal",
64 "internal/ceres",
65 ],
Keir Mierle07f14052017-11-07 01:13:29 -080066 deps = [
Rodrigo Queiroac22a972018-01-15 12:55:57 +010067 "//:ceres",
68 "@com_github_gflags_gflags//:gflags",
69 ],
Keir Mierle07f14052017-11-07 01:13:29 -080070)
71
72CERES_TESTS = [
Rodrigo Queiroac22a972018-01-15 12:55:57 +010073 "array_utils",
74 "autodiff_cost_function",
Sameer Agarwale6e6ae02022-01-24 13:16:00 -080075 "autodiff_manifold",
Rodrigo Queiroac22a972018-01-15 12:55:57 +010076 "autodiff",
77 "block_jacobi_preconditioner",
78 "block_random_access_dense_matrix",
79 "block_random_access_diagonal_matrix",
80 "block_random_access_sparse_matrix",
81 "block_sparse_matrix",
Rodrigo Queiroac22a972018-01-15 12:55:57 +010082 "canonical_views_clustering",
83 "c_api",
84 "compressed_col_sparse_matrix_utils",
85 "compressed_row_sparse_matrix",
Mike Vitus27789c02018-01-26 13:51:26 -080086 "concurrent_queue",
Rodrigo Queiroac22a972018-01-15 12:55:57 +010087 "conditioned_cost_function",
88 "conjugate_gradients_solver",
89 "corrector",
90 "cost_function_to_functor",
91 "covariance",
92 "cubic_interpolation",
Sameer Agarwale6e6ae02022-01-24 13:16:00 -080093 "dense_cholesky",
Rodrigo Queiroac22a972018-01-15 12:55:57 +010094 "dense_linear_solver",
95 "dense_sparse_matrix",
96 "detect_structure",
97 "dogleg_strategy",
98 "dynamic_autodiff_cost_function",
99 "dynamic_compressed_row_sparse_matrix",
100 "dynamic_numeric_diff_cost_function",
101 "dynamic_sparse_normal_cholesky_solver",
102 "dynamic_sparsity",
Keir Mierle7bdceb42018-01-10 17:14:57 -0800103 "evaluation_callback",
Rodrigo Queiroac22a972018-01-15 12:55:57 +0100104 "evaluator",
105 "gradient_checker",
106 "gradient_checking_cost_function",
107 "gradient_problem_solver",
108 "gradient_problem",
109 "graph_algorithms",
110 "graph",
111 "householder_vector",
112 "implicit_schur_complement",
113 "inner_product_computer",
114 "invert_psd_matrix",
115 "is_close",
Sameer Agarwal86814ab2018-04-05 11:48:26 -0700116 "iterative_refiner",
Rodrigo Queiroac22a972018-01-15 12:55:57 +0100117 "iterative_schur_complement_solver",
118 "jet",
119 "levenberg_marquardt_strategy",
120 "line_search_minimizer",
121 "line_search_preprocessor",
Rodrigo Queiroac22a972018-01-15 12:55:57 +0100122 "loss_function",
123 "minimizer",
124 "normal_prior",
125 "numeric_diff_cost_function",
126 "ordered_groups",
Mike Vitus126e0ef2018-02-22 11:06:24 -0800127 "parallel_for",
William Rucklidge21f519d2018-03-02 12:37:54 -0800128 "parallel_utils",
Rodrigo Queiroac22a972018-01-15 12:55:57 +0100129 "parameter_block_ordering",
130 "parameter_block",
131 "partitioned_matrix_view",
132 "polynomial",
133 "problem",
134 "program",
135 "reorder_program",
136 "residual_block",
137 "residual_block_utils",
138 "rotation",
139 "schur_complement_solver",
140 "schur_eliminator",
141 "single_linkage_clustering",
142 "small_blas",
143 "solver",
144 "sparse_cholesky",
145 "sparse_normal_cholesky_solver",
Sameer Agarwal9d02b762018-02-19 17:47:00 -0800146 "subset_preconditioner",
Rodrigo Queiroac22a972018-01-15 12:55:57 +0100147 "system",
Mike Vitus27789c02018-01-26 13:51:26 -0800148 "thread_pool",
Rodrigo Queiroac22a972018-01-15 12:55:57 +0100149 "tiny_solver_autodiff_function",
150 "tiny_solver_cost_function_adapter",
151 "tiny_solver",
152 "triplet_sparse_matrix",
153 "trust_region_minimizer",
154 "trust_region_preprocessor",
155 "visibility_based_preconditioner",
156 "visibility",
157]
Keir Mierle07f14052017-11-07 01:13:29 -0800158
Keir Mierle8549c882018-02-08 19:06:49 -0800159TEST_COPTS = [
Keir Mierlea3b1e192018-02-21 11:13:57 -0800160 # Needed to silence GFlags complaints.
Keir Mierle8549c882018-02-08 19:06:49 -0800161 "-Wno-sign-compare",
162
163 # These two warnings don't work well in conjunction with GMock, and
164 # trigger incorrectly on parts of rotation_test. For now, disable them,
165 # but in the future disable these warnings only for rotation_test.
166 # TODO(keir): When the tests are macro-ified, apply these selectively.
Keir Mierle8549c882018-02-08 19:06:49 -0800167 "-Wno-address",
168]
169
170TEST_DEPS = [
171 "//:ceres",
172 "//:test_util",
Sameer Agarwalbf47e1a2020-10-13 10:00:22 -0700173 "@com_gitlab_libeigen_eigen//:eigen",
Keir Mierle8549c882018-02-08 19:06:49 -0800174 "@com_github_gflags_gflags//:gflags",
175]
176
Keir Mierle07f14052017-11-07 01:13:29 -0800177# Instantiate all the tests with a template.
Keir Mierle07f14052017-11-07 01:13:29 -0800178[cc_test(
Rodrigo Queiroac22a972018-01-15 12:55:57 +0100179 name = test_name + "_test",
Keir Mierle8549c882018-02-08 19:06:49 -0800180 timeout = "short",
Rodrigo Queiroac22a972018-01-15 12:55:57 +0100181 srcs = ["internal/ceres/" + test_name + "_test.cc"],
Keir Mierle8549c882018-02-08 19:06:49 -0800182 copts = TEST_COPTS,
183 deps = TEST_DEPS,
Rodrigo Queiroac22a972018-01-15 12:55:57 +0100184) for test_name in CERES_TESTS]
Keir Mierle8549c882018-02-08 19:06:49 -0800185
186# Instantiate all the bundle adjustment tests. These are separate to
187# parallelize the execution of the tests; otherwise the tests take a long time.
188#
189# Note: While it is possible to run the Python script to generate the .cc files
190# as part of the build, it introduces an undesirable build-time Python
191# dependency that we'd prefer to avoid.
192[cc_test(
193 name = test_filename.split("/")[-1][:-3], # Remove .cc.
Alexander Ivanove1ca3302023-01-11 13:53:20 +0000194 timeout = "long",
Keir Mierle8549c882018-02-08 19:06:49 -0800195 srcs = [test_filename],
196 copts = TEST_COPTS,
197
198 # This is the data set that is bundled for the testing.
199 data = [":data/problem-16-22106-pre.txt"],
200 deps = TEST_DEPS,
201) for test_filename in glob([
202 "internal/ceres/generated_bundle_adjustment_tests/*_test.cc",
203])]
Keir Mierle22fa21c2018-02-25 15:18:08 -0800204
205# Build the benchmarks.
206[cc_binary(
207 name = benchmark_name,
208 srcs = ["internal/ceres/" + benchmark_name + ".cc"],
209 copts = TEST_COPTS,
210 deps = TEST_DEPS + ["@com_github_google_benchmark//:benchmark"],
211) for benchmark_name in [
Keir Mierle22fa21c2018-02-25 15:18:08 -0800212 "small_blas_gemm_benchmark",
213 "small_blas_gemv_benchmark",
214]]