xcoll 0.4.0__py3-none-any.whl → 0.5.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 (324) hide show
  1. xcoll/__init__.py +2 -1
  2. xcoll/beam_elements/__init__.py +9 -2
  3. xcoll/beam_elements/absorber.py +2 -2
  4. xcoll/beam_elements/base.py +105 -67
  5. xcoll/beam_elements/blowup.py +198 -0
  6. xcoll/beam_elements/{collimators_src → elements_src}/black_absorber.h +21 -3
  7. xcoll/beam_elements/{collimators_src → elements_src}/black_crystal.h +20 -2
  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 +19 -2
  11. xcoll/beam_elements/{collimators_src → elements_src}/everest_collimator.h +19 -3
  12. xcoll/beam_elements/{collimators_src → elements_src}/everest_crystal.h +30 -9
  13. xcoll/beam_elements/everest.py +5 -6
  14. xcoll/beam_elements/monitor.py +428 -0
  15. xcoll/colldb.py +103 -74
  16. xcoll/general.py +4 -4
  17. xcoll/initial_distribution.py +18 -6
  18. xcoll/install.py +3 -1
  19. xcoll/interaction_record/interaction_record.py +127 -81
  20. xcoll/interaction_record/interaction_record_src/interaction_record.h +43 -43
  21. xcoll/line_tools.py +8 -9
  22. xcoll/lossmap.py +48 -38
  23. xcoll/scattering_routines/everest/amorphous.h +4 -11
  24. xcoll/scattering_routines/everest/channeling.h +3 -8
  25. xcoll/scattering_routines/everest/everest.h +4 -1
  26. xcoll/scattering_routines/everest/jaw.h +4 -3
  27. xcoll/scattering_routines/everest/materials.py +35 -15
  28. xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
  29. xcoll/scattering_routines/everest/nuclear_interaction.h +1 -1
  30. xcoll/scattering_routines/everest/properties.h +6 -1
  31. xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
  32. xcoll/scattering_routines/geant4/collimasim/.git +1 -0
  33. xcoll/scattering_routines/geant4/collimasim/.gitignore +12 -0
  34. xcoll/scattering_routines/geant4/collimasim/.gitmodules +3 -0
  35. xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +26 -0
  36. xcoll/scattering_routines/geant4/collimasim/README.md +21 -0
  37. xcoll/scattering_routines/geant4/collimasim/docs/Makefile +20 -0
  38. xcoll/scattering_routines/geant4/collimasim/docs/make.bat +35 -0
  39. xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +10 -0
  40. xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +59 -0
  41. xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +26 -0
  42. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +37 -0
  43. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +19 -0
  44. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +65 -0
  45. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +73 -0
  46. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +1 -0
  47. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +9 -0
  48. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +386 -0
  49. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +45 -0
  50. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +8 -0
  51. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +16 -0
  52. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +8 -0
  53. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +3 -0
  54. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +19 -0
  55. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +969 -0
  56. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +84 -0
  57. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +48 -0
  58. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +16 -0
  59. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +103 -0
  60. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +45 -0
  61. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +151 -0
  62. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +3 -0
  63. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +297 -0
  64. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +29 -0
  65. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +6 -0
  66. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +180 -0
  67. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +23 -0
  68. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +192 -0
  69. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +11 -0
  70. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +81 -0
  71. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +93 -0
  72. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +310 -0
  73. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +109 -0
  74. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +43 -0
  75. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +171 -0
  76. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +251 -0
  77. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +305 -0
  78. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +1297 -0
  79. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +262 -0
  80. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +396 -0
  81. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +568 -0
  82. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +337 -0
  83. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +13 -0
  84. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +463 -0
  85. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +286 -0
  86. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +155 -0
  87. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +174 -0
  88. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +308 -0
  89. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +91 -0
  90. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +95 -0
  91. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +2050 -0
  92. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +542 -0
  93. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +8 -0
  94. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +648 -0
  95. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +381 -0
  96. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +343 -0
  97. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +48 -0
  98. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +105 -0
  99. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +72 -0
  100. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
  101. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
  102. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +427 -0
  103. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
  104. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +427 -0
  105. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +130 -0
  106. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +96 -0
  107. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +8 -0
  108. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +548 -0
  109. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +605 -0
  110. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +144 -0
  111. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +1432 -0
  112. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +213 -0
  113. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +2 -0
  114. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +65 -0
  115. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +709 -0
  116. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +1021 -0
  117. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +104 -0
  118. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +346 -0
  119. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +467 -0
  120. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +978 -0
  121. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +55 -0
  122. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +606 -0
  123. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +284 -0
  124. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +163 -0
  125. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +121 -0
  126. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +193 -0
  127. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +275 -0
  128. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +1741 -0
  129. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +163 -0
  130. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +65 -0
  131. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +2497 -0
  132. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +1879 -0
  133. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +103 -0
  134. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +375 -0
  135. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +747 -0
  136. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +88 -0
  137. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +11 -0
  138. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +52 -0
  139. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +12 -0
  140. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +6 -0
  141. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +21 -0
  142. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
  143. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +482 -0
  144. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +63 -0
  145. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +41 -0
  146. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +56 -0
  147. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +155 -0
  148. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +503 -0
  149. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +208 -0
  150. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +275 -0
  151. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +73 -0
  152. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +33 -0
  153. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
  154. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +279 -0
  155. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
  156. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +143 -0
  157. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +85 -0
  158. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +179 -0
  159. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +151 -0
  160. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +91 -0
  161. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +85 -0
  162. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +19 -0
  163. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +12 -0
  164. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +26 -0
  165. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +25 -0
  166. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +216 -0
  167. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +163 -0
  168. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +286 -0
  169. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +536 -0
  170. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +107 -0
  171. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +248 -0
  172. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +227 -0
  173. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +202 -0
  174. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +84 -0
  175. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +210 -0
  176. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +550 -0
  177. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +473 -0
  178. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +84 -0
  179. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +21 -0
  180. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +28 -0
  181. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +39 -0
  182. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +46 -0
  183. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +6 -0
  184. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +41 -0
  185. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +35 -0
  186. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +41 -0
  187. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +10 -0
  188. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +165 -0
  189. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +53 -0
  190. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +238 -0
  191. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +126 -0
  192. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +141 -0
  193. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +117 -0
  194. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +41 -0
  195. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +50 -0
  196. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +69 -0
  197. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +42 -0
  198. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +348 -0
  199. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +771 -0
  200. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +47 -0
  201. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +22 -0
  202. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +23 -0
  203. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +326 -0
  204. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +15 -0
  205. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +148 -0
  206. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +272 -0
  207. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +119 -0
  208. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +51 -0
  209. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +5 -0
  210. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +285 -0
  211. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +12 -0
  212. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +265 -0
  213. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +397 -0
  214. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +520 -0
  215. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +49 -0
  216. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +94 -0
  217. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +125 -0
  218. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +331 -0
  219. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +153 -0
  220. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +284 -0
  221. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +107 -0
  222. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +257 -0
  223. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +412 -0
  224. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +517 -0
  225. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +102 -0
  226. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +92 -0
  227. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +233 -0
  228. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +360 -0
  229. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +472 -0
  230. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +593 -0
  231. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +524 -0
  232. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +441 -0
  233. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +103 -0
  234. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +267 -0
  235. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +73 -0
  236. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +59 -0
  237. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +235 -0
  238. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +146 -0
  239. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +189 -0
  240. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +82 -0
  241. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +560 -0
  242. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +651 -0
  243. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +500 -0
  244. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +253 -0
  245. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +452 -0
  246. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +318 -0
  247. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +342 -0
  248. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +291 -0
  249. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +131 -0
  250. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +318 -0
  251. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +144 -0
  252. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +29 -0
  253. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +66 -0
  254. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +44 -0
  255. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +22 -0
  256. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +9 -0
  257. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +510 -0
  258. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +408 -0
  259. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +140 -0
  260. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +117 -0
  261. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +70 -0
  262. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +86 -0
  263. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +257 -0
  264. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +44 -0
  265. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +23 -0
  266. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +39 -0
  267. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +64 -0
  268. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +402 -0
  269. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +233 -0
  270. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +276 -0
  271. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +214 -0
  272. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +3 -0
  273. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +65 -0
  274. xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +41 -0
  275. xcoll/scattering_routines/geant4/collimasim/pyproject.toml +8 -0
  276. xcoll/scattering_routines/geant4/collimasim/setup.py +144 -0
  277. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +403 -0
  278. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +100 -0
  279. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +763 -0
  280. xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +118 -0
  281. xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +8 -0
  282. xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +63 -0
  283. xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +142 -0
  284. xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +556 -0
  285. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +6 -0
  286. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +24 -0
  287. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +1 -0
  288. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +1 -0
  289. xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +1 -0
  290. xcoll/scattering_routines/geant4/collimasim/tests/README.md +25 -0
  291. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +25 -0
  292. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +18 -0
  293. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +68 -0
  294. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +15 -0
  295. xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +110 -0
  296. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +7 -0
  297. xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +3 -0
  298. xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +54 -0
  299. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +3 -0
  300. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +3 -0
  301. xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +5 -0
  302. xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +51 -0
  303. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +65 -0
  304. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +59 -0
  305. xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +102 -0
  306. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +75 -0
  307. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +74 -0
  308. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +84 -0
  309. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +159 -0
  310. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +99 -0
  311. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +78 -0
  312. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +88 -0
  313. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +80 -0
  314. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +97 -0
  315. xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +96 -0
  316. xcoll/scattering_routines/geometry/collimator_geometry.h +9 -10
  317. xcoll/scattering_routines/geometry/crystal_geometry.h +9 -6
  318. {xcoll-0.4.0.dist-info → xcoll-0.5.1.dist-info}/METADATA +1 -1
  319. xcoll-0.5.1.dist-info/RECORD +413 -0
  320. xcoll/scattering_routines/fluka/build_fluka_input.py +0 -58
  321. xcoll-0.4.0.dist-info/RECORD +0 -126
  322. {xcoll-0.4.0.dist-info → xcoll-0.5.1.dist-info}/LICENSE +0 -0
  323. {xcoll-0.4.0.dist-info → xcoll-0.5.1.dist-info}/NOTICE +0 -0
  324. {xcoll-0.4.0.dist-info → xcoll-0.5.1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,55 @@
1
+ /*
2
+ pybind11/detail/typeid.h: Compiler-independent access to type identifiers
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
+ #pragma once
11
+
12
+ #include <cstdio>
13
+ #include <cstdlib>
14
+
15
+ #if defined(__GNUG__)
16
+ #include <cxxabi.h>
17
+ #endif
18
+
19
+ #include "common.h"
20
+
21
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
22
+ PYBIND11_NAMESPACE_BEGIN(detail)
23
+ /// Erase all occurrences of a substring
24
+ inline void erase_all(std::string &string, const std::string &search) {
25
+ for (size_t pos = 0;;) {
26
+ pos = string.find(search, pos);
27
+ if (pos == std::string::npos) break;
28
+ string.erase(pos, search.length());
29
+ }
30
+ }
31
+
32
+ PYBIND11_NOINLINE void clean_type_id(std::string &name) {
33
+ #if defined(__GNUG__)
34
+ int status = 0;
35
+ std::unique_ptr<char, void (*)(void *)> res {
36
+ abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free };
37
+ if (status == 0)
38
+ name = res.get();
39
+ #else
40
+ detail::erase_all(name, "class ");
41
+ detail::erase_all(name, "struct ");
42
+ detail::erase_all(name, "enum ");
43
+ #endif
44
+ detail::erase_all(name, "pybind11::");
45
+ }
46
+ PYBIND11_NAMESPACE_END(detail)
47
+
48
+ /// Return a string representation of a C++ type
49
+ template <typename T> static std::string type_id() {
50
+ std::string name(typeid(T).name());
51
+ detail::clean_type_id(name);
52
+ return name;
53
+ }
54
+
55
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
@@ -0,0 +1,606 @@
1
+ /*
2
+ pybind11/eigen.h: Transparent conversion for dense and sparse Eigen matrices
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
+ #pragma once
11
+
12
+ /* HINT: To suppress warnings originating from the Eigen headers, use -isystem.
13
+ See also:
14
+ https://stackoverflow.com/questions/2579576/i-dir-vs-isystem-dir
15
+ https://stackoverflow.com/questions/1741816/isystem-for-ms-visual-studio-c-compiler
16
+ */
17
+
18
+ #include "numpy.h"
19
+
20
+ // The C4127 suppression was introduced for Eigen 3.4.0. In theory we could
21
+ // make it version specific, or even remove it later, but considering that
22
+ // 1. C4127 is generally far more distracting than useful for modern template code, and
23
+ // 2. we definitely want to ignore any MSVC warnings originating from Eigen code,
24
+ // it is probably best to keep this around indefinitely.
25
+ #if defined(_MSC_VER)
26
+ # pragma warning(push)
27
+ # pragma warning(disable: 4127) // C4127: conditional expression is constant
28
+ #endif
29
+
30
+ #include <Eigen/Core>
31
+ #include <Eigen/SparseCore>
32
+
33
+ #if defined(_MSC_VER)
34
+ # pragma warning(pop)
35
+ #endif
36
+
37
+ // Eigen prior to 3.2.7 doesn't have proper move constructors--but worse, some classes get implicit
38
+ // move constructors that break things. We could detect this an explicitly copy, but an extra copy
39
+ // of matrices seems highly undesirable.
40
+ static_assert(EIGEN_VERSION_AT_LEAST(3,2,7), "Eigen support in pybind11 requires Eigen >= 3.2.7");
41
+
42
+ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
43
+
44
+ // Provide a convenience alias for easier pass-by-ref usage with fully dynamic strides:
45
+ using EigenDStride = Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>;
46
+ template <typename MatrixType> using EigenDRef = Eigen::Ref<MatrixType, 0, EigenDStride>;
47
+ template <typename MatrixType> using EigenDMap = Eigen::Map<MatrixType, 0, EigenDStride>;
48
+
49
+ PYBIND11_NAMESPACE_BEGIN(detail)
50
+
51
+ #if EIGEN_VERSION_AT_LEAST(3,3,0)
52
+ using EigenIndex = Eigen::Index;
53
+ #else
54
+ using EigenIndex = EIGEN_DEFAULT_DENSE_INDEX_TYPE;
55
+ #endif
56
+
57
+ // Matches Eigen::Map, Eigen::Ref, blocks, etc:
58
+ template <typename T> using is_eigen_dense_map = all_of<is_template_base_of<Eigen::DenseBase, T>, std::is_base_of<Eigen::MapBase<T, Eigen::ReadOnlyAccessors>, T>>;
59
+ template <typename T> using is_eigen_mutable_map = std::is_base_of<Eigen::MapBase<T, Eigen::WriteAccessors>, T>;
60
+ template <typename T> using is_eigen_dense_plain = all_of<negation<is_eigen_dense_map<T>>, is_template_base_of<Eigen::PlainObjectBase, T>>;
61
+ template <typename T> using is_eigen_sparse = is_template_base_of<Eigen::SparseMatrixBase, T>;
62
+ // Test for objects inheriting from EigenBase<Derived> that aren't captured by the above. This
63
+ // basically covers anything that can be assigned to a dense matrix but that don't have a typical
64
+ // matrix data layout that can be copied from their .data(). For example, DiagonalMatrix and
65
+ // SelfAdjointView fall into this category.
66
+ template <typename T> using is_eigen_other = all_of<
67
+ is_template_base_of<Eigen::EigenBase, T>,
68
+ negation<any_of<is_eigen_dense_map<T>, is_eigen_dense_plain<T>, is_eigen_sparse<T>>>
69
+ >;
70
+
71
+ // Captures numpy/eigen conformability status (returned by EigenProps::conformable()):
72
+ template <bool EigenRowMajor> struct EigenConformable {
73
+ bool conformable = false;
74
+ EigenIndex rows = 0, cols = 0;
75
+ EigenDStride stride{0, 0}; // Only valid if negativestrides is false!
76
+ bool negativestrides = false; // If true, do not use stride!
77
+
78
+ // NOLINTNEXTLINE(google-explicit-constructor)
79
+ EigenConformable(bool fits = false) : conformable{fits} {}
80
+ // Matrix type:
81
+ EigenConformable(EigenIndex r, EigenIndex c,
82
+ EigenIndex rstride, EigenIndex cstride) :
83
+ conformable{true}, rows{r}, cols{c} {
84
+ // TODO: when Eigen bug #747 is fixed, remove the tests for non-negativity. http://eigen.tuxfamily.org/bz/show_bug.cgi?id=747
85
+ if (rstride < 0 || cstride < 0) {
86
+ negativestrides = true;
87
+ } else {
88
+ stride = {EigenRowMajor ? rstride : cstride /* outer stride */,
89
+ EigenRowMajor ? cstride : rstride /* inner stride */ };
90
+ }
91
+ }
92
+ // Vector type:
93
+ EigenConformable(EigenIndex r, EigenIndex c, EigenIndex stride)
94
+ : EigenConformable(r, c, r == 1 ? c*stride : stride, c == 1 ? r : r*stride) {}
95
+
96
+ template <typename props> bool stride_compatible() const {
97
+ // To have compatible strides, we need (on both dimensions) one of fully dynamic strides,
98
+ // matching strides, or a dimension size of 1 (in which case the stride value is irrelevant)
99
+ return
100
+ !negativestrides &&
101
+ (props::inner_stride == Eigen::Dynamic || props::inner_stride == stride.inner() ||
102
+ (EigenRowMajor ? cols : rows) == 1) &&
103
+ (props::outer_stride == Eigen::Dynamic || props::outer_stride == stride.outer() ||
104
+ (EigenRowMajor ? rows : cols) == 1);
105
+ }
106
+ // NOLINTNEXTLINE(google-explicit-constructor)
107
+ operator bool() const { return conformable; }
108
+ };
109
+
110
+ template <typename Type> struct eigen_extract_stride { using type = Type; };
111
+ template <typename PlainObjectType, int MapOptions, typename StrideType>
112
+ struct eigen_extract_stride<Eigen::Map<PlainObjectType, MapOptions, StrideType>> { using type = StrideType; };
113
+ template <typename PlainObjectType, int Options, typename StrideType>
114
+ struct eigen_extract_stride<Eigen::Ref<PlainObjectType, Options, StrideType>> { using type = StrideType; };
115
+
116
+ // Helper struct for extracting information from an Eigen type
117
+ template <typename Type_> struct EigenProps {
118
+ using Type = Type_;
119
+ using Scalar = typename Type::Scalar;
120
+ using StrideType = typename eigen_extract_stride<Type>::type;
121
+ static constexpr EigenIndex
122
+ rows = Type::RowsAtCompileTime,
123
+ cols = Type::ColsAtCompileTime,
124
+ size = Type::SizeAtCompileTime;
125
+ static constexpr bool
126
+ row_major = Type::IsRowMajor,
127
+ vector = Type::IsVectorAtCompileTime, // At least one dimension has fixed size 1
128
+ fixed_rows = rows != Eigen::Dynamic,
129
+ fixed_cols = cols != Eigen::Dynamic,
130
+ fixed = size != Eigen::Dynamic, // Fully-fixed size
131
+ dynamic = !fixed_rows && !fixed_cols; // Fully-dynamic size
132
+
133
+ template <EigenIndex i, EigenIndex ifzero> using if_zero = std::integral_constant<EigenIndex, i == 0 ? ifzero : i>;
134
+ static constexpr EigenIndex inner_stride = if_zero<StrideType::InnerStrideAtCompileTime, 1>::value,
135
+ outer_stride = if_zero<StrideType::OuterStrideAtCompileTime,
136
+ vector ? size : row_major ? cols : rows>::value;
137
+ static constexpr bool dynamic_stride = inner_stride == Eigen::Dynamic && outer_stride == Eigen::Dynamic;
138
+ static constexpr bool requires_row_major = !dynamic_stride && !vector && (row_major ? inner_stride : outer_stride) == 1;
139
+ static constexpr bool requires_col_major = !dynamic_stride && !vector && (row_major ? outer_stride : inner_stride) == 1;
140
+
141
+ // Takes an input array and determines whether we can make it fit into the Eigen type. If
142
+ // the array is a vector, we attempt to fit it into either an Eigen 1xN or Nx1 vector
143
+ // (preferring the latter if it will fit in either, i.e. for a fully dynamic matrix type).
144
+ static EigenConformable<row_major> conformable(const array &a) {
145
+ const auto dims = a.ndim();
146
+ if (dims < 1 || dims > 2)
147
+ return false;
148
+
149
+ if (dims == 2) { // Matrix type: require exact match (or dynamic)
150
+
151
+ EigenIndex
152
+ np_rows = a.shape(0),
153
+ np_cols = a.shape(1),
154
+ np_rstride = a.strides(0) / static_cast<ssize_t>(sizeof(Scalar)),
155
+ np_cstride = a.strides(1) / static_cast<ssize_t>(sizeof(Scalar));
156
+ if ((PYBIND11_SILENCE_MSVC_C4127(fixed_rows) && np_rows != rows) ||
157
+ (PYBIND11_SILENCE_MSVC_C4127(fixed_cols) && np_cols != cols))
158
+ return false;
159
+
160
+ return {np_rows, np_cols, np_rstride, np_cstride};
161
+ }
162
+
163
+ // Otherwise we're storing an n-vector. Only one of the strides will be used, but whichever
164
+ // is used, we want the (single) numpy stride value.
165
+ const EigenIndex n = a.shape(0),
166
+ stride = a.strides(0) / static_cast<ssize_t>(sizeof(Scalar));
167
+
168
+ if (vector) { // Eigen type is a compile-time vector
169
+ if (PYBIND11_SILENCE_MSVC_C4127(fixed) && size != n)
170
+ return false; // Vector size mismatch
171
+ return {rows == 1 ? 1 : n, cols == 1 ? 1 : n, stride};
172
+ }
173
+ if (fixed) {
174
+ // The type has a fixed size, but is not a vector: abort
175
+ return false;
176
+ }
177
+ if (fixed_cols) {
178
+ // Since this isn't a vector, cols must be != 1. We allow this only if it exactly
179
+ // equals the number of elements (rows is Dynamic, and so 1 row is allowed).
180
+ if (cols != n) return false;
181
+ return {1, n, stride};
182
+ } // Otherwise it's either fully dynamic, or column dynamic; both become a column vector
183
+ if (PYBIND11_SILENCE_MSVC_C4127(fixed_rows) && rows != n) return false;
184
+ return {n, 1, stride};
185
+ }
186
+
187
+ static constexpr bool show_writeable = is_eigen_dense_map<Type>::value && is_eigen_mutable_map<Type>::value;
188
+ static constexpr bool show_order = is_eigen_dense_map<Type>::value;
189
+ static constexpr bool show_c_contiguous = show_order && requires_row_major;
190
+ static constexpr bool show_f_contiguous = !show_c_contiguous && show_order && requires_col_major;
191
+
192
+ static constexpr auto descriptor =
193
+ _("numpy.ndarray[") + npy_format_descriptor<Scalar>::name +
194
+ _("[") + _<fixed_rows>(_<(size_t) rows>(), _("m")) +
195
+ _(", ") + _<fixed_cols>(_<(size_t) cols>(), _("n")) +
196
+ _("]") +
197
+ // For a reference type (e.g. Ref<MatrixXd>) we have other constraints that might need to be
198
+ // satisfied: writeable=True (for a mutable reference), and, depending on the map's stride
199
+ // options, possibly f_contiguous or c_contiguous. We include them in the descriptor output
200
+ // to provide some hint as to why a TypeError is occurring (otherwise it can be confusing to
201
+ // see that a function accepts a 'numpy.ndarray[float64[3,2]]' and an error message that you
202
+ // *gave* a numpy.ndarray of the right type and dimensions.
203
+ _<show_writeable>(", flags.writeable", "") +
204
+ _<show_c_contiguous>(", flags.c_contiguous", "") +
205
+ _<show_f_contiguous>(", flags.f_contiguous", "") +
206
+ _("]");
207
+ };
208
+
209
+ // Casts an Eigen type to numpy array. If given a base, the numpy array references the src data,
210
+ // otherwise it'll make a copy. writeable lets you turn off the writeable flag for the array.
211
+ template <typename props> handle eigen_array_cast(typename props::Type const &src, handle base = handle(), bool writeable = true) {
212
+ constexpr ssize_t elem_size = sizeof(typename props::Scalar);
213
+ array a;
214
+ if (props::vector)
215
+ a = array({ src.size() }, { elem_size * src.innerStride() }, src.data(), base);
216
+ else
217
+ a = array({ src.rows(), src.cols() }, { elem_size * src.rowStride(), elem_size * src.colStride() },
218
+ src.data(), base);
219
+
220
+ if (!writeable)
221
+ array_proxy(a.ptr())->flags &= ~detail::npy_api::NPY_ARRAY_WRITEABLE_;
222
+
223
+ return a.release();
224
+ }
225
+
226
+ // Takes an lvalue ref to some Eigen type and a (python) base object, creating a numpy array that
227
+ // reference the Eigen object's data with `base` as the python-registered base class (if omitted,
228
+ // the base will be set to None, and lifetime management is up to the caller). The numpy array is
229
+ // non-writeable if the given type is const.
230
+ template <typename props, typename Type>
231
+ handle eigen_ref_array(Type &src, handle parent = none()) {
232
+ // none here is to get past array's should-we-copy detection, which currently always
233
+ // copies when there is no base. Setting the base to None should be harmless.
234
+ return eigen_array_cast<props>(src, parent, !std::is_const<Type>::value);
235
+ }
236
+
237
+ // Takes a pointer to some dense, plain Eigen type, builds a capsule around it, then returns a numpy
238
+ // array that references the encapsulated data with a python-side reference to the capsule to tie
239
+ // its destruction to that of any dependent python objects. Const-ness is determined by whether or
240
+ // not the Type of the pointer given is const.
241
+ template <typename props, typename Type, typename = enable_if_t<is_eigen_dense_plain<Type>::value>>
242
+ handle eigen_encapsulate(Type *src) {
243
+ capsule base(src, [](void *o) { delete static_cast<Type *>(o); });
244
+ return eigen_ref_array<props>(*src, base);
245
+ }
246
+
247
+ // Type caster for regular, dense matrix types (e.g. MatrixXd), but not maps/refs/etc. of dense
248
+ // types.
249
+ template<typename Type>
250
+ struct type_caster<Type, enable_if_t<is_eigen_dense_plain<Type>::value>> {
251
+ using Scalar = typename Type::Scalar;
252
+ using props = EigenProps<Type>;
253
+
254
+ bool load(handle src, bool convert) {
255
+ // If we're in no-convert mode, only load if given an array of the correct type
256
+ if (!convert && !isinstance<array_t<Scalar>>(src))
257
+ return false;
258
+
259
+ // Coerce into an array, but don't do type conversion yet; the copy below handles it.
260
+ auto buf = array::ensure(src);
261
+
262
+ if (!buf)
263
+ return false;
264
+
265
+ auto dims = buf.ndim();
266
+ if (dims < 1 || dims > 2)
267
+ return false;
268
+
269
+ auto fits = props::conformable(buf);
270
+ if (!fits)
271
+ return false;
272
+
273
+ // Allocate the new type, then build a numpy reference into it
274
+ value = Type(fits.rows, fits.cols);
275
+ auto ref = reinterpret_steal<array>(eigen_ref_array<props>(value));
276
+ if (dims == 1) ref = ref.squeeze();
277
+ else if (ref.ndim() == 1) buf = buf.squeeze();
278
+
279
+ int result = detail::npy_api::get().PyArray_CopyInto_(ref.ptr(), buf.ptr());
280
+
281
+ if (result < 0) { // Copy failed!
282
+ PyErr_Clear();
283
+ return false;
284
+ }
285
+
286
+ return true;
287
+ }
288
+
289
+ private:
290
+
291
+ // Cast implementation
292
+ template <typename CType>
293
+ static handle cast_impl(CType *src, return_value_policy policy, handle parent) {
294
+ switch (policy) {
295
+ case return_value_policy::take_ownership:
296
+ case return_value_policy::automatic:
297
+ return eigen_encapsulate<props>(src);
298
+ case return_value_policy::move:
299
+ return eigen_encapsulate<props>(new CType(std::move(*src)));
300
+ case return_value_policy::copy:
301
+ return eigen_array_cast<props>(*src);
302
+ case return_value_policy::reference:
303
+ case return_value_policy::automatic_reference:
304
+ return eigen_ref_array<props>(*src);
305
+ case return_value_policy::reference_internal:
306
+ return eigen_ref_array<props>(*src, parent);
307
+ default:
308
+ throw cast_error("unhandled return_value_policy: should not happen!");
309
+ };
310
+ }
311
+
312
+ public:
313
+
314
+ // Normal returned non-reference, non-const value:
315
+ static handle cast(Type &&src, return_value_policy /* policy */, handle parent) {
316
+ return cast_impl(&src, return_value_policy::move, parent);
317
+ }
318
+ // If you return a non-reference const, we mark the numpy array readonly:
319
+ static handle cast(const Type &&src, return_value_policy /* policy */, handle parent) {
320
+ return cast_impl(&src, return_value_policy::move, parent);
321
+ }
322
+ // lvalue reference return; default (automatic) becomes copy
323
+ static handle cast(Type &src, return_value_policy policy, handle parent) {
324
+ if (policy == return_value_policy::automatic || policy == return_value_policy::automatic_reference)
325
+ policy = return_value_policy::copy;
326
+ return cast_impl(&src, policy, parent);
327
+ }
328
+ // const lvalue reference return; default (automatic) becomes copy
329
+ static handle cast(const Type &src, return_value_policy policy, handle parent) {
330
+ if (policy == return_value_policy::automatic || policy == return_value_policy::automatic_reference)
331
+ policy = return_value_policy::copy;
332
+ return cast(&src, policy, parent);
333
+ }
334
+ // non-const pointer return
335
+ static handle cast(Type *src, return_value_policy policy, handle parent) {
336
+ return cast_impl(src, policy, parent);
337
+ }
338
+ // const pointer return
339
+ static handle cast(const Type *src, return_value_policy policy, handle parent) {
340
+ return cast_impl(src, policy, parent);
341
+ }
342
+
343
+ static constexpr auto name = props::descriptor;
344
+
345
+ // NOLINTNEXTLINE(google-explicit-constructor)
346
+ operator Type*() { return &value; }
347
+ // NOLINTNEXTLINE(google-explicit-constructor)
348
+ operator Type&() { return value; }
349
+ // NOLINTNEXTLINE(google-explicit-constructor)
350
+ operator Type&&() && { return std::move(value); }
351
+ template <typename T> using cast_op_type = movable_cast_op_type<T>;
352
+
353
+ private:
354
+ Type value;
355
+ };
356
+
357
+ // Base class for casting reference/map/block/etc. objects back to python.
358
+ template <typename MapType> struct eigen_map_caster {
359
+ private:
360
+ using props = EigenProps<MapType>;
361
+
362
+ public:
363
+
364
+ // Directly referencing a ref/map's data is a bit dangerous (whatever the map/ref points to has
365
+ // to stay around), but we'll allow it under the assumption that you know what you're doing (and
366
+ // have an appropriate keep_alive in place). We return a numpy array pointing directly at the
367
+ // ref's data (The numpy array ends up read-only if the ref was to a const matrix type.) Note
368
+ // that this means you need to ensure you don't destroy the object in some other way (e.g. with
369
+ // an appropriate keep_alive, or with a reference to a statically allocated matrix).
370
+ static handle cast(const MapType &src, return_value_policy policy, handle parent) {
371
+ switch (policy) {
372
+ case return_value_policy::copy:
373
+ return eigen_array_cast<props>(src);
374
+ case return_value_policy::reference_internal:
375
+ return eigen_array_cast<props>(src, parent, is_eigen_mutable_map<MapType>::value);
376
+ case return_value_policy::reference:
377
+ case return_value_policy::automatic:
378
+ case return_value_policy::automatic_reference:
379
+ return eigen_array_cast<props>(src, none(), is_eigen_mutable_map<MapType>::value);
380
+ default:
381
+ // move, take_ownership don't make any sense for a ref/map:
382
+ pybind11_fail("Invalid return_value_policy for Eigen Map/Ref/Block type");
383
+ }
384
+ }
385
+
386
+ static constexpr auto name = props::descriptor;
387
+
388
+ // Explicitly delete these: support python -> C++ conversion on these (i.e. these can be return
389
+ // types but not bound arguments). We still provide them (with an explicitly delete) so that
390
+ // you end up here if you try anyway.
391
+ bool load(handle, bool) = delete;
392
+ operator MapType() = delete;
393
+ template <typename> using cast_op_type = MapType;
394
+ };
395
+
396
+ // We can return any map-like object (but can only load Refs, specialized next):
397
+ template <typename Type> struct type_caster<Type, enable_if_t<is_eigen_dense_map<Type>::value>>
398
+ : eigen_map_caster<Type> {};
399
+
400
+ // Loader for Ref<...> arguments. See the documentation for info on how to make this work without
401
+ // copying (it requires some extra effort in many cases).
402
+ template <typename PlainObjectType, typename StrideType>
403
+ struct type_caster<
404
+ Eigen::Ref<PlainObjectType, 0, StrideType>,
405
+ enable_if_t<is_eigen_dense_map<Eigen::Ref<PlainObjectType, 0, StrideType>>::value>
406
+ > : public eigen_map_caster<Eigen::Ref<PlainObjectType, 0, StrideType>> {
407
+ private:
408
+ using Type = Eigen::Ref<PlainObjectType, 0, StrideType>;
409
+ using props = EigenProps<Type>;
410
+ using Scalar = typename props::Scalar;
411
+ using MapType = Eigen::Map<PlainObjectType, 0, StrideType>;
412
+ using Array = array_t<Scalar, array::forcecast |
413
+ ((props::row_major ? props::inner_stride : props::outer_stride) == 1 ? array::c_style :
414
+ (props::row_major ? props::outer_stride : props::inner_stride) == 1 ? array::f_style : 0)>;
415
+ static constexpr bool need_writeable = is_eigen_mutable_map<Type>::value;
416
+ // Delay construction (these have no default constructor)
417
+ std::unique_ptr<MapType> map;
418
+ std::unique_ptr<Type> ref;
419
+ // Our array. When possible, this is just a numpy array pointing to the source data, but
420
+ // sometimes we can't avoid copying (e.g. input is not a numpy array at all, has an incompatible
421
+ // layout, or is an array of a type that needs to be converted). Using a numpy temporary
422
+ // (rather than an Eigen temporary) saves an extra copy when we need both type conversion and
423
+ // storage order conversion. (Note that we refuse to use this temporary copy when loading an
424
+ // argument for a Ref<M> with M non-const, i.e. a read-write reference).
425
+ Array copy_or_ref;
426
+ public:
427
+ bool load(handle src, bool convert) {
428
+ // First check whether what we have is already an array of the right type. If not, we can't
429
+ // avoid a copy (because the copy is also going to do type conversion).
430
+ bool need_copy = !isinstance<Array>(src);
431
+
432
+ EigenConformable<props::row_major> fits;
433
+ if (!need_copy) {
434
+ // We don't need a converting copy, but we also need to check whether the strides are
435
+ // compatible with the Ref's stride requirements
436
+ auto aref = reinterpret_borrow<Array>(src);
437
+
438
+ if (aref && (!need_writeable || aref.writeable())) {
439
+ fits = props::conformable(aref);
440
+ if (!fits) return false; // Incompatible dimensions
441
+ if (!fits.template stride_compatible<props>())
442
+ need_copy = true;
443
+ else
444
+ copy_or_ref = std::move(aref);
445
+ }
446
+ else {
447
+ need_copy = true;
448
+ }
449
+ }
450
+
451
+ if (need_copy) {
452
+ // We need to copy: If we need a mutable reference, or we're not supposed to convert
453
+ // (either because we're in the no-convert overload pass, or because we're explicitly
454
+ // instructed not to copy (via `py::arg().noconvert()`) we have to fail loading.
455
+ if (!convert || need_writeable) return false;
456
+
457
+ Array copy = Array::ensure(src);
458
+ if (!copy) return false;
459
+ fits = props::conformable(copy);
460
+ if (!fits || !fits.template stride_compatible<props>())
461
+ return false;
462
+ copy_or_ref = std::move(copy);
463
+ loader_life_support::add_patient(copy_or_ref);
464
+ }
465
+
466
+ ref.reset();
467
+ map.reset(new MapType(data(copy_or_ref), fits.rows, fits.cols, make_stride(fits.stride.outer(), fits.stride.inner())));
468
+ ref.reset(new Type(*map));
469
+
470
+ return true;
471
+ }
472
+
473
+ // NOLINTNEXTLINE(google-explicit-constructor)
474
+ operator Type*() { return ref.get(); }
475
+ // NOLINTNEXTLINE(google-explicit-constructor)
476
+ operator Type&() { return *ref; }
477
+ template <typename _T> using cast_op_type = pybind11::detail::cast_op_type<_T>;
478
+
479
+ private:
480
+ template <typename T = Type, enable_if_t<is_eigen_mutable_map<T>::value, int> = 0>
481
+ Scalar *data(Array &a) { return a.mutable_data(); }
482
+
483
+ template <typename T = Type, enable_if_t<!is_eigen_mutable_map<T>::value, int> = 0>
484
+ const Scalar *data(Array &a) { return a.data(); }
485
+
486
+ // Attempt to figure out a constructor of `Stride` that will work.
487
+ // If both strides are fixed, use a default constructor:
488
+ template <typename S> using stride_ctor_default = bool_constant<
489
+ S::InnerStrideAtCompileTime != Eigen::Dynamic && S::OuterStrideAtCompileTime != Eigen::Dynamic &&
490
+ std::is_default_constructible<S>::value>;
491
+ // Otherwise, if there is a two-index constructor, assume it is (outer,inner) like
492
+ // Eigen::Stride, and use it:
493
+ template <typename S> using stride_ctor_dual = bool_constant<
494
+ !stride_ctor_default<S>::value && std::is_constructible<S, EigenIndex, EigenIndex>::value>;
495
+ // Otherwise, if there is a one-index constructor, and just one of the strides is dynamic, use
496
+ // it (passing whichever stride is dynamic).
497
+ template <typename S> using stride_ctor_outer = bool_constant<
498
+ !any_of<stride_ctor_default<S>, stride_ctor_dual<S>>::value &&
499
+ S::OuterStrideAtCompileTime == Eigen::Dynamic && S::InnerStrideAtCompileTime != Eigen::Dynamic &&
500
+ std::is_constructible<S, EigenIndex>::value>;
501
+ template <typename S> using stride_ctor_inner = bool_constant<
502
+ !any_of<stride_ctor_default<S>, stride_ctor_dual<S>>::value &&
503
+ S::InnerStrideAtCompileTime == Eigen::Dynamic && S::OuterStrideAtCompileTime != Eigen::Dynamic &&
504
+ std::is_constructible<S, EigenIndex>::value>;
505
+
506
+ template <typename S = StrideType, enable_if_t<stride_ctor_default<S>::value, int> = 0>
507
+ static S make_stride(EigenIndex, EigenIndex) { return S(); }
508
+ template <typename S = StrideType, enable_if_t<stride_ctor_dual<S>::value, int> = 0>
509
+ static S make_stride(EigenIndex outer, EigenIndex inner) { return S(outer, inner); }
510
+ template <typename S = StrideType, enable_if_t<stride_ctor_outer<S>::value, int> = 0>
511
+ static S make_stride(EigenIndex outer, EigenIndex) { return S(outer); }
512
+ template <typename S = StrideType, enable_if_t<stride_ctor_inner<S>::value, int> = 0>
513
+ static S make_stride(EigenIndex, EigenIndex inner) { return S(inner); }
514
+
515
+ };
516
+
517
+ // type_caster for special matrix types (e.g. DiagonalMatrix), which are EigenBase, but not
518
+ // EigenDense (i.e. they don't have a data(), at least not with the usual matrix layout).
519
+ // load() is not supported, but we can cast them into the python domain by first copying to a
520
+ // regular Eigen::Matrix, then casting that.
521
+ template <typename Type>
522
+ struct type_caster<Type, enable_if_t<is_eigen_other<Type>::value>> {
523
+ protected:
524
+ using Matrix = Eigen::Matrix<typename Type::Scalar, Type::RowsAtCompileTime, Type::ColsAtCompileTime>;
525
+ using props = EigenProps<Matrix>;
526
+ public:
527
+ static handle cast(const Type &src, return_value_policy /* policy */, handle /* parent */) {
528
+ handle h = eigen_encapsulate<props>(new Matrix(src));
529
+ return h;
530
+ }
531
+ static handle cast(const Type *src, return_value_policy policy, handle parent) { return cast(*src, policy, parent); }
532
+
533
+ static constexpr auto name = props::descriptor;
534
+
535
+ // Explicitly delete these: support python -> C++ conversion on these (i.e. these can be return
536
+ // types but not bound arguments). We still provide them (with an explicitly delete) so that
537
+ // you end up here if you try anyway.
538
+ bool load(handle, bool) = delete;
539
+ operator Type() = delete;
540
+ template <typename> using cast_op_type = Type;
541
+ };
542
+
543
+ template<typename Type>
544
+ struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
545
+ using Scalar = typename Type::Scalar;
546
+ using StorageIndex = remove_reference_t<decltype(*std::declval<Type>().outerIndexPtr())>;
547
+ using Index = typename Type::Index;
548
+ static constexpr bool rowMajor = Type::IsRowMajor;
549
+
550
+ bool load(handle src, bool) {
551
+ if (!src)
552
+ return false;
553
+
554
+ auto obj = reinterpret_borrow<object>(src);
555
+ object sparse_module = module_::import("scipy.sparse");
556
+ object matrix_type = sparse_module.attr(
557
+ rowMajor ? "csr_matrix" : "csc_matrix");
558
+
559
+ if (!type::handle_of(obj).is(matrix_type)) {
560
+ try {
561
+ obj = matrix_type(obj);
562
+ } catch (const error_already_set &) {
563
+ return false;
564
+ }
565
+ }
566
+
567
+ auto values = array_t<Scalar>((object) obj.attr("data"));
568
+ auto innerIndices = array_t<StorageIndex>((object) obj.attr("indices"));
569
+ auto outerIndices = array_t<StorageIndex>((object) obj.attr("indptr"));
570
+ auto shape = pybind11::tuple((pybind11::object) obj.attr("shape"));
571
+ auto nnz = obj.attr("nnz").cast<Index>();
572
+
573
+ if (!values || !innerIndices || !outerIndices)
574
+ return false;
575
+
576
+ value = Eigen::MappedSparseMatrix<Scalar,
577
+ Type::Flags & (Eigen::RowMajor | Eigen::ColMajor),
578
+ StorageIndex>(
579
+ shape[0].cast<Index>(), shape[1].cast<Index>(), nnz,
580
+ outerIndices.mutable_data(), innerIndices.mutable_data(), values.mutable_data());
581
+
582
+ return true;
583
+ }
584
+
585
+ static handle cast(const Type &src, return_value_policy /* policy */, handle /* parent */) {
586
+ const_cast<Type&>(src).makeCompressed();
587
+
588
+ object matrix_type = module_::import("scipy.sparse").attr(
589
+ rowMajor ? "csr_matrix" : "csc_matrix");
590
+
591
+ array data(src.nonZeros(), src.valuePtr());
592
+ array outerIndices((rowMajor ? src.rows() : src.cols()) + 1, src.outerIndexPtr());
593
+ array innerIndices(src.nonZeros(), src.innerIndexPtr());
594
+
595
+ return matrix_type(
596
+ std::make_tuple(data, innerIndices, outerIndices),
597
+ std::make_pair(src.rows(), src.cols())
598
+ ).release();
599
+ }
600
+
601
+ PYBIND11_TYPE_CASTER(Type, _<(Type::IsRowMajor) != 0>("scipy.sparse.csr_matrix[", "scipy.sparse.csc_matrix[")
602
+ + npy_format_descriptor<Scalar>::name + _("]"));
603
+ };
604
+
605
+ PYBIND11_NAMESPACE_END(detail)
606
+ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)