blob: 02a19f3f91a5d1a68e7e6b8873f40cf7be645df6 [file] [log] [blame]
Austin Schuh1d1e6ea2020-12-23 21:56:30 -08001// Ceres Solver - A fast non-linear least squares minimizer
2// Copyright 2019 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 materils 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// Authors: sameeragarwal@google.com (Sameer Agarwal)
30
31#include "Eigen/Dense"
32#include "benchmark/benchmark.h"
33#include "ceres/invert_psd_matrix.h"
34
35namespace ceres {
36namespace internal {
37
38template <int kSize>
39void BenchmarkFixedSizedInvertPSDMatrix(benchmark::State& state) {
40 using MatrixType = typename EigenTypes<kSize, kSize>::Matrix;
41 MatrixType input = MatrixType::Random();
42 input += input.transpose() + MatrixType::Identity();
43
44 MatrixType output;
45 constexpr bool kAssumeFullRank = true;
46 for (auto _ : state) {
47 benchmark::DoNotOptimize(
48 output = InvertPSDMatrix<kSize>(kAssumeFullRank, input));
49 }
50}
51
52BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 1);
53BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 2);
54BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 3);
55BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 4);
56BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 5);
57BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 6);
58BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 7);
59BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 8);
60BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 9);
61BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 10);
62BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 11);
63BENCHMARK_TEMPLATE(BenchmarkFixedSizedInvertPSDMatrix, 12);
64
65void BenchmarkDynamicallyInvertPSDMatrix(benchmark::State& state) {
66 using MatrixType =
67 typename EigenTypes<Eigen::Dynamic, Eigen::Dynamic>::Matrix;
68 const int size = state.range(0);
69 MatrixType input = MatrixType::Random(size, size);
70 input += input.transpose() + MatrixType::Identity(size, size);
71
72 MatrixType output;
73 constexpr bool kAssumeFullRank = true;
74 for (auto _ : state) {
75 benchmark::DoNotOptimize(
76 output = InvertPSDMatrix<Eigen::Dynamic>(kAssumeFullRank, input));
77 }
78}
79
80BENCHMARK(BenchmarkDynamicallyInvertPSDMatrix)
81 ->Apply([](benchmark::internal::Benchmark* benchmark) {
82 for (int i = 1; i < 13; ++i) {
83 benchmark->Args({i});
84 }
85 });
86
87} // namespace internal
88} // namespace ceres
89
90BENCHMARK_MAIN();