blob: cb258447bdbcfd565db81fdcb446d483bbe30416 [file] [log] [blame]
Austin Schuh033df092019-01-21 19:46:48 -08001# Ceres Solver - A fast non-linear least squares minimizer
2# Copyright 2018 Google Inc. All rights reserved.
3# 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
34load("//:bazel/ceres.bzl", "ceres_library")
James Kuszmaul9776b392023-01-14 14:08:08 -080035load("@org_frc971//tools/build_rules:select.bzl", "compiler_select")
Austin Schuh033df092019-01-21 19:46:48 -080036
37ceres_library(
38 name = "ceres",
39 restrict_schur_specializations = False,
40)
41
42cc_library(
43 name = "test_util",
44 srcs = ["internal/ceres/" + x for x in [
45 "evaluator_test_utils.cc",
46 "numeric_diff_test_utils.cc",
47 "test_util.cc",
48 "gmock_gtest_all.cc",
49 "gmock_main.cc",
50 "gmock/gmock.h",
51 "gmock/mock-log.h",
52 "gtest/gtest.h",
53 ]],
54 hdrs = [
55 "internal/ceres/gmock/gmock.h",
56 "internal/ceres/gmock/mock-log.h",
57 "internal/ceres/gtest/gtest.h",
58 ],
59 copts = [
60 "-Wno-sign-compare",
Brian Silverman4c7235a2021-11-17 19:04:37 -080061 "-Wno-unused-but-set-variable",
Austin Schuh033df092019-01-21 19:46:48 -080062 "-DCERES_TEST_SRCDIR_SUFFIX=\\\"data/\\\"",
Austin Schuh033df092019-01-21 19:46:48 -080063 ],
64 includes = [
65 "internal",
66 "internal/ceres",
67 ],
68 deps = [
69 "//:ceres",
70 "@com_github_gflags_gflags//:gflags",
71 ],
72)
73
74CERES_TESTS = [
75 "array_utils",
76 "autodiff_cost_function",
77 "autodiff_local_parameterization",
78 "autodiff",
79 "block_jacobi_preconditioner",
80 "block_random_access_dense_matrix",
81 "block_random_access_diagonal_matrix",
82 "block_random_access_sparse_matrix",
83 "block_sparse_matrix",
84 "canonical_views_clustering",
85 "c_api",
86 "compressed_col_sparse_matrix_utils",
87 "compressed_row_sparse_matrix",
88 "concurrent_queue",
89 "conditioned_cost_function",
90 "conjugate_gradients_solver",
91 "corrector",
92 "cost_function_to_functor",
93 "covariance",
94 "cubic_interpolation",
95 "dense_linear_solver",
96 "dense_sparse_matrix",
97 "detect_structure",
98 "dogleg_strategy",
99 "dynamic_autodiff_cost_function",
100 "dynamic_compressed_row_sparse_matrix",
101 "dynamic_numeric_diff_cost_function",
102 "dynamic_sparse_normal_cholesky_solver",
103 "dynamic_sparsity",
104 "evaluation_callback",
105 "evaluator",
106 "gradient_checker",
107 "gradient_checking_cost_function",
108 "gradient_problem_solver",
109 "gradient_problem",
110 "graph_algorithms",
111 "graph",
112 "householder_vector",
113 "implicit_schur_complement",
114 "inner_product_computer",
115 "invert_psd_matrix",
116 "is_close",
117 "iterative_refiner",
118 "iterative_schur_complement_solver",
119 "jet",
120 "levenberg_marquardt_strategy",
121 "line_search_minimizer",
122 "line_search_preprocessor",
123 "local_parameterization",
124 "loss_function",
125 "minimizer",
126 "normal_prior",
127 "numeric_diff_cost_function",
128 "ordered_groups",
129 "parallel_for",
130 "parallel_utils",
131 "parameter_block_ordering",
132 "parameter_block",
133 "partitioned_matrix_view",
134 "polynomial",
135 "problem",
136 "program",
137 "reorder_program",
138 "residual_block",
139 "residual_block_utils",
140 "rotation",
141 "schur_complement_solver",
142 "schur_eliminator",
143 "single_linkage_clustering",
144 "small_blas",
145 "solver",
146 "sparse_cholesky",
147 "sparse_normal_cholesky_solver",
148 "subset_preconditioner",
149 "system",
150 "thread_pool",
151 "tiny_solver_autodiff_function",
152 "tiny_solver_cost_function_adapter",
153 "tiny_solver",
154 "triplet_sparse_matrix",
155 "trust_region_minimizer",
156 "trust_region_preprocessor",
157 "visibility_based_preconditioner",
158 "visibility",
159]
160
161TEST_COPTS = [
162 # Needed to silence GFlags complaints.
163 "-Wno-sign-compare",
164
165 # These two warnings don't work well in conjunction with GMock, and
166 # trigger incorrectly on parts of rotation_test. For now, disable them,
167 # but in the future disable these warnings only for rotation_test.
168 # TODO(keir): When the tests are macro-ified, apply these selectively.
169 "-Wno-address",
170 "-Wno-unused-parameter",
James Kuszmaul9776b392023-01-14 14:08:08 -0800171] + compiler_select({
172 "gcc": ["-Wno-use-after-free"],
173 "clang": [],
174})
Austin Schuh033df092019-01-21 19:46:48 -0800175
176TEST_DEPS = [
177 "//:ceres",
178 "//:test_util",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700179 "@org_tuxfamily_eigen//:eigen",
Austin Schuh033df092019-01-21 19:46:48 -0800180 "@com_github_gflags_gflags//:gflags",
181]
182
183# Instantiate all the tests with a template.
184[cc_test(
185 name = test_name + "_test",
186 timeout = "short",
187 srcs = ["internal/ceres/" + test_name + "_test.cc"],
188 copts = TEST_COPTS,
189 deps = TEST_DEPS,
190) for test_name in CERES_TESTS]
191
192# Instantiate all the bundle adjustment tests. These are separate to
193# parallelize the execution of the tests; otherwise the tests take a long time.
194#
195# Note: While it is possible to run the Python script to generate the .cc files
196# as part of the build, it introduces an undesirable build-time Python
197# dependency that we'd prefer to avoid.
198[cc_test(
199 name = test_filename.split("/")[-1][:-3], # Remove .cc.
200 timeout = "moderate",
201 srcs = [test_filename],
202 copts = TEST_COPTS,
203
204 # This is the data set that is bundled for the testing.
205 data = [":data/problem-16-22106-pre.txt"],
206 deps = TEST_DEPS,
207) for test_filename in glob([
208 "internal/ceres/generated_bundle_adjustment_tests/*_test.cc",
209])]
210
211# Build the benchmarks.
212[cc_binary(
213 name = benchmark_name,
214 srcs = ["internal/ceres/" + benchmark_name + ".cc"],
215 copts = TEST_COPTS,
216 deps = TEST_DEPS + ["@com_github_google_benchmark//:benchmark"],
217) for benchmark_name in [
Austin Schuh033df092019-01-21 19:46:48 -0800218 "small_blas_gemm_benchmark",
219 "small_blas_gemv_benchmark",
220]]