Imported Upstream version ceres 1.13.0
[platform/upstream/ceres-solver.git] / internal / ceres / schur_eliminator_template.py
1 # Ceres Solver - A fast non-linear least squares minimizer
2 # Copyright 2017 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 # SchurEliminator class. It is a rather large class
33 # and the number of explicit instantiations is also large. Explicitly
34 # generating these instantiations in separate .cc files breaks the
35 # compilation into separate compilation unit rather than one large cc
36 # file which takes 2+GB of RAM to compile.
37 #
38 # This script creates two sets of files.
39 #
40 # 1. schur_eliminator_x_x_x.cc
41 # where, the x indicates the template parameters and
42 #
43 # 2. schur_eliminator.cc
44 #
45 # that contains a factory function for instantiating these classes
46 # based on runtime parameters.
47 #
48 # The list of tuples, specializations indicates the set of
49 # specializations that is generated.
50
51 # Set of template specializations to generate
52
53 HEADER = """// Ceres Solver - A fast non-linear least squares minimizer
54 // Copyright 2017 Google Inc. All rights reserved.
55 // http://ceres-solver.org/
56 //
57 // Redistribution and use in source and binary forms, with or without
58 // modification, are permitted provided that the following conditions are met:
59 //
60 // * Redistributions of source code must retain the above copyright notice,
61 //   this list of conditions and the following disclaimer.
62 // * Redistributions in binary form must reproduce the above copyright notice,
63 //   this list of conditions and the following disclaimer in the documentation
64 //   and/or other materials provided with the distribution.
65 // * Neither the name of Google Inc. nor the names of its contributors may be
66 //   used to endorse or promote products derived from this software without
67 //   specific prior written permission.
68 //
69 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
70 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
71 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
72 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
73 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
74 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
75 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
76 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
77 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
78 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
79 // POSSIBILITY OF SUCH DAMAGE.
80 //
81 // Author: sameeragarwal@google.com (Sameer Agarwal)
82 //
83 // Template specialization of SchurEliminator.
84 //
85 // ========================================
86 // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
87 // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
88 // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
89 // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
90 //=========================================
91 //
92 // This file is generated using generate_template_specializations.py.
93 """
94
95 DYNAMIC_FILE = """
96
97 #include "ceres/schur_eliminator_impl.h"
98 #include "ceres/internal/eigen.h"
99
100 namespace ceres {
101 namespace internal {
102
103 template class SchurEliminator<%s, %s, %s>;
104
105 }  // namespace internal
106 }  // namespace ceres
107 """
108
109 SPECIALIZATION_FILE = """
110 // This include must come before any #ifndef check on Ceres compile options.
111 #include "ceres/internal/port.h"
112
113 #ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION
114
115 #include "ceres/schur_eliminator_impl.h"
116 #include "ceres/internal/eigen.h"
117
118 namespace ceres {
119 namespace internal {
120
121 template class SchurEliminator<%s, %s, %s>;
122
123 }  // namespace internal
124 }  // namespace ceres
125
126 #endif  // CERES_RESTRICT_SCHUR_SPECIALIZATION
127 """
128
129 FACTORY_FILE_HEADER = """
130 #include "ceres/linear_solver.h"
131 #include "ceres/schur_eliminator.h"
132 #include "ceres/internal/eigen.h"
133
134 namespace ceres {
135 namespace internal {
136
137 SchurEliminatorBase*
138 SchurEliminatorBase::Create(const LinearSolver::Options& options) {
139 #ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION
140 """
141
142 FACTORY = """ return new SchurEliminator<%s, %s, %s>(options);"""
143
144 FACTORY_FOOTER = """
145 #endif
146   VLOG(1) << "Template specializations not found for <"
147           << options.row_block_size << ","
148           << options.e_block_size << ","
149           << options.f_block_size << ">";
150   return new SchurEliminator<Eigen::Dynamic, Eigen::Dynamic, Eigen::Dynamic>(options);
151 }
152
153 }  // namespace internal
154 }  // namespace ceres
155 """