xcoll 0.5.11__py3-none-any.whl → 0.6.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 (333) hide show
  1. xcoll/__init__.py +5 -18
  2. xcoll/beam_elements/__init__.py +1 -0
  3. xcoll/beam_elements/absorber.py +12 -2
  4. xcoll/beam_elements/base.py +162 -62
  5. xcoll/beam_elements/blowup.py +1 -0
  6. xcoll/beam_elements/elements_src/black_absorber.h +57 -58
  7. xcoll/beam_elements/elements_src/black_crystal.h +49 -50
  8. xcoll/beam_elements/elements_src/everest_block.h +21 -11
  9. xcoll/beam_elements/elements_src/everest_collimator.h +100 -91
  10. xcoll/beam_elements/elements_src/everest_crystal.h +145 -140
  11. xcoll/beam_elements/elements_src/transparent_collimator.h +126 -0
  12. xcoll/beam_elements/elements_src/transparent_crystal.h +118 -0
  13. xcoll/beam_elements/everest.py +16 -5
  14. xcoll/beam_elements/monitor.py +1 -0
  15. xcoll/beam_elements/transparent.py +83 -0
  16. xcoll/colldb.py +15 -6
  17. xcoll/general.py +1 -1
  18. xcoll/headers/particle_states.py +51 -0
  19. xcoll/initial_distribution.py +129 -103
  20. xcoll/interaction_record/interaction_record.py +2 -1
  21. xcoll/interaction_record/interaction_types.py +2 -2
  22. xcoll/line_tools.py +163 -74
  23. xcoll/lossmap.py +519 -127
  24. xcoll/plot.py +109 -0
  25. xcoll/rf_sweep.py +6 -0
  26. xcoll/scattering_routines/engine.py +600 -0
  27. xcoll/scattering_routines/environment.py +297 -0
  28. xcoll/scattering_routines/everest/amorphous.h +95 -71
  29. xcoll/scattering_routines/everest/{channeling.h → channelling.h} +121 -112
  30. xcoll/scattering_routines/everest/constants.h +1 -1
  31. xcoll/scattering_routines/everest/crystal_parameters.h +9 -9
  32. xcoll/scattering_routines/everest/everest.h +8 -3
  33. xcoll/scattering_routines/everest/everest.py +2 -1
  34. xcoll/scattering_routines/everest/ionisation_loss.h +141 -0
  35. xcoll/scattering_routines/everest/jaw.h +19 -24
  36. xcoll/scattering_routines/everest/materials.py +2 -0
  37. xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
  38. xcoll/scattering_routines/everest/nuclear_interaction.h +35 -19
  39. xcoll/scattering_routines/everest/properties.h +4 -73
  40. xcoll/xaux.py +73 -0
  41. {xcoll-0.5.11.dist-info → xcoll-0.6.0.dist-info}/METADATA +5 -5
  42. xcoll-0.6.0.dist-info/RECORD +135 -0
  43. xcoll/_manager.py +0 -22
  44. xcoll/headers/particle_states.h +0 -25
  45. xcoll/install.py +0 -35
  46. xcoll/scattering_routines/geant4/collimasim/.git +0 -1
  47. xcoll/scattering_routines/geant4/collimasim/.gitignore +0 -12
  48. xcoll/scattering_routines/geant4/collimasim/.gitmodules +0 -3
  49. xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +0 -26
  50. xcoll/scattering_routines/geant4/collimasim/README.md +0 -21
  51. xcoll/scattering_routines/geant4/collimasim/docs/Makefile +0 -20
  52. xcoll/scattering_routines/geant4/collimasim/docs/make.bat +0 -35
  53. xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +0 -10
  54. xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +0 -59
  55. xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +0 -26
  56. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +0 -37
  57. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +0 -19
  58. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +0 -65
  59. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +0 -73
  60. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +0 -1
  61. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +0 -9
  62. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +0 -386
  63. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +0 -45
  64. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +0 -8
  65. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +0 -16
  66. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +0 -8
  67. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +0 -3
  68. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +0 -19
  69. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +0 -969
  70. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +0 -84
  71. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +0 -48
  72. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +0 -16
  73. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +0 -103
  74. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +0 -45
  75. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +0 -151
  76. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +0 -3
  77. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +0 -297
  78. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +0 -29
  79. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +0 -6
  80. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +0 -180
  81. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +0 -23
  82. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +0 -192
  83. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +0 -11
  84. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +0 -81
  85. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +0 -93
  86. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +0 -310
  87. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +0 -109
  88. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +0 -43
  89. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +0 -171
  90. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +0 -251
  91. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +0 -305
  92. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +0 -1297
  93. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +0 -262
  94. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +0 -396
  95. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +0 -568
  96. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +0 -337
  97. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +0 -13
  98. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +0 -463
  99. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +0 -286
  100. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +0 -155
  101. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +0 -174
  102. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +0 -308
  103. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +0 -91
  104. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +0 -95
  105. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +0 -2050
  106. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +0 -542
  107. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +0 -8
  108. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +0 -648
  109. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +0 -381
  110. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +0 -343
  111. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +0 -48
  112. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +0 -105
  113. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +0 -72
  114. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
  115. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
  116. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +0 -427
  117. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
  118. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +0 -427
  119. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +0 -130
  120. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +0 -96
  121. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +0 -8
  122. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +0 -548
  123. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +0 -605
  124. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +0 -144
  125. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +0 -1432
  126. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +0 -213
  127. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +0 -2
  128. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +0 -65
  129. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +0 -709
  130. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +0 -1021
  131. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +0 -104
  132. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +0 -346
  133. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +0 -467
  134. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +0 -978
  135. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +0 -55
  136. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +0 -606
  137. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +0 -284
  138. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +0 -163
  139. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +0 -121
  140. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +0 -193
  141. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +0 -275
  142. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +0 -1741
  143. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +0 -163
  144. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +0 -65
  145. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +0 -2497
  146. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +0 -1879
  147. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +0 -103
  148. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +0 -375
  149. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +0 -747
  150. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +0 -88
  151. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +0 -11
  152. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +0 -52
  153. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +0 -12
  154. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +0 -6
  155. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +0 -21
  156. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
  157. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +0 -482
  158. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +0 -63
  159. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +0 -41
  160. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +0 -56
  161. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +0 -155
  162. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +0 -503
  163. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +0 -208
  164. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +0 -275
  165. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +0 -73
  166. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +0 -33
  167. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
  168. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +0 -279
  169. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
  170. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +0 -143
  171. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +0 -85
  172. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +0 -179
  173. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +0 -151
  174. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +0 -91
  175. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +0 -85
  176. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +0 -19
  177. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +0 -12
  178. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +0 -26
  179. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +0 -25
  180. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +0 -216
  181. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +0 -163
  182. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +0 -286
  183. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +0 -536
  184. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +0 -107
  185. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +0 -248
  186. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +0 -227
  187. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +0 -202
  188. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +0 -84
  189. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +0 -210
  190. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +0 -550
  191. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +0 -473
  192. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +0 -84
  193. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +0 -21
  194. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +0 -28
  195. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +0 -39
  196. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +0 -46
  197. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +0 -6
  198. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +0 -41
  199. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +0 -35
  200. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +0 -41
  201. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +0 -10
  202. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +0 -165
  203. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +0 -53
  204. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +0 -238
  205. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +0 -126
  206. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +0 -141
  207. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +0 -117
  208. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +0 -41
  209. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +0 -50
  210. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +0 -69
  211. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +0 -42
  212. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +0 -348
  213. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +0 -771
  214. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +0 -47
  215. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +0 -22
  216. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +0 -23
  217. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +0 -326
  218. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +0 -15
  219. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +0 -148
  220. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +0 -272
  221. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +0 -119
  222. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +0 -51
  223. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +0 -5
  224. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +0 -285
  225. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +0 -12
  226. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +0 -265
  227. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +0 -397
  228. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +0 -520
  229. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +0 -49
  230. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +0 -94
  231. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +0 -125
  232. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +0 -331
  233. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +0 -153
  234. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +0 -284
  235. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +0 -107
  236. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +0 -257
  237. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +0 -412
  238. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +0 -517
  239. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +0 -102
  240. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +0 -92
  241. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +0 -233
  242. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +0 -360
  243. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +0 -472
  244. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +0 -593
  245. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +0 -524
  246. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +0 -441
  247. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +0 -103
  248. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +0 -267
  249. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +0 -73
  250. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +0 -59
  251. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +0 -235
  252. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +0 -146
  253. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +0 -189
  254. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +0 -82
  255. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +0 -560
  256. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +0 -651
  257. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +0 -500
  258. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +0 -253
  259. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +0 -452
  260. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +0 -318
  261. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +0 -342
  262. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +0 -291
  263. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +0 -131
  264. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +0 -318
  265. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +0 -144
  266. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +0 -29
  267. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +0 -66
  268. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +0 -44
  269. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +0 -22
  270. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +0 -9
  271. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +0 -510
  272. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +0 -408
  273. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +0 -140
  274. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +0 -117
  275. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +0 -70
  276. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +0 -86
  277. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +0 -257
  278. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +0 -44
  279. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +0 -23
  280. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +0 -39
  281. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +0 -64
  282. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +0 -402
  283. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +0 -233
  284. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +0 -276
  285. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +0 -214
  286. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +0 -3
  287. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +0 -65
  288. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +0 -41
  289. xcoll/scattering_routines/geant4/collimasim/pyproject.toml +0 -8
  290. xcoll/scattering_routines/geant4/collimasim/setup.py +0 -144
  291. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +0 -403
  292. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +0 -100
  293. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +0 -763
  294. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +0 -118
  295. xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +0 -8
  296. xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +0 -63
  297. xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +0 -142
  298. xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +0 -556
  299. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +0 -6
  300. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +0 -24
  301. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +0 -1
  302. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +0 -1
  303. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +0 -1
  304. xcoll/scattering_routines/geant4/collimasim/tests/README.md +0 -25
  305. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +0 -25
  306. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +0 -18
  307. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +0 -68
  308. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +0 -15
  309. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +0 -110
  310. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +0 -7
  311. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +0 -3
  312. xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +0 -54
  313. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +0 -3
  314. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +0 -3
  315. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +0 -5
  316. xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +0 -51
  317. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +0 -65
  318. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +0 -59
  319. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +0 -102
  320. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +0 -75
  321. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +0 -74
  322. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +0 -84
  323. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +0 -159
  324. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +0 -99
  325. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +0 -78
  326. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +0 -88
  327. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +0 -80
  328. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +0 -97
  329. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +0 -96
  330. xcoll-0.5.11.dist-info/RECORD +0 -413
  331. {xcoll-0.5.11.dist-info → xcoll-0.6.0.dist-info}/LICENSE +0 -0
  332. {xcoll-0.5.11.dist-info → xcoll-0.6.0.dist-info}/NOTICE +0 -0
  333. {xcoll-0.5.11.dist-info → xcoll-0.6.0.dist-info}/WHEEL +0 -0
@@ -1,248 +0,0 @@
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"
@@ -1,227 +0,0 @@
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
- }
@@ -1,202 +0,0 @@
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
- )