├── .github └── workflows │ └── build_wheels.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── docker ├── README.txt ├── manylinux1 │ └── Dockerfile └── manylinux2014 │ └── Dockerfile ├── docs ├── Doxyfile ├── Makefile ├── conf.py ├── cpp_code.rst ├── index.rst ├── make.bat └── python_code.rst ├── examples ├── how-to-use-detailed.ipynb ├── img │ ├── grafA.png │ ├── grafB.png │ ├── graf_model.txt │ └── v_dogman │ │ ├── 1.ppm │ │ ├── 2.ppm │ │ ├── 3.ppm │ │ ├── 4.ppm │ │ ├── 5.ppm │ │ ├── 6.ppm │ │ ├── H_1_2 │ │ ├── H_1_3 │ │ ├── H_1_4 │ │ ├── H_1_5 │ │ └── H_1_6 ├── simple-example-colors.ipynb ├── simple-example.ipynb └── simple-example.py ├── img ├── ransacs.png └── ransacs2.png ├── lib └── pybind11 │ ├── CMakeLists.txt │ ├── CONTRIBUTING.md │ ├── ISSUE_TEMPLATE.md │ ├── LICENSE │ ├── MANIFEST.in │ ├── README.md │ ├── README.rst │ ├── docs │ ├── Doxyfile │ ├── Makefile │ ├── _static │ │ └── css │ │ │ └── custom.css │ ├── advanced │ │ ├── cast │ │ │ ├── chrono.rst │ │ │ ├── custom.rst │ │ │ ├── eigen.rst │ │ │ ├── functional.rst │ │ │ ├── index.rst │ │ │ ├── overview.rst │ │ │ ├── stl.rst │ │ │ └── strings.rst │ │ ├── classes.rst │ │ ├── embedding.rst │ │ ├── exceptions.rst │ │ ├── functions.rst │ │ ├── misc.rst │ │ ├── pycpp │ │ │ ├── index.rst │ │ │ ├── numpy.rst │ │ │ ├── object.rst │ │ │ └── utilities.rst │ │ └── smart_ptrs.rst │ ├── basics.rst │ ├── benchmark.py │ ├── benchmark.rst │ ├── changelog.rst │ ├── classes.rst │ ├── cmake │ │ └── index.rst │ ├── compiling.rst │ ├── conf.py │ ├── faq.rst │ ├── index.rst │ ├── installing.rst │ ├── limitations.rst │ ├── pybind11-logo.png │ ├── pybind11_vs_boost_python1.png │ ├── pybind11_vs_boost_python1.svg │ ├── pybind11_vs_boost_python2.png │ ├── pybind11_vs_boost_python2.svg │ ├── reference.rst │ ├── release.rst │ ├── requirements.txt │ └── upgrade.rst │ ├── include │ └── pybind11 │ │ ├── attr.h │ │ ├── buffer_info.h │ │ ├── cast.h │ │ ├── chrono.h │ │ ├── common.h │ │ ├── complex.h │ │ ├── detail │ │ ├── class.h │ │ ├── common.h │ │ ├── descr.h │ │ ├── init.h │ │ ├── internals.h │ │ ├── type_caster_base.h │ │ └── typeid.h │ │ ├── eigen.h │ │ ├── eigen │ │ ├── matrix.h │ │ └── tensor.h │ │ ├── embed.h │ │ ├── eval.h │ │ ├── functional.h │ │ ├── gil.h │ │ ├── iostream.h │ │ ├── numpy.h │ │ ├── operators.h │ │ ├── options.h │ │ ├── pybind11.h │ │ ├── pytypes.h │ │ ├── stl.h │ │ ├── stl │ │ └── filesystem.h │ │ └── stl_bind.h │ ├── noxfile.py │ ├── pybind11 │ ├── __init__.py │ ├── __main__.py │ ├── _version.py │ ├── commands.py │ ├── py.typed │ └── setup_helpers.py │ ├── pyproject.toml │ ├── setup.cfg │ ├── setup.py │ ├── tests │ ├── CMakeLists.txt │ ├── conftest.py │ ├── constructor_stats.h │ ├── cross_module_gil_utils.cpp │ ├── cross_module_interleaved_error_already_set.cpp │ ├── eigen_tensor_avoid_stl_array.cpp │ ├── env.py │ ├── extra_python_package │ │ ├── pytest.ini │ │ └── test_files.py │ ├── extra_setuptools │ │ ├── pytest.ini │ │ └── test_setuphelper.py │ ├── local_bindings.h │ ├── object.h │ ├── pybind11_cross_module_tests.cpp │ ├── pybind11_tests.cpp │ ├── pybind11_tests.h │ ├── pytest.ini │ ├── requirements.txt │ ├── test_async.cpp │ ├── test_async.py │ ├── test_buffers.cpp │ ├── test_buffers.py │ ├── test_builtin_casters.cpp │ ├── test_builtin_casters.py │ ├── test_call_policies.cpp │ ├── test_call_policies.py │ ├── test_callbacks.cpp │ ├── test_callbacks.py │ ├── test_chrono.cpp │ ├── test_chrono.py │ ├── test_class.cpp │ ├── test_class.py │ ├── test_cmake_build │ │ ├── CMakeLists.txt │ │ ├── embed.cpp │ │ ├── installed_embed │ │ │ └── CMakeLists.txt │ │ ├── installed_function │ │ │ └── CMakeLists.txt │ │ ├── installed_target │ │ │ └── CMakeLists.txt │ │ ├── main.cpp │ │ ├── subdirectory_embed │ │ │ └── CMakeLists.txt │ │ ├── subdirectory_function │ │ │ └── CMakeLists.txt │ │ ├── subdirectory_target │ │ │ └── CMakeLists.txt │ │ └── test.py │ ├── test_const_name.cpp │ ├── test_const_name.py │ ├── test_constants_and_functions.cpp │ ├── test_constants_and_functions.py │ ├── test_copy_move.cpp │ ├── test_copy_move.py │ ├── test_custom_type_casters.cpp │ ├── test_custom_type_casters.py │ ├── test_custom_type_setup.cpp │ ├── test_custom_type_setup.py │ ├── test_docstring_options.cpp │ ├── test_docstring_options.py │ ├── test_eigen_matrix.cpp │ ├── test_eigen_matrix.py │ ├── test_eigen_tensor.cpp │ ├── test_eigen_tensor.inl │ ├── test_eigen_tensor.py │ ├── test_embed │ │ ├── CMakeLists.txt │ │ ├── catch.cpp │ │ ├── external_module.cpp │ │ ├── test_interpreter.cpp │ │ ├── test_interpreter.py │ │ └── test_trampoline.py │ ├── test_enum.cpp │ ├── test_enum.py │ ├── test_eval.cpp │ ├── test_eval.py │ ├── test_eval_call.py │ ├── test_exceptions.cpp │ ├── test_exceptions.h │ ├── test_exceptions.py │ ├── test_factory_constructors.cpp │ ├── test_factory_constructors.py │ ├── test_gil_scoped.cpp │ ├── test_gil_scoped.py │ ├── test_iostream.cpp │ ├── test_iostream.py │ ├── test_kwargs_and_defaults.cpp │ ├── test_kwargs_and_defaults.py │ ├── test_local_bindings.cpp │ ├── test_local_bindings.py │ ├── test_methods_and_attributes.cpp │ ├── test_methods_and_attributes.py │ ├── test_modules.cpp │ ├── test_modules.py │ ├── test_multiple_inheritance.cpp │ ├── test_multiple_inheritance.py │ ├── test_numpy_array.cpp │ ├── test_numpy_array.py │ ├── test_numpy_dtypes.cpp │ ├── test_numpy_dtypes.py │ ├── test_numpy_vectorize.cpp │ ├── test_numpy_vectorize.py │ ├── test_opaque_types.cpp │ ├── test_opaque_types.py │ ├── test_operator_overloading.cpp │ ├── test_operator_overloading.py │ ├── test_pickling.cpp │ ├── test_pickling.py │ ├── test_pytypes.cpp │ ├── test_pytypes.py │ ├── test_sequences_and_iterators.cpp │ ├── test_sequences_and_iterators.py │ ├── test_smart_ptr.cpp │ ├── test_smart_ptr.py │ ├── test_stl.cpp │ ├── test_stl.py │ ├── test_stl_binders.cpp │ ├── test_stl_binders.py │ ├── test_tagbased_polymorphic.cpp │ ├── test_tagbased_polymorphic.py │ ├── test_thread.cpp │ ├── test_thread.py │ ├── test_union.cpp │ ├── test_union.py │ ├── test_virtual_functions.cpp │ ├── test_virtual_functions.py │ ├── valgrind-numpy-scipy.supp │ └── valgrind-python.supp │ └── tools │ ├── FindCatch.cmake │ ├── FindEigen3.cmake │ ├── FindPythonLibsNew.cmake │ ├── JoinPaths.cmake │ ├── check-style.sh │ ├── cmake_uninstall.cmake.in │ ├── codespell_ignore_lines_from_errors.py │ ├── libsize.py │ ├── make_changelog.py │ ├── pybind11.pc.in │ ├── pybind11Common.cmake │ ├── pybind11Config.cmake.in │ ├── pybind11NewTools.cmake │ ├── pybind11Tools.cmake │ ├── pyproject.toml │ ├── setup_global.py.in │ └── setup_main.py.in ├── setup.cfg ├── setup.py └── src └── pydegensac ├── __init__.py ├── bindings.cpp ├── degensac ├── DegUtils.c ├── DegUtils.h ├── Fcustomdef.h ├── Ftools.c ├── Ftools.h ├── Htools.c ├── Htools.h ├── Makefile ├── exp_ranF.c ├── exp_ranF.h ├── exp_ranH.c ├── exp_ranH.h ├── hash.c ├── hash.h ├── lapwrap.c ├── lapwrap.h ├── ranF.c ├── ranF.h ├── ranH.c ├── ranH.h ├── ranH2el.c ├── ranH2el.h ├── rtools.c ├── rtools.h ├── utools.c └── utools.h ├── matutls ├── CMakeLists.txt ├── Makefile ├── atou1.c ├── atovm.c ├── ccmath.h ├── chouse.c ├── chousv.c ├── cmattr.c ├── cmcpy.c ├── cminv.c ├── cmmul.c ├── cmmult.c ├── cmprt.c ├── complex.h ├── csolv.c ├── cvmul.c ├── eigen.c ├── eigval.c ├── evmax.c ├── hconj.c ├── heigval.c ├── heigvec.c ├── hevmax.c ├── hmgen.c ├── house.c ├── housev.c ├── ldumat.c ├── ldvmat.c ├── lsqsv.c ├── matconsts.c ├── matprt.c ├── mattr.c ├── matutl.h ├── matutls │ ├── matutls.dsp │ └── matutls.vcproj ├── mcopy.c ├── minv.c ├── mmul.c ├── ortho.c ├── otrma.c ├── otrsm.c ├── psinv.c ├── qrbdi.c ├── qrbdu1.c ├── qrbdv.c ├── qrecvc.c ├── qreval.c ├── qrevec.c ├── qrlsq.c ├── rmmult.c ├── ruinv.c ├── scons.what ├── smgen.c ├── solv.s ├── solvps.c ├── solvru.c ├── solvtd.c ├── sv2u1v.c ├── sv2uv.c ├── sv2val.c ├── svd2.c ├── svdu1v.c ├── svduv.c ├── svdval.c ├── trncm.c ├── trnm.c ├── unitary.c ├── utrncm.c ├── utrnhm.c └── vmul.c └── utils.py /.github/workflows/build_wheels.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | # build_wheels: 7 | # name: Build wheels on ubuntu-20.04 8 | # runs-on: ubuntu-latest 9 | # 10 | # steps: 11 | # - uses: actions/checkout@v2 12 | # 13 | # # Used to host cibuildwheel 14 | # - uses: actions/setup-python@v2 15 | # 16 | # - name: Install cibuildwheel 17 | # run: python3 -m pip install cibuildwheel==2.0.0a2 18 | # - name: Build wheels 19 | # run: python3 -m cibuildwheel --output-dir wheelhouse 20 | # # to supply options, put them in 'env', like: 21 | # env: 22 | # CIBW_BEFORE_ALL: yum install -y lapack-devel blas-devel 23 | # 24 | # - uses: actions/upload-artifact@v2 25 | # with: 26 | # path: ./wheelhouse/*.whl 27 | 28 | build_wheels_mac: 29 | name: Build wheels on mac 30 | runs-on: macOS-latest 31 | 32 | steps: 33 | - uses: actions/checkout@v2 34 | 35 | # Used to host cibuildwheel 36 | - uses: actions/setup-python@v2 37 | 38 | - name: Install cibuildwheel 39 | run: python3 -m pip install cibuildwheel==2.0.0a2 40 | - name: Build wheels 41 | run: python3 -m cibuildwheel --output-dir wheelhouse 42 | # to supply options, put them in 'env', like: 43 | env: 44 | CIBW_BEFORE_ALL: brew install openblas python 45 | CIBW_ARCHS_MACOS: x86_64 universal2 46 | - uses: actions/upload-artifact@v2 47 | with: 48 | path: ./wheelhouse/*.whl 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build directory 2 | build 3 | docs/_build 4 | tests/bin 5 | 6 | # Python 7 | *.egg-info 8 | __pycache__ 9 | .eggs 10 | 11 | # VS Code 12 | .vscode 13 | 14 | # Prerequisites 15 | *.d 16 | 17 | # Compiled Object files 18 | *.slo 19 | *.lo 20 | *.o 21 | *.obj 22 | 23 | # Precompiled Headers 24 | *.gch 25 | *.pch 26 | 27 | # Compiled Dynamic libraries 28 | *.so 29 | *.dylib 30 | *.dll 31 | 32 | # Fortran module files 33 | *.mod 34 | *.smod 35 | 36 | # Compiled Static libraries 37 | *.lai 38 | *.la 39 | *.a 40 | *.lib 41 | 42 | # Executables 43 | *.exe 44 | *.out 45 | *.app 46 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | project(pydegensac) 3 | 4 | add_definitions(-fPIC) 5 | 6 | FIND_PACKAGE(LAPACK REQUIRED) 7 | if (LAPACK_FOUND) 8 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LAPACK_CXX_FLAGS}") 9 | endif (LAPACK_FOUND) 10 | 11 | SET(CMAKE_BUILD_TYPE "RELEASE") 12 | 13 | IF(CMAKE_COMPILER_IS_GNUCXX) 14 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-strict-aliasing") 15 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wno-write-strings") 16 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -ansi") 17 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -ftree-vectorize -funroll-loops") 18 | ENDIF(CMAKE_COMPILER_IS_GNUCXX) 19 | 20 | add_subdirectory(src/pydegensac/matutls) 21 | add_subdirectory(lib/pybind11) 22 | 23 | 24 | ####### DEGENSAC 25 | include_directories( 26 | src/pydegensac 27 | src/pydegensac/degensac) 28 | set(degensac_srcs 29 | src/pydegensac/degensac/DegUtils.c 30 | src/pydegensac/degensac/exp_ranF.c 31 | src/pydegensac/degensac/exp_ranH.c 32 | src/pydegensac/degensac/Ftools.c 33 | src/pydegensac/degensac/hash.c 34 | src/pydegensac/degensac/Htools.c 35 | src/pydegensac/degensac/ranF.c 36 | src/pydegensac/degensac/ranH2el.c 37 | src/pydegensac/degensac/ranH.c 38 | src/pydegensac/degensac/rtools.c 39 | src/pydegensac/degensac/utools.c 40 | src/pydegensac/degensac/lapwrap.c 41 | ) 42 | 43 | add_library(pydegensac_support ${degensac_srcs}) 44 | pybind11_add_module(pydegensac "src/pydegensac/bindings.cpp") 45 | target_link_libraries(pydegensac PRIVATE ${LAPACK_LIBRARIES} matutls pydegensac_support) 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019, Ondra Chum, Dmytro Mishkin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docker/README.txt: -------------------------------------------------------------------------------- 1 | # How to create linux wheels 2 | 3 | 1. Build docker image 4 | 2. Login into contrainer 5 | 3. Build and repair wheels, manually changing needed python version 6 | 7 | ```bash 8 | sudo docker buildx build . 9 | sudo docker image ls 10 | sudo docker run --name pydegensac2 -v $(pwd):/mnt/pydegensac -it IMG_ID 11 | alias cmake=/usr/local/bin/cmake 12 | /opt/python/cp36-cp36m/bin/python3 setup.py bdist_wheel 13 | auditwheel repair dist/pydegensac-0.1.1-cp36-cp36m-linux_x86_64.whl 14 | ``` 15 | -------------------------------------------------------------------------------- /docker/manylinux1/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM quay.io/pypa/manylinux1_x86_64:latest 2 | 3 | #Taken from https://github.com/skvark/opencv-python/blob/master/docker/Dockerfile_x86_64 4 | RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \ 5 | tar -xf cmake-3.9.0.tar.gz && \ 6 | cd cmake-3.9.0 && \ 7 | #manylinux1 provides curl-devel equivalent and libcurl statically linked 8 | # against the same newer OpenSSL as other source-built tools 9 | # (1.0.2s as of this writing) 10 | yum -y install zlib-devel && \ 11 | #configure does a bootstrap make under the hood 12 | export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \ 13 | ./configure --system-curl && \ 14 | make && \ 15 | make install && \ 16 | cd .. && \ 17 | rm -rf cmake-3.9.0* 18 | 19 | # https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#GettheDependencies 20 | # manylinux provides the toolchain and git; we provide cmake 21 | RUN yum install -y lapack-devel blas-devel 22 | 23 | 24 | ENV PATH "$HOME/bin:$PATH" 25 | -------------------------------------------------------------------------------- /docker/manylinux2014/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM quay.io/pypa/manylinux2014_x86_64:latest 2 | 3 | # manylinux provides the toolchain and git; we provide cmake 4 | 5 | RUN yum install -y curl libcurl-devel lapack-devel blas-devel 6 | 7 | #Taken from https://github.com/skvark/opencv-python/blob/master/docker/Dockerfile_x86_64 8 | RUN curl -O -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz && \ 9 | tar -xf cmake-3.9.0.tar.gz && \ 10 | cd cmake-3.9.0 && \ 11 | #manylinux1 provides curl-devel equivalent and libcurl statically linked 12 | # against the same newer OpenSSL as other source-built tools 13 | # (1.0.2s as of this writing) 14 | yum -y install zlib-devel && \ 15 | #configure does a bootstrap make under the hood 16 | export MAKEFLAGS=-j$(getconf _NPROCESSORS_ONLN) && \ 17 | ./configure --system-curl && \ 18 | make && \ 19 | make install && \ 20 | cd .. && \ 21 | rm -rf cmake-3.9.0* 22 | 23 | # https://trac.ffmpeg.org/wiki/CompilationGuide/Centos#GettheDependencies 24 | ENV PATH "$HOME/bin:$PATH" 25 | -------------------------------------------------------------------------------- /docs/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = pydegensac 2 | INPUT = ../pydegensac/ 3 | 4 | GENERATE_HTML = NO 5 | GENERATE_LATEX = NO 6 | GENERATE_XML = YES 7 | XML_OUTPUT = _build/doxygenxml 8 | XML_PROGRAMLISTING = YES 9 | 10 | ALIASES = "rst=\verbatim embed:rst" 11 | ALIASES += "endrst=\endverbatim" 12 | 13 | QUIET = YES 14 | WARNINGS = YES 15 | WARN_IF_UNDOCUMENTED = NO 16 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = python3 -msphinx 7 | SPHINXPROJ = pydegensac 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/cpp_code.rst: -------------------------------------------------------------------------------- 1 | C++ code 2 | =================== 3 | 4 | .. doxygenfile:: main.hpp -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Example documentation for a hybrid Python/C++ project 2 | ===================================================== 3 | 4 | Contents: 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | python_code 10 | 11 | cpp_code 12 | 13 | Indices and tables 14 | ================== 15 | 16 | * :ref:`genindex` 17 | * :ref:`search` 18 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=python -msphinx 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | set SPHINXPROJ=Python-CPPExample 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The Sphinx module was not found. Make sure you have Sphinx installed, 20 | echo.then set the SPHINXBUILD environment variable to point to the full 21 | echo.path of the 'sphinx-build' executable. Alternatively you may add the 22 | echo.Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /docs/python_code.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: pydegensac 2 | -------------------------------------------------------------------------------- /examples/img/grafA.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/examples/img/grafA.png -------------------------------------------------------------------------------- /examples/img/grafB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/examples/img/grafB.png -------------------------------------------------------------------------------- /examples/img/graf_model.txt: -------------------------------------------------------------------------------- 1 | 1.1297248392416119 0.33695270601561222 -228.22758438566291 2 | -0.41743772244661481 0.7739252154844829 155.17964630469896 3 | -0.00043346159981064245 -0.00010730823043571054 1 4 | -------------------------------------------------------------------------------- /examples/img/v_dogman/1.ppm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/examples/img/v_dogman/1.ppm -------------------------------------------------------------------------------- /examples/img/v_dogman/2.ppm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/examples/img/v_dogman/2.ppm -------------------------------------------------------------------------------- /examples/img/v_dogman/3.ppm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/examples/img/v_dogman/3.ppm -------------------------------------------------------------------------------- /examples/img/v_dogman/4.ppm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/examples/img/v_dogman/4.ppm -------------------------------------------------------------------------------- /examples/img/v_dogman/5.ppm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/examples/img/v_dogman/5.ppm -------------------------------------------------------------------------------- /examples/img/v_dogman/6.ppm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/examples/img/v_dogman/6.ppm -------------------------------------------------------------------------------- /examples/img/v_dogman/H_1_2: -------------------------------------------------------------------------------- 1 | 0.49838 -0.015725 33.278 2 | -0.18045 0.77392 59.799 3 | -0.00064863 -4.2793e-05 0.99978 4 | -------------------------------------------------------------------------------- /examples/img/v_dogman/H_1_3: -------------------------------------------------------------------------------- 1 | 1.0819 0.012805 66.799 2 | 0.075853 1.006 5.6909 3 | 0.00034273 -2.4626e-05 1.0003 4 | -------------------------------------------------------------------------------- /examples/img/v_dogman/H_1_4: -------------------------------------------------------------------------------- 1 | 2.9721 0.034514 6.1536 2 | 0.86739 2.9829 -532.95 3 | 0.0035453 0.00017204 0.95976 4 | -------------------------------------------------------------------------------- /examples/img/v_dogman/H_1_5: -------------------------------------------------------------------------------- 1 | 0.31269 -0.011782 51.842 2 | -0.22276 0.71181 65.24 3 | -0.00081452 -4.173e-05 0.99309 4 | -------------------------------------------------------------------------------- /examples/img/v_dogman/H_1_6: -------------------------------------------------------------------------------- 1 | -0.036838 -0.012358 166.5 2 | -0.28304 0.70203 61.488 3 | -0.0011124 -1.7983e-05 0.99335 4 | -------------------------------------------------------------------------------- /img/ransacs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/img/ransacs.png -------------------------------------------------------------------------------- /img/ransacs2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/img/ransacs2.png -------------------------------------------------------------------------------- /lib/pybind11/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Thank you for your interest in this project! Please refer to the following 2 | sections on how to contribute code and bug reports. 3 | 4 | ### Reporting bugs 5 | 6 | At the moment, this project is run in the spare time of a single person 7 | ([Wenzel Jakob](http://rgl.epfl.ch/people/wjakob)) with very limited resources 8 | for issue tracker tickets. Thus, before submitting a question or bug report, 9 | please take a moment of your time and ensure that your issue isn't already 10 | discussed in the project documentation provided at 11 | [http://pybind11.readthedocs.org/en/latest](http://pybind11.readthedocs.org/en/latest). 12 | 13 | Assuming that you have identified a previously unknown problem or an important 14 | question, it's essential that you submit a self-contained and minimal piece of 15 | code that reproduces the problem. In other words: no external dependencies, 16 | isolate the function(s) that cause breakage, submit matched and complete C++ 17 | and Python snippets that can be easily compiled and run on my end. 18 | 19 | ## Pull requests 20 | Contributions are submitted, reviewed, and accepted using Github pull requests. 21 | Please refer to [this 22 | article](https://help.github.com/articles/using-pull-requests) for details and 23 | adhere to the following rules to make the process as smooth as possible: 24 | 25 | * Make a new branch for every feature you're working on. 26 | * Make small and clean pull requests that are easy to review but make sure they 27 | do add value by themselves. 28 | * Add tests for any new functionality and run the test suite (``make pytest``) 29 | to ensure that no existing features break. 30 | * This project has a strong focus on providing general solutions using a 31 | minimal amount of code, thus small pull requests are greatly preferred. 32 | 33 | ### License 34 | 35 | pybind11 is provided under a BSD-style license that can be found in the 36 | ``LICENSE`` file. By using, distributing, or contributing to this project, you 37 | agree to the terms and conditions of this license. 38 | -------------------------------------------------------------------------------- /lib/pybind11/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Make sure you've completed the following steps before submitting your issue -- thank you! 2 | You can remove this template text afterward. 3 | 4 | 1. Check if your question has already been answered in the [FAQ](http://pybind11.readthedocs.io/en/latest/faq.html) section. 5 | 2. Make sure you've read the [documentation](http://pybind11.readthedocs.io/en/latest/). Your issue may be addressed there. 6 | 3. If those resources didn't help and you only have a short question (not a bug report), consider asking in the [Gitter chat room](https://gitter.im/pybind/Lobby). 7 | 4. If you have a genuine bug report or a more complex question which is not answered in the previous items (or not suitable for chat), please fill in the details below. 8 | 5. Include a self-contained and minimal piece of code that reproduces the problem. If that's not possible, try to make the description as clear as possible. 9 | 10 | 11 | #### Issue description 12 | 13 | (Provide a short description, state the expected behavior and what actually happens.) 14 | 15 | #### Reproducible example code 16 | 17 | (The code should be minimal, have no external dependencies, isolate the function(s) that cause breakage. Submit matched and complete C++ and Python snippets that can be easily compiled and run to diagnose the issue.) 18 | -------------------------------------------------------------------------------- /lib/pybind11/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Wenzel Jakob , All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | Please also refer to the file .github/CONTRIBUTING.md, which clarifies licensing of 29 | external contributions to this project including patches, pull requests, etc. 30 | -------------------------------------------------------------------------------- /lib/pybind11/MANIFEST.in: -------------------------------------------------------------------------------- 1 | prune tests 2 | recursive-include pybind11/include/pybind11 *.h 3 | recursive-include pybind11 *.py 4 | recursive-include pybind11 py.typed 5 | include pybind11/share/cmake/pybind11/*.cmake 6 | include LICENSE README.rst pyproject.toml setup.py setup.cfg 7 | -------------------------------------------------------------------------------- /lib/pybind11/docs/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = pybind11 2 | INPUT = ../include/pybind11/ 3 | RECURSIVE = YES 4 | 5 | GENERATE_HTML = NO 6 | GENERATE_LATEX = NO 7 | GENERATE_XML = YES 8 | XML_OUTPUT = .build/doxygenxml 9 | XML_PROGRAMLISTING = YES 10 | 11 | MACRO_EXPANSION = YES 12 | EXPAND_ONLY_PREDEF = YES 13 | EXPAND_AS_DEFINED = PYBIND11_RUNTIME_EXCEPTION 14 | 15 | ALIASES = "rst=\verbatim embed:rst" 16 | ALIASES += "endrst=\endverbatim" 17 | 18 | QUIET = YES 19 | WARNINGS = YES 20 | WARN_IF_UNDOCUMENTED = NO 21 | PREDEFINED = PYBIND11_NOINLINE 22 | -------------------------------------------------------------------------------- /lib/pybind11/docs/_static/css/custom.css: -------------------------------------------------------------------------------- 1 | .highlight .go { 2 | color: #707070; 3 | } 4 | -------------------------------------------------------------------------------- /lib/pybind11/docs/advanced/cast/index.rst: -------------------------------------------------------------------------------- 1 | .. _type-conversions: 2 | 3 | Type conversions 4 | ################ 5 | 6 | Apart from enabling cross-language function calls, a fundamental problem 7 | that a binding tool like pybind11 must address is to provide access to 8 | native Python types in C++ and vice versa. There are three fundamentally 9 | different ways to do this—which approach is preferable for a particular type 10 | depends on the situation at hand. 11 | 12 | 1. Use a native C++ type everywhere. In this case, the type must be wrapped 13 | using pybind11-generated bindings so that Python can interact with it. 14 | 15 | 2. Use a native Python type everywhere. It will need to be wrapped so that 16 | C++ functions can interact with it. 17 | 18 | 3. Use a native C++ type on the C++ side and a native Python type on the 19 | Python side. pybind11 refers to this as a *type conversion*. 20 | 21 | Type conversions are the most "natural" option in the sense that native 22 | (non-wrapped) types are used everywhere. The main downside is that a copy 23 | of the data must be made on every Python ↔ C++ transition: this is 24 | needed since the C++ and Python versions of the same type generally won't 25 | have the same memory layout. 26 | 27 | pybind11 can perform many kinds of conversions automatically. An overview 28 | is provided in the table ":ref:`conversion_table`". 29 | 30 | The following subsections discuss the differences between these options in more 31 | detail. The main focus in this section is on type conversions, which represent 32 | the last case of the above list. 33 | 34 | .. toctree:: 35 | :maxdepth: 1 36 | 37 | overview 38 | strings 39 | stl 40 | functional 41 | chrono 42 | eigen 43 | custom 44 | -------------------------------------------------------------------------------- /lib/pybind11/docs/advanced/pycpp/index.rst: -------------------------------------------------------------------------------- 1 | Python C++ interface 2 | #################### 3 | 4 | pybind11 exposes Python types and functions using thin C++ wrappers, which 5 | makes it possible to conveniently call Python code from C++ without resorting 6 | to Python's C API. 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | 11 | object 12 | numpy 13 | utilities 14 | -------------------------------------------------------------------------------- /lib/pybind11/docs/cmake/index.rst: -------------------------------------------------------------------------------- 1 | CMake helpers 2 | ------------- 3 | 4 | Pybind11 can be used with ``add_subdirectory(extern/pybind11)``, or from an 5 | install with ``find_package(pybind11 CONFIG)``. The interface provided in 6 | either case is functionally identical. 7 | 8 | .. cmake-module:: ../../tools/pybind11Config.cmake.in 9 | -------------------------------------------------------------------------------- /lib/pybind11/docs/index.rst: -------------------------------------------------------------------------------- 1 | .. only:: latex 2 | 3 | Intro 4 | ===== 5 | 6 | .. include:: readme.rst 7 | 8 | .. only:: not latex 9 | 10 | Contents: 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | 15 | changelog 16 | upgrade 17 | 18 | .. toctree:: 19 | :caption: The Basics 20 | :maxdepth: 2 21 | 22 | installing 23 | basics 24 | classes 25 | compiling 26 | 27 | .. toctree:: 28 | :caption: Advanced Topics 29 | :maxdepth: 2 30 | 31 | advanced/functions 32 | advanced/classes 33 | advanced/exceptions 34 | advanced/smart_ptrs 35 | advanced/cast/index 36 | advanced/pycpp/index 37 | advanced/embedding 38 | advanced/misc 39 | 40 | .. toctree:: 41 | :caption: Extra Information 42 | :maxdepth: 1 43 | 44 | faq 45 | benchmark 46 | limitations 47 | reference 48 | cmake/index 49 | -------------------------------------------------------------------------------- /lib/pybind11/docs/pybind11-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/lib/pybind11/docs/pybind11-logo.png -------------------------------------------------------------------------------- /lib/pybind11/docs/pybind11_vs_boost_python1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/lib/pybind11/docs/pybind11_vs_boost_python1.png -------------------------------------------------------------------------------- /lib/pybind11/docs/pybind11_vs_boost_python2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/lib/pybind11/docs/pybind11_vs_boost_python2.png -------------------------------------------------------------------------------- /lib/pybind11/docs/requirements.txt: -------------------------------------------------------------------------------- 1 | breathe==4.34.0 2 | furo==2022.6.21 3 | sphinx==5.0.2 4 | sphinx-copybutton==0.5.0 5 | sphinxcontrib-moderncmakedomain==3.21.4 6 | sphinxcontrib-svg2pdfconverter==1.2.0 7 | -------------------------------------------------------------------------------- /lib/pybind11/include/pybind11/common.h: -------------------------------------------------------------------------------- 1 | #include "detail/common.h" 2 | #warning "Including 'common.h' is deprecated. It will be removed in v3.0. Use 'pybind11.h'." 3 | -------------------------------------------------------------------------------- /lib/pybind11/include/pybind11/complex.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/complex.h: Complex number support 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "pybind11.h" 13 | 14 | #include 15 | 16 | /// glibc defines I as a macro which breaks things, e.g., boost template names 17 | #ifdef I 18 | # undef I 19 | #endif 20 | 21 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 22 | 23 | template 24 | struct format_descriptor, detail::enable_if_t::value>> { 25 | static constexpr const char c = format_descriptor::c; 26 | static constexpr const char value[3] = {'Z', c, '\0'}; 27 | static std::string format() { return std::string(value); } 28 | }; 29 | 30 | #ifndef PYBIND11_CPP17 31 | 32 | template 33 | constexpr const char 34 | format_descriptor, 35 | detail::enable_if_t::value>>::value[3]; 36 | 37 | #endif 38 | 39 | PYBIND11_NAMESPACE_BEGIN(detail) 40 | 41 | template 42 | struct is_fmt_numeric, detail::enable_if_t::value>> { 43 | static constexpr bool value = true; 44 | static constexpr int index = is_fmt_numeric::index + 3; 45 | }; 46 | 47 | template 48 | class type_caster> { 49 | public: 50 | bool load(handle src, bool convert) { 51 | if (!src) { 52 | return false; 53 | } 54 | if (!convert && !PyComplex_Check(src.ptr())) { 55 | return false; 56 | } 57 | Py_complex result = PyComplex_AsCComplex(src.ptr()); 58 | if (result.real == -1.0 && PyErr_Occurred()) { 59 | PyErr_Clear(); 60 | return false; 61 | } 62 | value = std::complex((T) result.real, (T) result.imag); 63 | return true; 64 | } 65 | 66 | static handle 67 | cast(const std::complex &src, return_value_policy /* policy */, handle /* parent */) { 68 | return PyComplex_FromDoubles((double) src.real(), (double) src.imag()); 69 | } 70 | 71 | PYBIND11_TYPE_CASTER(std::complex, const_name("complex")); 72 | }; 73 | PYBIND11_NAMESPACE_END(detail) 74 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 75 | -------------------------------------------------------------------------------- /lib/pybind11/include/pybind11/detail/typeid.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/detail/typeid.h: Compiler-independent access to type identifiers 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | #if defined(__GNUG__) 16 | # include 17 | #endif 18 | 19 | #include "common.h" 20 | 21 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 22 | PYBIND11_NAMESPACE_BEGIN(detail) 23 | 24 | /// Erase all occurrences of a substring 25 | inline void erase_all(std::string &string, const std::string &search) { 26 | for (size_t pos = 0;;) { 27 | pos = string.find(search, pos); 28 | if (pos == std::string::npos) { 29 | break; 30 | } 31 | string.erase(pos, search.length()); 32 | } 33 | } 34 | 35 | PYBIND11_NOINLINE void clean_type_id(std::string &name) { 36 | #if defined(__GNUG__) 37 | int status = 0; 38 | std::unique_ptr res{ 39 | abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free}; 40 | if (status == 0) { 41 | name = res.get(); 42 | } 43 | #else 44 | detail::erase_all(name, "class "); 45 | detail::erase_all(name, "struct "); 46 | detail::erase_all(name, "enum "); 47 | #endif 48 | detail::erase_all(name, "pybind11::"); 49 | } 50 | 51 | inline std::string clean_type_id(const char *typeid_name) { 52 | std::string name(typeid_name); 53 | detail::clean_type_id(name); 54 | return name; 55 | } 56 | 57 | PYBIND11_NAMESPACE_END(detail) 58 | 59 | /// Return a string representation of a C++ type 60 | template 61 | static std::string type_id() { 62 | return detail::clean_type_id(typeid(T).name()); 63 | } 64 | 65 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 66 | -------------------------------------------------------------------------------- /lib/pybind11/include/pybind11/eigen.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/eigen.h: Transparent conversion for dense and sparse Eigen matrices 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "eigen/matrix.h" 13 | -------------------------------------------------------------------------------- /lib/pybind11/include/pybind11/options.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/options.h: global settings that are configurable at runtime. 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/common.h" 13 | 14 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 15 | 16 | class options { 17 | public: 18 | // Default RAII constructor, which leaves settings as they currently are. 19 | options() : previous_state(global_state()) {} 20 | 21 | // Class is non-copyable. 22 | options(const options &) = delete; 23 | options &operator=(const options &) = delete; 24 | 25 | // Destructor, which restores settings that were in effect before. 26 | ~options() { global_state() = previous_state; } 27 | 28 | // Setter methods (affect the global state): 29 | 30 | options &disable_user_defined_docstrings() & { 31 | global_state().show_user_defined_docstrings = false; 32 | return *this; 33 | } 34 | 35 | options &enable_user_defined_docstrings() & { 36 | global_state().show_user_defined_docstrings = true; 37 | return *this; 38 | } 39 | 40 | options &disable_function_signatures() & { 41 | global_state().show_function_signatures = false; 42 | return *this; 43 | } 44 | 45 | options &enable_function_signatures() & { 46 | global_state().show_function_signatures = true; 47 | return *this; 48 | } 49 | 50 | options &disable_enum_members_docstring() & { 51 | global_state().show_enum_members_docstring = false; 52 | return *this; 53 | } 54 | 55 | options &enable_enum_members_docstring() & { 56 | global_state().show_enum_members_docstring = true; 57 | return *this; 58 | } 59 | 60 | // Getter methods (return the global state): 61 | 62 | static bool show_user_defined_docstrings() { 63 | return global_state().show_user_defined_docstrings; 64 | } 65 | 66 | static bool show_function_signatures() { return global_state().show_function_signatures; } 67 | 68 | static bool show_enum_members_docstring() { 69 | return global_state().show_enum_members_docstring; 70 | } 71 | 72 | // This type is not meant to be allocated on the heap. 73 | void *operator new(size_t) = delete; 74 | 75 | private: 76 | struct state { 77 | bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings. 78 | bool show_function_signatures = true; //< Include auto-generated function signatures 79 | // in docstrings. 80 | bool show_enum_members_docstring = true; //< Include auto-generated member list in enum 81 | // docstrings. 82 | }; 83 | 84 | static state &global_state() { 85 | static state instance; 86 | return instance; 87 | } 88 | 89 | state previous_state; 90 | }; 91 | 92 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 93 | -------------------------------------------------------------------------------- /lib/pybind11/pybind11/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | if sys.version_info < (3, 6): 4 | msg = "pybind11 does not support Python < 3.6. 2.9 was the last release supporting Python 2.7 and 3.5." 5 | raise ImportError(msg) 6 | 7 | 8 | from ._version import __version__, version_info 9 | from .commands import get_cmake_dir, get_include, get_pkgconfig_dir 10 | 11 | __all__ = ( 12 | "version_info", 13 | "__version__", 14 | "get_include", 15 | "get_cmake_dir", 16 | "get_pkgconfig_dir", 17 | ) 18 | -------------------------------------------------------------------------------- /lib/pybind11/pybind11/__main__.py: -------------------------------------------------------------------------------- 1 | # pylint: disable=missing-function-docstring 2 | 3 | import argparse 4 | import sys 5 | import sysconfig 6 | 7 | from .commands import get_cmake_dir, get_include, get_pkgconfig_dir 8 | 9 | 10 | def print_includes() -> None: 11 | dirs = [ 12 | sysconfig.get_path("include"), 13 | sysconfig.get_path("platinclude"), 14 | get_include(), 15 | ] 16 | 17 | # Make unique but preserve order 18 | unique_dirs = [] 19 | for d in dirs: 20 | if d and d not in unique_dirs: 21 | unique_dirs.append(d) 22 | 23 | print(" ".join("-I" + d for d in unique_dirs)) 24 | 25 | 26 | def main() -> None: 27 | parser = argparse.ArgumentParser() 28 | parser.add_argument( 29 | "--includes", 30 | action="store_true", 31 | help="Include flags for both pybind11 and Python headers.", 32 | ) 33 | parser.add_argument( 34 | "--cmakedir", 35 | action="store_true", 36 | help="Print the CMake module directory, ideal for setting -Dpybind11_ROOT in CMake.", 37 | ) 38 | parser.add_argument( 39 | "--pkgconfigdir", 40 | action="store_true", 41 | help="Print the pkgconfig directory, ideal for setting $PKG_CONFIG_PATH.", 42 | ) 43 | args = parser.parse_args() 44 | if not sys.argv[1:]: 45 | parser.print_help() 46 | if args.includes: 47 | print_includes() 48 | if args.cmakedir: 49 | print(get_cmake_dir()) 50 | if args.pkgconfigdir: 51 | print(get_pkgconfig_dir()) 52 | 53 | 54 | if __name__ == "__main__": 55 | main() 56 | -------------------------------------------------------------------------------- /lib/pybind11/pybind11/_version.py: -------------------------------------------------------------------------------- 1 | from typing import Union 2 | 3 | 4 | def _to_int(s: str) -> Union[int, str]: 5 | try: 6 | return int(s) 7 | except ValueError: 8 | return s 9 | 10 | 11 | __version__ = "2.11.0.dev1" 12 | version_info = tuple(_to_int(s) for s in __version__.split(".")) 13 | -------------------------------------------------------------------------------- /lib/pybind11/pybind11/commands.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | DIR = os.path.abspath(os.path.dirname(__file__)) 4 | 5 | 6 | def get_include(user: bool = False) -> str: # pylint: disable=unused-argument 7 | """ 8 | Return the path to the pybind11 include directory. The historical "user" 9 | argument is unused, and may be removed. 10 | """ 11 | installed_path = os.path.join(DIR, "include") 12 | source_path = os.path.join(os.path.dirname(DIR), "include") 13 | return installed_path if os.path.exists(installed_path) else source_path 14 | 15 | 16 | def get_cmake_dir() -> str: 17 | """ 18 | Return the path to the pybind11 CMake module directory. 19 | """ 20 | cmake_installed_path = os.path.join(DIR, "share", "cmake", "pybind11") 21 | if os.path.exists(cmake_installed_path): 22 | return cmake_installed_path 23 | 24 | msg = "pybind11 not installed, installation required to access the CMake files" 25 | raise ImportError(msg) 26 | 27 | 28 | def get_pkgconfig_dir() -> str: 29 | """ 30 | Return the path to the pybind11 pkgconfig directory. 31 | """ 32 | pkgconfig_installed_path = os.path.join(DIR, "share", "pkgconfig") 33 | if os.path.exists(pkgconfig_installed_path): 34 | return pkgconfig_installed_path 35 | 36 | msg = "pybind11 not installed, installation required to access the pkgconfig files" 37 | raise ImportError(msg) 38 | -------------------------------------------------------------------------------- /lib/pybind11/pybind11/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/lib/pybind11/pybind11/py.typed -------------------------------------------------------------------------------- /lib/pybind11/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=42", "cmake>=3.18", "ninja"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [tool.check-manifest] 6 | ignore = [ 7 | "tests/**", 8 | "docs/**", 9 | "tools/**", 10 | "include/**", 11 | ".*", 12 | "pybind11/include/**", 13 | "pybind11/share/**", 14 | "CMakeLists.txt", 15 | "noxfile.py", 16 | ] 17 | 18 | [tool.isort] 19 | # Needs the compiled .so modules and env.py from tests 20 | known_first_party = "env,pybind11_cross_module_tests,pybind11_tests," 21 | # For black compatibility 22 | profile = "black" 23 | 24 | [tool.mypy] 25 | files = ["pybind11"] 26 | python_version = "3.6" 27 | strict = true 28 | show_error_codes = true 29 | enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] 30 | warn_unreachable = true 31 | 32 | [[tool.mypy.overrides]] 33 | module = ["ghapi.*", "setuptools.*"] 34 | ignore_missing_imports = true 35 | 36 | 37 | [tool.pytest.ini_options] 38 | minversion = "6.0" 39 | addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"] 40 | xfail_strict = true 41 | filterwarnings = ["error"] 42 | log_cli_level = "info" 43 | testpaths = [ 44 | "tests", 45 | ] 46 | timeout=300 47 | 48 | 49 | [tool.pylint] 50 | master.py-version = "3.6" 51 | reports.output-format = "colorized" 52 | messages_control.disable = [ 53 | "design", 54 | "fixme", 55 | "imports", 56 | "line-too-long", 57 | "imports", 58 | "invalid-name", 59 | "protected-access", 60 | "missing-module-docstring", 61 | ] 62 | -------------------------------------------------------------------------------- /lib/pybind11/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | long_description = file: README.rst 3 | long_description_content_type = text/x-rst 4 | description = Seamless operability between C++11 and Python 5 | author = Wenzel Jakob 6 | author_email = wenzel.jakob@epfl.ch 7 | url = https://github.com/pybind/pybind11 8 | license = BSD 9 | 10 | classifiers = 11 | Development Status :: 5 - Production/Stable 12 | Intended Audience :: Developers 13 | Topic :: Software Development :: Libraries :: Python Modules 14 | Topic :: Utilities 15 | Programming Language :: C++ 16 | Programming Language :: Python :: 3 :: Only 17 | Programming Language :: Python :: 3.6 18 | Programming Language :: Python :: 3.7 19 | Programming Language :: Python :: 3.8 20 | Programming Language :: Python :: 3.9 21 | Programming Language :: Python :: 3.10 22 | Programming Language :: Python :: 3.11 23 | License :: OSI Approved :: BSD License 24 | Programming Language :: Python :: Implementation :: PyPy 25 | Programming Language :: Python :: Implementation :: CPython 26 | Programming Language :: C++ 27 | Topic :: Software Development :: Libraries :: Python Modules 28 | 29 | keywords = 30 | C++11 31 | Python bindings 32 | 33 | project_urls = 34 | Documentation = https://pybind11.readthedocs.io/ 35 | Bug Tracker = https://github.com/pybind/pybind11/issues 36 | Discussions = https://github.com/pybind/pybind11/discussions 37 | Changelog = https://pybind11.readthedocs.io/en/latest/changelog.html 38 | Chat = https://gitter.im/pybind/Lobby 39 | 40 | [options] 41 | python_requires = >=3.6 42 | zip_safe = False 43 | 44 | 45 | [flake8] 46 | max-line-length = 120 47 | show_source = True 48 | exclude = .git, __pycache__, build, dist, docs, tools, venv 49 | extend-ignore = E203, E722 50 | extend-select = B902, B904 51 | -------------------------------------------------------------------------------- /lib/pybind11/tests/cross_module_interleaved_error_already_set.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2022 Google LLC 3 | 4 | All rights reserved. Use of this source code is governed by a 5 | BSD-style license that can be found in the LICENSE file. 6 | */ 7 | 8 | #include 9 | 10 | // This file mimics a DSO that makes pybind11 calls but does not define a PYBIND11_MODULE, 11 | // so that the first call of cross_module_error_already_set() triggers the first call of 12 | // pybind11::detail::get_internals(). 13 | 14 | namespace { 15 | 16 | namespace py = pybind11; 17 | 18 | void interleaved_error_already_set() { 19 | PyErr_SetString(PyExc_RuntimeError, "1st error."); 20 | try { 21 | throw py::error_already_set(); 22 | } catch (const py::error_already_set &) { 23 | // The 2nd error could be conditional in a real application. 24 | PyErr_SetString(PyExc_RuntimeError, "2nd error."); 25 | } // Here the 1st error is destroyed before the 2nd error is fetched. 26 | // The error_already_set dtor triggers a pybind11::detail::get_internals() 27 | // call via pybind11::gil_scoped_acquire. 28 | if (PyErr_Occurred()) { 29 | throw py::error_already_set(); 30 | } 31 | } 32 | 33 | constexpr char kModuleName[] = "cross_module_interleaved_error_already_set"; 34 | 35 | struct PyModuleDef moduledef = { 36 | PyModuleDef_HEAD_INIT, kModuleName, nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr}; 37 | 38 | } // namespace 39 | 40 | extern "C" PYBIND11_EXPORT PyObject *PyInit_cross_module_interleaved_error_already_set() { 41 | PyObject *m = PyModule_Create(&moduledef); 42 | if (m != nullptr) { 43 | static_assert(sizeof(&interleaved_error_already_set) == sizeof(void *), 44 | "Function pointer must have the same size as void *"); 45 | PyModule_AddObject( 46 | m, 47 | "funcaddr", 48 | PyLong_FromVoidPtr(reinterpret_cast(&interleaved_error_already_set))); 49 | } 50 | return m; 51 | } 52 | -------------------------------------------------------------------------------- /lib/pybind11/tests/eigen_tensor_avoid_stl_array.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/eigen_tensor.cpp -- automatic conversion of Eigen Tensor 3 | 4 | All rights reserved. Use of this source code is governed by a 5 | BSD-style license that can be found in the LICENSE file. 6 | */ 7 | 8 | #ifndef EIGEN_AVOID_STL_ARRAY 9 | # define EIGEN_AVOID_STL_ARRAY 10 | #endif 11 | 12 | #include "test_eigen_tensor.inl" 13 | 14 | PYBIND11_MODULE(eigen_tensor_avoid_stl_array, m) { eigen_tensor_test::test_module(m); } 15 | -------------------------------------------------------------------------------- /lib/pybind11/tests/env.py: -------------------------------------------------------------------------------- 1 | import platform 2 | import sys 3 | 4 | import pytest 5 | 6 | LINUX = sys.platform.startswith("linux") 7 | MACOS = sys.platform.startswith("darwin") 8 | WIN = sys.platform.startswith("win32") or sys.platform.startswith("cygwin") 9 | 10 | CPYTHON = platform.python_implementation() == "CPython" 11 | PYPY = platform.python_implementation() == "PyPy" 12 | 13 | 14 | def deprecated_call(): 15 | """ 16 | pytest.deprecated_call() seems broken in pytest<3.9.x; concretely, it 17 | doesn't work on CPython 3.8.0 with pytest==3.3.2 on Ubuntu 18.04 (#2922). 18 | 19 | This is a narrowed reimplementation of the following PR :( 20 | https://github.com/pytest-dev/pytest/pull/4104 21 | """ 22 | # TODO: Remove this when testing requires pytest>=3.9. 23 | pieces = pytest.__version__.split(".") 24 | pytest_major_minor = (int(pieces[0]), int(pieces[1])) 25 | if pytest_major_minor < (3, 9): 26 | return pytest.warns((DeprecationWarning, PendingDeprecationWarning)) 27 | else: 28 | return pytest.deprecated_call() 29 | -------------------------------------------------------------------------------- /lib/pybind11/tests/extra_python_package/pytest.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/lib/pybind11/tests/extra_python_package/pytest.ini -------------------------------------------------------------------------------- /lib/pybind11/tests/extra_setuptools/pytest.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ducha-aiki/pydegensac/030a44dc66eb5906a6898cc4b23cc5544b7244fe/lib/pybind11/tests/extra_setuptools/pytest.ini -------------------------------------------------------------------------------- /lib/pybind11/tests/pybind11_tests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace py = pybind11; 7 | using namespace pybind11::literals; 8 | 9 | class test_initializer { 10 | using Initializer = void (*)(py::module_ &); 11 | 12 | public: 13 | explicit test_initializer(Initializer init); 14 | test_initializer(const char *submodule_name, Initializer init); 15 | }; 16 | 17 | #define TEST_SUBMODULE(name, variable) \ 18 | void test_submodule_##name(py::module_ &); \ 19 | test_initializer name(#name, test_submodule_##name); \ 20 | void test_submodule_##name(py::module_ &(variable)) 21 | 22 | /// Dummy type which is not exported anywhere -- something to trigger a conversion error 23 | struct UnregisteredType {}; 24 | 25 | /// A user-defined type which is exported and can be used by any test 26 | class UserType { 27 | public: 28 | UserType() = default; 29 | explicit UserType(int i) : i(i) {} 30 | 31 | int value() const { return i; } 32 | void set(int set) { i = set; } 33 | 34 | private: 35 | int i = -1; 36 | }; 37 | 38 | /// Like UserType, but increments `value` on copy for quick reference vs. copy tests 39 | class IncType : public UserType { 40 | public: 41 | using UserType::UserType; 42 | IncType() = default; 43 | IncType(const IncType &other) : IncType(other.value() + 1) {} 44 | IncType(IncType &&) = delete; 45 | IncType &operator=(const IncType &) = delete; 46 | IncType &operator=(IncType &&) = delete; 47 | }; 48 | 49 | /// A simple union for basic testing 50 | union IntFloat { 51 | int i; 52 | float f; 53 | }; 54 | 55 | /// Custom cast-only type that casts to a string "rvalue" or "lvalue" depending on the cast 56 | /// context. Used to test recursive casters (e.g. std::tuple, stl containers). 57 | struct RValueCaster {}; 58 | PYBIND11_NAMESPACE_BEGIN(pybind11) 59 | PYBIND11_NAMESPACE_BEGIN(detail) 60 | template <> 61 | class type_caster { 62 | public: 63 | PYBIND11_TYPE_CASTER(RValueCaster, const_name("RValueCaster")); 64 | static handle cast(RValueCaster &&, return_value_policy, handle) { 65 | return py::str("rvalue").release(); 66 | } 67 | static handle cast(const RValueCaster &, return_value_policy, handle) { 68 | return py::str("lvalue").release(); 69 | } 70 | }; 71 | PYBIND11_NAMESPACE_END(detail) 72 | PYBIND11_NAMESPACE_END(pybind11) 73 | 74 | template 75 | void ignoreOldStyleInitWarnings(F &&body) { 76 | py::exec(R"( 77 | message = "pybind11-bound class '.+' is using an old-style placement-new '(?:__init__|__setstate__)' which has been deprecated" 78 | 79 | import warnings 80 | with warnings.catch_warnings(): 81 | warnings.filterwarnings("ignore", message=message, category=FutureWarning) 82 | body() 83 | )", 84 | py::dict(py::arg("body") = py::cpp_function(body))); 85 | } 86 | -------------------------------------------------------------------------------- /lib/pybind11/tests/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | minversion = 3.10 3 | norecursedirs = test_* extra_* 4 | xfail_strict = True 5 | addopts = 6 | # show summary of tests 7 | -ra 8 | # capture only Python print and C++ py::print, but not C output (low-level Python errors) 9 | --capture=sys 10 | # Show local info when a failure occurs 11 | --showlocals 12 | log_cli_level = info 13 | filterwarnings = 14 | # make warnings into errors but ignore certain third-party extension issues 15 | error 16 | # somehow, some DeprecationWarnings do not get turned into errors 17 | always::DeprecationWarning 18 | # importing scipy submodules on some version of Python 19 | ignore::ImportWarning 20 | # bogus numpy ABI warning (see numpy/#432) 21 | ignore:.*numpy.dtype size changed.*:RuntimeWarning 22 | ignore:.*numpy.ufunc size changed.*:RuntimeWarning 23 | -------------------------------------------------------------------------------- /lib/pybind11/tests/requirements.txt: -------------------------------------------------------------------------------- 1 | build==0.8.0 2 | numpy==1.21.5; platform_python_implementation=="PyPy" and sys_platform=="linux" and python_version=="3.7" 3 | numpy==1.19.3; platform_python_implementation!="PyPy" and python_version=="3.6" 4 | numpy==1.21.5; platform_python_implementation!="PyPy" and python_version>="3.7" and python_version<"3.10" 5 | numpy==1.22.2; platform_python_implementation!="PyPy" and python_version>="3.10" and python_version<"3.11" 6 | pytest==7.0.0 7 | pytest-timeout 8 | scipy==1.5.4; platform_python_implementation!="PyPy" and python_version<"3.10" 9 | scipy==1.8.0; platform_python_implementation!="PyPy" and python_version=="3.10" 10 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_async.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_async.cpp -- __await__ support 3 | 4 | Copyright (c) 2019 Google Inc. 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include "pybind11_tests.h" 11 | 12 | TEST_SUBMODULE(async_module, m) { 13 | struct DoesNotSupportAsync {}; 14 | py::class_(m, "DoesNotSupportAsync").def(py::init<>()); 15 | struct SupportsAsync {}; 16 | py::class_(m, "SupportsAsync") 17 | .def(py::init<>()) 18 | .def("__await__", [](const SupportsAsync &self) -> py::object { 19 | static_cast(self); 20 | py::object loop = py::module_::import("asyncio.events").attr("get_event_loop")(); 21 | py::object f = loop.attr("create_future")(); 22 | f.attr("set_result")(5); 23 | return f.attr("__await__")(); 24 | }); 25 | } 26 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_async.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | asyncio = pytest.importorskip("asyncio") 4 | m = pytest.importorskip("pybind11_tests.async_module") 5 | 6 | 7 | @pytest.fixture 8 | def event_loop(): 9 | loop = asyncio.new_event_loop() 10 | yield loop 11 | loop.close() 12 | 13 | 14 | async def get_await_result(x): 15 | return await x 16 | 17 | 18 | def test_await(event_loop): 19 | assert 5 == event_loop.run_until_complete(get_await_result(m.SupportsAsync())) 20 | 21 | 22 | def test_await_missing(event_loop): 23 | with pytest.raises(TypeError): 24 | event_loop.run_until_complete(get_await_result(m.DoesNotSupportAsync())) 25 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_cmake_build/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Built-in in CMake 3.5+ 2 | include(CMakeParseArguments) 3 | 4 | add_custom_target(test_cmake_build) 5 | 6 | function(pybind11_add_build_test name) 7 | cmake_parse_arguments(ARG "INSTALL" "" "" ${ARGN}) 8 | 9 | set(build_options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}") 10 | 11 | if(PYBIND11_FINDPYTHON) 12 | list(APPEND build_options "-DPYBIND11_FINDPYTHON=${PYBIND11_FINDPYTHON}") 13 | 14 | if(DEFINED Python_ROOT_DIR) 15 | list(APPEND build_options "-DPython_ROOT_DIR=${Python_ROOT_DIR}") 16 | endif() 17 | 18 | list(APPEND build_options "-DPython_EXECUTABLE=${Python_EXECUTABLE}") 19 | else() 20 | list(APPEND build_options "-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}") 21 | endif() 22 | 23 | if(DEFINED CMAKE_CXX_STANDARD) 24 | list(APPEND build_options "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}") 25 | endif() 26 | 27 | if(NOT ARG_INSTALL) 28 | list(APPEND build_options "-Dpybind11_SOURCE_DIR=${pybind11_SOURCE_DIR}") 29 | else() 30 | list(APPEND build_options "-DCMAKE_PREFIX_PATH=${pybind11_BINARY_DIR}/mock_install") 31 | endif() 32 | 33 | add_custom_target( 34 | test_build_${name} 35 | ${CMAKE_CTEST_COMMAND} 36 | --build-and-test 37 | "${CMAKE_CURRENT_SOURCE_DIR}/${name}" 38 | "${CMAKE_CURRENT_BINARY_DIR}/${name}" 39 | --build-config 40 | Release 41 | --build-noclean 42 | --build-generator 43 | ${CMAKE_GENERATOR} 44 | $<$:--build-generator-platform> 45 | ${CMAKE_GENERATOR_PLATFORM} 46 | --build-makeprogram 47 | ${CMAKE_MAKE_PROGRAM} 48 | --build-target 49 | check_${name} 50 | --build-options 51 | ${build_options}) 52 | if(ARG_INSTALL) 53 | add_dependencies(test_build_${name} mock_install) 54 | endif() 55 | add_dependencies(test_cmake_build test_build_${name}) 56 | endfunction() 57 | 58 | possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID) 59 | 60 | pybind11_add_build_test(subdirectory_function) 61 | pybind11_add_build_test(subdirectory_target) 62 | if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy") 63 | message(STATUS "Skipping embed test on PyPy") 64 | else() 65 | pybind11_add_build_test(subdirectory_embed) 66 | endif() 67 | 68 | if(PYBIND11_INSTALL) 69 | add_custom_target( 70 | mock_install ${CMAKE_COMMAND} "-DCMAKE_INSTALL_PREFIX=${pybind11_BINARY_DIR}/mock_install" -P 71 | "${pybind11_BINARY_DIR}/cmake_install.cmake") 72 | 73 | pybind11_add_build_test(installed_function INSTALL) 74 | pybind11_add_build_test(installed_target INSTALL) 75 | if(NOT ("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy" 76 | )) 77 | pybind11_add_build_test(installed_embed INSTALL) 78 | endif() 79 | endif() 80 | 81 | add_dependencies(check test_cmake_build) 82 | 83 | add_subdirectory(subdirectory_target EXCLUDE_FROM_ALL) 84 | add_subdirectory(subdirectory_embed EXCLUDE_FROM_ALL) 85 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_cmake_build/embed.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace py = pybind11; 3 | 4 | PYBIND11_EMBEDDED_MODULE(test_cmake_build, m) { 5 | m.def("add", [](int i, int j) { return i + j; }); 6 | } 7 | 8 | int main(int argc, char *argv[]) { 9 | if (argc != 2) { 10 | throw std::runtime_error("Expected test.py file as the first argument"); 11 | } 12 | auto *test_py_file = argv[1]; 13 | 14 | py::scoped_interpreter guard{}; 15 | 16 | auto m = py::module_::import("test_cmake_build"); 17 | if (m.attr("add")(1, 2).cast() != 3) { 18 | throw std::runtime_error("embed.cpp failed"); 19 | } 20 | 21 | py::module_::import("sys").attr("argv") = py::make_tuple("test.py", "embed.cpp"); 22 | py::eval_file(test_py_file, py::globals()); 23 | } 24 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4) 2 | 3 | # The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with 4 | # some versions of VS that have a patched CMake 3.11. This forces us to emulate 5 | # the behavior using the following workaround: 6 | if(${CMAKE_VERSION} VERSION_LESS 3.18) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.18) 10 | endif() 11 | 12 | project(test_installed_embed CXX) 13 | 14 | find_package(pybind11 CONFIG REQUIRED) 15 | message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") 16 | 17 | add_executable(test_installed_embed ../embed.cpp) 18 | target_link_libraries(test_installed_embed PRIVATE pybind11::embed) 19 | set_target_properties(test_installed_embed PROPERTIES OUTPUT_NAME test_cmake_build) 20 | 21 | # Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::embed). 22 | # This may be needed to resolve header conflicts, e.g. between Python release and debug headers. 23 | set_target_properties(test_installed_embed PROPERTIES NO_SYSTEM_FROM_IMPORTED ON) 24 | 25 | add_custom_target( 26 | check_installed_embed 27 | $ ${PROJECT_SOURCE_DIR}/../test.py 28 | DEPENDS test_installed_embed) 29 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4) 2 | project(test_installed_module CXX) 3 | 4 | # The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with 5 | # some versions of VS that have a patched CMake 3.11. This forces us to emulate 6 | # the behavior using the following workaround: 7 | if(${CMAKE_VERSION} VERSION_LESS 3.18) 8 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 9 | else() 10 | cmake_policy(VERSION 3.18) 11 | endif() 12 | 13 | project(test_installed_function CXX) 14 | 15 | find_package(pybind11 CONFIG REQUIRED) 16 | message( 17 | STATUS "Found pybind11 v${pybind11_VERSION} ${pybind11_VERSION_TYPE}: ${pybind11_INCLUDE_DIRS}") 18 | 19 | pybind11_add_module(test_installed_function SHARED NO_EXTRAS ../main.cpp) 20 | set_target_properties(test_installed_function PROPERTIES OUTPUT_NAME test_cmake_build) 21 | 22 | if(DEFINED Python_EXECUTABLE) 23 | set(_Python_EXECUTABLE "${Python_EXECUTABLE}") 24 | elseif(DEFINED PYTHON_EXECUTABLE) 25 | set(_Python_EXECUTABLE "${PYTHON_EXECUTABLE}") 26 | else() 27 | message(FATAL_ERROR "No Python executable defined (should not be possible at this stage)") 28 | endif() 29 | 30 | add_custom_target( 31 | check_installed_function 32 | ${CMAKE_COMMAND} 33 | -E 34 | env 35 | PYTHONPATH=$ 36 | ${_Python_EXECUTABLE} 37 | ${PROJECT_SOURCE_DIR}/../test.py 38 | ${PROJECT_NAME} 39 | DEPENDS test_installed_function) 40 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4) 2 | 3 | # The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with 4 | # some versions of VS that have a patched CMake 3.11. This forces us to emulate 5 | # the behavior using the following workaround: 6 | if(${CMAKE_VERSION} VERSION_LESS 3.18) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.18) 10 | endif() 11 | 12 | project(test_installed_target CXX) 13 | 14 | find_package(pybind11 CONFIG REQUIRED) 15 | message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}") 16 | 17 | add_library(test_installed_target MODULE ../main.cpp) 18 | 19 | target_link_libraries(test_installed_target PRIVATE pybind11::module) 20 | set_target_properties(test_installed_target PROPERTIES OUTPUT_NAME test_cmake_build) 21 | 22 | # Make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib 23 | pybind11_extension(test_installed_target) 24 | 25 | # Do not treat includes from IMPORTED target as SYSTEM (Python headers in pybind11::module). 26 | # This may be needed to resolve header conflicts, e.g. between Python release and debug headers. 27 | set_target_properties(test_installed_target PROPERTIES NO_SYSTEM_FROM_IMPORTED ON) 28 | 29 | if(DEFINED Python_EXECUTABLE) 30 | set(_Python_EXECUTABLE "${Python_EXECUTABLE}") 31 | elseif(DEFINED PYTHON_EXECUTABLE) 32 | set(_Python_EXECUTABLE "${PYTHON_EXECUTABLE}") 33 | else() 34 | message(FATAL_ERROR "No Python executable defined (should not be possible at this stage)") 35 | endif() 36 | 37 | add_custom_target( 38 | check_installed_target 39 | ${CMAKE_COMMAND} 40 | -E 41 | env 42 | PYTHONPATH=$ 43 | ${_Python_EXECUTABLE} 44 | ${PROJECT_SOURCE_DIR}/../test.py 45 | ${PROJECT_NAME} 46 | DEPENDS test_installed_target) 47 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_cmake_build/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace py = pybind11; 3 | 4 | PYBIND11_MODULE(test_cmake_build, m) { 5 | m.def("add", [](int i, int j) { return i + j; }); 6 | } 7 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4) 2 | 3 | # The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with 4 | # some versions of VS that have a patched CMake 3.11. This forces us to emulate 5 | # the behavior using the following workaround: 6 | if(${CMAKE_VERSION} VERSION_LESS 3.18) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.18) 10 | endif() 11 | 12 | project(test_subdirectory_embed CXX) 13 | 14 | set(PYBIND11_INSTALL 15 | ON 16 | CACHE BOOL "") 17 | set(PYBIND11_EXPORT_NAME test_export) 18 | 19 | add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) 20 | 21 | # Test basic target functionality 22 | add_executable(test_subdirectory_embed ../embed.cpp) 23 | target_link_libraries(test_subdirectory_embed PRIVATE pybind11::embed) 24 | set_target_properties(test_subdirectory_embed PROPERTIES OUTPUT_NAME test_cmake_build) 25 | 26 | add_custom_target( 27 | check_subdirectory_embed 28 | $ "${PROJECT_SOURCE_DIR}/../test.py" 29 | DEPENDS test_subdirectory_embed) 30 | 31 | # Test custom export group -- PYBIND11_EXPORT_NAME 32 | add_library(test_embed_lib ../embed.cpp) 33 | target_link_libraries(test_embed_lib PRIVATE pybind11::embed) 34 | 35 | install( 36 | TARGETS test_embed_lib 37 | EXPORT test_export 38 | ARCHIVE DESTINATION bin 39 | LIBRARY DESTINATION lib 40 | RUNTIME DESTINATION lib) 41 | install(EXPORT test_export DESTINATION lib/cmake/test_export/test_export-Targets.cmake) 42 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4) 2 | 3 | # The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with 4 | # some versions of VS that have a patched CMake 3.11. This forces us to emulate 5 | # the behavior using the following workaround: 6 | if(${CMAKE_VERSION} VERSION_LESS 3.18) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.18) 10 | endif() 11 | 12 | project(test_subdirectory_function CXX) 13 | 14 | add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) 15 | pybind11_add_module(test_subdirectory_function ../main.cpp) 16 | set_target_properties(test_subdirectory_function PROPERTIES OUTPUT_NAME test_cmake_build) 17 | 18 | if(DEFINED Python_EXECUTABLE) 19 | set(_Python_EXECUTABLE "${Python_EXECUTABLE}") 20 | elseif(DEFINED PYTHON_EXECUTABLE) 21 | set(_Python_EXECUTABLE "${PYTHON_EXECUTABLE}") 22 | else() 23 | message(FATAL_ERROR "No Python executable defined (should not be possible at this stage)") 24 | endif() 25 | 26 | add_custom_target( 27 | check_subdirectory_function 28 | ${CMAKE_COMMAND} 29 | -E 30 | env 31 | PYTHONPATH=$ 32 | ${_Python_EXECUTABLE} 33 | ${PROJECT_SOURCE_DIR}/../test.py 34 | ${PROJECT_NAME} 35 | DEPENDS test_subdirectory_function) 36 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4) 2 | 3 | # The `cmake_minimum_required(VERSION 3.4...3.18)` syntax does not work with 4 | # some versions of VS that have a patched CMake 3.11. This forces us to emulate 5 | # the behavior using the following workaround: 6 | if(${CMAKE_VERSION} VERSION_LESS 3.18) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.18) 10 | endif() 11 | 12 | project(test_subdirectory_target CXX) 13 | 14 | add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) 15 | 16 | add_library(test_subdirectory_target MODULE ../main.cpp) 17 | set_target_properties(test_subdirectory_target PROPERTIES OUTPUT_NAME test_cmake_build) 18 | 19 | target_link_libraries(test_subdirectory_target PRIVATE pybind11::module) 20 | 21 | # Make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib 22 | pybind11_extension(test_subdirectory_target) 23 | 24 | if(DEFINED Python_EXECUTABLE) 25 | set(_Python_EXECUTABLE "${Python_EXECUTABLE}") 26 | elseif(DEFINED PYTHON_EXECUTABLE) 27 | set(_Python_EXECUTABLE "${PYTHON_EXECUTABLE}") 28 | else() 29 | message(FATAL_ERROR "No Python executable defined (should not be possible at this stage)") 30 | endif() 31 | 32 | add_custom_target( 33 | check_subdirectory_target 34 | ${CMAKE_COMMAND} 35 | -E 36 | env 37 | PYTHONPATH=$ 38 | ${_Python_EXECUTABLE} 39 | ${PROJECT_SOURCE_DIR}/../test.py 40 | ${PROJECT_NAME} 41 | DEPENDS test_subdirectory_target) 42 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_cmake_build/test.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | import test_cmake_build 4 | 5 | assert isinstance(__file__, str) # Test this is properly set 6 | 7 | assert test_cmake_build.add(1, 2) == 3 8 | print(f"{sys.argv[1]} imports, runs, and adds: 1 + 2 = 3") 9 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_const_name.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pybind11_tests import const_name as m 4 | 5 | 6 | @pytest.mark.parametrize("func", (m.const_name_tests, m.underscore_tests)) 7 | @pytest.mark.parametrize( 8 | "selector, expected", 9 | enumerate( 10 | ( 11 | "", 12 | "A", 13 | "Bd", 14 | "Cef", 15 | "%", 16 | "%", 17 | "T1", 18 | "U2", 19 | "D1", 20 | "E2", 21 | "KeepAtEnd", 22 | ) 23 | ), 24 | ) 25 | def test_const_name(func, selector, expected): 26 | if isinstance(func, str): 27 | pytest.skip(func) 28 | text = func(selector) 29 | assert text == expected 30 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_constants_and_functions.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | m = pytest.importorskip("pybind11_tests.constants_and_functions") 4 | 5 | 6 | def test_constants(): 7 | assert m.some_constant == 14 8 | 9 | 10 | def test_function_overloading(): 11 | assert m.test_function() == "test_function()" 12 | assert m.test_function(7) == "test_function(7)" 13 | assert m.test_function(m.MyEnum.EFirstEntry) == "test_function(enum=1)" 14 | assert m.test_function(m.MyEnum.ESecondEntry) == "test_function(enum=2)" 15 | 16 | assert m.test_function() == "test_function()" 17 | assert m.test_function("abcd") == "test_function(char *)" 18 | assert m.test_function(1, 1.0) == "test_function(int, float)" 19 | assert m.test_function(1, 1.0) == "test_function(int, float)" 20 | assert m.test_function(2.0, 2) == "test_function(float, int)" 21 | 22 | 23 | def test_bytes(): 24 | assert m.print_bytes(m.return_bytes()) == "bytes[1 0 2 0]" 25 | 26 | 27 | def test_exception_specifiers(): 28 | c = m.C() 29 | assert c.m1(2) == 1 30 | assert c.m2(3) == 1 31 | assert c.m3(5) == 2 32 | assert c.m4(7) == 3 33 | assert c.m5(10) == 5 34 | assert c.m6(14) == 8 35 | assert c.m7(20) == 13 36 | assert c.m8(29) == 21 37 | 38 | assert m.f1(33) == 34 39 | assert m.f2(53) == 55 40 | assert m.f3(86) == 89 41 | assert m.f4(140) == 144 42 | 43 | 44 | def test_function_record_leaks(): 45 | class RaisingRepr: 46 | def __repr__(self): 47 | raise RuntimeError("Surprise!") 48 | 49 | with pytest.raises(RuntimeError): 50 | m.register_large_capture_with_invalid_arguments(m) 51 | with pytest.raises(RuntimeError): 52 | m.register_with_raising_repr(m, RaisingRepr()) 53 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_custom_type_setup.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_custom_type_setup.cpp -- Tests `pybind11::custom_type_setup` 3 | 4 | Copyright (c) Google LLC 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | #include "pybind11_tests.h" 13 | 14 | namespace py = pybind11; 15 | 16 | namespace { 17 | 18 | struct OwnsPythonObjects { 19 | py::object value = py::none(); 20 | }; 21 | } // namespace 22 | 23 | TEST_SUBMODULE(custom_type_setup, m) { 24 | py::class_ cls( 25 | m, "OwnsPythonObjects", py::custom_type_setup([](PyHeapTypeObject *heap_type) { 26 | auto *type = &heap_type->ht_type; 27 | type->tp_flags |= Py_TPFLAGS_HAVE_GC; 28 | type->tp_traverse = [](PyObject *self_base, visitproc visit, void *arg) { 29 | auto &self = py::cast(py::handle(self_base)); 30 | Py_VISIT(self.value.ptr()); 31 | return 0; 32 | }; 33 | type->tp_clear = [](PyObject *self_base) { 34 | auto &self = py::cast(py::handle(self_base)); 35 | self.value = py::none(); 36 | return 0; 37 | }; 38 | })); 39 | cls.def(py::init<>()); 40 | cls.def_readwrite("value", &OwnsPythonObjects::value); 41 | } 42 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_custom_type_setup.py: -------------------------------------------------------------------------------- 1 | import gc 2 | import weakref 3 | 4 | import pytest 5 | 6 | import env # noqa: F401 7 | from pybind11_tests import custom_type_setup as m 8 | 9 | 10 | @pytest.fixture 11 | def gc_tester(): 12 | """Tests that an object is garbage collected. 13 | 14 | Assumes that any unreferenced objects are fully collected after calling 15 | `gc.collect()`. That is true on CPython, but does not appear to reliably 16 | hold on PyPy. 17 | """ 18 | 19 | weak_refs = [] 20 | 21 | def add_ref(obj): 22 | # PyPy does not support `gc.is_tracked`. 23 | if hasattr(gc, "is_tracked"): 24 | assert gc.is_tracked(obj) 25 | weak_refs.append(weakref.ref(obj)) 26 | 27 | yield add_ref 28 | 29 | gc.collect() 30 | for ref in weak_refs: 31 | assert ref() is None 32 | 33 | 34 | # PyPy does not seem to reliably garbage collect. 35 | @pytest.mark.skipif("env.PYPY") 36 | def test_self_cycle(gc_tester): 37 | obj = m.OwnsPythonObjects() 38 | obj.value = obj 39 | gc_tester(obj) 40 | 41 | 42 | # PyPy does not seem to reliably garbage collect. 43 | @pytest.mark.skipif("env.PYPY") 44 | def test_indirect_cycle(gc_tester): 45 | obj = m.OwnsPythonObjects() 46 | obj_list = [obj] 47 | obj.value = obj_list 48 | gc_tester(obj) 49 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_docstring_options.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import docstring_options as m 2 | 3 | 4 | def test_docstring_options(): 5 | # options.disable_function_signatures() 6 | assert not m.test_function1.__doc__ 7 | 8 | assert m.test_function2.__doc__ == "A custom docstring" 9 | 10 | # docstring specified on just the first overload definition: 11 | assert m.test_overloaded1.__doc__ == "Overload docstring" 12 | 13 | # docstring on both overloads: 14 | assert m.test_overloaded2.__doc__ == "overload docstring 1\noverload docstring 2" 15 | 16 | # docstring on only second overload: 17 | assert m.test_overloaded3.__doc__ == "Overload docstr" 18 | 19 | # options.enable_function_signatures() 20 | assert m.test_function3.__doc__.startswith("test_function3(a: int, b: int) -> None") 21 | 22 | assert m.test_function4.__doc__.startswith("test_function4(a: int, b: int) -> None") 23 | assert m.test_function4.__doc__.endswith("A custom docstring\n") 24 | 25 | # options.disable_function_signatures() 26 | # options.disable_user_defined_docstrings() 27 | assert not m.test_function5.__doc__ 28 | 29 | # nested options.enable_user_defined_docstrings() 30 | assert m.test_function6.__doc__ == "A custom docstring" 31 | 32 | # RAII destructor 33 | assert m.test_function7.__doc__.startswith("test_function7(a: int, b: int) -> None") 34 | assert m.test_function7.__doc__.endswith("A custom docstring\n") 35 | 36 | # when all options are disabled, no docstring (instead of an empty one) should be generated 37 | assert m.test_function8.__doc__ is None 38 | 39 | # Suppression of user-defined docstrings for non-function objects 40 | assert not m.DocstringTestFoo.__doc__ 41 | assert not m.DocstringTestFoo.value_prop.__doc__ 42 | 43 | # Check existig behaviour of enum docstings 44 | assert ( 45 | m.DocstringTestEnum1.__doc__ 46 | == "Enum docstring\n\nMembers:\n\n Member1\n\n Member2" 47 | ) 48 | 49 | # options.enable_enum_members_docstring() 50 | assert ( 51 | m.DocstringTestEnum2.__doc__ 52 | == "Enum docstring\n\nMembers:\n\n Member1\n\n Member2" 53 | ) 54 | 55 | # options.disable_enum_members_docstring() 56 | assert m.DocstringTestEnum3.__doc__ == "Enum docstring" 57 | 58 | # options.disable_user_defined_docstrings() 59 | assert m.DocstringTestEnum4.__doc__ == "Members:\n\n Member1\n\n Member2" 60 | 61 | # options.disable_user_defined_docstrings() 62 | # options.disable_enum_members_docstring() 63 | # When all options are disabled, no docstring (instead of an empty one) should be generated 64 | assert m.DocstringTestEnum5.__doc__ is None 65 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_eigen_tensor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/eigen_tensor.cpp -- automatic conversion of Eigen Tensor 3 | 4 | All rights reserved. Use of this source code is governed by a 5 | BSD-style license that can be found in the LICENSE file. 6 | */ 7 | 8 | #define PYBIND11_TEST_EIGEN_TENSOR_NAMESPACE eigen_tensor 9 | 10 | #ifdef EIGEN_AVOID_STL_ARRAY 11 | # undef EIGEN_AVOID_STL_ARRAY 12 | #endif 13 | 14 | #include "test_eigen_tensor.inl" 15 | 16 | #include "pybind11_tests.h" 17 | 18 | test_initializer egien_tensor("eigen_tensor", eigen_tensor_test::test_module); 19 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_embed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID) 2 | 3 | if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy") 4 | message(STATUS "Skipping embed test on PyPy") 5 | add_custom_target(cpptest) # Dummy target on PyPy. Embedding is not supported. 6 | set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}") 7 | return() 8 | endif() 9 | 10 | find_package(Catch 2.13.9) 11 | 12 | if(CATCH_FOUND) 13 | message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}") 14 | else() 15 | message(STATUS "Catch not detected. Interpreter tests will be skipped. Install Catch headers" 16 | " manually or use `cmake -DDOWNLOAD_CATCH=ON` to fetch them automatically.") 17 | return() 18 | endif() 19 | 20 | find_package(Threads REQUIRED) 21 | 22 | add_executable(test_embed catch.cpp test_interpreter.cpp) 23 | pybind11_enable_warnings(test_embed) 24 | 25 | target_link_libraries(test_embed PRIVATE pybind11::embed Catch2::Catch2 Threads::Threads) 26 | 27 | if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) 28 | file(COPY test_interpreter.py test_trampoline.py DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") 29 | endif() 30 | 31 | add_custom_target( 32 | cpptest 33 | COMMAND "$" 34 | DEPENDS test_embed 35 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") 36 | 37 | pybind11_add_module(external_module THIN_LTO external_module.cpp) 38 | set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY 39 | "${CMAKE_CURRENT_BINARY_DIR}") 40 | foreach(config ${CMAKE_CONFIGURATION_TYPES}) 41 | string(TOUPPER ${config} config) 42 | set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} 43 | "${CMAKE_CURRENT_BINARY_DIR}") 44 | endforeach() 45 | add_dependencies(cpptest external_module) 46 | 47 | add_dependencies(check cpptest) 48 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_embed/catch.cpp: -------------------------------------------------------------------------------- 1 | // The Catch implementation is compiled here. This is a standalone 2 | // translation unit to avoid recompiling it for every test change. 3 | 4 | #include 5 | 6 | // Silence MSVC C++17 deprecation warning from Catch regarding std::uncaught_exceptions (up to 7 | // catch 2.0.1; this should be fixed in the next catch release after 2.0.1). 8 | PYBIND11_WARNING_DISABLE_MSVC(4996) 9 | 10 | // Catch uses _ internally, which breaks gettext style defines 11 | #ifdef _ 12 | # undef _ 13 | #endif 14 | 15 | #define CATCH_CONFIG_RUNNER 16 | #include 17 | 18 | namespace py = pybind11; 19 | 20 | int main(int argc, char *argv[]) { 21 | // Setup for TEST_CASE in test_interpreter.cpp, tagging on a large random number: 22 | std::string updated_pythonpath("pybind11_test_embed_PYTHONPATH_2099743835476552"); 23 | const char *preexisting_pythonpath = getenv("PYTHONPATH"); 24 | if (preexisting_pythonpath != nullptr) { 25 | #if defined(_WIN32) 26 | updated_pythonpath += ';'; 27 | #else 28 | updated_pythonpath += ':'; 29 | #endif 30 | updated_pythonpath += preexisting_pythonpath; 31 | } 32 | #if defined(_WIN32) 33 | _putenv_s("PYTHONPATH", updated_pythonpath.c_str()); 34 | #else 35 | setenv("PYTHONPATH", updated_pythonpath.c_str(), /*replace=*/1); 36 | #endif 37 | 38 | py::scoped_interpreter guard{}; 39 | 40 | auto result = Catch::Session().run(argc, argv); 41 | 42 | return result < 0xff ? result : 0xff; 43 | } 44 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_embed/external_module.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace py = pybind11; 4 | 5 | /* Simple test module/test class to check that the referenced internals data of external pybind11 6 | * modules aren't preserved over a finalize/initialize. 7 | */ 8 | 9 | PYBIND11_MODULE(external_module, m) { 10 | class A { 11 | public: 12 | explicit A(int value) : v{value} {}; 13 | int v; 14 | }; 15 | 16 | py::class_(m, "A").def(py::init()).def_readwrite("value", &A::v); 17 | 18 | m.def("internals_at", 19 | []() { return reinterpret_cast(&py::detail::get_internals()); }); 20 | } 21 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_embed/test_interpreter.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from widget_module import Widget 4 | 5 | 6 | class DerivedWidget(Widget): 7 | def __init__(self, message): 8 | super().__init__(message) 9 | 10 | def the_answer(self): 11 | return 42 12 | 13 | def argv0(self): 14 | return sys.argv[0] 15 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_embed/test_trampoline.py: -------------------------------------------------------------------------------- 1 | import trampoline_module 2 | 3 | 4 | def func(): 5 | class Test(trampoline_module.test_override_cache_helper): 6 | def func(self): 7 | return 42 8 | 9 | return Test() 10 | 11 | 12 | def func2(): 13 | class Test(trampoline_module.test_override_cache_helper): 14 | pass 15 | 16 | return Test() 17 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_eval.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import pytest 4 | 5 | import env # noqa: F401 6 | from pybind11_tests import eval_ as m 7 | 8 | 9 | def test_evals(capture): 10 | with capture: 11 | assert m.test_eval_statements() 12 | assert capture == "Hello World!" 13 | 14 | assert m.test_eval() 15 | assert m.test_eval_single_statement() 16 | 17 | assert m.test_eval_failure() 18 | 19 | 20 | @pytest.mark.xfail("env.PYPY", raises=RuntimeError) 21 | def test_eval_file(): 22 | filename = os.path.join(os.path.dirname(__file__), "test_eval_call.py") 23 | assert m.test_eval_file(filename) 24 | 25 | assert m.test_eval_file_failure() 26 | 27 | 28 | def test_eval_empty_globals(): 29 | assert "__builtins__" in m.eval_empty_globals(None) 30 | 31 | g = {} 32 | assert "__builtins__" in m.eval_empty_globals(g) 33 | assert "__builtins__" in g 34 | 35 | 36 | def test_eval_closure(): 37 | global_, local = m.test_eval_closure() 38 | 39 | assert global_["closure_value"] == 42 40 | assert local["closure_value"] == 0 41 | 42 | assert "local_value" not in global_ 43 | assert local["local_value"] == 0 44 | 45 | assert "func_global" not in global_ 46 | assert local["func_global"]() == 42 47 | 48 | assert "func_local" not in global_ 49 | with pytest.raises(NameError): 50 | local["func_local"]() 51 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_eval_call.py: -------------------------------------------------------------------------------- 1 | # This file is called from 'test_eval.py' 2 | 3 | if "call_test2" in locals(): 4 | call_test2(y) # noqa: F821 undefined name 5 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_exceptions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "pybind11_tests.h" 3 | 4 | #include 5 | 6 | // shared exceptions for cross_module_tests 7 | 8 | class PYBIND11_EXPORT_EXCEPTION shared_exception : public pybind11::builtin_exception { 9 | public: 10 | using builtin_exception::builtin_exception; 11 | explicit shared_exception() : shared_exception("") {} 12 | void set_error() const override { PyErr_SetString(PyExc_RuntimeError, what()); } 13 | }; 14 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_opaque_types.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_opaque_types.cpp -- opaque types, passing void pointers 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | #include "pybind11_tests.h" 13 | 14 | #include 15 | 16 | // IMPORTANT: Disable internal pybind11 translation mechanisms for STL data structures 17 | // 18 | // This also deliberately doesn't use the below StringList type alias to test 19 | // that MAKE_OPAQUE can handle a type containing a `,`. (The `std::allocator` 20 | // bit is just the default `std::vector` allocator). 21 | PYBIND11_MAKE_OPAQUE(std::vector>); 22 | 23 | using StringList = std::vector>; 24 | 25 | TEST_SUBMODULE(opaque_types, m) { 26 | // test_string_list 27 | py::class_(m, "StringList") 28 | .def(py::init<>()) 29 | .def("pop_back", &StringList::pop_back) 30 | /* There are multiple versions of push_back(), etc. Select the right ones. */ 31 | .def("push_back", (void(StringList::*)(const std::string &)) & StringList::push_back) 32 | .def("back", (std::string & (StringList::*) ()) & StringList::back) 33 | .def("__len__", [](const StringList &v) { return v.size(); }) 34 | .def( 35 | "__iter__", 36 | [](StringList &v) { return py::make_iterator(v.begin(), v.end()); }, 37 | py::keep_alive<0, 1>()); 38 | 39 | class ClassWithSTLVecProperty { 40 | public: 41 | StringList stringList; 42 | }; 43 | py::class_(m, "ClassWithSTLVecProperty") 44 | .def(py::init<>()) 45 | .def_readwrite("stringList", &ClassWithSTLVecProperty::stringList); 46 | 47 | m.def("print_opaque_list", [](const StringList &l) { 48 | std::string ret = "Opaque list: ["; 49 | bool first = true; 50 | for (const auto &entry : l) { 51 | if (!first) { 52 | ret += ", "; 53 | } 54 | ret += entry; 55 | first = false; 56 | } 57 | return ret + "]"; 58 | }); 59 | 60 | // test_pointers 61 | m.def("return_void_ptr", []() { return (void *) 0x1234; }); 62 | m.def("get_void_ptr_value", [](void *ptr) { return reinterpret_cast(ptr); }); 63 | m.def("return_null_str", []() { return (char *) nullptr; }); 64 | m.def("get_null_str_value", [](char *ptr) { return reinterpret_cast(ptr); }); 65 | 66 | m.def("return_unique_ptr", []() -> std::unique_ptr { 67 | auto *result = new StringList(); 68 | result->push_back("some value"); 69 | return std::unique_ptr(result); 70 | }); 71 | 72 | // test unions 73 | py::class_(m, "IntFloat") 74 | .def(py::init<>()) 75 | .def_readwrite("i", &IntFloat::i) 76 | .def_readwrite("f", &IntFloat::f); 77 | } 78 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_opaque_types.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pybind11_tests import ConstructorStats, UserType 4 | from pybind11_tests import opaque_types as m 5 | 6 | 7 | def test_string_list(): 8 | lst = m.StringList() 9 | lst.push_back("Element 1") 10 | lst.push_back("Element 2") 11 | assert m.print_opaque_list(lst) == "Opaque list: [Element 1, Element 2]" 12 | assert lst.back() == "Element 2" 13 | 14 | for i, k in enumerate(lst, start=1): 15 | assert k == f"Element {i}" 16 | lst.pop_back() 17 | assert m.print_opaque_list(lst) == "Opaque list: [Element 1]" 18 | 19 | cvp = m.ClassWithSTLVecProperty() 20 | assert m.print_opaque_list(cvp.stringList) == "Opaque list: []" 21 | 22 | cvp.stringList = lst 23 | cvp.stringList.push_back("Element 3") 24 | assert m.print_opaque_list(cvp.stringList) == "Opaque list: [Element 1, Element 3]" 25 | 26 | 27 | def test_pointers(msg): 28 | living_before = ConstructorStats.get(UserType).alive() 29 | assert m.get_void_ptr_value(m.return_void_ptr()) == 0x1234 30 | assert m.get_void_ptr_value(UserType()) # Should also work for other C++ types 31 | assert ConstructorStats.get(UserType).alive() == living_before 32 | 33 | with pytest.raises(TypeError) as excinfo: 34 | m.get_void_ptr_value([1, 2, 3]) # This should not work 35 | assert ( 36 | msg(excinfo.value) 37 | == """ 38 | get_void_ptr_value(): incompatible function arguments. The following argument types are supported: 39 | 1. (arg0: capsule) -> int 40 | 41 | Invoked with: [1, 2, 3] 42 | """ 43 | ) 44 | 45 | assert m.return_null_str() is None 46 | assert m.get_null_str_value(m.return_null_str()) is not None 47 | 48 | ptr = m.return_unique_ptr() 49 | assert "StringList" in repr(ptr) 50 | assert m.print_opaque_list(ptr) == "Opaque list: [some value]" 51 | 52 | 53 | def test_unions(): 54 | int_float_union = m.IntFloat() 55 | int_float_union.i = 42 56 | assert int_float_union.i == 42 57 | int_float_union.f = 3.0 58 | assert int_float_union.f == 3.0 59 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_pickling.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import re 3 | 4 | import pytest 5 | 6 | import env 7 | from pybind11_tests import pickling as m 8 | 9 | 10 | def test_pickle_simple_callable(): 11 | assert m.simple_callable() == 20220426 12 | if env.PYPY: 13 | serialized = pickle.dumps(m.simple_callable) 14 | deserialized = pickle.loads(serialized) 15 | assert deserialized() == 20220426 16 | else: 17 | # To document broken behavior: currently it fails universally with 18 | # all C Python versions. 19 | with pytest.raises(TypeError) as excinfo: 20 | pickle.dumps(m.simple_callable) 21 | assert re.search("can.*t pickle .*PyCapsule.* object", str(excinfo.value)) 22 | 23 | 24 | @pytest.mark.parametrize("cls_name", ["Pickleable", "PickleableNew"]) 25 | def test_roundtrip(cls_name): 26 | cls = getattr(m, cls_name) 27 | p = cls("test_value") 28 | p.setExtra1(15) 29 | p.setExtra2(48) 30 | 31 | data = pickle.dumps(p, 2) # Must use pickle protocol >= 2 32 | p2 = pickle.loads(data) 33 | assert p2.value() == p.value() 34 | assert p2.extra1() == p.extra1() 35 | assert p2.extra2() == p.extra2() 36 | 37 | 38 | @pytest.mark.xfail("env.PYPY") 39 | @pytest.mark.parametrize("cls_name", ["PickleableWithDict", "PickleableWithDictNew"]) 40 | def test_roundtrip_with_dict(cls_name): 41 | cls = getattr(m, cls_name) 42 | p = cls("test_value") 43 | p.extra = 15 44 | p.dynamic = "Attribute" 45 | 46 | data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL) 47 | p2 = pickle.loads(data) 48 | assert p2.value == p.value 49 | assert p2.extra == p.extra 50 | assert p2.dynamic == p.dynamic 51 | 52 | 53 | def test_enum_pickle(): 54 | from pybind11_tests import enums as e 55 | 56 | data = pickle.dumps(e.EOne, 2) 57 | assert e.EOne == pickle.loads(data) 58 | 59 | 60 | # 61 | # exercise_trampoline 62 | # 63 | class SimplePyDerived(m.SimpleBase): 64 | pass 65 | 66 | 67 | def test_roundtrip_simple_py_derived(): 68 | p = SimplePyDerived() 69 | p.num = 202 70 | p.stored_in_dict = 303 71 | data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL) 72 | p2 = pickle.loads(data) 73 | assert isinstance(p2, SimplePyDerived) 74 | assert p2.num == 202 75 | assert p2.stored_in_dict == 303 76 | 77 | 78 | def test_roundtrip_simple_cpp_derived(): 79 | p = m.make_SimpleCppDerivedAsBase() 80 | assert m.check_dynamic_cast_SimpleCppDerived(p) 81 | p.num = 404 82 | if not env.PYPY: 83 | # To ensure that this unit test is not accidentally invalidated. 84 | with pytest.raises(AttributeError): 85 | # Mimics the `setstate` C++ implementation. 86 | setattr(p, "__dict__", {}) # noqa: B010 87 | data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL) 88 | p2 = pickle.loads(data) 89 | assert isinstance(p2, m.SimpleBase) 90 | assert p2.num == 404 91 | # Issue #3062: pickleable base C++ classes can incur object slicing 92 | # if derived typeid is not registered with pybind11 93 | assert not m.check_dynamic_cast_SimpleCppDerived(p2) 94 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_tagbased_polymorphic.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import tagbased_polymorphic as m 2 | 3 | 4 | def test_downcast(): 5 | zoo = m.create_zoo() 6 | assert [type(animal) for animal in zoo] == [ 7 | m.Labrador, 8 | m.Dog, 9 | m.Chihuahua, 10 | m.Cat, 11 | m.Panther, 12 | ] 13 | assert [animal.name for animal in zoo] == [ 14 | "Fido", 15 | "Ginger", 16 | "Hertzl", 17 | "Tiger", 18 | "Leo", 19 | ] 20 | zoo[1].sound = "woooooo" 21 | assert [dog.bark() for dog in zoo[:3]] == [ 22 | "Labrador Fido goes WOOF!", 23 | "Dog Ginger goes woooooo", 24 | "Chihuahua Hertzl goes iyiyiyiyiyi and runs in circles", 25 | ] 26 | assert [cat.purr() for cat in zoo[3:]] == ["mrowr", "mrrrRRRRRR"] 27 | zoo[0].excitement -= 1000 28 | assert zoo[0].excitement == 14000 29 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_thread.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_thread.cpp -- call pybind11 bound methods in threads 3 | 4 | Copyright (c) 2021 Laramie Leavitt (Google LLC) 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #include "pybind11_tests.h" 14 | 15 | #include 16 | #include 17 | 18 | namespace py = pybind11; 19 | 20 | namespace { 21 | 22 | struct IntStruct { 23 | explicit IntStruct(int v) : value(v){}; 24 | ~IntStruct() { value = -value; } 25 | IntStruct(const IntStruct &) = default; 26 | IntStruct &operator=(const IntStruct &) = default; 27 | 28 | int value; 29 | }; 30 | 31 | } // namespace 32 | 33 | TEST_SUBMODULE(thread, m) { 34 | 35 | py::class_(m, "IntStruct").def(py::init([](const int i) { return IntStruct(i); })); 36 | 37 | // implicitly_convertible uses loader_life_support when an implicit 38 | // conversion is required in order to lifetime extend the reference. 39 | // 40 | // This test should be run with ASAN for better effectiveness. 41 | py::implicitly_convertible(); 42 | 43 | m.def("test", [](int expected, const IntStruct &in) { 44 | { 45 | py::gil_scoped_release release; 46 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); 47 | } 48 | 49 | if (in.value != expected) { 50 | throw std::runtime_error("Value changed!!"); 51 | } 52 | }); 53 | 54 | m.def( 55 | "test_no_gil", 56 | [](int expected, const IntStruct &in) { 57 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); 58 | if (in.value != expected) { 59 | throw std::runtime_error("Value changed!!"); 60 | } 61 | }, 62 | py::call_guard()); 63 | 64 | // NOTE: std::string_view also uses loader_life_support to ensure that 65 | // the string contents remain alive, but that's a C++ 17 feature. 66 | } 67 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_thread.py: -------------------------------------------------------------------------------- 1 | import threading 2 | 3 | from pybind11_tests import thread as m 4 | 5 | 6 | class Thread(threading.Thread): 7 | def __init__(self, fn): 8 | super().__init__() 9 | self.fn = fn 10 | self.e = None 11 | 12 | def run(self): 13 | try: 14 | for i in range(10): 15 | self.fn(i, i) 16 | except Exception as e: 17 | self.e = e 18 | 19 | def join(self): 20 | super().join() 21 | if self.e: 22 | raise self.e 23 | 24 | 25 | def test_implicit_conversion(): 26 | a = Thread(m.test) 27 | b = Thread(m.test) 28 | c = Thread(m.test) 29 | for x in [a, b, c]: 30 | x.start() 31 | for x in [c, b, a]: 32 | x.join() 33 | 34 | 35 | def test_implicit_conversion_no_gil(): 36 | a = Thread(m.test_no_gil) 37 | b = Thread(m.test_no_gil) 38 | c = Thread(m.test_no_gil) 39 | for x in [a, b, c]: 40 | x.start() 41 | for x in [c, b, a]: 42 | x.join() 43 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_union.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_class.cpp -- test py::class_ definitions and basic functionality 3 | 4 | Copyright (c) 2019 Roland Dreier 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include "pybind11_tests.h" 11 | 12 | TEST_SUBMODULE(union_, m) { 13 | union TestUnion { 14 | int value_int; 15 | unsigned value_uint; 16 | }; 17 | 18 | py::class_(m, "TestUnion") 19 | .def(py::init<>()) 20 | .def_readonly("as_int", &TestUnion::value_int) 21 | .def_readwrite("as_uint", &TestUnion::value_uint); 22 | } 23 | -------------------------------------------------------------------------------- /lib/pybind11/tests/test_union.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import union_ as m 2 | 3 | 4 | def test_union(): 5 | instance = m.TestUnion() 6 | 7 | instance.as_uint = 10 8 | assert instance.as_int == 10 9 | -------------------------------------------------------------------------------- /lib/pybind11/tools/FindCatch.cmake: -------------------------------------------------------------------------------- 1 | # - Find the Catch test framework or download it (single header) 2 | # 3 | # This is a quick module for internal use. It assumes that Catch is 4 | # REQUIRED and that a minimum version is provided (not EXACT). If 5 | # a suitable version isn't found locally, the single header file 6 | # will be downloaded and placed in the build dir: PROJECT_BINARY_DIR. 7 | # 8 | # This code sets the following variables: 9 | # CATCH_INCLUDE_DIR - path to catch.hpp 10 | # CATCH_VERSION - version number 11 | 12 | option(DOWNLOAD_CATCH "Download catch2 if not found") 13 | 14 | if(NOT Catch_FIND_VERSION) 15 | message(FATAL_ERROR "A version number must be specified.") 16 | elseif(Catch_FIND_REQUIRED) 17 | message(FATAL_ERROR "This module assumes Catch is not required.") 18 | elseif(Catch_FIND_VERSION_EXACT) 19 | message(FATAL_ERROR "Exact version numbers are not supported, only minimum.") 20 | endif() 21 | 22 | # Extract the version number from catch.hpp 23 | function(_get_catch_version) 24 | file( 25 | STRINGS "${CATCH_INCLUDE_DIR}/catch.hpp" version_line 26 | REGEX "Catch v.*" 27 | LIMIT_COUNT 1) 28 | if(version_line MATCHES "Catch v([0-9]+)\\.([0-9]+)\\.([0-9]+)") 29 | set(CATCH_VERSION 30 | "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}" 31 | PARENT_SCOPE) 32 | endif() 33 | endfunction() 34 | 35 | # Download the single-header version of Catch 36 | function(_download_catch version destination_dir) 37 | message(STATUS "Downloading catch v${version}...") 38 | set(url https://github.com/philsquared/Catch/releases/download/v${version}/catch.hpp) 39 | file( 40 | DOWNLOAD ${url} "${destination_dir}/catch.hpp" 41 | STATUS status 42 | LOG log) 43 | list(GET status 0 error) 44 | if(error) 45 | string(REPLACE "\n" "\n " log " ${log}") 46 | message(FATAL_ERROR "Could not download URL:\n" " ${url}\n" "Log:\n" "${log}") 47 | endif() 48 | set(CATCH_INCLUDE_DIR 49 | "${destination_dir}" 50 | CACHE INTERNAL "") 51 | endfunction() 52 | 53 | # Look for catch locally 54 | find_path( 55 | CATCH_INCLUDE_DIR 56 | NAMES catch.hpp 57 | PATH_SUFFIXES catch2) 58 | if(CATCH_INCLUDE_DIR) 59 | _get_catch_version() 60 | endif() 61 | 62 | # Download the header if it wasn't found or if it's outdated 63 | if(NOT CATCH_VERSION OR CATCH_VERSION VERSION_LESS ${Catch_FIND_VERSION}) 64 | if(DOWNLOAD_CATCH) 65 | _download_catch(${Catch_FIND_VERSION} "${PROJECT_BINARY_DIR}/catch/") 66 | _get_catch_version() 67 | else() 68 | set(CATCH_FOUND FALSE) 69 | return() 70 | endif() 71 | endif() 72 | 73 | add_library(Catch2::Catch2 IMPORTED INTERFACE) 74 | set_property(TARGET Catch2::Catch2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CATCH_INCLUDE_DIR}") 75 | 76 | set(CATCH_FOUND TRUE) 77 | -------------------------------------------------------------------------------- /lib/pybind11/tools/JoinPaths.cmake: -------------------------------------------------------------------------------- 1 | # This module provides function for joining paths 2 | # known from most languages 3 | # 4 | # SPDX-License-Identifier: (MIT OR CC0-1.0) 5 | # Copyright 2020 Jan Tojnar 6 | # https://github.com/jtojnar/cmake-snips 7 | # 8 | # Modelled after Python’s os.path.join 9 | # https://docs.python.org/3.7/library/os.path.html#os.path.join 10 | # Windows not supported 11 | function(join_paths joined_path first_path_segment) 12 | set(temp_path "${first_path_segment}") 13 | foreach(current_segment IN LISTS ARGN) 14 | if(NOT ("${current_segment}" STREQUAL "")) 15 | if(IS_ABSOLUTE "${current_segment}") 16 | set(temp_path "${current_segment}") 17 | else() 18 | set(temp_path "${temp_path}/${current_segment}") 19 | endif() 20 | endif() 21 | endforeach() 22 | set(${joined_path} "${temp_path}" PARENT_SCOPE) 23 | endfunction() 24 | -------------------------------------------------------------------------------- /lib/pybind11/tools/check-style.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Script to check include/test code for common pybind11 code style errors. 4 | # 5 | # This script currently checks for 6 | # 7 | # 1. missing space between keyword and parenthesis, e.g.: for(, if(, while( 8 | # 2. Missing space between right parenthesis and brace, e.g. 'for (...){' 9 | # 3. opening brace on its own line. It should always be on the same line as the 10 | # if/while/for/do statement. 11 | # 12 | # Invoke as: tools/check-style.sh 13 | # 14 | 15 | check_style_errors=0 16 | IFS=$'\n' 17 | 18 | 19 | found="$(grep '\<\(if\|for\|while\|catch\)(\|){' "$@" -rn --color=always)" 20 | if [ -n "$found" ]; then 21 | echo -e '\033[31;01mError: found the following coding style problems:\033[0m' 22 | check_style_errors=1 23 | echo "${found//^/ /}" 24 | fi 25 | 26 | found="$(awk ' 27 | function prefix(filename, lineno) { 28 | return " \033[35m" filename "\033[36m:\033[32m" lineno "\033[36m:\033[0m" 29 | } 30 | function mark(pattern, string) { sub(pattern, "\033[01;31m&\033[0m", string); return string } 31 | last && /^\s*{/ { 32 | print prefix(FILENAME, FNR-1) mark("\\)\\s*$", last) 33 | print prefix(FILENAME, FNR) mark("^\\s*{", $0) 34 | last="" 35 | } 36 | { last = /(if|for|while|catch|switch)\s*\(.*\)\s*$/ ? $0 : "" } 37 | ' "$(find include -type f)" "$@")" 38 | if [ -n "$found" ]; then 39 | check_style_errors=1 40 | echo -e '\033[31;01mError: braces should occur on the same line as the if/while/.. statement. Found issues in the following files:\033[0m' 41 | echo "$found" 42 | fi 43 | 44 | exit $check_style_errors 45 | -------------------------------------------------------------------------------- /lib/pybind11/tools/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | # Source: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake 2 | 3 | if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") 4 | message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") 5 | endif() 6 | 7 | file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) 8 | string(REGEX REPLACE "\n" ";" files "${files}") 9 | foreach(file ${files}) 10 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 11 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 12 | exec_program( 13 | "@CMAKE_COMMAND@" ARGS 14 | "-E remove \"$ENV{DESTDIR}${file}\"" 15 | OUTPUT_VARIABLE rm_out 16 | RETURN_VALUE rm_retval) 17 | if(NOT "${rm_retval}" STREQUAL 0) 18 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 19 | endif() 20 | else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 21 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 22 | endif() 23 | endforeach() 24 | -------------------------------------------------------------------------------- /lib/pybind11/tools/codespell_ignore_lines_from_errors.py: -------------------------------------------------------------------------------- 1 | """Simple script for rebuilding .codespell-ignore-lines 2 | 3 | Usage: 4 | 5 | cat < /dev/null > .codespell-ignore-lines 6 | pre-commit run --all-files codespell >& /tmp/codespell_errors.txt 7 | python3 tools/codespell_ignore_lines_from_errors.py /tmp/codespell_errors.txt > .codespell-ignore-lines 8 | 9 | git diff to review changes, then commit, push. 10 | """ 11 | 12 | import sys 13 | from typing import List 14 | 15 | 16 | def run(args: List[str]) -> None: 17 | assert len(args) == 1, "codespell_errors.txt" 18 | cache = {} 19 | done = set() 20 | for line in sorted(open(args[0]).read().splitlines()): 21 | i = line.find(" ==> ") 22 | if i > 0: 23 | flds = line[:i].split(":") 24 | if len(flds) >= 2: 25 | filename, line_num = flds[:2] 26 | if filename not in cache: 27 | cache[filename] = open(filename).read().splitlines() 28 | supp = cache[filename][int(line_num) - 1] 29 | if supp not in done: 30 | print(supp) 31 | done.add(supp) 32 | 33 | 34 | if __name__ == "__main__": 35 | run(args=sys.argv[1:]) 36 | -------------------------------------------------------------------------------- /lib/pybind11/tools/libsize.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | # Internal build script for generating debugging test .so size. 5 | # Usage: 6 | # python libsize.py file.so save.txt -- displays the size of file.so and, if save.txt exists, compares it to the 7 | # size in it, then overwrites save.txt with the new size for future runs. 8 | 9 | if len(sys.argv) != 3: 10 | sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt") 11 | 12 | lib = sys.argv[1] 13 | save = sys.argv[2] 14 | 15 | if not os.path.exists(lib): 16 | sys.exit(f"Error: requested file ({lib}) does not exist") 17 | 18 | libsize = os.path.getsize(lib) 19 | 20 | print("------", os.path.basename(lib), "file size:", libsize, end="") 21 | 22 | if os.path.exists(save): 23 | with open(save) as sf: 24 | oldsize = int(sf.readline()) 25 | 26 | if oldsize > 0: 27 | change = libsize - oldsize 28 | if change == 0: 29 | print(" (no change)") 30 | else: 31 | print(f" (change of {change:+} bytes = {change / oldsize:+.2%})") 32 | else: 33 | print() 34 | 35 | with open(save, "w") as sf: 36 | sf.write(str(libsize)) 37 | -------------------------------------------------------------------------------- /lib/pybind11/tools/make_changelog.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | 5 | import ghapi.all 6 | from rich import print 7 | from rich.syntax import Syntax 8 | 9 | ENTRY = re.compile( 10 | r""" 11 | Suggested \s changelog \s entry: 12 | .* 13 | ```rst 14 | \s* 15 | (.*?) 16 | \s* 17 | ``` 18 | """, 19 | re.DOTALL | re.VERBOSE, 20 | ) 21 | 22 | print() 23 | 24 | 25 | api = ghapi.all.GhApi(owner="pybind", repo="pybind11") 26 | 27 | issues_pages = ghapi.page.paged( 28 | api.issues.list_for_repo, labels="needs changelog", state="closed" 29 | ) 30 | issues = (issue for page in issues_pages for issue in page) 31 | missing = [] 32 | 33 | for issue in issues: 34 | changelog = ENTRY.findall(issue.body or "") 35 | if not changelog or not changelog[0]: 36 | missing.append(issue) 37 | else: 38 | (msg,) = changelog 39 | if not msg.startswith("* "): 40 | msg = "* " + msg 41 | if not msg.endswith("."): 42 | msg += "." 43 | 44 | msg += f"\n `#{issue.number} <{issue.html_url}>`_" 45 | 46 | print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True)) 47 | print() 48 | 49 | if missing: 50 | print() 51 | print("[blue]" + "-" * 30) 52 | print() 53 | 54 | for issue in missing: 55 | print(f"[red bold]Missing:[/red bold][red] {issue.title}") 56 | print(f"[red] {issue.html_url}\n") 57 | 58 | print("[bold]Template:\n") 59 | msg = "## Suggested changelog entry:\n\n```rst\n\n```" 60 | print(Syntax(msg, "md", theme="ansi_light")) 61 | 62 | print() 63 | -------------------------------------------------------------------------------- /lib/pybind11/tools/pybind11.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix_for_pc_file@ 2 | includedir=@includedir_for_pc_file@ 3 | 4 | Name: @PROJECT_NAME@ 5 | Description: Seamless operability between C++11 and Python 6 | Version: @PROJECT_VERSION@ 7 | Cflags: -I${includedir} 8 | -------------------------------------------------------------------------------- /lib/pybind11/tools/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=42", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | -------------------------------------------------------------------------------- /lib/pybind11/tools/setup_global.py.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Setup script for pybind11-global (in the sdist or in tools/setup_global.py in the repository) 4 | # This package is targeted for easy use from CMake. 5 | 6 | import glob 7 | import os 8 | import re 9 | 10 | # Setuptools has to be before distutils 11 | from setuptools import setup 12 | 13 | from distutils.command.install_headers import install_headers 14 | 15 | class InstallHeadersNested(install_headers): 16 | def run(self): 17 | headers = self.distribution.headers or [] 18 | for header in headers: 19 | # Remove pybind11/include/ 20 | short_header = header.split("/", 2)[-1] 21 | 22 | dst = os.path.join(self.install_dir, os.path.dirname(short_header)) 23 | self.mkpath(dst) 24 | (out, _) = self.copy_file(header, dst) 25 | self.outfiles.append(out) 26 | 27 | 28 | main_headers = glob.glob("pybind11/include/pybind11/*.h") 29 | detail_headers = glob.glob("pybind11/include/pybind11/detail/*.h") 30 | eigen_headers = glob.glob("pybind11/include/pybind11/eigen/*.h") 31 | stl_headers = glob.glob("pybind11/include/pybind11/stl/*.h") 32 | cmake_files = glob.glob("pybind11/share/cmake/pybind11/*.cmake") 33 | pkgconfig_files = glob.glob("pybind11/share/pkgconfig/*.pc") 34 | headers = main_headers + detail_headers + stl_headers + eigen_headers 35 | 36 | cmdclass = {"install_headers": InstallHeadersNested} 37 | $extra_cmd 38 | 39 | # This will _not_ affect installing from wheels, 40 | # only building wheels or installing from SDist. 41 | # Primarily intended on Windows, where this is sometimes 42 | # customized (for example, conda-forge uses Library/) 43 | base = os.environ.get("PYBIND11_GLOBAL_PREFIX", "") 44 | 45 | # Must have a separator 46 | if base and not base.endswith("/"): 47 | base += "/" 48 | 49 | setup( 50 | name="pybind11_global", 51 | version="$version", 52 | packages=[], 53 | headers=headers, 54 | data_files=[ 55 | (base + "share/cmake/pybind11", cmake_files), 56 | (base + "share/pkgconfig", pkgconfig_files), 57 | (base + "include/pybind11", main_headers), 58 | (base + "include/pybind11/detail", detail_headers), 59 | (base + "include/pybind11/eigen", eigen_headers), 60 | (base + "include/pybind11/stl", stl_headers), 61 | ], 62 | cmdclass=cmdclass, 63 | ) 64 | -------------------------------------------------------------------------------- /lib/pybind11/tools/setup_main.py.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Setup script (in the sdist or in tools/setup_main.py in the repository) 4 | 5 | from setuptools import setup 6 | 7 | cmdclass = {} 8 | $extra_cmd 9 | 10 | setup( 11 | name="pybind11", 12 | version="$version", 13 | download_url='https://github.com/pybind/pybind11/tarball/v$version', 14 | packages=[ 15 | "pybind11", 16 | "pybind11.include.pybind11", 17 | "pybind11.include.pybind11.detail", 18 | "pybind11.include.pybind11.eigen", 19 | "pybind11.include.pybind11.stl", 20 | "pybind11.share.cmake.pybind11", 21 | "pybind11.share.pkgconfig", 22 | ], 23 | package_data={ 24 | "pybind11": ["py.typed"], 25 | "pybind11.include.pybind11": ["*.h"], 26 | "pybind11.include.pybind11.detail": ["*.h"], 27 | "pybind11.include.pybind11.eigen": ["*.h"], 28 | "pybind11.include.pybind11.stl": ["*.h"], 29 | "pybind11.share.cmake.pybind11": ["*.cmake"], 30 | "pybind11.share.pkgconfig": ["*.pc"], 31 | }, 32 | extras_require={ 33 | "global": ["pybind11_global==$version"] 34 | }, 35 | entry_points={ 36 | "console_scripts": [ 37 | "pybind11-config = pybind11.__main__:main", 38 | ], 39 | "pipx.run": [ 40 | "pybind11 = pybind11.__main__:main", 41 | ] 42 | }, 43 | cmdclass=cmdclass 44 | ) 45 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | # Inside of setup.cfg 2 | [metadata] 3 | description-file = README.md 4 | -------------------------------------------------------------------------------- /src/pydegensac/__init__.py: -------------------------------------------------------------------------------- 1 | from .pydegensac import * 2 | from .utils import (findHomography, 3 | findFundamentalMatrix, 4 | convert_cv2_kpts_to_xyA) 5 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/DegUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEG_UTILS_H_ 2 | #define __DEG_UTILS_H_ 3 | /*function [deg, H, inl] = checksample(F, u7, th) 4 | %checksample tests for the degeneracy of 7pt sample 5 | % [deg, H, inl] = checksample(F, u7, th) 6 | % F is the fundamental matrix 7 | % u7 6-by-7 matrix of 2 view correspondences, th - threshold 8 | % when the seven corrs contain at least five point correspondences (inl) 9 | % linked by homography (H) then deg is set to sum(inl)*/ 10 | 11 | int checksample(double * F, double * u7, double th, double * H); 12 | 13 | /*function H = Hdetect (F, u3) 14 | 15 | % Hdetect calcucates homography from fund. matrix F and 3 point corrs. 16 | % H = Hdetect (F, u3) 17 | % F : 3-by-3 rank 2 fundamental matrix 18 | % u3 : 6-by-3 correspondences of image pts in homog. coordinates 19 | % see Hartley & Zisserman: Scene planes and homographies (p.318)*/ 20 | 21 | void Hdetect(double * F, double * u7, unsigned char * IDXS, double * H); 22 | 23 | void dHDs(double * H, double * u, unsigned len, double * Ds, int * bufferP, double * bufferZ); 24 | 25 | void sortDs(double * Ds, double * sDs, unsigned char * idx); 26 | 27 | void skew_sym(double * a, double * ax); 28 | 29 | void fillu3(double * u7, unsigned char * IDXS, double * u3a, double * u3b); 30 | 31 | void crossp(double *h,double *u,double *v); 32 | 33 | /*function [F, inls] = rFtH(u, hinl, th, H)*/ 34 | unsigned rFtH(double * u, unsigned char * hinl, double th, double * H, unsigned len, 35 | double * F, int * bufferP, double * bufferZ); 36 | 37 | unsigned dmin(unsigned a, unsigned b); 38 | 39 | /*%calculates number of samples needed to be done 40 | function SampleCnt = nsamples(ni, ptNum, pf, conf)*/ 41 | 42 | /*unsigned nsamples(unsigned ni, unsigned np, unsigned ss, double conf);*/ 43 | 44 | /*function [F,inl, tinl] = innerFH (uH, uO, u, th, num, sam_sizH, sam_sizO)*/ 45 | void innerFH(double * uH, unsigned lenH, double * uO, unsigned lenO, 46 | double * u, unsigned len, double th, unsigned repCount, unsigned sam_sizH, unsigned sam_sizO, 47 | double * F, unsigned char * inl); 48 | 49 | /*Draw combined sample from two arrays of TCs*/ 50 | void dual_sample(double * uA, unsigned lenA, unsigned sA, double * uB, unsigned lenB, unsigned sB, double * usam); 51 | 52 | /*Iterative LSQs 53 | function [F,inl] = u2Fit(u, F, th, ths)*/ 54 | unsigned u2Fit(double * u, unsigned len, double * F, unsigned char * inl, double th, double ths, unsigned iters); 55 | 56 | /*Copied from mex file*/ 57 | unsigned innerH(double * H, double * u, unsigned len, double th, unsigned iters, unsigned char * inl, int * pool, double * buffer); 58 | 59 | /*Transforms inliers from list to bit-array*/ 60 | void transformInliers(int * inl, int * inl2, unsigned inlCount, unsigned len); 61 | 62 | #endif //__DEG_UTILS__ 63 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/Fcustomdef.h: -------------------------------------------------------------------------------- 1 | #ifndef FCUSTOMDEF_H 2 | #define FCUSTOMDEF_H 3 | typedef void (*FDsPtr) (const double*, const double *,double *, int); 4 | typedef void (*exFDsPtr) (const double*, const double *,double *, double *, int); 5 | typedef void (*FDsidxPtr)(const double *, const double *, double *, int, int *, int); 6 | 7 | 8 | 9 | #endif // FCUSTOMDEF_H 10 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/Ftools.h: -------------------------------------------------------------------------------- 1 | #ifndef __FTOOLS_H__ 2 | #define __FTOOLS_H__ 3 | 4 | #define u1 (*(u)) 5 | #define u2 (*(u+1)) 6 | #define u3 (*(u+2)) 7 | #define u4 (*(u+3)) 8 | #define u5 (*(u+4)) 9 | #define u6 (*(u+5)) 10 | 11 | #define a11 (*A) 12 | #define a12 (*(A+1)) 13 | #define a13 (*(A+2)) 14 | #define a21 (*(A+3)) 15 | #define a22 (*(A+4)) 16 | #define a23 (*(A+5)) 17 | #define a31 (*(A+6)) 18 | #define a32 (*(A+7)) 19 | #define a33 (*(A+8)) 20 | 21 | #define b11 (*B) 22 | #define b12 (*(B+1)) 23 | #define b13 (*(B+2)) 24 | #define b21 (*(B+3)) 25 | #define b22 (*(B+4)) 26 | #define b23 (*(B+5)) 27 | #define b31 (*(B+6)) 28 | #define b32 (*(B+7)) 29 | #define b33 (*(B+8)) 30 | 31 | #define rr_a (*po) 32 | #define rr_d (*(po + 3)) 33 | 34 | #include "Fcustomdef.h" 35 | void lin_fm(const double *u, double *p, const int* inl, const int len); 36 | 37 | void slcm(double *A, double *B, double *p); 38 | 39 | #ifdef __cplusplus 40 | extern "C" 41 | #endif 42 | void FDs (const double *u, const double *F, double *p, int len); 43 | 44 | 45 | #ifdef __cplusplus 46 | extern "C" 47 | #endif 48 | void FDsSym (const double *u, const double *F, double *p, int len); 49 | 50 | #ifdef __cplusplus 51 | extern "C" 52 | #endif 53 | void FDsidx (const double *mu, const double *F, double *p, int len, int *idx, int siz); 54 | 55 | 56 | #ifdef __cplusplus 57 | extern "C" 58 | #endif 59 | void FDsSymidx (const double *mu, const double *F, double *p, int len, int *idx, int siz); 60 | 61 | 62 | 63 | #ifdef __cplusplus 64 | extern "C" 65 | #endif 66 | void FDsfull (const double *u, const double *F, double *p, int len); 67 | 68 | 69 | #ifdef __cplusplus 70 | extern "C" 71 | #endif 72 | void exFDs (const double *u, const double *F, double *p, double *w, int len); 73 | 74 | 75 | #ifdef __cplusplus 76 | extern "C" 77 | #endif 78 | void exFDsSym (const double *u, const double *F, double *p, double *w, int len); 79 | 80 | int rroots3 (double *po, double *r); 81 | 82 | void lin_fmN(const double *u, double *p, const int *inl, int len, 83 | double *A1, double *A2); 84 | 85 | void singulF(double *F); 86 | 87 | void u2f(const double *u, const int *inl, int len, 88 | double *F, double *buffer); 89 | 90 | void u2fw(const double *u, const int *inl, const double * w, 91 | int len, double *F, double *buffer); 92 | 93 | void epipole(double *ec, const double *F); 94 | 95 | int all_ori_valid(double *F, double *us, int *idx, int N); 96 | 97 | int exFDso (const double *u, const double *F, double *p, double *w, int len, 98 | double th, int * inl_buff, int **inls); 99 | 100 | void FDso (const double *u, const double *F, double *p, double *sgn, int len); 101 | 102 | int nullspace_qr7x9(const double *A, double *N); 103 | 104 | #endif /* __FTOOLS_H__ */ 105 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/Makefile: -------------------------------------------------------------------------------- 1 | include ../../config 2 | 3 | INCLUDES += -I$(LIBS_ROOT_DIR)/include_ext -I../utls -I../matutls -I../lapack 4 | 5 | ransac_CFILES = Ftools.c Htools.c ranF.c ranH.c rtools.c utools.c experF.c proF.c waldtools.c 6 | 7 | LIBS = ransac 8 | 9 | $(do_libs) 10 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/exp_ranH.h: -------------------------------------------------------------------------------- 1 | #ifndef _EXP_RANSAC_RAN_H 2 | #define _EXP_RANSAC_RAN_H 3 | 4 | #include "exp_ranF.h" 5 | #include "Htools.h" 6 | 7 | #define D3_H_RATIO 1 8 | #define D3_H_MIN 0 9 | /*empirically 7*mss...*/ 10 | #define D3_H_MAX 28 11 | 12 | int HcloseToSingular(const double *h); 13 | 14 | 15 | Score exp_iterH(double *u, int len, int *inliers, double th, double ths, 16 | int steps, double *H, double *Z, double **errs, double *buffer, 17 | int iterID, unsigned inlLimit, double *resids); 18 | 19 | Score exp_inHrani (double *u, int len, int *inliers, int ninl, 20 | double th, double *Z, double **errs, 21 | double *buffer, double *H, int rep, 22 | int * iterID, unsigned inlLimit, double *resids); 23 | 24 | #ifdef __cplusplus 25 | extern "C" 26 | #endif 27 | Score exp_ransacHcustomLAF (double *u, double *u_1, double *u_2, int len, double th, 28 | double laf_coef, 29 | double conf, int max_sam, 30 | double *H, unsigned char * inl, 31 | int iter_type, int * data_out, 32 | int oriented_constraint, unsigned inlLimit, double **resids, 33 | HDsPtr HDS1, HDsiPtr HDSi1, HDsidxPtr HDSidx1, double SymCheck_th); 34 | /* Model-Change Error of homography (squared), 35 | deefined as mean square error of sample points when added the point as hard constraint */ 36 | void hMCEs(double *Z, double *u, double *d, int *samidx, int len, double * errs, double thr); 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/hash.c: -------------------------------------------------------------------------------- 1 | #include "hash.h" 2 | //#include 3 | 4 | uint32_t SuperFastHash (const char * data, int len) { 5 | uint32_t hash = len, tmp; 6 | int rem; 7 | 8 | if (len <= 0 || data == 0) return 0; 9 | 10 | rem = len & 3; 11 | len >>= 2; 12 | 13 | /* Main loop */ 14 | for (;len > 0; len--) { 15 | hash += get16bits (data); 16 | tmp = (get16bits (data+2) << 11) ^ hash; 17 | hash = (hash << 16) ^ tmp; 18 | data += 2*sizeof (uint16_t); 19 | hash += hash >> 11; 20 | } 21 | 22 | /* Handle end cases */ 23 | switch (rem) { 24 | case 3: hash += get16bits (data); 25 | hash ^= hash << 16; 26 | hash ^= ((signed char)data[sizeof (uint16_t)]) << 18; 27 | hash += hash >> 11; 28 | break; 29 | case 2: hash += get16bits (data); 30 | hash ^= hash << 11; 31 | hash += hash >> 17; 32 | break; 33 | case 1: hash += (signed char)*data; 34 | hash ^= hash << 10; 35 | hash += hash >> 1; 36 | } 37 | 38 | /* Force "avalanching" of final 127 bits */ 39 | hash ^= hash << 3; 40 | hash += hash >> 5; 41 | hash ^= hash << 4; 42 | hash += hash >> 17; 43 | hash ^= hash << 25; 44 | hash += hash >> 6; 45 | 46 | return hash; 47 | } 48 | 49 | void htInit(HashTable * ht) { 50 | unsigned i; 51 | for (i = 0; i < HT_FIELDS; ++i) { 52 | ht->fields[i] = 0; 53 | } 54 | } 55 | 56 | void htClear(HashTable * ht) { 57 | unsigned i; 58 | HashField * hf; 59 | for (i = 0; i < HT_FIELDS; ++i) { 60 | while (ht->fields[i]) { 61 | hf = ht->fields[i]; 62 | ht->fields[i] = ht->fields[i]->next; 63 | free(hf); 64 | } 65 | } 66 | } 67 | 68 | void htInsert(HashTable * ht, uint32_t hash, int length, int iterID) { 69 | HashField * hf = (HashField *)malloc(sizeof(HashField)); 70 | hf->next = ht->fields[hash % HT_FIELDS]; 71 | hf->hash = hash; 72 | hf->length = length; 73 | hf->iterID = iterID; 74 | ht->fields[hash % HT_FIELDS] = hf; 75 | } 76 | 77 | int htContains(HashTable * ht, uint32_t hash, int length, int iterID) { /* compare thrs to be sure, but slower */ 78 | HashField * hf = ht->fields[hash % HT_FIELDS]; 79 | while (hf) { // the same iterID 80 | if (hf->hash == hash && hf->length == length && hf->iterID == iterID) { 81 | return iterID; 82 | } else { 83 | hf = hf->next; 84 | } 85 | } 86 | 87 | hf = ht->fields[hash % HT_FIELDS]; 88 | while (hf) { // other iterID 89 | if (hf->hash == hash && hf->length == length) { 90 | return hf->iterID; 91 | } else { 92 | hf = hf->next; 93 | } 94 | } 95 | return -1; 96 | } 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/hash.h: -------------------------------------------------------------------------------- 1 | #include /* Replace with 3 | 4 | #undef get16bits 5 | #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ 6 | || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) 7 | #define get16bits(d) (*((const uint16_t *) (d))) 8 | #endif 9 | 10 | #if !defined (get16bits) 11 | #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\ 12 | +(uint32_t)(((const uint8_t *)(d))[0]) ) 13 | #endif 14 | 15 | #define HT_FIELDS 64 16 | 17 | uint32_t SuperFastHash (const char * data, int len); 18 | 19 | typedef struct _HashField 20 | { 21 | uint32_t hash; 22 | int length; 23 | int iterID; 24 | double thr; 25 | struct _HashField * next; 26 | } HashField; 27 | 28 | typedef struct _HashTable 29 | { 30 | HashField * fields[HT_FIELDS]; 31 | } HashTable; 32 | HashTable HASH_TABLE; 33 | 34 | void htInit(HashTable * ht); 35 | 36 | void htClear(HashTable * ht); 37 | 38 | void htInsert(HashTable * ht, uint32_t hash, int length, int iterID); 39 | 40 | int htContains(HashTable * ht, uint32_t hash, int length, int iterID); 41 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/lapwrap.h: -------------------------------------------------------------------------------- 1 | #ifndef __LAPWRAP_H__ 2 | #define __LAPWRAP_H__ 3 | #include 4 | 5 | #ifndef _WIN32 6 | //#include "/usr/local/MATLAB/R2012a/extern/include/lapack.h" 7 | //#include //if doesn`t work (uncomment previous comment and delete underscores in lapwrap.c functions 8 | #endif 9 | 10 | 11 | 12 | typedef ptrdiff_t lapack_int; 13 | 14 | /* Library of tools wrapping LAPACK utilities and making their usage a bit more comfortable. 15 | All the matrices are stored row-wise! */ 16 | 17 | /* Standard (=FULL) SVD */ 18 | /* prototype is similar to the one in CCMATH, but V is returned transposed 19 | Compute the singular value transformation A = U*S*V^T. 20 | 21 | int lap_SVD(double *d,double *a,double *u,int m,double *vt,int n) 22 | d = pointer to double array of dimension n 23 | (output = singular values of A) 24 | a = pointer to store of the m by n input matrix A 25 | (A is altered by the computation) 26 | u = pointer to store for m by m orthogonal matrix U 27 | vt= pointer to store for n by n orthogonal matrix V^T 28 | m = number of rows in A 29 | n = number of columns in A (m>=n required) 30 | return value: status flag with: 31 | 0 -> success 32 | 1 -> failed to converge. */ 33 | int lap_SVD (double *d, double *a, double *u, lapack_int m, double *vt, lapack_int n); 34 | 35 | 36 | /* Eigen-decomposition 37 | Compute the eigenvalues and eigenvectors of a real symmetric 38 | matrix A. 39 | 40 | void eigen(double *a,double *ev,int n) 41 | double *a,*ev; int n; 42 | a = pointer to store for symmetric n by n input 43 | matrix A. The computation overloads this with an 44 | orthogonal matrix of eigenvectors E. 45 | ev = pointer to the array of the output eigenvalues 46 | n = dimension parameter (dim(a)= n*n, dim(ev)= n) 47 | return value: status flag with: 48 | 0 -> success 49 | 1 -> failed to converge 50 | 51 | The input and output matrices are related by 52 | 53 | A = E*D*E~ where D is the diagonal matrix of eigenvalues 54 | D[i,j] = ev[i] if i=j and 0 otherwise. 55 | 56 | The columns of E are the eigenvectors. */ 57 | int lap_eig(double *a,double *ev, lapack_int n); 58 | 59 | #endif /* __LAPWRAP_H__ */ 60 | 61 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/ranF.h: -------------------------------------------------------------------------------- 1 | #ifndef __RAN_F_H__ 2 | #define __RAN_F_H__ 3 | 4 | #include "rtools.h" 5 | 6 | 7 | Score iterF (double *u, int len, int *inliers, double th, double ths, double *F, 8 | double **errs, double *buffer, unsigned inlLimit); 9 | 10 | Score inFrani (double *u, int len, int *inliers, int ninl, double th, 11 | double **errs, double *buffer, double *F, unsigned inlLimit); 12 | 13 | Score ransacF (double *u, int len, double th, double conf, int max_sam, 14 | double *F, unsigned char * inl, int * data_out, int do_lo, int inlLimit); 15 | 16 | /* LO-RANSAC as simply as possible */ 17 | void ransacFsimple (double *u, int len, double th, double *F); 18 | 19 | int prosacF(double *u, int len, double th, double conf, int * gf, 20 | double *F, unsigned char * inl, int * data_out, double * outn); 21 | 22 | #endif /* __RAN_F_H__ */ 23 | 24 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/ranH.h: -------------------------------------------------------------------------------- 1 | #ifndef __RAN_H_H__ 2 | #define __RAN_H_H__ 3 | 4 | #include "rtools.h" 5 | 6 | 7 | Score iterH (double *u, int len, int *inliers, double th, double ths, double *H, double *Z, 8 | double **errs, double *buffer, unsigned inlLimit); 9 | 10 | Score inHrani (double *u, int len, int *inliers, int ninl, double th, double *Z, 11 | double **errs, double *buffer, double *H, unsigned inlLimit); 12 | 13 | /* LO-RANSAC */ 14 | #ifdef __cplusplus 15 | extern "C" 16 | #endif 17 | Score ransacH (double *u, int len, double th, double conf, int max_sam, 18 | double *H, unsigned char * inl, int *data_out, int do_lo, int inlLimit); 19 | 20 | /* LO-RANSAC as simply as possible */ 21 | void ransacHsimple (double *u, int len, double th, double *H); 22 | 23 | #endif /* __RAN_H_H__ */ 24 | 25 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/ranH2el.h: -------------------------------------------------------------------------------- 1 | #ifndef _RANH2EL_H_ 2 | #define _RANH2EL_H_ 3 | 4 | /* X'Y'A'B'C'XYABC, first is u', second u! (Chum's notation :-) */ 5 | #define _u1 (u[0]) 6 | #define _u2 (u[1]) 7 | #define _u4 (u[5]) 8 | #define _u5 (u[6]) 9 | /* transposed! */ 10 | #define _a1 (A[0]) 11 | #define _a2 (A[3]) 12 | #define _a3 (A[6]) 13 | #define _a4 (A[1]) 14 | #define _a5 (A[4]) 15 | #define _a6 (A[7]) 16 | #define _a7 (A[2]) 17 | #define _a8 (A[5]) 18 | #define _a9 (A[8]) 19 | #define _b1 (B[0]) 20 | #define _b2 (B[3]) 21 | #define _b3 (B[6]) 22 | #define _b4 (B[1]) 23 | #define _b5 (B[4]) 24 | #define _b6 (B[7]) 25 | #define _b7 (B[2]) 26 | #define _b8 (B[5]) 27 | #define _b9 (B[8]) 28 | 29 | #define SQRT2 (1.4142135623730950) 30 | /* (18/7)^2 -> ratio of medians RMSE on GT from minimal samples (2el/4pt), multiplier for threshold of points to go to LO */ 31 | #define TAU (18.0*18.0/7.0/7.0) 32 | 33 | #include "rtools.h" 34 | 35 | Score ransacH2el (double *u10, int len, double th, double conf, int max_sam, 36 | double *H, unsigned char * inl, int *data_out, int do_lo, int inlLimit); 37 | 38 | void getTransf (double *u10, double *N, double *D); 39 | 40 | /*% function H = A2toRH (N1, D1, N2, D2) 41 | % 42 | % computes homography H from two ellipse-to-ellipse correspondences 43 | % N1, N2 are 3x3 matrices representing affine transformations normalizing 44 | % ellipses in the first image to unit circles 45 | % D1, D2 are 3x3 matrices representing affine transformations de-normalizing 46 | % unit circles to ellipses in the second image 47 | % 48 | % For more details see Chum, Matas ICPR 2012:. 49 | % Homography Estimation from Correspondences of Local Elliptical Features*/ 50 | int A2toRH(double *N1, double *D1, double *N2, double *D2, double *u, int *samidx, double *h); 51 | /* More elliptical correspondences */ 52 | int AntoRH(double *u, int *inls, int len, double *h); 53 | 54 | /* Fill Z by equation coefficients given by u */ 55 | void Zu(double * Z, double * u, int len); 56 | 57 | /* Fill Z by equation coefficients given by u, using normalization transformations T1&T2 */ 58 | void ZuN(double * Z, double * u, double * T1, double * T2, int len); 59 | 60 | /* Fill Z by equation coefficients given by N&D */ 61 | void Znd(double * Z, double * A, double * B, int len); 62 | 63 | /* Compute normalization transformation from 2 points */ 64 | void norm2pt(double x1, double y1, double x2, double y2, double *T, double *iT); 65 | 66 | /* Compute normalization transformation from more points */ 67 | void norm10(double * u10, int * inls, int len, double * T, double * iT); 68 | 69 | /* Perform inner RANSAC followed by iterative least squares. 70 | 71 | For small size of inner sample use model computation by ellipses, for bigger use points. */ 72 | Score inHraniEl (double * u10, double *u6, int len, int *inliers, int ninl, double th, double *Z, 73 | double **errs, double *buffer, double *H, unsigned inlLimit); 74 | 75 | 76 | 77 | #endif //_RANH2EL_H_ 78 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/rtools.h: -------------------------------------------------------------------------------- 1 | #ifndef __RTOOLS_H__ 2 | #define __RTOOLS_H__ 3 | 4 | #define DEGENSAC_EPS 2.2204e-16 5 | #define MAX_SAMPLES 1000000 6 | #define CONFIDENCE 0.95 7 | #define ITER_SAM 50 8 | #define RAN_REP 10 9 | #define ILSQ_ITERS 4 10 | #define TC 4 11 | 12 | #define INL_LIMIT_H 28 13 | #define INL_LIMIT_F 49 14 | 15 | #define RESIDS_M (2 + RAN_REP*(1+ILSQ_ITERS+1)) 16 | 17 | /* RANSAC Scoring */ 18 | typedef struct 19 | { 20 | /* number of inliers, rectangular gain function */ 21 | unsigned I; 22 | /* MSAC scoring, truncated quadratic gain function */ 23 | double J; 24 | /* number of inliers in both ways */ 25 | unsigned Is; 26 | /* number of LAF-consistent inliers in both ways */ 27 | unsigned Ilafs; 28 | 29 | } Score; 30 | 31 | #define SC_R 1 32 | #define SC_M 2 33 | #define SC_H 3 34 | #define __SCORE__ SC_M 35 | 36 | /* MSAC Width Multiplier (squared) */ 37 | #if __SCORE__ == SC_M || __SCORE__ == SC_H 38 | #define MWM (9/4) 39 | #else 40 | #define MWM (1) 41 | #endif 42 | 43 | int sample (int *pool, int max_sz, int i); 44 | 45 | int *randsubset (int * pool, int max_sz, int siz); 46 | 47 | void rsample (double *data, int dat_siz, 48 | int *pool, int size, int max_sz, double *dst); 49 | 50 | void addcorrT (double *src, int dat_siz, int max_sz, double *dst); 51 | 52 | void rsampleT (double *data, int dat_siz, 53 | int *pool, int size, int max_sz, double *dst); 54 | 55 | void rsampleTn (double *data, int dat_siz, int *pool, 56 | int size, int n, int max_sz, double *dst); 57 | 58 | void multirsample (double *data, int dat_siz, int dps, 59 | int *pool, int size, int max_sz, double *dst); 60 | 61 | void multirsampleT (double *data, int dat_siz, int dps, 62 | int *pool, int size, int max_sz, double *dst); 63 | 64 | /* Indexes of inliers with error lower than given threshold. Returns RANSAC score. */ 65 | Score inlidxs (const double * err, int len, double th, int * inl); 66 | 67 | /*Indexes of inliers with error lower than given threshold. Returns inliers count.*/ 68 | int inlidxso (const double * err, const double * sgn, int len, double th, 69 | int * inl_buff, int ** inls); 70 | 71 | /*Number of samples to ensure given confidence*/ 72 | int nsamples(int ninl, int ptNum, int samsiz, double conf); 73 | 74 | double truncQuad(double epsilon, double thr); 75 | 76 | /* Score comparator */ 77 | int scoreLess(const Score s1, const Score s2); 78 | 79 | /*Extract sample given by samidx (list of indexes)*/ 80 | void loadSample(double * u, int * samidx, unsigned sample_size, unsigned data_size, double * u_out); 81 | 82 | #endif /* __RTOOLS_H__ */ 83 | 84 | -------------------------------------------------------------------------------- /src/pydegensac/degensac/utools.h: -------------------------------------------------------------------------------- 1 | #ifndef __UTOOLS_H_ 2 | #define __UTOOLS_H_ 3 | 4 | #define _f1 (*F) 5 | #define _f2 (*(F+1)) 6 | #define _f3 (*(F+2)) 7 | #define _f4 (*(F+3)) 8 | #define _f5 (*(F+4)) 9 | #define _f6 (*(F+5)) 10 | #define _f7 (*(F+6)) 11 | #define _f8 (*(F+7)) 12 | #define _f9 (*(F+8)) 13 | 14 | #define crossprod(out,a,b) crossprod_st(out,a,b,1) 15 | #define crossprodT(out,a,b) crossprod_st(out,a,b,3) 16 | 17 | void normu (const double *u, const int * inl, int len, 18 | double *A1, double *A2); 19 | 20 | void denormF (double *F, double *A1, double *A2); 21 | 22 | void denormH (double *F, double *A1, double *A2); 23 | 24 | void scalmul (double *data, double m, int len, int step) ; 25 | 26 | int nullspace(double *matrix, double *nullspace, int n, int * buffer); 27 | 28 | void cov_mat(double *Cv, const double * Z, int len, int siz); 29 | 30 | void crossprod_st(double *out, const double *a, const double *b, int st); 31 | 32 | double det3 (const double *A); 33 | 34 | #endif /* __UTOOLS_H_ */ 35 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 3.9) 2 | PROJECT(MatUtls C) 3 | 4 | IF(CMAKE_COMPILER_IS_GNUCXX) 5 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-strict-aliasing") 6 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -Wno-write-strings") 7 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -ansi") 8 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -ftree-vectorize -funroll-loops") 9 | ENDIF(CMAKE_COMPILER_IS_GNUCXX) 10 | 11 | include_directories(.) 12 | set(matutls_srcs 13 | atou1.c cmprt.c hevmax.c 14 | mcopy.c qrbdv.c solvru.c 15 | trncm.c atovm.c csolv.c 16 | hmgen.c minv.c qrecvc.c 17 | solvtd.c trnm.c chouse.c cvmul.c house.c 18 | mmul.c qreval.c sv2u1v.c unitary.c 19 | chousv.c eigen.c housev.c ortho.c qrevec.c sv2uv.c utrncm.c 20 | cmattr.c eigval.c ldumat.c otrma.c 21 | qrlsq.c sv2val.c utrnhm.c 22 | cmcpy.c evmax.c ldvmat.c otrsm.c rmmult.c vmul.c 23 | cminv.c hconj.c lsqsv.c psinv.c ruinv.c svdu1v.c 24 | cmmul.c heigval.c matprt.c qrbdi.c smgen.c svduv.c 25 | cmmult.c heigvec.c mattr.c qrbdu1.c solvps.c svdval.c 26 | matconsts.c) 27 | add_library(matutls ${matutls_srcs}) 28 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/Makefile: -------------------------------------------------------------------------------- 1 | include ../../config 2 | 3 | CFLAGS += -fno-builtin 4 | 5 | LIBS = matutls 6 | 7 | matutls_CFILES = atou1.c cmcpy.c csolv.c hconj.c house.c mattr.c otrma.c \ 8 | qrbdv.c ruinv.c sv2u1v.c svduv.c utrncm.c atovm.c cminv.c \ 9 | cvmul.c heigval.c housev.c mcopy.c otrsm.c qrecvc.c smgen.c \ 10 | sv2uv.c svdval.c utrnhm.c chouse.c cmmul.c eigen.c heigvec.c\ 11 | ldumat.c minv.c psinv.c qreval.c solvps.c sv2val.c trncm.c \ 12 | vmul.c chousv.c cmmult.c eigval.c hevmax.c ldvmat.c mmul.c \ 13 | qrbdi.c qrevec.c solvru.c trnm.c cmattr.c cmprt.c evmax.c \ 14 | hmgen.c matprt.c ortho.c qrbdu1.c rmmult.c solvtd.c svdu1v.c\ 15 | unitary.c lsqsv.c qrlsq.c 16 | 17 | $(do_libs) 18 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/atou1.c: -------------------------------------------------------------------------------- 1 | /* atou1.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | void atou1(double *a,int m,int n) 10 | { double *p0,*p,*q,*w; 11 | int i,j,k,mm; 12 | double s,h; 13 | w=(double *)calloc(m,sizeof(double)); 14 | p0=a+n*n-1; i=n-1; mm=m-n; 15 | if(mm==0){ *p0=1.; p0-=n+1; --i; ++mm;} 16 | for(; i>=0 ;--i,++mm,p0-=n+1){ 17 | if(*p0!=0.){ 18 | for(j=0,p=p0+n; j=0 ;--i,p0-=n+1,q0-=n+1,++mm){ 15 | if(i && *(p0-1)!=0.){ 16 | for(j=0,p=p0,h=1.; j 9 | #include "complex.h" 10 | void chouse(Cpx *a,double *d,double *dp,int n) 11 | { double sc,x,y; Cpx cc,u,*q0; 12 | int i,j,k,m,e; 13 | Cpx *qw,*pc,*p; 14 | q0=(Cpx *)calloc(2*n,sizeof(Cpx)); 15 | for(i=0,p=q0+n,pc=a; i0.){ sc=sqrt(sc); p=pc+1; 20 | y=sc+(x=sqrt(p->re*p->re+p->im*p->im)); 21 | if(x>0.){ cc.re=p->re/x; cc.im=p->im/x;} 22 | else{ cc.re=1.; cc.im=0.;} 23 | x=1./sqrt(2.*sc*y); y*=x; 24 | for(i=0,qw=pc+1; ire - (u.im=qw[i].im)*p->im; 31 | q0[i].im+=u.re*p->im + u.im*p->re; ++p; 32 | for(k=i+1; kre - qw[k].im*p->im; 34 | q0[i].im+=qw[k].im*p->re + qw[k].re*p->im; 35 | q0[k].re+=u.re*p->re + u.im*p->im; 36 | q0[k].im+=u.im*p->re - u.re*p->im; 37 | } 38 | y+=u.re*q0[i].re + u.im*q0[i].im; 39 | } 40 | for(i=0; ire-=qw[i].re*q0[k].re + qw[i].im*q0[k].im 47 | +q0[i].re*qw[k].re + q0[i].im*qw[k].im; 48 | p->im-=qw[i].im*q0[k].re - qw[i].re*q0[k].im 49 | +q0[i].im*qw[k].re - q0[i].re*qw[k].im; 50 | } 51 | } 52 | } 53 | d[j]=pc->re; dp[j]=sc; 54 | } 55 | d[j]=pc->re; d[j+1]=(pc+n+1)->re; 56 | u= *(pc+1); dp[j]=sqrt(u.re*u.re+u.im*u.im); 57 | for(j=0,pc=a,qw=q0+n; jre; pc[i].im= -p->im; 61 | } 62 | } 63 | free(q0); 64 | } 65 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/chousv.c: -------------------------------------------------------------------------------- 1 | /* chousv.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | void chousv(Cpx *a,double *d,double *dp,int n) 11 | { double sc,x,y; Cpx cc,u,*qs; 12 | int i,j,k,m,e; 13 | Cpx *qw,*pc,*p,*q; 14 | qs=(Cpx *)calloc(2*n,sizeof(Cpx)); q=qs+n; 15 | for(j=0,pc=a; j0.){ sc=sqrt(sc); p=pc+1; 19 | y=sc+(x=sqrt(p->re*p->re+p->im*p->im)); 20 | if(x>0.){ cc.re=p->re/x; cc.im=p->im/x;} 21 | else{ cc.re=1.; cc.im=0.;} 22 | q->re= -cc.re; q->im= -cc.im; 23 | x=1./sqrt(2.*sc*y); y*=x; 24 | for(i=0,qw=pc+1; ire - (u.im=qw[i].im)*p->im; 31 | qs[i].im+=u.re*p->im + u.im*p->re; ++p; 32 | for(k=i+1; kre - qw[k].im*p->im; 34 | qs[i].im+=qw[k].im*p->re + qw[k].re*p->im; 35 | qs[k].re+=u.re*p->re + u.im*p->im; 36 | qs[k].im+=u.im*p->re - u.re*p->im; 37 | } 38 | y+=u.re*qs[i].re + u.im*qs[i].im; 39 | } 40 | for(i=0; ire-=qw[i].re*qs[k].re + qw[i].im*qs[k].im 47 | +qs[i].re*qw[k].re + qs[i].im*qw[k].im; 48 | p->im-=qw[i].im*qs[k].re - qw[i].re*qs[k].im 49 | +qs[i].im*qw[k].re - qs[i].re*qw[k].im; 50 | } 51 | } 52 | } 53 | d[j]=pc->re; dp[j]=sc; 54 | } 55 | d[j]=pc->re; cc= *(pc+1); d[j+1]=(pc+=n+1)->re; 56 | dp[j]=sc=sqrt(cc.re*cc.re+cc.im*cc.im); 57 | q->re=cc.re/=sc; q->im=cc.im/=sc; 58 | for(i=0,m=n+n,p=pc; ire=p->im=0.; 59 | pc->re=1.; (pc-=n+1)->re=1.; qw=pc-n; 60 | for(m=2; mre=1.; jre-qw[i].im*q->im; 64 | u.im+=qw[i].re*q->im+qw[i].im*q->re; 65 | } 66 | for(i=0,q=p,u.re+=u.re,u.im+=u.im; ire-=u.re*qw[i].re+u.im*qw[i].im; 68 | q->im-=u.im*qw[i].re-u.re*qw[i].im; 69 | } 70 | } 71 | for(i=0,p=qw+m-1; ire=p->im=0.; 72 | (pc-=n+1)->re=1.; 73 | } 74 | for(j=1,p=a+n+1,q=qs+n,u.re=1.,u.im=0.; jre-u.im*q->im; u.im=u.im*q->re+u.re*q->im; u.re=sc; 76 | for(i=1; ire-u.im*p->im; p->im=u.re*p->im+u.im*p->re; p->re=sc; 78 | } 79 | } 80 | free(qs); 81 | } 82 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/cmattr.c: -------------------------------------------------------------------------------- 1 | /* cmattr.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "complex.h" 9 | void cmattr(Cpx *a,Cpx *b,int m,int n) 10 | { Cpx *p; int i,j; 11 | for(i=0; ire*q->re-p->im*q->im; 17 | s.im+=p->im*q->re+p->re*q->im; ++p; ++q; 18 | } 19 | *c++ =s; 20 | } 21 | } 22 | trncm(b,n); 23 | } 24 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/cmmult.c: -------------------------------------------------------------------------------- 1 | /* cmmult.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | void cmmult(Cpx *cm,Cpx *a,Cpx *b,int n,int m,int l) 11 | { Cpx z,*q0,*p,*q; int i,j,k; 12 | q0=(Cpx *)calloc(m,sizeof(Cpx)); 13 | for(i=0; ire*q0[k].re-p->im*q0[k].im; 18 | z.im+=p->im*q0[k].re+p->re*q0[k].im; 19 | } 20 | *q=z; 21 | } 22 | } 23 | free(q0); 24 | } 25 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/cmprt.c: -------------------------------------------------------------------------------- 1 | /* cmprt.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "complex.h" 9 | #include 10 | void cmprt(Cpx *a,int m,int n,char *f) 11 | { int i,j; Cpx *p; 12 | for(i=0,p=a; ire,p->im); 14 | printf("\n"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/complex.h: -------------------------------------------------------------------------------- 1 | /* complex.h CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #ifndef CPX 9 | struct complex 10 | { 11 | double re,im; 12 | }; 13 | typedef struct complex Cpx; 14 | #define CPX 1 15 | #endif 16 | 17 | #include 18 | struct complex cadd(Cpx a,Cpx b); 19 | struct complex csub(Cpx a,Cpx b); 20 | struct complex cmul(Cpx a,Cpx b); 21 | struct complex cdiv(Cpx a,Cpx b); 22 | struct complex crmu(double x,Cpx a); 23 | struct complex cimu(double y,Cpx a); 24 | struct complex ccng(Cpx c); 25 | struct complex cdef(double r,double i); 26 | #ifndef WIN32 27 | double cabs(Cpx a); 28 | #endif 29 | struct complex cnrm(Cpx a); 30 | struct complex csqrt(Cpx a); 31 | struct complex cexp(Cpx a); 32 | struct complex clog(Cpx a); 33 | struct complex csin(Cpx a); 34 | struct complex ccos(Cpx a); 35 | struct complex ctan(Cpx a); 36 | struct complex casin(Cpx f); 37 | struct complex cacos(Cpx f); 38 | struct complex catan(Cpx f); 39 | struct complex csinh(Cpx h); 40 | struct complex ccosh(Cpx h); 41 | struct complex ctanh(Cpx h); 42 | struct complex casinh(Cpx g); 43 | struct complex cacosh(Cpx g); 44 | struct complex catanh(Cpx g); 45 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/csolv.c: -------------------------------------------------------------------------------- 1 | /* csolv.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | int csolv(Cpx *a,Cpx *b,int n) 11 | { int i,j,k,lc; Cpx *ps,*p,*q,*pa,*pd; 12 | Cpx z,h,*q0; double s,t,tq=0.,zr=1.e-15; 13 | q0=(Cpx *)calloc(n,sizeof(Cpx)); 14 | pa=a; pd=a; 15 | for(j=0; j0){ 17 | for(i=0,p=pa,q=q0; ire*q->re-p->im*q->im; 22 | z.im+=p->im*q->re+p->re*q->im; 23 | } 24 | q0[i].re-=z.re; q0[i].im-=z.im; 25 | } 26 | for(i=0,p=pa,q=q0; ire)+fabs(pd->im); lc=j; 29 | for(k=j+1,ps=pd; kre)+fabs(ps->im))>s){ s=t; lc=k;} 31 | } 32 | tq=tq>s?tq:s; if(sre*pd->re+pd->im*pd->im; 39 | h.re=pd->re/t; h.im= -(pd->im)/t; 40 | for(k=j+1,ps=pd+n; kre*h.re-ps->im*h.im; 42 | z.im=ps->im*h.re+ps->re*h.im; *ps=z; 43 | } 44 | } 45 | for(j=1,ps=b+1; jre*q->re-p->im*q->im; 48 | z.im+=p->im*q->re+p->re*q->im; ++p; ++q; 49 | } 50 | ps->re-=z.re; ps->im-=z.im; 51 | } 52 | for(j=n-1,--ps,pd=a+n*n-1; j>=0 ;--j,pd-=n+1){ 53 | for(k=j+1,p=pd+1,q=b+j+1,z.re=z.im=0.; kre*q->re-p->im*q->im; 55 | z.im+=p->im*q->re+p->re*q->im; ++p; ++q; 56 | } 57 | h.re=ps->re-z.re; h.im=ps->im-z.im; 58 | t=pd->re*pd->re+pd->im*pd->im; 59 | ps->re=(h.re*pd->re+h.im*pd->im)/t; 60 | ps->im=(h.im*pd->re-h.re*pd->im)/t; --ps; 61 | } 62 | free(q0); return 0; 63 | } 64 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/cvmul.c: -------------------------------------------------------------------------------- 1 | /* cvmul.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include "complex.h" 9 | void cvmul(Cpx *u,Cpx *a,Cpx *v,int n) 10 | { Cpx *q; int i,j; 11 | for(i=0; ire=u->im=0.; 13 | for(j=0,q=v; jre+=a->re*q->re-a->im*q->im; 15 | u->im+=a->im*q->re+a->re*q->im; 16 | } 17 | } 18 | } 19 | Cpx cvnrm(Cpx *u,Cpx *v,int n) 20 | { int k; Cpx z; 21 | z.re=z.im=0.; 22 | for(k=0; kre*v->re+u->im*v->im; 24 | z.im+=u->re*v->im-u->im*v->re; 25 | } 26 | return z; 27 | } 28 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/eigen.c: -------------------------------------------------------------------------------- 1 | /* eigen.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "matutl.h" 10 | void eigen(double *a,double *ev,int n) 11 | { double *dp; 12 | dp=(double *)calloc(n,sizeof(double)); 13 | housev(a,ev,dp,n); 14 | qrevec(ev,a,dp,n); trnm(a,n); 15 | free(dp); 16 | } 17 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/eigval.c: -------------------------------------------------------------------------------- 1 | /* eigval.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "matutl.h" 10 | void eigval(double *a,double *ev,int n) 11 | { double *dp; 12 | dp=(double *)calloc(n,sizeof(double)); 13 | house(a,ev,dp,n); 14 | qreval(ev,dp,n); 15 | free(dp); 16 | } 17 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/evmax.c: -------------------------------------------------------------------------------- 1 | /* evmax.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include 10 | double evmax(double *a,double *u,int n) 11 | { double *p,*q,*qm,*r,*s,*t; 12 | double ev,evm,c,h; int kc; 13 | q=(double *)calloc(n,sizeof(double)); qm=q+n; 14 | *(qm-1)=1.; ev=0.; 15 | for(kc=0; kc<200 ;++kc){ h=c=0.; evm=ev; 16 | for(p=u,r=a,s=q; sre=q->re; 15 | (p++)->im= -q->im; *q=s; q+=n; 16 | } 17 | a->im= -a->im; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/heigval.c: -------------------------------------------------------------------------------- 1 | /* heigval.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | #include "matutl.h" 11 | void heigval(Cpx *a,double *ev,int n) 12 | { double *dp; 13 | dp=(double *)calloc(n,sizeof(double)); 14 | chouse(a,ev,dp,n); 15 | qreval(ev,dp,n); 16 | free(dp); 17 | } 18 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/heigvec.c: -------------------------------------------------------------------------------- 1 | /* heigvec.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | #include "matutl.h" 11 | void heigvec(Cpx *a,double *ev,int n) 12 | { double *dp; 13 | dp=(double *)calloc(n,sizeof(double)); 14 | chousv(a,ev,dp,n); 15 | qrecvc(ev,a,dp,n); hconj(a,n); 16 | free(dp); 17 | } 18 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/hevmax.c: -------------------------------------------------------------------------------- 1 | /* hevmax.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | double hevmax(Cpx *a,Cpx *u,int n) 11 | { Cpx *x,*p,h; 12 | double e,ep,s,t,te=1.e-12; 13 | int k,j; 14 | x=(Cpx *)calloc(n,sizeof(Cpx)); 15 | x[0].re=1.; e=0.; 16 | do{ 17 | for(k=0,p=a,s=t=0.; kre*x[j].re-p->im*x[j].im; 20 | h.im+=p->im*x[j].re+p->re*x[j].im; 21 | } 22 | s+=h.re*h.re+h.im*h.im; 23 | t+=h.re*x[k].re+h.im*x[k].im; 24 | u[k]=h; 25 | } 26 | ep=e; e=s/t; s=1./sqrt(s); 27 | for(k=0; kfabs(te*e)); 31 | free(x); 32 | return e; 33 | } 34 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/hmgen.c: -------------------------------------------------------------------------------- 1 | /* hmgen.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | #include "matutl.h" 11 | void hmgen(Cpx *h,double *ev,Cpx *u,int n) 12 | { Cpx *v,*p; 13 | int i,j; double e; 14 | v=(Cpx *)calloc(n*n,sizeof(Cpx)); 15 | cmcpy(v,u,n*n); hconj(v,n); 16 | for(i=0,p=v; ire*=e; p->im*=e; 19 | } 20 | } 21 | cmmul(h,u,v,n); 22 | free(v); 23 | } 24 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/house.c: -------------------------------------------------------------------------------- 1 | /* house.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include 10 | void house(double *a,double *d,double *dp,int n) 11 | { double sc,x,y,h; 12 | int i,j,k,m,e; 13 | double *qw,*qs,*pc,*p; 14 | qs=(double *)calloc(2*n,sizeof(double)); 15 | for(j=0,qw=qs+n,pc=a; j0.){ sc=sqrt(sc); 20 | if((x= *(pc+1))<0.){ y=x-sc; h=1./sqrt(-2.*sc*y);} 21 | else{ y=x+sc; h=1./sqrt(2.*sc*y); sc= -sc;} 22 | for(i=0,qw=pc+1; i 9 | #include 10 | void housev(double *a,double *d,double *dp,int n) 11 | { double sc,x,y,h; 12 | int i,j,k,m,e; 13 | double *qw,*qs,*pc,*p; 14 | qs=(double *)calloc(n,sizeof(double)); 15 | for(j=0,pc=a; j0.){ sc=sqrt(sc); 19 | if((x= *(pc+1))<0.){ y=x-sc; h=1./sqrt(-2.*sc*y);} 20 | else{ y=x+sc; h=1./sqrt(2.*sc*y); sc= -sc;} 21 | for(i=0,qw=pc+1; i 9 | void ldumat(double *a,double *u,int m,int n) 10 | { double *p0,*q0,*p,*q,*w; 11 | int i,j,k,mm; 12 | double s,h; 13 | w=(double *)calloc(m,sizeof(double)); 14 | for(i=0,mm=m*m,q=u; i=0 ;--i,++mm,p0-=n+1,q0-=m+1){ 19 | if(*p0!=0.){ 20 | for(j=0,p=p0+n,h=1.; j0 ;--i,p0-=n+1,q0-=n+1,++mm){ 16 | if(*(p0-1)!=0.){ 17 | for(j=0,p=p0,h=1.; j 9 | void vmul(double *x,double *v,double *y,int n); 10 | void smgen(double *var,double *y,double *v,int n); 11 | double lsqsv(double *x,int *pr,double *var,double *d,double *b,double *v, 12 | int m,int n,double th) 13 | { double ssq,sig,*y,*p; 14 | int i,k; 15 | y=(double *)calloc(n,sizeof(double)); 16 | for(i=n,ssq=0.,p=b+n; in){ 24 | sig=ssq/(double)(m-n); 25 | for(i=0; i 9 | void matprt(double *a,int n,int m,char *fmt) 10 | { int i,j; double *p; 11 | for(i=0,p=a; i 9 | #include 10 | int minv(double *a,int n) 11 | { int lc,*le; double s,t,tq=0.,zr=1.e-15; 12 | double *pa,*pd,*ps,*p,*q,*q0; 13 | int i,j,k,m; 14 | le=(int *)malloc(n*sizeof(int)); 15 | q0=(double *)malloc(n*sizeof(double)); 16 | for(j=0,pa=pd=a; j0){ 18 | for(i=0,q=q0,p=pa; is){ s=t; lc=k;} 28 | } 29 | tq=tq>s?tq:s; if(s=0 ;--j){ --pa; pd-=n+1; 51 | for(i=0,m=n-j-1,q=q0,p=pd+n; ij ;--k,ps-=n){ t= -(*ps); 53 | for(i=j+1,p=ps,q=q0; ik){ t=0.; p=ps+j; i=j;} 62 | else{ t=q0[j]; p=ps+k+1; i=k+1;} 63 | for(; i=0 ;--j){ 69 | for(k=0,p=a+j,q=a+ *(--le); k 9 | static double tpi=6.28318530717958647; 10 | void ortho(double *e,int n) 11 | { int i,j,k,m; 12 | double *p,*q,c,s,a,unfl(); 13 | for(i=0,p=e; i 9 | void otrma(double *c,double *a,double *b,int n) 10 | { double z,*q0,*p,*s,*t; 11 | int i,j,k; 12 | q0=(double *)calloc(n,sizeof(double)); 13 | for(i=0; i 9 | void otrsm(double *sm,double *a,double *b,int n) 10 | { double z,*q0,*p,*s,*t; 11 | int i,j,k; 12 | q0=(double *)calloc(n,sizeof(double)); 13 | for(i=0; i 9 | #include "matutl.h" 10 | int psinv(double *v,int n) 11 | { double z,*p,*q,*r,*s,*t; int j,k; 12 | for(j=0,p=v; j 9 | int qrbdi(double *dm,double *em,int m) 10 | { int i,j,k,n; 11 | double u,x,y,a,b,c,s,t; 12 | for(j=1,t=fabs(dm[0]); jt) t=s; 14 | t*=1.e-15; n=100*m; 15 | for(j=0; m>1 && j0 ;--k){ 17 | if(fabs(em[k-1])0.){ 30 | c=sqrt((u+a)/(u+u)); 31 | if(c!=0.) s/=(c*u); else s=1.; 32 | for(i=k; ik){ 35 | a=s*em[i]; b*=c; 36 | em[i-1]=u=sqrt(x*x+a*a); 37 | c=x/u; s=a/u; 38 | } 39 | a=c*y+s*b; b=c*b-s*y; 40 | s*=dm[i+1]; dm[i]=u=sqrt(a*a+s*s); 41 | y=c*dm[i+1]; c=a/u; s/=u; 42 | x=c*b+s*y; y=c*y-s*b; 43 | } 44 | } 45 | em[m-2]=x; dm[m-1]=y; 46 | if(fabs(x) 9 | int qrbdu1(double *dm,double *em,double *um,int mm,double *vm,int m) 10 | { int i,j,k,n,jj,nm; 11 | double u,x,y,a,b,c,s,t,w,*p,*q; 12 | for(j=1,t=fabs(dm[0]); jt) t=s; 14 | t*=1.e-15; n=100*m; nm=m; 15 | for(j=0; m>1 && j0 ;--k){ 17 | if(fabs(em[k-1])0.){ 34 | c=sqrt((u+a)/(u+u)); 35 | if(c!=0.) s/=(c*u); else s=1.; 36 | for(i=k; ik){ 39 | a=s*em[i]; b*=c; 40 | em[i-1]=u=sqrt(x*x+a*a); 41 | c=x/u; s=a/u; 42 | } 43 | a=c*y+s*b; b=c*b-s*y; 44 | for(jj=0,p=vm+i; jj 9 | int qrbdv(double *dm,double *em,double *um,int mm,double *vm,int m) 10 | { int i,j,k,n,jj,nm; 11 | double u,x,y,a,b,c,s,t,w,*p,*q; 12 | for (j=1,t=fabs(dm[0]); jt) t=s; 14 | t*=1.e-15; n=100*m; nm=m; 15 | for(j=0; m>1 && j0 ;--k){ 17 | if(fabs(em[k-1])k){ 39 | a=s*em[i]; b*=c; 40 | em[i-1]=u=sqrt(x*x+a*a); 41 | c=x/u; s=a/u; 42 | } 43 | a=c*y+s*b; b=c*b-s*y; 44 | for(jj=0,p=vm+i; jj1 && fabs(dp[m-2])>fabs(ev[k])*tzr) break; 20 | if((cc=sqrt((1.+x/h)/2.))!=0.) sc=dp[k]/(2.*cc*h); else sc=1.; 21 | x+=ev[m]; ev[m--]=x-h; ev[m--]=x+h; 22 | for(i=0,p=evec+n*(m+1); i0.) d=ev[m]+x-h; else d=ev[m]+x+h; 31 | cc=1.; y=0.; ev[0]-=d; 32 | for(k=0; k0) dp[k-1]=sc*h; 35 | ev[k]=cc*h; cc=x/h; sc=dp[k]/h; ev[k+1]-=d; y*=sc; 36 | ev[k]=cc*(ev[k]+y)+ev[k+1]*sc*sc+d; 37 | for(i=0,p=evec+n*k; i 9 | int qreval(double *ev,double *dp,int n) 10 | { double cc,sc,d,x,y,h,tzr=1.e-15; 11 | int j,k,m,mqr=8*n; 12 | for(j=0,m=n-1;;++j){ 13 | while(1){ if(m<1) return 0; k=m-1; 14 | if(fabs(dp[k])<=fabs(ev[m])*tzr) --m; 15 | else{ x=(ev[k]-ev[m])/2.; h=sqrt(x*x+dp[k]*dp[k]); 16 | if(m>1 && fabs(dp[m-2])>fabs(ev[k])*tzr) break; 17 | x+=ev[m]; ev[m--]=x-h; ev[m--]=x+h; 18 | } 19 | } 20 | if(j>mqr) return -1; 21 | if(x>0.) d=ev[m]+x-h; else d=ev[m]+x+h; 22 | cc=1.; y=0.; ev[0]-=d; 23 | for(k=0; k0) dp[k-1]=sc*h; 26 | ev[k]=cc*h; cc=x/h; sc=dp[k]/h; ev[k+1]-=d; y*=sc; 27 | ev[k]=cc*(ev[k]+y)+ev[k+1]*sc*sc+d; 28 | } 29 | ev[k]=ev[k]*cc-y; dp[k-1]=ev[k]*sc; ev[k]=ev[k]*cc+d; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/qrevec.c: -------------------------------------------------------------------------------- 1 | /* qrevec.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | int qrevec(double *ev,double *evec,double *dp,int n) 10 | { double cc,sc,d,x,y,h,tzr=1.e-15; 11 | int i,j,k,m,mqr=8*n; 12 | double *p; 13 | for(j=0,m=n-1;;++j){ 14 | while(1){ if(m<1) return 0; k=m-1; 15 | if(fabs(dp[k])<=fabs(ev[m])*tzr) --m; 16 | else{ x=(ev[k]-ev[m])/2.; h=sqrt(x*x+dp[k]*dp[k]); 17 | if(m>1 && fabs(dp[m-2])>fabs(ev[k])*tzr) break; 18 | if((cc=sqrt((1.+x/h)/2.))!=0.) sc=dp[k]/(2.*cc*h); else sc=1.; 19 | x+=ev[m]; ev[m--]=x-h; ev[m--]=x+h; 20 | for(i=0,p=evec+n*(m+1); imqr) return -1; 26 | if(x>0.) d=ev[m]+x-h; else d=ev[m]+x+h; 27 | cc=1.; y=0.; ev[0]-=d; 28 | for(k=0; k0) dp[k-1]=sc*h; 31 | ev[k]=cc*h; cc=x/h; sc=dp[k]/h; ev[k+1]-=d; y*=sc; 32 | ev[k]=cc*(ev[k]+y)+ev[k+1]*sc*sc+d; 33 | for(i=0,p=evec+n*k; i 9 | #include 10 | int solvru(double *a,double *b,int n); 11 | double qrlsq(double *a,double *b,int m,int n,int *f) 12 | { double *p,*q,*w; 13 | double s,h,r; 14 | int i,j,k,mm,ms; 15 | if(m1){ 19 | for(j=0,q=p,s=0.; j0.){ 23 | h=sqrt(s); if(*p<0.) h= -h; 24 | s+= *p*h; s=1./s; w[0]+=h; 25 | for(k=1,ms=n-i; k 9 | void rmmult(double *rm,double *a,double *b,int n,int m,int l) 10 | { double z,*q0,*p,*q; int i,j,k; 11 | q0=(double *)calloc(m,sizeof(double)); 12 | for(i=0; itt) tt=z; 12 | tt*=1.e-16; 13 | for(j=0,p=a; j 9 | int solvps(double *a,double *b,int n) 10 | { double *p,*q,*r,*s,t; 11 | int j,k; 12 | for(j=0,p=a; j=0 ;--j,p-=n+1){ 26 | for(k=j+1,q=p+n; ks) s=t; 12 | s*=1.e-16; 13 | for(j=n-1,p=a+n*n-1; j>=0 ;--j,p-=n+1){ 14 | for(k=j+1,q=p+1; k=0 ;--j){ 13 | x[j]-=s*c[j]; s=(x[j]/=a[j]);} 14 | } 15 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/sv2u1v.c: -------------------------------------------------------------------------------- 1 | /* sv2u1v.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include 10 | #include "matutl.h" 11 | int sv2u1v(double *d,double *a,int m,double *v,int n) 12 | { double *p,*p1,*q,*pp,*w,*e; 13 | double s,t,h,r,sv; 14 | int i,j,k,mm,nm,ms; 15 | if(m1){ sv=h=0.; 19 | for(j=0,q=p,s=0.; j0.){ 23 | h=sqrt(s); if(*p<0.) h= -h; 24 | s+= *p*h; s=1./s; t=1./(w[0]+=h); 25 | sv=1.+fabs(*p/h); 26 | for(k=1,ms=n-i; k1){ sv=h=0.; 47 | for(j=0,q=p,s=0.; j0.){ 51 | h=sqrt(s); if(*p<0.) h= -h; 52 | s+= *p*h; s=1./s; t=1./(w[0]+=h); 53 | sv=1.+fabs(*p/h); 54 | for(k=1,ms=n-i; k1){ sv=h=0.; 68 | for(j=0,q=p1,s=0.; j0.){ 70 | h=sqrt(s); if(*p1<0.) h= -h; 71 | sv=1.+fabs(*p1/h); 72 | s+= *p1*h; s=1./s; t=1./(*p1+=h); 73 | for(k=n,ms=n*(n-i); k 9 | #include 10 | #include "matutl.h" 11 | int sv2uv(double *d,double *a,double *u,int m,double *v,int n) 12 | { double *p,*p1,*q,*pp,*w,*e; 13 | double s,t,h,r,sv; 14 | int i,j,k,mm,nm,ms; 15 | if(m1){ sv=h=0.; 19 | for(j=0,q=p,s=0.; j0.){ 23 | h=sqrt(s); if(*p<0.) h= -h; 24 | s+= *p*h; s=1./s; t=1./(w[0]+=h); 25 | sv=1.+fabs(*p/h); 26 | for(k=1,ms=n-i; k1){ sv=h=0.; 46 | for(j=0,q=p,s=0.; j0.){ 50 | h=sqrt(s); if(*p<0.) h= -h; 51 | s+= *p*h; s=1./s; t=1./(w[0]+=h); 52 | sv=1.+fabs(*p/h); 53 | for(k=1,ms=n-i; k1){ sv=h=0.; 67 | for(j=0,q=p1,s=0.; j0.){ 69 | h=sqrt(s); if(*p1<0.) h= -h; 70 | sv=1.+fabs(*p1/h); 71 | s+= *p1*h; s=1./s; t=1./(*p1+=h); 72 | for(k=n,ms=n*(n-i); k 9 | #include 10 | #include "matutl.h" 11 | 12 | int sv2val(double *d,double *a,int m,int n) 13 | { 14 | double *p,*p1,*q,*w,*v; 15 | double s,h,u; 16 | int i,j,k,mm,nm,ms; 17 | if(m1 ;++i,--mm,p+=n+1){ 20 | for(j=0,q=p,s=0.; j0.){ 24 | h=sqrt(s); if(*p<0.) h= -h; 25 | s+= *p*h; s=1./s; w[0]+=h; 26 | for(k=1,ms=n-i; k1){ 39 | for(j=0,q=p,s=0.; j0.){ 43 | h=sqrt(s); if(*p<0.) h= -h; 44 | s+= *p*h; s=1./s; w[0]+=h; 45 | for(k=1,ms=n-i; k1){ 55 | for(j=0,q=p1,s=0.; j0.){ 57 | h=sqrt(s); if(*p1<0.) h= -h; 58 | s+= *p1*h; s=1./s; *p1+=h; 59 | for(k=n,ms=n*(m-i); k 3 | #include 4 | #include "svduv.c" 5 | #include "ldvmat.c" 6 | #include "ldumat.c" 7 | #include "atou1.c" 8 | #include "qrbdu1.c" 9 | #include "qrbdv.c" 10 | #include "svdu1v.c" 11 | 12 | void pm(double *p, int c, int r) 13 | { 14 | int i,j; 15 | 16 | for (i=0; i 9 | #include 10 | #include "matutl.h" 11 | int svdu1v(double *d,double *a,int m,double *v,int n) 12 | { double *p,*p1,*q,*pp,*w,*e; 13 | double s,h,r,t,sv; 14 | int i,j,k,mm,nm,ms; 15 | if(m1){ sv=h=0.; 19 | for(j=0,q=p,s=0.; j0.){ 23 | h=sqrt(s); if(*p<0.) h= -h; 24 | s+= *p*h; s=1./s; t=1./(w[0]+=h); 25 | sv=1.+fabs(*p/h); 26 | for(k=1,ms=n-i; k1){ 38 | for(j=0,q=p1,s=0.; j0.){ 40 | h=sqrt(s); if(*p1<0.) h= -h; 41 | sv=1.+fabs(*p1/h); 42 | s+= *p1*h; s=1./s; t=1./(*p1+=h); 43 | for(k=n,ms=n*(m-i); k 9 | #include 10 | #include "matutl.h" 11 | int svduv(double *d,double *a,double *u,int m,double *v,int n) 12 | { double *p,*p1,*q,*pp,*w,*e; 13 | double s,h,r,t,sv; 14 | int i,j,k,mm,nm,ms; 15 | if(m1){ sv=h=0.; 19 | for(j=0,q=p,s=0.; j0.){ 23 | h=sqrt(s); if(*p<0.) h= -h; 24 | s+= *p*h; s=1./s; t=1./(w[0]+=h); 25 | sv=1.+fabs(*p/h); 26 | for(k=1,ms=n-i; k1){ 38 | for(j=0,q=p1,s=0.; j0.){ 40 | h=sqrt(s); if(*p1<0.) h= -h; 41 | sv=1.+fabs(*p1/h); 42 | s+= *p1*h; s=1./s; t=1./(*p1+=h); 43 | for(k=n,ms=n*(m-i); k 9 | #include 10 | #include "matutl.h" 11 | int svdval(double *d,double *a,int m,int n) 12 | { double *p,*p1,*q,*w,*v; 13 | double s,h,u; 14 | int i,j,k,mm,nm,ms; 15 | if(m1){ 19 | for(j=0,q=p,s=0.; j0.){ 23 | h=sqrt(s); if(*p<0.) h= -h; 24 | s+= *p*h; s=1./s; w[0]+=h; 25 | for(k=1,ms=n-i; k1){ 35 | for(j=0,q=p1,s=0.; j0.){ 37 | h=sqrt(s); if(*p1<0.) h= -h; 38 | s+= *p1*h; s=1./s; *p1+=h; 39 | for(k=n,ms=n*(m-i); k 9 | #include "complex.h" 10 | static void ortho(); 11 | static double tpi=6.283185307179586; 12 | double unfl(); 13 | void unitary(Cpx *u,int n) 14 | { int i,j,k,m; Cpx h,*v,*e,*p,*r; 15 | double *g,*q,a; 16 | m=n*n; 17 | g=(double *)calloc(n*n,sizeof(double)); 18 | v=(Cpx *)calloc(m+n,sizeof(Cpx)); 19 | e=v+m; 20 | h.re=1.; h.im=0.; 21 | for(i=0; ire= *q++; 35 | } 36 | for(i=0,p=v; ire-h.im*p->im; 39 | p->im=h.im*p->re+h.re*p->im; p->re=a; 40 | } 41 | } 42 | ortho(g,n); 43 | for(i=m=0,p=u; ire=p->im=0.; 46 | for(k=0,q=g+m,r=v+j; kre+= *q*r->re; p->im+= *q++ *r->im; 48 | } 49 | } 50 | } 51 | free(g); free(v); 52 | } 53 | static void ortho(double *g,int n) 54 | { int i,j,k,m; 55 | double *p,*q,c,s,a; 56 | for(i=0,p=g; i 9 | #include "complex.h" 10 | void utrncm(Cpx *cm,Cpx *a,Cpx *b,int n) 11 | { Cpx z,*q0,*p,*s,*t; 12 | int i,j,k; 13 | q0=(Cpx *)calloc(n,sizeof(Cpx)); 14 | for(i=0; ire*s->re+t->im*s->im; 19 | z.im+=t->im*s->re-t->re*s->im; 20 | } 21 | q0[j]=z; 22 | } 23 | for(j=0,p=cm,t=a; jre*s->re-t->im*s->im; 27 | z.im+=t->im*s->re+t->re*s->im; 28 | } 29 | *p=z; 30 | } 31 | } 32 | free(q0); 33 | } 34 | -------------------------------------------------------------------------------- /src/pydegensac/matutls/utrnhm.c: -------------------------------------------------------------------------------- 1 | /* utrnhm.c CCMATH mathematics library source code. 2 | * 3 | * Copyright (C) 2000 Daniel A. Atkinson All rights reserved. 4 | * This code may be redistributed under the terms of the GNU library 5 | * public license (LGPL). ( See the lgpl.license file for details.) 6 | * ------------------------------------------------------------------------ 7 | */ 8 | #include 9 | #include "complex.h" 10 | void utrnhm(Cpx *hm,Cpx *a,Cpx *b,int n) 11 | { Cpx z,*q0,*p,*s,*t; 12 | int i,j,k; 13 | q0=(Cpx *)calloc(n,sizeof(Cpx)); 14 | for(i=0; ire*s->re+t->im*s->im; 19 | z.im+=t->im*s->re-t->re*s->im; 20 | } 21 | q0[j]=z; 22 | } 23 | for(j=0,p=hm+i,t=a; j<=i ;++j,p+=n){ 24 | z.re=z.im=0.; 25 | for(k=0,s=q0; kre*s->re-t->im*s->im; 27 | z.im+=t->im*s->re+t->re*s->im; 28 | } 29 | *p=z; if(j