xcoll 0.4.0__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 +2 -1
- xcoll/beam_elements/__init__.py +7 -1
- xcoll/beam_elements/absorber.py +2 -2
- xcoll/beam_elements/base.py +105 -67
- xcoll/beam_elements/blowup.py +198 -0
- xcoll/beam_elements/{collimators_src → elements_src}/black_absorber.h +21 -3
- xcoll/beam_elements/{collimators_src → elements_src}/black_crystal.h +20 -2
- 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 +19 -2
- xcoll/beam_elements/{collimators_src → elements_src}/everest_collimator.h +19 -3
- xcoll/beam_elements/{collimators_src → elements_src}/everest_crystal.h +30 -9
- xcoll/beam_elements/everest.py +5 -6
- xcoll/beam_elements/monitor.py +428 -0
- xcoll/colldb.py +103 -74
- xcoll/general.py +4 -4
- xcoll/initial_distribution.py +18 -6
- xcoll/install.py +3 -1
- xcoll/interaction_record/interaction_record.py +126 -80
- xcoll/interaction_record/interaction_record_src/interaction_record.h +43 -43
- xcoll/line_tools.py +8 -9
- xcoll/lossmap.py +48 -38
- xcoll/scattering_routines/everest/amorphous.h +4 -11
- xcoll/scattering_routines/everest/channeling.h +3 -8
- xcoll/scattering_routines/everest/everest.h +4 -1
- xcoll/scattering_routines/everest/jaw.h +4 -3
- xcoll/scattering_routines/everest/materials.py +35 -15
- xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
- xcoll/scattering_routines/everest/nuclear_interaction.h +1 -1
- 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/collimator_geometry.h +9 -10
- xcoll/scattering_routines/geometry/crystal_geometry.h +9 -6
- {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/METADATA +1 -1
- xcoll-0.5.0.dist-info/RECORD +413 -0
- xcoll/scattering_routines/fluka/build_fluka_input.py +0 -58
- xcoll-0.4.0.dist-info/RECORD +0 -126
- {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/LICENSE +0 -0
- {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/NOTICE +0 -0
- {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from pybind11_tests import ConstructorStats
|
|
5
|
+
|
|
6
|
+
np = pytest.importorskip("numpy")
|
|
7
|
+
m = pytest.importorskip("pybind11_tests.eigen")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
ref = np.array(
|
|
11
|
+
[
|
|
12
|
+
[0.0, 3, 0, 0, 0, 11],
|
|
13
|
+
[22, 0, 0, 0, 17, 11],
|
|
14
|
+
[7, 5, 0, 1, 0, 11],
|
|
15
|
+
[0, 0, 0, 0, 0, 11],
|
|
16
|
+
[0, 0, 14, 0, 8, 11],
|
|
17
|
+
]
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def assert_equal_ref(mat):
|
|
22
|
+
np.testing.assert_array_equal(mat, ref)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def assert_sparse_equal_ref(sparse_mat):
|
|
26
|
+
assert_equal_ref(sparse_mat.toarray())
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_fixed():
|
|
30
|
+
assert_equal_ref(m.fixed_c())
|
|
31
|
+
assert_equal_ref(m.fixed_r())
|
|
32
|
+
assert_equal_ref(m.fixed_copy_r(m.fixed_r()))
|
|
33
|
+
assert_equal_ref(m.fixed_copy_c(m.fixed_c()))
|
|
34
|
+
assert_equal_ref(m.fixed_copy_r(m.fixed_c()))
|
|
35
|
+
assert_equal_ref(m.fixed_copy_c(m.fixed_r()))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_dense():
|
|
39
|
+
assert_equal_ref(m.dense_r())
|
|
40
|
+
assert_equal_ref(m.dense_c())
|
|
41
|
+
assert_equal_ref(m.dense_copy_r(m.dense_r()))
|
|
42
|
+
assert_equal_ref(m.dense_copy_c(m.dense_c()))
|
|
43
|
+
assert_equal_ref(m.dense_copy_r(m.dense_c()))
|
|
44
|
+
assert_equal_ref(m.dense_copy_c(m.dense_r()))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_partially_fixed():
|
|
48
|
+
ref2 = np.array([[0.0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]])
|
|
49
|
+
np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2), ref2)
|
|
50
|
+
np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2), ref2)
|
|
51
|
+
np.testing.assert_array_equal(m.partial_copy_four_rm_r(ref2[:, 1]), ref2[:, [1]])
|
|
52
|
+
np.testing.assert_array_equal(m.partial_copy_four_rm_c(ref2[0, :]), ref2[[0], :])
|
|
53
|
+
np.testing.assert_array_equal(
|
|
54
|
+
m.partial_copy_four_rm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)]
|
|
55
|
+
)
|
|
56
|
+
np.testing.assert_array_equal(
|
|
57
|
+
m.partial_copy_four_rm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :]
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2), ref2)
|
|
61
|
+
np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2), ref2)
|
|
62
|
+
np.testing.assert_array_equal(m.partial_copy_four_cm_r(ref2[:, 1]), ref2[:, [1]])
|
|
63
|
+
np.testing.assert_array_equal(m.partial_copy_four_cm_c(ref2[0, :]), ref2[[0], :])
|
|
64
|
+
np.testing.assert_array_equal(
|
|
65
|
+
m.partial_copy_four_cm_r(ref2[:, (0, 2)]), ref2[:, (0, 2)]
|
|
66
|
+
)
|
|
67
|
+
np.testing.assert_array_equal(
|
|
68
|
+
m.partial_copy_four_cm_c(ref2[(3, 1, 2), :]), ref2[(3, 1, 2), :]
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# TypeError should be raise for a shape mismatch
|
|
72
|
+
functions = [
|
|
73
|
+
m.partial_copy_four_rm_r,
|
|
74
|
+
m.partial_copy_four_rm_c,
|
|
75
|
+
m.partial_copy_four_cm_r,
|
|
76
|
+
m.partial_copy_four_cm_c,
|
|
77
|
+
]
|
|
78
|
+
matrix_with_wrong_shape = [[1, 2], [3, 4]]
|
|
79
|
+
for f in functions:
|
|
80
|
+
with pytest.raises(TypeError) as excinfo:
|
|
81
|
+
f(matrix_with_wrong_shape)
|
|
82
|
+
assert "incompatible function arguments" in str(excinfo.value)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_mutator_descriptors():
|
|
86
|
+
zr = np.arange(30, dtype="float32").reshape(5, 6) # row-major
|
|
87
|
+
zc = zr.reshape(6, 5).transpose() # column-major
|
|
88
|
+
|
|
89
|
+
m.fixed_mutator_r(zr)
|
|
90
|
+
m.fixed_mutator_c(zc)
|
|
91
|
+
m.fixed_mutator_a(zr)
|
|
92
|
+
m.fixed_mutator_a(zc)
|
|
93
|
+
with pytest.raises(TypeError) as excinfo:
|
|
94
|
+
m.fixed_mutator_r(zc)
|
|
95
|
+
assert (
|
|
96
|
+
"(arg0: numpy.ndarray[numpy.float32[5, 6],"
|
|
97
|
+
" flags.writeable, flags.c_contiguous]) -> None" in str(excinfo.value)
|
|
98
|
+
)
|
|
99
|
+
with pytest.raises(TypeError) as excinfo:
|
|
100
|
+
m.fixed_mutator_c(zr)
|
|
101
|
+
assert (
|
|
102
|
+
"(arg0: numpy.ndarray[numpy.float32[5, 6],"
|
|
103
|
+
" flags.writeable, flags.f_contiguous]) -> None" in str(excinfo.value)
|
|
104
|
+
)
|
|
105
|
+
with pytest.raises(TypeError) as excinfo:
|
|
106
|
+
m.fixed_mutator_a(np.array([[1, 2], [3, 4]], dtype="float32"))
|
|
107
|
+
assert "(arg0: numpy.ndarray[numpy.float32[5, 6], flags.writeable]) -> None" in str(
|
|
108
|
+
excinfo.value
|
|
109
|
+
)
|
|
110
|
+
zr.flags.writeable = False
|
|
111
|
+
with pytest.raises(TypeError):
|
|
112
|
+
m.fixed_mutator_r(zr)
|
|
113
|
+
with pytest.raises(TypeError):
|
|
114
|
+
m.fixed_mutator_a(zr)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def test_cpp_casting():
|
|
118
|
+
assert m.cpp_copy(m.fixed_r()) == 22.0
|
|
119
|
+
assert m.cpp_copy(m.fixed_c()) == 22.0
|
|
120
|
+
z = np.array([[5.0, 6], [7, 8]])
|
|
121
|
+
assert m.cpp_copy(z) == 7.0
|
|
122
|
+
assert m.cpp_copy(m.get_cm_ref()) == 21.0
|
|
123
|
+
assert m.cpp_copy(m.get_rm_ref()) == 21.0
|
|
124
|
+
assert m.cpp_ref_c(m.get_cm_ref()) == 21.0
|
|
125
|
+
assert m.cpp_ref_r(m.get_rm_ref()) == 21.0
|
|
126
|
+
with pytest.raises(RuntimeError) as excinfo:
|
|
127
|
+
# Can't reference m.fixed_c: it contains floats, m.cpp_ref_any wants doubles
|
|
128
|
+
m.cpp_ref_any(m.fixed_c())
|
|
129
|
+
assert "Unable to cast Python instance" in str(excinfo.value)
|
|
130
|
+
with pytest.raises(RuntimeError) as excinfo:
|
|
131
|
+
# Can't reference m.fixed_r: it contains floats, m.cpp_ref_any wants doubles
|
|
132
|
+
m.cpp_ref_any(m.fixed_r())
|
|
133
|
+
assert "Unable to cast Python instance" in str(excinfo.value)
|
|
134
|
+
assert m.cpp_ref_any(m.ReturnTester.create()) == 1.0
|
|
135
|
+
|
|
136
|
+
assert m.cpp_ref_any(m.get_cm_ref()) == 21.0
|
|
137
|
+
assert m.cpp_ref_any(m.get_cm_ref()) == 21.0
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_pass_readonly_array():
|
|
141
|
+
z = np.full((5, 6), 42.0)
|
|
142
|
+
z.flags.writeable = False
|
|
143
|
+
np.testing.assert_array_equal(z, m.fixed_copy_r(z))
|
|
144
|
+
np.testing.assert_array_equal(m.fixed_r_const(), m.fixed_r())
|
|
145
|
+
assert not m.fixed_r_const().flags.writeable
|
|
146
|
+
np.testing.assert_array_equal(m.fixed_copy_r(m.fixed_r_const()), m.fixed_r_const())
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def test_nonunit_stride_from_python():
|
|
150
|
+
counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3))
|
|
151
|
+
second_row = counting_mat[1, :]
|
|
152
|
+
second_col = counting_mat[:, 1]
|
|
153
|
+
np.testing.assert_array_equal(m.double_row(second_row), 2.0 * second_row)
|
|
154
|
+
np.testing.assert_array_equal(m.double_col(second_row), 2.0 * second_row)
|
|
155
|
+
np.testing.assert_array_equal(m.double_complex(second_row), 2.0 * second_row)
|
|
156
|
+
np.testing.assert_array_equal(m.double_row(second_col), 2.0 * second_col)
|
|
157
|
+
np.testing.assert_array_equal(m.double_col(second_col), 2.0 * second_col)
|
|
158
|
+
np.testing.assert_array_equal(m.double_complex(second_col), 2.0 * second_col)
|
|
159
|
+
|
|
160
|
+
counting_3d = np.arange(27.0, dtype=np.float32).reshape((3, 3, 3))
|
|
161
|
+
slices = [counting_3d[0, :, :], counting_3d[:, 0, :], counting_3d[:, :, 0]]
|
|
162
|
+
for ref_mat in slices:
|
|
163
|
+
np.testing.assert_array_equal(m.double_mat_cm(ref_mat), 2.0 * ref_mat)
|
|
164
|
+
np.testing.assert_array_equal(m.double_mat_rm(ref_mat), 2.0 * ref_mat)
|
|
165
|
+
|
|
166
|
+
# Mutator:
|
|
167
|
+
m.double_threer(second_row)
|
|
168
|
+
m.double_threec(second_col)
|
|
169
|
+
np.testing.assert_array_equal(counting_mat, [[0.0, 2, 2], [6, 16, 10], [6, 14, 8]])
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def test_negative_stride_from_python(msg):
|
|
173
|
+
"""Eigen doesn't support (as of yet) negative strides. When a function takes an Eigen matrix by
|
|
174
|
+
copy or const reference, we can pass a numpy array that has negative strides. Otherwise, an
|
|
175
|
+
exception will be thrown as Eigen will not be able to map the numpy array."""
|
|
176
|
+
|
|
177
|
+
counting_mat = np.arange(9.0, dtype=np.float32).reshape((3, 3))
|
|
178
|
+
counting_mat = counting_mat[::-1, ::-1]
|
|
179
|
+
second_row = counting_mat[1, :]
|
|
180
|
+
second_col = counting_mat[:, 1]
|
|
181
|
+
np.testing.assert_array_equal(m.double_row(second_row), 2.0 * second_row)
|
|
182
|
+
np.testing.assert_array_equal(m.double_col(second_row), 2.0 * second_row)
|
|
183
|
+
np.testing.assert_array_equal(m.double_complex(second_row), 2.0 * second_row)
|
|
184
|
+
np.testing.assert_array_equal(m.double_row(second_col), 2.0 * second_col)
|
|
185
|
+
np.testing.assert_array_equal(m.double_col(second_col), 2.0 * second_col)
|
|
186
|
+
np.testing.assert_array_equal(m.double_complex(second_col), 2.0 * second_col)
|
|
187
|
+
|
|
188
|
+
counting_3d = np.arange(27.0, dtype=np.float32).reshape((3, 3, 3))
|
|
189
|
+
counting_3d = counting_3d[::-1, ::-1, ::-1]
|
|
190
|
+
slices = [counting_3d[0, :, :], counting_3d[:, 0, :], counting_3d[:, :, 0]]
|
|
191
|
+
for ref_mat in slices:
|
|
192
|
+
np.testing.assert_array_equal(m.double_mat_cm(ref_mat), 2.0 * ref_mat)
|
|
193
|
+
np.testing.assert_array_equal(m.double_mat_rm(ref_mat), 2.0 * ref_mat)
|
|
194
|
+
|
|
195
|
+
# Mutator:
|
|
196
|
+
with pytest.raises(TypeError) as excinfo:
|
|
197
|
+
m.double_threer(second_row)
|
|
198
|
+
assert (
|
|
199
|
+
msg(excinfo.value)
|
|
200
|
+
== """
|
|
201
|
+
double_threer(): incompatible function arguments. The following argument types are supported:
|
|
202
|
+
1. (arg0: numpy.ndarray[numpy.float32[1, 3], flags.writeable]) -> None
|
|
203
|
+
|
|
204
|
+
Invoked with: """ # noqa: E501 line too long
|
|
205
|
+
+ repr(np.array([5.0, 4.0, 3.0], dtype="float32"))
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
with pytest.raises(TypeError) as excinfo:
|
|
209
|
+
m.double_threec(second_col)
|
|
210
|
+
assert (
|
|
211
|
+
msg(excinfo.value)
|
|
212
|
+
== """
|
|
213
|
+
double_threec(): incompatible function arguments. The following argument types are supported:
|
|
214
|
+
1. (arg0: numpy.ndarray[numpy.float32[3, 1], flags.writeable]) -> None
|
|
215
|
+
|
|
216
|
+
Invoked with: """ # noqa: E501 line too long
|
|
217
|
+
+ repr(np.array([7.0, 4.0, 1.0], dtype="float32"))
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def test_nonunit_stride_to_python():
|
|
222
|
+
assert np.all(m.diagonal(ref) == ref.diagonal())
|
|
223
|
+
assert np.all(m.diagonal_1(ref) == ref.diagonal(1))
|
|
224
|
+
for i in range(-5, 7):
|
|
225
|
+
assert np.all(
|
|
226
|
+
m.diagonal_n(ref, i) == ref.diagonal(i)
|
|
227
|
+
), "m.diagonal_n({})".format(i)
|
|
228
|
+
|
|
229
|
+
assert np.all(m.block(ref, 2, 1, 3, 3) == ref[2:5, 1:4])
|
|
230
|
+
assert np.all(m.block(ref, 1, 4, 4, 2) == ref[1:, 4:])
|
|
231
|
+
assert np.all(m.block(ref, 1, 4, 3, 2) == ref[1:4, 4:])
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def test_eigen_ref_to_python():
|
|
235
|
+
chols = [m.cholesky1, m.cholesky2, m.cholesky3, m.cholesky4]
|
|
236
|
+
for i, chol in enumerate(chols, start=1):
|
|
237
|
+
mymat = chol(np.array([[1.0, 2, 4], [2, 13, 23], [4, 23, 77]]))
|
|
238
|
+
assert np.all(
|
|
239
|
+
mymat == np.array([[1, 0, 0], [2, 3, 0], [4, 5, 6]])
|
|
240
|
+
), "cholesky{}".format(i)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def assign_both(a1, a2, r, c, v):
|
|
244
|
+
a1[r, c] = v
|
|
245
|
+
a2[r, c] = v
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def array_copy_but_one(a, r, c, v):
|
|
249
|
+
z = np.array(a, copy=True)
|
|
250
|
+
z[r, c] = v
|
|
251
|
+
return z
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def test_eigen_return_references():
|
|
255
|
+
"""Tests various ways of returning references and non-referencing copies"""
|
|
256
|
+
|
|
257
|
+
master = np.ones((10, 10))
|
|
258
|
+
a = m.ReturnTester()
|
|
259
|
+
a_get1 = a.get()
|
|
260
|
+
assert not a_get1.flags.owndata and a_get1.flags.writeable
|
|
261
|
+
assign_both(a_get1, master, 3, 3, 5)
|
|
262
|
+
a_get2 = a.get_ptr()
|
|
263
|
+
assert not a_get2.flags.owndata and a_get2.flags.writeable
|
|
264
|
+
assign_both(a_get1, master, 2, 3, 6)
|
|
265
|
+
|
|
266
|
+
a_view1 = a.view()
|
|
267
|
+
assert not a_view1.flags.owndata and not a_view1.flags.writeable
|
|
268
|
+
with pytest.raises(ValueError):
|
|
269
|
+
a_view1[2, 3] = 4
|
|
270
|
+
a_view2 = a.view_ptr()
|
|
271
|
+
assert not a_view2.flags.owndata and not a_view2.flags.writeable
|
|
272
|
+
with pytest.raises(ValueError):
|
|
273
|
+
a_view2[2, 3] = 4
|
|
274
|
+
|
|
275
|
+
a_copy1 = a.copy_get()
|
|
276
|
+
assert a_copy1.flags.owndata and a_copy1.flags.writeable
|
|
277
|
+
np.testing.assert_array_equal(a_copy1, master)
|
|
278
|
+
a_copy1[7, 7] = -44 # Shouldn't affect anything else
|
|
279
|
+
c1want = array_copy_but_one(master, 7, 7, -44)
|
|
280
|
+
a_copy2 = a.copy_view()
|
|
281
|
+
assert a_copy2.flags.owndata and a_copy2.flags.writeable
|
|
282
|
+
np.testing.assert_array_equal(a_copy2, master)
|
|
283
|
+
a_copy2[4, 4] = -22 # Shouldn't affect anything else
|
|
284
|
+
c2want = array_copy_but_one(master, 4, 4, -22)
|
|
285
|
+
|
|
286
|
+
a_ref1 = a.ref()
|
|
287
|
+
assert not a_ref1.flags.owndata and a_ref1.flags.writeable
|
|
288
|
+
assign_both(a_ref1, master, 1, 1, 15)
|
|
289
|
+
a_ref2 = a.ref_const()
|
|
290
|
+
assert not a_ref2.flags.owndata and not a_ref2.flags.writeable
|
|
291
|
+
with pytest.raises(ValueError):
|
|
292
|
+
a_ref2[5, 5] = 33
|
|
293
|
+
a_ref3 = a.ref_safe()
|
|
294
|
+
assert not a_ref3.flags.owndata and a_ref3.flags.writeable
|
|
295
|
+
assign_both(a_ref3, master, 0, 7, 99)
|
|
296
|
+
a_ref4 = a.ref_const_safe()
|
|
297
|
+
assert not a_ref4.flags.owndata and not a_ref4.flags.writeable
|
|
298
|
+
with pytest.raises(ValueError):
|
|
299
|
+
a_ref4[7, 0] = 987654321
|
|
300
|
+
|
|
301
|
+
a_copy3 = a.copy_ref()
|
|
302
|
+
assert a_copy3.flags.owndata and a_copy3.flags.writeable
|
|
303
|
+
np.testing.assert_array_equal(a_copy3, master)
|
|
304
|
+
a_copy3[8, 1] = 11
|
|
305
|
+
c3want = array_copy_but_one(master, 8, 1, 11)
|
|
306
|
+
a_copy4 = a.copy_ref_const()
|
|
307
|
+
assert a_copy4.flags.owndata and a_copy4.flags.writeable
|
|
308
|
+
np.testing.assert_array_equal(a_copy4, master)
|
|
309
|
+
a_copy4[8, 4] = 88
|
|
310
|
+
c4want = array_copy_but_one(master, 8, 4, 88)
|
|
311
|
+
|
|
312
|
+
a_block1 = a.block(3, 3, 2, 2)
|
|
313
|
+
assert not a_block1.flags.owndata and a_block1.flags.writeable
|
|
314
|
+
a_block1[0, 0] = 55
|
|
315
|
+
master[3, 3] = 55
|
|
316
|
+
a_block2 = a.block_safe(2, 2, 3, 2)
|
|
317
|
+
assert not a_block2.flags.owndata and a_block2.flags.writeable
|
|
318
|
+
a_block2[2, 1] = -123
|
|
319
|
+
master[4, 3] = -123
|
|
320
|
+
a_block3 = a.block_const(6, 7, 4, 3)
|
|
321
|
+
assert not a_block3.flags.owndata and not a_block3.flags.writeable
|
|
322
|
+
with pytest.raises(ValueError):
|
|
323
|
+
a_block3[2, 2] = -44444
|
|
324
|
+
|
|
325
|
+
a_copy5 = a.copy_block(2, 2, 2, 3)
|
|
326
|
+
assert a_copy5.flags.owndata and a_copy5.flags.writeable
|
|
327
|
+
np.testing.assert_array_equal(a_copy5, master[2:4, 2:5])
|
|
328
|
+
a_copy5[1, 1] = 777
|
|
329
|
+
c5want = array_copy_but_one(master[2:4, 2:5], 1, 1, 777)
|
|
330
|
+
|
|
331
|
+
a_corn1 = a.corners()
|
|
332
|
+
assert not a_corn1.flags.owndata and a_corn1.flags.writeable
|
|
333
|
+
a_corn1 *= 50
|
|
334
|
+
a_corn1[1, 1] = 999
|
|
335
|
+
master[0, 0] = 50
|
|
336
|
+
master[0, 9] = 50
|
|
337
|
+
master[9, 0] = 50
|
|
338
|
+
master[9, 9] = 999
|
|
339
|
+
a_corn2 = a.corners_const()
|
|
340
|
+
assert not a_corn2.flags.owndata and not a_corn2.flags.writeable
|
|
341
|
+
with pytest.raises(ValueError):
|
|
342
|
+
a_corn2[1, 0] = 51
|
|
343
|
+
|
|
344
|
+
# All of the changes made all the way along should be visible everywhere
|
|
345
|
+
# now (except for the copies, of course)
|
|
346
|
+
np.testing.assert_array_equal(a_get1, master)
|
|
347
|
+
np.testing.assert_array_equal(a_get2, master)
|
|
348
|
+
np.testing.assert_array_equal(a_view1, master)
|
|
349
|
+
np.testing.assert_array_equal(a_view2, master)
|
|
350
|
+
np.testing.assert_array_equal(a_ref1, master)
|
|
351
|
+
np.testing.assert_array_equal(a_ref2, master)
|
|
352
|
+
np.testing.assert_array_equal(a_ref3, master)
|
|
353
|
+
np.testing.assert_array_equal(a_ref4, master)
|
|
354
|
+
np.testing.assert_array_equal(a_block1, master[3:5, 3:5])
|
|
355
|
+
np.testing.assert_array_equal(a_block2, master[2:5, 2:4])
|
|
356
|
+
np.testing.assert_array_equal(a_block3, master[6:10, 7:10])
|
|
357
|
+
np.testing.assert_array_equal(
|
|
358
|
+
a_corn1, master[0 :: master.shape[0] - 1, 0 :: master.shape[1] - 1]
|
|
359
|
+
)
|
|
360
|
+
np.testing.assert_array_equal(
|
|
361
|
+
a_corn2, master[0 :: master.shape[0] - 1, 0 :: master.shape[1] - 1]
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
np.testing.assert_array_equal(a_copy1, c1want)
|
|
365
|
+
np.testing.assert_array_equal(a_copy2, c2want)
|
|
366
|
+
np.testing.assert_array_equal(a_copy3, c3want)
|
|
367
|
+
np.testing.assert_array_equal(a_copy4, c4want)
|
|
368
|
+
np.testing.assert_array_equal(a_copy5, c5want)
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def assert_keeps_alive(cl, method, *args):
|
|
372
|
+
cstats = ConstructorStats.get(cl)
|
|
373
|
+
start_with = cstats.alive()
|
|
374
|
+
a = cl()
|
|
375
|
+
assert cstats.alive() == start_with + 1
|
|
376
|
+
z = method(a, *args)
|
|
377
|
+
assert cstats.alive() == start_with + 1
|
|
378
|
+
del a
|
|
379
|
+
# Here's the keep alive in action:
|
|
380
|
+
assert cstats.alive() == start_with + 1
|
|
381
|
+
del z
|
|
382
|
+
# Keep alive should have expired:
|
|
383
|
+
assert cstats.alive() == start_with
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def test_eigen_keepalive():
|
|
387
|
+
a = m.ReturnTester()
|
|
388
|
+
cstats = ConstructorStats.get(m.ReturnTester)
|
|
389
|
+
assert cstats.alive() == 1
|
|
390
|
+
unsafe = [a.ref(), a.ref_const(), a.block(1, 2, 3, 4)]
|
|
391
|
+
copies = [
|
|
392
|
+
a.copy_get(),
|
|
393
|
+
a.copy_view(),
|
|
394
|
+
a.copy_ref(),
|
|
395
|
+
a.copy_ref_const(),
|
|
396
|
+
a.copy_block(4, 3, 2, 1),
|
|
397
|
+
]
|
|
398
|
+
del a
|
|
399
|
+
assert cstats.alive() == 0
|
|
400
|
+
del unsafe
|
|
401
|
+
del copies
|
|
402
|
+
|
|
403
|
+
for meth in [
|
|
404
|
+
m.ReturnTester.get,
|
|
405
|
+
m.ReturnTester.get_ptr,
|
|
406
|
+
m.ReturnTester.view,
|
|
407
|
+
m.ReturnTester.view_ptr,
|
|
408
|
+
m.ReturnTester.ref_safe,
|
|
409
|
+
m.ReturnTester.ref_const_safe,
|
|
410
|
+
m.ReturnTester.corners,
|
|
411
|
+
m.ReturnTester.corners_const,
|
|
412
|
+
]:
|
|
413
|
+
assert_keeps_alive(m.ReturnTester, meth)
|
|
414
|
+
|
|
415
|
+
for meth in [m.ReturnTester.block_safe, m.ReturnTester.block_const]:
|
|
416
|
+
assert_keeps_alive(m.ReturnTester, meth, 4, 3, 2, 1)
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def test_eigen_ref_mutators():
|
|
420
|
+
"""Tests Eigen's ability to mutate numpy values"""
|
|
421
|
+
|
|
422
|
+
orig = np.array([[1.0, 2, 3], [4, 5, 6], [7, 8, 9]])
|
|
423
|
+
zr = np.array(orig)
|
|
424
|
+
zc = np.array(orig, order="F")
|
|
425
|
+
m.add_rm(zr, 1, 0, 100)
|
|
426
|
+
assert np.all(zr == np.array([[1.0, 2, 3], [104, 5, 6], [7, 8, 9]]))
|
|
427
|
+
m.add_cm(zc, 1, 0, 200)
|
|
428
|
+
assert np.all(zc == np.array([[1.0, 2, 3], [204, 5, 6], [7, 8, 9]]))
|
|
429
|
+
|
|
430
|
+
m.add_any(zr, 1, 0, 20)
|
|
431
|
+
assert np.all(zr == np.array([[1.0, 2, 3], [124, 5, 6], [7, 8, 9]]))
|
|
432
|
+
m.add_any(zc, 1, 0, 10)
|
|
433
|
+
assert np.all(zc == np.array([[1.0, 2, 3], [214, 5, 6], [7, 8, 9]]))
|
|
434
|
+
|
|
435
|
+
# Can't reference a col-major array with a row-major Ref, and vice versa:
|
|
436
|
+
with pytest.raises(TypeError):
|
|
437
|
+
m.add_rm(zc, 1, 0, 1)
|
|
438
|
+
with pytest.raises(TypeError):
|
|
439
|
+
m.add_cm(zr, 1, 0, 1)
|
|
440
|
+
|
|
441
|
+
# Overloads:
|
|
442
|
+
m.add1(zr, 1, 0, -100)
|
|
443
|
+
m.add2(zr, 1, 0, -20)
|
|
444
|
+
assert np.all(zr == orig)
|
|
445
|
+
m.add1(zc, 1, 0, -200)
|
|
446
|
+
m.add2(zc, 1, 0, -10)
|
|
447
|
+
assert np.all(zc == orig)
|
|
448
|
+
|
|
449
|
+
# a non-contiguous slice (this won't work on either the row- or
|
|
450
|
+
# column-contiguous refs, but should work for the any)
|
|
451
|
+
cornersr = zr[0::2, 0::2]
|
|
452
|
+
cornersc = zc[0::2, 0::2]
|
|
453
|
+
|
|
454
|
+
assert np.all(cornersr == np.array([[1.0, 3], [7, 9]]))
|
|
455
|
+
assert np.all(cornersc == np.array([[1.0, 3], [7, 9]]))
|
|
456
|
+
|
|
457
|
+
with pytest.raises(TypeError):
|
|
458
|
+
m.add_rm(cornersr, 0, 1, 25)
|
|
459
|
+
with pytest.raises(TypeError):
|
|
460
|
+
m.add_cm(cornersr, 0, 1, 25)
|
|
461
|
+
with pytest.raises(TypeError):
|
|
462
|
+
m.add_rm(cornersc, 0, 1, 25)
|
|
463
|
+
with pytest.raises(TypeError):
|
|
464
|
+
m.add_cm(cornersc, 0, 1, 25)
|
|
465
|
+
m.add_any(cornersr, 0, 1, 25)
|
|
466
|
+
m.add_any(cornersc, 0, 1, 44)
|
|
467
|
+
assert np.all(zr == np.array([[1.0, 2, 28], [4, 5, 6], [7, 8, 9]]))
|
|
468
|
+
assert np.all(zc == np.array([[1.0, 2, 47], [4, 5, 6], [7, 8, 9]]))
|
|
469
|
+
|
|
470
|
+
# You shouldn't be allowed to pass a non-writeable array to a mutating Eigen method:
|
|
471
|
+
zro = zr[0:4, 0:4]
|
|
472
|
+
zro.flags.writeable = False
|
|
473
|
+
with pytest.raises(TypeError):
|
|
474
|
+
m.add_rm(zro, 0, 0, 0)
|
|
475
|
+
with pytest.raises(TypeError):
|
|
476
|
+
m.add_any(zro, 0, 0, 0)
|
|
477
|
+
with pytest.raises(TypeError):
|
|
478
|
+
m.add1(zro, 0, 0, 0)
|
|
479
|
+
with pytest.raises(TypeError):
|
|
480
|
+
m.add2(zro, 0, 0, 0)
|
|
481
|
+
|
|
482
|
+
# integer array shouldn't be passable to a double-matrix-accepting mutating func:
|
|
483
|
+
zi = np.array([[1, 2], [3, 4]])
|
|
484
|
+
with pytest.raises(TypeError):
|
|
485
|
+
m.add_rm(zi)
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def test_numpy_ref_mutators():
|
|
489
|
+
"""Tests numpy mutating Eigen matrices (for returned Eigen::Ref<...>s)"""
|
|
490
|
+
|
|
491
|
+
m.reset_refs() # In case another test already changed it
|
|
492
|
+
|
|
493
|
+
zc = m.get_cm_ref()
|
|
494
|
+
zcro = m.get_cm_const_ref()
|
|
495
|
+
zr = m.get_rm_ref()
|
|
496
|
+
zrro = m.get_rm_const_ref()
|
|
497
|
+
|
|
498
|
+
assert [zc[1, 2], zcro[1, 2], zr[1, 2], zrro[1, 2]] == [23] * 4
|
|
499
|
+
|
|
500
|
+
assert not zc.flags.owndata and zc.flags.writeable
|
|
501
|
+
assert not zr.flags.owndata and zr.flags.writeable
|
|
502
|
+
assert not zcro.flags.owndata and not zcro.flags.writeable
|
|
503
|
+
assert not zrro.flags.owndata and not zrro.flags.writeable
|
|
504
|
+
|
|
505
|
+
zc[1, 2] = 99
|
|
506
|
+
expect = np.array([[11.0, 12, 13], [21, 22, 99], [31, 32, 33]])
|
|
507
|
+
# We should have just changed zc, of course, but also zcro and the original eigen matrix
|
|
508
|
+
assert np.all(zc == expect)
|
|
509
|
+
assert np.all(zcro == expect)
|
|
510
|
+
assert np.all(m.get_cm_ref() == expect)
|
|
511
|
+
|
|
512
|
+
zr[1, 2] = 99
|
|
513
|
+
assert np.all(zr == expect)
|
|
514
|
+
assert np.all(zrro == expect)
|
|
515
|
+
assert np.all(m.get_rm_ref() == expect)
|
|
516
|
+
|
|
517
|
+
# Make sure the readonly ones are numpy-readonly:
|
|
518
|
+
with pytest.raises(ValueError):
|
|
519
|
+
zcro[1, 2] = 6
|
|
520
|
+
with pytest.raises(ValueError):
|
|
521
|
+
zrro[1, 2] = 6
|
|
522
|
+
|
|
523
|
+
# We should be able to explicitly copy like this (and since we're copying,
|
|
524
|
+
# the const should drop away)
|
|
525
|
+
y1 = np.array(m.get_cm_const_ref())
|
|
526
|
+
|
|
527
|
+
assert y1.flags.owndata and y1.flags.writeable
|
|
528
|
+
# We should get copies of the eigen data, which was modified above:
|
|
529
|
+
assert y1[1, 2] == 99
|
|
530
|
+
y1[1, 2] += 12
|
|
531
|
+
assert y1[1, 2] == 111
|
|
532
|
+
assert zc[1, 2] == 99 # Make sure we aren't referencing the original
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
def test_both_ref_mutators():
|
|
536
|
+
"""Tests a complex chain of nested eigen/numpy references"""
|
|
537
|
+
|
|
538
|
+
m.reset_refs() # In case another test already changed it
|
|
539
|
+
|
|
540
|
+
z = m.get_cm_ref() # numpy -> eigen
|
|
541
|
+
z[0, 2] -= 3
|
|
542
|
+
z2 = m.incr_matrix(z, 1) # numpy -> eigen -> numpy -> eigen
|
|
543
|
+
z2[1, 1] += 6
|
|
544
|
+
z3 = m.incr_matrix(z, 2) # (numpy -> eigen)^3
|
|
545
|
+
z3[2, 2] += -5
|
|
546
|
+
z4 = m.incr_matrix(z, 3) # (numpy -> eigen)^4
|
|
547
|
+
z4[1, 1] -= 1
|
|
548
|
+
z5 = m.incr_matrix(z, 4) # (numpy -> eigen)^5
|
|
549
|
+
z5[0, 0] = 0
|
|
550
|
+
assert np.all(z == z2)
|
|
551
|
+
assert np.all(z == z3)
|
|
552
|
+
assert np.all(z == z4)
|
|
553
|
+
assert np.all(z == z5)
|
|
554
|
+
expect = np.array([[0.0, 22, 20], [31, 37, 33], [41, 42, 38]])
|
|
555
|
+
assert np.all(z == expect)
|
|
556
|
+
|
|
557
|
+
y = np.array(range(100), dtype="float64").reshape(10, 10)
|
|
558
|
+
y2 = m.incr_matrix_any(y, 10) # np -> eigen -> np
|
|
559
|
+
y3 = m.incr_matrix_any(
|
|
560
|
+
y2[0::2, 0::2], -33
|
|
561
|
+
) # np -> eigen -> np slice -> np -> eigen -> np
|
|
562
|
+
y4 = m.even_rows(y3) # numpy -> eigen slice -> (... y3)
|
|
563
|
+
y5 = m.even_cols(y4) # numpy -> eigen slice -> (... y4)
|
|
564
|
+
y6 = m.incr_matrix_any(y5, 1000) # numpy -> eigen -> (... y5)
|
|
565
|
+
|
|
566
|
+
# Apply same mutations using just numpy:
|
|
567
|
+
yexpect = np.array(range(100), dtype="float64").reshape(10, 10)
|
|
568
|
+
yexpect += 10
|
|
569
|
+
yexpect[0::2, 0::2] -= 33
|
|
570
|
+
yexpect[0::4, 0::4] += 1000
|
|
571
|
+
assert np.all(y6 == yexpect[0::4, 0::4])
|
|
572
|
+
assert np.all(y5 == yexpect[0::4, 0::4])
|
|
573
|
+
assert np.all(y4 == yexpect[0::4, 0::2])
|
|
574
|
+
assert np.all(y3 == yexpect[0::2, 0::2])
|
|
575
|
+
assert np.all(y2 == yexpect)
|
|
576
|
+
assert np.all(y == yexpect)
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
def test_nocopy_wrapper():
|
|
580
|
+
# get_elem requires a column-contiguous matrix reference, but should be
|
|
581
|
+
# callable with other types of matrix (via copying):
|
|
582
|
+
int_matrix_colmajor = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], order="F")
|
|
583
|
+
dbl_matrix_colmajor = np.array(
|
|
584
|
+
int_matrix_colmajor, dtype="double", order="F", copy=True
|
|
585
|
+
)
|
|
586
|
+
int_matrix_rowmajor = np.array(int_matrix_colmajor, order="C", copy=True)
|
|
587
|
+
dbl_matrix_rowmajor = np.array(
|
|
588
|
+
int_matrix_rowmajor, dtype="double", order="C", copy=True
|
|
589
|
+
)
|
|
590
|
+
|
|
591
|
+
# All should be callable via get_elem:
|
|
592
|
+
assert m.get_elem(int_matrix_colmajor) == 8
|
|
593
|
+
assert m.get_elem(dbl_matrix_colmajor) == 8
|
|
594
|
+
assert m.get_elem(int_matrix_rowmajor) == 8
|
|
595
|
+
assert m.get_elem(dbl_matrix_rowmajor) == 8
|
|
596
|
+
|
|
597
|
+
# All but the second should fail with m.get_elem_nocopy:
|
|
598
|
+
with pytest.raises(TypeError) as excinfo:
|
|
599
|
+
m.get_elem_nocopy(int_matrix_colmajor)
|
|
600
|
+
assert "get_elem_nocopy(): incompatible function arguments." in str(
|
|
601
|
+
excinfo.value
|
|
602
|
+
) and ", flags.f_contiguous" in str(excinfo.value)
|
|
603
|
+
assert m.get_elem_nocopy(dbl_matrix_colmajor) == 8
|
|
604
|
+
with pytest.raises(TypeError) as excinfo:
|
|
605
|
+
m.get_elem_nocopy(int_matrix_rowmajor)
|
|
606
|
+
assert "get_elem_nocopy(): incompatible function arguments." in str(
|
|
607
|
+
excinfo.value
|
|
608
|
+
) and ", flags.f_contiguous" in str(excinfo.value)
|
|
609
|
+
with pytest.raises(TypeError) as excinfo:
|
|
610
|
+
m.get_elem_nocopy(dbl_matrix_rowmajor)
|
|
611
|
+
assert "get_elem_nocopy(): incompatible function arguments." in str(
|
|
612
|
+
excinfo.value
|
|
613
|
+
) and ", flags.f_contiguous" in str(excinfo.value)
|
|
614
|
+
|
|
615
|
+
# For the row-major test, we take a long matrix in row-major, so only the third is allowed:
|
|
616
|
+
with pytest.raises(TypeError) as excinfo:
|
|
617
|
+
m.get_elem_rm_nocopy(int_matrix_colmajor)
|
|
618
|
+
assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
|
|
619
|
+
excinfo.value
|
|
620
|
+
) and ", flags.c_contiguous" in str(excinfo.value)
|
|
621
|
+
with pytest.raises(TypeError) as excinfo:
|
|
622
|
+
m.get_elem_rm_nocopy(dbl_matrix_colmajor)
|
|
623
|
+
assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
|
|
624
|
+
excinfo.value
|
|
625
|
+
) and ", flags.c_contiguous" in str(excinfo.value)
|
|
626
|
+
assert m.get_elem_rm_nocopy(int_matrix_rowmajor) == 8
|
|
627
|
+
with pytest.raises(TypeError) as excinfo:
|
|
628
|
+
m.get_elem_rm_nocopy(dbl_matrix_rowmajor)
|
|
629
|
+
assert "get_elem_rm_nocopy(): incompatible function arguments." in str(
|
|
630
|
+
excinfo.value
|
|
631
|
+
) and ", flags.c_contiguous" in str(excinfo.value)
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
def test_eigen_ref_life_support():
|
|
635
|
+
"""Ensure the lifetime of temporary arrays created by the `Ref` caster
|
|
636
|
+
|
|
637
|
+
The `Ref` caster sometimes creates a copy which needs to stay alive. This needs to
|
|
638
|
+
happen both for directs casts (just the array) or indirectly (e.g. list of arrays).
|
|
639
|
+
"""
|
|
640
|
+
|
|
641
|
+
a = np.full(shape=10, fill_value=8, dtype=np.int8)
|
|
642
|
+
assert m.get_elem_direct(a) == 8
|
|
643
|
+
|
|
644
|
+
list_of_a = [a]
|
|
645
|
+
assert m.get_elem_indirect(list_of_a) == 8
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
def test_special_matrix_objects():
|
|
649
|
+
assert np.all(m.incr_diag(7) == np.diag([1.0, 2, 3, 4, 5, 6, 7]))
|
|
650
|
+
|
|
651
|
+
asymm = np.array([[1.0, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]])
|
|
652
|
+
symm_lower = np.array(asymm)
|
|
653
|
+
symm_upper = np.array(asymm)
|
|
654
|
+
for i in range(4):
|
|
655
|
+
for j in range(i + 1, 4):
|
|
656
|
+
symm_lower[i, j] = symm_lower[j, i]
|
|
657
|
+
symm_upper[j, i] = symm_upper[i, j]
|
|
658
|
+
|
|
659
|
+
assert np.all(m.symmetric_lower(asymm) == symm_lower)
|
|
660
|
+
assert np.all(m.symmetric_upper(asymm) == symm_upper)
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
def test_dense_signature(doc):
|
|
664
|
+
assert (
|
|
665
|
+
doc(m.double_col)
|
|
666
|
+
== """
|
|
667
|
+
double_col(arg0: numpy.ndarray[numpy.float32[m, 1]]) -> numpy.ndarray[numpy.float32[m, 1]]
|
|
668
|
+
"""
|
|
669
|
+
)
|
|
670
|
+
assert (
|
|
671
|
+
doc(m.double_row)
|
|
672
|
+
== """
|
|
673
|
+
double_row(arg0: numpy.ndarray[numpy.float32[1, n]]) -> numpy.ndarray[numpy.float32[1, n]]
|
|
674
|
+
"""
|
|
675
|
+
)
|
|
676
|
+
assert doc(m.double_complex) == (
|
|
677
|
+
"""
|
|
678
|
+
double_complex(arg0: numpy.ndarray[numpy.complex64[m, 1]])"""
|
|
679
|
+
""" -> numpy.ndarray[numpy.complex64[m, 1]]
|
|
680
|
+
"""
|
|
681
|
+
)
|
|
682
|
+
assert doc(m.double_mat_rm) == (
|
|
683
|
+
"""
|
|
684
|
+
double_mat_rm(arg0: numpy.ndarray[numpy.float32[m, n]])"""
|
|
685
|
+
""" -> numpy.ndarray[numpy.float32[m, n]]
|
|
686
|
+
"""
|
|
687
|
+
)
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
def test_named_arguments():
|
|
691
|
+
a = np.array([[1.0, 2], [3, 4], [5, 6]])
|
|
692
|
+
b = np.ones((2, 1))
|
|
693
|
+
|
|
694
|
+
assert np.all(m.matrix_multiply(a, b) == np.array([[3.0], [7], [11]]))
|
|
695
|
+
assert np.all(m.matrix_multiply(A=a, B=b) == np.array([[3.0], [7], [11]]))
|
|
696
|
+
assert np.all(m.matrix_multiply(B=b, A=a) == np.array([[3.0], [7], [11]]))
|
|
697
|
+
|
|
698
|
+
with pytest.raises(ValueError) as excinfo:
|
|
699
|
+
m.matrix_multiply(b, a)
|
|
700
|
+
assert str(excinfo.value) == "Nonconformable matrices!"
|
|
701
|
+
|
|
702
|
+
with pytest.raises(ValueError) as excinfo:
|
|
703
|
+
m.matrix_multiply(A=b, B=a)
|
|
704
|
+
assert str(excinfo.value) == "Nonconformable matrices!"
|
|
705
|
+
|
|
706
|
+
with pytest.raises(ValueError) as excinfo:
|
|
707
|
+
m.matrix_multiply(B=a, A=b)
|
|
708
|
+
assert str(excinfo.value) == "Nonconformable matrices!"
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
def test_sparse():
|
|
712
|
+
pytest.importorskip("scipy")
|
|
713
|
+
assert_sparse_equal_ref(m.sparse_r())
|
|
714
|
+
assert_sparse_equal_ref(m.sparse_c())
|
|
715
|
+
assert_sparse_equal_ref(m.sparse_copy_r(m.sparse_r()))
|
|
716
|
+
assert_sparse_equal_ref(m.sparse_copy_c(m.sparse_c()))
|
|
717
|
+
assert_sparse_equal_ref(m.sparse_copy_r(m.sparse_c()))
|
|
718
|
+
assert_sparse_equal_ref(m.sparse_copy_c(m.sparse_r()))
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
def test_sparse_signature(doc):
|
|
722
|
+
pytest.importorskip("scipy")
|
|
723
|
+
assert (
|
|
724
|
+
doc(m.sparse_copy_r)
|
|
725
|
+
== """
|
|
726
|
+
sparse_copy_r(arg0: scipy.sparse.csr_matrix[numpy.float32]) -> scipy.sparse.csr_matrix[numpy.float32]
|
|
727
|
+
""" # noqa: E501 line too long
|
|
728
|
+
)
|
|
729
|
+
assert (
|
|
730
|
+
doc(m.sparse_copy_c)
|
|
731
|
+
== """
|
|
732
|
+
sparse_copy_c(arg0: scipy.sparse.csc_matrix[numpy.float32]) -> scipy.sparse.csc_matrix[numpy.float32]
|
|
733
|
+
""" # noqa: E501 line too long
|
|
734
|
+
)
|
|
735
|
+
|
|
736
|
+
|
|
737
|
+
def test_issue738():
|
|
738
|
+
"""Ignore strides on a length-1 dimension (even if they would be incompatible length > 1)"""
|
|
739
|
+
assert np.all(m.iss738_f1(np.array([[1.0, 2, 3]])) == np.array([[1.0, 102, 203]]))
|
|
740
|
+
assert np.all(
|
|
741
|
+
m.iss738_f1(np.array([[1.0], [2], [3]])) == np.array([[1.0], [12], [23]])
|
|
742
|
+
)
|
|
743
|
+
|
|
744
|
+
assert np.all(m.iss738_f2(np.array([[1.0, 2, 3]])) == np.array([[1.0, 102, 203]]))
|
|
745
|
+
assert np.all(
|
|
746
|
+
m.iss738_f2(np.array([[1.0], [2], [3]])) == np.array([[1.0], [12], [23]])
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
def test_issue1105():
|
|
751
|
+
"""Issue 1105: 1xN or Nx1 input arrays weren't accepted for eigen
|
|
752
|
+
compile-time row vectors or column vector"""
|
|
753
|
+
assert m.iss1105_row(np.ones((1, 7)))
|
|
754
|
+
assert m.iss1105_col(np.ones((7, 1)))
|
|
755
|
+
|
|
756
|
+
# These should still fail (incompatible dimensions):
|
|
757
|
+
with pytest.raises(TypeError) as excinfo:
|
|
758
|
+
m.iss1105_row(np.ones((7, 1)))
|
|
759
|
+
assert "incompatible function arguments" in str(excinfo.value)
|
|
760
|
+
with pytest.raises(TypeError) as excinfo:
|
|
761
|
+
m.iss1105_col(np.ones((1, 7)))
|
|
762
|
+
assert "incompatible function arguments" in str(excinfo.value)
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
def test_custom_operator_new():
|
|
766
|
+
"""Using Eigen types as member variables requires a class-specific
|
|
767
|
+
operator new with proper alignment"""
|
|
768
|
+
|
|
769
|
+
o = m.CustomOperatorNew()
|
|
770
|
+
np.testing.assert_allclose(o.a, 0.0)
|
|
771
|
+
np.testing.assert_allclose(o.b.diagonal(), 1.0)
|