schur_eliminator_template.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. # Ceres Solver - A fast non-linear least squares minimizer
  2. # Copyright 2023 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. # Set of template specializations to generate
  51. HEADER = """// Ceres Solver - A fast non-linear least squares minimizer
  52. // Copyright 2023 Google Inc. All rights reserved.
  53. // http://ceres-solver.org/
  54. //
  55. // Redistribution and use in source and binary forms, with or without
  56. // modification, are permitted provided that the following conditions are met:
  57. //
  58. // * Redistributions of source code must retain the above copyright notice,
  59. // this list of conditions and the following disclaimer.
  60. // * Redistributions in binary form must reproduce the above copyright notice,
  61. // this list of conditions and the following disclaimer in the documentation
  62. // and/or other materials provided with the distribution.
  63. // * Neither the name of Google Inc. nor the names of its contributors may be
  64. // used to endorse or promote products derived from this software without
  65. // specific prior written permission.
  66. //
  67. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  68. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  69. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  70. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  71. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  72. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  73. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  74. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  75. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  76. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  77. // POSSIBILITY OF SUCH DAMAGE.
  78. //
  79. // Author: sameeragarwal@google.com (Sameer Agarwal)
  80. //
  81. // Template specialization of SchurEliminator.
  82. //
  83. // ========================================
  84. // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
  85. // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
  86. // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
  87. // THIS FILE IS AUTOGENERATED. DO NOT EDIT.
  88. //=========================================
  89. //
  90. // This file is generated using generate_template_specializations.py.
  91. """
  92. DYNAMIC_FILE = """
  93. #include "ceres/schur_eliminator_impl.h"
  94. namespace ceres::internal {
  95. template class SchurEliminator<%s, %s, %s>;
  96. } // namespace ceres::internal
  97. """
  98. SPECIALIZATION_FILE = """
  99. // This include must come before any #ifndef check on Ceres compile options.
  100. #include "ceres/internal/config.h"
  101. #ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION
  102. #include "ceres/schur_eliminator_impl.h"
  103. namespace ceres::internal {
  104. template class SchurEliminator<%s, %s, %s>;
  105. } // namespace ceres::internal
  106. #endif // CERES_RESTRICT_SCHUR_SPECIALIZATION
  107. """
  108. FACTORY_FILE_HEADER = """
  109. #include <memory>
  110. #include "ceres/linear_solver.h"
  111. #include "ceres/schur_eliminator.h"
  112. namespace ceres::internal {
  113. SchurEliminatorBase::~SchurEliminatorBase() = default;
  114. std::unique_ptr<SchurEliminatorBase> SchurEliminatorBase::Create(
  115. const LinearSolver::Options& options) {
  116. #ifndef CERES_RESTRICT_SCHUR_SPECIALIZATION
  117. """
  118. FACTORY = """ return std::make_unique<SchurEliminator<%s, %s, %s>>(options);"""
  119. FACTORY_FOOTER = """
  120. #endif
  121. VLOG(1) << "Template specializations not found for <"
  122. << options.row_block_size << "," << options.e_block_size << ","
  123. << options.f_block_size << ">";
  124. return std::make_unique<SchurEliminator<Eigen::Dynamic,
  125. Eigen::Dynamic,
  126. Eigen::Dynamic>>(options);
  127. }
  128. } // namespace ceres::internal
  129. """