blob: 9af4c0e522dfb4134dcfcbd1d833d75f4f7e0b4a [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001# Ceres Solver - A fast non-linear least squares minimizer
Austin Schuh3de38b02024-06-25 18:25:10 -07002# Copyright 2023 Google Inc. All rights reserved.
Austin Schuh70cc9552019-01-21 19:46:48 -08003# 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: sameeragarwal@google.com (Sameer Agarwal)
30#
31# Script for explicitly generating template specialization of the
32# PartitionedMatrixView class. Explicitly generating these
33# instantiations in separate .cc files breaks the compilation into
34# separate compilation unit rather than one large cc file.
35#
36# This script creates two sets of files.
37#
38# 1. partitioned_matrix_view_x_x_x.cc
39# where the x indicates the template parameters and
40#
41# 2. partitioned_matrix_view.cc
42#
43# that contains a factory function for instantiating these classes
44# based on runtime parameters.
45#
46# The list of tuples, specializations indicates the set of
47# specializations that is generated.
48
49HEADER = """// Ceres Solver - A fast non-linear least squares minimizer
Austin Schuh3de38b02024-06-25 18:25:10 -070050// Copyright 2023 Google Inc. All rights reserved.
Austin Schuh70cc9552019-01-21 19:46:48 -080051// http://ceres-solver.org/
52//
53// Redistribution and use in source and binary forms, with or without
54// modification, are permitted provided that the following conditions are met:
55//
56// * Redistributions of source code must retain the above copyright notice,
57// this list of conditions and the following disclaimer.
58// * Redistributions in binary form must reproduce the above copyright notice,
59// this list of conditions and the following disclaimer in the documentation
60// and/or other materials provided with the distribution.
61// * Neither the name of Google Inc. nor the names of its contributors may be
62// used to endorse or promote products derived from this software without
63// specific prior written permission.
64//
65// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
66// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
67// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
68// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
69// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
70// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
71// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
72// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
73// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
74// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
75// POSSIBILITY OF SUCH DAMAGE.
76//
77// Author: sameeragarwal@google.com (Sameer Agarwal)
78//
79// Template specialization of PartitionedMatrixView.
80//
81// ========================================
82// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
83// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
84// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
85// THIS FILE IS AUTOGENERATED. DO NOT EDIT.
86//=========================================
87//
88// This file is generated using generate_template_specializations.py.
89"""
90
91DYNAMIC_FILE = """
Austin Schuh70cc9552019-01-21 19:46:48 -080092#include "ceres/partitioned_matrix_view_impl.h"
Austin Schuh70cc9552019-01-21 19:46:48 -080093
Austin Schuh3de38b02024-06-25 18:25:10 -070094namespace ceres::internal {
Austin Schuh70cc9552019-01-21 19:46:48 -080095
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080096template class PartitionedMatrixView<%s,
97 %s,
98 %s>;
Austin Schuh70cc9552019-01-21 19:46:48 -080099
Austin Schuh3de38b02024-06-25 18:25:10 -0700100} // namespace ceres::internal
Austin Schuh70cc9552019-01-21 19:46:48 -0800101"""
102
103SPECIALIZATION_FILE = """
104// This include must come before any #ifndef check on Ceres compile options.
Austin Schuh3de38b02024-06-25 18:25:10 -0700105#include "ceres/internal/config.h"
Austin Schuh70cc9552019-01-21 19:46:48 -0800106
107#ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION
108
109#include "ceres/partitioned_matrix_view_impl.h"
Austin Schuh70cc9552019-01-21 19:46:48 -0800110
Austin Schuh3de38b02024-06-25 18:25:10 -0700111namespace ceres::internal {
Austin Schuh70cc9552019-01-21 19:46:48 -0800112
113template class PartitionedMatrixView<%s, %s, %s>;
114
Austin Schuh3de38b02024-06-25 18:25:10 -0700115} // namespace ceres::internal
Austin Schuh70cc9552019-01-21 19:46:48 -0800116
117#endif // CERES_RESTRICT_SCHUR_SPECIALIZATION
118"""
119
120FACTORY_FILE_HEADER = """
Austin Schuh3de38b02024-06-25 18:25:10 -0700121#include <memory>
122
Austin Schuh70cc9552019-01-21 19:46:48 -0800123#include "ceres/linear_solver.h"
124#include "ceres/partitioned_matrix_view.h"
Austin Schuh70cc9552019-01-21 19:46:48 -0800125
Austin Schuh3de38b02024-06-25 18:25:10 -0700126namespace ceres::internal {
Austin Schuh70cc9552019-01-21 19:46:48 -0800127
Austin Schuh3de38b02024-06-25 18:25:10 -0700128PartitionedMatrixViewBase::~PartitionedMatrixViewBase() = default;
129
130std::unique_ptr<PartitionedMatrixViewBase> PartitionedMatrixViewBase::Create(
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800131 const LinearSolver::Options& options, const BlockSparseMatrix& matrix) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800132#ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION
133"""
Austin Schuh3de38b02024-06-25 18:25:10 -0700134FACTORY = """ return std::make_unique<PartitionedMatrixView<%s,%s, %s>>(
135 options, matrix);"""
Austin Schuh70cc9552019-01-21 19:46:48 -0800136
137FACTORY_FOOTER = """
138#endif
139 VLOG(1) << "Template specializations not found for <"
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800140 << options.row_block_size << "," << options.e_block_size << ","
Austin Schuh70cc9552019-01-21 19:46:48 -0800141 << options.f_block_size << ">";
Austin Schuh3de38b02024-06-25 18:25:10 -0700142 return std::make_unique<PartitionedMatrixView<Eigen::Dynamic,
143 Eigen::Dynamic,
144 Eigen::Dynamic>>(
145 options, matrix);
Austin Schuh70cc9552019-01-21 19:46:48 -0800146};
147
Austin Schuh3de38b02024-06-25 18:25:10 -0700148} // namespace ceres::internal
Austin Schuh70cc9552019-01-21 19:46:48 -0800149"""