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,463 +0,0 @@
1
- .. _numpy:
2
-
3
- NumPy
4
- #####
5
-
6
- Buffer protocol
7
- ===============
8
-
9
- Python supports an extremely general and convenient approach for exchanging
10
- data between plugin libraries. Types can expose a buffer view [#f2]_, which
11
- provides fast direct access to the raw internal data representation. Suppose we
12
- want to bind the following simplistic Matrix class:
13
-
14
- .. code-block:: cpp
15
-
16
- class Matrix {
17
- public:
18
- Matrix(size_t rows, size_t cols) : m_rows(rows), m_cols(cols) {
19
- m_data = new float[rows*cols];
20
- }
21
- float *data() { return m_data; }
22
- size_t rows() const { return m_rows; }
23
- size_t cols() const { return m_cols; }
24
- private:
25
- size_t m_rows, m_cols;
26
- float *m_data;
27
- };
28
-
29
- The following binding code exposes the ``Matrix`` contents as a buffer object,
30
- making it possible to cast Matrices into NumPy arrays. It is even possible to
31
- completely avoid copy operations with Python expressions like
32
- ``np.array(matrix_instance, copy = False)``.
33
-
34
- .. code-block:: cpp
35
-
36
- py::class_<Matrix>(m, "Matrix", py::buffer_protocol())
37
- .def_buffer([](Matrix &m) -> py::buffer_info {
38
- return py::buffer_info(
39
- m.data(), /* Pointer to buffer */
40
- sizeof(float), /* Size of one scalar */
41
- py::format_descriptor<float>::format(), /* Python struct-style format descriptor */
42
- 2, /* Number of dimensions */
43
- { m.rows(), m.cols() }, /* Buffer dimensions */
44
- { sizeof(float) * m.cols(), /* Strides (in bytes) for each index */
45
- sizeof(float) }
46
- );
47
- });
48
-
49
- Supporting the buffer protocol in a new type involves specifying the special
50
- ``py::buffer_protocol()`` tag in the ``py::class_`` constructor and calling the
51
- ``def_buffer()`` method with a lambda function that creates a
52
- ``py::buffer_info`` description record on demand describing a given matrix
53
- instance. The contents of ``py::buffer_info`` mirror the Python buffer protocol
54
- specification.
55
-
56
- .. code-block:: cpp
57
-
58
- struct buffer_info {
59
- void *ptr;
60
- py::ssize_t itemsize;
61
- std::string format;
62
- py::ssize_t ndim;
63
- std::vector<py::ssize_t> shape;
64
- std::vector<py::ssize_t> strides;
65
- };
66
-
67
- To create a C++ function that can take a Python buffer object as an argument,
68
- simply use the type ``py::buffer`` as one of its arguments. Buffers can exist
69
- in a great variety of configurations, hence some safety checks are usually
70
- necessary in the function body. Below, you can see a basic example on how to
71
- define a custom constructor for the Eigen double precision matrix
72
- (``Eigen::MatrixXd``) type, which supports initialization from compatible
73
- buffer objects (e.g. a NumPy matrix).
74
-
75
- .. code-block:: cpp
76
-
77
- /* Bind MatrixXd (or some other Eigen type) to Python */
78
- typedef Eigen::MatrixXd Matrix;
79
-
80
- typedef Matrix::Scalar Scalar;
81
- constexpr bool rowMajor = Matrix::Flags & Eigen::RowMajorBit;
82
-
83
- py::class_<Matrix>(m, "Matrix", py::buffer_protocol())
84
- .def(py::init([](py::buffer b) {
85
- typedef Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> Strides;
86
-
87
- /* Request a buffer descriptor from Python */
88
- py::buffer_info info = b.request();
89
-
90
- /* Some sanity checks ... */
91
- if (info.format != py::format_descriptor<Scalar>::format())
92
- throw std::runtime_error("Incompatible format: expected a double array!");
93
-
94
- if (info.ndim != 2)
95
- throw std::runtime_error("Incompatible buffer dimension!");
96
-
97
- auto strides = Strides(
98
- info.strides[rowMajor ? 0 : 1] / (py::ssize_t)sizeof(Scalar),
99
- info.strides[rowMajor ? 1 : 0] / (py::ssize_t)sizeof(Scalar));
100
-
101
- auto map = Eigen::Map<Matrix, 0, Strides>(
102
- static_cast<Scalar *>(info.ptr), info.shape[0], info.shape[1], strides);
103
-
104
- return Matrix(map);
105
- }));
106
-
107
- For reference, the ``def_buffer()`` call for this Eigen data type should look
108
- as follows:
109
-
110
- .. code-block:: cpp
111
-
112
- .def_buffer([](Matrix &m) -> py::buffer_info {
113
- return py::buffer_info(
114
- m.data(), /* Pointer to buffer */
115
- sizeof(Scalar), /* Size of one scalar */
116
- py::format_descriptor<Scalar>::format(), /* Python struct-style format descriptor */
117
- 2, /* Number of dimensions */
118
- { m.rows(), m.cols() }, /* Buffer dimensions */
119
- { sizeof(Scalar) * (rowMajor ? m.cols() : 1),
120
- sizeof(Scalar) * (rowMajor ? 1 : m.rows()) }
121
- /* Strides (in bytes) for each index */
122
- );
123
- })
124
-
125
- For a much easier approach of binding Eigen types (although with some
126
- limitations), refer to the section on :doc:`/advanced/cast/eigen`.
127
-
128
- .. seealso::
129
-
130
- The file :file:`tests/test_buffers.cpp` contains a complete example
131
- that demonstrates using the buffer protocol with pybind11 in more detail.
132
-
133
- .. [#f2] http://docs.python.org/3/c-api/buffer.html
134
-
135
- Arrays
136
- ======
137
-
138
- By exchanging ``py::buffer`` with ``py::array`` in the above snippet, we can
139
- restrict the function so that it only accepts NumPy arrays (rather than any
140
- type of Python object satisfying the buffer protocol).
141
-
142
- In many situations, we want to define a function which only accepts a NumPy
143
- array of a certain data type. This is possible via the ``py::array_t<T>``
144
- template. For instance, the following function requires the argument to be a
145
- NumPy array containing double precision values.
146
-
147
- .. code-block:: cpp
148
-
149
- void f(py::array_t<double> array);
150
-
151
- When it is invoked with a different type (e.g. an integer or a list of
152
- integers), the binding code will attempt to cast the input into a NumPy array
153
- of the requested type. This feature requires the :file:`pybind11/numpy.h`
154
- header to be included. Note that :file:`pybind11/numpy.h` does not depend on
155
- the NumPy headers, and thus can be used without declaring a build-time
156
- dependency on NumPy; NumPy>=1.7.0 is a runtime dependency.
157
-
158
- Data in NumPy arrays is not guaranteed to packed in a dense manner;
159
- furthermore, entries can be separated by arbitrary column and row strides.
160
- Sometimes, it can be useful to require a function to only accept dense arrays
161
- using either the C (row-major) or Fortran (column-major) ordering. This can be
162
- accomplished via a second template argument with values ``py::array::c_style``
163
- or ``py::array::f_style``.
164
-
165
- .. code-block:: cpp
166
-
167
- void f(py::array_t<double, py::array::c_style | py::array::forcecast> array);
168
-
169
- The ``py::array::forcecast`` argument is the default value of the second
170
- template parameter, and it ensures that non-conforming arguments are converted
171
- into an array satisfying the specified requirements instead of trying the next
172
- function overload.
173
-
174
- There are several methods on arrays; the methods listed below under references
175
- work, as well as the following functions based on the NumPy API:
176
-
177
- - ``.dtype()`` returns the type of the contained values.
178
-
179
- - ``.strides()`` returns a pointer to the strides of the array (optionally pass
180
- an integer axis to get a number).
181
-
182
- - ``.flags()`` returns the flag settings. ``.writable()`` and ``.owndata()``
183
- are directly available.
184
-
185
- - ``.offset_at()`` returns the offset (optionally pass indices).
186
-
187
- - ``.squeeze()`` returns a view with length-1 axes removed.
188
-
189
- - ``.view(dtype)`` returns a view of the array with a different dtype.
190
-
191
- - ``.reshape({i, j, ...})`` returns a view of the array with a different shape.
192
- ``.resize({...})`` is also available.
193
-
194
- - ``.index_at(i, j, ...)`` gets the count from the beginning to a given index.
195
-
196
-
197
- There are also several methods for getting references (described below).
198
-
199
- Structured types
200
- ================
201
-
202
- In order for ``py::array_t`` to work with structured (record) types, we first
203
- need to register the memory layout of the type. This can be done via
204
- ``PYBIND11_NUMPY_DTYPE`` macro, called in the plugin definition code, which
205
- expects the type followed by field names:
206
-
207
- .. code-block:: cpp
208
-
209
- struct A {
210
- int x;
211
- double y;
212
- };
213
-
214
- struct B {
215
- int z;
216
- A a;
217
- };
218
-
219
- // ...
220
- PYBIND11_MODULE(test, m) {
221
- // ...
222
-
223
- PYBIND11_NUMPY_DTYPE(A, x, y);
224
- PYBIND11_NUMPY_DTYPE(B, z, a);
225
- /* now both A and B can be used as template arguments to py::array_t */
226
- }
227
-
228
- The structure should consist of fundamental arithmetic types, ``std::complex``,
229
- previously registered substructures, and arrays of any of the above. Both C++
230
- arrays and ``std::array`` are supported. While there is a static assertion to
231
- prevent many types of unsupported structures, it is still the user's
232
- responsibility to use only "plain" structures that can be safely manipulated as
233
- raw memory without violating invariants.
234
-
235
- Vectorizing functions
236
- =====================
237
-
238
- Suppose we want to bind a function with the following signature to Python so
239
- that it can process arbitrary NumPy array arguments (vectors, matrices, general
240
- N-D arrays) in addition to its normal arguments:
241
-
242
- .. code-block:: cpp
243
-
244
- double my_func(int x, float y, double z);
245
-
246
- After including the ``pybind11/numpy.h`` header, this is extremely simple:
247
-
248
- .. code-block:: cpp
249
-
250
- m.def("vectorized_func", py::vectorize(my_func));
251
-
252
- Invoking the function like below causes 4 calls to be made to ``my_func`` with
253
- each of the array elements. The significant advantage of this compared to
254
- solutions like ``numpy.vectorize()`` is that the loop over the elements runs
255
- entirely on the C++ side and can be crunched down into a tight, optimized loop
256
- by the compiler. The result is returned as a NumPy array of type
257
- ``numpy.dtype.float64``.
258
-
259
- .. code-block:: pycon
260
-
261
- >>> x = np.array([[1, 3], [5, 7]])
262
- >>> y = np.array([[2, 4], [6, 8]])
263
- >>> z = 3
264
- >>> result = vectorized_func(x, y, z)
265
-
266
- The scalar argument ``z`` is transparently replicated 4 times. The input
267
- arrays ``x`` and ``y`` are automatically converted into the right types (they
268
- are of type ``numpy.dtype.int64`` but need to be ``numpy.dtype.int32`` and
269
- ``numpy.dtype.float32``, respectively).
270
-
271
- .. note::
272
-
273
- Only arithmetic, complex, and POD types passed by value or by ``const &``
274
- reference are vectorized; all other arguments are passed through as-is.
275
- Functions taking rvalue reference arguments cannot be vectorized.
276
-
277
- In cases where the computation is too complicated to be reduced to
278
- ``vectorize``, it will be necessary to create and access the buffer contents
279
- manually. The following snippet contains a complete example that shows how this
280
- works (the code is somewhat contrived, since it could have been done more
281
- simply using ``vectorize``).
282
-
283
- .. code-block:: cpp
284
-
285
- #include <pybind11/pybind11.h>
286
- #include <pybind11/numpy.h>
287
-
288
- namespace py = pybind11;
289
-
290
- py::array_t<double> add_arrays(py::array_t<double> input1, py::array_t<double> input2) {
291
- py::buffer_info buf1 = input1.request(), buf2 = input2.request();
292
-
293
- if (buf1.ndim != 1 || buf2.ndim != 1)
294
- throw std::runtime_error("Number of dimensions must be one");
295
-
296
- if (buf1.size != buf2.size)
297
- throw std::runtime_error("Input shapes must match");
298
-
299
- /* No pointer is passed, so NumPy will allocate the buffer */
300
- auto result = py::array_t<double>(buf1.size);
301
-
302
- py::buffer_info buf3 = result.request();
303
-
304
- double *ptr1 = static_cast<double *>(buf1.ptr);
305
- double *ptr2 = static_cast<double *>(buf2.ptr);
306
- double *ptr3 = static_cast<double *>(buf3.ptr);
307
-
308
- for (size_t idx = 0; idx < buf1.shape[0]; idx++)
309
- ptr3[idx] = ptr1[idx] + ptr2[idx];
310
-
311
- return result;
312
- }
313
-
314
- PYBIND11_MODULE(test, m) {
315
- m.def("add_arrays", &add_arrays, "Add two NumPy arrays");
316
- }
317
-
318
- .. seealso::
319
-
320
- The file :file:`tests/test_numpy_vectorize.cpp` contains a complete
321
- example that demonstrates using :func:`vectorize` in more detail.
322
-
323
- Direct access
324
- =============
325
-
326
- For performance reasons, particularly when dealing with very large arrays, it
327
- is often desirable to directly access array elements without internal checking
328
- of dimensions and bounds on every access when indices are known to be already
329
- valid. To avoid such checks, the ``array`` class and ``array_t<T>`` template
330
- class offer an unchecked proxy object that can be used for this unchecked
331
- access through the ``unchecked<N>`` and ``mutable_unchecked<N>`` methods,
332
- where ``N`` gives the required dimensionality of the array:
333
-
334
- .. code-block:: cpp
335
-
336
- m.def("sum_3d", [](py::array_t<double> x) {
337
- auto r = x.unchecked<3>(); // x must have ndim = 3; can be non-writeable
338
- double sum = 0;
339
- for (py::ssize_t i = 0; i < r.shape(0); i++)
340
- for (py::ssize_t j = 0; j < r.shape(1); j++)
341
- for (py::ssize_t k = 0; k < r.shape(2); k++)
342
- sum += r(i, j, k);
343
- return sum;
344
- });
345
- m.def("increment_3d", [](py::array_t<double> x) {
346
- auto r = x.mutable_unchecked<3>(); // Will throw if ndim != 3 or flags.writeable is false
347
- for (py::ssize_t i = 0; i < r.shape(0); i++)
348
- for (py::ssize_t j = 0; j < r.shape(1); j++)
349
- for (py::ssize_t k = 0; k < r.shape(2); k++)
350
- r(i, j, k) += 1.0;
351
- }, py::arg().noconvert());
352
-
353
- To obtain the proxy from an ``array`` object, you must specify both the data
354
- type and number of dimensions as template arguments, such as ``auto r =
355
- myarray.mutable_unchecked<float, 2>()``.
356
-
357
- If the number of dimensions is not known at compile time, you can omit the
358
- dimensions template parameter (i.e. calling ``arr_t.unchecked()`` or
359
- ``arr.unchecked<T>()``. This will give you a proxy object that works in the
360
- same way, but results in less optimizable code and thus a small efficiency
361
- loss in tight loops.
362
-
363
- Note that the returned proxy object directly references the array's data, and
364
- only reads its shape, strides, and writeable flag when constructed. You must
365
- take care to ensure that the referenced array is not destroyed or reshaped for
366
- the duration of the returned object, typically by limiting the scope of the
367
- returned instance.
368
-
369
- The returned proxy object supports some of the same methods as ``py::array`` so
370
- that it can be used as a drop-in replacement for some existing, index-checked
371
- uses of ``py::array``:
372
-
373
- - ``.ndim()`` returns the number of dimensions
374
-
375
- - ``.data(1, 2, ...)`` and ``r.mutable_data(1, 2, ...)``` returns a pointer to
376
- the ``const T`` or ``T`` data, respectively, at the given indices. The
377
- latter is only available to proxies obtained via ``a.mutable_unchecked()``.
378
-
379
- - ``.itemsize()`` returns the size of an item in bytes, i.e. ``sizeof(T)``.
380
-
381
- - ``.ndim()`` returns the number of dimensions.
382
-
383
- - ``.shape(n)`` returns the size of dimension ``n``
384
-
385
- - ``.size()`` returns the total number of elements (i.e. the product of the shapes).
386
-
387
- - ``.nbytes()`` returns the number of bytes used by the referenced elements
388
- (i.e. ``itemsize()`` times ``size()``).
389
-
390
- .. seealso::
391
-
392
- The file :file:`tests/test_numpy_array.cpp` contains additional examples
393
- demonstrating the use of this feature.
394
-
395
- Ellipsis
396
- ========
397
-
398
- Python 3 provides a convenient ``...`` ellipsis notation that is often used to
399
- slice multidimensional arrays. For instance, the following snippet extracts the
400
- middle dimensions of a tensor with the first and last index set to zero.
401
- In Python 2, the syntactic sugar ``...`` is not available, but the singleton
402
- ``Ellipsis`` (of type ``ellipsis``) can still be used directly.
403
-
404
- .. code-block:: python
405
-
406
- a = ... # a NumPy array
407
- b = a[0, ..., 0]
408
-
409
- The function ``py::ellipsis()`` function can be used to perform the same
410
- operation on the C++ side:
411
-
412
- .. code-block:: cpp
413
-
414
- py::array a = /* A NumPy array */;
415
- py::array b = a[py::make_tuple(0, py::ellipsis(), 0)];
416
-
417
- .. versionchanged:: 2.6
418
- ``py::ellipsis()`` is now also available in Python 2.
419
-
420
- Memory view
421
- ===========
422
-
423
- For a case when we simply want to provide a direct accessor to C/C++ buffer
424
- without a concrete class object, we can return a ``memoryview`` object. Suppose
425
- we wish to expose a ``memoryview`` for 2x4 uint8_t array, we can do the
426
- following:
427
-
428
- .. code-block:: cpp
429
-
430
- const uint8_t buffer[] = {
431
- 0, 1, 2, 3,
432
- 4, 5, 6, 7
433
- };
434
- m.def("get_memoryview2d", []() {
435
- return py::memoryview::from_buffer(
436
- buffer, // buffer pointer
437
- { 2, 4 }, // shape (rows, cols)
438
- { sizeof(uint8_t) * 4, sizeof(uint8_t) } // strides in bytes
439
- );
440
- })
441
-
442
- This approach is meant for providing a ``memoryview`` for a C/C++ buffer not
443
- managed by Python. The user is responsible for managing the lifetime of the
444
- buffer. Using a ``memoryview`` created in this way after deleting the buffer in
445
- C++ side results in undefined behavior.
446
-
447
- We can also use ``memoryview::from_memory`` for a simple 1D contiguous buffer:
448
-
449
- .. code-block:: cpp
450
-
451
- m.def("get_memoryview1d", []() {
452
- return py::memoryview::from_memory(
453
- buffer, // buffer pointer
454
- sizeof(uint8_t) * 8 // buffer size
455
- );
456
- })
457
-
458
- .. note::
459
-
460
- ``memoryview::from_memory`` is not available in Python 2.
461
-
462
- .. versionchanged:: 2.6
463
- ``memoryview::from_memory`` added.