blob: 5fa8ef231df5d9f44f65adfd42df96aa69552dc2 [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")
35
36ceres_library(
37 name = "ceres",
38 restrict_schur_specializations = False,
39)
40
41cc_library(
42 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",
49 "gmock/gmock.h",
50 "gmock/mock-log.h",
51 "gtest/gtest.h",
52 ]],
53 hdrs = [
54 "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",
Brian Silverman4c7235a2021-11-17 19:04:37 -080060 "-Wno-unused-but-set-variable",
Austin Schuh033df092019-01-21 19:46:48 -080061 "-DCERES_TEST_SRCDIR_SUFFIX=\\\"data/\\\"",
Austin Schuh033df092019-01-21 19:46:48 -080062 ],
63 includes = [
64 "internal",
65 "internal/ceres",
66 ],
67 deps = [
68 "//:ceres",
69 "@com_github_gflags_gflags//:gflags",
70 ],
71)
72
73CERES_TESTS = [
74 "array_utils",
75 "autodiff_cost_function",
76 "autodiff_local_parameterization",
77 "autodiff",
78 "block_jacobi_preconditioner",
79 "block_random_access_dense_matrix",
80 "block_random_access_diagonal_matrix",
81 "block_random_access_sparse_matrix",
82 "block_sparse_matrix",
83 "canonical_views_clustering",
84 "c_api",
85 "compressed_col_sparse_matrix_utils",
86 "compressed_row_sparse_matrix",
87 "concurrent_queue",
88 "conditioned_cost_function",
89 "conjugate_gradients_solver",
90 "corrector",
91 "cost_function_to_functor",
92 "covariance",
93 "cubic_interpolation",
94 "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",
103 "evaluation_callback",
104 "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",
116 "iterative_refiner",
117 "iterative_schur_complement_solver",
118 "jet",
119 "levenberg_marquardt_strategy",
120 "line_search_minimizer",
121 "line_search_preprocessor",
122 "local_parameterization",
123 "loss_function",
124 "minimizer",
125 "normal_prior",
126 "numeric_diff_cost_function",
127 "ordered_groups",
128 "parallel_for",
129 "parallel_utils",
130 "parameter_block_ordering",
131 "parameter_block",
132 "partitioned_matrix_view",
133 "polynomial",
134 "problem",
135 "program",
136 "reorder_program",
137 "residual_block",
138 "residual_block_utils",
139 "rotation",
140 "schur_complement_solver",
141 "schur_eliminator",
142 "single_linkage_clustering",
143 "small_blas",
144 "solver",
145 "sparse_cholesky",
146 "sparse_normal_cholesky_solver",
147 "subset_preconditioner",
148 "system",
149 "thread_pool",
150 "tiny_solver_autodiff_function",
151 "tiny_solver_cost_function_adapter",
152 "tiny_solver",
153 "triplet_sparse_matrix",
154 "trust_region_minimizer",
155 "trust_region_preprocessor",
156 "visibility_based_preconditioner",
157 "visibility",
158]
159
160TEST_COPTS = [
161 # Needed to silence GFlags complaints.
162 "-Wno-sign-compare",
163
164 # These two warnings don't work well in conjunction with GMock, and
165 # trigger incorrectly on parts of rotation_test. For now, disable them,
166 # but in the future disable these warnings only for rotation_test.
167 # TODO(keir): When the tests are macro-ified, apply these selectively.
168 "-Wno-address",
169 "-Wno-unused-parameter",
Austin Schuhf386bf92020-12-23 22:16:19 -0800170]
Austin Schuh033df092019-01-21 19:46:48 -0800171
172TEST_DEPS = [
173 "//:ceres",
174 "//:test_util",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700175 "@org_tuxfamily_eigen//:eigen",
Austin Schuh033df092019-01-21 19:46:48 -0800176 "@com_github_gflags_gflags//:gflags",
177]
178
179# Instantiate all the tests with a template.
180[cc_test(
181 name = test_name + "_test",
182 timeout = "short",
183 srcs = ["internal/ceres/" + test_name + "_test.cc"],
184 copts = TEST_COPTS,
185 deps = TEST_DEPS,
186) for test_name in CERES_TESTS]
187
188# Instantiate all the bundle adjustment tests. These are separate to
189# parallelize the execution of the tests; otherwise the tests take a long time.
190#
191# Note: While it is possible to run the Python script to generate the .cc files
192# as part of the build, it introduces an undesirable build-time Python
193# dependency that we'd prefer to avoid.
194[cc_test(
195 name = test_filename.split("/")[-1][:-3], # Remove .cc.
196 timeout = "moderate",
197 srcs = [test_filename],
198 copts = TEST_COPTS,
199
200 # This is the data set that is bundled for the testing.
201 data = [":data/problem-16-22106-pre.txt"],
202 deps = TEST_DEPS,
203) for test_filename in glob([
204 "internal/ceres/generated_bundle_adjustment_tests/*_test.cc",
205])]
206
207# Build the benchmarks.
208[cc_binary(
209 name = benchmark_name,
210 srcs = ["internal/ceres/" + benchmark_name + ".cc"],
211 copts = TEST_COPTS,
212 deps = TEST_DEPS + ["@com_github_google_benchmark//:benchmark"],
213) for benchmark_name in [
Austin Schuh033df092019-01-21 19:46:48 -0800214 "small_blas_gemm_benchmark",
215 "small_blas_gemv_benchmark",
216]]