xcoll 0.3.6__py3-none-any.whl → 0.5.0__py3-none-any.whl

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

Potentially problematic release.


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

Files changed (350) hide show
  1. xcoll/__init__.py +13 -4
  2. xcoll/beam_elements/__init__.py +14 -6
  3. xcoll/beam_elements/absorber.py +41 -7
  4. xcoll/beam_elements/base.py +1202 -247
  5. xcoll/beam_elements/blowup.py +198 -0
  6. xcoll/beam_elements/elements_src/black_absorber.h +136 -0
  7. xcoll/beam_elements/elements_src/black_crystal.h +129 -0
  8. xcoll/beam_elements/elements_src/blowup.h +42 -0
  9. xcoll/beam_elements/elements_src/emittance_monitor.h +109 -0
  10. xcoll/beam_elements/{collimators_src → elements_src}/everest_block.h +59 -30
  11. xcoll/beam_elements/elements_src/everest_collimator.h +237 -0
  12. xcoll/beam_elements/elements_src/everest_crystal.h +280 -0
  13. xcoll/beam_elements/everest.py +65 -119
  14. xcoll/beam_elements/monitor.py +428 -0
  15. xcoll/colldb.py +276 -747
  16. xcoll/general.py +5 -5
  17. xcoll/headers/checks.h +1 -1
  18. xcoll/headers/particle_states.h +2 -2
  19. xcoll/initial_distribution.py +207 -0
  20. xcoll/install.py +179 -0
  21. xcoll/interaction_record/__init__.py +1 -0
  22. xcoll/interaction_record/interaction_record.py +298 -0
  23. xcoll/interaction_record/interaction_record_src/interaction_record.h +98 -0
  24. xcoll/{impacts → interaction_record}/interaction_types.py +11 -4
  25. xcoll/line_tools.py +82 -0
  26. xcoll/lossmap.py +219 -0
  27. xcoll/manager.py +2 -937
  28. xcoll/rf_sweep.py +1 -1
  29. xcoll/scattering_routines/everest/amorphous.h +232 -0
  30. xcoll/scattering_routines/everest/channeling.h +240 -0
  31. xcoll/scattering_routines/everest/crystal_parameters.h +137 -0
  32. xcoll/scattering_routines/everest/everest.h +11 -30
  33. xcoll/scattering_routines/everest/everest.py +13 -10
  34. xcoll/scattering_routines/everest/jaw.h +28 -197
  35. xcoll/scattering_routines/everest/materials.py +37 -15
  36. xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +31 -10
  37. xcoll/scattering_routines/everest/nuclear_interaction.h +86 -0
  38. xcoll/scattering_routines/everest/properties.h +6 -1
  39. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
  40. xcoll/scattering_routines/geant4/collimasim/.git +1 -0
  41. xcoll/scattering_routines/geant4/collimasim/.gitignore +12 -0
  42. xcoll/scattering_routines/geant4/collimasim/.gitmodules +3 -0
  43. xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +26 -0
  44. xcoll/scattering_routines/geant4/collimasim/README.md +21 -0
  45. xcoll/scattering_routines/geant4/collimasim/docs/Makefile +20 -0
  46. xcoll/scattering_routines/geant4/collimasim/docs/make.bat +35 -0
  47. xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +10 -0
  48. xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +59 -0
  49. xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +26 -0
  50. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +37 -0
  51. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +19 -0
  52. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +65 -0
  53. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +73 -0
  54. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +1 -0
  55. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +9 -0
  56. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +386 -0
  57. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +45 -0
  58. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +8 -0
  59. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +16 -0
  60. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +8 -0
  61. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +3 -0
  62. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +19 -0
  63. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +969 -0
  64. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +84 -0
  65. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +48 -0
  66. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +16 -0
  67. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +103 -0
  68. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +45 -0
  69. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +151 -0
  70. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +3 -0
  71. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +297 -0
  72. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +29 -0
  73. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +6 -0
  74. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +180 -0
  75. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +23 -0
  76. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +192 -0
  77. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +11 -0
  78. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +81 -0
  79. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +93 -0
  80. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +310 -0
  81. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +109 -0
  82. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +43 -0
  83. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +171 -0
  84. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +251 -0
  85. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +305 -0
  86. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +1297 -0
  87. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +262 -0
  88. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +396 -0
  89. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +568 -0
  90. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +337 -0
  91. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +13 -0
  92. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +463 -0
  93. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +286 -0
  94. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +155 -0
  95. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +174 -0
  96. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +308 -0
  97. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +91 -0
  98. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +95 -0
  99. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +2050 -0
  100. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +542 -0
  101. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +8 -0
  102. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +648 -0
  103. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +381 -0
  104. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +343 -0
  105. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +48 -0
  106. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +105 -0
  107. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +72 -0
  108. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
  109. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
  110. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +427 -0
  111. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
  112. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +427 -0
  113. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +130 -0
  114. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +96 -0
  115. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +8 -0
  116. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +548 -0
  117. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +605 -0
  118. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +144 -0
  119. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +1432 -0
  120. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +213 -0
  121. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +2 -0
  122. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +65 -0
  123. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +709 -0
  124. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +1021 -0
  125. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +104 -0
  126. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +346 -0
  127. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +467 -0
  128. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +978 -0
  129. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +55 -0
  130. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +606 -0
  131. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +284 -0
  132. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +163 -0
  133. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +121 -0
  134. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +193 -0
  135. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +275 -0
  136. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +1741 -0
  137. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +163 -0
  138. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +65 -0
  139. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +2497 -0
  140. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +1879 -0
  141. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +103 -0
  142. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +375 -0
  143. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +747 -0
  144. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +88 -0
  145. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +11 -0
  146. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +52 -0
  147. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +12 -0
  148. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +6 -0
  149. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +21 -0
  150. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
  151. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +482 -0
  152. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +63 -0
  153. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +41 -0
  154. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +56 -0
  155. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +155 -0
  156. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +503 -0
  157. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +208 -0
  158. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +275 -0
  159. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +73 -0
  160. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +33 -0
  161. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
  162. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +279 -0
  163. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
  164. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +143 -0
  165. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +85 -0
  166. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +179 -0
  167. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +151 -0
  168. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +91 -0
  169. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +85 -0
  170. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +19 -0
  171. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +12 -0
  172. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +26 -0
  173. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +25 -0
  174. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +216 -0
  175. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +163 -0
  176. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +286 -0
  177. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +536 -0
  178. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +107 -0
  179. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +248 -0
  180. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +227 -0
  181. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +202 -0
  182. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +84 -0
  183. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +210 -0
  184. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +550 -0
  185. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +473 -0
  186. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +84 -0
  187. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +21 -0
  188. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +28 -0
  189. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +39 -0
  190. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +46 -0
  191. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +6 -0
  192. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +41 -0
  193. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +35 -0
  194. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +41 -0
  195. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +10 -0
  196. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +165 -0
  197. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +53 -0
  198. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +238 -0
  199. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +126 -0
  200. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +141 -0
  201. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +117 -0
  202. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +41 -0
  203. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +50 -0
  204. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +69 -0
  205. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +42 -0
  206. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +348 -0
  207. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +771 -0
  208. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +47 -0
  209. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +22 -0
  210. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +23 -0
  211. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +326 -0
  212. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +15 -0
  213. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +148 -0
  214. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +272 -0
  215. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +119 -0
  216. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +51 -0
  217. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +5 -0
  218. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +285 -0
  219. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +12 -0
  220. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +265 -0
  221. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +397 -0
  222. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +520 -0
  223. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +49 -0
  224. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +94 -0
  225. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +125 -0
  226. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +331 -0
  227. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +153 -0
  228. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +284 -0
  229. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +107 -0
  230. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +257 -0
  231. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +412 -0
  232. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +517 -0
  233. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +102 -0
  234. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +92 -0
  235. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +233 -0
  236. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +360 -0
  237. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +472 -0
  238. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +593 -0
  239. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +524 -0
  240. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +441 -0
  241. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +103 -0
  242. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +267 -0
  243. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +73 -0
  244. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +59 -0
  245. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +235 -0
  246. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +146 -0
  247. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +189 -0
  248. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +82 -0
  249. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +560 -0
  250. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +651 -0
  251. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +500 -0
  252. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +253 -0
  253. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +452 -0
  254. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +318 -0
  255. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +342 -0
  256. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +291 -0
  257. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +131 -0
  258. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +318 -0
  259. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +144 -0
  260. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +29 -0
  261. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +66 -0
  262. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +44 -0
  263. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +22 -0
  264. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +9 -0
  265. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +510 -0
  266. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +408 -0
  267. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +140 -0
  268. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +117 -0
  269. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +70 -0
  270. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +86 -0
  271. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +257 -0
  272. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +44 -0
  273. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +23 -0
  274. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +39 -0
  275. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +64 -0
  276. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +402 -0
  277. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +233 -0
  278. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +276 -0
  279. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +214 -0
  280. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +3 -0
  281. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +65 -0
  282. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +41 -0
  283. xcoll/scattering_routines/geant4/collimasim/pyproject.toml +8 -0
  284. xcoll/scattering_routines/geant4/collimasim/setup.py +144 -0
  285. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +403 -0
  286. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +100 -0
  287. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +763 -0
  288. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +118 -0
  289. xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +8 -0
  290. xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +63 -0
  291. xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +142 -0
  292. xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +556 -0
  293. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +6 -0
  294. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +24 -0
  295. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +1 -0
  296. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +1 -0
  297. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +1 -0
  298. xcoll/scattering_routines/geant4/collimasim/tests/README.md +25 -0
  299. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +25 -0
  300. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +18 -0
  301. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +68 -0
  302. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +15 -0
  303. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +110 -0
  304. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +7 -0
  305. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +3 -0
  306. xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +54 -0
  307. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +3 -0
  308. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +3 -0
  309. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +5 -0
  310. xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +51 -0
  311. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +65 -0
  312. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +59 -0
  313. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +102 -0
  314. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +75 -0
  315. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +74 -0
  316. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +84 -0
  317. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +159 -0
  318. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +99 -0
  319. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +78 -0
  320. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +88 -0
  321. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +80 -0
  322. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +97 -0
  323. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +96 -0
  324. xcoll/scattering_routines/geometry/__init__.py +6 -0
  325. xcoll/scattering_routines/geometry/collimator_geometry.h +218 -0
  326. xcoll/scattering_routines/geometry/crystal_geometry.h +153 -0
  327. xcoll/scattering_routines/geometry/geometry.py +26 -0
  328. xcoll/scattering_routines/geometry/get_s.h +92 -0
  329. xcoll/scattering_routines/geometry/methods.h +111 -0
  330. xcoll/scattering_routines/geometry/objects.h +154 -0
  331. xcoll/scattering_routines/geometry/rotation.h +23 -0
  332. xcoll/scattering_routines/geometry/segments.h +226 -0
  333. xcoll/scattering_routines/geometry/sort.h +184 -0
  334. {xcoll-0.3.6.dist-info → xcoll-0.5.0.dist-info}/METADATA +1 -1
  335. xcoll-0.5.0.dist-info/RECORD +413 -0
  336. xcoll/beam_elements/collimators_src/absorber.h +0 -141
  337. xcoll/beam_elements/collimators_src/everest_collimator.h +0 -142
  338. xcoll/beam_elements/collimators_src/everest_crystal.h +0 -115
  339. xcoll/collimator_settings.py +0 -457
  340. xcoll/impacts/__init__.py +0 -1
  341. xcoll/impacts/impacts.py +0 -102
  342. xcoll/impacts/impacts_src/impacts.h +0 -99
  343. xcoll/scattering_routines/everest/crystal.h +0 -1302
  344. xcoll/scattering_routines/everest/scatter.h +0 -169
  345. xcoll/scattering_routines/everest/scatter_crystal.h +0 -260
  346. xcoll/scattering_routines/fluka/build_fluka_input.py +0 -58
  347. xcoll-0.3.6.dist-info/RECORD +0 -111
  348. {xcoll-0.3.6.dist-info → xcoll-0.5.0.dist-info}/LICENSE +0 -0
  349. {xcoll-0.3.6.dist-info → xcoll-0.5.0.dist-info}/NOTICE +0 -0
  350. {xcoll-0.3.6.dist-info → xcoll-0.5.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,267 @@
1
+ # -*- coding: utf-8 -*-
2
+ import pytest
3
+
4
+ from pybind11_tests import numpy_vectorize as m
5
+
6
+ np = pytest.importorskip("numpy")
7
+
8
+
9
+ def test_vectorize(capture):
10
+ assert np.isclose(m.vectorized_func3(np.array(3 + 7j)), [6 + 14j])
11
+
12
+ for f in [m.vectorized_func, m.vectorized_func2]:
13
+ with capture:
14
+ assert np.isclose(f(1, 2, 3), 6)
15
+ assert capture == "my_func(x:int=1, y:float=2, z:float=3)"
16
+ with capture:
17
+ assert np.isclose(f(np.array(1), np.array(2), 3), 6)
18
+ assert capture == "my_func(x:int=1, y:float=2, z:float=3)"
19
+ with capture:
20
+ assert np.allclose(f(np.array([1, 3]), np.array([2, 4]), 3), [6, 36])
21
+ assert (
22
+ capture
23
+ == """
24
+ my_func(x:int=1, y:float=2, z:float=3)
25
+ my_func(x:int=3, y:float=4, z:float=3)
26
+ """
27
+ )
28
+ with capture:
29
+ a = np.array([[1, 2], [3, 4]], order="F")
30
+ b = np.array([[10, 20], [30, 40]], order="F")
31
+ c = 3
32
+ result = f(a, b, c)
33
+ assert np.allclose(result, a * b * c)
34
+ assert result.flags.f_contiguous
35
+ # All inputs are F order and full or singletons, so we the result is in col-major order:
36
+ assert (
37
+ capture
38
+ == """
39
+ my_func(x:int=1, y:float=10, z:float=3)
40
+ my_func(x:int=3, y:float=30, z:float=3)
41
+ my_func(x:int=2, y:float=20, z:float=3)
42
+ my_func(x:int=4, y:float=40, z:float=3)
43
+ """
44
+ )
45
+ with capture:
46
+ a, b, c = (
47
+ np.array([[1, 3, 5], [7, 9, 11]]),
48
+ np.array([[2, 4, 6], [8, 10, 12]]),
49
+ 3,
50
+ )
51
+ assert np.allclose(f(a, b, c), a * b * c)
52
+ assert (
53
+ capture
54
+ == """
55
+ my_func(x:int=1, y:float=2, z:float=3)
56
+ my_func(x:int=3, y:float=4, z:float=3)
57
+ my_func(x:int=5, y:float=6, z:float=3)
58
+ my_func(x:int=7, y:float=8, z:float=3)
59
+ my_func(x:int=9, y:float=10, z:float=3)
60
+ my_func(x:int=11, y:float=12, z:float=3)
61
+ """
62
+ )
63
+ with capture:
64
+ a, b, c = np.array([[1, 2, 3], [4, 5, 6]]), np.array([2, 3, 4]), 2
65
+ assert np.allclose(f(a, b, c), a * b * c)
66
+ assert (
67
+ capture
68
+ == """
69
+ my_func(x:int=1, y:float=2, z:float=2)
70
+ my_func(x:int=2, y:float=3, z:float=2)
71
+ my_func(x:int=3, y:float=4, z:float=2)
72
+ my_func(x:int=4, y:float=2, z:float=2)
73
+ my_func(x:int=5, y:float=3, z:float=2)
74
+ my_func(x:int=6, y:float=4, z:float=2)
75
+ """
76
+ )
77
+ with capture:
78
+ a, b, c = np.array([[1, 2, 3], [4, 5, 6]]), np.array([[2], [3]]), 2
79
+ assert np.allclose(f(a, b, c), a * b * c)
80
+ assert (
81
+ capture
82
+ == """
83
+ my_func(x:int=1, y:float=2, z:float=2)
84
+ my_func(x:int=2, y:float=2, z:float=2)
85
+ my_func(x:int=3, y:float=2, z:float=2)
86
+ my_func(x:int=4, y:float=3, z:float=2)
87
+ my_func(x:int=5, y:float=3, z:float=2)
88
+ my_func(x:int=6, y:float=3, z:float=2)
89
+ """
90
+ )
91
+ with capture:
92
+ a, b, c = (
93
+ np.array([[1, 2, 3], [4, 5, 6]], order="F"),
94
+ np.array([[2], [3]]),
95
+ 2,
96
+ )
97
+ assert np.allclose(f(a, b, c), a * b * c)
98
+ assert (
99
+ capture
100
+ == """
101
+ my_func(x:int=1, y:float=2, z:float=2)
102
+ my_func(x:int=2, y:float=2, z:float=2)
103
+ my_func(x:int=3, y:float=2, z:float=2)
104
+ my_func(x:int=4, y:float=3, z:float=2)
105
+ my_func(x:int=5, y:float=3, z:float=2)
106
+ my_func(x:int=6, y:float=3, z:float=2)
107
+ """
108
+ )
109
+ with capture:
110
+ a, b, c = np.array([[1, 2, 3], [4, 5, 6]])[::, ::2], np.array([[2], [3]]), 2
111
+ assert np.allclose(f(a, b, c), a * b * c)
112
+ assert (
113
+ capture
114
+ == """
115
+ my_func(x:int=1, y:float=2, z:float=2)
116
+ my_func(x:int=3, y:float=2, z:float=2)
117
+ my_func(x:int=4, y:float=3, z:float=2)
118
+ my_func(x:int=6, y:float=3, z:float=2)
119
+ """
120
+ )
121
+ with capture:
122
+ a, b, c = (
123
+ np.array([[1, 2, 3], [4, 5, 6]], order="F")[::, ::2],
124
+ np.array([[2], [3]]),
125
+ 2,
126
+ )
127
+ assert np.allclose(f(a, b, c), a * b * c)
128
+ assert (
129
+ capture
130
+ == """
131
+ my_func(x:int=1, y:float=2, z:float=2)
132
+ my_func(x:int=3, y:float=2, z:float=2)
133
+ my_func(x:int=4, y:float=3, z:float=2)
134
+ my_func(x:int=6, y:float=3, z:float=2)
135
+ """
136
+ )
137
+
138
+
139
+ def test_type_selection():
140
+ assert m.selective_func(np.array([1], dtype=np.int32)) == "Int branch taken."
141
+ assert m.selective_func(np.array([1.0], dtype=np.float32)) == "Float branch taken."
142
+ assert (
143
+ m.selective_func(np.array([1.0j], dtype=np.complex64))
144
+ == "Complex float branch taken."
145
+ )
146
+
147
+
148
+ def test_docs(doc):
149
+ assert (
150
+ doc(m.vectorized_func)
151
+ == """
152
+ vectorized_func(arg0: numpy.ndarray[numpy.int32], arg1: numpy.ndarray[numpy.float32], arg2: numpy.ndarray[numpy.float64]) -> object
153
+ """ # noqa: E501 line too long
154
+ )
155
+
156
+
157
+ def test_trivial_broadcasting():
158
+ trivial, vectorized_is_trivial = m.trivial, m.vectorized_is_trivial
159
+
160
+ assert vectorized_is_trivial(1, 2, 3) == trivial.c_trivial
161
+ assert vectorized_is_trivial(np.array(1), np.array(2), 3) == trivial.c_trivial
162
+ assert (
163
+ vectorized_is_trivial(np.array([1, 3]), np.array([2, 4]), 3)
164
+ == trivial.c_trivial
165
+ )
166
+ assert trivial.c_trivial == vectorized_is_trivial(
167
+ np.array([[1, 3, 5], [7, 9, 11]]), np.array([[2, 4, 6], [8, 10, 12]]), 3
168
+ )
169
+ assert (
170
+ vectorized_is_trivial(np.array([[1, 2, 3], [4, 5, 6]]), np.array([2, 3, 4]), 2)
171
+ == trivial.non_trivial
172
+ )
173
+ assert (
174
+ vectorized_is_trivial(np.array([[1, 2, 3], [4, 5, 6]]), np.array([[2], [3]]), 2)
175
+ == trivial.non_trivial
176
+ )
177
+ z1 = np.array([[1, 2, 3, 4], [5, 6, 7, 8]], dtype="int32")
178
+ z2 = np.array(z1, dtype="float32")
179
+ z3 = np.array(z1, dtype="float64")
180
+ assert vectorized_is_trivial(z1, z2, z3) == trivial.c_trivial
181
+ assert vectorized_is_trivial(1, z2, z3) == trivial.c_trivial
182
+ assert vectorized_is_trivial(z1, 1, z3) == trivial.c_trivial
183
+ assert vectorized_is_trivial(z1, z2, 1) == trivial.c_trivial
184
+ assert vectorized_is_trivial(z1[::2, ::2], 1, 1) == trivial.non_trivial
185
+ assert vectorized_is_trivial(1, 1, z1[::2, ::2]) == trivial.c_trivial
186
+ assert vectorized_is_trivial(1, 1, z3[::2, ::2]) == trivial.non_trivial
187
+ assert vectorized_is_trivial(z1, 1, z3[1::4, 1::4]) == trivial.c_trivial
188
+
189
+ y1 = np.array(z1, order="F")
190
+ y2 = np.array(y1)
191
+ y3 = np.array(y1)
192
+ assert vectorized_is_trivial(y1, y2, y3) == trivial.f_trivial
193
+ assert vectorized_is_trivial(y1, 1, 1) == trivial.f_trivial
194
+ assert vectorized_is_trivial(1, y2, 1) == trivial.f_trivial
195
+ assert vectorized_is_trivial(1, 1, y3) == trivial.f_trivial
196
+ assert vectorized_is_trivial(y1, z2, 1) == trivial.non_trivial
197
+ assert vectorized_is_trivial(z1[1::4, 1::4], y2, 1) == trivial.f_trivial
198
+ assert vectorized_is_trivial(y1[1::4, 1::4], z2, 1) == trivial.c_trivial
199
+
200
+ assert m.vectorized_func(z1, z2, z3).flags.c_contiguous
201
+ assert m.vectorized_func(y1, y2, y3).flags.f_contiguous
202
+ assert m.vectorized_func(z1, 1, 1).flags.c_contiguous
203
+ assert m.vectorized_func(1, y2, 1).flags.f_contiguous
204
+ assert m.vectorized_func(z1[1::4, 1::4], y2, 1).flags.f_contiguous
205
+ assert m.vectorized_func(y1[1::4, 1::4], z2, 1).flags.c_contiguous
206
+
207
+
208
+ def test_passthrough_arguments(doc):
209
+ assert doc(m.vec_passthrough) == (
210
+ "vec_passthrough("
211
+ + ", ".join(
212
+ [
213
+ "arg0: float",
214
+ "arg1: numpy.ndarray[numpy.float64]",
215
+ "arg2: numpy.ndarray[numpy.float64]",
216
+ "arg3: numpy.ndarray[numpy.int32]",
217
+ "arg4: int",
218
+ "arg5: m.numpy_vectorize.NonPODClass",
219
+ "arg6: numpy.ndarray[numpy.float64]",
220
+ ]
221
+ )
222
+ + ") -> object"
223
+ )
224
+
225
+ b = np.array([[10, 20, 30]], dtype="float64")
226
+ c = np.array([100, 200]) # NOT a vectorized argument
227
+ d = np.array([[1000], [2000], [3000]], dtype="int")
228
+ g = np.array([[1000000, 2000000, 3000000]], dtype="int") # requires casting
229
+ assert np.all(
230
+ m.vec_passthrough(1, b, c, d, 10000, m.NonPODClass(100000), g)
231
+ == np.array(
232
+ [
233
+ [1111111, 2111121, 3111131],
234
+ [1112111, 2112121, 3112131],
235
+ [1113111, 2113121, 3113131],
236
+ ]
237
+ )
238
+ )
239
+
240
+
241
+ def test_method_vectorization():
242
+ o = m.VectorizeTestClass(3)
243
+ x = np.array([1, 2], dtype="int")
244
+ y = np.array([[10], [20]], dtype="float32")
245
+ assert np.all(o.method(x, y) == [[14, 15], [24, 25]])
246
+
247
+
248
+ def test_array_collapse():
249
+ assert not isinstance(m.vectorized_func(1, 2, 3), np.ndarray)
250
+ assert not isinstance(m.vectorized_func(np.array(1), 2, 3), np.ndarray)
251
+ z = m.vectorized_func([1], 2, 3)
252
+ assert isinstance(z, np.ndarray)
253
+ assert z.shape == (1,)
254
+ z = m.vectorized_func(1, [[[2]]], 3)
255
+ assert isinstance(z, np.ndarray)
256
+ assert z.shape == (1, 1, 1)
257
+
258
+
259
+ def test_vectorized_noreturn():
260
+ x = m.NonPODClass(0)
261
+ assert x.value == 0
262
+ m.add_to(x, [1, 2, 3, 4])
263
+ assert x.value == 10
264
+ m.add_to(x, 1)
265
+ assert x.value == 11
266
+ m.add_to(x, [[1, 1], [2, 3]])
267
+ assert x.value == 18
@@ -0,0 +1,73 @@
1
+ /*
2
+ tests/test_opaque_types.cpp -- opaque types, passing void pointers
3
+
4
+ Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5
+
6
+ All rights reserved. Use of this source code is governed by a
7
+ BSD-style license that can be found in the LICENSE file.
8
+ */
9
+
10
+ #include "pybind11_tests.h"
11
+ #include <pybind11/stl.h>
12
+ #include <vector>
13
+
14
+ // IMPORTANT: Disable internal pybind11 translation mechanisms for STL data structures
15
+ //
16
+ // This also deliberately doesn't use the below StringList type alias to test
17
+ // that MAKE_OPAQUE can handle a type containing a `,`. (The `std::allocator`
18
+ // bit is just the default `std::vector` allocator).
19
+ PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
20
+
21
+ using StringList = std::vector<std::string, std::allocator<std::string>>;
22
+
23
+ TEST_SUBMODULE(opaque_types, m) {
24
+ // test_string_list
25
+ py::class_<StringList>(m, "StringList")
26
+ .def(py::init<>())
27
+ .def("pop_back", &StringList::pop_back)
28
+ /* There are multiple versions of push_back(), etc. Select the right ones. */
29
+ .def("push_back", (void (StringList::*)(const std::string &)) &StringList::push_back)
30
+ .def("back", (std::string &(StringList::*)()) &StringList::back)
31
+ .def("__len__", [](const StringList &v) { return v.size(); })
32
+ .def("__iter__", [](StringList &v) {
33
+ return py::make_iterator(v.begin(), v.end());
34
+ }, py::keep_alive<0, 1>());
35
+
36
+ class ClassWithSTLVecProperty {
37
+ public:
38
+ StringList stringList;
39
+ };
40
+ py::class_<ClassWithSTLVecProperty>(m, "ClassWithSTLVecProperty")
41
+ .def(py::init<>())
42
+ .def_readwrite("stringList", &ClassWithSTLVecProperty::stringList);
43
+
44
+ m.def("print_opaque_list", [](const StringList &l) {
45
+ std::string ret = "Opaque list: [";
46
+ bool first = true;
47
+ for (const auto &entry : l) {
48
+ if (!first)
49
+ ret += ", ";
50
+ ret += entry;
51
+ first = false;
52
+ }
53
+ return ret + "]";
54
+ });
55
+
56
+ // test_pointers
57
+ m.def("return_void_ptr", []() { return (void *) 0x1234; });
58
+ m.def("get_void_ptr_value", [](void *ptr) { return reinterpret_cast<std::intptr_t>(ptr); });
59
+ m.def("return_null_str", []() { return (char *) nullptr; });
60
+ m.def("get_null_str_value", [](char *ptr) { return reinterpret_cast<std::intptr_t>(ptr); });
61
+
62
+ m.def("return_unique_ptr", []() -> std::unique_ptr<StringList> {
63
+ auto *result = new StringList();
64
+ result->push_back("some value");
65
+ return std::unique_ptr<StringList>(result);
66
+ });
67
+
68
+ // test unions
69
+ py::class_<IntFloat>(m, "IntFloat")
70
+ .def(py::init<>())
71
+ .def_readwrite("i", &IntFloat::i)
72
+ .def_readwrite("f", &IntFloat::f);
73
+ }
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+ import pytest
3
+
4
+ from pybind11_tests import ConstructorStats, UserType
5
+ from pybind11_tests import opaque_types as m
6
+
7
+
8
+ def test_string_list():
9
+ lst = m.StringList()
10
+ lst.push_back("Element 1")
11
+ lst.push_back("Element 2")
12
+ assert m.print_opaque_list(lst) == "Opaque list: [Element 1, Element 2]"
13
+ assert lst.back() == "Element 2"
14
+
15
+ for i, k in enumerate(lst, start=1):
16
+ assert k == "Element {}".format(i)
17
+ lst.pop_back()
18
+ assert m.print_opaque_list(lst) == "Opaque list: [Element 1]"
19
+
20
+ cvp = m.ClassWithSTLVecProperty()
21
+ assert m.print_opaque_list(cvp.stringList) == "Opaque list: []"
22
+
23
+ cvp.stringList = lst
24
+ cvp.stringList.push_back("Element 3")
25
+ assert m.print_opaque_list(cvp.stringList) == "Opaque list: [Element 1, Element 3]"
26
+
27
+
28
+ def test_pointers(msg):
29
+ living_before = ConstructorStats.get(UserType).alive()
30
+ assert m.get_void_ptr_value(m.return_void_ptr()) == 0x1234
31
+ assert m.get_void_ptr_value(UserType()) # Should also work for other C++ types
32
+ assert ConstructorStats.get(UserType).alive() == living_before
33
+
34
+ with pytest.raises(TypeError) as excinfo:
35
+ m.get_void_ptr_value([1, 2, 3]) # This should not work
36
+ assert (
37
+ msg(excinfo.value)
38
+ == """
39
+ get_void_ptr_value(): incompatible function arguments. The following argument types are supported:
40
+ 1. (arg0: capsule) -> int
41
+
42
+ Invoked with: [1, 2, 3]
43
+ """ # noqa: E501 line too long
44
+ )
45
+
46
+ assert m.return_null_str() is None
47
+ assert m.get_null_str_value(m.return_null_str()) is not None
48
+
49
+ ptr = m.return_unique_ptr()
50
+ assert "StringList" in repr(ptr)
51
+ assert m.print_opaque_list(ptr) == "Opaque list: [some value]"
52
+
53
+
54
+ def test_unions():
55
+ int_float_union = m.IntFloat()
56
+ int_float_union.i = 42
57
+ assert int_float_union.i == 42
58
+ int_float_union.f = 3.0
59
+ assert int_float_union.f == 3.0
@@ -0,0 +1,235 @@
1
+ /*
2
+ tests/test_operator_overloading.cpp -- operator overloading
3
+
4
+ Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5
+
6
+ All rights reserved. Use of this source code is governed by a
7
+ BSD-style license that can be found in the LICENSE file.
8
+ */
9
+
10
+ #include "pybind11_tests.h"
11
+ #include "constructor_stats.h"
12
+ #include <pybind11/operators.h>
13
+ #include <functional>
14
+
15
+ class Vector2 {
16
+ public:
17
+ Vector2(float x, float y) : x(x), y(y) { print_created(this, toString()); }
18
+ Vector2(const Vector2 &v) : x(v.x), y(v.y) { print_copy_created(this); }
19
+ Vector2(Vector2 &&v) noexcept : x(v.x), y(v.y) {
20
+ print_move_created(this);
21
+ v.x = v.y = 0;
22
+ }
23
+ Vector2 &operator=(const Vector2 &v) { x = v.x; y = v.y; print_copy_assigned(this); return *this; }
24
+ Vector2 &operator=(Vector2 &&v) noexcept {
25
+ x = v.x;
26
+ y = v.y;
27
+ v.x = v.y = 0;
28
+ print_move_assigned(this);
29
+ return *this;
30
+ }
31
+ ~Vector2() { print_destroyed(this); }
32
+
33
+ std::string toString() const { return "[" + std::to_string(x) + ", " + std::to_string(y) + "]"; }
34
+
35
+ Vector2 operator-() const { return Vector2(-x, -y); }
36
+ Vector2 operator+(const Vector2 &v) const { return Vector2(x + v.x, y + v.y); }
37
+ Vector2 operator-(const Vector2 &v) const { return Vector2(x - v.x, y - v.y); }
38
+ Vector2 operator-(float value) const { return Vector2(x - value, y - value); }
39
+ Vector2 operator+(float value) const { return Vector2(x + value, y + value); }
40
+ Vector2 operator*(float value) const { return Vector2(x * value, y * value); }
41
+ Vector2 operator/(float value) const { return Vector2(x / value, y / value); }
42
+ Vector2 operator*(const Vector2 &v) const { return Vector2(x * v.x, y * v.y); }
43
+ Vector2 operator/(const Vector2 &v) const { return Vector2(x / v.x, y / v.y); }
44
+ Vector2& operator+=(const Vector2 &v) { x += v.x; y += v.y; return *this; }
45
+ Vector2& operator-=(const Vector2 &v) { x -= v.x; y -= v.y; return *this; }
46
+ Vector2& operator*=(float v) { x *= v; y *= v; return *this; }
47
+ Vector2& operator/=(float v) { x /= v; y /= v; return *this; }
48
+ Vector2& operator*=(const Vector2 &v) { x *= v.x; y *= v.y; return *this; }
49
+ Vector2& operator/=(const Vector2 &v) { x /= v.x; y /= v.y; return *this; }
50
+
51
+ friend Vector2 operator+(float f, const Vector2 &v) { return Vector2(f + v.x, f + v.y); }
52
+ friend Vector2 operator-(float f, const Vector2 &v) { return Vector2(f - v.x, f - v.y); }
53
+ friend Vector2 operator*(float f, const Vector2 &v) { return Vector2(f * v.x, f * v.y); }
54
+ friend Vector2 operator/(float f, const Vector2 &v) { return Vector2(f / v.x, f / v.y); }
55
+
56
+ bool operator==(const Vector2 &v) const {
57
+ return x == v.x && y == v.y;
58
+ }
59
+ bool operator!=(const Vector2 &v) const {
60
+ return x != v.x || y != v.y;
61
+ }
62
+ private:
63
+ float x, y;
64
+ };
65
+
66
+ class C1 { };
67
+ class C2 { };
68
+
69
+ int operator+(const C1 &, const C1 &) { return 11; }
70
+ int operator+(const C2 &, const C2 &) { return 22; }
71
+ int operator+(const C2 &, const C1 &) { return 21; }
72
+ int operator+(const C1 &, const C2 &) { return 12; }
73
+
74
+ // Note: Specializing explicit within `namespace std { ... }` is done due to a
75
+ // bug in GCC<7. If you are supporting compilers later than this, consider
76
+ // specializing `using template<> struct std::hash<...>` in the global
77
+ // namespace instead, per this recommendation:
78
+ // https://en.cppreference.com/w/cpp/language/extending_std#Adding_template_specializations
79
+ namespace std {
80
+ template<>
81
+ struct hash<Vector2> {
82
+ // Not a good hash function, but easy to test
83
+ size_t operator()(const Vector2 &) { return 4; }
84
+ };
85
+ } // namespace std
86
+
87
+ // Not a good abs function, but easy to test.
88
+ std::string abs(const Vector2&) {
89
+ return "abs(Vector2)";
90
+ }
91
+
92
+ // MSVC & Intel warns about unknown pragmas, and warnings are errors.
93
+ #if !defined(_MSC_VER) && !defined(__INTEL_COMPILER)
94
+ #pragma GCC diagnostic push
95
+ // clang 7.0.0 and Apple LLVM 10.0.1 introduce `-Wself-assign-overloaded` to
96
+ // `-Wall`, which is used here for overloading (e.g. `py::self += py::self `).
97
+ // Here, we suppress the warning using `#pragma diagnostic`.
98
+ // Taken from: https://github.com/RobotLocomotion/drake/commit/aaf84b46
99
+ // TODO(eric): This could be resolved using a function / functor (e.g. `py::self()`).
100
+ #if defined(__APPLE__) && defined(__clang__)
101
+ #if (__clang_major__ >= 10)
102
+ #pragma GCC diagnostic ignored "-Wself-assign-overloaded"
103
+ #endif
104
+ #elif defined(__clang__)
105
+ #if (__clang_major__ >= 7)
106
+ #pragma GCC diagnostic ignored "-Wself-assign-overloaded"
107
+ #endif
108
+ #endif
109
+ #endif
110
+
111
+ TEST_SUBMODULE(operators, m) {
112
+
113
+ // test_operator_overloading
114
+ py::class_<Vector2>(m, "Vector2")
115
+ .def(py::init<float, float>())
116
+ .def(py::self + py::self)
117
+ .def(py::self + float())
118
+ .def(py::self - py::self)
119
+ .def(py::self - float())
120
+ .def(py::self * float())
121
+ .def(py::self / float())
122
+ .def(py::self * py::self)
123
+ .def(py::self / py::self)
124
+ .def(py::self += py::self)
125
+ .def(py::self -= py::self)
126
+ .def(py::self *= float())
127
+ .def(py::self /= float())
128
+ .def(py::self *= py::self)
129
+ .def(py::self /= py::self)
130
+ .def(float() + py::self)
131
+ .def(float() - py::self)
132
+ .def(float() * py::self)
133
+ .def(float() / py::self)
134
+ .def(-py::self)
135
+ .def("__str__", &Vector2::toString)
136
+ .def("__repr__", &Vector2::toString)
137
+ .def(py::self == py::self)
138
+ .def(py::self != py::self)
139
+ .def(py::hash(py::self))
140
+ // N.B. See warning about usage of `py::detail::abs(py::self)` in
141
+ // `operators.h`.
142
+ .def("__abs__", [](const Vector2& v) { return abs(v); })
143
+ ;
144
+
145
+ m.attr("Vector") = m.attr("Vector2");
146
+
147
+ // test_operators_notimplemented
148
+ // #393: need to return NotSupported to ensure correct arithmetic operator behavior
149
+ py::class_<C1>(m, "C1")
150
+ .def(py::init<>())
151
+ .def(py::self + py::self);
152
+
153
+ py::class_<C2>(m, "C2")
154
+ .def(py::init<>())
155
+ .def(py::self + py::self)
156
+ .def("__add__", [](const C2& c2, const C1& c1) { return c2 + c1; })
157
+ .def("__radd__", [](const C2& c2, const C1& c1) { return c1 + c2; });
158
+
159
+ // test_nested
160
+ // #328: first member in a class can't be used in operators
161
+ struct NestABase { int value = -2; };
162
+ py::class_<NestABase>(m, "NestABase")
163
+ .def(py::init<>())
164
+ .def_readwrite("value", &NestABase::value);
165
+
166
+ struct NestA : NestABase {
167
+ int value = 3;
168
+ NestA& operator+=(int i) { value += i; return *this; }
169
+ };
170
+ py::class_<NestA>(m, "NestA")
171
+ .def(py::init<>())
172
+ .def(py::self += int())
173
+ .def("as_base", [](NestA &a) -> NestABase& {
174
+ return (NestABase&) a;
175
+ }, py::return_value_policy::reference_internal);
176
+ m.def("get_NestA", [](const NestA &a) { return a.value; });
177
+
178
+ struct NestB {
179
+ NestA a;
180
+ int value = 4;
181
+ NestB& operator-=(int i) { value -= i; return *this; }
182
+ };
183
+ py::class_<NestB>(m, "NestB")
184
+ .def(py::init<>())
185
+ .def(py::self -= int())
186
+ .def_readwrite("a", &NestB::a);
187
+ m.def("get_NestB", [](const NestB &b) { return b.value; });
188
+
189
+ struct NestC {
190
+ NestB b;
191
+ int value = 5;
192
+ NestC& operator*=(int i) { value *= i; return *this; }
193
+ };
194
+ py::class_<NestC>(m, "NestC")
195
+ .def(py::init<>())
196
+ .def(py::self *= int())
197
+ .def_readwrite("b", &NestC::b);
198
+ m.def("get_NestC", [](const NestC &c) { return c.value; });
199
+
200
+
201
+ // test_overriding_eq_reset_hash
202
+ // #2191 Overriding __eq__ should set __hash__ to None
203
+ struct Comparable {
204
+ int value;
205
+ bool operator==(const Comparable& rhs) const {return value == rhs.value;}
206
+ };
207
+
208
+ struct Hashable : Comparable {
209
+ explicit Hashable(int value): Comparable{value}{};
210
+ size_t hash() const { return static_cast<size_t>(value); }
211
+ };
212
+
213
+ struct Hashable2 : Hashable {
214
+ using Hashable::Hashable;
215
+ };
216
+
217
+ py::class_<Comparable>(m, "Comparable")
218
+ .def(py::init<int>())
219
+ .def(py::self == py::self);
220
+
221
+ py::class_<Hashable>(m, "Hashable")
222
+ .def(py::init<int>())
223
+ .def(py::self == py::self)
224
+ .def("__hash__", &Hashable::hash);
225
+
226
+ // define __hash__ before __eq__
227
+ py::class_<Hashable2>(m, "Hashable2")
228
+ .def("__hash__", &Hashable::hash)
229
+ .def(py::init<int>())
230
+ .def(py::self == py::self);
231
+ }
232
+
233
+ #if !defined(_MSC_VER) && !defined(__INTEL_COMPILER)
234
+ #pragma GCC diagnostic pop
235
+ #endif