xcoll 0.5.12__py3-none-any.whl → 0.6.1__py3-none-any.whl

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

Potentially problematic release.


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

Files changed (336) hide show
  1. xcoll/__init__.py +5 -18
  2. xcoll/__init__.py.orig +26 -0
  3. xcoll/beam_elements/__init__.py +1 -0
  4. xcoll/beam_elements/absorber.py +12 -2
  5. xcoll/beam_elements/base.py +162 -62
  6. xcoll/beam_elements/blowup.py +1 -0
  7. xcoll/beam_elements/elements_src/black_absorber.h +57 -58
  8. xcoll/beam_elements/elements_src/black_crystal.h +49 -50
  9. xcoll/beam_elements/elements_src/everest_block.h +21 -11
  10. xcoll/beam_elements/elements_src/everest_collimator.h +100 -91
  11. xcoll/beam_elements/elements_src/everest_crystal.h +145 -140
  12. xcoll/beam_elements/elements_src/transparent_collimator.h +126 -0
  13. xcoll/beam_elements/elements_src/transparent_crystal.h +118 -0
  14. xcoll/beam_elements/everest.py +16 -5
  15. xcoll/beam_elements/monitor.py +1 -0
  16. xcoll/beam_elements/transparent.py +83 -0
  17. xcoll/colldb.py +15 -6
  18. xcoll/general.py +1 -1
  19. xcoll/general.py.orig +20 -0
  20. xcoll/headers/particle_states.py +51 -0
  21. xcoll/initial_distribution.py +121 -91
  22. xcoll/initial_distribution.py.orig +256 -0
  23. xcoll/interaction_record/interaction_record.py +2 -1
  24. xcoll/interaction_record/interaction_types.py +2 -2
  25. xcoll/line_tools.py +163 -73
  26. xcoll/lossmap.py +519 -127
  27. xcoll/plot.py +109 -0
  28. xcoll/rf_sweep.py +6 -0
  29. xcoll/scattering_routines/engine.py +414 -217
  30. xcoll/scattering_routines/environment.py +297 -0
  31. xcoll/scattering_routines/everest/amorphous.h +95 -71
  32. xcoll/scattering_routines/everest/{channeling.h → channelling.h} +121 -112
  33. xcoll/scattering_routines/everest/constants.h +1 -1
  34. xcoll/scattering_routines/everest/crystal_parameters.h +9 -9
  35. xcoll/scattering_routines/everest/everest.h +8 -3
  36. xcoll/scattering_routines/everest/everest.py +2 -1
  37. xcoll/scattering_routines/everest/ionisation_loss.h +141 -0
  38. xcoll/scattering_routines/everest/jaw.h +19 -24
  39. xcoll/scattering_routines/everest/materials.py +2 -0
  40. xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
  41. xcoll/scattering_routines/everest/nuclear_interaction.h +35 -19
  42. xcoll/scattering_routines/everest/properties.h +3 -72
  43. xcoll/xaux.py +65 -109
  44. {xcoll-0.5.12.dist-info → xcoll-0.6.1.dist-info}/METADATA +5 -5
  45. xcoll-0.6.1.dist-info/RECORD +138 -0
  46. xcoll/_manager.py +0 -22
  47. xcoll/headers/particle_states.h +0 -25
  48. xcoll/install.py +0 -35
  49. xcoll/scattering_routines/geant4/collimasim/.git +0 -1
  50. xcoll/scattering_routines/geant4/collimasim/.gitignore +0 -12
  51. xcoll/scattering_routines/geant4/collimasim/.gitmodules +0 -3
  52. xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +0 -26
  53. xcoll/scattering_routines/geant4/collimasim/README.md +0 -21
  54. xcoll/scattering_routines/geant4/collimasim/docs/Makefile +0 -20
  55. xcoll/scattering_routines/geant4/collimasim/docs/make.bat +0 -35
  56. xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +0 -10
  57. xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +0 -59
  58. xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +0 -26
  59. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +0 -37
  60. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +0 -19
  61. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +0 -65
  62. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +0 -73
  63. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +0 -1
  64. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +0 -9
  65. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +0 -386
  66. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +0 -45
  67. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +0 -8
  68. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +0 -16
  69. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +0 -8
  70. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +0 -3
  71. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +0 -19
  72. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +0 -969
  73. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +0 -84
  74. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +0 -48
  75. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +0 -16
  76. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +0 -103
  77. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +0 -45
  78. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +0 -151
  79. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +0 -3
  80. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +0 -297
  81. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +0 -29
  82. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +0 -6
  83. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +0 -180
  84. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +0 -23
  85. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +0 -192
  86. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +0 -11
  87. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +0 -81
  88. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +0 -93
  89. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +0 -310
  90. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +0 -109
  91. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +0 -43
  92. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +0 -171
  93. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +0 -251
  94. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +0 -305
  95. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +0 -1297
  96. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +0 -262
  97. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +0 -396
  98. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +0 -568
  99. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +0 -337
  100. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +0 -13
  101. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +0 -463
  102. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +0 -286
  103. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +0 -155
  104. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +0 -174
  105. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +0 -308
  106. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +0 -91
  107. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +0 -95
  108. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +0 -2050
  109. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +0 -542
  110. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +0 -8
  111. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +0 -648
  112. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +0 -381
  113. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +0 -343
  114. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +0 -48
  115. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +0 -105
  116. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +0 -72
  117. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
  118. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
  119. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +0 -427
  120. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
  121. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +0 -427
  122. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +0 -130
  123. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +0 -96
  124. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +0 -8
  125. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +0 -548
  126. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +0 -605
  127. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +0 -144
  128. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +0 -1432
  129. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +0 -213
  130. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +0 -2
  131. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +0 -65
  132. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +0 -709
  133. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +0 -1021
  134. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +0 -104
  135. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +0 -346
  136. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +0 -467
  137. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +0 -978
  138. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +0 -55
  139. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +0 -606
  140. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +0 -284
  141. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +0 -163
  142. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +0 -121
  143. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +0 -193
  144. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +0 -275
  145. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +0 -1741
  146. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +0 -163
  147. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +0 -65
  148. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +0 -2497
  149. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +0 -1879
  150. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +0 -103
  151. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +0 -375
  152. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +0 -747
  153. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +0 -88
  154. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +0 -11
  155. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +0 -52
  156. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +0 -12
  157. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +0 -6
  158. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +0 -21
  159. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
  160. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +0 -482
  161. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +0 -63
  162. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +0 -41
  163. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +0 -56
  164. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +0 -155
  165. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +0 -503
  166. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +0 -208
  167. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +0 -275
  168. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +0 -73
  169. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +0 -33
  170. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
  171. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +0 -279
  172. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
  173. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +0 -143
  174. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +0 -85
  175. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +0 -179
  176. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +0 -151
  177. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +0 -91
  178. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +0 -85
  179. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +0 -19
  180. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +0 -12
  181. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +0 -26
  182. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +0 -25
  183. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +0 -216
  184. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +0 -163
  185. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +0 -286
  186. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +0 -536
  187. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +0 -107
  188. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +0 -248
  189. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +0 -227
  190. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +0 -202
  191. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +0 -84
  192. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +0 -210
  193. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +0 -550
  194. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +0 -473
  195. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +0 -84
  196. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +0 -21
  197. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +0 -28
  198. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +0 -39
  199. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +0 -46
  200. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +0 -6
  201. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +0 -41
  202. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +0 -35
  203. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +0 -41
  204. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +0 -10
  205. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +0 -165
  206. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +0 -53
  207. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +0 -238
  208. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +0 -126
  209. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +0 -141
  210. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +0 -117
  211. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +0 -41
  212. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +0 -50
  213. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +0 -69
  214. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +0 -42
  215. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +0 -348
  216. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +0 -771
  217. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +0 -47
  218. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +0 -22
  219. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +0 -23
  220. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +0 -326
  221. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +0 -15
  222. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +0 -148
  223. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +0 -272
  224. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +0 -119
  225. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +0 -51
  226. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +0 -5
  227. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +0 -285
  228. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +0 -12
  229. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +0 -265
  230. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +0 -397
  231. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +0 -520
  232. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +0 -49
  233. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +0 -94
  234. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +0 -125
  235. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +0 -331
  236. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +0 -153
  237. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +0 -284
  238. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +0 -107
  239. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +0 -257
  240. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +0 -412
  241. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +0 -517
  242. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +0 -102
  243. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +0 -92
  244. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +0 -233
  245. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +0 -360
  246. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +0 -472
  247. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +0 -593
  248. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +0 -524
  249. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +0 -441
  250. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +0 -103
  251. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +0 -267
  252. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +0 -73
  253. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +0 -59
  254. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +0 -235
  255. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +0 -146
  256. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +0 -189
  257. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +0 -82
  258. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +0 -560
  259. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +0 -651
  260. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +0 -500
  261. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +0 -253
  262. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +0 -452
  263. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +0 -318
  264. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +0 -342
  265. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +0 -291
  266. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +0 -131
  267. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +0 -318
  268. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +0 -144
  269. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +0 -29
  270. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +0 -66
  271. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +0 -44
  272. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +0 -22
  273. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +0 -9
  274. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +0 -510
  275. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +0 -408
  276. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +0 -140
  277. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +0 -117
  278. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +0 -70
  279. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +0 -86
  280. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +0 -257
  281. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +0 -44
  282. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +0 -23
  283. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +0 -39
  284. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +0 -64
  285. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +0 -402
  286. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +0 -233
  287. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +0 -276
  288. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +0 -214
  289. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +0 -3
  290. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +0 -65
  291. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +0 -41
  292. xcoll/scattering_routines/geant4/collimasim/pyproject.toml +0 -8
  293. xcoll/scattering_routines/geant4/collimasim/setup.py +0 -144
  294. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +0 -403
  295. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +0 -100
  296. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +0 -763
  297. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +0 -118
  298. xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +0 -8
  299. xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +0 -63
  300. xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +0 -142
  301. xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +0 -556
  302. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +0 -6
  303. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +0 -24
  304. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +0 -1
  305. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +0 -1
  306. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +0 -1
  307. xcoll/scattering_routines/geant4/collimasim/tests/README.md +0 -25
  308. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +0 -25
  309. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +0 -18
  310. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +0 -68
  311. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +0 -15
  312. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +0 -110
  313. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +0 -7
  314. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +0 -3
  315. xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +0 -54
  316. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +0 -3
  317. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +0 -3
  318. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +0 -5
  319. xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +0 -51
  320. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +0 -65
  321. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +0 -59
  322. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +0 -102
  323. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +0 -75
  324. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +0 -74
  325. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +0 -84
  326. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +0 -159
  327. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +0 -99
  328. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +0 -78
  329. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +0 -88
  330. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +0 -80
  331. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +0 -97
  332. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +0 -96
  333. xcoll-0.5.12.dist-info/RECORD +0 -415
  334. {xcoll-0.5.12.dist-info → xcoll-0.6.1.dist-info}/LICENSE +0 -0
  335. {xcoll-0.5.12.dist-info → xcoll-0.6.1.dist-info}/NOTICE +0 -0
  336. {xcoll-0.5.12.dist-info → xcoll-0.6.1.dist-info}/WHEEL +0 -0
