xcoll 0.5.12__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 +121 -91
  20. xcoll/interaction_record/interaction_record.py +2 -1
  21. xcoll/interaction_record/interaction_types.py +2 -2
  22. xcoll/line_tools.py +163 -73
  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 +414 -217
  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 +3 -72
  40. xcoll/xaux.py +65 -109
  41. {xcoll-0.5.12.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.12.dist-info/RECORD +0 -415
  331. {xcoll-0.5.12.dist-info → xcoll-0.6.0.dist-info}/LICENSE +0 -0
  332. {xcoll-0.5.12.dist-info → xcoll-0.6.0.dist-info}/NOTICE +0 -0
  333. {xcoll-0.5.12.dist-info → xcoll-0.6.0.dist-info}/WHEEL +0 -0
@@ -1,568 +0,0 @@
1
- Functions
2
- #########
3
-
4
- Before proceeding with this section, make sure that you are already familiar
5
- with the basics of binding functions and classes, as explained in :doc:`/basics`
6
- and :doc:`/classes`. The following guide is applicable to both free and member
7
- functions, i.e. *methods* in Python.
8
-
9
- .. _return_value_policies:
10
-
11
- Return value policies
12
- =====================
13
-
14
- Python and C++ use fundamentally different ways of managing the memory and
15
- lifetime of objects managed by them. This can lead to issues when creating
16
- bindings for functions that return a non-trivial type. Just by looking at the
17
- type information, it is not clear whether Python should take charge of the
18
- returned value and eventually free its resources, or if this is handled on the
19
- C++ side. For this reason, pybind11 provides a several *return value policy*
20
- annotations that can be passed to the :func:`module_::def` and
21
- :func:`class_::def` functions. The default policy is
22
- :enum:`return_value_policy::automatic`.
23
-
24
- Return value policies are tricky, and it's very important to get them right.
25
- Just to illustrate what can go wrong, consider the following simple example:
26
-
27
- .. code-block:: cpp
28
-
29
- /* Function declaration */
30
- Data *get_data() { return _data; /* (pointer to a static data structure) */ }
31
- ...
32
-
33
- /* Binding code */
34
- m.def("get_data", &get_data); // <-- KABOOM, will cause crash when called from Python
35
-
36
- What's going on here? When ``get_data()`` is called from Python, the return
37
- value (a native C++ type) must be wrapped to turn it into a usable Python type.
38
- In this case, the default return value policy (:enum:`return_value_policy::automatic`)
39
- causes pybind11 to assume ownership of the static ``_data`` instance.
40
-
41
- When Python's garbage collector eventually deletes the Python
42
- wrapper, pybind11 will also attempt to delete the C++ instance (via ``operator
43
- delete()``) due to the implied ownership. At this point, the entire application
44
- will come crashing down, though errors could also be more subtle and involve
45
- silent data corruption.
46
-
47
- In the above example, the policy :enum:`return_value_policy::reference` should have
48
- been specified so that the global data instance is only *referenced* without any
49
- implied transfer of ownership, i.e.:
50
-
51
- .. code-block:: cpp
52
-
53
- m.def("get_data", &get_data, py::return_value_policy::reference);
54
-
55
- On the other hand, this is not the right policy for many other situations,
56
- where ignoring ownership could lead to resource leaks.
57
- As a developer using pybind11, it's important to be familiar with the different
58
- return value policies, including which situation calls for which one of them.
59
- The following table provides an overview of available policies:
60
-
61
- .. tabularcolumns:: |p{0.5\textwidth}|p{0.45\textwidth}|
62
-
63
- +--------------------------------------------------+----------------------------------------------------------------------------+
64
- | Return value policy | Description |
65
- +==================================================+============================================================================+
66
- | :enum:`return_value_policy::take_ownership` | Reference an existing object (i.e. do not create a new copy) and take |
67
- | | ownership. Python will call the destructor and delete operator when the |
68
- | | object's reference count reaches zero. Undefined behavior ensues when the |
69
- | | C++ side does the same, or when the data was not dynamically allocated. |
70
- +--------------------------------------------------+----------------------------------------------------------------------------+
71
- | :enum:`return_value_policy::copy` | Create a new copy of the returned object, which will be owned by Python. |
72
- | | This policy is comparably safe because the lifetimes of the two instances |
73
- | | are decoupled. |
74
- +--------------------------------------------------+----------------------------------------------------------------------------+
75
- | :enum:`return_value_policy::move` | Use ``std::move`` to move the return value contents into a new instance |
76
- | | that will be owned by Python. This policy is comparably safe because the |
77
- | | lifetimes of the two instances (move source and destination) are decoupled.|
78
- +--------------------------------------------------+----------------------------------------------------------------------------+
79
- | :enum:`return_value_policy::reference` | Reference an existing object, but do not take ownership. The C++ side is |
80
- | | responsible for managing the object's lifetime and deallocating it when |
81
- | | it is no longer used. Warning: undefined behavior will ensue when the C++ |
82
- | | side deletes an object that is still referenced and used by Python. |
83
- +--------------------------------------------------+----------------------------------------------------------------------------+
84
- | :enum:`return_value_policy::reference_internal` | Indicates that the lifetime of the return value is tied to the lifetime |
85
- | | of a parent object, namely the implicit ``this``, or ``self`` argument of |
86
- | | the called method or property. Internally, this policy works just like |
87
- | | :enum:`return_value_policy::reference` but additionally applies a |
88
- | | ``keep_alive<0, 1>`` *call policy* (described in the next section) that |
89
- | | prevents the parent object from being garbage collected as long as the |
90
- | | return value is referenced by Python. This is the default policy for |
91
- | | property getters created via ``def_property``, ``def_readwrite``, etc. |
92
- +--------------------------------------------------+----------------------------------------------------------------------------+
93
- | :enum:`return_value_policy::automatic` | This policy falls back to the policy |
94
- | | :enum:`return_value_policy::take_ownership` when the return value is a |
95
- | | pointer. Otherwise, it uses :enum:`return_value_policy::move` or |
96
- | | :enum:`return_value_policy::copy` for rvalue and lvalue references, |
97
- | | respectively. See above for a description of what all of these different |
98
- | | policies do. This is the default policy for ``py::class_``-wrapped types. |
99
- +--------------------------------------------------+----------------------------------------------------------------------------+
100
- | :enum:`return_value_policy::automatic_reference` | As above, but use policy :enum:`return_value_policy::reference` when the |
101
- | | return value is a pointer. This is the default conversion policy for |
102
- | | function arguments when calling Python functions manually from C++ code |
103
- | | (i.e. via ``handle::operator()``) and the casters in ``pybind11/stl.h``. |
104
- | | You probably won't need to use this explicitly. |
105
- +--------------------------------------------------+----------------------------------------------------------------------------+
106
-
107
- Return value policies can also be applied to properties:
108
-
109
- .. code-block:: cpp
110
-
111
- class_<MyClass>(m, "MyClass")
112
- .def_property("data", &MyClass::getData, &MyClass::setData,
113
- py::return_value_policy::copy);
114
-
115
- Technically, the code above applies the policy to both the getter and the
116
- setter function, however, the setter doesn't really care about *return*
117
- value policies which makes this a convenient terse syntax. Alternatively,
118
- targeted arguments can be passed through the :class:`cpp_function` constructor:
119
-
120
- .. code-block:: cpp
121
-
122
- class_<MyClass>(m, "MyClass")
123
- .def_property("data"
124
- py::cpp_function(&MyClass::getData, py::return_value_policy::copy),
125
- py::cpp_function(&MyClass::setData)
126
- );
127
-
128
- .. warning::
129
-
130
- Code with invalid return value policies might access uninitialized memory or
131
- free data structures multiple times, which can lead to hard-to-debug
132
- non-determinism and segmentation faults, hence it is worth spending the
133
- time to understand all the different options in the table above.
134
-
135
- .. note::
136
-
137
- One important aspect of the above policies is that they only apply to
138
- instances which pybind11 has *not* seen before, in which case the policy
139
- clarifies essential questions about the return value's lifetime and
140
- ownership. When pybind11 knows the instance already (as identified by its
141
- type and address in memory), it will return the existing Python object
142
- wrapper rather than creating a new copy.
143
-
144
- .. note::
145
-
146
- The next section on :ref:`call_policies` discusses *call policies* that can be
147
- specified *in addition* to a return value policy from the list above. Call
148
- policies indicate reference relationships that can involve both return values
149
- and parameters of functions.
150
-
151
- .. note::
152
-
153
- As an alternative to elaborate call policies and lifetime management logic,
154
- consider using smart pointers (see the section on :ref:`smart_pointers` for
155
- details). Smart pointers can tell whether an object is still referenced from
156
- C++ or Python, which generally eliminates the kinds of inconsistencies that
157
- can lead to crashes or undefined behavior. For functions returning smart
158
- pointers, it is not necessary to specify a return value policy.
159
-
160
- .. _call_policies:
161
-
162
- Additional call policies
163
- ========================
164
-
165
- In addition to the above return value policies, further *call policies* can be
166
- specified to indicate dependencies between parameters or ensure a certain state
167
- for the function call.
168
-
169
- Keep alive
170
- ----------
171
-
172
- In general, this policy is required when the C++ object is any kind of container
173
- and another object is being added to the container. ``keep_alive<Nurse, Patient>``
174
- indicates that the argument with index ``Patient`` should be kept alive at least
175
- until the argument with index ``Nurse`` is freed by the garbage collector. Argument
176
- indices start at one, while zero refers to the return value. For methods, index
177
- ``1`` refers to the implicit ``this`` pointer, while regular arguments begin at
178
- index ``2``. Arbitrarily many call policies can be specified. When a ``Nurse``
179
- with value ``None`` is detected at runtime, the call policy does nothing.
180
-
181
- When the nurse is not a pybind11-registered type, the implementation internally
182
- relies on the ability to create a *weak reference* to the nurse object. When
183
- the nurse object is not a pybind11-registered type and does not support weak
184
- references, an exception will be thrown.
185
-
186
- If you use an incorrect argument index, you will get a ``RuntimeError`` saying
187
- ``Could not activate keep_alive!``. You should review the indices you're using.
188
-
189
- Consider the following example: here, the binding code for a list append
190
- operation ties the lifetime of the newly added element to the underlying
191
- container:
192
-
193
- .. code-block:: cpp
194
-
195
- py::class_<List>(m, "List")
196
- .def("append", &List::append, py::keep_alive<1, 2>());
197
-
198
- For consistency, the argument indexing is identical for constructors. Index
199
- ``1`` still refers to the implicit ``this`` pointer, i.e. the object which is
200
- being constructed. Index ``0`` refers to the return type which is presumed to
201
- be ``void`` when a constructor is viewed like a function. The following example
202
- ties the lifetime of the constructor element to the constructed object:
203
-
204
- .. code-block:: cpp
205
-
206
- py::class_<Nurse>(m, "Nurse")
207
- .def(py::init<Patient &>(), py::keep_alive<1, 2>());
208
-
209
- .. note::
210
-
211
- ``keep_alive`` is analogous to the ``with_custodian_and_ward`` (if Nurse,
212
- Patient != 0) and ``with_custodian_and_ward_postcall`` (if Nurse/Patient ==
213
- 0) policies from Boost.Python.
214
-
215
- Call guard
216
- ----------
217
-
218
- The ``call_guard<T>`` policy allows any scope guard type ``T`` to be placed
219
- around the function call. For example, this definition:
220
-
221
- .. code-block:: cpp
222
-
223
- m.def("foo", foo, py::call_guard<T>());
224
-
225
- is equivalent to the following pseudocode:
226
-
227
- .. code-block:: cpp
228
-
229
- m.def("foo", [](args...) {
230
- T scope_guard;
231
- return foo(args...); // forwarded arguments
232
- });
233
-
234
- The only requirement is that ``T`` is default-constructible, but otherwise any
235
- scope guard will work. This is very useful in combination with ``gil_scoped_release``.
236
- See :ref:`gil`.
237
-
238
- Multiple guards can also be specified as ``py::call_guard<T1, T2, T3...>``. The
239
- constructor order is left to right and destruction happens in reverse.
240
-
241
- .. seealso::
242
-
243
- The file :file:`tests/test_call_policies.cpp` contains a complete example
244
- that demonstrates using `keep_alive` and `call_guard` in more detail.
245
-
246
- .. _python_objects_as_args:
247
-
248
- Python objects as arguments
249
- ===========================
250
-
251
- pybind11 exposes all major Python types using thin C++ wrapper classes. These
252
- wrapper classes can also be used as parameters of functions in bindings, which
253
- makes it possible to directly work with native Python types on the C++ side.
254
- For instance, the following statement iterates over a Python ``dict``:
255
-
256
- .. code-block:: cpp
257
-
258
- void print_dict(const py::dict& dict) {
259
- /* Easily interact with Python types */
260
- for (auto item : dict)
261
- std::cout << "key=" << std::string(py::str(item.first)) << ", "
262
- << "value=" << std::string(py::str(item.second)) << std::endl;
263
- }
264
-
265
- It can be exported:
266
-
267
- .. code-block:: cpp
268
-
269
- m.def("print_dict", &print_dict);
270
-
271
- And used in Python as usual:
272
-
273
- .. code-block:: pycon
274
-
275
- >>> print_dict({"foo": 123, "bar": "hello"})
276
- key=foo, value=123
277
- key=bar, value=hello
278
-
279
- For more information on using Python objects in C++, see :doc:`/advanced/pycpp/index`.
280
-
281
- Accepting \*args and \*\*kwargs
282
- ===============================
283
-
284
- Python provides a useful mechanism to define functions that accept arbitrary
285
- numbers of arguments and keyword arguments:
286
-
287
- .. code-block:: python
288
-
289
- def generic(*args, **kwargs):
290
- ... # do something with args and kwargs
291
-
292
- Such functions can also be created using pybind11:
293
-
294
- .. code-block:: cpp
295
-
296
- void generic(py::args args, const py::kwargs& kwargs) {
297
- /// .. do something with args
298
- if (kwargs)
299
- /// .. do something with kwargs
300
- }
301
-
302
- /// Binding code
303
- m.def("generic", &generic);
304
-
305
- The class ``py::args`` derives from ``py::tuple`` and ``py::kwargs`` derives
306
- from ``py::dict``.
307
-
308
- You may also use just one or the other, and may combine these with other
309
- arguments as long as the ``py::args`` and ``py::kwargs`` arguments are the last
310
- arguments accepted by the function.
311
-
312
- Please refer to the other examples for details on how to iterate over these,
313
- and on how to cast their entries into C++ objects. A demonstration is also
314
- available in ``tests/test_kwargs_and_defaults.cpp``.
315
-
316
- .. note::
317
-
318
- When combining \*args or \*\*kwargs with :ref:`keyword_args` you should
319
- *not* include ``py::arg`` tags for the ``py::args`` and ``py::kwargs``
320
- arguments.
321
-
322
- Default arguments revisited
323
- ===========================
324
-
325
- The section on :ref:`default_args` previously discussed basic usage of default
326
- arguments using pybind11. One noteworthy aspect of their implementation is that
327
- default arguments are converted to Python objects right at declaration time.
328
- Consider the following example:
329
-
330
- .. code-block:: cpp
331
-
332
- py::class_<MyClass>("MyClass")
333
- .def("myFunction", py::arg("arg") = SomeType(123));
334
-
335
- In this case, pybind11 must already be set up to deal with values of the type
336
- ``SomeType`` (via a prior instantiation of ``py::class_<SomeType>``), or an
337
- exception will be thrown.
338
-
339
- Another aspect worth highlighting is that the "preview" of the default argument
340
- in the function signature is generated using the object's ``__repr__`` method.
341
- If not available, the signature may not be very helpful, e.g.:
342
-
343
- .. code-block:: pycon
344
-
345
- FUNCTIONS
346
- ...
347
- | myFunction(...)
348
- | Signature : (MyClass, arg : SomeType = <SomeType object at 0x101b7b080>) -> NoneType
349
- ...
350
-
351
- The first way of addressing this is by defining ``SomeType.__repr__``.
352
- Alternatively, it is possible to specify the human-readable preview of the
353
- default argument manually using the ``arg_v`` notation:
354
-
355
- .. code-block:: cpp
356
-
357
- py::class_<MyClass>("MyClass")
358
- .def("myFunction", py::arg_v("arg", SomeType(123), "SomeType(123)"));
359
-
360
- Sometimes it may be necessary to pass a null pointer value as a default
361
- argument. In this case, remember to cast it to the underlying type in question,
362
- like so:
363
-
364
- .. code-block:: cpp
365
-
366
- py::class_<MyClass>("MyClass")
367
- .def("myFunction", py::arg("arg") = static_cast<SomeType *>(nullptr));
368
-
369
- Keyword-only arguments
370
- ======================
371
-
372
- Python 3 introduced keyword-only arguments by specifying an unnamed ``*``
373
- argument in a function definition:
374
-
375
- .. code-block:: python
376
-
377
- def f(a, *, b): # a can be positional or via keyword; b must be via keyword
378
- pass
379
-
380
-
381
- f(a=1, b=2) # good
382
- f(b=2, a=1) # good
383
- f(1, b=2) # good
384
- f(1, 2) # TypeError: f() takes 1 positional argument but 2 were given
385
-
386
- Pybind11 provides a ``py::kw_only`` object that allows you to implement
387
- the same behaviour by specifying the object between positional and keyword-only
388
- argument annotations when registering the function:
389
-
390
- .. code-block:: cpp
391
-
392
- m.def("f", [](int a, int b) { /* ... */ },
393
- py::arg("a"), py::kw_only(), py::arg("b"));
394
-
395
- Note that you currently cannot combine this with a ``py::args`` argument. This
396
- feature does *not* require Python 3 to work.
397
-
398
- .. versionadded:: 2.6
399
-
400
- Positional-only arguments
401
- =========================
402
-
403
- Python 3.8 introduced a new positional-only argument syntax, using ``/`` in the
404
- function definition (note that this has been a convention for CPython
405
- positional arguments, such as in ``pow()``, since Python 2). You can
406
- do the same thing in any version of Python using ``py::pos_only()``:
407
-
408
- .. code-block:: cpp
409
-
410
- m.def("f", [](int a, int b) { /* ... */ },
411
- py::arg("a"), py::pos_only(), py::arg("b"));
412
-
413
- You now cannot give argument ``a`` by keyword. This can be combined with
414
- keyword-only arguments, as well.
415
-
416
- .. versionadded:: 2.6
417
-
418
- .. _nonconverting_arguments:
419
-
420
- Non-converting arguments
421
- ========================
422
-
423
- Certain argument types may support conversion from one type to another. Some
424
- examples of conversions are:
425
-
426
- * :ref:`implicit_conversions` declared using ``py::implicitly_convertible<A,B>()``
427
- * Calling a method accepting a double with an integer argument
428
- * Calling a ``std::complex<float>`` argument with a non-complex python type
429
- (for example, with a float). (Requires the optional ``pybind11/complex.h``
430
- header).
431
- * Calling a function taking an Eigen matrix reference with a numpy array of the
432
- wrong type or of an incompatible data layout. (Requires the optional
433
- ``pybind11/eigen.h`` header).
434
-
435
- This behaviour is sometimes undesirable: the binding code may prefer to raise
436
- an error rather than convert the argument. This behaviour can be obtained
437
- through ``py::arg`` by calling the ``.noconvert()`` method of the ``py::arg``
438
- object, such as:
439
-
440
- .. code-block:: cpp
441
-
442
- m.def("floats_only", [](double f) { return 0.5 * f; }, py::arg("f").noconvert());
443
- m.def("floats_preferred", [](double f) { return 0.5 * f; }, py::arg("f"));
444
-
445
- Attempting the call the second function (the one without ``.noconvert()``) with
446
- an integer will succeed, but attempting to call the ``.noconvert()`` version
447
- will fail with a ``TypeError``:
448
-
449
- .. code-block:: pycon
450
-
451
- >>> floats_preferred(4)
452
- 2.0
453
- >>> floats_only(4)
454
- Traceback (most recent call last):
455
- File "<stdin>", line 1, in <module>
456
- TypeError: floats_only(): incompatible function arguments. The following argument types are supported:
457
- 1. (f: float) -> float
458
-
459
- Invoked with: 4
460
-
461
- You may, of course, combine this with the :var:`_a` shorthand notation (see
462
- :ref:`keyword_args`) and/or :ref:`default_args`. It is also permitted to omit
463
- the argument name by using the ``py::arg()`` constructor without an argument
464
- name, i.e. by specifying ``py::arg().noconvert()``.
465
-
466
- .. note::
467
-
468
- When specifying ``py::arg`` options it is necessary to provide the same
469
- number of options as the bound function has arguments. Thus if you want to
470
- enable no-convert behaviour for just one of several arguments, you will
471
- need to specify a ``py::arg()`` annotation for each argument with the
472
- no-convert argument modified to ``py::arg().noconvert()``.
473
-
474
- .. _none_arguments:
475
-
476
- Allow/Prohibiting None arguments
477
- ================================
478
-
479
- When a C++ type registered with :class:`py::class_` is passed as an argument to
480
- a function taking the instance as pointer or shared holder (e.g. ``shared_ptr``
481
- or a custom, copyable holder as described in :ref:`smart_pointers`), pybind
482
- allows ``None`` to be passed from Python which results in calling the C++
483
- function with ``nullptr`` (or an empty holder) for the argument.
484
-
485
- To explicitly enable or disable this behaviour, using the
486
- ``.none`` method of the :class:`py::arg` object:
487
-
488
- .. code-block:: cpp
489
-
490
- py::class_<Dog>(m, "Dog").def(py::init<>());
491
- py::class_<Cat>(m, "Cat").def(py::init<>());
492
- m.def("bark", [](Dog *dog) -> std::string {
493
- if (dog) return "woof!"; /* Called with a Dog instance */
494
- else return "(no dog)"; /* Called with None, dog == nullptr */
495
- }, py::arg("dog").none(true));
496
- m.def("meow", [](Cat *cat) -> std::string {
497
- // Can't be called with None argument
498
- return "meow";
499
- }, py::arg("cat").none(false));
500
-
501
- With the above, the Python call ``bark(None)`` will return the string ``"(no
502
- dog)"``, while attempting to call ``meow(None)`` will raise a ``TypeError``:
503
-
504
- .. code-block:: pycon
505
-
506
- >>> from animals import Dog, Cat, bark, meow
507
- >>> bark(Dog())
508
- 'woof!'
509
- >>> meow(Cat())
510
- 'meow'
511
- >>> bark(None)
512
- '(no dog)'
513
- >>> meow(None)
514
- Traceback (most recent call last):
515
- File "<stdin>", line 1, in <module>
516
- TypeError: meow(): incompatible function arguments. The following argument types are supported:
517
- 1. (cat: animals.Cat) -> str
518
-
519
- Invoked with: None
520
-
521
- The default behaviour when the tag is unspecified is to allow ``None``.
522
-
523
- .. note::
524
-
525
- Even when ``.none(true)`` is specified for an argument, ``None`` will be converted to a
526
- ``nullptr`` *only* for custom and :ref:`opaque <opaque>` types. Pointers to built-in types
527
- (``double *``, ``int *``, ...) and STL types (``std::vector<T> *``, ...; if ``pybind11/stl.h``
528
- is included) are copied when converted to C++ (see :doc:`/advanced/cast/overview`) and will
529
- not allow ``None`` as argument. To pass optional argument of these copied types consider
530
- using ``std::optional<T>``
531
-
532
- .. _overload_resolution:
533
-
534
- Overload resolution order
535
- =========================
536
-
537
- When a function or method with multiple overloads is called from Python,
538
- pybind11 determines which overload to call in two passes. The first pass
539
- attempts to call each overload without allowing argument conversion (as if
540
- every argument had been specified as ``py::arg().noconvert()`` as described
541
- above).
542
-
543
- If no overload succeeds in the no-conversion first pass, a second pass is
544
- attempted in which argument conversion is allowed (except where prohibited via
545
- an explicit ``py::arg().noconvert()`` attribute in the function definition).
546
-
547
- If the second pass also fails a ``TypeError`` is raised.
548
-
549
- Within each pass, overloads are tried in the order they were registered with
550
- pybind11. If the ``py::prepend()`` tag is added to the definition, a function
551
- can be placed at the beginning of the overload sequence instead, allowing user
552
- overloads to proceed built in functions.
553
-
554
- What this means in practice is that pybind11 will prefer any overload that does
555
- not require conversion of arguments to an overload that does, but otherwise
556
- prefers earlier-defined overloads to later-defined ones.
557
-
558
- .. note::
559
-
560
- pybind11 does *not* further prioritize based on the number/pattern of
561
- overloaded arguments. That is, pybind11 does not prioritize a function
562
- requiring one conversion over one requiring three, but only prioritizes
563
- overloads requiring no conversion at all to overloads that require
564
- conversion of at least one argument.
565
-
566
- .. versionadded:: 2.6
567
-
568
- The ``py::prepend()`` tag.