Keir Mierle | 07f1405 | 2017-11-07 01:13:29 -0800 | [diff] [blame] | 1 | # Ceres Solver - A fast non-linear least squares minimizer |
Sameer Agarwal | 5a30cae | 2023-09-19 15:29:34 -0700 | [diff] [blame] | 2 | # Copyright 2023 Google Inc. All rights reserved. |
Keir Mierle | 07f1405 | 2017-11-07 01:13:29 -0800 | [diff] [blame] | 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 | |
Rodrigo Queiro | c1075cd | 2018-01-15 14:07:47 +0100 | [diff] [blame] | 34 | load("//:bazel/ceres.bzl", "ceres_library") |
Keir Mierle | 07f1405 | 2017-11-07 01:13:29 -0800 | [diff] [blame] | 35 | |
Keir Mierle | 8549c88 | 2018-02-08 19:06:49 -0800 | [diff] [blame] | 36 | ceres_library( |
| 37 | name = "ceres", |
| 38 | restrict_schur_specializations = False, |
| 39 | ) |
Keir Mierle | 07f1405 | 2017-11-07 01:13:29 -0800 | [diff] [blame] | 40 | |
| 41 | cc_library( |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 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", |
Keir Mierle | 8549c88 | 2018-02-08 19:06:49 -0800 | [diff] [blame] | 49 | "gmock/gmock.h", |
| 50 | "gmock/mock-log.h", |
| 51 | "gtest/gtest.h", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 52 | ]], |
Keir Mierle | 07f1405 | 2017-11-07 01:13:29 -0800 | [diff] [blame] | 53 | hdrs = [ |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 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", |
| 60 | "-DCERES_TEST_SRCDIR_SUFFIX=\\\"data/\\\"", |
| 61 | ], |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 62 | includes = [ |
| 63 | "internal", |
| 64 | "internal/ceres", |
| 65 | ], |
Keir Mierle | 07f1405 | 2017-11-07 01:13:29 -0800 | [diff] [blame] | 66 | deps = [ |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 67 | "//:ceres", |
| 68 | "@com_github_gflags_gflags//:gflags", |
| 69 | ], |
Keir Mierle | 07f1405 | 2017-11-07 01:13:29 -0800 | [diff] [blame] | 70 | ) |
| 71 | |
| 72 | CERES_TESTS = [ |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 73 | "array_utils", |
| 74 | "autodiff_cost_function", |
Sameer Agarwal | e6e6ae0 | 2022-01-24 13:16:00 -0800 | [diff] [blame] | 75 | "autodiff_manifold", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 76 | "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 Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 82 | "canonical_views_clustering", |
| 83 | "c_api", |
| 84 | "compressed_col_sparse_matrix_utils", |
| 85 | "compressed_row_sparse_matrix", |
Mike Vitus | 27789c0 | 2018-01-26 13:51:26 -0800 | [diff] [blame] | 86 | "concurrent_queue", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 87 | "conditioned_cost_function", |
| 88 | "conjugate_gradients_solver", |
| 89 | "corrector", |
| 90 | "cost_function_to_functor", |
| 91 | "covariance", |
| 92 | "cubic_interpolation", |
Sameer Agarwal | e6e6ae0 | 2022-01-24 13:16:00 -0800 | [diff] [blame] | 93 | "dense_cholesky", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 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", |
Keir Mierle | 7bdceb4 | 2018-01-10 17:14:57 -0800 | [diff] [blame] | 103 | "evaluation_callback", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 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", |
Sameer Agarwal | 86814ab | 2018-04-05 11:48:26 -0700 | [diff] [blame] | 116 | "iterative_refiner", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 117 | "iterative_schur_complement_solver", |
| 118 | "jet", |
| 119 | "levenberg_marquardt_strategy", |
| 120 | "line_search_minimizer", |
| 121 | "line_search_preprocessor", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 122 | "loss_function", |
| 123 | "minimizer", |
| 124 | "normal_prior", |
| 125 | "numeric_diff_cost_function", |
| 126 | "ordered_groups", |
Mike Vitus | 126e0ef | 2018-02-22 11:06:24 -0800 | [diff] [blame] | 127 | "parallel_for", |
William Rucklidge | 21f519d | 2018-03-02 12:37:54 -0800 | [diff] [blame] | 128 | "parallel_utils", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 129 | "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 Agarwal | 9d02b76 | 2018-02-19 17:47:00 -0800 | [diff] [blame] | 146 | "subset_preconditioner", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 147 | "system", |
Mike Vitus | 27789c0 | 2018-01-26 13:51:26 -0800 | [diff] [blame] | 148 | "thread_pool", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 149 | "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 Mierle | 07f1405 | 2017-11-07 01:13:29 -0800 | [diff] [blame] | 158 | |
Keir Mierle | 8549c88 | 2018-02-08 19:06:49 -0800 | [diff] [blame] | 159 | TEST_COPTS = [ |
Keir Mierle | a3b1e19 | 2018-02-21 11:13:57 -0800 | [diff] [blame] | 160 | # Needed to silence GFlags complaints. |
Keir Mierle | 8549c88 | 2018-02-08 19:06:49 -0800 | [diff] [blame] | 161 | "-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 Mierle | 8549c88 | 2018-02-08 19:06:49 -0800 | [diff] [blame] | 167 | "-Wno-address", |
| 168 | ] |
| 169 | |
| 170 | TEST_DEPS = [ |
| 171 | "//:ceres", |
| 172 | "//:test_util", |
Sameer Agarwal | bf47e1a | 2020-10-13 10:00:22 -0700 | [diff] [blame] | 173 | "@com_gitlab_libeigen_eigen//:eigen", |
Keir Mierle | 8549c88 | 2018-02-08 19:06:49 -0800 | [diff] [blame] | 174 | "@com_github_gflags_gflags//:gflags", |
| 175 | ] |
| 176 | |
Keir Mierle | 07f1405 | 2017-11-07 01:13:29 -0800 | [diff] [blame] | 177 | # Instantiate all the tests with a template. |
Keir Mierle | 07f1405 | 2017-11-07 01:13:29 -0800 | [diff] [blame] | 178 | [cc_test( |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 179 | name = test_name + "_test", |
Keir Mierle | 8549c88 | 2018-02-08 19:06:49 -0800 | [diff] [blame] | 180 | timeout = "short", |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 181 | srcs = ["internal/ceres/" + test_name + "_test.cc"], |
Keir Mierle | 8549c88 | 2018-02-08 19:06:49 -0800 | [diff] [blame] | 182 | copts = TEST_COPTS, |
| 183 | deps = TEST_DEPS, |
Rodrigo Queiro | ac22a97 | 2018-01-15 12:55:57 +0100 | [diff] [blame] | 184 | ) for test_name in CERES_TESTS] |
Keir Mierle | 8549c88 | 2018-02-08 19:06:49 -0800 | [diff] [blame] | 185 | |
| 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 Ivanov | e1ca330 | 2023-01-11 13:53:20 +0000 | [diff] [blame] | 194 | timeout = "long", |
Keir Mierle | 8549c88 | 2018-02-08 19:06:49 -0800 | [diff] [blame] | 195 | 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 Mierle | 22fa21c | 2018-02-25 15:18:08 -0800 | [diff] [blame] | 204 | |
| 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 Mierle | 22fa21c | 2018-02-25 15:18:08 -0800 | [diff] [blame] | 212 | "small_blas_gemm_benchmark", |
| 213 | "small_blas_gemv_benchmark", |
| 214 | ]] |