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