xcoll 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of xcoll might be problematic. Click here for more details.

Files changed (324) hide show
  1. xcoll/__init__.py +2 -1
  2. xcoll/beam_elements/__init__.py +7 -1
  3. xcoll/beam_elements/absorber.py +2 -2
  4. xcoll/beam_elements/base.py +105 -67
  5. xcoll/beam_elements/blowup.py +198 -0
  6. xcoll/beam_elements/{collimators_src → elements_src}/black_absorber.h +21 -3
  7. xcoll/beam_elements/{collimators_src → elements_src}/black_crystal.h +20 -2
  8. xcoll/beam_elements/elements_src/blowup.h +42 -0
  9. xcoll/beam_elements/elements_src/emittance_monitor.h +109 -0
  10. xcoll/beam_elements/{collimators_src → elements_src}/everest_block.h +19 -2
  11. xcoll/beam_elements/{collimators_src → elements_src}/everest_collimator.h +19 -3
  12. xcoll/beam_elements/{collimators_src → elements_src}/everest_crystal.h +30 -9
  13. xcoll/beam_elements/everest.py +5 -6
  14. xcoll/beam_elements/monitor.py +428 -0
  15. xcoll/colldb.py +103 -74
  16. xcoll/general.py +4 -4
  17. xcoll/initial_distribution.py +18 -6
  18. xcoll/install.py +3 -1
  19. xcoll/interaction_record/interaction_record.py +126 -80
  20. xcoll/interaction_record/interaction_record_src/interaction_record.h +43 -43
  21. xcoll/line_tools.py +8 -9
  22. xcoll/lossmap.py +48 -38
  23. xcoll/scattering_routines/everest/amorphous.h +4 -11
  24. xcoll/scattering_routines/everest/channeling.h +3 -8
  25. xcoll/scattering_routines/everest/everest.h +4 -1
  26. xcoll/scattering_routines/everest/jaw.h +4 -3
  27. xcoll/scattering_routines/everest/materials.py +35 -15
  28. xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
  29. xcoll/scattering_routines/everest/nuclear_interaction.h +1 -1
  30. xcoll/scattering_routines/everest/properties.h +6 -1
  31. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
  32. xcoll/scattering_routines/geant4/collimasim/.git +1 -0
  33. xcoll/scattering_routines/geant4/collimasim/.gitignore +12 -0
  34. xcoll/scattering_routines/geant4/collimasim/.gitmodules +3 -0
  35. xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +26 -0
  36. xcoll/scattering_routines/geant4/collimasim/README.md +21 -0
  37. xcoll/scattering_routines/geant4/collimasim/docs/Makefile +20 -0
  38. xcoll/scattering_routines/geant4/collimasim/docs/make.bat +35 -0
  39. xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +10 -0
  40. xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +59 -0
  41. xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +26 -0
  42. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +37 -0
  43. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +19 -0
  44. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +65 -0
  45. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +73 -0
  46. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +1 -0
  47. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +9 -0
  48. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +386 -0
  49. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +45 -0
  50. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +8 -0
  51. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +16 -0
  52. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +8 -0
  53. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +3 -0
  54. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +19 -0
  55. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +969 -0
  56. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +84 -0
  57. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +48 -0
  58. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +16 -0
  59. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +103 -0
  60. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +45 -0
  61. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +151 -0
  62. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +3 -0
  63. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +297 -0
  64. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +29 -0
  65. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +6 -0
  66. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +180 -0
  67. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +23 -0
  68. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +192 -0
  69. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +11 -0
  70. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +81 -0
  71. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +93 -0
  72. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +310 -0
  73. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +109 -0
  74. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +43 -0
  75. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +171 -0
  76. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +251 -0
  77. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +305 -0
  78. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +1297 -0
  79. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +262 -0
  80. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +396 -0
  81. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +568 -0
  82. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +337 -0
  83. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +13 -0
  84. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +463 -0
  85. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +286 -0
  86. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +155 -0
  87. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +174 -0
  88. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +308 -0
  89. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +91 -0
  90. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +95 -0
  91. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +2050 -0
  92. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +542 -0
  93. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +8 -0
  94. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +648 -0
  95. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +381 -0
  96. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +343 -0
  97. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +48 -0
  98. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +105 -0
  99. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +72 -0
  100. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
  101. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
  102. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +427 -0
  103. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
  104. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +427 -0
  105. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +130 -0
  106. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +96 -0
  107. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +8 -0
  108. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +548 -0
  109. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +605 -0
  110. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +144 -0
  111. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +1432 -0
  112. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +213 -0
  113. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +2 -0
  114. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +65 -0
  115. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +709 -0
  116. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +1021 -0
  117. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +104 -0
  118. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +346 -0
  119. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +467 -0
  120. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +978 -0
  121. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +55 -0
  122. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +606 -0
  123. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +284 -0
  124. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +163 -0
  125. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +121 -0
  126. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +193 -0
  127. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +275 -0
  128. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +1741 -0
  129. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +163 -0
  130. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +65 -0
  131. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +2497 -0
  132. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +1879 -0
  133. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +103 -0
  134. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +375 -0
  135. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +747 -0
  136. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +88 -0
  137. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +11 -0
  138. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +52 -0
  139. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +12 -0
  140. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +6 -0
  141. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +21 -0
  142. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
  143. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +482 -0
  144. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +63 -0
  145. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +41 -0
  146. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +56 -0
  147. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +155 -0
  148. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +503 -0
  149. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +208 -0
  150. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +275 -0
  151. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +73 -0
  152. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +33 -0
  153. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
  154. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +279 -0
  155. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
  156. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +143 -0
  157. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +85 -0
  158. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +179 -0
  159. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +151 -0
  160. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +91 -0
  161. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +85 -0
  162. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +19 -0
  163. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +12 -0
  164. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +26 -0
  165. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +25 -0
  166. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +216 -0
  167. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +163 -0
  168. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +286 -0
  169. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +536 -0
  170. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +107 -0
  171. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +248 -0
  172. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +227 -0
  173. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +202 -0
  174. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +84 -0
  175. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +210 -0
  176. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +550 -0
  177. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +473 -0
  178. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +84 -0
  179. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +21 -0
  180. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +28 -0
  181. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +39 -0
  182. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +46 -0
  183. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +6 -0
  184. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +41 -0
  185. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +35 -0
  186. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +41 -0
  187. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +10 -0
  188. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +165 -0
  189. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +53 -0
  190. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +238 -0
  191. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +126 -0
  192. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +141 -0
  193. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +117 -0
  194. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +41 -0
  195. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +50 -0
  196. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +69 -0
  197. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +42 -0
  198. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +348 -0
  199. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +771 -0
  200. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +47 -0
  201. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +22 -0
  202. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +23 -0
  203. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +326 -0
  204. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +15 -0
  205. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +148 -0
  206. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +272 -0
  207. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +119 -0
  208. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +51 -0
  209. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +5 -0
  210. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +285 -0
  211. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +12 -0
  212. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +265 -0
  213. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +397 -0
  214. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +520 -0
  215. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +49 -0
  216. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +94 -0
  217. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +125 -0
  218. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +331 -0
  219. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +153 -0
  220. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +284 -0
  221. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +107 -0
  222. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +257 -0
  223. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +412 -0
  224. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +517 -0
  225. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +102 -0
  226. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +92 -0
  227. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +233 -0
  228. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +360 -0
  229. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +472 -0
  230. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +593 -0
  231. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +524 -0
  232. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +441 -0
  233. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +103 -0
  234. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +267 -0
  235. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +73 -0
  236. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +59 -0
  237. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +235 -0
  238. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +146 -0
  239. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +189 -0
  240. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +82 -0
  241. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +560 -0
  242. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +651 -0
  243. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +500 -0
  244. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +253 -0
  245. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +452 -0
  246. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +318 -0
  247. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +342 -0
  248. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +291 -0
  249. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +131 -0
  250. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +318 -0
  251. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +144 -0
  252. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +29 -0
  253. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +66 -0
  254. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +44 -0
  255. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +22 -0
  256. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +9 -0
  257. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +510 -0
  258. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +408 -0
  259. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +140 -0
  260. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +117 -0
  261. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +70 -0
  262. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +86 -0
  263. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +257 -0
  264. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +44 -0
  265. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +23 -0
  266. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +39 -0
  267. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +64 -0
  268. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +402 -0
  269. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +233 -0
  270. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +276 -0
  271. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +214 -0
  272. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +3 -0
  273. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +65 -0
  274. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +41 -0
  275. xcoll/scattering_routines/geant4/collimasim/pyproject.toml +8 -0
  276. xcoll/scattering_routines/geant4/collimasim/setup.py +144 -0
  277. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +403 -0
  278. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +100 -0
  279. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +763 -0
  280. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +118 -0
  281. xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +8 -0
  282. xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +63 -0
  283. xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +142 -0
  284. xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +556 -0
  285. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +6 -0
  286. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +24 -0
  287. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +1 -0
  288. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +1 -0
  289. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +1 -0
  290. xcoll/scattering_routines/geant4/collimasim/tests/README.md +25 -0
  291. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +25 -0
  292. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +18 -0
  293. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +68 -0
  294. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +15 -0
  295. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +110 -0
  296. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +7 -0
  297. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +3 -0
  298. xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +54 -0
  299. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +3 -0
  300. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +3 -0
  301. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +5 -0
  302. xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +51 -0
  303. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +65 -0
  304. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +59 -0
  305. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +102 -0
  306. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +75 -0
  307. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +74 -0
  308. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +84 -0
  309. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +159 -0
  310. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +99 -0
  311. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +78 -0
  312. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +88 -0
  313. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +80 -0
  314. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +97 -0
  315. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +96 -0
  316. xcoll/scattering_routines/geometry/collimator_geometry.h +9 -10
  317. xcoll/scattering_routines/geometry/crystal_geometry.h +9 -6
  318. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/METADATA +1 -1
  319. xcoll-0.5.0.dist-info/RECORD +413 -0
  320. xcoll/scattering_routines/fluka/build_fluka_input.py +0 -58
  321. xcoll-0.4.0.dist-info/RECORD +0 -126
  322. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/LICENSE +0 -0
  323. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/NOTICE +0 -0
  324. {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,510 @@
1
+ /*
2
+ tests/test_virtual_functions.cpp -- overriding virtual functions from Python
3
+
4
+ Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5
+
6
+ All rights reserved. Use of this source code is governed by a
7
+ BSD-style license that can be found in the LICENSE file.
8
+ */
9
+
10
+ #include "pybind11_tests.h"
11
+ #include "constructor_stats.h"
12
+ #include <pybind11/functional.h>
13
+ #include <thread>
14
+
15
+ /* This is an example class that we'll want to be able to extend from Python */
16
+ class ExampleVirt {
17
+ public:
18
+ explicit ExampleVirt(int state) : state(state) { print_created(this, state); }
19
+ ExampleVirt(const ExampleVirt &e) : state(e.state) { print_copy_created(this); }
20
+ ExampleVirt(ExampleVirt &&e) noexcept : state(e.state) {
21
+ print_move_created(this);
22
+ e.state = 0;
23
+ }
24
+ virtual ~ExampleVirt() { print_destroyed(this); }
25
+
26
+ virtual int run(int value) {
27
+ py::print("Original implementation of "
28
+ "ExampleVirt::run(state={}, value={}, str1={}, str2={})"_s.format(state, value, get_string1(), *get_string2()));
29
+ return state + value;
30
+ }
31
+
32
+ virtual bool run_bool() = 0;
33
+ virtual void pure_virtual() = 0;
34
+
35
+ // Returning a reference/pointer to a type converted from python (numbers, strings, etc.) is a
36
+ // bit trickier, because the actual int& or std::string& or whatever only exists temporarily, so
37
+ // we have to handle it specially in the trampoline class (see below).
38
+ virtual const std::string &get_string1() { return str1; }
39
+ virtual const std::string *get_string2() { return &str2; }
40
+
41
+ private:
42
+ int state;
43
+ const std::string str1{"default1"}, str2{"default2"};
44
+ };
45
+
46
+ /* This is a wrapper class that must be generated */
47
+ class PyExampleVirt : public ExampleVirt {
48
+ public:
49
+ using ExampleVirt::ExampleVirt; /* Inherit constructors */
50
+
51
+ int run(int value) override {
52
+ /* Generate wrapping code that enables native function overloading */
53
+ PYBIND11_OVERRIDE(
54
+ int, /* Return type */
55
+ ExampleVirt, /* Parent class */
56
+ run, /* Name of function */
57
+ value /* Argument(s) */
58
+ );
59
+ }
60
+
61
+ bool run_bool() override {
62
+ PYBIND11_OVERRIDE_PURE(
63
+ bool, /* Return type */
64
+ ExampleVirt, /* Parent class */
65
+ run_bool, /* Name of function */
66
+ /* This function has no arguments. The trailing comma
67
+ in the previous line is needed for some compilers */
68
+ );
69
+ }
70
+
71
+ void pure_virtual() override {
72
+ PYBIND11_OVERRIDE_PURE(
73
+ void, /* Return type */
74
+ ExampleVirt, /* Parent class */
75
+ pure_virtual, /* Name of function */
76
+ /* This function has no arguments. The trailing comma
77
+ in the previous line is needed for some compilers */
78
+ );
79
+ }
80
+
81
+ // We can return reference types for compatibility with C++ virtual interfaces that do so, but
82
+ // note they have some significant limitations (see the documentation).
83
+ const std::string &get_string1() override {
84
+ PYBIND11_OVERRIDE(
85
+ const std::string &, /* Return type */
86
+ ExampleVirt, /* Parent class */
87
+ get_string1, /* Name of function */
88
+ /* (no arguments) */
89
+ );
90
+ }
91
+
92
+ const std::string *get_string2() override {
93
+ PYBIND11_OVERRIDE(
94
+ const std::string *, /* Return type */
95
+ ExampleVirt, /* Parent class */
96
+ get_string2, /* Name of function */
97
+ /* (no arguments) */
98
+ );
99
+ }
100
+
101
+ };
102
+
103
+ class NonCopyable {
104
+ public:
105
+ NonCopyable(int a, int b) : value{new int(a*b)} { print_created(this, a, b); }
106
+ NonCopyable(NonCopyable &&o) noexcept {
107
+ value = std::move(o.value);
108
+ print_move_created(this);
109
+ }
110
+ NonCopyable(const NonCopyable &) = delete;
111
+ NonCopyable() = delete;
112
+ void operator=(const NonCopyable &) = delete;
113
+ void operator=(NonCopyable &&) = delete;
114
+ std::string get_value() const {
115
+ if (value)
116
+ return std::to_string(*value);
117
+ return "(null)";
118
+ }
119
+ ~NonCopyable() { print_destroyed(this); }
120
+
121
+ private:
122
+ std::unique_ptr<int> value;
123
+ };
124
+
125
+ // This is like the above, but is both copy and movable. In effect this means it should get moved
126
+ // when it is not referenced elsewhere, but copied if it is still referenced.
127
+ class Movable {
128
+ public:
129
+ Movable(int a, int b) : value{a+b} { print_created(this, a, b); }
130
+ Movable(const Movable &m) { value = m.value; print_copy_created(this); }
131
+ Movable(Movable &&m) noexcept {
132
+ value = m.value;
133
+ print_move_created(this);
134
+ }
135
+ std::string get_value() const { return std::to_string(value); }
136
+ ~Movable() { print_destroyed(this); }
137
+ private:
138
+ int value;
139
+ };
140
+
141
+ class NCVirt {
142
+ public:
143
+ virtual ~NCVirt() = default;
144
+ NCVirt() = default;
145
+ NCVirt(const NCVirt&) = delete;
146
+ virtual NonCopyable get_noncopyable(int a, int b) { return NonCopyable(a, b); }
147
+ virtual Movable get_movable(int a, int b) = 0;
148
+
149
+ std::string print_nc(int a, int b) { return get_noncopyable(a, b).get_value(); }
150
+ std::string print_movable(int a, int b) { return get_movable(a, b).get_value(); }
151
+ };
152
+ class NCVirtTrampoline : public NCVirt {
153
+ #if !defined(__INTEL_COMPILER) && !defined(__CUDACC__) && !defined(__PGIC__)
154
+ NonCopyable get_noncopyable(int a, int b) override {
155
+ PYBIND11_OVERRIDE(NonCopyable, NCVirt, get_noncopyable, a, b);
156
+ }
157
+ #endif
158
+ Movable get_movable(int a, int b) override {
159
+ PYBIND11_OVERRIDE_PURE(Movable, NCVirt, get_movable, a, b);
160
+ }
161
+ };
162
+
163
+ struct Base {
164
+ /* for some reason MSVC2015 can't compile this if the function is pure virtual */
165
+ virtual std::string dispatch() const { return {}; };
166
+ virtual ~Base() = default;
167
+ Base() = default;
168
+ Base(const Base&) = delete;
169
+ };
170
+
171
+ struct DispatchIssue : Base {
172
+ std::string dispatch() const override {
173
+ PYBIND11_OVERRIDE_PURE(std::string, Base, dispatch, /* no arguments */);
174
+ }
175
+ };
176
+
177
+ static void test_gil() {
178
+ {
179
+ py::gil_scoped_acquire lock;
180
+ py::print("1st lock acquired");
181
+
182
+ }
183
+
184
+ {
185
+ py::gil_scoped_acquire lock;
186
+ py::print("2nd lock acquired");
187
+ }
188
+
189
+ }
190
+
191
+ static void test_gil_from_thread() {
192
+ py::gil_scoped_release release;
193
+
194
+ std::thread t(test_gil);
195
+ t.join();
196
+ }
197
+
198
+
199
+ // Forward declaration (so that we can put the main tests here; the inherited virtual approaches are
200
+ // rather long).
201
+ void initialize_inherited_virtuals(py::module_ &m);
202
+
203
+ TEST_SUBMODULE(virtual_functions, m) {
204
+ // test_override
205
+ py::class_<ExampleVirt, PyExampleVirt>(m, "ExampleVirt")
206
+ .def(py::init<int>())
207
+ /* Reference original class in function definitions */
208
+ .def("run", &ExampleVirt::run)
209
+ .def("run_bool", &ExampleVirt::run_bool)
210
+ .def("pure_virtual", &ExampleVirt::pure_virtual);
211
+
212
+ py::class_<NonCopyable>(m, "NonCopyable")
213
+ .def(py::init<int, int>());
214
+
215
+ py::class_<Movable>(m, "Movable")
216
+ .def(py::init<int, int>());
217
+
218
+ // test_move_support
219
+ #if !defined(__INTEL_COMPILER) && !defined(__CUDACC__) && !defined(__PGIC__)
220
+ py::class_<NCVirt, NCVirtTrampoline>(m, "NCVirt")
221
+ .def(py::init<>())
222
+ .def("get_noncopyable", &NCVirt::get_noncopyable)
223
+ .def("get_movable", &NCVirt::get_movable)
224
+ .def("print_nc", &NCVirt::print_nc)
225
+ .def("print_movable", &NCVirt::print_movable);
226
+ #endif
227
+
228
+ m.def("runExampleVirt", [](ExampleVirt *ex, int value) { return ex->run(value); });
229
+ m.def("runExampleVirtBool", [](ExampleVirt* ex) { return ex->run_bool(); });
230
+ m.def("runExampleVirtVirtual", [](ExampleVirt *ex) { ex->pure_virtual(); });
231
+
232
+ m.def("cstats_debug", &ConstructorStats::get<ExampleVirt>);
233
+ initialize_inherited_virtuals(m);
234
+
235
+ // test_alias_delay_initialization1
236
+ // don't invoke Python dispatch classes by default when instantiating C++ classes
237
+ // that were not extended on the Python side
238
+ struct A {
239
+ A() = default;
240
+ A(const A&) = delete;
241
+ virtual ~A() = default;
242
+ virtual void f() { py::print("A.f()"); }
243
+ };
244
+
245
+ struct PyA : A {
246
+ PyA() { py::print("PyA.PyA()"); }
247
+ PyA(const PyA&) = delete;
248
+ ~PyA() override { py::print("PyA.~PyA()"); }
249
+
250
+ void f() override {
251
+ py::print("PyA.f()");
252
+ // This convolution just gives a `void`, but tests that PYBIND11_TYPE() works to protect
253
+ // a type containing a ,
254
+ PYBIND11_OVERRIDE(PYBIND11_TYPE(typename std::enable_if<true, void>::type), A, f);
255
+ }
256
+ };
257
+
258
+ py::class_<A, PyA>(m, "A")
259
+ .def(py::init<>())
260
+ .def("f", &A::f);
261
+
262
+ m.def("call_f", [](A *a) { a->f(); });
263
+
264
+ // test_alias_delay_initialization2
265
+ // ... unless we explicitly request it, as in this example:
266
+ struct A2 {
267
+ A2() = default;
268
+ A2(const A2&) = delete;
269
+ virtual ~A2() = default;
270
+ virtual void f() { py::print("A2.f()"); }
271
+ };
272
+
273
+ struct PyA2 : A2 {
274
+ PyA2() { py::print("PyA2.PyA2()"); }
275
+ PyA2(const PyA2&) = delete;
276
+ ~PyA2() override { py::print("PyA2.~PyA2()"); }
277
+ void f() override {
278
+ py::print("PyA2.f()");
279
+ PYBIND11_OVERRIDE(void, A2, f);
280
+ }
281
+ };
282
+
283
+ py::class_<A2, PyA2>(m, "A2")
284
+ .def(py::init_alias<>())
285
+ .def(py::init([](int) { return new PyA2(); }))
286
+ .def("f", &A2::f);
287
+
288
+ m.def("call_f", [](A2 *a2) { a2->f(); });
289
+
290
+ // test_dispatch_issue
291
+ // #159: virtual function dispatch has problems with similar-named functions
292
+ py::class_<Base, DispatchIssue>(m, "DispatchIssue")
293
+ .def(py::init<>())
294
+ .def("dispatch", &Base::dispatch);
295
+
296
+ m.def("dispatch_issue_go", [](const Base * b) { return b->dispatch(); });
297
+
298
+ // test_override_ref
299
+ // #392/397: overriding reference-returning functions
300
+ class OverrideTest {
301
+ public:
302
+ struct A { std::string value = "hi"; };
303
+ std::string v;
304
+ A a;
305
+ explicit OverrideTest(const std::string &v) : v{v} {}
306
+ OverrideTest() = default;
307
+ OverrideTest(const OverrideTest&) = delete;
308
+ virtual std::string str_value() { return v; }
309
+ virtual std::string &str_ref() { return v; }
310
+ virtual A A_value() { return a; }
311
+ virtual A &A_ref() { return a; }
312
+ virtual ~OverrideTest() = default;
313
+ };
314
+
315
+ class PyOverrideTest : public OverrideTest {
316
+ public:
317
+ using OverrideTest::OverrideTest;
318
+ std::string str_value() override { PYBIND11_OVERRIDE(std::string, OverrideTest, str_value); }
319
+ // Not allowed (uncommenting should hit a static_assert failure): we can't get a reference
320
+ // to a python numeric value, since we only copy values in the numeric type caster:
321
+ // std::string &str_ref() override { PYBIND11_OVERRIDE(std::string &, OverrideTest, str_ref); }
322
+ // But we can work around it like this:
323
+ private:
324
+ std::string _tmp;
325
+ std::string str_ref_helper() { PYBIND11_OVERRIDE(std::string, OverrideTest, str_ref); }
326
+ public:
327
+ std::string &str_ref() override { return _tmp = str_ref_helper(); }
328
+
329
+ A A_value() override { PYBIND11_OVERRIDE(A, OverrideTest, A_value); }
330
+ A &A_ref() override { PYBIND11_OVERRIDE(A &, OverrideTest, A_ref); }
331
+ };
332
+
333
+ py::class_<OverrideTest::A>(m, "OverrideTest_A")
334
+ .def_readwrite("value", &OverrideTest::A::value);
335
+ py::class_<OverrideTest, PyOverrideTest>(m, "OverrideTest")
336
+ .def(py::init<const std::string &>())
337
+ .def("str_value", &OverrideTest::str_value)
338
+ // .def("str_ref", &OverrideTest::str_ref)
339
+ .def("A_value", &OverrideTest::A_value)
340
+ .def("A_ref", &OverrideTest::A_ref);
341
+ }
342
+
343
+
344
+ // Inheriting virtual methods. We do two versions here: the repeat-everything version and the
345
+ // templated trampoline versions mentioned in docs/advanced.rst.
346
+ //
347
+ // These base classes are exactly the same, but we technically need distinct
348
+ // classes for this example code because we need to be able to bind them
349
+ // properly (pybind11, sensibly, doesn't allow us to bind the same C++ class to
350
+ // multiple python classes).
351
+ class A_Repeat {
352
+ #define A_METHODS \
353
+ public: \
354
+ virtual int unlucky_number() = 0; \
355
+ virtual std::string say_something(unsigned times) { \
356
+ std::string s = ""; \
357
+ for (unsigned i = 0; i < times; ++i) \
358
+ s += "hi"; \
359
+ return s; \
360
+ } \
361
+ std::string say_everything() { \
362
+ return say_something(1) + " " + std::to_string(unlucky_number()); \
363
+ }
364
+ A_METHODS
365
+ A_Repeat() = default;
366
+ A_Repeat(const A_Repeat&) = delete;
367
+ virtual ~A_Repeat() = default;
368
+ };
369
+ class B_Repeat : public A_Repeat {
370
+ #define B_METHODS \
371
+ public: \
372
+ int unlucky_number() override { return 13; } \
373
+ std::string say_something(unsigned times) override { \
374
+ return "B says hi " + std::to_string(times) + " times"; \
375
+ } \
376
+ virtual double lucky_number() { return 7.0; }
377
+ B_METHODS
378
+ };
379
+ class C_Repeat : public B_Repeat {
380
+ #define C_METHODS \
381
+ public: \
382
+ int unlucky_number() override { return 4444; } \
383
+ double lucky_number() override { return 888; }
384
+ C_METHODS
385
+ };
386
+ class D_Repeat : public C_Repeat {
387
+ #define D_METHODS // Nothing overridden.
388
+ D_METHODS
389
+ };
390
+
391
+ // Base classes for templated inheritance trampolines. Identical to the repeat-everything version:
392
+ class A_Tpl {
393
+ A_METHODS;
394
+ A_Tpl() = default;
395
+ A_Tpl(const A_Tpl&) = delete;
396
+ virtual ~A_Tpl() = default;
397
+ };
398
+ class B_Tpl : public A_Tpl { B_METHODS };
399
+ class C_Tpl : public B_Tpl { C_METHODS };
400
+ class D_Tpl : public C_Tpl { D_METHODS };
401
+
402
+
403
+ // Inheritance approach 1: each trampoline gets every virtual method (11 in total)
404
+ class PyA_Repeat : public A_Repeat {
405
+ public:
406
+ using A_Repeat::A_Repeat;
407
+ int unlucky_number() override { PYBIND11_OVERRIDE_PURE(int, A_Repeat, unlucky_number, ); }
408
+ std::string say_something(unsigned times) override { PYBIND11_OVERRIDE(std::string, A_Repeat, say_something, times); }
409
+ };
410
+ class PyB_Repeat : public B_Repeat {
411
+ public:
412
+ using B_Repeat::B_Repeat;
413
+ int unlucky_number() override { PYBIND11_OVERRIDE(int, B_Repeat, unlucky_number, ); }
414
+ std::string say_something(unsigned times) override { PYBIND11_OVERRIDE(std::string, B_Repeat, say_something, times); }
415
+ double lucky_number() override { PYBIND11_OVERRIDE(double, B_Repeat, lucky_number, ); }
416
+ };
417
+ class PyC_Repeat : public C_Repeat {
418
+ public:
419
+ using C_Repeat::C_Repeat;
420
+ int unlucky_number() override { PYBIND11_OVERRIDE(int, C_Repeat, unlucky_number, ); }
421
+ std::string say_something(unsigned times) override { PYBIND11_OVERRIDE(std::string, C_Repeat, say_something, times); }
422
+ double lucky_number() override { PYBIND11_OVERRIDE(double, C_Repeat, lucky_number, ); }
423
+ };
424
+ class PyD_Repeat : public D_Repeat {
425
+ public:
426
+ using D_Repeat::D_Repeat;
427
+ int unlucky_number() override { PYBIND11_OVERRIDE(int, D_Repeat, unlucky_number, ); }
428
+ std::string say_something(unsigned times) override { PYBIND11_OVERRIDE(std::string, D_Repeat, say_something, times); }
429
+ double lucky_number() override { PYBIND11_OVERRIDE(double, D_Repeat, lucky_number, ); }
430
+ };
431
+
432
+ // Inheritance approach 2: templated trampoline classes.
433
+ //
434
+ // Advantages:
435
+ // - we have only 2 (template) class and 4 method declarations (one per virtual method, plus one for
436
+ // any override of a pure virtual method), versus 4 classes and 6 methods (MI) or 4 classes and 11
437
+ // methods (repeat).
438
+ // - Compared to MI, we also don't have to change the non-trampoline inheritance to virtual, and can
439
+ // properly inherit constructors.
440
+ //
441
+ // Disadvantage:
442
+ // - the compiler must still generate and compile 14 different methods (more, even, than the 11
443
+ // required for the repeat approach) instead of the 6 required for MI. (If there was no pure
444
+ // method (or no pure method override), the number would drop down to the same 11 as the repeat
445
+ // approach).
446
+ template <class Base = A_Tpl>
447
+ class PyA_Tpl : public Base {
448
+ public:
449
+ using Base::Base; // Inherit constructors
450
+ int unlucky_number() override { PYBIND11_OVERRIDE_PURE(int, Base, unlucky_number, ); }
451
+ std::string say_something(unsigned times) override { PYBIND11_OVERRIDE(std::string, Base, say_something, times); }
452
+ };
453
+ template <class Base = B_Tpl>
454
+ class PyB_Tpl : public PyA_Tpl<Base> {
455
+ public:
456
+ using PyA_Tpl<Base>::PyA_Tpl; // Inherit constructors (via PyA_Tpl's inherited constructors)
457
+ // NOLINTNEXTLINE(bugprone-parent-virtual-call)
458
+ int unlucky_number() override { PYBIND11_OVERRIDE(int, Base, unlucky_number, ); }
459
+ double lucky_number() override { PYBIND11_OVERRIDE(double, Base, lucky_number, ); }
460
+ };
461
+ // Since C_Tpl and D_Tpl don't declare any new virtual methods, we don't actually need these (we can
462
+ // use PyB_Tpl<C_Tpl> and PyB_Tpl<D_Tpl> for the trampoline classes instead):
463
+ /*
464
+ template <class Base = C_Tpl> class PyC_Tpl : public PyB_Tpl<Base> {
465
+ public:
466
+ using PyB_Tpl<Base>::PyB_Tpl;
467
+ };
468
+ template <class Base = D_Tpl> class PyD_Tpl : public PyC_Tpl<Base> {
469
+ public:
470
+ using PyC_Tpl<Base>::PyC_Tpl;
471
+ };
472
+ */
473
+
474
+ void initialize_inherited_virtuals(py::module_ &m) {
475
+ // test_inherited_virtuals
476
+
477
+ // Method 1: repeat
478
+ py::class_<A_Repeat, PyA_Repeat>(m, "A_Repeat")
479
+ .def(py::init<>())
480
+ .def("unlucky_number", &A_Repeat::unlucky_number)
481
+ .def("say_something", &A_Repeat::say_something)
482
+ .def("say_everything", &A_Repeat::say_everything);
483
+ py::class_<B_Repeat, A_Repeat, PyB_Repeat>(m, "B_Repeat")
484
+ .def(py::init<>())
485
+ .def("lucky_number", &B_Repeat::lucky_number);
486
+ py::class_<C_Repeat, B_Repeat, PyC_Repeat>(m, "C_Repeat")
487
+ .def(py::init<>());
488
+ py::class_<D_Repeat, C_Repeat, PyD_Repeat>(m, "D_Repeat")
489
+ .def(py::init<>());
490
+
491
+ // test_
492
+ // Method 2: Templated trampolines
493
+ py::class_<A_Tpl, PyA_Tpl<>>(m, "A_Tpl")
494
+ .def(py::init<>())
495
+ .def("unlucky_number", &A_Tpl::unlucky_number)
496
+ .def("say_something", &A_Tpl::say_something)
497
+ .def("say_everything", &A_Tpl::say_everything);
498
+ py::class_<B_Tpl, A_Tpl, PyB_Tpl<>>(m, "B_Tpl")
499
+ .def(py::init<>())
500
+ .def("lucky_number", &B_Tpl::lucky_number);
501
+ py::class_<C_Tpl, B_Tpl, PyB_Tpl<C_Tpl>>(m, "C_Tpl")
502
+ .def(py::init<>());
503
+ py::class_<D_Tpl, C_Tpl, PyB_Tpl<D_Tpl>>(m, "D_Tpl")
504
+ .def(py::init<>());
505
+
506
+
507
+ // Fix issue #1454 (crash when acquiring/releasing GIL on another thread in Python 2.7)
508
+ m.def("test_gil", &test_gil);
509
+ m.def("test_gil_from_thread", &test_gil_from_thread);
510
+ };