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