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,248 @@
1
+ # -*- coding: utf-8 -*-
2
+ import pytest
3
+
4
+ import env # noqa: F401
5
+ from pybind11_tests import ConstructorStats
6
+ from pybind11_tests import call_policies as m
7
+
8
+
9
+ @pytest.mark.xfail("env.PYPY", reason="sometimes comes out 1 off on PyPy", strict=False)
10
+ def test_keep_alive_argument(capture):
11
+ n_inst = ConstructorStats.detail_reg_inst()
12
+ with capture:
13
+ p = m.Parent()
14
+ assert capture == "Allocating parent."
15
+ with capture:
16
+ p.addChild(m.Child())
17
+ assert ConstructorStats.detail_reg_inst() == n_inst + 1
18
+ assert (
19
+ capture
20
+ == """
21
+ Allocating child.
22
+ Releasing child.
23
+ """
24
+ )
25
+ with capture:
26
+ del p
27
+ assert ConstructorStats.detail_reg_inst() == n_inst
28
+ assert capture == "Releasing parent."
29
+
30
+ with capture:
31
+ p = m.Parent()
32
+ assert capture == "Allocating parent."
33
+ with capture:
34
+ p.addChildKeepAlive(m.Child())
35
+ assert ConstructorStats.detail_reg_inst() == n_inst + 2
36
+ assert capture == "Allocating child."
37
+ with capture:
38
+ del p
39
+ assert ConstructorStats.detail_reg_inst() == n_inst
40
+ assert (
41
+ capture
42
+ == """
43
+ Releasing parent.
44
+ Releasing child.
45
+ """
46
+ )
47
+
48
+ p = m.Parent()
49
+ c = m.Child()
50
+ assert ConstructorStats.detail_reg_inst() == n_inst + 2
51
+ m.free_function(p, c)
52
+ del c
53
+ assert ConstructorStats.detail_reg_inst() == n_inst + 2
54
+ del p
55
+ assert ConstructorStats.detail_reg_inst() == n_inst
56
+
57
+ with pytest.raises(RuntimeError) as excinfo:
58
+ m.invalid_arg_index()
59
+ assert str(excinfo.value) == "Could not activate keep_alive!"
60
+
61
+
62
+ def test_keep_alive_return_value(capture):
63
+ n_inst = ConstructorStats.detail_reg_inst()
64
+ with capture:
65
+ p = m.Parent()
66
+ assert capture == "Allocating parent."
67
+ with capture:
68
+ p.returnChild()
69
+ assert ConstructorStats.detail_reg_inst() == n_inst + 1
70
+ assert (
71
+ capture
72
+ == """
73
+ Allocating child.
74
+ Releasing child.
75
+ """
76
+ )
77
+ with capture:
78
+ del p
79
+ assert ConstructorStats.detail_reg_inst() == n_inst
80
+ assert capture == "Releasing parent."
81
+
82
+ with capture:
83
+ p = m.Parent()
84
+ assert capture == "Allocating parent."
85
+ with capture:
86
+ p.returnChildKeepAlive()
87
+ assert ConstructorStats.detail_reg_inst() == n_inst + 2
88
+ assert capture == "Allocating child."
89
+ with capture:
90
+ del p
91
+ assert ConstructorStats.detail_reg_inst() == n_inst
92
+ assert (
93
+ capture
94
+ == """
95
+ Releasing parent.
96
+ Releasing child.
97
+ """
98
+ )
99
+
100
+ p = m.Parent()
101
+ assert ConstructorStats.detail_reg_inst() == n_inst + 1
102
+ with capture:
103
+ m.Parent.staticFunction(p)
104
+ assert ConstructorStats.detail_reg_inst() == n_inst + 2
105
+ assert capture == "Allocating child."
106
+ with capture:
107
+ del p
108
+ assert ConstructorStats.detail_reg_inst() == n_inst
109
+ assert (
110
+ capture
111
+ == """
112
+ Releasing parent.
113
+ Releasing child.
114
+ """
115
+ )
116
+
117
+
118
+ # https://foss.heptapod.net/pypy/pypy/-/issues/2447
119
+ @pytest.mark.xfail("env.PYPY", reason="_PyObject_GetDictPtr is unimplemented")
120
+ def test_alive_gc(capture):
121
+ n_inst = ConstructorStats.detail_reg_inst()
122
+ p = m.ParentGC()
123
+ p.addChildKeepAlive(m.Child())
124
+ assert ConstructorStats.detail_reg_inst() == n_inst + 2
125
+ lst = [p]
126
+ lst.append(lst) # creates a circular reference
127
+ with capture:
128
+ del p, lst
129
+ assert ConstructorStats.detail_reg_inst() == n_inst
130
+ assert (
131
+ capture
132
+ == """
133
+ Releasing parent.
134
+ Releasing child.
135
+ """
136
+ )
137
+
138
+
139
+ def test_alive_gc_derived(capture):
140
+ class Derived(m.Parent):
141
+ pass
142
+
143
+ n_inst = ConstructorStats.detail_reg_inst()
144
+ p = Derived()
145
+ p.addChildKeepAlive(m.Child())
146
+ assert ConstructorStats.detail_reg_inst() == n_inst + 2
147
+ lst = [p]
148
+ lst.append(lst) # creates a circular reference
149
+ with capture:
150
+ del p, lst
151
+ assert ConstructorStats.detail_reg_inst() == n_inst
152
+ assert (
153
+ capture
154
+ == """
155
+ Releasing parent.
156
+ Releasing child.
157
+ """
158
+ )
159
+
160
+
161
+ def test_alive_gc_multi_derived(capture):
162
+ class Derived(m.Parent, m.Child):
163
+ def __init__(self):
164
+ m.Parent.__init__(self)
165
+ m.Child.__init__(self)
166
+
167
+ n_inst = ConstructorStats.detail_reg_inst()
168
+ p = Derived()
169
+ p.addChildKeepAlive(m.Child())
170
+ # +3 rather than +2 because Derived corresponds to two registered instances
171
+ assert ConstructorStats.detail_reg_inst() == n_inst + 3
172
+ lst = [p]
173
+ lst.append(lst) # creates a circular reference
174
+ with capture:
175
+ del p, lst
176
+ assert ConstructorStats.detail_reg_inst() == n_inst
177
+ assert (
178
+ capture
179
+ == """
180
+ Releasing parent.
181
+ Releasing child.
182
+ Releasing child.
183
+ """
184
+ )
185
+
186
+
187
+ def test_return_none(capture):
188
+ n_inst = ConstructorStats.detail_reg_inst()
189
+ with capture:
190
+ p = m.Parent()
191
+ assert capture == "Allocating parent."
192
+ with capture:
193
+ p.returnNullChildKeepAliveChild()
194
+ assert ConstructorStats.detail_reg_inst() == n_inst + 1
195
+ assert capture == ""
196
+ with capture:
197
+ del p
198
+ assert ConstructorStats.detail_reg_inst() == n_inst
199
+ assert capture == "Releasing parent."
200
+
201
+ with capture:
202
+ p = m.Parent()
203
+ assert capture == "Allocating parent."
204
+ with capture:
205
+ p.returnNullChildKeepAliveParent()
206
+ assert ConstructorStats.detail_reg_inst() == n_inst + 1
207
+ assert capture == ""
208
+ with capture:
209
+ del p
210
+ assert ConstructorStats.detail_reg_inst() == n_inst
211
+ assert capture == "Releasing parent."
212
+
213
+
214
+ def test_keep_alive_constructor(capture):
215
+ n_inst = ConstructorStats.detail_reg_inst()
216
+
217
+ with capture:
218
+ p = m.Parent(m.Child())
219
+ assert ConstructorStats.detail_reg_inst() == n_inst + 2
220
+ assert (
221
+ capture
222
+ == """
223
+ Allocating child.
224
+ Allocating parent.
225
+ """
226
+ )
227
+ with capture:
228
+ del p
229
+ assert ConstructorStats.detail_reg_inst() == n_inst
230
+ assert (
231
+ capture
232
+ == """
233
+ Releasing parent.
234
+ Releasing child.
235
+ """
236
+ )
237
+
238
+
239
+ def test_call_guard():
240
+ assert m.unguarded_call() == "unguarded"
241
+ assert m.guarded_call() == "guarded"
242
+
243
+ assert m.multiple_guards_correct_order() == "guarded & guarded"
244
+ assert m.multiple_guards_wrong_order() == "unguarded & guarded"
245
+
246
+ if hasattr(m, "with_gil"):
247
+ assert m.with_gil() == "GIL held"
248
+ assert m.without_gil() == "GIL released"
@@ -0,0 +1,227 @@
1
+ /*
2
+ tests/test_callbacks.cpp -- callbacks
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
+
16
+ int dummy_function(int i) { return i + 1; }
17
+
18
+ TEST_SUBMODULE(callbacks, m) {
19
+ // test_callbacks, test_function_signatures
20
+ m.def("test_callback1", [](const py::object &func) { return func(); });
21
+ m.def("test_callback2", [](const py::object &func) { return func("Hello", 'x', true, 5); });
22
+ m.def("test_callback3", [](const std::function<int(int)> &func) {
23
+ return "func(43) = " + std::to_string(func(43)); });
24
+ m.def("test_callback4", []() -> std::function<int(int)> { return [](int i) { return i+1; }; });
25
+ m.def("test_callback5", []() {
26
+ return py::cpp_function([](int i) { return i+1; }, py::arg("number"));
27
+ });
28
+
29
+ // test_keyword_args_and_generalized_unpacking
30
+ m.def("test_tuple_unpacking", [](const py::function &f) {
31
+ auto t1 = py::make_tuple(2, 3);
32
+ auto t2 = py::make_tuple(5, 6);
33
+ return f("positional", 1, *t1, 4, *t2);
34
+ });
35
+
36
+ m.def("test_dict_unpacking", [](const py::function &f) {
37
+ auto d1 = py::dict("key"_a="value", "a"_a=1);
38
+ auto d2 = py::dict();
39
+ auto d3 = py::dict("b"_a=2);
40
+ return f("positional", 1, **d1, **d2, **d3);
41
+ });
42
+
43
+ m.def("test_keyword_args", [](const py::function &f) { return f("x"_a = 10, "y"_a = 20); });
44
+
45
+ m.def("test_unpacking_and_keywords1", [](const py::function &f) {
46
+ auto args = py::make_tuple(2);
47
+ auto kwargs = py::dict("d"_a=4);
48
+ return f(1, *args, "c"_a=3, **kwargs);
49
+ });
50
+
51
+ m.def("test_unpacking_and_keywords2", [](const py::function &f) {
52
+ auto kwargs1 = py::dict("a"_a=1);
53
+ auto kwargs2 = py::dict("c"_a=3, "d"_a=4);
54
+ return f("positional", *py::make_tuple(1), 2, *py::make_tuple(3, 4), 5,
55
+ "key"_a="value", **kwargs1, "b"_a=2, **kwargs2, "e"_a=5);
56
+ });
57
+
58
+ m.def("test_unpacking_error1", [](const py::function &f) {
59
+ auto kwargs = py::dict("x"_a=3);
60
+ return f("x"_a=1, "y"_a=2, **kwargs); // duplicate ** after keyword
61
+ });
62
+
63
+ m.def("test_unpacking_error2", [](const py::function &f) {
64
+ auto kwargs = py::dict("x"_a=3);
65
+ return f(**kwargs, "x"_a=1); // duplicate keyword after **
66
+ });
67
+
68
+ m.def("test_arg_conversion_error1",
69
+ [](const py::function &f) { f(234, UnregisteredType(), "kw"_a = 567); });
70
+
71
+ m.def("test_arg_conversion_error2", [](const py::function &f) {
72
+ f(234, "expected_name"_a=UnregisteredType(), "kw"_a=567);
73
+ });
74
+
75
+ // test_lambda_closure_cleanup
76
+ struct Payload {
77
+ Payload() { print_default_created(this); }
78
+ ~Payload() { print_destroyed(this); }
79
+ Payload(const Payload &) { print_copy_created(this); }
80
+ Payload(Payload &&) noexcept { print_move_created(this); }
81
+ };
82
+ // Export the payload constructor statistics for testing purposes:
83
+ m.def("payload_cstats", &ConstructorStats::get<Payload>);
84
+ m.def("test_lambda_closure_cleanup", []() -> std::function<void()> {
85
+ Payload p;
86
+
87
+ // In this situation, `Func` in the implementation of
88
+ // `cpp_function::initialize` is NOT trivially destructible.
89
+ return [p]() {
90
+ /* p should be cleaned up when the returned function is garbage collected */
91
+ (void) p;
92
+ };
93
+ });
94
+
95
+ class CppCallable {
96
+ public:
97
+ CppCallable() { track_default_created(this); }
98
+ ~CppCallable() { track_destroyed(this); }
99
+ CppCallable(const CppCallable &) { track_copy_created(this); }
100
+ CppCallable(CppCallable &&) noexcept { track_move_created(this); }
101
+ void operator()() {}
102
+ };
103
+
104
+ m.def("test_cpp_callable_cleanup", []() {
105
+ // Related issue: https://github.com/pybind/pybind11/issues/3228
106
+ // Related PR: https://github.com/pybind/pybind11/pull/3229
107
+ py::list alive_counts;
108
+ ConstructorStats &stat = ConstructorStats::get<CppCallable>();
109
+ alive_counts.append(stat.alive());
110
+ {
111
+ CppCallable cpp_callable;
112
+ alive_counts.append(stat.alive());
113
+ {
114
+ // In this situation, `Func` in the implementation of
115
+ // `cpp_function::initialize` IS trivially destructible,
116
+ // only `capture` is not.
117
+ py::cpp_function py_func(cpp_callable);
118
+ py::detail::silence_unused_warnings(py_func);
119
+ alive_counts.append(stat.alive());
120
+ }
121
+ alive_counts.append(stat.alive());
122
+ {
123
+ py::cpp_function py_func(std::move(cpp_callable));
124
+ py::detail::silence_unused_warnings(py_func);
125
+ alive_counts.append(stat.alive());
126
+ }
127
+ alive_counts.append(stat.alive());
128
+ }
129
+ alive_counts.append(stat.alive());
130
+ return alive_counts;
131
+ });
132
+
133
+ // test_cpp_function_roundtrip
134
+ /* Test if passing a function pointer from C++ -> Python -> C++ yields the original pointer */
135
+ m.def("dummy_function", &dummy_function);
136
+ m.def("dummy_function_overloaded", [](int i, int j) { return i + j; });
137
+ m.def("dummy_function_overloaded", &dummy_function);
138
+ m.def("dummy_function2", [](int i, int j) { return i + j; });
139
+ m.def("roundtrip", [](std::function<int(int)> f, bool expect_none = false) {
140
+ if (expect_none && f)
141
+ throw std::runtime_error("Expected None to be converted to empty std::function");
142
+ return f;
143
+ }, py::arg("f"), py::arg("expect_none")=false);
144
+ m.def("test_dummy_function", [](const std::function<int(int)> &f) -> std::string {
145
+ using fn_type = int (*)(int);
146
+ auto result = f.target<fn_type>();
147
+ if (!result) {
148
+ auto r = f(1);
149
+ return "can't convert to function pointer: eval(1) = " + std::to_string(r);
150
+ }
151
+ if (*result == dummy_function) {
152
+ auto r = (*result)(1);
153
+ return "matches dummy_function: eval(1) = " + std::to_string(r);
154
+ }
155
+ return "argument does NOT match dummy_function. This should never happen!";
156
+
157
+ });
158
+
159
+ class AbstractBase {
160
+ public:
161
+ // [workaround(intel)] = default does not work here
162
+ // Defaulting this destructor results in linking errors with the Intel compiler
163
+ // (in Debug builds only, tested with icpc (ICC) 2021.1 Beta 20200827)
164
+ virtual ~AbstractBase() {} // NOLINT(modernize-use-equals-default)
165
+ virtual unsigned int func() = 0;
166
+ };
167
+ m.def("func_accepting_func_accepting_base",
168
+ [](const std::function<double(AbstractBase &)> &) {});
169
+
170
+ struct MovableObject {
171
+ bool valid = true;
172
+
173
+ MovableObject() = default;
174
+ MovableObject(const MovableObject &) = default;
175
+ MovableObject &operator=(const MovableObject &) = default;
176
+ MovableObject(MovableObject &&o) noexcept : valid(o.valid) { o.valid = false; }
177
+ MovableObject &operator=(MovableObject &&o) noexcept {
178
+ valid = o.valid;
179
+ o.valid = false;
180
+ return *this;
181
+ }
182
+ };
183
+ py::class_<MovableObject>(m, "MovableObject");
184
+
185
+ // test_movable_object
186
+ m.def("callback_with_movable", [](const std::function<void(MovableObject &)> &f) {
187
+ auto x = MovableObject();
188
+ f(x); // lvalue reference shouldn't move out object
189
+ return x.valid; // must still return `true`
190
+ });
191
+
192
+ // test_bound_method_callback
193
+ struct CppBoundMethodTest {};
194
+ py::class_<CppBoundMethodTest>(m, "CppBoundMethodTest")
195
+ .def(py::init<>())
196
+ .def("triple", [](CppBoundMethodTest &, int val) { return 3 * val; });
197
+
198
+ // This checks that builtin functions can be passed as callbacks
199
+ // rather than throwing RuntimeError due to trying to extract as capsule
200
+ m.def("test_sum_builtin", [](const std::function<double(py::iterable)> &sum_builtin, const py::iterable &i) {
201
+ return sum_builtin(i);
202
+ });
203
+
204
+ // test async Python callbacks
205
+ using callback_f = std::function<void(int)>;
206
+ m.def("test_async_callback", [](const callback_f &f, const py::list &work) {
207
+ // make detached thread that calls `f` with piece of work after a little delay
208
+ auto start_f = [f](int j) {
209
+ auto invoke_f = [f, j] {
210
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
211
+ f(j);
212
+ };
213
+ auto t = std::thread(std::move(invoke_f));
214
+ t.detach();
215
+ };
216
+
217
+ // spawn worker threads
218
+ for (auto i : work)
219
+ start_f(py::cast<int>(i));
220
+ });
221
+
222
+ m.def("callback_num_times", [](const py::function &f, std::size_t num) {
223
+ for (std::size_t i = 0; i < num; i++) {
224
+ f();
225
+ }
226
+ });
227
+ }
@@ -0,0 +1,202 @@
1
+ # -*- coding: utf-8 -*-
2
+ import time
3
+ from threading import Thread
4
+
5
+ import pytest
6
+
7
+ import env # noqa: F401
8
+ from pybind11_tests import callbacks as m
9
+
10
+
11
+ def test_callbacks():
12
+ from functools import partial
13
+
14
+ def func1():
15
+ return "func1"
16
+
17
+ def func2(a, b, c, d):
18
+ return "func2", a, b, c, d
19
+
20
+ def func3(a):
21
+ return "func3({})".format(a)
22
+
23
+ assert m.test_callback1(func1) == "func1"
24
+ assert m.test_callback2(func2) == ("func2", "Hello", "x", True, 5)
25
+ assert m.test_callback1(partial(func2, 1, 2, 3, 4)) == ("func2", 1, 2, 3, 4)
26
+ assert m.test_callback1(partial(func3, "partial")) == "func3(partial)"
27
+ assert m.test_callback3(lambda i: i + 1) == "func(43) = 44"
28
+
29
+ f = m.test_callback4()
30
+ assert f(43) == 44
31
+ f = m.test_callback5()
32
+ assert f(number=43) == 44
33
+
34
+
35
+ def test_bound_method_callback():
36
+ # Bound Python method:
37
+ class MyClass:
38
+ def double(self, val):
39
+ return 2 * val
40
+
41
+ z = MyClass()
42
+ assert m.test_callback3(z.double) == "func(43) = 86"
43
+
44
+ z = m.CppBoundMethodTest()
45
+ assert m.test_callback3(z.triple) == "func(43) = 129"
46
+
47
+
48
+ def test_keyword_args_and_generalized_unpacking():
49
+ def f(*args, **kwargs):
50
+ return args, kwargs
51
+
52
+ assert m.test_tuple_unpacking(f) == (("positional", 1, 2, 3, 4, 5, 6), {})
53
+ assert m.test_dict_unpacking(f) == (
54
+ ("positional", 1),
55
+ {"key": "value", "a": 1, "b": 2},
56
+ )
57
+ assert m.test_keyword_args(f) == ((), {"x": 10, "y": 20})
58
+ assert m.test_unpacking_and_keywords1(f) == ((1, 2), {"c": 3, "d": 4})
59
+ assert m.test_unpacking_and_keywords2(f) == (
60
+ ("positional", 1, 2, 3, 4, 5),
61
+ {"key": "value", "a": 1, "b": 2, "c": 3, "d": 4, "e": 5},
62
+ )
63
+
64
+ with pytest.raises(TypeError) as excinfo:
65
+ m.test_unpacking_error1(f)
66
+ assert "Got multiple values for keyword argument" in str(excinfo.value)
67
+
68
+ with pytest.raises(TypeError) as excinfo:
69
+ m.test_unpacking_error2(f)
70
+ assert "Got multiple values for keyword argument" in str(excinfo.value)
71
+
72
+ with pytest.raises(RuntimeError) as excinfo:
73
+ m.test_arg_conversion_error1(f)
74
+ assert "Unable to convert call argument" in str(excinfo.value)
75
+
76
+ with pytest.raises(RuntimeError) as excinfo:
77
+ m.test_arg_conversion_error2(f)
78
+ assert "Unable to convert call argument" in str(excinfo.value)
79
+
80
+
81
+ def test_lambda_closure_cleanup():
82
+ m.test_lambda_closure_cleanup()
83
+ cstats = m.payload_cstats()
84
+ assert cstats.alive() == 0
85
+ assert cstats.copy_constructions == 1
86
+ assert cstats.move_constructions >= 1
87
+
88
+
89
+ def test_cpp_callable_cleanup():
90
+ alive_counts = m.test_cpp_callable_cleanup()
91
+ assert alive_counts == [0, 1, 2, 1, 2, 1, 0]
92
+
93
+
94
+ def test_cpp_function_roundtrip():
95
+ """Test if passing a function pointer from C++ -> Python -> C++ yields the original pointer"""
96
+
97
+ assert (
98
+ m.test_dummy_function(m.dummy_function) == "matches dummy_function: eval(1) = 2"
99
+ )
100
+ assert (
101
+ m.test_dummy_function(m.roundtrip(m.dummy_function))
102
+ == "matches dummy_function: eval(1) = 2"
103
+ )
104
+ assert (
105
+ m.test_dummy_function(m.dummy_function_overloaded)
106
+ == "matches dummy_function: eval(1) = 2"
107
+ )
108
+ assert m.roundtrip(None, expect_none=True) is None
109
+ assert (
110
+ m.test_dummy_function(lambda x: x + 2)
111
+ == "can't convert to function pointer: eval(1) = 3"
112
+ )
113
+
114
+ with pytest.raises(TypeError) as excinfo:
115
+ m.test_dummy_function(m.dummy_function2)
116
+ assert "incompatible function arguments" in str(excinfo.value)
117
+
118
+ with pytest.raises(TypeError) as excinfo:
119
+ m.test_dummy_function(lambda x, y: x + y)
120
+ assert any(
121
+ s in str(excinfo.value)
122
+ for s in ("missing 1 required positional argument", "takes exactly 2 arguments")
123
+ )
124
+
125
+
126
+ def test_function_signatures(doc):
127
+ assert doc(m.test_callback3) == "test_callback3(arg0: Callable[[int], int]) -> str"
128
+ assert doc(m.test_callback4) == "test_callback4() -> Callable[[int], int]"
129
+
130
+
131
+ def test_movable_object():
132
+ assert m.callback_with_movable(lambda _: None) is True
133
+
134
+
135
+ @pytest.mark.skipif(
136
+ "env.PYPY",
137
+ reason="PyPy segfaults on here. See discussion on #1413.",
138
+ )
139
+ def test_python_builtins():
140
+ """Test if python builtins like sum() can be used as callbacks"""
141
+ assert m.test_sum_builtin(sum, [1, 2, 3]) == 6
142
+ assert m.test_sum_builtin(sum, []) == 0
143
+
144
+
145
+ def test_async_callbacks():
146
+ # serves as state for async callback
147
+ class Item:
148
+ def __init__(self, value):
149
+ self.value = value
150
+
151
+ res = []
152
+
153
+ # generate stateful lambda that will store result in `res`
154
+ def gen_f():
155
+ s = Item(3)
156
+ return lambda j: res.append(s.value + j)
157
+
158
+ # do some work async
159
+ work = [1, 2, 3, 4]
160
+ m.test_async_callback(gen_f(), work)
161
+ # wait until work is done
162
+ from time import sleep
163
+
164
+ sleep(0.5)
165
+ assert sum(res) == sum(x + 3 for x in work)
166
+
167
+
168
+ def test_async_async_callbacks():
169
+ t = Thread(target=test_async_callbacks)
170
+ t.start()
171
+ t.join()
172
+
173
+
174
+ def test_callback_num_times():
175
+ # Super-simple micro-benchmarking related to PR #2919.
176
+ # Example runtimes (Intel Xeon 2.2GHz, fully optimized):
177
+ # num_millions 1, repeats 2: 0.1 secs
178
+ # num_millions 20, repeats 10: 11.5 secs
179
+ one_million = 1000000
180
+ num_millions = 1 # Try 20 for actual micro-benchmarking.
181
+ repeats = 2 # Try 10.
182
+ rates = []
183
+ for rep in range(repeats):
184
+ t0 = time.time()
185
+ m.callback_num_times(lambda: None, num_millions * one_million)
186
+ td = time.time() - t0
187
+ rate = num_millions / td if td else 0
188
+ rates.append(rate)
189
+ if not rep:
190
+ print()
191
+ print(
192
+ "callback_num_times: {:d} million / {:.3f} seconds = {:.3f} million / second".format(
193
+ num_millions, td, rate
194
+ )
195
+ )
196
+ if len(rates) > 1:
197
+ print("Min Mean Max")
198
+ print(
199
+ "{:6.3f} {:6.3f} {:6.3f}".format(
200
+ min(rates), sum(rates) / len(rates), max(rates)
201
+ )
202
+ )