partitioned_matrix_view_template.py 5.9 KB

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