@@ -1,286 +0,0 @@
1
- Python types
2
- ############
3
-
4
- .. _wrappers:
5
-
6
- Available wrappers
7
- ==================
8
-
9
- All major Python types are available as thin C++ wrapper classes. These
10
- can also be used as function parameters -- see :ref:`python_objects_as_args`.
11
-
12
- Available types include :class:`handle`, :class:`object`, :class:`bool_`,
13
- :class:`int_`, :class:`float_`, :class:`str`, :class:`bytes`, :class:`tuple`,
14
- :class:`list`, :class:`dict`, :class:`slice`, :class:`none`, :class:`capsule`,
15
- :class:`iterable`, :class:`iterator`, :class:`function`, :class:`buffer`,
16
- :class:`array`, and :class:`array_t`.
17
-
18
- .. warning::
19
-
20
- Be sure to review the :ref:`pytypes_gotchas` before using this heavily in
21
- your C++ API.
22
-
23
- .. _instantiating_compound_types:
24
-
25
- Instantiating compound Python types from C++
26
- ============================================
27
-
28
- Dictionaries can be initialized in the :class:`dict` constructor:
29
-
30
- .. code-block:: cpp
31
-
32
- using namespace pybind11::literals; // to bring in the `_a` literal
33
- py::dict d("spam"_a=py::none(), "eggs"_a=42);
34
-
35
- A tuple of python objects can be instantiated using :func:`py::make_tuple`:
36
-
37
- .. code-block:: cpp
38
-
39
- py::tuple tup = py::make_tuple(42, py::none(), "spam");
40
-
41
- Each element is converted to a supported Python type.
42
-
43
- A `simple namespace`_ can be instantiated using
44
-
45
- .. code-block:: cpp
46
-
47
- using namespace pybind11::literals; // to bring in the `_a` literal
48
- py::object SimpleNamespace = py::module_::import("types").attr("SimpleNamespace");
49
- py::object ns = SimpleNamespace("spam"_a=py::none(), "eggs"_a=42);
50
-
51
- Attributes on a namespace can be modified with the :func:`py::delattr`,
52
- :func:`py::getattr`, and :func:`py::setattr` functions. Simple namespaces can
53
- be useful as lightweight stand-ins for class instances.
54
-
55
- .. _simple namespace: https://docs.python.org/3/library/types.html#types.SimpleNamespace
56
-
57
- .. _casting_back_and_forth:
58
-
59
- Casting back and forth
60
- ======================
61
-
62
- In this kind of mixed code, it is often necessary to convert arbitrary C++
63
- types to Python, which can be done using :func:`py::cast`:
64
-
65
- .. code-block:: cpp
66
-
67
- MyClass *cls = ...;
68
- py::object obj = py::cast(cls);
69
-
70
- The reverse direction uses the following syntax:
71
-
72
- .. code-block:: cpp
73
-
74
- py::object obj = ...;
75
- MyClass *cls = obj.cast<MyClass *>();
76
-
77
- When conversion fails, both directions throw the exception :class:`cast_error`.
78
-
79
- .. _python_libs:
80
-
81
- Accessing Python libraries from C++
82
- ===================================
83
-
84
- It is also possible to import objects defined in the Python standard
85
- library or available in the current Python environment (``sys.path``) and work
86
- with these in C++.
87
-
88
- This example obtains a reference to the Python ``Decimal`` class.
89
-
90
- .. code-block:: cpp
91
-
92
- // Equivalent to "from decimal import Decimal"
93
- py::object Decimal = py::module_::import("decimal").attr("Decimal");
94
-
95
- .. code-block:: cpp
96
-
97
- // Try to import scipy
98
- py::object scipy = py::module_::import("scipy");
99
- return scipy.attr("__version__");
100
-
101
-
102
- .. _calling_python_functions:
103
-
104
- Calling Python functions
105
- ========================
106
-
107
- It is also possible to call Python classes, functions and methods
108
- via ``operator()``.
109
-
110
- .. code-block:: cpp
111
-
112
- // Construct a Python object of class Decimal
113
- py::object pi = Decimal("3.14159");
114
-
115
- .. code-block:: cpp
116
-
117
- // Use Python to make our directories
118
- py::object os = py::module_::import("os");
119
- py::object makedirs = os.attr("makedirs");
120
- makedirs("/tmp/path/to/somewhere");
121
-
122
- One can convert the result obtained from Python to a pure C++ version
123
- if a ``py::class_`` or type conversion is defined.
124
-
125
- .. code-block:: cpp
126
-
127
- py::function f = <...>;
128
- py::object result_py = f(1234, "hello", some_instance);
129
- MyClass &result = result_py.cast<MyClass>();
130
-
131
- .. _calling_python_methods:
132
-
133
- Calling Python methods
134
- ========================
135
-
136
- To call an object's method, one can again use ``.attr`` to obtain access to the
137
- Python method.
138
-
139
- .. code-block:: cpp
140
-
141
- // Calculate e^π in decimal
142
- py::object exp_pi = pi.attr("exp")();
143
- py::print(py::str(exp_pi));
144
-
145
- In the example above ``pi.attr("exp")`` is a *bound method*: it will always call
146
- the method for that same instance of the class. Alternately one can create an
147
- *unbound method* via the Python class (instead of instance) and pass the ``self``
148
- object explicitly, followed by other arguments.
149
-
150
- .. code-block:: cpp
151
-
152
- py::object decimal_exp = Decimal.attr("exp");
153
-
154
- // Compute the e^n for n=0..4
155
- for (int n = 0; n < 5; n++) {
156
- py::print(decimal_exp(Decimal(n));
157
- }
158
-
159
- Keyword arguments
160
- =================
161
-
162
- Keyword arguments are also supported. In Python, there is the usual call syntax:
163
-
164
- .. code-block:: python
165
-
166
- def f(number, say, to):
167
- ... # function code
168
-
169
-
170
- f(1234, say="hello", to=some_instance) # keyword call in Python
171
-
172
- In C++, the same call can be made using:
173
-
174
- .. code-block:: cpp
175
-
176
- using namespace pybind11::literals; // to bring in the `_a` literal
177
- f(1234, "say"_a="hello", "to"_a=some_instance); // keyword call in C++
178
-
179
- Unpacking arguments
180
- ===================
181
-
182
- Unpacking of ``*args`` and ``**kwargs`` is also possible and can be mixed with
183
- other arguments:
184
-
185
- .. code-block:: cpp
186
-
187
- // * unpacking
188
- py::tuple args = py::make_tuple(1234, "hello", some_instance);
189
- f(*args);
190
-
191
- // ** unpacking
192
- py::dict kwargs = py::dict("number"_a=1234, "say"_a="hello", "to"_a=some_instance);
193
- f(**kwargs);
194
-
195
- // mixed keywords, * and ** unpacking
196
- py::tuple args = py::make_tuple(1234);
197
- py::dict kwargs = py::dict("to"_a=some_instance);
198
- f(*args, "say"_a="hello", **kwargs);
199
-
200
- Generalized unpacking according to PEP448_ is also supported:
201
-
202
- .. code-block:: cpp
203
-
204
- py::dict kwargs1 = py::dict("number"_a=1234);
205
- py::dict kwargs2 = py::dict("to"_a=some_instance);
206
- f(**kwargs1, "say"_a="hello", **kwargs2);
207
-
208
- .. seealso::
209
-
210
- The file :file:`tests/test_pytypes.cpp` contains a complete
211
- example that demonstrates passing native Python types in more detail. The
212
- file :file:`tests/test_callbacks.cpp` presents a few examples of calling
213
- Python functions from C++, including keywords arguments and unpacking.
214
-
215
- .. _PEP448: https://www.python.org/dev/peps/pep-0448/
216
-
217
- .. _implicit_casting:
218
-
219
- Implicit casting
220
- ================
221
-
222
- When using the C++ interface for Python types, or calling Python functions,
223
- objects of type :class:`object` are returned. It is possible to invoke implicit
224
- conversions to subclasses like :class:`dict`. The same holds for the proxy objects
225
- returned by ``operator[]`` or ``obj.attr()``.
226
- Casting to subtypes improves code readability and allows values to be passed to
227
- C++ functions that require a specific subtype rather than a generic :class:`object`.
228
-
229
- .. code-block:: cpp
230
-
231
- #include <pybind11/numpy.h>
232
- using namespace pybind11::literals;
233
-
234
- py::module_ os = py::module_::import("os");
235
- py::module_ path = py::module_::import("os.path"); // like 'import os.path as path'
236
- py::module_ np = py::module_::import("numpy"); // like 'import numpy as np'
237
-
238
- py::str curdir_abs = path.attr("abspath")(path.attr("curdir"));
239
- py::print(py::str("Current directory: ") + curdir_abs);
240
- py::dict environ = os.attr("environ");
241
- py::print(environ["HOME"]);
242
- py::array_t<float> arr = np.attr("ones")(3, "dtype"_a="float32");
243
- py::print(py::repr(arr + py::int_(1)));
244
-
245
- These implicit conversions are available for subclasses of :class:`object`; there
246
- is no need to call ``obj.cast()`` explicitly as for custom classes, see
247
- :ref:`casting_back_and_forth`.
248
-
249
- .. note::
250
- If a trivial conversion via move constructor is not possible, both implicit and
251
- explicit casting (calling ``obj.cast()``) will attempt a "rich" conversion.
252
- For instance, ``py::list env = os.attr("environ");`` will succeed and is
253
- equivalent to the Python code ``env = list(os.environ)`` that produces a
254
- list of the dict keys.
255
-
256
- .. TODO: Adapt text once PR #2349 has landed
257
-
258
- Handling exceptions
259
- ===================
260
-
261
- Python exceptions from wrapper classes will be thrown as a ``py::error_already_set``.
262
- See :ref:`Handling exceptions from Python in C++
263
- <handling_python_exceptions_cpp>` for more information on handling exceptions
264
- raised when calling C++ wrapper classes.
265
-
266
- .. _pytypes_gotchas:
267
-
268
- Gotchas
269
- =======
270
-
271
- Default-Constructed Wrappers
272
- ----------------------------
273
-
274
- When a wrapper type is default-constructed, it is **not** a valid Python object (i.e. it is not ``py::none()``). It is simply the same as
275
- ``PyObject*`` null pointer. To check for this, use
276
- ``static_cast<bool>(my_wrapper)``.
277
-
278
- Assigning py::none() to wrappers
279
- --------------------------------
280
-
281
- You may be tempted to use types like ``py::str`` and ``py::dict`` in C++
282
- signatures (either pure C++, or in bound signatures), and assign them default
283
- values of ``py::none()``. However, in a best case scenario, it will fail fast
284
- because ``None`` is not convertible to that type (e.g. ``py::dict``), or in a
285
- worse case scenario, it will silently work but corrupt the types you want to
286
- work with (e.g. ``py::str(py::none())`` will yield ``"None"`` in Python).
@@ -1,155 +0,0 @@
1
- Utilities
2
- #########
3
-
4
- Using Python's print function in C++
5
- ====================================
6
-
7
- The usual way to write output in C++ is using ``std::cout`` while in Python one
8
- would use ``print``. Since these methods use different buffers, mixing them can
9
- lead to output order issues. To resolve this, pybind11 modules can use the
10
- :func:`py::print` function which writes to Python's ``sys.stdout`` for consistency.
11
-
12
- Python's ``print`` function is replicated in the C++ API including optional
13
- keyword arguments ``sep``, ``end``, ``file``, ``flush``. Everything works as
14
- expected in Python:
15
-
16
- .. code-block:: cpp
17
-
18
- py::print(1, 2.0, "three"); // 1 2.0 three
19
- py::print(1, 2.0, "three", "sep"_a="-"); // 1-2.0-three
20
-
21
- auto args = py::make_tuple("unpacked", true);
22
- py::print("->", *args, "end"_a="<-"); // -> unpacked True <-
23
-
24
- .. _ostream_redirect:
25
-
26
- Capturing standard output from ostream
27
- ======================================
28
-
29
- Often, a library will use the streams ``std::cout`` and ``std::cerr`` to print,
30
- but this does not play well with Python's standard ``sys.stdout`` and ``sys.stderr``
31
- redirection. Replacing a library's printing with ``py::print <print>`` may not
32
- be feasible. This can be fixed using a guard around the library function that
33
- redirects output to the corresponding Python streams:
34
-
35
- .. code-block:: cpp
36
-
37
- #include <pybind11/iostream.h>
38
-
39
- ...
40
-
41
- // Add a scoped redirect for your noisy code
42
- m.def("noisy_func", []() {
43
- py::scoped_ostream_redirect stream(
44
- std::cout, // std::ostream&
45
- py::module_::import("sys").attr("stdout") // Python output
46
- );
47
- call_noisy_func();
48
- });
49
-
50
- .. warning::
51
-
52
- The implementation in ``pybind11/iostream.h`` is NOT thread safe. Multiple
53
- threads writing to a redirected ostream concurrently cause data races
54
- and potentially buffer overflows. Therefore it is currently a requirement
55
- that all (possibly) concurrent redirected ostream writes are protected by
56
- a mutex. #HelpAppreciated: Work on iostream.h thread safety. For more
57
- background see the discussions under
58
- `PR #2982 <https://github.com/pybind/pybind11/pull/2982>`_ and
59
- `PR #2995 <https://github.com/pybind/pybind11/pull/2995>`_.
60
-
61
- This method respects flushes on the output streams and will flush if needed
62
- when the scoped guard is destroyed. This allows the output to be redirected in
63
- real time, such as to a Jupyter notebook. The two arguments, the C++ stream and
64
- the Python output, are optional, and default to standard output if not given. An
65
- extra type, ``py::scoped_estream_redirect <scoped_estream_redirect>``, is identical
66
- except for defaulting to ``std::cerr`` and ``sys.stderr``; this can be useful with
67
- ``py::call_guard``, which allows multiple items, but uses the default constructor:
68
-
69
- .. code-block:: cpp
70
-
71
- // Alternative: Call single function using call guard
72
- m.def("noisy_func", &call_noisy_function,
73
- py::call_guard<py::scoped_ostream_redirect,
74
- py::scoped_estream_redirect>());
75
-
76
- The redirection can also be done in Python with the addition of a context
77
- manager, using the ``py::add_ostream_redirect() <add_ostream_redirect>`` function:
78
-
79
- .. code-block:: cpp
80
-
81
- py::add_ostream_redirect(m, "ostream_redirect");
82
-
83
- The name in Python defaults to ``ostream_redirect`` if no name is passed. This
84
- creates the following context manager in Python:
85
-
86
- .. code-block:: python
87
-
88
- with ostream_redirect(stdout=True, stderr=True):
89
- noisy_function()
90
-
91
- It defaults to redirecting both streams, though you can use the keyword
92
- arguments to disable one of the streams if needed.
93
-
94
- .. note::
95
-
96
- The above methods will not redirect C-level output to file descriptors, such
97
- as ``fprintf``. For those cases, you'll need to redirect the file
98
- descriptors either directly in C or with Python's ``os.dup2`` function
99
- in an operating-system dependent way.
100
-
101
- .. _eval:
102
-
103
- Evaluating Python expressions from strings and files
104
- ====================================================
105
-
106
- pybind11 provides the ``eval``, ``exec`` and ``eval_file`` functions to evaluate
107
- Python expressions and statements. The following example illustrates how they
108
- can be used.
109
-
110
- .. code-block:: cpp
111
-
112
- // At beginning of file
113
- #include <pybind11/eval.h>
114
-
115
- ...
116
-
117
- // Evaluate in scope of main module
118
- py::object scope = py::module_::import("__main__").attr("__dict__");
119
-
120
- // Evaluate an isolated expression
121
- int result = py::eval("my_variable + 10", scope).cast<int>();
122
-
123
- // Evaluate a sequence of statements
124
- py::exec(
125
- "print('Hello')\n"
126
- "print('world!');",
127
- scope);
128
-
129
- // Evaluate the statements in an separate Python file on disk
130
- py::eval_file("script.py", scope);
131
-
132
- C++11 raw string literals are also supported and quite handy for this purpose.
133
- The only requirement is that the first statement must be on a new line following
134
- the raw string delimiter ``R"(``, ensuring all lines have common leading indent:
135
-
136
- .. code-block:: cpp
137
-
138
- py::exec(R"(
139
- x = get_answer()
140
- if x == 42:
141
- print('Hello World!')
142
- else:
143
- print('Bye!')
144
- )", scope
145
- );
146
-
147
- .. note::
148
-
149
- `eval` and `eval_file` accept a template parameter that describes how the
150
- string/file should be interpreted. Possible choices include ``eval_expr``
151
- (isolated expression), ``eval_single_statement`` (a single statement, return
152
- value is always ``none``), and ``eval_statements`` (sequence of statements,
153
- return value is always ``none``). `eval` defaults to ``eval_expr``,
154
- `eval_file` defaults to ``eval_statements`` and `exec` is just a shortcut
155
- for ``eval<eval_statements>``.
@@ -1,174 +0,0 @@
1
- Smart pointers
2
- ##############
3
-
4
- std::unique_ptr
5
- ===============
6
-
7
- Given a class ``Example`` with Python bindings, it's possible to return
8
- instances wrapped in C++11 unique pointers, like so
9
-
10
- .. code-block:: cpp
11
-
12
- std::unique_ptr<Example> create_example() { return std::unique_ptr<Example>(new Example()); }
13
-
14
- .. code-block:: cpp
15
-
16
- m.def("create_example", &create_example);
17
-
18
- In other words, there is nothing special that needs to be done. While returning
19
- unique pointers in this way is allowed, it is *illegal* to use them as function
20
- arguments. For instance, the following function signature cannot be processed
21
- by pybind11.
22
-
23
- .. code-block:: cpp
24
-
25
- void do_something_with_example(std::unique_ptr<Example> ex) { ... }
26
-
27
- The above signature would imply that Python needs to give up ownership of an
28
- object that is passed to this function, which is generally not possible (for
29
- instance, the object might be referenced elsewhere).
30
-
31
- std::shared_ptr
32
- ===============
33
-
34
- The binding generator for classes, :class:`class_`, can be passed a template
35
- type that denotes a special *holder* type that is used to manage references to
36
- the object. If no such holder type template argument is given, the default for
37
- a type named ``Type`` is ``std::unique_ptr<Type>``, which means that the object
38
- is deallocated when Python's reference count goes to zero.
39
-
40
- It is possible to switch to other types of reference counting wrappers or smart
41
- pointers, which is useful in codebases that rely on them. For instance, the
42
- following snippet causes ``std::shared_ptr`` to be used instead.
43
-
44
- .. code-block:: cpp
45
-
46
- py::class_<Example, std::shared_ptr<Example> /* <- holder type */> obj(m, "Example");
47
-
48
- Note that any particular class can only be associated with a single holder type.
49
-
50
- One potential stumbling block when using holder types is that they need to be
51
- applied consistently. Can you guess what's broken about the following binding
52
- code?
53
-
54
- .. code-block:: cpp
55
-
56
- class Child { };
57
-
58
- class Parent {
59
- public:
60
- Parent() : child(std::make_shared<Child>()) { }
61
- Child *get_child() { return child.get(); } /* Hint: ** DON'T DO THIS ** */
62
- private:
63
- std::shared_ptr<Child> child;
64
- };
65
-
66
- PYBIND11_MODULE(example, m) {
67
- py::class_<Child, std::shared_ptr<Child>>(m, "Child");
68
-
69
- py::class_<Parent, std::shared_ptr<Parent>>(m, "Parent")
70
- .def(py::init<>())
71
- .def("get_child", &Parent::get_child);
72
- }
73
-
74
- The following Python code will cause undefined behavior (and likely a
75
- segmentation fault).
76
-
77
- .. code-block:: python
78
-
79
- from example import Parent
80
-
81
- print(Parent().get_child())
82
-
83
- The problem is that ``Parent::get_child()`` returns a pointer to an instance of
84
- ``Child``, but the fact that this instance is already managed by
85
- ``std::shared_ptr<...>`` is lost when passing raw pointers. In this case,
86
- pybind11 will create a second independent ``std::shared_ptr<...>`` that also
87
- claims ownership of the pointer. In the end, the object will be freed **twice**
88
- since these shared pointers have no way of knowing about each other.
89
-
90
- There are two ways to resolve this issue:
91
-
92
- 1. For types that are managed by a smart pointer class, never use raw pointers
93
- in function arguments or return values. In other words: always consistently
94
- wrap pointers into their designated holder types (such as
95
- ``std::shared_ptr<...>``). In this case, the signature of ``get_child()``
96
- should be modified as follows:
97
-
98
- .. code-block:: cpp
99
-
100
- std::shared_ptr<Child> get_child() { return child; }
101
-
102
- 2. Adjust the definition of ``Child`` by specifying
103
- ``std::enable_shared_from_this<T>`` (see cppreference_ for details) as a
104
- base class. This adds a small bit of information to ``Child`` that allows
105
- pybind11 to realize that there is already an existing
106
- ``std::shared_ptr<...>`` and communicate with it. In this case, the
107
- declaration of ``Child`` should look as follows:
108
-
109
- .. _cppreference: http://en.cppreference.com/w/cpp/memory/enable_shared_from_this
110
-
111
- .. code-block:: cpp
112
-
113
- class Child : public std::enable_shared_from_this<Child> { };
114
-
115
- .. _smart_pointers:
116
-
117
- Custom smart pointers
118
- =====================
119
-
120
- pybind11 supports ``std::unique_ptr`` and ``std::shared_ptr`` right out of the
121
- box. For any other custom smart pointer, transparent conversions can be enabled
122
- using a macro invocation similar to the following. It must be declared at the
123
- top namespace level before any binding code:
124
-
125
- .. code-block:: cpp
126
-
127
- PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>);
128
-
129
- The first argument of :func:`PYBIND11_DECLARE_HOLDER_TYPE` should be a
130
- placeholder name that is used as a template parameter of the second argument.
131
- Thus, feel free to use any identifier, but use it consistently on both sides;
132
- also, don't use the name of a type that already exists in your codebase.
133
-
134
- The macro also accepts a third optional boolean parameter that is set to false
135
- by default. Specify
136
-
137
- .. code-block:: cpp
138
-
139
- PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>, true);
140
-
141
- if ``SmartPtr<T>`` can always be initialized from a ``T*`` pointer without the
142
- risk of inconsistencies (such as multiple independent ``SmartPtr`` instances
143
- believing that they are the sole owner of the ``T*`` pointer). A common
144
- situation where ``true`` should be passed is when the ``T`` instances use
145
- *intrusive* reference counting.
146
-
147
- Please take a look at the :ref:`macro_notes` before using this feature.
148
-
149
- By default, pybind11 assumes that your custom smart pointer has a standard
150
- interface, i.e. provides a ``.get()`` member function to access the underlying
151
- raw pointer. If this is not the case, pybind11's ``holder_helper`` must be
152
- specialized:
153
-
154
- .. code-block:: cpp
155
-
156
- // Always needed for custom holder types
157
- PYBIND11_DECLARE_HOLDER_TYPE(T, SmartPtr<T>);
158
-
159
- // Only needed if the type's `.get()` goes by another name
160
- namespace pybind11 { namespace detail {
161
- template <typename T>
162
- struct holder_helper<SmartPtr<T>> { // <-- specialization
163
- static const T *get(const SmartPtr<T> &p) { return p.getPointer(); }
164
- };
165
- }}
166
-
167
- The above specialization informs pybind11 that the custom ``SmartPtr`` class
168
- provides ``.get()`` functionality via ``.getPointer()``.
169
-
170
- .. seealso::
171
-
172
- The file :file:`tests/test_smart_ptr.cpp` contains a complete example
173
- that demonstrates how to work with custom reference-counting holder types
174
- in more detail.