xcoll 0.4.0__py3-none-any.whl → 0.5.1__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 +9 -2
  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 +127 -81
  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.1.dist-info}/METADATA +1 -1
  319. xcoll-0.5.1.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.1.dist-info}/LICENSE +0 -0
  323. {xcoll-0.4.0.dist-info → xcoll-0.5.1.dist-info}/NOTICE +0 -0
  324. {xcoll-0.4.0.dist-info → xcoll-0.5.1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,550 @@
1
+ /*
2
+ tests/test_class.cpp -- test py::class_ definitions and basic functionality
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
+ #if defined(__INTEL_COMPILER) && __cplusplus >= 201703L
11
+ // Intel compiler requires a separate header file to support aligned new operators
12
+ // and does not set the __cpp_aligned_new feature macro.
13
+ // This header needs to be included before pybind11.
14
+ #include <aligned_new>
15
+ #endif
16
+
17
+ #include "pybind11_tests.h"
18
+ #include "constructor_stats.h"
19
+ #include "local_bindings.h"
20
+ #include <pybind11/stl.h>
21
+
22
+ #include <utility>
23
+
24
+ #if defined(_MSC_VER)
25
+ # pragma warning(disable: 4324) // warning C4324: structure was padded due to alignment specifier
26
+ #endif
27
+
28
+ // test_brace_initialization
29
+ struct NoBraceInitialization {
30
+ explicit NoBraceInitialization(std::vector<int> v) : vec{std::move(v)} {}
31
+ template <typename T>
32
+ NoBraceInitialization(std::initializer_list<T> l) : vec(l) {}
33
+
34
+ std::vector<int> vec;
35
+ };
36
+
37
+ TEST_SUBMODULE(class_, m) {
38
+ // test_instance
39
+ struct NoConstructor {
40
+ NoConstructor() = default;
41
+ NoConstructor(const NoConstructor &) = default;
42
+ NoConstructor(NoConstructor &&) = default;
43
+ static NoConstructor *new_instance() {
44
+ auto *ptr = new NoConstructor();
45
+ print_created(ptr, "via new_instance");
46
+ return ptr;
47
+ }
48
+ ~NoConstructor() { print_destroyed(this); }
49
+ };
50
+ struct NoConstructorNew {
51
+ NoConstructorNew() = default;
52
+ NoConstructorNew(const NoConstructorNew &) = default;
53
+ NoConstructorNew(NoConstructorNew &&) = default;
54
+ static NoConstructorNew *new_instance() {
55
+ auto *ptr = new NoConstructorNew();
56
+ print_created(ptr, "via new_instance");
57
+ return ptr;
58
+ }
59
+ ~NoConstructorNew() { print_destroyed(this); }
60
+ };
61
+
62
+ py::class_<NoConstructor>(m, "NoConstructor")
63
+ .def_static("new_instance", &NoConstructor::new_instance, "Return an instance");
64
+
65
+ py::class_<NoConstructorNew>(m, "NoConstructorNew")
66
+ .def(py::init([](const NoConstructorNew &self) { return self; })) // Need a NOOP __init__
67
+ .def_static("__new__",
68
+ [](const py::object &) { return NoConstructorNew::new_instance(); });
69
+
70
+ // test_inheritance
71
+ class Pet {
72
+ public:
73
+ Pet(const std::string &name, const std::string &species)
74
+ : m_name(name), m_species(species) {}
75
+ std::string name() const { return m_name; }
76
+ std::string species() const { return m_species; }
77
+ private:
78
+ std::string m_name;
79
+ std::string m_species;
80
+ };
81
+
82
+ class Dog : public Pet {
83
+ public:
84
+ explicit Dog(const std::string &name) : Pet(name, "dog") {}
85
+ std::string bark() const { return "Woof!"; }
86
+ };
87
+
88
+ class Rabbit : public Pet {
89
+ public:
90
+ explicit Rabbit(const std::string &name) : Pet(name, "parrot") {}
91
+ };
92
+
93
+ class Hamster : public Pet {
94
+ public:
95
+ explicit Hamster(const std::string &name) : Pet(name, "rodent") {}
96
+ };
97
+
98
+ class Chimera : public Pet {
99
+ Chimera() : Pet("Kimmy", "chimera") {}
100
+ };
101
+
102
+ py::class_<Pet> pet_class(m, "Pet");
103
+ pet_class
104
+ .def(py::init<std::string, std::string>())
105
+ .def("name", &Pet::name)
106
+ .def("species", &Pet::species);
107
+
108
+ /* One way of declaring a subclass relationship: reference parent's class_ object */
109
+ py::class_<Dog>(m, "Dog", pet_class)
110
+ .def(py::init<std::string>());
111
+
112
+ /* Another way of declaring a subclass relationship: reference parent's C++ type */
113
+ py::class_<Rabbit, Pet>(m, "Rabbit")
114
+ .def(py::init<std::string>());
115
+
116
+ /* And another: list parent in class template arguments */
117
+ py::class_<Hamster, Pet>(m, "Hamster")
118
+ .def(py::init<std::string>());
119
+
120
+ /* Constructors are not inherited by default */
121
+ py::class_<Chimera, Pet>(m, "Chimera");
122
+
123
+ m.def("pet_name_species", [](const Pet &pet) { return pet.name() + " is a " + pet.species(); });
124
+ m.def("dog_bark", [](const Dog &dog) { return dog.bark(); });
125
+
126
+ // test_automatic_upcasting
127
+ struct BaseClass {
128
+ BaseClass() = default;
129
+ BaseClass(const BaseClass &) = default;
130
+ BaseClass(BaseClass &&) = default;
131
+ virtual ~BaseClass() = default;
132
+ };
133
+ struct DerivedClass1 : BaseClass { };
134
+ struct DerivedClass2 : BaseClass { };
135
+
136
+ py::class_<BaseClass>(m, "BaseClass").def(py::init<>());
137
+ py::class_<DerivedClass1>(m, "DerivedClass1").def(py::init<>());
138
+ py::class_<DerivedClass2>(m, "DerivedClass2").def(py::init<>());
139
+
140
+ m.def("return_class_1", []() -> BaseClass* { return new DerivedClass1(); });
141
+ m.def("return_class_2", []() -> BaseClass* { return new DerivedClass2(); });
142
+ m.def("return_class_n", [](int n) -> BaseClass* {
143
+ if (n == 1) return new DerivedClass1();
144
+ if (n == 2) return new DerivedClass2();
145
+ return new BaseClass();
146
+ });
147
+ m.def("return_none", []() -> BaseClass* { return nullptr; });
148
+
149
+ // test_isinstance
150
+ m.def("check_instances", [](const py::list &l) {
151
+ return py::make_tuple(
152
+ py::isinstance<py::tuple>(l[0]),
153
+ py::isinstance<py::dict>(l[1]),
154
+ py::isinstance<Pet>(l[2]),
155
+ py::isinstance<Pet>(l[3]),
156
+ py::isinstance<Dog>(l[4]),
157
+ py::isinstance<Rabbit>(l[5]),
158
+ py::isinstance<UnregisteredType>(l[6])
159
+ );
160
+ });
161
+
162
+ struct Invalid {};
163
+
164
+ // test_type
165
+ m.def("check_type", [](int category) {
166
+ // Currently not supported (via a fail at compile time)
167
+ // See https://github.com/pybind/pybind11/issues/2486
168
+ // if (category == 2)
169
+ // return py::type::of<int>();
170
+ if (category == 1)
171
+ return py::type::of<DerivedClass1>();
172
+ return py::type::of<Invalid>();
173
+ });
174
+
175
+ m.def("get_type_of", [](py::object ob) { return py::type::of(std::move(ob)); });
176
+
177
+ m.def("get_type_classic", [](py::handle h) {
178
+ return h.get_type();
179
+ });
180
+
181
+ m.def("as_type", [](const py::object &ob) { return py::type(ob); });
182
+
183
+ // test_mismatched_holder
184
+ struct MismatchBase1 { };
185
+ struct MismatchDerived1 : MismatchBase1 { };
186
+
187
+ struct MismatchBase2 { };
188
+ struct MismatchDerived2 : MismatchBase2 { };
189
+
190
+ m.def("mismatched_holder_1", []() {
191
+ auto mod = py::module_::import("__main__");
192
+ py::class_<MismatchBase1, std::shared_ptr<MismatchBase1>>(mod, "MismatchBase1");
193
+ py::class_<MismatchDerived1, MismatchBase1>(mod, "MismatchDerived1");
194
+ });
195
+ m.def("mismatched_holder_2", []() {
196
+ auto mod = py::module_::import("__main__");
197
+ py::class_<MismatchBase2>(mod, "MismatchBase2");
198
+ py::class_<MismatchDerived2, std::shared_ptr<MismatchDerived2>,
199
+ MismatchBase2>(mod, "MismatchDerived2");
200
+ });
201
+
202
+ // test_override_static
203
+ // #511: problem with inheritance + overwritten def_static
204
+ struct MyBase {
205
+ static std::unique_ptr<MyBase> make() {
206
+ return std::unique_ptr<MyBase>(new MyBase());
207
+ }
208
+ };
209
+
210
+ struct MyDerived : MyBase {
211
+ static std::unique_ptr<MyDerived> make() {
212
+ return std::unique_ptr<MyDerived>(new MyDerived());
213
+ }
214
+ };
215
+
216
+ py::class_<MyBase>(m, "MyBase")
217
+ .def_static("make", &MyBase::make);
218
+
219
+ py::class_<MyDerived, MyBase>(m, "MyDerived")
220
+ .def_static("make", &MyDerived::make)
221
+ .def_static("make2", &MyDerived::make);
222
+
223
+ // test_implicit_conversion_life_support
224
+ struct ConvertibleFromUserType {
225
+ int i;
226
+
227
+ explicit ConvertibleFromUserType(UserType u) : i(u.value()) {}
228
+ };
229
+
230
+ py::class_<ConvertibleFromUserType>(m, "AcceptsUserType")
231
+ .def(py::init<UserType>());
232
+ py::implicitly_convertible<UserType, ConvertibleFromUserType>();
233
+
234
+ m.def("implicitly_convert_argument", [](const ConvertibleFromUserType &r) { return r.i; });
235
+ m.def("implicitly_convert_variable", [](const py::object &o) {
236
+ // `o` is `UserType` and `r` is a reference to a temporary created by implicit
237
+ // conversion. This is valid when called inside a bound function because the temp
238
+ // object is attached to the same life support system as the arguments.
239
+ const auto &r = o.cast<const ConvertibleFromUserType &>();
240
+ return r.i;
241
+ });
242
+ m.add_object("implicitly_convert_variable_fail", [&] {
243
+ auto f = [](PyObject *, PyObject *args) -> PyObject * {
244
+ auto o = py::reinterpret_borrow<py::tuple>(args)[0];
245
+ try { // It should fail here because there is no life support.
246
+ o.cast<const ConvertibleFromUserType &>();
247
+ } catch (const py::cast_error &e) {
248
+ return py::str(e.what()).release().ptr();
249
+ }
250
+ return py::str().release().ptr();
251
+ };
252
+
253
+ auto def = new PyMethodDef{"f", f, METH_VARARGS, nullptr};
254
+ py::capsule def_capsule(def, [](void *ptr) { delete reinterpret_cast<PyMethodDef *>(ptr); });
255
+ return py::reinterpret_steal<py::object>(PyCFunction_NewEx(def, def_capsule.ptr(), m.ptr()));
256
+ }());
257
+
258
+ // test_operator_new_delete
259
+ struct HasOpNewDel {
260
+ std::uint64_t i;
261
+ static void *operator new(size_t s) { py::print("A new", s); return ::operator new(s); }
262
+ static void *operator new(size_t s, void *ptr) { py::print("A placement-new", s); return ptr; }
263
+ static void operator delete(void *p) { py::print("A delete"); return ::operator delete(p); }
264
+ };
265
+ struct HasOpNewDelSize {
266
+ std::uint32_t i;
267
+ static void *operator new(size_t s) { py::print("B new", s); return ::operator new(s); }
268
+ static void *operator new(size_t s, void *ptr) { py::print("B placement-new", s); return ptr; }
269
+ static void operator delete(void *p, size_t s) { py::print("B delete", s); return ::operator delete(p); }
270
+ };
271
+ struct AliasedHasOpNewDelSize {
272
+ std::uint64_t i;
273
+ static void *operator new(size_t s) { py::print("C new", s); return ::operator new(s); }
274
+ static void *operator new(size_t s, void *ptr) { py::print("C placement-new", s); return ptr; }
275
+ static void operator delete(void *p, size_t s) { py::print("C delete", s); return ::operator delete(p); }
276
+ virtual ~AliasedHasOpNewDelSize() = default;
277
+ AliasedHasOpNewDelSize() = default;
278
+ AliasedHasOpNewDelSize(const AliasedHasOpNewDelSize&) = delete;
279
+ };
280
+ struct PyAliasedHasOpNewDelSize : AliasedHasOpNewDelSize {
281
+ PyAliasedHasOpNewDelSize() = default;
282
+ explicit PyAliasedHasOpNewDelSize(int) {}
283
+ std::uint64_t j;
284
+ };
285
+ struct HasOpNewDelBoth {
286
+ std::uint32_t i[8];
287
+ static void *operator new(size_t s) { py::print("D new", s); return ::operator new(s); }
288
+ static void *operator new(size_t s, void *ptr) { py::print("D placement-new", s); return ptr; }
289
+ static void operator delete(void *p) { py::print("D delete"); return ::operator delete(p); }
290
+ static void operator delete(void *p, size_t s) { py::print("D wrong delete", s); return ::operator delete(p); }
291
+ };
292
+ py::class_<HasOpNewDel>(m, "HasOpNewDel").def(py::init<>());
293
+ py::class_<HasOpNewDelSize>(m, "HasOpNewDelSize").def(py::init<>());
294
+ py::class_<HasOpNewDelBoth>(m, "HasOpNewDelBoth").def(py::init<>());
295
+ py::class_<AliasedHasOpNewDelSize, PyAliasedHasOpNewDelSize> aliased(m, "AliasedHasOpNewDelSize");
296
+ aliased.def(py::init<>());
297
+ aliased.attr("size_noalias") = py::int_(sizeof(AliasedHasOpNewDelSize));
298
+ aliased.attr("size_alias") = py::int_(sizeof(PyAliasedHasOpNewDelSize));
299
+
300
+ // This test is actually part of test_local_bindings (test_duplicate_local), but we need a
301
+ // definition in a different compilation unit within the same module:
302
+ bind_local<LocalExternal, 17>(m, "LocalExternal", py::module_local());
303
+
304
+ // test_bind_protected_functions
305
+ class ProtectedA {
306
+ protected:
307
+ int foo() const { return value; }
308
+
309
+ private:
310
+ int value = 42;
311
+ };
312
+
313
+ class PublicistA : public ProtectedA {
314
+ public:
315
+ using ProtectedA::foo;
316
+ };
317
+
318
+ py::class_<ProtectedA>(m, "ProtectedA")
319
+ .def(py::init<>())
320
+ #if !defined(_MSC_VER) || _MSC_VER >= 1910
321
+ .def("foo", &PublicistA::foo);
322
+ #else
323
+ .def("foo", static_cast<int (ProtectedA::*)() const>(&PublicistA::foo));
324
+ #endif
325
+
326
+ class ProtectedB {
327
+ public:
328
+ virtual ~ProtectedB() = default;
329
+ ProtectedB() = default;
330
+ ProtectedB(const ProtectedB &) = delete;
331
+
332
+ protected:
333
+ virtual int foo() const { return value; }
334
+
335
+ private:
336
+ int value = 42;
337
+ };
338
+
339
+ class TrampolineB : public ProtectedB {
340
+ public:
341
+ int foo() const override { PYBIND11_OVERRIDE(int, ProtectedB, foo, ); }
342
+ };
343
+
344
+ class PublicistB : public ProtectedB {
345
+ public:
346
+ // [workaround(intel)] = default does not work here
347
+ // Removing or defaulting this destructor results in linking errors with the Intel compiler
348
+ // (in Debug builds only, tested with icpc (ICC) 2021.1 Beta 20200827)
349
+ ~PublicistB() override {}; // NOLINT(modernize-use-equals-default)
350
+ using ProtectedB::foo;
351
+ };
352
+
353
+ py::class_<ProtectedB, TrampolineB>(m, "ProtectedB")
354
+ .def(py::init<>())
355
+ #if !defined(_MSC_VER) || _MSC_VER >= 1910
356
+ .def("foo", &PublicistB::foo);
357
+ #else
358
+ .def("foo", static_cast<int (ProtectedB::*)() const>(&PublicistB::foo));
359
+ #endif
360
+
361
+ // test_brace_initialization
362
+ struct BraceInitialization {
363
+ int field1;
364
+ std::string field2;
365
+ };
366
+
367
+ py::class_<BraceInitialization>(m, "BraceInitialization")
368
+ .def(py::init<int, const std::string &>())
369
+ .def_readwrite("field1", &BraceInitialization::field1)
370
+ .def_readwrite("field2", &BraceInitialization::field2);
371
+ // We *don't* want to construct using braces when the given constructor argument maps to a
372
+ // constructor, because brace initialization could go to the wrong place (in particular when
373
+ // there is also an `initializer_list<T>`-accept constructor):
374
+ py::class_<NoBraceInitialization>(m, "NoBraceInitialization")
375
+ .def(py::init<std::vector<int>>())
376
+ .def_readonly("vec", &NoBraceInitialization::vec);
377
+
378
+ // test_reentrant_implicit_conversion_failure
379
+ // #1035: issue with runaway reentrant implicit conversion
380
+ struct BogusImplicitConversion {
381
+ BogusImplicitConversion(const BogusImplicitConversion &) = default;
382
+ };
383
+
384
+ py::class_<BogusImplicitConversion>(m, "BogusImplicitConversion")
385
+ .def(py::init<const BogusImplicitConversion &>());
386
+
387
+ py::implicitly_convertible<int, BogusImplicitConversion>();
388
+
389
+ // test_qualname
390
+ // #1166: nested class docstring doesn't show nested name
391
+ // Also related: tests that __qualname__ is set properly
392
+ struct NestBase {};
393
+ struct Nested {};
394
+ py::class_<NestBase> base(m, "NestBase");
395
+ base.def(py::init<>());
396
+ py::class_<Nested>(base, "Nested")
397
+ .def(py::init<>())
398
+ .def("fn", [](Nested &, int, NestBase &, Nested &) {})
399
+ .def("fa", [](Nested &, int, NestBase &, Nested &) {},
400
+ "a"_a, "b"_a, "c"_a);
401
+ base.def("g", [](NestBase &, Nested &) {});
402
+ base.def("h", []() { return NestBase(); });
403
+
404
+ // test_error_after_conversion
405
+ // The second-pass path through dispatcher() previously didn't
406
+ // remember which overload was used, and would crash trying to
407
+ // generate a useful error message
408
+
409
+ struct NotRegistered {};
410
+ struct StringWrapper { std::string str; };
411
+ m.def("test_error_after_conversions", [](int) {});
412
+ m.def("test_error_after_conversions",
413
+ [](const StringWrapper &) -> NotRegistered { return {}; });
414
+ py::class_<StringWrapper>(m, "StringWrapper").def(py::init<std::string>());
415
+ py::implicitly_convertible<std::string, StringWrapper>();
416
+
417
+ #if defined(PYBIND11_CPP17)
418
+ struct alignas(1024) Aligned {
419
+ std::uintptr_t ptr() const { return (uintptr_t) this; }
420
+ };
421
+ py::class_<Aligned>(m, "Aligned")
422
+ .def(py::init<>())
423
+ .def("ptr", &Aligned::ptr);
424
+ #endif
425
+
426
+ // test_final
427
+ struct IsFinal final {};
428
+ py::class_<IsFinal>(m, "IsFinal", py::is_final());
429
+
430
+ // test_non_final_final
431
+ struct IsNonFinalFinal {};
432
+ py::class_<IsNonFinalFinal>(m, "IsNonFinalFinal", py::is_final());
433
+
434
+ // test_exception_rvalue_abort
435
+ struct PyPrintDestructor {
436
+ PyPrintDestructor() = default;
437
+ ~PyPrintDestructor() {
438
+ py::print("Print from destructor");
439
+ }
440
+ void throw_something() { throw std::runtime_error("error"); }
441
+ };
442
+ py::class_<PyPrintDestructor>(m, "PyPrintDestructor")
443
+ .def(py::init<>())
444
+ .def("throw_something", &PyPrintDestructor::throw_something);
445
+
446
+ // test_multiple_instances_with_same_pointer
447
+ struct SamePointer {};
448
+ static SamePointer samePointer;
449
+ py::class_<SamePointer, std::unique_ptr<SamePointer, py::nodelete>>(m, "SamePointer")
450
+ .def(py::init([]() { return &samePointer; }));
451
+
452
+ struct Empty {};
453
+ py::class_<Empty>(m, "Empty")
454
+ .def(py::init<>());
455
+
456
+ // test_base_and_derived_nested_scope
457
+ struct BaseWithNested {
458
+ struct Nested {};
459
+ };
460
+
461
+ struct DerivedWithNested : BaseWithNested {
462
+ struct Nested {};
463
+ };
464
+
465
+ py::class_<BaseWithNested> baseWithNested_class(m, "BaseWithNested");
466
+ py::class_<DerivedWithNested, BaseWithNested> derivedWithNested_class(m, "DerivedWithNested");
467
+ py::class_<BaseWithNested::Nested>(baseWithNested_class, "Nested")
468
+ .def_static("get_name", []() { return "BaseWithNested::Nested"; });
469
+ py::class_<DerivedWithNested::Nested>(derivedWithNested_class, "Nested")
470
+ .def_static("get_name", []() { return "DerivedWithNested::Nested"; });
471
+
472
+ // test_register_duplicate_class
473
+ struct Duplicate {};
474
+ struct OtherDuplicate {};
475
+ struct DuplicateNested {};
476
+ struct OtherDuplicateNested {};
477
+
478
+ m.def("register_duplicate_class_name", [](const py::module_ &m) {
479
+ py::class_<Duplicate>(m, "Duplicate");
480
+ py::class_<OtherDuplicate>(m, "Duplicate");
481
+ });
482
+ m.def("register_duplicate_class_type", [](const py::module_ &m) {
483
+ py::class_<OtherDuplicate>(m, "OtherDuplicate");
484
+ py::class_<OtherDuplicate>(m, "YetAnotherDuplicate");
485
+ });
486
+ m.def("register_duplicate_nested_class_name", [](const py::object &gt) {
487
+ py::class_<DuplicateNested>(gt, "DuplicateNested");
488
+ py::class_<OtherDuplicateNested>(gt, "DuplicateNested");
489
+ });
490
+ m.def("register_duplicate_nested_class_type", [](const py::object &gt) {
491
+ py::class_<OtherDuplicateNested>(gt, "OtherDuplicateNested");
492
+ py::class_<OtherDuplicateNested>(gt, "YetAnotherDuplicateNested");
493
+ });
494
+ }
495
+
496
+ template <int N> class BreaksBase { public:
497
+ virtual ~BreaksBase() = default;
498
+ BreaksBase() = default;
499
+ BreaksBase(const BreaksBase&) = delete;
500
+ };
501
+ template <int N> class BreaksTramp : public BreaksBase<N> {};
502
+ // These should all compile just fine:
503
+ using DoesntBreak1 = py::class_<BreaksBase<1>, std::unique_ptr<BreaksBase<1>>, BreaksTramp<1>>;
504
+ using DoesntBreak2 = py::class_<BreaksBase<2>, BreaksTramp<2>, std::unique_ptr<BreaksBase<2>>>;
505
+ using DoesntBreak3 = py::class_<BreaksBase<3>, std::unique_ptr<BreaksBase<3>>>;
506
+ using DoesntBreak4 = py::class_<BreaksBase<4>, BreaksTramp<4>>;
507
+ using DoesntBreak5 = py::class_<BreaksBase<5>>;
508
+ using DoesntBreak6 = py::class_<BreaksBase<6>, std::shared_ptr<BreaksBase<6>>, BreaksTramp<6>>;
509
+ using DoesntBreak7 = py::class_<BreaksBase<7>, BreaksTramp<7>, std::shared_ptr<BreaksBase<7>>>;
510
+ using DoesntBreak8 = py::class_<BreaksBase<8>, std::shared_ptr<BreaksBase<8>>>;
511
+ #define CHECK_BASE(N) static_assert(std::is_same<typename DoesntBreak##N::type, BreaksBase<(N)>>::value, \
512
+ "DoesntBreak" #N " has wrong type!")
513
+ CHECK_BASE(1); CHECK_BASE(2); CHECK_BASE(3); CHECK_BASE(4); CHECK_BASE(5); CHECK_BASE(6); CHECK_BASE(7); CHECK_BASE(8);
514
+ #define CHECK_ALIAS(N) static_assert(DoesntBreak##N::has_alias && std::is_same<typename DoesntBreak##N::type_alias, BreaksTramp<(N)>>::value, \
515
+ "DoesntBreak" #N " has wrong type_alias!")
516
+ #define CHECK_NOALIAS(N) static_assert(!DoesntBreak##N::has_alias && std::is_void<typename DoesntBreak##N::type_alias>::value, \
517
+ "DoesntBreak" #N " has type alias, but shouldn't!")
518
+ CHECK_ALIAS(1); CHECK_ALIAS(2); CHECK_NOALIAS(3); CHECK_ALIAS(4); CHECK_NOALIAS(5); CHECK_ALIAS(6); CHECK_ALIAS(7); CHECK_NOALIAS(8);
519
+ #define CHECK_HOLDER(N, TYPE) static_assert(std::is_same<typename DoesntBreak##N::holder_type, std::TYPE##_ptr<BreaksBase<(N)>>>::value, \
520
+ "DoesntBreak" #N " has wrong holder_type!")
521
+ CHECK_HOLDER(1, unique); CHECK_HOLDER(2, unique); CHECK_HOLDER(3, unique); CHECK_HOLDER(4, unique); CHECK_HOLDER(5, unique);
522
+ CHECK_HOLDER(6, shared); CHECK_HOLDER(7, shared); CHECK_HOLDER(8, shared);
523
+
524
+ // There's no nice way to test that these fail because they fail to compile; leave them here,
525
+ // though, so that they can be manually tested by uncommenting them (and seeing that compilation
526
+ // failures occurs).
527
+
528
+ // We have to actually look into the type: the typedef alone isn't enough to instantiate the type:
529
+ #define CHECK_BROKEN(N) static_assert(std::is_same<typename Breaks##N::type, BreaksBase<-(N)>>::value, \
530
+ "Breaks1 has wrong type!");
531
+
532
+ //// Two holder classes:
533
+ //typedef py::class_<BreaksBase<-1>, std::unique_ptr<BreaksBase<-1>>, std::unique_ptr<BreaksBase<-1>>> Breaks1;
534
+ //CHECK_BROKEN(1);
535
+ //// Two aliases:
536
+ //typedef py::class_<BreaksBase<-2>, BreaksTramp<-2>, BreaksTramp<-2>> Breaks2;
537
+ //CHECK_BROKEN(2);
538
+ //// Holder + 2 aliases
539
+ //typedef py::class_<BreaksBase<-3>, std::unique_ptr<BreaksBase<-3>>, BreaksTramp<-3>, BreaksTramp<-3>> Breaks3;
540
+ //CHECK_BROKEN(3);
541
+ //// Alias + 2 holders
542
+ //typedef py::class_<BreaksBase<-4>, std::unique_ptr<BreaksBase<-4>>, BreaksTramp<-4>, std::shared_ptr<BreaksBase<-4>>> Breaks4;
543
+ //CHECK_BROKEN(4);
544
+ //// Invalid option (not a subclass or holder)
545
+ //typedef py::class_<BreaksBase<-5>, BreaksTramp<-4>> Breaks5;
546
+ //CHECK_BROKEN(5);
547
+ //// Invalid option: multiple inheritance not supported:
548
+ //template <> struct BreaksBase<-8> : BreaksBase<-6>, BreaksBase<-7> {};
549
+ //typedef py::class_<BreaksBase<-8>, BreaksBase<-6>, BreaksBase<-7>> Breaks8;
550
+ //CHECK_BROKEN(8);