blob: 05a25bf83350d3e52e59d271750716f6e17ffb69 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001# Ceres Solver - A fast non-linear least squares minimizer
2# Copyright 2015 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: 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
50// Copyright 2017 Google Inc. All rights reserved.
51// 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
94namespace ceres {
95namespace internal {
96
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080097template class PartitionedMatrixView<%s,
98 %s,
99 %s>;
Austin Schuh70cc9552019-01-21 19:46:48 -0800100
101} // namespace internal
102} // namespace ceres
103"""
104
105SPECIALIZATION_FILE = """
106// This include must come before any #ifndef check on Ceres compile options.
107#include "ceres/internal/port.h"
108
109#ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION
110
111#include "ceres/partitioned_matrix_view_impl.h"
Austin Schuh70cc9552019-01-21 19:46:48 -0800112
113namespace ceres {
114namespace internal {
115
116template class PartitionedMatrixView<%s, %s, %s>;
117
118} // namespace internal
119} // namespace ceres
120
121#endif // CERES_RESTRICT_SCHUR_SPECIALIZATION
122"""
123
124FACTORY_FILE_HEADER = """
125#include "ceres/linear_solver.h"
126#include "ceres/partitioned_matrix_view.h"
Austin Schuh70cc9552019-01-21 19:46:48 -0800127
128namespace ceres {
129namespace internal {
130
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800131PartitionedMatrixViewBase* PartitionedMatrixViewBase::Create(
132 const LinearSolver::Options& options, const BlockSparseMatrix& matrix) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800133#ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION
134"""
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800135FACTORY = """ return new PartitionedMatrixView<%s, %s, %s>(matrix,
136 options.elimination_groups[0]);"""
Austin Schuh70cc9552019-01-21 19:46:48 -0800137
138FACTORY_FOOTER = """
139#endif
140 VLOG(1) << "Template specializations not found for <"
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800141 << options.row_block_size << "," << options.e_block_size << ","
Austin Schuh70cc9552019-01-21 19:46:48 -0800142 << options.f_block_size << ">";
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800143 return new PartitionedMatrixView<Eigen::Dynamic,
144 Eigen::Dynamic,
145 Eigen::Dynamic>(
146 matrix, options.elimination_groups[0]);
Austin Schuh70cc9552019-01-21 19:46:48 -0800147};
148
149} // namespace internal
150} // namespace ceres
151"""