├── .github └── workflows │ ├── linux-ci.yml │ └── macos-ci.yml ├── .gitignore ├── CMakeLists.txt ├── DOCS.md ├── LICENSE ├── README.md ├── cmake ├── GtwrapUtils.cmake ├── MatlabWrap.cmake ├── PybindWrap.cmake └── gtwrapConfig.cmake.in ├── docs ├── doc_template.py ├── docs.py └── parser │ ├── doxygen.conf │ ├── parse_doxygen_xml.py │ └── parse_xml.py ├── gtwrap ├── __init__.py ├── interface_parser │ ├── __init__.py │ ├── classes.py │ ├── declaration.py │ ├── enum.py │ ├── function.py │ ├── module.py │ ├── namespace.py │ ├── template.py │ ├── tokens.py │ ├── type.py │ ├── utils.py │ └── variable.py ├── matlab_wrapper │ ├── __init__.py │ ├── mixins.py │ ├── templates.py │ └── wrapper.py ├── pybind_wrapper.py ├── template_instantiator │ ├── __init__.py │ ├── classes.py │ ├── constructor.py │ ├── declaration.py │ ├── function.py │ ├── helpers.py │ ├── method.py │ └── namespace.py └── xml_parser │ ├── __init__.py │ └── xml_parser.py ├── matlab.h ├── pybind11 ├── .appveyor.yml ├── .clang-format ├── .clang-tidy ├── .cmake-format.yaml ├── .codespell-ignore-lines ├── .gitattributes ├── .github │ ├── CODEOWNERS │ ├── CONTRIBUTING.md │ ├── ISSUE_TEMPLATE │ │ ├── bug-report.yml │ │ └── config.yml │ ├── dependabot.yml │ ├── labeler.yml │ ├── labeler_merged.yml │ ├── matchers │ │ └── pylint.json │ ├── pull_request_template.md │ └── workflows │ │ ├── ci.yml │ │ ├── configure.yml │ │ ├── emscripten.yaml │ │ ├── format.yml │ │ ├── labeler.yml │ │ ├── pip.yml │ │ └── upstream.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .readthedocs.yml ├── CMakeLists.txt ├── LICENSE ├── MANIFEST.in ├── README.rst ├── SECURITY.md ├── 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.in │ ├── requirements.txt │ └── upgrade.rst ├── include │ └── pybind11 │ │ ├── attr.h │ │ ├── buffer_info.h │ │ ├── cast.h │ │ ├── chrono.h │ │ ├── common.h │ │ ├── complex.h │ │ ├── detail │ │ ├── class.h │ │ ├── common.h │ │ ├── cpp_conduit.h │ │ ├── descr.h │ │ ├── exception_translation.h │ │ ├── init.h │ │ ├── internals.h │ │ ├── type_caster_base.h │ │ ├── typeid.h │ │ └── value_and_holder.h │ │ ├── eigen.h │ │ ├── eigen │ │ ├── common.h │ │ ├── matrix.h │ │ └── tensor.h │ │ ├── embed.h │ │ ├── eval.h │ │ ├── functional.h │ │ ├── gil.h │ │ ├── gil_safe_call_once.h │ │ ├── iostream.h │ │ ├── numpy.h │ │ ├── operators.h │ │ ├── options.h │ │ ├── pybind11.h │ │ ├── pytypes.h │ │ ├── stl.h │ │ ├── stl │ │ └── filesystem.h │ │ ├── stl_bind.h │ │ ├── type_caster_pyobject_ptr.h │ │ └── typing.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 │ ├── exo_planet_c_api.cpp │ ├── exo_planet_pybind11.cpp │ ├── extra_python_package │ │ ├── pytest.ini │ │ └── test_files.py │ ├── extra_setuptools │ │ ├── pytest.ini │ │ └── test_setuphelper.py │ ├── home_planet_very_lonely_traveler.cpp │ ├── local_bindings.h │ ├── object.h │ ├── pybind11_cross_module_tests.cpp │ ├── pybind11_tests.cpp │ ├── pybind11_tests.h │ ├── pyproject.toml │ ├── 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_cpp_conduit.cpp │ ├── test_cpp_conduit.py │ ├── test_cpp_conduit_traveler_bindings.h │ ├── test_cpp_conduit_traveler_types.h │ ├── 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_python_multiple_inheritance.cpp │ ├── test_python_multiple_inheritance.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_type_caster_pyobject_ptr.cpp │ ├── test_type_caster_pyobject_ptr.py │ ├── test_type_caster_std_function_specializations.cpp │ ├── test_type_caster_std_function_specializations.py │ ├── test_union.cpp │ ├── test_union.py │ ├── test_unnamed_namespace_a.cpp │ ├── test_unnamed_namespace_a.py │ ├── test_unnamed_namespace_b.cpp │ ├── test_unnamed_namespace_b.py │ ├── test_vector_unique_ptr_member.cpp │ ├── test_vector_unique_ptr_member.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 │ ├── pybind11GuessPythonExtSuffix.cmake │ ├── pybind11NewTools.cmake │ ├── pybind11Tools.cmake │ ├── pyproject.toml │ ├── setup_global.py.in │ ├── setup_main.py.in │ └── test-pybind11GuessPythonExtSuffix.cmake ├── requirements.txt ├── scripts ├── matlab_wrap.py └── pybind_wrap.py ├── setup.py ├── sphinx ├── Makefile ├── conf.py ├── index.rst ├── make.bat └── wrap.rst ├── templates ├── matlab_wrapper.tpl.in └── pybind_wrapper.tpl.example ├── tests ├── .gitignore ├── CMakeLists.txt ├── actual │ └── .gitignore ├── expected │ ├── matlab │ │ ├── +Pet │ │ │ └── Kind.m │ │ ├── +gtsam │ │ │ ├── +MCU │ │ │ │ ├── Avengers.m │ │ │ │ └── GotG.m │ │ │ ├── +OptimizerGaussNewtonParams │ │ │ │ └── Verbosity.m │ │ │ ├── Class1.m │ │ │ ├── Class2.m │ │ │ ├── ClassA.m │ │ │ ├── GeneralSFMFactorCal3Bundler.m │ │ │ ├── NonlinearFactorGraph.m │ │ │ ├── PinholeCameraCal3Bundler.m │ │ │ ├── Point2.m │ │ │ ├── Point3.m │ │ │ ├── SfmTrack.m │ │ │ ├── Values.m │ │ │ └── VerbosityLM.m │ │ ├── +ns1 │ │ │ ├── ClassA.m │ │ │ ├── ClassB.m │ │ │ └── aGlobalFunction.m │ │ ├── +ns2 │ │ │ ├── +ns3 │ │ │ │ └── ClassB.m │ │ │ ├── ClassA.m │ │ │ ├── ClassC.m │ │ │ ├── aGlobalFunction.m │ │ │ └── overloadedGlobalFunction.m │ │ ├── ClassD.m │ │ ├── Color.m │ │ ├── DefaultFuncInt.m │ │ ├── DefaultFuncObj.m │ │ ├── DefaultFuncString.m │ │ ├── DefaultFuncVector.m │ │ ├── DefaultFuncZero.m │ │ ├── FastSet.m │ │ ├── ForwardKinematics.m │ │ ├── ForwardKinematicsFactor.m │ │ ├── FunDouble.m │ │ ├── FunRange.m │ │ ├── MultiTemplatedFunctionDoubleSize_tDouble.m │ │ ├── MultiTemplatedFunctionStringSize_tDouble.m │ │ ├── MultipleTemplatesIntDouble.m │ │ ├── MultipleTemplatesIntFloat.m │ │ ├── MyBase.m │ │ ├── MyFactorPosePoint2.m │ │ ├── MyTemplateMatrix.m │ │ ├── MyTemplatePoint2.m │ │ ├── MyVector12.m │ │ ├── MyVector3.m │ │ ├── PrimitiveRefDouble.m │ │ ├── ScopedTemplateResult.m │ │ ├── TemplatedConstructor.m │ │ ├── TemplatedFunctionRot3.m │ │ ├── Test.m │ │ ├── aGlobalFunction.m │ │ ├── class_wrapper.cpp │ │ ├── enum_wrapper.cpp │ │ ├── functions_wrapper.cpp │ │ ├── geometry_wrapper.cpp │ │ ├── inheritance_wrapper.cpp │ │ ├── load2D.m │ │ ├── multiple_files_wrapper.cpp │ │ ├── namespaces_wrapper.cpp │ │ ├── overloadedGlobalFunction.m │ │ ├── setPose.m │ │ ├── special_cases_wrapper.cpp │ │ └── template_wrapper.cpp │ ├── python │ │ ├── class_pybind.cpp │ │ ├── enum_pybind.cpp │ │ ├── functions_pybind.cpp │ │ ├── geometry_pybind.cpp │ │ ├── inheritance_pybind.cpp │ │ ├── namespaces_pybind.cpp │ │ ├── operator_pybind.cpp │ │ ├── special_cases_pybind.cpp │ │ └── templates_pybind.cpp │ └── xml │ │ ├── JacobianFactorQ_8h.xml │ │ ├── NonlinearFactor_8h.xml │ │ ├── classgtsam_1_1JacobianFactorQ.xml │ │ ├── classgtsam_1_1NoiseModelFactor.xml │ │ ├── classgtsam_1_1NoiseModelFactor1.xml │ │ ├── classgtsam_1_1NoiseModelFactor2.xml │ │ ├── classgtsam_1_1NoiseModelFactor3.xml │ │ ├── classgtsam_1_1NoiseModelFactor4.xml │ │ ├── classgtsam_1_1NoiseModelFactor5.xml │ │ ├── classgtsam_1_1NoiseModelFactor6.xml │ │ ├── classgtsam_1_1NonlinearFactor.xml │ │ ├── combine.xslt │ │ ├── compound.xsd │ │ ├── deprecated.xml │ │ ├── dir_59425e443f801f1f2fd8bbe4959a3ccf.xml │ │ ├── dir_e4787312bc569bb879bb1171628269de.xml │ │ ├── index.xml │ │ ├── index.xsd │ │ ├── namespacegtsam.xml │ │ ├── structgtsam_1_1traits_3_01JacobianFactorQ_3_01D_00_01ZDim_01_4_01_4.xml │ │ └── structgtsam_1_1traits_3_01NonlinearFactor_01_4.xml ├── fixtures │ ├── class.i │ ├── enum.i │ ├── functions.i │ ├── geometry.i │ ├── inheritance.i │ ├── namespaces.i │ ├── operator.i │ ├── part1.i │ ├── part2.i │ ├── special_cases.i │ └── templates.i ├── pybind_wrapper.tpl ├── pybind_wrapper_test.cc ├── pybind_wrapper_test.gth ├── pybind_wrapper_test.h ├── pybind_wrapper_test_script.py ├── testDependencies.h ├── testMemory.m ├── test_docs.py ├── test_interface_parser.py ├── test_matlab_wrapper.py ├── test_pybind_wrapper.py └── test_template_instantiator.py └── utilities └── update.sh /.github/workflows/linux-ci.yml: -------------------------------------------------------------------------------- 1 | name: Wrap CI for Linux 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | build: 7 | name: Tests for 🐍 ${{ matrix.python-version }} 8 | runs-on: ubuntu-22.04 9 | 10 | strategy: 11 | fail-fast: false 12 | matrix: 13 | python-version: ["3.9", "3.10", "3.11", "3.12"] 14 | 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v2 18 | 19 | - name: Install Dependencies 20 | run: | 21 | sudo apt-get -y update 22 | sudo apt install cmake build-essential pkg-config libpython3-dev python3-numpy libboost-all-dev 23 | 24 | - name: Set up Python ${{ matrix.python-version }} 25 | uses: actions/setup-python@v2 26 | with: 27 | python-version: ${{ matrix.python-version }} 28 | 29 | - name: Python Dependencies 30 | run: | 31 | sudo pip3 install -U pip setuptools 32 | sudo pip3 install -r requirements.txt 33 | 34 | - name: Build and Test 35 | run: | 36 | cmake . 37 | cd tests 38 | # Use Pytest to run all the tests. 39 | pytest 40 | -------------------------------------------------------------------------------- /.github/workflows/macos-ci.yml: -------------------------------------------------------------------------------- 1 | name: Wrap CI for macOS 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | build: 7 | name: Tests for 🐍 ${{ matrix.python-version }} 8 | runs-on: macos-14 9 | 10 | strategy: 11 | fail-fast: false 12 | matrix: 13 | python-version: ["3.9", "3.10", "3.11", "3.12"] 14 | 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v2 18 | 19 | - name: Install Dependencies 20 | run: | 21 | brew install cmake ninja boost 22 | 23 | - name: Set up Python ${{ matrix.python-version }} 24 | uses: actions/setup-python@v2 25 | with: 26 | python-version: ${{ matrix.python-version }} 27 | 28 | - name: Python Dependencies 29 | run: | 30 | pip3 install -U pip setuptools 31 | pip3 install -r requirements.txt 32 | 33 | - name: Build and Test 34 | run: | 35 | # Build 36 | cmake . 37 | cd tests 38 | # Use Pytest to run all the tests. 39 | pytest 40 | 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | .vscode/ 3 | *build* 4 | *install* 5 | *dist* 6 | *.egg-info 7 | 8 | **/.DS_Store 9 | 10 | # Files related to code coverage stats 11 | **/.coverage 12 | 13 | gtwrap/matlab_wrapper/matlab_wrapper.tpl 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Georgia Tech Research Corporation 2 | Atlanta, Georgia 30332-0415 3 | All Rights Reserved 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | 11 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /cmake/gtwrapConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # This config file modifies CMAKE_MODULE_PATH so that the wrap cmake files may 2 | # be included This file also allows the use of `find_package(gtwrap)` in CMake. 3 | 4 | @PACKAGE_INIT@ 5 | 6 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") 7 | 8 | # Set the path to the Python package directory so we can add it to the PYTHONPATH. 9 | # Used in the *Wrap.cmake files. 10 | set_and_check(GTWRAP_PYTHON_PACKAGE_DIR @PACKAGE_INSTALL_LIB_DIR@) 11 | 12 | # Load all the CMake scripts from the standard location 13 | include(@PACKAGE_INSTALL_CMAKE_DIR@/PybindWrap.cmake) 14 | include(@PACKAGE_INSTALL_CMAKE_DIR@/MatlabWrap.cmake) 15 | include(@PACKAGE_INSTALL_CMAKE_DIR@/GtwrapUtils.cmake) 16 | 17 | # Set the variables for the wrapping scripts to be used in the build. 18 | set_and_check(PYBIND_WRAP_SCRIPT "@PACKAGE_INSTALL_BIN_DIR@/pybind_wrap.py") 19 | set_and_check(MATLAB_WRAP_SCRIPT "@PACKAGE_INSTALL_BIN_DIR@/matlab_wrap.py") 20 | 21 | # Load the pybind11 code from the library installation path 22 | add_subdirectory(@PACKAGE_INSTALL_LIB_DIR@/pybind11 pybind11) 23 | 24 | check_required_components(gtwrap) 25 | -------------------------------------------------------------------------------- /docs/doc_template.py: -------------------------------------------------------------------------------- 1 | import xml.etree.ElementTree as ET 2 | 3 | 4 | class Doc(): 5 | def __init__(self, tree): 6 | self.tree = tree 7 | 8 | def get_tree(self): 9 | """Get this Doc's tree. 10 | 11 | Returns: 12 | The xml.etree.ElementTree object of the documentation. 13 | """ 14 | return self.tree 15 | 16 | def __eq__(self, other): 17 | if other is None or other.get_tree() is None: 18 | return None 19 | 20 | return ET.tostring(self.tree.getroot()) == \ 21 | ET.tostring(other.get_tree().getroot()) 22 | 23 | 24 | class ClassDoc(Doc): 25 | pass 26 | 27 | 28 | class FreeDoc(Doc): 29 | pass 30 | 31 | 32 | class Docs(): 33 | def __init__(self, class_docs, free_docs): 34 | # These are dicts that map file_path -> Doc 35 | self.class_docs = class_docs 36 | self.free_docs = free_docs 37 | 38 | def get_class_docs(self, class_name): 39 | '''Get the documentation for the class. 40 | 41 | Arguments: 42 | class_name -- the name of the class 43 | 44 | Returns: 45 | The ClassDoc with the class's documentation. None if the class does not 46 | exist. 47 | ''' 48 | return self.class_docs.get(class_name) 49 | 50 | def get_free_docs(self, free_func_name): 51 | '''Get the documentation for a free function. 52 | 53 | Arguments: 54 | free_func_name -- the name of the free function 55 | 56 | Returns: 57 | The FreeDoc with the free function's documentation. None if the class 58 | does not exist. 59 | ''' 60 | return self.free_docs.get(free_func_name) 61 | 62 | def get_class_docs_keys_list(self): 63 | return list(self.class_docs) 64 | 65 | def get_free_docs_keys_list(self): 66 | return list(self.free_docs) 67 | 68 | def get_class_docs_values_list(self): 69 | return list(self.class_docs.values()) 70 | 71 | def get_free_docs_values_list(self): 72 | return list(self.free_docs.values()) 73 | -------------------------------------------------------------------------------- /docs/docs.py: -------------------------------------------------------------------------------- 1 | import xml.etree.ElementTree as ET 2 | 3 | 4 | class Doc(): 5 | def __init__(self, tree): 6 | self.tree = tree 7 | 8 | def get_tree(self): 9 | """Get this Doc's tree. 10 | 11 | Returns: 12 | The xml.etree.ElementTree object of the documentation. 13 | """ 14 | return self.tree 15 | 16 | def __eq__(self, other): 17 | if other is None or other.get_tree() is None: 18 | return None 19 | 20 | return ET.tostring(self.tree.getroot()) == \ 21 | ET.tostring(other.get_tree().getroot()) 22 | 23 | 24 | class ClassDoc(Doc): 25 | pass 26 | 27 | 28 | class FreeDoc(Doc): 29 | pass 30 | 31 | 32 | class Docs(): 33 | def __init__(self, class_docs, free_docs): 34 | # These are dicts that map file_path -> Doc 35 | self.class_docs = class_docs 36 | self.free_docs = free_docs 37 | 38 | def get_class_docs(self, class_name): 39 | '''Get the documentation for the class. 40 | 41 | Arguments: 42 | class_name -- the name of the class 43 | 44 | Returns: 45 | The ClassDoc with the class's documentation. None if the class does not 46 | exist. 47 | ''' 48 | return self.class_docs.get(class_name) 49 | 50 | def get_free_docs(self, free_func_name): 51 | '''Get the documentation for a free function. 52 | 53 | Arguments: 54 | free_func_name -- the name of the free function 55 | 56 | Returns: 57 | The FreeDoc with the free function's documentation. None if the class 58 | does not exist. 59 | ''' 60 | return self.free_docs.get(free_func_name) 61 | 62 | def get_class_docs_keys_list(self): 63 | return list(self.class_docs) 64 | 65 | def get_free_docs_keys_list(self): 66 | return list(self.free_docs) 67 | 68 | def get_class_docs_values_list(self): 69 | return list(self.class_docs.values()) 70 | 71 | def get_free_docs_values_list(self): 72 | return list(self.free_docs.values()) 73 | -------------------------------------------------------------------------------- /gtwrap/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/borglab/wrap/66087700e50917f96a7ba89a02c45edb7b7c04b3/gtwrap/__init__.py -------------------------------------------------------------------------------- /gtwrap/interface_parser/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | GTSAM Copyright 2010-2020, Georgia Tech Research Corporation, 3 | Atlanta, Georgia 30332-0415 4 | All Rights Reserved 5 | 6 | See LICENSE for the license information 7 | 8 | Parser to get the interface of a C++ source file 9 | 10 | Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert 11 | """ 12 | 13 | import sys 14 | 15 | import pyparsing # type: ignore 16 | 17 | from .classes import * 18 | from .declaration import * 19 | from .enum import * 20 | from .function import * 21 | from .module import * 22 | from .namespace import * 23 | from .template import * 24 | from .tokens import * 25 | from .type import * 26 | 27 | # Fix deepcopy issue with pyparsing 28 | # Can remove once https://github.com/pyparsing/pyparsing/issues/208 is resolved. 29 | if sys.version_info >= (3, 8): 30 | 31 | def fixed_get_attr(self, item): 32 | """ 33 | Fix for monkey-patching issue with deepcopy in pyparsing.ParseResults 34 | """ 35 | if item == '__deepcopy__': 36 | raise AttributeError(item) 37 | try: 38 | return self[item] 39 | except KeyError: 40 | return "" 41 | 42 | # apply the monkey-patch 43 | pyparsing.ParseResults.__getattr__ = fixed_get_attr 44 | 45 | pyparsing.ParserElement.enablePackrat() 46 | -------------------------------------------------------------------------------- /gtwrap/interface_parser/declaration.py: -------------------------------------------------------------------------------- 1 | """ 2 | GTSAM Copyright 2010-2020, Georgia Tech Research Corporation, 3 | Atlanta, Georgia 30332-0415 4 | All Rights Reserved 5 | 6 | See LICENSE for the license information 7 | 8 | Classes and rules for declarations such as includes and forward declarations. 9 | 10 | Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert 11 | """ 12 | 13 | from pyparsing import CharsNotIn, Optional # type: ignore 14 | 15 | from .tokens import (CLASS, COLON, INCLUDE, LOPBRACK, ROPBRACK, SEMI_COLON, 16 | VIRTUAL) 17 | from .type import Typename 18 | from .utils import collect_namespaces 19 | 20 | 21 | class Include: 22 | """ 23 | Rule to parse #include directives. 24 | """ 25 | rule = (INCLUDE + LOPBRACK + CharsNotIn('>')("header") + 26 | ROPBRACK).setParseAction(lambda t: Include(t.header)) 27 | 28 | def __init__(self, header: CharsNotIn, parent: str = ''): 29 | self.header = header 30 | self.parent = parent 31 | 32 | def __repr__(self) -> str: 33 | return "#include <{}>".format(self.header) 34 | 35 | 36 | class ForwardDeclaration: 37 | """ 38 | Rule to parse forward declarations in the interface file. 39 | """ 40 | rule = (Optional(VIRTUAL("is_virtual")) + CLASS + Typename.rule("name") + 41 | Optional(COLON + Typename.rule("parent_type")) + 42 | SEMI_COLON).setParseAction(lambda t: ForwardDeclaration( 43 | t.name, t.parent_type, t.is_virtual)) 44 | 45 | def __init__(self, 46 | typename: Typename, 47 | parent_type: str, 48 | is_virtual: str, 49 | parent: str = ''): 50 | self.name = typename.name 51 | self.typename = typename 52 | if parent_type: 53 | self.parent_type = parent_type 54 | else: 55 | self.parent_type = '' 56 | 57 | self.is_virtual = is_virtual 58 | self.parent = parent 59 | 60 | def namespaces(self) -> list: 61 | """Get the namespaces which this class is nested under as a list.""" 62 | return collect_namespaces(self) 63 | 64 | def __repr__(self) -> str: 65 | return "ForwardDeclaration: {} {}".format(self.is_virtual, self.name) 66 | -------------------------------------------------------------------------------- /gtwrap/interface_parser/enum.py: -------------------------------------------------------------------------------- 1 | """ 2 | GTSAM Copyright 2010-2020, Georgia Tech Research Corporation, 3 | Atlanta, Georgia 30332-0415 4 | All Rights Reserved 5 | 6 | See LICENSE for the license information 7 | 8 | Parser class and rules for parsing C++ enums. 9 | 10 | Author: Varun Agrawal 11 | """ 12 | 13 | from pyparsing import delimitedList # type: ignore 14 | 15 | from .tokens import ENUM, IDENT, LBRACE, RBRACE, SEMI_COLON 16 | from .type import Typename 17 | from .utils import collect_namespaces 18 | 19 | 20 | class Enumerator: 21 | """ 22 | Rule to parse an enumerator inside an enum. 23 | """ 24 | rule = ( 25 | IDENT("enumerator")).setParseAction(lambda t: Enumerator(t.enumerator)) 26 | 27 | def __init__(self, name): 28 | self.name = name 29 | 30 | def __repr__(self): 31 | return "Enumerator: ({0})".format(self.name) 32 | 33 | 34 | class Enum: 35 | """ 36 | Rule to parse enums defined in the interface file. 37 | 38 | E.g. 39 | ``` 40 | enum Kind { 41 | Dog, 42 | Cat 43 | }; 44 | ``` 45 | """ 46 | 47 | rule = (ENUM + IDENT("name") + LBRACE + 48 | delimitedList(Enumerator.rule)("enumerators") + RBRACE + 49 | SEMI_COLON).setParseAction(lambda t: Enum(t.name, t.enumerators)) 50 | 51 | def __init__(self, name, enumerators, parent=''): 52 | self.name = name 53 | self.enumerators = enumerators 54 | self.parent = parent 55 | 56 | def namespaces(self) -> list: 57 | """Get the namespaces which this class is nested under as a list.""" 58 | return collect_namespaces(self) 59 | 60 | def cpp_typename(self): 61 | """ 62 | Return a Typename with the namespaces and cpp name of this 63 | class. 64 | """ 65 | namespaces_name = self.namespaces() 66 | namespaces_name.append(self.name) 67 | return Typename(namespaces_name) 68 | 69 | def __repr__(self): 70 | return "Enum: {0}".format(self.name) 71 | -------------------------------------------------------------------------------- /gtwrap/interface_parser/module.py: -------------------------------------------------------------------------------- 1 | """ 2 | GTSAM Copyright 2010-2020, Georgia Tech Research Corporation, 3 | Atlanta, Georgia 30332-0415 4 | All Rights Reserved 5 | 6 | See LICENSE for the license information 7 | 8 | Rules and classes for parsing a module. 9 | 10 | Author: Duy Nguyen Ta, Fan Jiang, Matthew Sklar, Varun Agrawal, and Frank Dellaert 11 | """ 12 | 13 | # pylint: disable=unnecessary-lambda, unused-import, expression-not-assigned, no-else-return, protected-access, too-few-public-methods, too-many-arguments 14 | 15 | from pyparsing import (ParseResults, ZeroOrMore, # type: ignore 16 | cppStyleComment, stringEnd) 17 | 18 | from .classes import Class 19 | from .declaration import ForwardDeclaration, Include 20 | from .enum import Enum 21 | from .function import GlobalFunction 22 | from .namespace import Namespace 23 | from .template import TypedefTemplateInstantiation 24 | from .variable import Variable 25 | 26 | 27 | class Module: 28 | """ 29 | Module is just a global namespace. 30 | 31 | E.g. 32 | ``` 33 | namespace gtsam { 34 | ... 35 | } 36 | ``` 37 | """ 38 | 39 | rule = ( 40 | ZeroOrMore(ForwardDeclaration.rule # 41 | ^ Include.rule # 42 | ^ Class.rule # 43 | ^ TypedefTemplateInstantiation.rule # 44 | ^ GlobalFunction.rule # 45 | ^ Enum.rule # 46 | ^ Variable.rule # 47 | ^ Namespace.rule # 48 | ).setParseAction(lambda t: Namespace('', t.asList())) + 49 | stringEnd) 50 | 51 | rule.ignore(cppStyleComment) 52 | 53 | @staticmethod 54 | def parseString(s: str) -> ParseResults: 55 | """Parse the source string and apply the rules.""" 56 | return Module.rule.parseString(s)[0] 57 | -------------------------------------------------------------------------------- /gtwrap/interface_parser/utils.py: -------------------------------------------------------------------------------- 1 | """ 2 | GTSAM Copyright 2010-2020, Georgia Tech Research Corporation, 3 | Atlanta, Georgia 30332-0415 4 | All Rights Reserved 5 | 6 | See LICENSE for the license information 7 | 8 | Various common utilities. 9 | 10 | Author: Varun Agrawal 11 | """ 12 | 13 | 14 | def collect_namespaces(obj): 15 | """ 16 | Get the chain of namespaces from the lowest to highest for the given object. 17 | 18 | Args: 19 | obj: Object of type Namespace, Class, InstantiatedClass, or Enum. 20 | """ 21 | namespaces = [] 22 | ancestor = obj.parent 23 | while ancestor and ancestor.name: 24 | namespaces = [ancestor.name] + namespaces 25 | ancestor = ancestor.parent 26 | return [''] + namespaces 27 | -------------------------------------------------------------------------------- /gtwrap/interface_parser/variable.py: -------------------------------------------------------------------------------- 1 | """ 2 | GTSAM Copyright 2010-2020, Georgia Tech Research Corporation, 3 | Atlanta, Georgia 30332-0415 4 | All Rights Reserved 5 | 6 | See LICENSE for the license information 7 | 8 | Parser classes and rules for parsing C++ variables. 9 | 10 | Author: Varun Agrawal, Gerry Chen 11 | """ 12 | 13 | from typing import List 14 | 15 | from pyparsing import Optional, ParseResults # type: ignore 16 | 17 | from .tokens import DEFAULT_ARG, EQUAL, IDENT, SEMI_COLON 18 | from .type import TemplatedType, Type 19 | 20 | 21 | class Variable: 22 | """ 23 | Rule to parse variables. 24 | Variables are a combination of Type/TemplatedType and the variable identifier. 25 | 26 | E.g. 27 | ``` 28 | class Hello { 29 | string name; // This is a property variable. 30 | }; 31 | 32 | Vector3 kGravity; // This is a global variable. 33 | ```` 34 | """ 35 | rule = ((Type.rule ^ TemplatedType.rule)("ctype") # 36 | + IDENT("name") # 37 | + Optional(EQUAL + DEFAULT_ARG)("default") # 38 | + SEMI_COLON # 39 | ).setParseAction(lambda t: Variable( 40 | t.ctype, # 41 | t.name, # 42 | t.default[0] if isinstance(t.default, ParseResults) else None)) 43 | 44 | def __init__(self, 45 | ctype: List[Type], 46 | name: str, 47 | default: ParseResults = None, 48 | parent=''): 49 | self.ctype = ctype[0] # ParseResult is a list 50 | self.name = name 51 | self.default = default 52 | self.parent = parent 53 | 54 | def __repr__(self) -> str: 55 | return '{} {}'.format(self.ctype.__repr__(), self.name) 56 | -------------------------------------------------------------------------------- /gtwrap/matlab_wrapper/__init__.py: -------------------------------------------------------------------------------- 1 | """Package to wrap C++ code to Matlab via MEX.""" 2 | 3 | from .wrapper import MatlabWrapper 4 | -------------------------------------------------------------------------------- /gtwrap/template_instantiator/__init__.py: -------------------------------------------------------------------------------- 1 | """Code to help instantiate templated classes, methods and functions.""" 2 | 3 | # pylint: disable=too-many-arguments, too-many-instance-attributes, no-self-use, no-else-return, too-many-arguments, unused-format-string-argument, unused-variable. unused-argument, too-many-branches 4 | 5 | from typing import Iterable, Sequence, Union 6 | 7 | import gtwrap.interface_parser as parser 8 | from gtwrap.template_instantiator.classes import * 9 | from gtwrap.template_instantiator.constructor import * 10 | from gtwrap.template_instantiator.declaration import * 11 | from gtwrap.template_instantiator.function import * 12 | from gtwrap.template_instantiator.helpers import * 13 | from gtwrap.template_instantiator.method import * 14 | from gtwrap.template_instantiator.namespace import * 15 | -------------------------------------------------------------------------------- /gtwrap/template_instantiator/constructor.py: -------------------------------------------------------------------------------- 1 | """Class constructor instantiator.""" 2 | 3 | # pylint: disable=unused-argument 4 | 5 | from typing import Iterable, List 6 | 7 | import gtwrap.interface_parser as parser 8 | 9 | 10 | class InstantiatedConstructor(parser.Constructor): 11 | """ 12 | Instantiate constructor with template parameters. 13 | 14 | E.g. 15 | class A { 16 | template 17 | A(X x, Y y); 18 | } 19 | """ 20 | def __init__(self, 21 | original: parser.Constructor, 22 | instantiations: Iterable[parser.Typename] = ()): 23 | self.original = original 24 | self.instantiations = instantiations 25 | self.name = original.name 26 | self.args = original.args 27 | self.template = original.template 28 | self.parent = original.parent 29 | 30 | super().__init__(self.name, 31 | self.args, 32 | self.template, 33 | parent=self.parent) 34 | 35 | @classmethod 36 | def construct(cls, original: parser.Constructor, typenames: List[str], 37 | class_instantiations: List[parser.Typename], 38 | method_instantiations: List[parser.Typename], 39 | instantiated_args: List[parser.Argument], 40 | parent: 'InstantiatedClass'): 41 | """Class method to construct object as required by InstantiationHelper.""" 42 | method = parser.Constructor( 43 | name=parent.name, 44 | args=parser.ArgumentList(instantiated_args), 45 | template=original.template, 46 | parent=parent, 47 | ) 48 | return InstantiatedConstructor(method, 49 | instantiations=method_instantiations) 50 | 51 | def to_cpp(self): 52 | """Generate the C++ code for wrapping.""" 53 | if self.original.template: 54 | # to_cpp will handle all the namespacing and templating 55 | instantiation_list = [x.to_cpp() for x in self.instantiations] 56 | # now can simply combine the instantiations, separated by commas 57 | ret = "{}<{}>".format(self.original.name, 58 | ",".join(instantiation_list)) 59 | else: 60 | ret = self.original.name 61 | return ret 62 | 63 | def __repr__(self): 64 | return "Instantiated {}".format(super().__repr__()) 65 | -------------------------------------------------------------------------------- /gtwrap/template_instantiator/declaration.py: -------------------------------------------------------------------------------- 1 | """Instantiate a forward declaration.""" 2 | 3 | import gtwrap.interface_parser as parser 4 | from gtwrap.template_instantiator.helpers import instantiate_name 5 | 6 | 7 | class InstantiatedDeclaration(parser.ForwardDeclaration): 8 | """ 9 | Instantiate typedefs of forward declarations. 10 | This is useful when we wish to typedef a templated class 11 | which is not defined in the current project. 12 | 13 | E.g. 14 | class FactorFromAnotherMother; 15 | 16 | typedef FactorFromAnotherMother FactorWeCanUse; 17 | """ 18 | def __init__(self, original, instantiations=(), new_name=''): 19 | super().__init__(original.typename, 20 | original.parent_type, 21 | original.is_virtual, 22 | parent=original.parent) 23 | 24 | self.original = original 25 | self.instantiations = instantiations 26 | self.parent = original.parent 27 | 28 | self.name = instantiate_name( 29 | original.name, instantiations) if not new_name else new_name 30 | 31 | def to_cpp(self): 32 | """Generate the C++ code for wrapping.""" 33 | instantiated_names = [ 34 | inst.qualified_name() for inst in self.instantiations 35 | ] 36 | name = "{}<{}>".format(self.original.name, 37 | ",".join(instantiated_names)) 38 | namespaces_name = self.namespaces() 39 | namespaces_name.append(name) 40 | # Leverage Typename to generate the fully qualified C++ name 41 | return parser.Typename(namespaces_name).to_cpp() 42 | 43 | def __repr__(self): 44 | return "Instantiated {}".format( 45 | super(InstantiatedDeclaration, self).__repr__()) 46 | -------------------------------------------------------------------------------- /gtwrap/xml_parser/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/borglab/wrap/66087700e50917f96a7ba89a02c45edb7b7c04b3/gtwrap/xml_parser/__init__.py -------------------------------------------------------------------------------- /pybind11/.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | image: 3 | - Visual Studio 2017 4 | test: off 5 | skip_branch_with_pr: true 6 | build: 7 | parallel: true 8 | platform: 9 | - x86 10 | environment: 11 | matrix: 12 | - PYTHON: 38 13 | CONFIG: Debug 14 | install: 15 | - ps: | 16 | $env:CMAKE_GENERATOR = "Visual Studio 15 2017" 17 | if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" } 18 | $env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH" 19 | python -W ignore -m pip install --upgrade pip wheel 20 | python -W ignore -m pip install pytest numpy --no-warn-script-location pytest-timeout 21 | - ps: | 22 | Start-FileDownload 'https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip' 23 | 7z x eigen-3.3.7.zip -y > $null 24 | $env:CMAKE_INCLUDE_PATH = "eigen-3.3.7;$env:CMAKE_INCLUDE_PATH" 25 | build_script: 26 | - cmake -G "%CMAKE_GENERATOR%" -A "%CMAKE_ARCH%" 27 | -DCMAKE_CXX_STANDARD=14 28 | -DPYBIND11_WERROR=ON 29 | -DDOWNLOAD_CATCH=ON 30 | -DCMAKE_SUPPRESS_REGENERATION=1 31 | . 32 | - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" 33 | - cmake --build . --config %CONFIG% --target pytest -- /m /v:m /logger:%MSBuildLogger% 34 | - cmake --build . --config %CONFIG% --target cpptest -- /m /v:m /logger:%MSBuildLogger% 35 | on_failure: if exist "tests\test_cmake_build" type tests\test_cmake_build\*.log* 36 | -------------------------------------------------------------------------------- /pybind11/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | # See all possible options and defaults with: 3 | # clang-format --style=llvm --dump-config 4 | BasedOnStyle: LLVM 5 | AccessModifierOffset: -4 6 | AllowShortLambdasOnASingleLine: true 7 | AlwaysBreakTemplateDeclarations: Yes 8 | BinPackArguments: false 9 | BinPackParameters: false 10 | BreakBeforeBinaryOperators: All 11 | BreakConstructorInitializers: BeforeColon 12 | ColumnLimit: 99 13 | CommentPragmas: 'NOLINT:.*|^ IWYU pragma:' 14 | IncludeBlocks: Regroup 15 | IndentCaseLabels: true 16 | IndentPPDirectives: AfterHash 17 | IndentWidth: 4 18 | Language: Cpp 19 | SpaceAfterCStyleCast: true 20 | Standard: Cpp11 21 | StatementMacros: ['PyObject_HEAD'] 22 | TabWidth: 4 23 | IncludeCategories: 24 | - Regex: '' 35 | Priority: 4 36 | - Regex: '.*' 37 | Priority: 5 38 | ... 39 | -------------------------------------------------------------------------------- /pybind11/.cmake-format.yaml: -------------------------------------------------------------------------------- 1 | parse: 2 | additional_commands: 3 | pybind11_add_module: 4 | flags: 5 | - THIN_LTO 6 | - MODULE 7 | - SHARED 8 | - NO_EXTRAS 9 | - EXCLUDE_FROM_ALL 10 | - SYSTEM 11 | 12 | format: 13 | line_width: 99 14 | tab_size: 2 15 | 16 | # If an argument group contains more than this many sub-groups 17 | # (parg or kwarg groups) then force it to a vertical layout. 18 | max_subgroups_hwrap: 2 19 | 20 | # If a positional argument group contains more than this many 21 | # arguments, then force it to a vertical layout. 22 | max_pargs_hwrap: 6 23 | 24 | # If a cmdline positional group consumes more than this many 25 | # lines without nesting, then invalidate the layout (and nest) 26 | max_rows_cmdline: 2 27 | separate_ctrl_name_with_space: false 28 | separate_fn_name_with_space: false 29 | dangle_parens: false 30 | 31 | # If the trailing parenthesis must be 'dangled' on its on 32 | # 'line, then align it to this reference: `prefix`: the start' 33 | # 'of the statement, `prefix-indent`: the start of the' 34 | # 'statement, plus one indentation level, `child`: align to' 35 | # the column of the arguments 36 | dangle_align: prefix 37 | # If the statement spelling length (including space and 38 | # parenthesis) is smaller than this amount, then force reject 39 | # nested layouts. 40 | min_prefix_chars: 4 41 | 42 | # If the statement spelling length (including space and 43 | # parenthesis) is larger than the tab width by more than this 44 | # amount, then force reject un-nested layouts. 45 | max_prefix_chars: 10 46 | 47 | # If a candidate layout is wrapped horizontally but it exceeds 48 | # this many lines, then reject the layout. 49 | max_lines_hwrap: 2 50 | 51 | line_ending: unix 52 | 53 | # Format command names consistently as 'lower' or 'upper' case 54 | command_case: canonical 55 | 56 | # Format keywords consistently as 'lower' or 'upper' case 57 | # unchanged is valid too 58 | keyword_case: 'upper' 59 | 60 | # A list of command names which should always be wrapped 61 | always_wrap: [] 62 | 63 | # If true, the argument lists which are known to be sortable 64 | # will be sorted lexicographically 65 | enable_sort: true 66 | 67 | # If true, the parsers may infer whether or not an argument 68 | # list is sortable (without annotation). 69 | autosort: false 70 | 71 | # Causes a few issues - can be solved later, possibly. 72 | markup: 73 | enable_markup: false 74 | -------------------------------------------------------------------------------- /pybind11/.codespell-ignore-lines: -------------------------------------------------------------------------------- 1 | template 2 | template 3 | auto &this_ = static_cast(*this); 4 | if (load_impl(temp, false)) { 5 | ssize_t nd = 0; 6 | auto trivial = broadcast(buffers, nd, shape); 7 | auto ndim = (size_t) nd; 8 | int nd; 9 | ssize_t ndim() const { return detail::array_proxy(m_ptr)->nd; } 10 | using op = op_impl; 11 | template 12 | template 13 | class_ &def(const detail::op_ &op, const Extra &...extra) { 14 | class_ &def_cast(const detail::op_ &op, const Extra &...extra) { 15 | @pytest.mark.parametrize("access", ["ro", "rw", "static_ro", "static_rw"]) 16 | struct IntStruct { 17 | explicit IntStruct(int v) : value(v){}; 18 | ~IntStruct() { value = -value; } 19 | IntStruct(const IntStruct &) = default; 20 | IntStruct &operator=(const IntStruct &) = default; 21 | py::class_(m, "IntStruct").def(py::init([](const int i) { return IntStruct(i); })); 22 | py::implicitly_convertible(); 23 | m.def("test", [](int expected, const IntStruct &in) { 24 | [](int expected, const IntStruct &in) { 25 | -------------------------------------------------------------------------------- /pybind11/.gitattributes: -------------------------------------------------------------------------------- 1 | docs/*.svg binary 2 | -------------------------------------------------------------------------------- /pybind11/.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | *.cmake @henryiii 2 | CMakeLists.txt @henryiii 3 | *.yml @henryiii 4 | *.yaml @henryiii 5 | /tools/ @henryiii 6 | /pybind11/ @henryiii 7 | noxfile.py @henryiii 8 | .clang-format @henryiii 9 | .clang-tidy @henryiii 10 | -------------------------------------------------------------------------------- /pybind11/.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Ask a question 4 | url: https://github.com/pybind/pybind11/discussions/new 5 | about: Please ask and answer questions here, or propose new ideas. 6 | - name: Gitter room 7 | url: https://gitter.im/pybind/Lobby 8 | about: A room for discussing pybind11 with an active community 9 | -------------------------------------------------------------------------------- /pybind11/.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | # Maintain dependencies for GitHub Actions 4 | - package-ecosystem: "github-actions" 5 | directory: "/" 6 | schedule: 7 | interval: "weekly" 8 | groups: 9 | actions: 10 | patterns: 11 | - "*" 12 | ignore: 13 | - dependency-name: actions/checkout 14 | versions: 15 | - "<5" 16 | -------------------------------------------------------------------------------- /pybind11/.github/labeler.yml: -------------------------------------------------------------------------------- 1 | docs: 2 | all: 3 | - changed-files: 4 | - all-globs-to-all-files: 5 | - '!docs/changelog.rst' 6 | - '!docs/upgrade.rst' 7 | - base-branch: "^(?!dependabot).*" 8 | - base-branch: "^(?!pre-commit-ci).*" 9 | 10 | ci: 11 | - changed-files: 12 | - any-glob-to-any-file: 13 | - '.github/workflows/*.yml' 14 | -------------------------------------------------------------------------------- /pybind11/.github/labeler_merged.yml: -------------------------------------------------------------------------------- 1 | # Add 'needs changelog` label to any change to code files as long as the `CHANGELOG` hasn't changed 2 | # Skip dependabot and pre-commit-ci PRs 3 | needs changelog: 4 | - all: 5 | - changed-files: 6 | - all-globs-to-all-files: "!docs/changelog.rst" 7 | - base-branch: "^(?!dependabot).*" 8 | - base-branch: "^(?!pre-commit-ci).*" 9 | -------------------------------------------------------------------------------- /pybind11/.github/matchers/pylint.json: -------------------------------------------------------------------------------- 1 | { 2 | "problemMatcher": [ 3 | { 4 | "severity": "warning", 5 | "pattern": [ 6 | { 7 | "regexp": "^([^:]+):(\\d+):(\\d+): ([A-DF-Z]\\d+): \\033\\[[\\d;]+m([^\\033]+).*$", 8 | "file": 1, 9 | "line": 2, 10 | "column": 3, 11 | "code": 4, 12 | "message": 5 13 | } 14 | ], 15 | "owner": "pylint-warning" 16 | }, 17 | { 18 | "severity": "error", 19 | "pattern": [ 20 | { 21 | "regexp": "^([^:]+):(\\d+):(\\d+): (E\\d+): \\033\\[[\\d;]+m([^\\033]+).*$", 22 | "file": 1, 23 | "line": 2, 24 | "column": 3, 25 | "code": 4, 26 | "message": 5 27 | } 28 | ], 29 | "owner": "pylint-error" 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /pybind11/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 5 | ## Description 6 | 7 | 8 | 9 | 10 | ## Suggested changelog entry: 11 | 12 | 14 | 15 | ```rst 16 | 17 | ``` 18 | 19 | 20 | -------------------------------------------------------------------------------- /pybind11/.github/workflows/emscripten.yaml: -------------------------------------------------------------------------------- 1 | name: WASM 2 | 3 | on: 4 | workflow_dispatch: 5 | pull_request: 6 | branches: 7 | - master 8 | - stable 9 | - v* 10 | 11 | concurrency: 12 | group: ${{ github.workflow }}-${{ github.ref }} 13 | cancel-in-progress: true 14 | 15 | jobs: 16 | build-wasm-emscripten: 17 | name: Pyodide wheel 18 | runs-on: ubuntu-22.04 19 | steps: 20 | - uses: actions/checkout@v4 21 | with: 22 | submodules: true 23 | fetch-depth: 0 24 | 25 | - uses: pypa/cibuildwheel@v2.20 26 | env: 27 | PYODIDE_BUILD_EXPORTS: whole_archive 28 | with: 29 | package-dir: tests 30 | only: cp312-pyodide_wasm32 31 | -------------------------------------------------------------------------------- /pybind11/.github/workflows/format.yml: -------------------------------------------------------------------------------- 1 | # This is a format job. Pre-commit has a first-party GitHub action, so we use 2 | # that: https://github.com/pre-commit/action 3 | 4 | name: Format 5 | 6 | on: 7 | workflow_dispatch: 8 | pull_request: 9 | push: 10 | branches: 11 | - master 12 | - stable 13 | - "v*" 14 | 15 | permissions: 16 | contents: read 17 | 18 | env: 19 | FORCE_COLOR: 3 20 | # For cmake: 21 | VERBOSE: 1 22 | 23 | jobs: 24 | pre-commit: 25 | name: Format 26 | runs-on: ubuntu-latest 27 | steps: 28 | - uses: actions/checkout@v4 29 | - uses: actions/setup-python@v5 30 | with: 31 | python-version: "3.x" 32 | - name: Add matchers 33 | run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json" 34 | - uses: pre-commit/action@v3.0.1 35 | with: 36 | # Slow hooks are marked with manual - slow is okay here, run them too 37 | extra_args: --hook-stage manual --all-files 38 | 39 | clang-tidy: 40 | # When making changes here, please also review the "Clang-Tidy" section 41 | # in .github/CONTRIBUTING.md and update as needed. 42 | name: Clang-Tidy 43 | runs-on: ubuntu-latest 44 | container: silkeh/clang:18-bookworm 45 | steps: 46 | - uses: actions/checkout@v4 47 | 48 | - name: Install requirements 49 | run: apt-get update && apt-get install -y git python3-dev python3-pytest 50 | 51 | - name: Configure 52 | run: > 53 | cmake -S . -B build 54 | -DCMAKE_CXX_CLANG_TIDY="$(which clang-tidy);--use-color;--warnings-as-errors=*" 55 | -DDOWNLOAD_EIGEN=ON 56 | -DDOWNLOAD_CATCH=ON 57 | -DCMAKE_CXX_STANDARD=17 58 | 59 | - name: Build 60 | run: cmake --build build -j 2 -- --keep-going 61 | -------------------------------------------------------------------------------- /pybind11/.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | name: Labeler 2 | on: 3 | pull_request_target: 4 | types: [closed] 5 | 6 | permissions: {} 7 | 8 | jobs: 9 | label: 10 | name: Labeler 11 | runs-on: ubuntu-latest 12 | permissions: 13 | contents: read 14 | pull-requests: write 15 | steps: 16 | 17 | - uses: actions/labeler@v5 18 | if: > 19 | github.event.pull_request.merged == true && 20 | !startsWith(github.event.pull_request.title, 'chore(deps):') && 21 | !startsWith(github.event.pull_request.title, 'ci(fix):') && 22 | !startsWith(github.event.pull_request.title, 'docs(changelog):') 23 | with: 24 | repo-token: ${{ secrets.GITHUB_TOKEN }} 25 | configuration-path: .github/labeler_merged.yml 26 | -------------------------------------------------------------------------------- /pybind11/.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | Makefile 4 | cmake_install.cmake 5 | cmake_uninstall.cmake 6 | .DS_Store 7 | *.so 8 | *.pyd 9 | *.dll 10 | *.sln 11 | *.sdf 12 | *.opensdf 13 | *.vcxproj 14 | *.vcxproj.user 15 | *.filters 16 | example.dir 17 | Win32 18 | x64 19 | Release 20 | Debug 21 | .vs 22 | CTestTestfile.cmake 23 | Testing 24 | autogen 25 | MANIFEST 26 | /.ninja_* 27 | /*.ninja 28 | /docs/.build 29 | *.py[co] 30 | *.egg-info 31 | *~ 32 | .*.swp 33 | .DS_Store 34 | /dist 35 | /*build* 36 | .cache/ 37 | sosize-*.txt 38 | pybind11Config*.cmake 39 | pybind11Targets.cmake 40 | /*env* 41 | /.vscode 42 | /pybind11/include/* 43 | /pybind11/share/* 44 | /docs/_build/* 45 | .ipynb_checkpoints/ 46 | tests/main.cpp 47 | -------------------------------------------------------------------------------- /pybind11/.readthedocs.yml: -------------------------------------------------------------------------------- 1 | # https://blog.readthedocs.com/migrate-configuration-v2/ 2 | 3 | version: 2 4 | 5 | build: 6 | os: ubuntu-22.04 7 | apt_packages: 8 | - librsvg2-bin 9 | tools: 10 | python: "3.11" 11 | 12 | sphinx: 13 | configuration: docs/conf.py 14 | 15 | python: 16 | install: 17 | - requirements: docs/requirements.txt 18 | 19 | formats: 20 | - pdf 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 SECURITY.md pyproject.toml setup.py setup.cfg 7 | -------------------------------------------------------------------------------- /pybind11/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Security updates are applied only to the latest release. 6 | 7 | ## Reporting a Vulnerability 8 | 9 | If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released. 10 | 11 | Please disclose it at [security advisory](https://github.com/pybind/pybind11/security/advisories/new). 12 | 13 | This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure. 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pybind11/docs/_static/css/custom.css: -------------------------------------------------------------------------------- 1 | .highlight .go { 2 | color: #707070; 3 | } 4 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pybind11/docs/pybind11-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/borglab/wrap/66087700e50917f96a7ba89a02c45edb7b7c04b3/pybind11/docs/pybind11-logo.png -------------------------------------------------------------------------------- /pybind11/docs/pybind11_vs_boost_python1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/borglab/wrap/66087700e50917f96a7ba89a02c45edb7b7c04b3/pybind11/docs/pybind11_vs_boost_python1.png -------------------------------------------------------------------------------- /pybind11/docs/pybind11_vs_boost_python2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/borglab/wrap/66087700e50917f96a7ba89a02c45edb7b7c04b3/pybind11/docs/pybind11_vs_boost_python2.png -------------------------------------------------------------------------------- /pybind11/docs/requirements.in: -------------------------------------------------------------------------------- 1 | breathe 2 | furo 3 | sphinx 4 | sphinx-copybutton 5 | sphinxcontrib-moderncmakedomain 6 | sphinxcontrib-svg2pdfconverter 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pybind11/include/pybind11/eigen/common.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 The pybind Community. 2 | 3 | #pragma once 4 | 5 | // Common message for `static_assert()`s, which are useful to easily 6 | // preempt much less obvious errors. 7 | #define PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED \ 8 | "Pointer types (in particular `PyObject *`) are not supported as scalar types for Eigen " \ 9 | "types." 10 | -------------------------------------------------------------------------------- /pybind11/include/pybind11/type_caster_pyobject_ptr.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 The pybind Community. 2 | 3 | #pragma once 4 | 5 | #include "detail/common.h" 6 | #include "detail/descr.h" 7 | #include "cast.h" 8 | #include "pytypes.h" 9 | 10 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 11 | PYBIND11_NAMESPACE_BEGIN(detail) 12 | 13 | template <> 14 | class type_caster { 15 | public: 16 | static constexpr auto name = const_name("object"); // See discussion under PR #4601. 17 | 18 | // This overload is purely to guard against accidents. 19 | template ::value, int> = 0> 21 | static handle cast(T &&, return_value_policy, handle /*parent*/) { 22 | static_assert(is_same_ignoring_cvref::value, 23 | "Invalid C++ type T for to-Python conversion (type_caster)."); 24 | return nullptr; // Unreachable. 25 | } 26 | 27 | static handle cast(PyObject *src, return_value_policy policy, handle /*parent*/) { 28 | if (src == nullptr) { 29 | throw error_already_set(); 30 | } 31 | if (PyErr_Occurred()) { 32 | raise_from(PyExc_SystemError, "src != nullptr but PyErr_Occurred()"); 33 | throw error_already_set(); 34 | } 35 | if (policy == return_value_policy::take_ownership) { 36 | return src; 37 | } 38 | if (policy == return_value_policy::reference 39 | || policy == return_value_policy::automatic_reference) { 40 | return handle(src).inc_ref(); 41 | } 42 | pybind11_fail("type_caster::cast(): unsupported return_value_policy: " 43 | + std::to_string(static_cast(policy))); 44 | } 45 | 46 | bool load(handle src, bool) { 47 | value = reinterpret_borrow(src); 48 | return true; 49 | } 50 | 51 | template 52 | using cast_op_type = PyObject *; 53 | 54 | explicit operator PyObject *() { return value.ptr(); } 55 | 56 | private: 57 | object value; 58 | }; 59 | 60 | PYBIND11_NAMESPACE_END(detail) 61 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 62 | -------------------------------------------------------------------------------- /pybind11/pybind11/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import sys 4 | 5 | if sys.version_info < (3, 7): # noqa: UP036 6 | msg = "pybind11 does not support Python < 3.7. v2.12 was the last release supporting Python 3.6." 7 | raise ImportError(msg) 8 | 9 | 10 | from ._version import __version__, version_info 11 | from .commands import get_cmake_dir, get_include, get_pkgconfig_dir 12 | 13 | __all__ = ( 14 | "version_info", 15 | "__version__", 16 | "get_include", 17 | "get_cmake_dir", 18 | "get_pkgconfig_dir", 19 | ) 20 | -------------------------------------------------------------------------------- /pybind11/pybind11/_version.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | 4 | def _to_int(s: str) -> int | str: 5 | try: 6 | return int(s) 7 | except ValueError: 8 | return s 9 | 10 | 11 | __version__ = "2.13.6" 12 | version_info = tuple(_to_int(s) for s in __version__.split(".")) 13 | -------------------------------------------------------------------------------- /pybind11/pybind11/commands.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import os 4 | 5 | DIR = os.path.abspath(os.path.dirname(__file__)) 6 | 7 | 8 | def get_include(user: bool = False) -> str: # noqa: ARG001 9 | """ 10 | Return the path to the pybind11 include directory. The historical "user" 11 | argument is unused, and may be removed. 12 | """ 13 | installed_path = os.path.join(DIR, "include") 14 | source_path = os.path.join(os.path.dirname(DIR), "include") 15 | return installed_path if os.path.exists(installed_path) else source_path 16 | 17 | 18 | def get_cmake_dir() -> str: 19 | """ 20 | Return the path to the pybind11 CMake module directory. 21 | """ 22 | cmake_installed_path = os.path.join(DIR, "share", "cmake", "pybind11") 23 | if os.path.exists(cmake_installed_path): 24 | return cmake_installed_path 25 | 26 | msg = "pybind11 not installed, installation required to access the CMake files" 27 | raise ImportError(msg) 28 | 29 | 30 | def get_pkgconfig_dir() -> str: 31 | """ 32 | Return the path to the pybind11 pkgconfig directory. 33 | """ 34 | pkgconfig_installed_path = os.path.join(DIR, "share", "pkgconfig") 35 | if os.path.exists(pkgconfig_installed_path): 36 | return pkgconfig_installed_path 37 | 38 | msg = "pybind11 not installed, installation required to access the pkgconfig files" 39 | raise ImportError(msg) 40 | -------------------------------------------------------------------------------- /pybind11/pybind11/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/borglab/wrap/66087700e50917f96a7ba89a02c45edb7b7c04b3/pybind11/pybind11/py.typed -------------------------------------------------------------------------------- /pybind11/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=42", "cmake>=3.18", "ninja"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | 6 | [tool.check-manifest] 7 | ignore = [ 8 | "tests/**", 9 | "docs/**", 10 | "tools/**", 11 | "include/**", 12 | ".*", 13 | "pybind11/include/**", 14 | "pybind11/share/**", 15 | "CMakeLists.txt", 16 | "noxfile.py", 17 | ] 18 | 19 | 20 | [tool.mypy] 21 | files = ["pybind11"] 22 | python_version = "3.8" 23 | strict = true 24 | enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] 25 | warn_unreachable = true 26 | 27 | [[tool.mypy.overrides]] 28 | module = ["ghapi.*"] 29 | ignore_missing_imports = true 30 | 31 | 32 | [tool.pylint] 33 | master.py-version = "3.7" 34 | reports.output-format = "colorized" 35 | messages_control.disable = [ 36 | "design", 37 | "fixme", 38 | "imports", 39 | "line-too-long", 40 | "imports", 41 | "invalid-name", 42 | "protected-access", 43 | "missing-module-docstring", 44 | "unused-argument", # covered by Ruff ARG 45 | ] 46 | 47 | [tool.ruff] 48 | target-version = "py37" 49 | src = ["src"] 50 | 51 | [tool.ruff.lint] 52 | extend-select = [ 53 | "B", # flake8-bugbear 54 | "I", # isort 55 | "N", # pep8-naming 56 | "ARG", # flake8-unused-arguments 57 | "C4", # flake8-comprehensions 58 | "EM", # flake8-errmsg 59 | "ICN", # flake8-import-conventions 60 | "PGH", # pygrep-hooks 61 | "PIE", # flake8-pie 62 | "PL", # pylint 63 | "PT", # flake8-pytest-style 64 | "RET", # flake8-return 65 | "RUF100", # Ruff-specific 66 | "SIM", # flake8-simplify 67 | "UP", # pyupgrade 68 | "YTT", # flake8-2020 69 | ] 70 | ignore = [ 71 | "PLR", # Design related pylint 72 | "E501", # Line too long (Black is enough) 73 | "PT011", # Too broad with raises in pytest 74 | "PT004", # Fixture that doesn't return needs underscore (no, it is fine) 75 | "SIM118", # iter(x) is not always the same as iter(x.keys()) 76 | ] 77 | unfixable = ["T20"] 78 | isort.known-first-party = ["env", "pybind11_cross_module_tests", "pybind11_tests"] 79 | isort.required-imports = ["from __future__ import annotations"] 80 | 81 | 82 | [tool.ruff.lint.per-file-ignores] 83 | "tests/**" = ["EM", "N", "E721"] 84 | "tests/test_call_policies.py" = ["PLC1901"] 85 | 86 | [tool.repo-review] 87 | ignore = ["PP"] 88 | -------------------------------------------------------------------------------- /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.7 18 | Programming Language :: Python :: 3.8 19 | Programming Language :: Python :: 3.9 20 | Programming Language :: Python :: 3.10 21 | Programming Language :: Python :: 3.11 22 | Programming Language :: Python :: 3.12 23 | Programming Language :: Python :: 3.13 24 | License :: OSI Approved :: BSD License 25 | Programming Language :: Python :: Implementation :: PyPy 26 | Programming Language :: Python :: Implementation :: CPython 27 | Programming Language :: C++ 28 | Topic :: Software Development :: Libraries :: Python Modules 29 | 30 | keywords = 31 | C++11 32 | Python bindings 33 | 34 | project_urls = 35 | Documentation = https://pybind11.readthedocs.io/ 36 | Bug Tracker = https://github.com/pybind/pybind11/issues 37 | Discussions = https://github.com/pybind/pybind11/discussions 38 | Changelog = https://pybind11.readthedocs.io/en/latest/changelog.html 39 | Chat = https://gitter.im/pybind/Lobby 40 | 41 | [options] 42 | python_requires = >=3.7 43 | zip_safe = False 44 | -------------------------------------------------------------------------------- /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 | py::set_error(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 | py::set_error(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 | #ifdef Py_GIL_DISABLED 46 | PyUnstable_Module_SetGIL(m, Py_MOD_GIL_NOT_USED); 47 | #endif 48 | PyModule_AddObject( 49 | m, 50 | "funcaddr", 51 | PyLong_FromVoidPtr(reinterpret_cast(&interleaved_error_already_set))); 52 | } 53 | return m; 54 | } 55 | -------------------------------------------------------------------------------- /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, pybind11::mod_gil_not_used()) { 15 | eigen_tensor_test::test_module(m); 16 | } 17 | -------------------------------------------------------------------------------- /pybind11/tests/env.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import platform 4 | import sys 5 | import sysconfig 6 | 7 | import pytest 8 | 9 | LINUX = sys.platform.startswith("linux") 10 | MACOS = sys.platform.startswith("darwin") 11 | WIN = sys.platform.startswith("win32") or sys.platform.startswith("cygwin") 12 | 13 | CPYTHON = platform.python_implementation() == "CPython" 14 | PYPY = platform.python_implementation() == "PyPy" 15 | PY_GIL_DISABLED = bool(sysconfig.get_config_var("Py_GIL_DISABLED")) 16 | 17 | 18 | def deprecated_call(): 19 | """ 20 | pytest.deprecated_call() seems broken in pytest<3.9.x; concretely, it 21 | doesn't work on CPython 3.8.0 with pytest==3.3.2 on Ubuntu 18.04 (#2922). 22 | 23 | This is a narrowed reimplementation of the following PR :( 24 | https://github.com/pytest-dev/pytest/pull/4104 25 | """ 26 | # TODO: Remove this when testing requires pytest>=3.9. 27 | pieces = pytest.__version__.split(".") 28 | pytest_major_minor = (int(pieces[0]), int(pieces[1])) 29 | if pytest_major_minor < (3, 9): 30 | return pytest.warns((DeprecationWarning, PendingDeprecationWarning)) 31 | return pytest.deprecated_call() 32 | -------------------------------------------------------------------------------- /pybind11/tests/exo_planet_pybind11.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 The pybind Community. 2 | 3 | #if defined(PYBIND11_INTERNALS_VERSION) 4 | # undef PYBIND11_INTERNALS_VERSION 5 | #endif 6 | #define PYBIND11_INTERNALS_VERSION 900000001 7 | 8 | #include "test_cpp_conduit_traveler_bindings.h" 9 | 10 | namespace pybind11_tests { 11 | namespace test_cpp_conduit { 12 | 13 | PYBIND11_MODULE(exo_planet_pybind11, m) { 14 | wrap_traveler(m); 15 | m.def("wrap_very_lonely_traveler", [m]() { wrap_very_lonely_traveler(m); }); 16 | } 17 | 18 | } // namespace test_cpp_conduit 19 | } // namespace pybind11_tests 20 | -------------------------------------------------------------------------------- /pybind11/tests/extra_python_package/pytest.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/borglab/wrap/66087700e50917f96a7ba89a02c45edb7b7c04b3/pybind11/tests/extra_python_package/pytest.ini -------------------------------------------------------------------------------- /pybind11/tests/extra_setuptools/pytest.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/borglab/wrap/66087700e50917f96a7ba89a02c45edb7b7c04b3/pybind11/tests/extra_setuptools/pytest.ini -------------------------------------------------------------------------------- /pybind11/tests/home_planet_very_lonely_traveler.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 The pybind Community. 2 | 3 | #include "test_cpp_conduit_traveler_bindings.h" 4 | 5 | namespace pybind11_tests { 6 | namespace test_cpp_conduit { 7 | 8 | PYBIND11_MODULE(home_planet_very_lonely_traveler, m) { 9 | m.def("wrap_very_lonely_traveler", [m]() { wrap_very_lonely_traveler(m); }); 10 | } 11 | 12 | } // namespace test_cpp_conduit 13 | } // namespace pybind11_tests 14 | -------------------------------------------------------------------------------- /pybind11/tests/pyproject.toml: -------------------------------------------------------------------------------- 1 | # Warning: this is currently used for pyodide, and is not a general out-of-tree 2 | # builder for the tests (yet). Specifically, wheels can't be built from SDists. 3 | 4 | [build-system] 5 | requires = ["scikit-build-core"] 6 | build-backend = "scikit_build_core.build" 7 | 8 | [project] 9 | name = "pybind11_tests" 10 | version = "0.0.1" 11 | dependencies = ["pytest", "pytest-timeout", "numpy", "scipy"] 12 | 13 | [tool.scikit-build] 14 | # Hide a warning while we also support CMake < 3.15 15 | cmake.version = ">=3.15" 16 | 17 | [tool.scikit-build.cmake.define] 18 | PYBIND11_FINDPYTHON = true 19 | 20 | [tool.cibuildwheel] 21 | test-command = "pytest -o timeout=0 -p no:cacheprovider {project}/tests/test_*.py" 22 | -------------------------------------------------------------------------------- /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 | default:The global interpreter lock:RuntimeWarning 24 | -------------------------------------------------------------------------------- /pybind11/tests/requirements.txt: -------------------------------------------------------------------------------- 1 | --only-binary=:all: 2 | build~=1.0; python_version>="3.7" 3 | numpy~=1.20.0; python_version=="3.7" and platform_python_implementation=="PyPy" 4 | numpy~=1.23.0; python_version=="3.8" and platform_python_implementation=="PyPy" 5 | numpy~=1.25.0; python_version=="3.9" and platform_python_implementation=='PyPy' 6 | numpy~=1.21.5; platform_python_implementation!="PyPy" and python_version>="3.7" and python_version<"3.10" 7 | numpy~=1.22.2; platform_python_implementation!="PyPy" and python_version=="3.10" 8 | numpy~=1.26.0; platform_python_implementation!="PyPy" and python_version>="3.11" and python_version<"3.13" 9 | pytest~=7.0 10 | pytest-timeout 11 | scipy~=1.5.4; platform_python_implementation!="PyPy" and python_version<"3.10" 12 | scipy~=1.8.0; platform_python_implementation!="PyPy" and python_version=="3.10" and sys_platform!='win32' 13 | scipy~=1.11.1; platform_python_implementation!="PyPy" and python_version>="3.11" and python_version<"3.13" and sys_platform!='win32' 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pybind11/tests/test_async.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import sys 4 | 5 | import pytest 6 | 7 | asyncio = pytest.importorskip("asyncio") 8 | m = pytest.importorskip("pybind11_tests.async_module") 9 | 10 | if sys.platform.startswith("emscripten"): 11 | pytest.skip("Can't run a new event_loop in pyodide", allow_module_level=True) 12 | 13 | 14 | @pytest.fixture 15 | def event_loop(): 16 | loop = asyncio.new_event_loop() 17 | yield loop 18 | loop.close() 19 | 20 | 21 | async def get_await_result(x): 22 | return await x 23 | 24 | 25 | def test_await(event_loop): 26 | assert event_loop.run_until_complete(get_await_result(m.SupportsAsync())) == 5 27 | 28 | 29 | def test_await_missing(event_loop): 30 | with pytest.raises(TypeError): 31 | event_loop.run_until_complete(get_await_result(m.DoesNotSupportAsync())) 32 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | # The `cmake_minimum_required(VERSION 3.5...3.29)` 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.29) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.29) 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 | -------------------------------------------------------------------------------- /pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | project(test_installed_module CXX) 3 | 4 | # The `cmake_minimum_required(VERSION 3.5...3.29)` 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.29) 8 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 9 | else() 10 | cmake_policy(VERSION 3.29) 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 | -------------------------------------------------------------------------------- /pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | # The `cmake_minimum_required(VERSION 3.5...3.29)` 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.29) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.29) 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 | -------------------------------------------------------------------------------- /pybind11/tests/test_cmake_build/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace py = pybind11; 3 | 4 | PYBIND11_MODULE(test_cmake_build, m, py::mod_gil_not_used()) { 5 | m.def("add", [](int i, int j) { return i + j; }); 6 | } 7 | -------------------------------------------------------------------------------- /pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | # The `cmake_minimum_required(VERSION 3.5...3.29)` 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.29) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.29) 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 | # Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests 20 | # (makes transition easier while we support both modes). 21 | if(DEFINED PYTHON_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE) 22 | set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") 23 | endif() 24 | 25 | add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) 26 | 27 | # Test basic target functionality 28 | add_executable(test_subdirectory_embed ../embed.cpp) 29 | target_link_libraries(test_subdirectory_embed PRIVATE pybind11::embed) 30 | set_target_properties(test_subdirectory_embed PROPERTIES OUTPUT_NAME test_cmake_build) 31 | 32 | add_custom_target( 33 | check_subdirectory_embed 34 | $ "${PROJECT_SOURCE_DIR}/../test.py" 35 | DEPENDS test_subdirectory_embed) 36 | 37 | # Test custom export group -- PYBIND11_EXPORT_NAME 38 | add_library(test_embed_lib ../embed.cpp) 39 | target_link_libraries(test_embed_lib PRIVATE pybind11::embed) 40 | 41 | install( 42 | TARGETS test_embed_lib 43 | EXPORT test_export 44 | ARCHIVE DESTINATION bin 45 | LIBRARY DESTINATION lib 46 | RUNTIME DESTINATION lib) 47 | install(EXPORT test_export DESTINATION lib/cmake/test_export/test_export-Targets.cmake) 48 | -------------------------------------------------------------------------------- /pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | # The `cmake_minimum_required(VERSION 3.5...3.29)` 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.29) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.29) 10 | endif() 11 | 12 | project(test_subdirectory_function CXX) 13 | 14 | # Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests 15 | # (makes transition easier while we support both modes). 16 | if(DEFINED PYTHON_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE) 17 | set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") 18 | endif() 19 | 20 | add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) 21 | pybind11_add_module(test_subdirectory_function ../main.cpp) 22 | set_target_properties(test_subdirectory_function PROPERTIES OUTPUT_NAME test_cmake_build) 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_function 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_function) 42 | -------------------------------------------------------------------------------- /pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | # The `cmake_minimum_required(VERSION 3.5...3.29)` 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.29) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.29) 10 | endif() 11 | 12 | project(test_subdirectory_target CXX) 13 | 14 | # Allow PYTHON_EXECUTABLE if in FINDPYTHON mode and building pybind11's tests 15 | # (makes transition easier while we support both modes). 16 | if(DEFINED PYTHON_EXECUTABLE AND NOT DEFINED Python_EXECUTABLE) 17 | set(Python_EXECUTABLE "${PYTHON_EXECUTABLE}") 18 | endif() 19 | 20 | add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) 21 | 22 | add_library(test_subdirectory_target MODULE ../main.cpp) 23 | set_target_properties(test_subdirectory_target PROPERTIES OUTPUT_NAME test_cmake_build) 24 | 25 | target_link_libraries(test_subdirectory_target PRIVATE pybind11::module) 26 | 27 | # Make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib 28 | pybind11_extension(test_subdirectory_target) 29 | 30 | if(DEFINED Python_EXECUTABLE) 31 | set(_Python_EXECUTABLE "${Python_EXECUTABLE}") 32 | elseif(DEFINED PYTHON_EXECUTABLE) 33 | set(_Python_EXECUTABLE "${PYTHON_EXECUTABLE}") 34 | else() 35 | message(FATAL_ERROR "No Python executable defined (should not be possible at this stage)") 36 | endif() 37 | 38 | add_custom_target( 39 | check_subdirectory_target 40 | ${CMAKE_COMMAND} 41 | -E 42 | env 43 | PYTHONPATH=$ 44 | ${_Python_EXECUTABLE} 45 | ${PROJECT_SOURCE_DIR}/../test.py 46 | ${PROJECT_NAME} 47 | DEPENDS test_subdirectory_target) 48 | -------------------------------------------------------------------------------- /pybind11/tests/test_cmake_build/test.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import sys 4 | 5 | import test_cmake_build 6 | 7 | assert isinstance(__file__, str) # Test this is properly set 8 | 9 | assert test_cmake_build.add(1, 2) == 3 10 | print(f"{sys.argv[1]} imports, runs, and adds: 1 + 2 = 3") 11 | -------------------------------------------------------------------------------- /pybind11/tests/test_const_name.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import pytest 4 | 5 | from pybind11_tests import const_name as m 6 | 7 | 8 | @pytest.mark.parametrize("func", [m.const_name_tests, m.underscore_tests]) 9 | @pytest.mark.parametrize( 10 | ("selector", "expected"), 11 | enumerate( 12 | ( 13 | "", 14 | "A", 15 | "Bd", 16 | "Cef", 17 | "%", 18 | "%", 19 | "T1", 20 | "U2", 21 | "D1", 22 | "E2", 23 | "KeepAtEnd", 24 | ) 25 | ), 26 | ) 27 | def test_const_name(func, selector, expected): 28 | if isinstance(func, str): 29 | pytest.skip(func) 30 | text = func(selector) 31 | assert text == expected 32 | -------------------------------------------------------------------------------- /pybind11/tests/test_constants_and_functions.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import pytest 4 | 5 | m = pytest.importorskip("pybind11_tests.constants_and_functions") 6 | 7 | 8 | def test_constants(): 9 | assert m.some_constant == 14 10 | 11 | 12 | def test_function_overloading(): 13 | assert m.test_function() == "test_function()" 14 | assert m.test_function(7) == "test_function(7)" 15 | assert m.test_function(m.MyEnum.EFirstEntry) == "test_function(enum=1)" 16 | assert m.test_function(m.MyEnum.ESecondEntry) == "test_function(enum=2)" 17 | 18 | assert m.test_function() == "test_function()" 19 | assert m.test_function("abcd") == "test_function(char *)" 20 | assert m.test_function(1, 1.0) == "test_function(int, float)" 21 | assert m.test_function(1, 1.0) == "test_function(int, float)" 22 | assert m.test_function(2.0, 2) == "test_function(float, int)" 23 | 24 | 25 | def test_bytes(): 26 | assert m.print_bytes(m.return_bytes()) == "bytes[1 0 2 0]" 27 | 28 | 29 | def test_exception_specifiers(): 30 | c = m.C() 31 | assert c.m1(2) == 1 32 | assert c.m2(3) == 1 33 | assert c.m3(5) == 2 34 | assert c.m4(7) == 3 35 | assert c.m5(10) == 5 36 | assert c.m6(14) == 8 37 | assert c.m7(20) == 13 38 | assert c.m8(29) == 21 39 | 40 | assert m.f1(33) == 34 41 | assert m.f2(53) == 55 42 | assert m.f3(86) == 89 43 | assert m.f4(140) == 144 44 | 45 | 46 | def test_function_record_leaks(): 47 | class RaisingRepr: 48 | def __repr__(self): 49 | raise RuntimeError("Surprise!") 50 | 51 | with pytest.raises(RuntimeError): 52 | m.register_large_capture_with_invalid_arguments(m) 53 | with pytest.raises(RuntimeError): 54 | m.register_with_raising_repr(m, RaisingRepr()) 55 | 56 | 57 | def test_noexcept_lambda(): 58 | assert m.l1() == 0 59 | -------------------------------------------------------------------------------- /pybind11/tests/test_cpp_conduit.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 The pybind Community. 2 | 3 | #include "pybind11_tests.h" 4 | #include "test_cpp_conduit_traveler_bindings.h" 5 | 6 | #include 7 | 8 | namespace pybind11_tests { 9 | namespace test_cpp_conduit { 10 | 11 | TEST_SUBMODULE(cpp_conduit, m) { 12 | m.attr("PYBIND11_PLATFORM_ABI_ID") = py::bytes(PYBIND11_PLATFORM_ABI_ID); 13 | m.attr("cpp_type_info_capsule_Traveler") 14 | = py::capsule(&typeid(Traveler), typeid(std::type_info).name()); 15 | m.attr("cpp_type_info_capsule_int") = py::capsule(&typeid(int), typeid(std::type_info).name()); 16 | 17 | wrap_traveler(m); 18 | wrap_lonely_traveler(m); 19 | } 20 | 21 | } // namespace test_cpp_conduit 22 | } // namespace pybind11_tests 23 | -------------------------------------------------------------------------------- /pybind11/tests/test_cpp_conduit_traveler_bindings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 The pybind Community. 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | #include "test_cpp_conduit_traveler_types.h" 8 | 9 | #include 10 | 11 | namespace pybind11_tests { 12 | namespace test_cpp_conduit { 13 | 14 | namespace py = pybind11; 15 | 16 | inline void wrap_traveler(py::module_ m) { 17 | py::class_(m, "Traveler") 18 | .def(py::init()) 19 | .def_readwrite("luggage", &Traveler::luggage) 20 | // See issue #3788: 21 | .def("__getattr__", [](const Traveler &self, const std::string &key) { 22 | return "Traveler GetAttr: " + key + " luggage: " + self.luggage; 23 | }); 24 | 25 | m.def("get_luggage", [](const Traveler &person) { return person.luggage; }); 26 | 27 | py::class_(m, "PremiumTraveler") 28 | .def(py::init()) 29 | .def_readwrite("points", &PremiumTraveler::points) 30 | // See issue #3788: 31 | .def("__getattr__", [](const PremiumTraveler &self, const std::string &key) { 32 | return "PremiumTraveler GetAttr: " + key + " points: " + std::to_string(self.points); 33 | }); 34 | 35 | m.def("get_points", [](const PremiumTraveler &person) { return person.points; }); 36 | } 37 | 38 | inline void wrap_lonely_traveler(py::module_ m) { 39 | py::class_(std::move(m), "LonelyTraveler"); 40 | } 41 | 42 | inline void wrap_very_lonely_traveler(py::module_ m) { 43 | py::class_(std::move(m), "VeryLonelyTraveler"); 44 | } 45 | 46 | } // namespace test_cpp_conduit 47 | } // namespace pybind11_tests 48 | -------------------------------------------------------------------------------- /pybind11/tests/test_cpp_conduit_traveler_types.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2024 The pybind Community. 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | namespace pybind11_tests { 8 | namespace test_cpp_conduit { 9 | 10 | struct Traveler { 11 | explicit Traveler(const std::string &luggage) : luggage(luggage) {} 12 | std::string luggage; 13 | }; 14 | 15 | struct PremiumTraveler : Traveler { 16 | explicit PremiumTraveler(const std::string &luggage, int points) 17 | : Traveler(luggage), points(points) {} 18 | int points; 19 | }; 20 | 21 | struct LonelyTraveler {}; 22 | struct VeryLonelyTraveler : LonelyTraveler {}; 23 | 24 | } // namespace test_cpp_conduit 25 | } // namespace pybind11_tests 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pybind11/tests/test_custom_type_setup.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import gc 4 | import weakref 5 | 6 | import pytest 7 | 8 | import env # noqa: F401 9 | from pybind11_tests import custom_type_setup as m 10 | 11 | 12 | @pytest.fixture 13 | def gc_tester(): 14 | """Tests that an object is garbage collected. 15 | 16 | Assumes that any unreferenced objects are fully collected after calling 17 | `gc.collect()`. That is true on CPython, but does not appear to reliably 18 | hold on PyPy. 19 | """ 20 | 21 | weak_refs = [] 22 | 23 | def add_ref(obj): 24 | # PyPy does not support `gc.is_tracked`. 25 | if hasattr(gc, "is_tracked"): 26 | assert gc.is_tracked(obj) 27 | weak_refs.append(weakref.ref(obj)) 28 | 29 | yield add_ref 30 | 31 | gc.collect() 32 | for ref in weak_refs: 33 | assert ref() is None 34 | 35 | 36 | # PyPy does not seem to reliably garbage collect. 37 | @pytest.mark.skipif("env.PYPY") 38 | def test_self_cycle(gc_tester): 39 | obj = m.OwnsPythonObjects() 40 | obj.value = obj 41 | gc_tester(obj) 42 | 43 | 44 | # PyPy does not seem to reliably garbage collect. 45 | @pytest.mark.skipif("env.PYPY") 46 | def test_indirect_cycle(gc_tester): 47 | obj = m.OwnsPythonObjects() 48 | obj_list = [obj] 49 | obj.value = obj_list 50 | gc_tester(obj) 51 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | if(TARGET Python::Module AND NOT TARGET Python::Python) 11 | message(STATUS "Skipping embed test since no embed libs found") 12 | add_custom_target(cpptest) # Dummy target since embedding is not supported. 13 | set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}") 14 | return() 15 | endif() 16 | 17 | find_package(Catch 2.13.9) 18 | 19 | if(CATCH_FOUND) 20 | message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}") 21 | else() 22 | message(STATUS "Catch not detected. Interpreter tests will be skipped. Install Catch headers" 23 | " manually or use `cmake -DDOWNLOAD_CATCH=ON` to fetch them automatically.") 24 | return() 25 | endif() 26 | 27 | find_package(Threads REQUIRED) 28 | 29 | add_executable(test_embed catch.cpp test_interpreter.cpp) 30 | pybind11_enable_warnings(test_embed) 31 | 32 | target_link_libraries(test_embed PRIVATE pybind11::embed Catch2::Catch2 Threads::Threads) 33 | 34 | if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) 35 | file(COPY test_interpreter.py test_trampoline.py DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") 36 | endif() 37 | 38 | add_custom_target( 39 | cpptest 40 | COMMAND "$" 41 | DEPENDS test_embed 42 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") 43 | 44 | pybind11_add_module(external_module THIN_LTO external_module.cpp) 45 | set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY 46 | "${CMAKE_CURRENT_BINARY_DIR}") 47 | foreach(config ${CMAKE_CONFIGURATION_TYPES}) 48 | string(TOUPPER ${config} config) 49 | set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} 50 | "${CMAKE_CURRENT_BINARY_DIR}") 51 | endforeach() 52 | add_dependencies(cpptest external_module) 53 | 54 | add_dependencies(check cpptest) 55 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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, py::mod_gil_not_used()) { 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 | -------------------------------------------------------------------------------- /pybind11/tests/test_embed/test_interpreter.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import sys 4 | 5 | from widget_module import Widget 6 | 7 | 8 | class DerivedWidget(Widget): 9 | def __init__(self, message): 10 | super().__init__(message) 11 | 12 | def the_answer(self): 13 | return 42 14 | 15 | def argv0(self): 16 | return sys.argv[0] 17 | -------------------------------------------------------------------------------- /pybind11/tests/test_embed/test_trampoline.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import trampoline_module 4 | 5 | 6 | def func(): 7 | class Test(trampoline_module.test_override_cache_helper): 8 | def func(self): 9 | return 42 10 | 11 | return Test() 12 | 13 | 14 | def func2(): 15 | class Test(trampoline_module.test_override_cache_helper): 16 | pass 17 | 18 | return Test() 19 | -------------------------------------------------------------------------------- /pybind11/tests/test_eval.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import os 4 | 5 | import pytest 6 | 7 | import env # noqa: F401 8 | from pybind11_tests import eval_ as m 9 | 10 | 11 | def test_evals(capture): 12 | with capture: 13 | assert m.test_eval_statements() 14 | assert capture == "Hello World!" 15 | 16 | assert m.test_eval() 17 | assert m.test_eval_single_statement() 18 | 19 | assert m.test_eval_failure() 20 | 21 | 22 | @pytest.mark.xfail("env.PYPY", raises=RuntimeError) 23 | def test_eval_file(): 24 | filename = os.path.join(os.path.dirname(__file__), "test_eval_call.py") 25 | assert m.test_eval_file(filename) 26 | 27 | assert m.test_eval_file_failure() 28 | 29 | 30 | def test_eval_empty_globals(): 31 | assert "__builtins__" in m.eval_empty_globals(None) 32 | 33 | g = {} 34 | assert "__builtins__" in m.eval_empty_globals(g) 35 | assert "__builtins__" in g 36 | 37 | 38 | def test_eval_closure(): 39 | global_, local = m.test_eval_closure() 40 | 41 | assert global_["closure_value"] == 42 42 | assert local["closure_value"] == 0 43 | 44 | assert "local_value" not in global_ 45 | assert local["local_value"] == 0 46 | 47 | assert "func_global" not in global_ 48 | assert local["func_global"]() == 42 49 | 50 | assert "func_local" not in global_ 51 | with pytest.raises(NameError): 52 | local["func_local"]() 53 | -------------------------------------------------------------------------------- /pybind11/tests/test_eval_call.py: -------------------------------------------------------------------------------- 1 | # This file is called from 'test_eval.py' 2 | from __future__ import annotations 3 | 4 | if "call_test2" in locals(): 5 | call_test2(y) # noqa: F821 undefined name 6 | -------------------------------------------------------------------------------- /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 { py::set_error(PyExc_RuntimeError, what()); } 13 | }; 14 | -------------------------------------------------------------------------------- /pybind11/tests/test_opaque_types.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import pytest 4 | 5 | from pybind11_tests import ConstructorStats, UserType 6 | from pybind11_tests import opaque_types as m 7 | 8 | 9 | def test_string_list(): 10 | lst = m.StringList() 11 | lst.push_back("Element 1") 12 | lst.push_back("Element 2") 13 | assert m.print_opaque_list(lst) == "Opaque list: [Element 1, Element 2]" 14 | assert lst.back() == "Element 2" 15 | 16 | for i, k in enumerate(lst, start=1): 17 | assert k == f"Element {i}" 18 | lst.pop_back() 19 | assert m.print_opaque_list(lst) == "Opaque list: [Element 1]" 20 | 21 | cvp = m.ClassWithSTLVecProperty() 22 | assert m.print_opaque_list(cvp.stringList) == "Opaque list: []" 23 | 24 | cvp.stringList = lst 25 | cvp.stringList.push_back("Element 3") 26 | assert m.print_opaque_list(cvp.stringList) == "Opaque list: [Element 1, Element 3]" 27 | 28 | 29 | def test_pointers(msg): 30 | living_before = ConstructorStats.get(UserType).alive() 31 | assert m.get_void_ptr_value(m.return_void_ptr()) == 0x1234 32 | assert m.get_void_ptr_value(UserType()) # Should also work for other C++ types 33 | assert ConstructorStats.get(UserType).alive() == living_before 34 | 35 | with pytest.raises(TypeError) as excinfo: 36 | m.get_void_ptr_value([1, 2, 3]) # This should not work 37 | assert ( 38 | msg(excinfo.value) 39 | == """ 40 | get_void_ptr_value(): incompatible function arguments. The following argument types are supported: 41 | 1. (arg0: capsule) -> int 42 | 43 | Invoked with: [1, 2, 3] 44 | """ 45 | ) 46 | 47 | assert m.return_null_str() is None 48 | assert m.get_null_str_value(m.return_null_str()) is not None 49 | 50 | ptr = m.return_unique_ptr() 51 | assert "StringList" in repr(ptr) 52 | assert m.print_opaque_list(ptr) == "Opaque list: [some value]" 53 | 54 | 55 | def test_unions(): 56 | int_float_union = m.IntFloat() 57 | int_float_union.i = 42 58 | assert int_float_union.i == 42 59 | int_float_union.f = 3.0 60 | assert int_float_union.f == 3.0 61 | -------------------------------------------------------------------------------- /pybind11/tests/test_python_multiple_inheritance.cpp: -------------------------------------------------------------------------------- 1 | #include "pybind11_tests.h" 2 | 3 | namespace test_python_multiple_inheritance { 4 | 5 | // Copied from: 6 | // https://github.com/google/clif/blob/5718e4d0807fd3b6a8187dde140069120b81ecef/clif/testing/python_multiple_inheritance.h 7 | 8 | struct CppBase { 9 | explicit CppBase(int value) : base_value(value) {} 10 | int get_base_value() const { return base_value; } 11 | void reset_base_value(int new_value) { base_value = new_value; } 12 | 13 | private: 14 | int base_value; 15 | }; 16 | 17 | struct CppDrvd : CppBase { 18 | explicit CppDrvd(int value) : CppBase(value), drvd_value(value * 3) {} 19 | int get_drvd_value() const { return drvd_value; } 20 | void reset_drvd_value(int new_value) { drvd_value = new_value; } 21 | 22 | int get_base_value_from_drvd() const { return get_base_value(); } 23 | void reset_base_value_from_drvd(int new_value) { reset_base_value(new_value); } 24 | 25 | private: 26 | int drvd_value; 27 | }; 28 | 29 | } // namespace test_python_multiple_inheritance 30 | 31 | TEST_SUBMODULE(python_multiple_inheritance, m) { 32 | using namespace test_python_multiple_inheritance; 33 | 34 | py::class_(m, "CppBase") 35 | .def(py::init()) 36 | .def("get_base_value", &CppBase::get_base_value) 37 | .def("reset_base_value", &CppBase::reset_base_value); 38 | 39 | py::class_(m, "CppDrvd") 40 | .def(py::init()) 41 | .def("get_drvd_value", &CppDrvd::get_drvd_value) 42 | .def("reset_drvd_value", &CppDrvd::reset_drvd_value) 43 | .def("get_base_value_from_drvd", &CppDrvd::get_base_value_from_drvd) 44 | .def("reset_base_value_from_drvd", &CppDrvd::reset_base_value_from_drvd); 45 | } 46 | -------------------------------------------------------------------------------- /pybind11/tests/test_python_multiple_inheritance.py: -------------------------------------------------------------------------------- 1 | # Adapted from: 2 | # https://github.com/google/clif/blob/5718e4d0807fd3b6a8187dde140069120b81ecef/clif/testing/python/python_multiple_inheritance_test.py 3 | from __future__ import annotations 4 | 5 | from pybind11_tests import python_multiple_inheritance as m 6 | 7 | 8 | class PC(m.CppBase): 9 | pass 10 | 11 | 12 | class PPCC(PC, m.CppDrvd): 13 | pass 14 | 15 | 16 | def test_PC(): 17 | d = PC(11) 18 | assert d.get_base_value() == 11 19 | d.reset_base_value(13) 20 | assert d.get_base_value() == 13 21 | 22 | 23 | def test_PPCC(): 24 | d = PPCC(11) 25 | assert d.get_drvd_value() == 33 26 | d.reset_drvd_value(55) 27 | assert d.get_drvd_value() == 55 28 | 29 | assert d.get_base_value() == 11 30 | assert d.get_base_value_from_drvd() == 11 31 | d.reset_base_value(20) 32 | assert d.get_base_value() == 20 33 | assert d.get_base_value_from_drvd() == 20 34 | d.reset_base_value_from_drvd(30) 35 | assert d.get_base_value() == 30 36 | assert d.get_base_value_from_drvd() == 30 37 | -------------------------------------------------------------------------------- /pybind11/tests/test_tagbased_polymorphic.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from pybind11_tests import tagbased_polymorphic as m 4 | 5 | 6 | def test_downcast(): 7 | zoo = m.create_zoo() 8 | assert [type(animal) for animal in zoo] == [ 9 | m.Labrador, 10 | m.Dog, 11 | m.Chihuahua, 12 | m.Cat, 13 | m.Panther, 14 | ] 15 | assert [animal.name for animal in zoo] == [ 16 | "Fido", 17 | "Ginger", 18 | "Hertzl", 19 | "Tiger", 20 | "Leo", 21 | ] 22 | zoo[1].sound = "woooooo" 23 | assert [dog.bark() for dog in zoo[:3]] == [ 24 | "Labrador Fido goes WOOF!", 25 | "Dog Ginger goes woooooo", 26 | "Chihuahua Hertzl goes iyiyiyiyiyi and runs in circles", 27 | ] 28 | assert [cat.purr() for cat in zoo[3:]] == ["mrowr", "mrrrRRRRRR"] 29 | zoo[0].excitement -= 1000 30 | assert zoo[0].excitement == 14000 31 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pybind11/tests/test_thread.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import sys 4 | import threading 5 | 6 | import pytest 7 | 8 | from pybind11_tests import thread as m 9 | 10 | 11 | class Thread(threading.Thread): 12 | def __init__(self, fn): 13 | super().__init__() 14 | self.fn = fn 15 | self.e = None 16 | 17 | def run(self): 18 | try: 19 | for i in range(10): 20 | self.fn(i, i) 21 | except Exception as e: 22 | self.e = e 23 | 24 | def join(self): 25 | super().join() 26 | if self.e: 27 | raise self.e 28 | 29 | 30 | @pytest.mark.skipif(sys.platform.startswith("emscripten"), reason="Requires threads") 31 | def test_implicit_conversion(): 32 | a = Thread(m.test) 33 | b = Thread(m.test) 34 | c = Thread(m.test) 35 | for x in [a, b, c]: 36 | x.start() 37 | for x in [c, b, a]: 38 | x.join() 39 | 40 | 41 | @pytest.mark.skipif(sys.platform.startswith("emscripten"), reason="Requires threads") 42 | def test_implicit_conversion_no_gil(): 43 | a = Thread(m.test_no_gil) 44 | b = Thread(m.test_no_gil) 45 | c = Thread(m.test_no_gil) 46 | for x in [a, b, c]: 47 | x.start() 48 | for x in [c, b, a]: 49 | x.join() 50 | -------------------------------------------------------------------------------- /pybind11/tests/test_type_caster_std_function_specializations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "pybind11_tests.h" 5 | 6 | namespace py = pybind11; 7 | 8 | namespace { 9 | 10 | struct SpecialReturn { 11 | int value = 99; 12 | }; 13 | 14 | } // namespace 15 | 16 | namespace pybind11 { 17 | namespace detail { 18 | namespace type_caster_std_function_specializations { 19 | 20 | template 21 | struct func_wrapper : func_wrapper_base { 22 | using func_wrapper_base::func_wrapper_base; 23 | SpecialReturn operator()(Args... args) const { 24 | gil_scoped_acquire acq; 25 | SpecialReturn result; 26 | try { 27 | result = hfunc.f(std::forward(args)...).template cast(); 28 | } catch (error_already_set &) { 29 | result.value += 1; 30 | } 31 | result.value += 100; 32 | return result; 33 | } 34 | }; 35 | 36 | } // namespace type_caster_std_function_specializations 37 | } // namespace detail 38 | } // namespace pybind11 39 | 40 | TEST_SUBMODULE(type_caster_std_function_specializations, m) { 41 | py::class_(m, "SpecialReturn") 42 | .def(py::init<>()) 43 | .def_readwrite("value", &SpecialReturn::value); 44 | m.def("call_callback_with_special_return", 45 | [](const std::function &func) { return func(); }); 46 | } 47 | -------------------------------------------------------------------------------- /pybind11/tests/test_type_caster_std_function_specializations.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from pybind11_tests import type_caster_std_function_specializations as m 4 | 5 | 6 | def test_callback_with_special_return(): 7 | def return_special(): 8 | return m.SpecialReturn() 9 | 10 | def raise_exception(): 11 | raise ValueError("called raise_exception.") 12 | 13 | assert return_special().value == 99 14 | assert m.call_callback_with_special_return(return_special).value == 199 15 | assert m.call_callback_with_special_return(raise_exception).value == 200 16 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pybind11/tests/test_union.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from pybind11_tests import union_ as m 4 | 5 | 6 | def test_union(): 7 | instance = m.TestUnion() 8 | 9 | instance.as_uint = 10 10 | assert instance.as_int == 10 11 | -------------------------------------------------------------------------------- /pybind11/tests/test_unnamed_namespace_a.cpp: -------------------------------------------------------------------------------- 1 | #include "pybind11_tests.h" 2 | 3 | namespace { 4 | struct any_struct {}; 5 | } // namespace 6 | 7 | TEST_SUBMODULE(unnamed_namespace_a, m) { 8 | if (py::detail::get_type_info(typeid(any_struct)) == nullptr) { 9 | py::class_(m, "unnamed_namespace_a_any_struct"); 10 | } else { 11 | m.attr("unnamed_namespace_a_any_struct") = py::none(); 12 | } 13 | m.attr("PYBIND11_INTERNALS_VERSION") = PYBIND11_INTERNALS_VERSION; 14 | m.attr("defined_WIN32_or__WIN32") = 15 | #if defined(WIN32) || defined(_WIN32) 16 | true; 17 | #else 18 | false; 19 | #endif 20 | m.attr("defined___clang__") = 21 | #if defined(__clang__) 22 | true; 23 | #else 24 | false; 25 | #endif 26 | m.attr("defined__LIBCPP_VERSION") = 27 | #if defined(_LIBCPP_VERSION) 28 | true; 29 | #else 30 | false; 31 | #endif 32 | m.attr("defined___GLIBCXX__") = 33 | #if defined(__GLIBCXX__) 34 | true; 35 | #else 36 | false; 37 | #endif 38 | } 39 | -------------------------------------------------------------------------------- /pybind11/tests/test_unnamed_namespace_a.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import pytest 4 | 5 | from pybind11_tests import unnamed_namespace_a as m 6 | from pybind11_tests import unnamed_namespace_b as mb 7 | 8 | XFAIL_CONDITION = ( 9 | "(m.PYBIND11_INTERNALS_VERSION <= 4 and (m.defined___clang__ or not m.defined___GLIBCXX__))" 10 | " or " 11 | "(m.PYBIND11_INTERNALS_VERSION >= 5 and not m.defined_WIN32_or__WIN32" 12 | " and " 13 | "(m.defined___clang__ or m.defined__LIBCPP_VERSION))" 14 | ) 15 | XFAIL_REASON = "Known issues: https://github.com/pybind/pybind11/pull/4319" 16 | 17 | 18 | @pytest.mark.xfail(XFAIL_CONDITION, reason=XFAIL_REASON, strict=False) 19 | @pytest.mark.parametrize( 20 | "any_struct", [m.unnamed_namespace_a_any_struct, mb.unnamed_namespace_b_any_struct] 21 | ) 22 | def test_have_class_any_struct(any_struct): 23 | assert any_struct is not None 24 | 25 | 26 | def test_have_at_least_one_class_any_struct(): 27 | assert ( 28 | m.unnamed_namespace_a_any_struct is not None 29 | or mb.unnamed_namespace_b_any_struct is not None 30 | ) 31 | 32 | 33 | @pytest.mark.xfail(XFAIL_CONDITION, reason=XFAIL_REASON, strict=True) 34 | def test_have_both_class_any_struct(): 35 | assert m.unnamed_namespace_a_any_struct is not None 36 | assert mb.unnamed_namespace_b_any_struct is not None 37 | -------------------------------------------------------------------------------- /pybind11/tests/test_unnamed_namespace_b.cpp: -------------------------------------------------------------------------------- 1 | #include "pybind11_tests.h" 2 | 3 | namespace { 4 | struct any_struct {}; 5 | } // namespace 6 | 7 | TEST_SUBMODULE(unnamed_namespace_b, m) { 8 | if (py::detail::get_type_info(typeid(any_struct)) == nullptr) { 9 | py::class_(m, "unnamed_namespace_b_any_struct"); 10 | } else { 11 | m.attr("unnamed_namespace_b_any_struct") = py::none(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /pybind11/tests/test_unnamed_namespace_b.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | from pybind11_tests import unnamed_namespace_b as m 4 | 5 | 6 | def test_have_attr_any_struct(): 7 | assert hasattr(m, "unnamed_namespace_b_any_struct") 8 | -------------------------------------------------------------------------------- /pybind11/tests/test_vector_unique_ptr_member.cpp: -------------------------------------------------------------------------------- 1 | #include "pybind11_tests.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace pybind11_tests { 8 | namespace vector_unique_ptr_member { 9 | 10 | struct DataType {}; 11 | 12 | // Reduced from a use case in the wild. 13 | struct VectorOwner { 14 | static std::unique_ptr Create(std::size_t num_elems) { 15 | return std::unique_ptr( 16 | new VectorOwner(std::vector>(num_elems))); 17 | } 18 | 19 | std::size_t data_size() const { return data_.size(); } 20 | 21 | private: 22 | explicit VectorOwner(std::vector> data) : data_(std::move(data)) {} 23 | 24 | const std::vector> data_; 25 | }; 26 | 27 | } // namespace vector_unique_ptr_member 28 | } // namespace pybind11_tests 29 | 30 | namespace pybind11 { 31 | namespace detail { 32 | 33 | template <> 34 | struct is_copy_constructible 35 | : std::false_type {}; 36 | 37 | template <> 38 | struct is_move_constructible 39 | : std::false_type {}; 40 | 41 | } // namespace detail 42 | } // namespace pybind11 43 | 44 | using namespace pybind11_tests::vector_unique_ptr_member; 45 | 46 | py::object py_cast_VectorOwner_ptr(VectorOwner *ptr) { return py::cast(ptr); } 47 | 48 | TEST_SUBMODULE(vector_unique_ptr_member, m) { 49 | py::class_(m, "VectorOwner") 50 | .def_static("Create", &VectorOwner::Create) 51 | .def("data_size", &VectorOwner::data_size); 52 | 53 | m.def("py_cast_VectorOwner_ptr", py_cast_VectorOwner_ptr); 54 | } 55 | -------------------------------------------------------------------------------- /pybind11/tests/test_vector_unique_ptr_member.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import pytest 4 | 5 | from pybind11_tests import vector_unique_ptr_member as m 6 | 7 | 8 | @pytest.mark.parametrize("num_elems", range(3)) 9 | def test_create(num_elems): 10 | vo = m.VectorOwner.Create(num_elems) 11 | assert vo.data_size() == num_elems 12 | 13 | 14 | def test_cast(): 15 | vo = m.VectorOwner.Create(0) 16 | assert m.py_cast_VectorOwner_ptr(vo) is vo 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | from __future__ import annotations 13 | 14 | import sys 15 | 16 | 17 | def run(args: list[str]) -> None: 18 | assert len(args) == 1, "codespell_errors.txt" 19 | cache = {} 20 | done = set() 21 | with open(args[0]) as f: 22 | lines = f.read().splitlines() 23 | 24 | for line in sorted(lines): 25 | i = line.find(" ==> ") 26 | if i > 0: 27 | flds = line[:i].split(":") 28 | if len(flds) >= 2: 29 | filename, line_num = flds[:2] 30 | if filename not in cache: 31 | with open(filename) as f: 32 | cache[filename] = f.read().splitlines() 33 | supp = cache[filename][int(line_num) - 1] 34 | if supp not in done: 35 | print(supp) 36 | done.add(supp) 37 | 38 | 39 | if __name__ == "__main__": 40 | run(args=sys.argv[1:]) 41 | -------------------------------------------------------------------------------- /pybind11/tools/libsize.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import os 4 | import sys 5 | 6 | # Internal build script for generating debugging test .so size. 7 | # Usage: 8 | # python libsize.py file.so save.txt -- displays the size of file.so and, if save.txt exists, compares it to the 9 | # size in it, then overwrites save.txt with the new size for future runs. 10 | 11 | if len(sys.argv) != 3: 12 | sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt") 13 | 14 | lib = sys.argv[1] 15 | save = sys.argv[2] 16 | 17 | if not os.path.exists(lib): 18 | sys.exit(f"Error: requested file ({lib}) does not exist") 19 | 20 | libsize = os.path.getsize(lib) 21 | 22 | print("------", os.path.basename(lib), "file size:", libsize, end="") 23 | 24 | if os.path.exists(save): 25 | with open(save) as sf: 26 | oldsize = int(sf.readline()) 27 | 28 | if oldsize > 0: 29 | change = libsize - oldsize 30 | if change == 0: 31 | print(" (no change)") 32 | else: 33 | print(f" (change of {change:+} bytes = {change / oldsize:+.2%})") 34 | else: 35 | print() 36 | 37 | with open(save, "w") as sf: 38 | sf.write(str(libsize)) 39 | -------------------------------------------------------------------------------- /pybind11/tools/make_changelog.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from __future__ import annotations 3 | 4 | import re 5 | 6 | import ghapi.all 7 | from rich import print 8 | from rich.syntax import Syntax 9 | 10 | ENTRY = re.compile( 11 | r""" 12 | Suggested \s changelog \s entry: 13 | .* 14 | ```rst 15 | \s* 16 | (.*?) 17 | \s* 18 | ``` 19 | """, 20 | re.DOTALL | re.VERBOSE, 21 | ) 22 | 23 | print() 24 | 25 | 26 | api = ghapi.all.GhApi(owner="pybind", repo="pybind11") 27 | 28 | issues_pages = ghapi.page.paged( 29 | api.issues.list_for_repo, labels="needs changelog", state="closed" 30 | ) 31 | issues = (issue for page in issues_pages for issue in page) 32 | missing = [] 33 | cats_descr = { 34 | "feat": "New Features", 35 | "feat(types)": "", 36 | "feat(cmake)": "", 37 | "fix": "Bug fixes", 38 | "fix(types)": "", 39 | "fix(cmake)": "", 40 | "docs": "Documentation", 41 | "tests": "Tests", 42 | "ci": "CI", 43 | "chore": "Other", 44 | "unknown": "Uncategorised", 45 | } 46 | cats: dict[str, list[str]] = {c: [] for c in cats_descr} 47 | 48 | for issue in issues: 49 | changelog = ENTRY.findall(issue.body or "") 50 | if not changelog or not changelog[0]: 51 | missing.append(issue) 52 | else: 53 | (msg,) = changelog 54 | if msg.startswith("- "): 55 | msg = msg[2:] 56 | if not msg.startswith("* "): 57 | msg = "* " + msg 58 | if not msg.endswith("."): 59 | msg += "." 60 | 61 | msg += f"\n `#{issue.number} <{issue.html_url}>`_" 62 | for cat in cats: 63 | if issue.title.lower().startswith(f"{cat}:"): 64 | cats[cat].append(msg) 65 | break 66 | else: 67 | cats["unknown"].append(msg) 68 | 69 | for cat, msgs in cats.items(): 70 | if msgs: 71 | desc = cats_descr[cat] 72 | print(f"[bold]{desc}:" if desc else f".. {cat}") 73 | print() 74 | for msg in msgs: 75 | print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True)) 76 | print() 77 | print() 78 | 79 | if missing: 80 | print() 81 | print("[blue]" + "-" * 30) 82 | print() 83 | 84 | for issue in missing: 85 | print(f"[red bold]Missing:[/red bold][red] {issue.title}") 86 | print(f"[red] {issue.html_url}\n") 87 | 88 | print("[bold]Template:\n") 89 | msg = "## Suggested changelog entry:\n\n```rst\n\n```" 90 | print(Syntax(msg, "md", theme="ansi_light")) 91 | 92 | print() 93 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pybind11/tools/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=42", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyparsing==3.1.1 2 | pytest>=6.2.4 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | """Setup file for the GTwrap package""" 2 | 3 | try: 4 | from setuptools import find_packages, setup 5 | except ImportError: 6 | from distutils.core import find_packages, setup 7 | 8 | packages = find_packages() 9 | 10 | setup( 11 | name='gtwrap', 12 | description='Library to wrap C++ with Python and Matlab', 13 | version='2.0.0', 14 | author="Frank Dellaert et. al.", 15 | author_email="dellaert@gatech.edu", 16 | license='BSD', 17 | keywords="wrap, bindings, cpp, python", 18 | long_description=open("README.md").read(), 19 | long_description_content_type="text/markdown", 20 | python_requires=">=3.5", 21 | # https://pypi.org/classifiers 22 | classifiers=[ 23 | 'Development Status :: 4 - Beta', 24 | 'Intended Audience :: Education', 25 | 'Intended Audience :: Developers', 26 | 'Intended Audience :: Science/Research', 27 | 'Operating System :: MacOS', 28 | 'Operating System :: Microsoft :: Windows', 29 | 'Operating System :: POSIX', 30 | 'Programming Language :: Python :: 3', 31 | 'Topic :: Software Development :: Libraries' 32 | ], 33 | packages=packages, 34 | platforms="any", 35 | install_requires=open("requirements.txt").readlines(), 36 | ) 37 | -------------------------------------------------------------------------------- /sphinx/index.rst: -------------------------------------------------------------------------------- 1 | pybind_wrapper Documentation 2 | ============================ 3 | 4 | Contents: 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | wrap 10 | 11 | -------------------------------------------------------------------------------- /sphinx/wrap.rst: -------------------------------------------------------------------------------- 1 | .. automodule:: python_example 2 | -------------------------------------------------------------------------------- /templates/matlab_wrapper.tpl.in: -------------------------------------------------------------------------------- 1 | #include <${GTWRAP_INCLUDE_NAME}/matlab.h> 2 | #include 3 | -------------------------------------------------------------------------------- /templates/pybind_wrapper.tpl.example: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "gtsam/base/serialization.h" 8 | #include "gtsam/base/utilities.h" // for RedirectCout. 9 | 10 | {includes} 11 | 12 | {boost_class_export} 13 | 14 | #include "python/preamble.h" 15 | 16 | using namespace std; 17 | 18 | namespace py = pybind11; 19 | 20 | {submodules} 21 | 22 | {module_def} {{ 23 | m_.doc() = "pybind11 wrapper of {module_name}"; 24 | 25 | {submodules_init} 26 | 27 | {wrapped_namespace} 28 | 29 | #include "python/specializations.h" 30 | 31 | }} 32 | 33 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | actual/** 2 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | gtsamAddTestsGlob(wrap "test*.cpp" "" "wrap_lib") 2 | -------------------------------------------------------------------------------- /tests/actual/.gitignore: -------------------------------------------------------------------------------- 1 | ./* 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/expected/matlab/+Pet/Kind.m: -------------------------------------------------------------------------------- 1 | classdef Kind < uint32 2 | enumeration 3 | Dog(0) 4 | Cat(1) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/+MCU/Avengers.m: -------------------------------------------------------------------------------- 1 | classdef Avengers < uint32 2 | enumeration 3 | CaptainAmerica(0) 4 | IronMan(1) 5 | Hulk(2) 6 | Hawkeye(3) 7 | Thor(4) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/+MCU/GotG.m: -------------------------------------------------------------------------------- 1 | classdef GotG < uint32 2 | enumeration 3 | Starlord(0) 4 | Gamorra(1) 5 | Rocket(2) 6 | Drax(3) 7 | Groot(4) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/+OptimizerGaussNewtonParams/Verbosity.m: -------------------------------------------------------------------------------- 1 | classdef Verbosity < uint32 2 | enumeration 3 | SILENT(0) 4 | SUMMARY(1) 5 | VERBOSE(2) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/Class1.m: -------------------------------------------------------------------------------- 1 | %class Class1, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %Class1() 6 | % 7 | classdef Class1 < handle 8 | properties 9 | ptr_gtsamClass1 = 0 10 | end 11 | methods 12 | function obj = Class1(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | multiple_files_wrapper(0, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = multiple_files_wrapper(1); 18 | else 19 | error('Arguments do not match any overload of gtsam.Class1 constructor'); 20 | end 21 | obj.ptr_gtsamClass1 = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | multiple_files_wrapper(2, obj.ptr_gtsamClass1); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/Class2.m: -------------------------------------------------------------------------------- 1 | %class Class2, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %Class2() 6 | % 7 | classdef Class2 < handle 8 | properties 9 | ptr_gtsamClass2 = 0 10 | end 11 | methods 12 | function obj = Class2(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | multiple_files_wrapper(3, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = multiple_files_wrapper(4); 18 | else 19 | error('Arguments do not match any overload of gtsam.Class2 constructor'); 20 | end 21 | obj.ptr_gtsamClass2 = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | multiple_files_wrapper(5, obj.ptr_gtsamClass2); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/ClassA.m: -------------------------------------------------------------------------------- 1 | %class ClassA, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %ClassA() 6 | % 7 | classdef ClassA < handle 8 | properties 9 | ptr_gtsamClassA = 0 10 | end 11 | methods 12 | function obj = ClassA(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | multiple_files_wrapper(6, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = multiple_files_wrapper(7); 18 | else 19 | error('Arguments do not match any overload of gtsam.ClassA constructor'); 20 | end 21 | obj.ptr_gtsamClassA = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | multiple_files_wrapper(8, obj.ptr_gtsamClassA); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/GeneralSFMFactorCal3Bundler.m: -------------------------------------------------------------------------------- 1 | %class GeneralSFMFactorCal3Bundler, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Properties------- 5 | %verbosity 6 | % 7 | classdef GeneralSFMFactorCal3Bundler < handle 8 | properties 9 | ptr_gtsamGeneralSFMFactorCal3Bundler = 0 10 | verbosity 11 | end 12 | methods 13 | function obj = GeneralSFMFactorCal3Bundler(varargin) 14 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 15 | my_ptr = varargin{2}; 16 | special_cases_wrapper(9, my_ptr); 17 | else 18 | error('Arguments do not match any overload of gtsam.GeneralSFMFactorCal3Bundler constructor'); 19 | end 20 | obj.ptr_gtsamGeneralSFMFactorCal3Bundler = my_ptr; 21 | end 22 | 23 | function delete(obj) 24 | special_cases_wrapper(10, obj.ptr_gtsamGeneralSFMFactorCal3Bundler); 25 | end 26 | 27 | function display(obj), obj.print(''); end 28 | %DISPLAY Calls print on the object 29 | function disp(obj), obj.display; end 30 | %DISP Calls print on the object 31 | 32 | function varargout = get.verbosity(this) 33 | varargout{1} = special_cases_wrapper(11, this); 34 | this.verbosity = varargout{1}; 35 | end 36 | 37 | function set.verbosity(this, value) 38 | obj.verbosity = value; 39 | special_cases_wrapper(12, this, value); 40 | end 41 | end 42 | 43 | methods(Static = true) 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/NonlinearFactorGraph.m: -------------------------------------------------------------------------------- 1 | %class NonlinearFactorGraph, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Methods------- 5 | %addPriorPinholeCameraCal3Bundler(size_t key, PinholeCamera prior, Base noiseModel) : returns void 6 | % 7 | classdef NonlinearFactorGraph < handle 8 | properties 9 | ptr_gtsamNonlinearFactorGraph = 0 10 | end 11 | methods 12 | function obj = NonlinearFactorGraph(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | special_cases_wrapper(0, my_ptr); 16 | else 17 | error('Arguments do not match any overload of gtsam.NonlinearFactorGraph constructor'); 18 | end 19 | obj.ptr_gtsamNonlinearFactorGraph = my_ptr; 20 | end 21 | 22 | function delete(obj) 23 | special_cases_wrapper(1, obj.ptr_gtsamNonlinearFactorGraph); 24 | end 25 | 26 | function display(obj), obj.print(''); end 27 | %DISPLAY Calls print on the object 28 | function disp(obj), obj.display; end 29 | %DISP Calls print on the object 30 | function varargout = addPriorPinholeCameraCal3Bundler(this, varargin) 31 | % ADDPRIORPINHOLECAMERACAL3BUNDLER usage: addPriorPinholeCameraCal3Bundler(size_t key, PinholeCamera prior, Base noiseModel) : returns void 32 | % Doxygen can be found at https://gtsam.org/doxygen/ 33 | if length(varargin) == 3 && isa(varargin{1},'numeric') && isa(varargin{2},'gtsam.PinholeCameraCal3Bundler') && isa(varargin{3},'gtsam.noiseModel.Base') 34 | special_cases_wrapper(2, this, varargin{:}); 35 | return 36 | end 37 | error('Arguments do not match any overload of function gtsam.NonlinearFactorGraph.addPriorPinholeCameraCal3Bundler'); 38 | end 39 | 40 | end 41 | 42 | methods(Static = true) 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/PinholeCameraCal3Bundler.m: -------------------------------------------------------------------------------- 1 | %class PinholeCameraCal3Bundler, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | classdef PinholeCameraCal3Bundler < handle 5 | properties 6 | ptr_gtsamPinholeCameraCal3Bundler = 0 7 | end 8 | methods 9 | function obj = PinholeCameraCal3Bundler(varargin) 10 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 11 | my_ptr = varargin{2}; 12 | special_cases_wrapper(7, my_ptr); 13 | else 14 | error('Arguments do not match any overload of gtsam.PinholeCameraCal3Bundler constructor'); 15 | end 16 | obj.ptr_gtsamPinholeCameraCal3Bundler = my_ptr; 17 | end 18 | 19 | function delete(obj) 20 | special_cases_wrapper(8, obj.ptr_gtsamPinholeCameraCal3Bundler); 21 | end 22 | 23 | function display(obj), obj.print(''); end 24 | %DISPLAY Calls print on the object 25 | function disp(obj), obj.display; end 26 | %DISP Calls print on the object 27 | end 28 | 29 | methods(Static = true) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/SfmTrack.m: -------------------------------------------------------------------------------- 1 | %class SfmTrack, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Properties------- 5 | %measurements 6 | % 7 | classdef SfmTrack < handle 8 | properties 9 | ptr_gtsamSfmTrack = 0 10 | measurements 11 | end 12 | methods 13 | function obj = SfmTrack(varargin) 14 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 15 | my_ptr = varargin{2}; 16 | special_cases_wrapper(3, my_ptr); 17 | else 18 | error('Arguments do not match any overload of gtsam.SfmTrack constructor'); 19 | end 20 | obj.ptr_gtsamSfmTrack = my_ptr; 21 | end 22 | 23 | function delete(obj) 24 | special_cases_wrapper(4, obj.ptr_gtsamSfmTrack); 25 | end 26 | 27 | function display(obj), obj.print(''); end 28 | %DISPLAY Calls print on the object 29 | function disp(obj), obj.display; end 30 | %DISP Calls print on the object 31 | 32 | function varargout = get.measurements(this) 33 | varargout{1} = special_cases_wrapper(5, this); 34 | this.measurements = varargout{1}; 35 | end 36 | 37 | function set.measurements(this, value) 38 | obj.measurements = value; 39 | special_cases_wrapper(6, this, value); 40 | end 41 | end 42 | 43 | methods(Static = true) 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/Values.m: -------------------------------------------------------------------------------- 1 | %class Values, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %Values() 6 | %Values(Values other) 7 | % 8 | %-------Methods------- 9 | %insert(size_t j, Vector vector) : returns void 10 | %insert(size_t j, Matrix matrix) : returns void 11 | % 12 | classdef Values < handle 13 | properties 14 | ptr_gtsamValues = 0 15 | end 16 | methods 17 | function obj = Values(varargin) 18 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 19 | my_ptr = varargin{2}; 20 | namespaces_wrapper(26, my_ptr); 21 | elseif nargin == 0 22 | my_ptr = namespaces_wrapper(27); 23 | elseif nargin == 1 && isa(varargin{1},'gtsam.Values') 24 | my_ptr = namespaces_wrapper(28, varargin{1}); 25 | else 26 | error('Arguments do not match any overload of gtsam.Values constructor'); 27 | end 28 | obj.ptr_gtsamValues = my_ptr; 29 | end 30 | 31 | function delete(obj) 32 | namespaces_wrapper(29, obj.ptr_gtsamValues); 33 | end 34 | 35 | function display(obj), obj.print(''); end 36 | %DISPLAY Calls print on the object 37 | function disp(obj), obj.display; end 38 | %DISP Calls print on the object 39 | function varargout = insert(this, varargin) 40 | % INSERT usage: insert(size_t j, Vector vector) : returns void 41 | % Doxygen can be found at https://gtsam.org/doxygen/ 42 | if length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'double') && size(varargin{2},2)==1 43 | namespaces_wrapper(30, this, varargin{:}); 44 | return 45 | end 46 | % INSERT usage: insert(size_t j, Matrix matrix) : returns void 47 | % Doxygen can be found at https://gtsam.org/doxygen/ 48 | if length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'double') 49 | namespaces_wrapper(31, this, varargin{:}); 50 | return 51 | end 52 | error('Arguments do not match any overload of function gtsam.Values.insert'); 53 | end 54 | 55 | end 56 | 57 | methods(Static = true) 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /tests/expected/matlab/+gtsam/VerbosityLM.m: -------------------------------------------------------------------------------- 1 | classdef VerbosityLM < uint32 2 | enumeration 3 | SILENT(0) 4 | SUMMARY(1) 5 | TERMINATION(2) 6 | LAMBDA(3) 7 | TRYLAMBDA(4) 8 | TRYCONFIG(5) 9 | DAMPED(6) 10 | TRYDELTA(7) 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /tests/expected/matlab/+ns1/ClassA.m: -------------------------------------------------------------------------------- 1 | %class ClassA, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %ClassA() 6 | % 7 | classdef ClassA < handle 8 | properties 9 | ptr_ns1ClassA = 0 10 | end 11 | methods 12 | function obj = ClassA(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | namespaces_wrapper(0, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = namespaces_wrapper(1); 18 | else 19 | error('Arguments do not match any overload of ns1.ClassA constructor'); 20 | end 21 | obj.ptr_ns1ClassA = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | namespaces_wrapper(2, obj.ptr_ns1ClassA); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/+ns1/ClassB.m: -------------------------------------------------------------------------------- 1 | %class ClassB, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %ClassB() 6 | % 7 | classdef ClassB < handle 8 | properties 9 | ptr_ns1ClassB = 0 10 | end 11 | methods 12 | function obj = ClassB(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | namespaces_wrapper(3, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = namespaces_wrapper(4); 18 | else 19 | error('Arguments do not match any overload of ns1.ClassB constructor'); 20 | end 21 | obj.ptr_ns1ClassB = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | namespaces_wrapper(5, obj.ptr_ns1ClassB); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/+ns1/aGlobalFunction.m: -------------------------------------------------------------------------------- 1 | function varargout = aGlobalFunction(varargin) 2 | if length(varargin) == 0 3 | varargout{1} = namespaces_wrapper(6, varargin{:}); 4 | else 5 | error('Arguments do not match any overload of function aGlobalFunction'); 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /tests/expected/matlab/+ns2/+ns3/ClassB.m: -------------------------------------------------------------------------------- 1 | %class ClassB, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %ClassB() 6 | % 7 | classdef ClassB < handle 8 | properties 9 | ptr_ns2ns3ClassB = 0 10 | end 11 | methods 12 | function obj = ClassB(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | namespaces_wrapper(14, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = namespaces_wrapper(15); 18 | else 19 | error('Arguments do not match any overload of ns2.ns3.ClassB constructor'); 20 | end 21 | obj.ptr_ns2ns3ClassB = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | namespaces_wrapper(16, obj.ptr_ns2ns3ClassB); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/+ns2/ClassC.m: -------------------------------------------------------------------------------- 1 | %class ClassC, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %ClassC() 6 | % 7 | classdef ClassC < handle 8 | properties 9 | ptr_ns2ClassC = 0 10 | end 11 | methods 12 | function obj = ClassC(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | namespaces_wrapper(17, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = namespaces_wrapper(18); 18 | else 19 | error('Arguments do not match any overload of ns2.ClassC constructor'); 20 | end 21 | obj.ptr_ns2ClassC = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | namespaces_wrapper(19, obj.ptr_ns2ClassC); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/+ns2/aGlobalFunction.m: -------------------------------------------------------------------------------- 1 | function varargout = aGlobalFunction(varargin) 2 | if length(varargin) == 0 3 | varargout{1} = namespaces_wrapper(20, varargin{:}); 4 | else 5 | error('Arguments do not match any overload of function aGlobalFunction'); 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /tests/expected/matlab/+ns2/overloadedGlobalFunction.m: -------------------------------------------------------------------------------- 1 | function varargout = overloadedGlobalFunction(varargin) 2 | if length(varargin) == 1 && isa(varargin{1},'ns1.ClassA') 3 | varargout{1} = namespaces_wrapper(21, varargin{:}); 4 | elseif length(varargin) == 2 && isa(varargin{1},'ns1.ClassA') && isa(varargin{2},'double') 5 | varargout{1} = namespaces_wrapper(22, varargin{:}); 6 | else 7 | error('Arguments do not match any overload of function overloadedGlobalFunction'); 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /tests/expected/matlab/ClassD.m: -------------------------------------------------------------------------------- 1 | %class ClassD, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %ClassD() 6 | % 7 | classdef ClassD < handle 8 | properties 9 | ptr_ClassD = 0 10 | end 11 | methods 12 | function obj = ClassD(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | namespaces_wrapper(23, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = namespaces_wrapper(24); 18 | else 19 | error('Arguments do not match any overload of ClassD constructor'); 20 | end 21 | obj.ptr_ClassD = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | namespaces_wrapper(25, obj.ptr_ClassD); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/Color.m: -------------------------------------------------------------------------------- 1 | classdef Color < uint32 2 | enumeration 3 | Red(0) 4 | Green(1) 5 | Blue(2) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /tests/expected/matlab/DefaultFuncInt.m: -------------------------------------------------------------------------------- 1 | function varargout = DefaultFuncInt(varargin) 2 | if length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') 3 | functions_wrapper(8, varargin{:}); 4 | elseif length(varargin) == 1 && isa(varargin{1},'numeric') 5 | functions_wrapper(9, varargin{:}); 6 | elseif length(varargin) == 0 7 | functions_wrapper(10, varargin{:}); 8 | else 9 | error('Arguments do not match any overload of function DefaultFuncInt'); 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /tests/expected/matlab/DefaultFuncObj.m: -------------------------------------------------------------------------------- 1 | function varargout = DefaultFuncObj(varargin) 2 | if length(varargin) == 1 && isa(varargin{1},'gtsam.KeyFormatter') 3 | functions_wrapper(14, varargin{:}); 4 | elseif length(varargin) == 0 5 | functions_wrapper(15, varargin{:}); 6 | else 7 | error('Arguments do not match any overload of function DefaultFuncObj'); 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /tests/expected/matlab/DefaultFuncString.m: -------------------------------------------------------------------------------- 1 | function varargout = DefaultFuncString(varargin) 2 | if length(varargin) == 2 && isa(varargin{1},'char') && isa(varargin{2},'char') 3 | functions_wrapper(11, varargin{:}); 4 | elseif length(varargin) == 1 && isa(varargin{1},'char') 5 | functions_wrapper(12, varargin{:}); 6 | elseif length(varargin) == 0 7 | functions_wrapper(13, varargin{:}); 8 | else 9 | error('Arguments do not match any overload of function DefaultFuncString'); 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /tests/expected/matlab/DefaultFuncVector.m: -------------------------------------------------------------------------------- 1 | function varargout = DefaultFuncVector(varargin) 2 | if length(varargin) == 2 && isa(varargin{1},'std.vectornumeric') && isa(varargin{2},'std.vectorchar') 3 | functions_wrapper(20, varargin{:}); 4 | elseif length(varargin) == 1 && isa(varargin{1},'std.vectornumeric') 5 | functions_wrapper(21, varargin{:}); 6 | elseif length(varargin) == 0 7 | functions_wrapper(22, varargin{:}); 8 | else 9 | error('Arguments do not match any overload of function DefaultFuncVector'); 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /tests/expected/matlab/DefaultFuncZero.m: -------------------------------------------------------------------------------- 1 | function varargout = DefaultFuncZero(varargin) 2 | if length(varargin) == 5 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') && isa(varargin{4},'numeric') && isa(varargin{5},'logical') 3 | functions_wrapper(16, varargin{:}); 4 | elseif length(varargin) == 4 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') && isa(varargin{4},'numeric') 5 | functions_wrapper(17, varargin{:}); 6 | elseif length(varargin) == 3 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') 7 | functions_wrapper(18, varargin{:}); 8 | elseif length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') 9 | functions_wrapper(19, varargin{:}); 10 | else 11 | error('Arguments do not match any overload of function DefaultFuncZero'); 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /tests/expected/matlab/FastSet.m: -------------------------------------------------------------------------------- 1 | %class FastSet, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %FastSet() 6 | % 7 | classdef FastSet < handle 8 | properties 9 | ptr_FastSet = 0 10 | end 11 | methods 12 | function obj = FastSet(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | class_wrapper(73, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = class_wrapper(74); 18 | else 19 | error('Arguments do not match any overload of FastSet constructor'); 20 | end 21 | obj.ptr_FastSet = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | class_wrapper(75, obj.ptr_FastSet); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/ForwardKinematics.m: -------------------------------------------------------------------------------- 1 | %class ForwardKinematics, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %ForwardKinematics(Robot robot, string start_link_name, string end_link_name, Values joint_angles, Pose3 l2Tp) 6 | % 7 | classdef ForwardKinematics < handle 8 | properties 9 | ptr_ForwardKinematics = 0 10 | end 11 | methods 12 | function obj = ForwardKinematics(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | class_wrapper(63, my_ptr); 16 | elseif nargin == 5 && isa(varargin{1},'gtdynamics.Robot') && isa(varargin{2},'char') && isa(varargin{3},'char') && isa(varargin{4},'gtsam.Values') && isa(varargin{5},'gtsam.Pose3') 17 | my_ptr = class_wrapper(64, varargin{1}, varargin{2}, varargin{3}, varargin{4}, varargin{5}); 18 | elseif nargin == 4 && isa(varargin{1},'gtdynamics.Robot') && isa(varargin{2},'char') && isa(varargin{3},'char') && isa(varargin{4},'gtsam.Values') 19 | my_ptr = class_wrapper(65, varargin{1}, varargin{2}, varargin{3}, varargin{4}); 20 | else 21 | error('Arguments do not match any overload of ForwardKinematics constructor'); 22 | end 23 | obj.ptr_ForwardKinematics = my_ptr; 24 | end 25 | 26 | function delete(obj) 27 | class_wrapper(66, obj.ptr_ForwardKinematics); 28 | end 29 | 30 | function display(obj), obj.print(''); end 31 | %DISPLAY Calls print on the object 32 | function disp(obj), obj.display; end 33 | %DISP Calls print on the object 34 | end 35 | 36 | methods(Static = true) 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /tests/expected/matlab/ForwardKinematicsFactor.m: -------------------------------------------------------------------------------- 1 | %class ForwardKinematicsFactor, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | classdef ForwardKinematicsFactor < gtsam.BetweenFactor 5 | properties 6 | ptr_ForwardKinematicsFactor = 0 7 | end 8 | methods 9 | function obj = ForwardKinematicsFactor(varargin) 10 | if (nargin == 2 || (nargin == 3 && strcmp(varargin{3}, 'void'))) && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 11 | if nargin == 2 12 | my_ptr = varargin{2}; 13 | else 14 | my_ptr = inheritance_wrapper(52, varargin{2}); 15 | end 16 | base_ptr = inheritance_wrapper(51, my_ptr); 17 | else 18 | error('Arguments do not match any overload of ForwardKinematicsFactor constructor'); 19 | end 20 | obj = obj@gtsam.BetweenFactorPose3(uint64(5139824614673773682), base_ptr); 21 | obj.ptr_ForwardKinematicsFactor = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | inheritance_wrapper(53, obj.ptr_ForwardKinematicsFactor); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/FunRange.m: -------------------------------------------------------------------------------- 1 | %class FunRange, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %FunRange() 6 | % 7 | %-------Methods------- 8 | %range(double d) : returns FunRange 9 | % 10 | %-------Static Methods------- 11 | %create() : returns FunRange 12 | % 13 | %-------Serialization Interface------- 14 | %string_serialize() : returns string 15 | %string_deserialize(string serialized) : returns FunRange 16 | % 17 | classdef FunRange < handle 18 | properties 19 | ptr_FunRange = 0 20 | end 21 | methods 22 | function obj = FunRange(varargin) 23 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 24 | my_ptr = varargin{2}; 25 | class_wrapper(0, my_ptr); 26 | elseif nargin == 0 27 | my_ptr = class_wrapper(1); 28 | else 29 | error('Arguments do not match any overload of FunRange constructor'); 30 | end 31 | obj.ptr_FunRange = my_ptr; 32 | end 33 | 34 | function delete(obj) 35 | class_wrapper(2, obj.ptr_FunRange); 36 | end 37 | 38 | function display(obj), obj.print(''); end 39 | %DISPLAY Calls print on the object 40 | function disp(obj), obj.display; end 41 | %DISP Calls print on the object 42 | function varargout = range(this, varargin) 43 | % RANGE usage: range(double d) : returns FunRange 44 | % Doxygen can be found at https://gtsam.org/doxygen/ 45 | if length(varargin) == 1 && isa(varargin{1},'double') 46 | varargout{1} = class_wrapper(3, this, varargin{:}); 47 | return 48 | end 49 | error('Arguments do not match any overload of function FunRange.range'); 50 | end 51 | 52 | end 53 | 54 | methods(Static = true) 55 | function varargout = create(varargin) 56 | % CREATE usage: create() : returns FunRange 57 | % Doxygen can be found at https://gtsam.org/doxygen/ 58 | if length(varargin) == 0 59 | varargout{1} = class_wrapper(4, varargin{:}); 60 | return 61 | end 62 | 63 | error('Arguments do not match any overload of function FunRange.create'); 64 | end 65 | 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /tests/expected/matlab/MultiTemplatedFunctionDoubleSize_tDouble.m: -------------------------------------------------------------------------------- 1 | function varargout = MultiTemplatedFunctionDoubleSize_tDouble(varargin) 2 | if length(varargin) == 2 && isa(varargin{1},'T') && isa(varargin{2},'numeric') 3 | varargout{1} = functions_wrapper(7, varargin{:}); 4 | else 5 | error('Arguments do not match any overload of function MultiTemplatedFunctionDoubleSize_tDouble'); 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /tests/expected/matlab/MultiTemplatedFunctionStringSize_tDouble.m: -------------------------------------------------------------------------------- 1 | function varargout = MultiTemplatedFunctionStringSize_tDouble(varargin) 2 | if length(varargin) == 2 && isa(varargin{1},'T') && isa(varargin{2},'numeric') 3 | varargout{1} = functions_wrapper(6, varargin{:}); 4 | else 5 | error('Arguments do not match any overload of function MultiTemplatedFunctionStringSize_tDouble'); 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /tests/expected/matlab/MultipleTemplatesIntDouble.m: -------------------------------------------------------------------------------- 1 | %class MultipleTemplatesIntDouble, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | classdef MultipleTemplatesIntDouble < handle 5 | properties 6 | ptr_MultipleTemplatesIntDouble = 0 7 | end 8 | methods 9 | function obj = MultipleTemplatesIntDouble(varargin) 10 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 11 | my_ptr = varargin{2}; 12 | class_wrapper(59, my_ptr); 13 | else 14 | error('Arguments do not match any overload of MultipleTemplatesIntDouble constructor'); 15 | end 16 | obj.ptr_MultipleTemplatesIntDouble = my_ptr; 17 | end 18 | 19 | function delete(obj) 20 | class_wrapper(60, obj.ptr_MultipleTemplatesIntDouble); 21 | end 22 | 23 | function display(obj), obj.print(''); end 24 | %DISPLAY Calls print on the object 25 | function disp(obj), obj.display; end 26 | %DISP Calls print on the object 27 | end 28 | 29 | methods(Static = true) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /tests/expected/matlab/MultipleTemplatesIntFloat.m: -------------------------------------------------------------------------------- 1 | %class MultipleTemplatesIntFloat, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | classdef MultipleTemplatesIntFloat < handle 5 | properties 6 | ptr_MultipleTemplatesIntFloat = 0 7 | end 8 | methods 9 | function obj = MultipleTemplatesIntFloat(varargin) 10 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 11 | my_ptr = varargin{2}; 12 | class_wrapper(61, my_ptr); 13 | else 14 | error('Arguments do not match any overload of MultipleTemplatesIntFloat constructor'); 15 | end 16 | obj.ptr_MultipleTemplatesIntFloat = my_ptr; 17 | end 18 | 19 | function delete(obj) 20 | class_wrapper(62, obj.ptr_MultipleTemplatesIntFloat); 21 | end 22 | 23 | function display(obj), obj.print(''); end 24 | %DISPLAY Calls print on the object 25 | function disp(obj), obj.display; end 26 | %DISP Calls print on the object 27 | end 28 | 29 | methods(Static = true) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /tests/expected/matlab/MyBase.m: -------------------------------------------------------------------------------- 1 | %class MyBase, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | classdef MyBase < handle 5 | properties 6 | ptr_MyBase = 0 7 | end 8 | methods 9 | function obj = MyBase(varargin) 10 | if (nargin == 2 || (nargin == 3 && strcmp(varargin{3}, 'void'))) && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 11 | if nargin == 2 12 | my_ptr = varargin{2}; 13 | else 14 | my_ptr = inheritance_wrapper(1, varargin{2}); 15 | end 16 | inheritance_wrapper(0, my_ptr); 17 | else 18 | error('Arguments do not match any overload of MyBase constructor'); 19 | end 20 | obj.ptr_MyBase = my_ptr; 21 | end 22 | 23 | function delete(obj) 24 | inheritance_wrapper(2, obj.ptr_MyBase); 25 | end 26 | 27 | function display(obj), obj.print(''); end 28 | %DISPLAY Calls print on the object 29 | function disp(obj), obj.display; end 30 | %DISP Calls print on the object 31 | end 32 | 33 | methods(Static = true) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /tests/expected/matlab/MyFactorPosePoint2.m: -------------------------------------------------------------------------------- 1 | %class MyFactorPosePoint2, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %MyFactorPosePoint2(size_t key1, size_t key2, double measured, Base noiseModel) 6 | % 7 | %-------Methods------- 8 | %print(string s, KeyFormatter keyFormatter) : returns void 9 | % 10 | classdef MyFactorPosePoint2 < handle 11 | properties 12 | ptr_MyFactorPosePoint2 = 0 13 | end 14 | methods 15 | function obj = MyFactorPosePoint2(varargin) 16 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 17 | my_ptr = varargin{2}; 18 | class_wrapper(80, my_ptr); 19 | elseif nargin == 4 && isa(varargin{1},'numeric') && isa(varargin{2},'numeric') && isa(varargin{3},'double') && isa(varargin{4},'gtsam.noiseModel.Base') 20 | my_ptr = class_wrapper(81, varargin{1}, varargin{2}, varargin{3}, varargin{4}); 21 | else 22 | error('Arguments do not match any overload of MyFactorPosePoint2 constructor'); 23 | end 24 | obj.ptr_MyFactorPosePoint2 = my_ptr; 25 | end 26 | 27 | function delete(obj) 28 | class_wrapper(82, obj.ptr_MyFactorPosePoint2); 29 | end 30 | 31 | function display(obj), obj.print(''); end 32 | %DISPLAY Calls print on the object 33 | function disp(obj), obj.display; end 34 | %DISP Calls print on the object 35 | function varargout = print(this, varargin) 36 | % PRINT usage: print(string s, KeyFormatter keyFormatter) : returns void 37 | % Doxygen can be found at https://gtsam.org/doxygen/ 38 | if length(varargin) == 2 && isa(varargin{1},'char') && isa(varargin{2},'gtsam.KeyFormatter') 39 | class_wrapper(83, this, varargin{:}); 40 | return 41 | end 42 | % PRINT usage: print(string s) : returns void 43 | % Doxygen can be found at https://gtsam.org/doxygen/ 44 | if length(varargin) == 1 && isa(varargin{1},'char') 45 | class_wrapper(84, this, varargin{:}); 46 | return 47 | end 48 | % PRINT usage: print() : returns void 49 | % Doxygen can be found at https://gtsam.org/doxygen/ 50 | if length(varargin) == 0 51 | class_wrapper(85, this, varargin{:}); 52 | return 53 | end 54 | error('Arguments do not match any overload of function MyFactorPosePoint2.print'); 55 | end 56 | 57 | end 58 | 59 | methods(Static = true) 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /tests/expected/matlab/MyVector12.m: -------------------------------------------------------------------------------- 1 | %class MyVector12, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %MyVector12() 6 | % 7 | classdef MyVector12 < handle 8 | properties 9 | ptr_MyVector12 = 0 10 | end 11 | methods 12 | function obj = MyVector12(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | class_wrapper(56, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = class_wrapper(57); 18 | else 19 | error('Arguments do not match any overload of MyVector12 constructor'); 20 | end 21 | obj.ptr_MyVector12 = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | class_wrapper(58, obj.ptr_MyVector12); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/MyVector3.m: -------------------------------------------------------------------------------- 1 | %class MyVector3, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %MyVector3() 6 | % 7 | classdef MyVector3 < handle 8 | properties 9 | ptr_MyVector3 = 0 10 | end 11 | methods 12 | function obj = MyVector3(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | class_wrapper(53, my_ptr); 16 | elseif nargin == 0 17 | my_ptr = class_wrapper(54); 18 | else 19 | error('Arguments do not match any overload of MyVector3 constructor'); 20 | end 21 | obj.ptr_MyVector3 = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | class_wrapper(55, obj.ptr_MyVector3); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/PrimitiveRefDouble.m: -------------------------------------------------------------------------------- 1 | %class PrimitiveRefDouble, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %PrimitiveRefDouble() 6 | % 7 | %-------Static Methods------- 8 | %Brutal(double t) : returns PrimitiveRef 9 | % 10 | %-------Serialization Interface------- 11 | %string_serialize() : returns string 12 | %string_deserialize(string serialized) : returns PrimitiveRefDouble 13 | % 14 | classdef PrimitiveRefDouble < handle 15 | properties 16 | ptr_PrimitiveRefDouble = 0 17 | end 18 | methods 19 | function obj = PrimitiveRefDouble(varargin) 20 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 21 | my_ptr = varargin{2}; 22 | class_wrapper(49, my_ptr); 23 | elseif nargin == 0 24 | my_ptr = class_wrapper(50); 25 | else 26 | error('Arguments do not match any overload of PrimitiveRefDouble constructor'); 27 | end 28 | obj.ptr_PrimitiveRefDouble = my_ptr; 29 | end 30 | 31 | function delete(obj) 32 | class_wrapper(51, obj.ptr_PrimitiveRefDouble); 33 | end 34 | 35 | function display(obj), obj.print(''); end 36 | %DISPLAY Calls print on the object 37 | function disp(obj), obj.display; end 38 | %DISP Calls print on the object 39 | end 40 | 41 | methods(Static = true) 42 | function varargout = Brutal(varargin) 43 | % BRUTAL usage: Brutal(double t) : returns PrimitiveRefdouble 44 | % Doxygen can be found at https://gtsam.org/doxygen/ 45 | if length(varargin) == 1 && isa(varargin{1},'double') 46 | varargout{1} = class_wrapper(52, varargin{:}); 47 | return 48 | end 49 | 50 | error('Arguments do not match any overload of function PrimitiveRefDouble.Brutal'); 51 | end 52 | 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /tests/expected/matlab/ScopedTemplateResult.m: -------------------------------------------------------------------------------- 1 | %class ScopedTemplateResult, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %ScopedTemplateResult(Result::Value arg) 6 | % 7 | classdef ScopedTemplateResult < handle 8 | properties 9 | ptr_ScopedTemplateResult = 0 10 | end 11 | methods 12 | function obj = ScopedTemplateResult(varargin) 13 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 14 | my_ptr = varargin{2}; 15 | template_wrapper(6, my_ptr); 16 | elseif nargin == 1 && isa(varargin{1},'Result::Value') 17 | my_ptr = template_wrapper(7, varargin{1}); 18 | else 19 | error('Arguments do not match any overload of ScopedTemplateResult constructor'); 20 | end 21 | obj.ptr_ScopedTemplateResult = my_ptr; 22 | end 23 | 24 | function delete(obj) 25 | template_wrapper(8, obj.ptr_ScopedTemplateResult); 26 | end 27 | 28 | function display(obj), obj.print(''); end 29 | %DISPLAY Calls print on the object 30 | function disp(obj), obj.display; end 31 | %DISP Calls print on the object 32 | end 33 | 34 | methods(Static = true) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /tests/expected/matlab/TemplatedConstructor.m: -------------------------------------------------------------------------------- 1 | %class TemplatedConstructor, see Doxygen page for details 2 | %at https://gtsam.org/doxygen/ 3 | % 4 | %-------Constructors------- 5 | %TemplatedConstructor() 6 | %TemplatedConstructor(string arg) 7 | %TemplatedConstructor(int arg) 8 | %TemplatedConstructor(double arg) 9 | % 10 | classdef TemplatedConstructor < handle 11 | properties 12 | ptr_TemplatedConstructor = 0 13 | end 14 | methods 15 | function obj = TemplatedConstructor(varargin) 16 | if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682) 17 | my_ptr = varargin{2}; 18 | template_wrapper(0, my_ptr); 19 | elseif nargin == 0 20 | my_ptr = template_wrapper(1); 21 | elseif nargin == 1 && isa(varargin{1},'char') 22 | my_ptr = template_wrapper(2, varargin{1}); 23 | elseif nargin == 1 && isa(varargin{1},'numeric') 24 | my_ptr = template_wrapper(3, varargin{1}); 25 | elseif nargin == 1 && isa(varargin{1},'double') 26 | my_ptr = template_wrapper(4, varargin{1}); 27 | else 28 | error('Arguments do not match any overload of TemplatedConstructor constructor'); 29 | end 30 | obj.ptr_TemplatedConstructor = my_ptr; 31 | end 32 | 33 | function delete(obj) 34 | template_wrapper(5, obj.ptr_TemplatedConstructor); 35 | end 36 | 37 | function display(obj), obj.print(''); end 38 | %DISPLAY Calls print on the object 39 | function disp(obj), obj.display; end 40 | %DISP Calls print on the object 41 | end 42 | 43 | methods(Static = true) 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /tests/expected/matlab/TemplatedFunctionRot3.m: -------------------------------------------------------------------------------- 1 | function varargout = TemplatedFunctionRot3(varargin) 2 | if length(varargin) == 1 && isa(varargin{1},'gtsam.Rot3') 3 | functions_wrapper(26, varargin{:}); 4 | else 5 | error('Arguments do not match any overload of function TemplatedFunctionRot3'); 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /tests/expected/matlab/aGlobalFunction.m: -------------------------------------------------------------------------------- 1 | function varargout = aGlobalFunction(varargin) 2 | if length(varargin) == 0 3 | varargout{1} = functions_wrapper(3, varargin{:}); 4 | else 5 | error('Arguments do not match any overload of function aGlobalFunction'); 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /tests/expected/matlab/load2D.m: -------------------------------------------------------------------------------- 1 | function varargout = load2D(varargin) 2 | if length(varargin) == 5 && isa(varargin{1},'char') && isa(varargin{2},'Test') && isa(varargin{3},'numeric') && isa(varargin{4},'logical') && isa(varargin{5},'logical') 3 | [ varargout{1} varargout{2} ] = functions_wrapper(0, varargin{:}); 4 | elseif length(varargin) == 5 && isa(varargin{1},'char') && isa(varargin{2},'gtsam.noiseModel.Diagonal') && isa(varargin{3},'numeric') && isa(varargin{4},'logical') && isa(varargin{5},'logical') 5 | [ varargout{1} varargout{2} ] = functions_wrapper(1, varargin{:}); 6 | elseif length(varargin) == 2 && isa(varargin{1},'char') && isa(varargin{2},'gtsam.noiseModel.Diagonal') 7 | [ varargout{1} varargout{2} ] = functions_wrapper(2, varargin{:}); 8 | else 9 | error('Arguments do not match any overload of function load2D'); 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /tests/expected/matlab/overloadedGlobalFunction.m: -------------------------------------------------------------------------------- 1 | function varargout = overloadedGlobalFunction(varargin) 2 | if length(varargin) == 1 && isa(varargin{1},'numeric') 3 | varargout{1} = functions_wrapper(4, varargin{:}); 4 | elseif length(varargin) == 2 && isa(varargin{1},'numeric') && isa(varargin{2},'double') 5 | varargout{1} = functions_wrapper(5, varargin{:}); 6 | else 7 | error('Arguments do not match any overload of function overloadedGlobalFunction'); 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /tests/expected/matlab/setPose.m: -------------------------------------------------------------------------------- 1 | function varargout = setPose(varargin) 2 | if length(varargin) == 1 && isa(varargin{1},'gtsam.Pose3') 3 | functions_wrapper(23, varargin{:}); 4 | elseif length(varargin) == 0 5 | functions_wrapper(24, varargin{:}); 6 | else 7 | error('Arguments do not match any overload of function setPose'); 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /tests/expected/python/operator_pybind.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "gtsam/nonlinear/utilities.h" // for RedirectCout. 6 | 7 | #include "gtsam/geometry/Pose3.h" 8 | 9 | 10 | 11 | 12 | using namespace std; 13 | 14 | namespace py = pybind11; 15 | 16 | PYBIND11_MODULE(operator_py, m_) { 17 | m_.doc() = "pybind11 wrapper of operator_py"; 18 | 19 | pybind11::module m_gtsam = m_.def_submodule("gtsam", "gtsam submodule"); 20 | 21 | py::class_>(m_gtsam, "Pose3") 22 | .def(py::init<>()) 23 | .def(py::init(), py::arg("R"), py::arg("t")) 24 | .def(py::self * py::self); 25 | 26 | py::class_, std::shared_ptr>>(m_gtsam, "ContainerMatrix") 27 | .def("__call__", >sam::Container::operator()) 28 | .def("__getitem__", >sam::Container::operator[]); 29 | 30 | 31 | #include "python/specializations.h" 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /tests/expected/python/special_cases_pybind.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "gtsam/nonlinear/utilities.h" // for RedirectCout. 6 | 7 | #include "gtsam/geometry/Cal3Bundler.h" 8 | 9 | 10 | 11 | 12 | using namespace std; 13 | 14 | namespace py = pybind11; 15 | 16 | PYBIND11_MODULE(special_cases_py, m_) { 17 | m_.doc() = "pybind11 wrapper of special_cases_py"; 18 | 19 | pybind11::module m_gtsam = m_.def_submodule("gtsam", "gtsam submodule"); 20 | 21 | py::class_>(m_gtsam, "NonlinearFactorGraph") 22 | .def("addPriorPinholeCameraCal3Bundler",[](gtsam::NonlinearFactorGraph* self, size_t key, const gtsam::PinholeCamera& prior, const std::shared_ptr noiseModel){ self->addPrior>(key, prior, noiseModel);}, py::arg("key"), py::arg("prior"), py::arg("noiseModel")); 23 | 24 | py::class_>(m_gtsam, "SfmTrack") 25 | .def_readwrite("measurements", >sam::SfmTrack::measurements); 26 | 27 | py::class_, std::shared_ptr>>(m_gtsam, "PinholeCameraCal3Bundler"); 28 | 29 | py::class_, gtsam::Point3>, std::shared_ptr, gtsam::Point3>>> generalsfmfactorcal3bundler(m_gtsam, "GeneralSFMFactorCal3Bundler"); 30 | generalsfmfactorcal3bundler 31 | .def_readwrite("verbosity", >sam::GeneralSFMFactor, gtsam::Point3>::verbosity); 32 | 33 | py::enum_, gtsam::Point3>::Verbosity>(generalsfmfactorcal3bundler, "Verbosity", py::arithmetic()) 34 | .value("SILENT", gtsam::GeneralSFMFactor, gtsam::Point3>::Verbosity::SILENT) 35 | .value("SUMMARY", gtsam::GeneralSFMFactor, gtsam::Point3>::Verbosity::SUMMARY) 36 | .value("VALUES", gtsam::GeneralSFMFactor, gtsam::Point3>::Verbosity::VALUES); 37 | 38 | 39 | 40 | #include "python/specializations.h" 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /tests/expected/python/templates_pybind.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "gtsam/nonlinear/utilities.h" // for RedirectCout. 6 | 7 | 8 | 9 | 10 | 11 | using namespace std; 12 | 13 | namespace py = pybind11; 14 | 15 | PYBIND11_MODULE(templates_py, m_) { 16 | m_.doc() = "pybind11 wrapper of templates_py"; 17 | 18 | 19 | py::class_>(m_, "TemplatedConstructor") 20 | .def(py::init<>()) 21 | .def(py::init(), py::arg("arg")) 22 | .def(py::init(), py::arg("arg")) 23 | .def(py::init(), py::arg("arg")); 24 | 25 | py::class_, std::shared_ptr>>(m_, "ScopedTemplateResult") 26 | .def(py::init(), py::arg("arg")); 27 | 28 | 29 | #include "python/specializations.h" 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /tests/expected/xml/combine.xslt: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/expected/xml/deprecated.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | deprecated 5 | Deprecated List 6 | 7 | 8 | Member ADD_CLONE_NONLINEAR_FACTOR (Derived) 9 | : will go away shortly - just add the clone function directly 10 | Member gtsam::NoiseModelFactor::get_noiseModel () const 11 | access to the noise model 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tests/expected/xml/dir_59425e443f801f1f2fd8bbe4959a3ccf.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tests 5 | tests/doc-test-files 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tests/expected/xml/dir_e4787312bc569bb879bb1171628269de.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tests/doc-test-files 5 | JacobianFactorQ.h 6 | NonlinearFactor.h 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/expected/xml/namespacegtsam.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | gtsam 5 | gtsam::JacobianFactorQ 6 | gtsam::NoiseModelFactor 7 | gtsam::NoiseModelFactor1 8 | gtsam::NoiseModelFactor2 9 | gtsam::NoiseModelFactor3 10 | gtsam::NoiseModelFactor4 11 | gtsam::NoiseModelFactor5 12 | gtsam::NoiseModelFactor6 13 | gtsam::NonlinearFactor 14 | gtsam::traits< JacobianFactorQ< D, ZDim > > 15 | gtsam::traits< NonlinearFactor > 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/expected/xml/structgtsam_1_1traits_3_01JacobianFactorQ_3_01D_00_01ZDim_01_4_01_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | gtsam::traits< JacobianFactorQ< D, ZDim > > 5 | Testable< JacobianFactorQ< D, ZDim > > 6 | 7 | 8 | size_t 9 | D 10 | D 11 | 12 | 13 | size_t 14 | ZDim 15 | ZDim 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /tests/expected/xml/structgtsam_1_1traits_3_01NonlinearFactor_01_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | gtsam::traits< NonlinearFactor > 5 | Testable< NonlinearFactor > 6 | NonlinearFactor.h 7 | 8 | 9 | 10 | traits 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /tests/fixtures/enum.i: -------------------------------------------------------------------------------- 1 | enum Color { Red, Green, Blue }; 2 | 3 | class Pet { 4 | enum Kind { Dog, Cat }; 5 | 6 | Pet(const string &name, Pet::Kind type); 7 | void setColor(const Color& color); 8 | Color getColor() const; 9 | 10 | string name; 11 | Pet::Kind type; 12 | }; 13 | 14 | namespace gtsam { 15 | // Test global enums 16 | enum VerbosityLM { 17 | SILENT, 18 | SUMMARY, 19 | TERMINATION, 20 | LAMBDA, 21 | TRYLAMBDA, 22 | TRYCONFIG, 23 | DAMPED, 24 | TRYDELTA 25 | }; 26 | 27 | // Test multiple enums in a classs 28 | class MCU { 29 | MCU(); 30 | 31 | enum Avengers { 32 | CaptainAmerica, 33 | IronMan, 34 | Hulk, 35 | Hawkeye, 36 | Thor 37 | }; 38 | 39 | enum GotG { 40 | Starlord, 41 | Gamorra, 42 | Rocket, 43 | Drax, 44 | Groot 45 | }; 46 | 47 | }; 48 | 49 | template 50 | class Optimizer { 51 | enum Verbosity { 52 | SILENT, 53 | SUMMARY, 54 | VERBOSE 55 | }; 56 | 57 | Optimizer(const This::Verbosity& verbosity); 58 | 59 | void setVerbosity(const This::Verbosity value); 60 | 61 | gtsam::Optimizer::Verbosity getVerbosity() const; 62 | gtsam::VerbosityLM getVerbosity() const; 63 | }; 64 | 65 | typedef gtsam::Optimizer OptimizerGaussNewtonParams; 66 | 67 | } // namespace gtsam 68 | -------------------------------------------------------------------------------- /tests/fixtures/functions.i: -------------------------------------------------------------------------------- 1 | /** 2 | * A multi-line comment! 3 | */ 4 | // another comment 5 | 6 | class gtsam::NonlinearFactorGraph; 7 | class gtsam::Values; 8 | class gtsam::noiseModel::Diagonal; 9 | 10 | pair load2D(string filename, Test* model, int maxID, bool addNoise, bool smart); 11 | pair load2D(string filename, const gtsam::noiseModel::Diagonal* model, int maxID, bool addNoise, bool smart); 12 | pair load2D(string filename, gtsam::noiseModel::Diagonal@ model); 13 | 14 | gtsam::Vector aGlobalFunction(); 15 | 16 | // An overloaded global function 17 | gtsam::Vector overloadedGlobalFunction(int a); 18 | gtsam::Vector overloadedGlobalFunction(int a, double b); 19 | 20 | // A templated free/global function. Multiple templates supported. 21 | template 22 | R MultiTemplatedFunction(const T& x, T2 y); 23 | 24 | // Check if we can typedef the templated function 25 | template 26 | void TemplatedFunction(const T& t); 27 | 28 | typedef TemplatedFunction TemplatedFunctionRot3; 29 | 30 | // Check default arguments 31 | void DefaultFuncInt(int a = 123, int b = 0); 32 | void DefaultFuncString(const string& s = "hello", const string& name = ""); 33 | void DefaultFuncObj(const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter); 34 | void DefaultFuncZero(int a, int b, double c = 0.0, int d = 0, bool e = false); 35 | void DefaultFuncVector(const std::vector &i = {1, 2, 3}, const std::vector &s = {"borglab", "gtsam"}); 36 | 37 | // Test for non-trivial default constructor 38 | void setPose(const gtsam::Pose3& pose = gtsam::Pose3()); 39 | 40 | std::pair 41 | EliminateDiscrete(const gtsam::DiscreteFactorGraph& factors, 42 | const gtsam::Ordering& frontalKeys); 43 | -------------------------------------------------------------------------------- /tests/fixtures/geometry.i: -------------------------------------------------------------------------------- 1 | // comments! 2 | 3 | class VectorNotEigen; 4 | 5 | namespace gtsam { 6 | 7 | #include 8 | class Point2 { 9 | Point2(); 10 | Point2(double x, double y); 11 | double x() const; 12 | double y() const; 13 | int dim() const; 14 | char returnChar() const; 15 | void argChar(char a) const; 16 | void argChar(char* a) const; 17 | void argChar(char& a) const; 18 | void argChar(char@ a) const; 19 | void argChar(const char* a) const; 20 | void argChar(const char& a) const; 21 | void argChar(const char@ a) const; 22 | void argUChar(unsigned char a) const; 23 | void eigenArguments(const gtsam::Vector& v, const gtsam::Matrix& m) const; 24 | VectorNotEigen vectorConfusion(); 25 | 26 | void serializable() const; // Sets flag and creates export, but does not make serialization functions 27 | }; 28 | 29 | #include 30 | class Point3 { 31 | Point3(double x, double y, double z); 32 | double norm() const; 33 | 34 | // static functions - use static keyword and uppercase 35 | static double staticFunction(); 36 | static gtsam::Point3 StaticFunctionRet(double z); 37 | 38 | // enabling serialization functionality 39 | void serialize() const; // Just triggers a flag internally and removes actual function 40 | }; 41 | 42 | } 43 | // another comment 44 | -------------------------------------------------------------------------------- /tests/fixtures/inheritance.i: -------------------------------------------------------------------------------- 1 | // A base class 2 | virtual class MyBase { 3 | }; 4 | 5 | // A templated class 6 | template 7 | virtual class MyTemplate : MyBase { 8 | MyTemplate(); 9 | 10 | template 11 | ARG templatedMethod(const ARG& t); 12 | 13 | // Stress test templates and pointer combinations 14 | void accept_T(const T& value) const; 15 | void accept_Tptr(T* value) const; 16 | T* return_Tptr(T* value) const; 17 | T return_T(T@ value) const; 18 | pair create_ptrs () const; 19 | pair create_MixedPtrs () const; 20 | pair return_ptrs (T* p1, T* p2) const; 21 | 22 | static This Level(const T& K); 23 | }; 24 | 25 | 26 | virtual class ForwardKinematicsFactor : gtsam::BetweenFactor {}; 27 | 28 | template 29 | virtual class ParentHasTemplate : MyTemplate {}; 30 | -------------------------------------------------------------------------------- /tests/fixtures/namespaces.i: -------------------------------------------------------------------------------- 1 | /** 2 | * This is a wrap header to verify permutations on namespaces 3 | */ 4 | 5 | #include 6 | namespace ns1 { 7 | 8 | class ClassA { 9 | ClassA(); 10 | }; 11 | 12 | #include 13 | class ClassB { 14 | ClassB(); 15 | }; 16 | 17 | // check namespace handling 18 | gtsam::Vector aGlobalFunction(); 19 | 20 | } // namespace ns1 21 | 22 | #include 23 | namespace ns2 { 24 | 25 | #include 26 | class ClassA { 27 | ClassA(); 28 | static double afunction(); 29 | double memberFunction(); 30 | int nsArg(const ns1::ClassB& arg); 31 | ns2::ns3::ClassB nsReturn(double q); 32 | }; 33 | 34 | #include 35 | namespace ns3 { 36 | 37 | class ClassB { 38 | ClassB(); 39 | }; 40 | 41 | } // namespace ns3 42 | 43 | class ClassC { 44 | ClassC(); 45 | }; 46 | 47 | // separate namespace global function, same name 48 | gtsam::Vector aGlobalFunction(); 49 | 50 | // An overloaded global function 51 | ns1::ClassA overloadedGlobalFunction(const ns1::ClassA& a); 52 | ns1::ClassA overloadedGlobalFunction(const ns1::ClassA& a, double b); 53 | 54 | int aNs2Var; 55 | 56 | } // namespace ns2 57 | 58 | class ClassD { 59 | ClassD(); 60 | }; 61 | 62 | int aGlobalVar; 63 | 64 | namespace gtsam { 65 | #include 66 | class Values { 67 | Values(); 68 | Values(const gtsam::Values& other); 69 | 70 | void insert(size_t j, const gtsam::Vector& vector); 71 | void insert(size_t j, const gtsam::Matrix& matrix); 72 | }; 73 | } -------------------------------------------------------------------------------- /tests/fixtures/operator.i: -------------------------------------------------------------------------------- 1 | namespace gtsam { 2 | 3 | #include 4 | class Pose3 { 5 | Pose3(); 6 | Pose3(gtsam::Rot3 R, gtsam::Point3 t); 7 | 8 | gtsam::Pose3 operator*(gtsam::Pose3 other) const; 9 | }; 10 | 11 | template 12 | class Container { 13 | gtsam::JacobianFactor operator()(const T& m) const; 14 | T operator[](size_t idx) const; 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /tests/fixtures/part1.i: -------------------------------------------------------------------------------- 1 | // First file to test for multi-file support. 2 | 3 | namespace gtsam { 4 | class Class1 { 5 | Class1(); 6 | }; 7 | 8 | class Class2 { 9 | Class2(); 10 | }; 11 | } // namespace gtsam -------------------------------------------------------------------------------- /tests/fixtures/part2.i: -------------------------------------------------------------------------------- 1 | // Second file to test for multi-file support. 2 | 3 | namespace gtsam { 4 | class ClassA { 5 | ClassA(); 6 | }; 7 | } // namespace gtsam -------------------------------------------------------------------------------- /tests/fixtures/special_cases.i: -------------------------------------------------------------------------------- 1 | // Check for templated class as template argument for method! 2 | namespace gtsam { 3 | 4 | #include 5 | 6 | class Cal3Bundler; 7 | 8 | template 9 | class PinholeCamera {}; 10 | typedef gtsam::PinholeCamera PinholeCameraCal3Bundler; 11 | 12 | class NonlinearFactorGraph { 13 | template }> 14 | void addPrior(size_t key, const T& prior, 15 | const gtsam::noiseModel::Base* noiseModel); 16 | }; 17 | 18 | // Typedef with template as template arg. 19 | template 20 | class GeneralSFMFactor { 21 | gtsam::This::Verbosity verbosity; 22 | 23 | enum Verbosity { 24 | SILENT, 25 | SUMMARY, 26 | VALUES 27 | }; 28 | }; 29 | 30 | typedef gtsam::GeneralSFMFactor, gtsam::Point3> GeneralSFMFactorCal3Bundler; 31 | 32 | // Template as template arg for class property. 33 | class SfmTrack { 34 | std::vector> measurements; 35 | }; 36 | 37 | } // namespace gtsam 38 | 39 | 40 | // class VariableIndex { 41 | // VariableIndex(); 42 | // // template 43 | // VariableIndex(const T& graph); 44 | // VariableIndex(const T& graph, size_t nVariables); 45 | // }; 46 | -------------------------------------------------------------------------------- /tests/fixtures/templates.i: -------------------------------------------------------------------------------- 1 | // Test for templated constructor 2 | class TemplatedConstructor { 3 | TemplatedConstructor(); 4 | 5 | template 6 | TemplatedConstructor(const T& arg); 7 | }; 8 | 9 | // Test for a scoped value inside a template 10 | template 11 | class ScopedTemplate { 12 | // T should be properly substituted here. 13 | ScopedTemplate(const T::Value& arg); 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /tests/pybind_wrapper.tpl: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "gtsam/nonlinear/utilities.h" // for RedirectCout. 6 | 7 | {includes} 8 | 9 | {boost_class_export} 10 | 11 | using namespace std; 12 | 13 | namespace py = pybind11; 14 | 15 | PYBIND11_MODULE({module_name}, m_) {{ 16 | m_.doc() = "pybind11 wrapper of {module_name}"; 17 | 18 | {wrapped_namespace} 19 | 20 | #include "python/specializations.h" 21 | 22 | }} 23 | 24 | -------------------------------------------------------------------------------- /tests/pybind_wrapper_test.cc: -------------------------------------------------------------------------------- 1 | #include "tools/workspace/pybind_wrapper/test/pybind_wrapper_test.h" 2 | 3 | namespace anzu { 4 | 5 | namespace sub { 6 | double Point2::sum() const { return x_ + y_; } 7 | } // namespace sub 8 | 9 | double Point3::sum() const { return x_ + y_ + z_; } 10 | 11 | double global_func_on_base(const std::shared_ptr& point) { 12 | return point->sum(); 13 | } 14 | 15 | } // namespace anzu 16 | 17 | double global_func_overloads(const std::shared_ptr& point2) { 18 | return point2->sum(); 19 | } 20 | 21 | double global_func_overloads(const std::shared_ptr& point3) { 22 | return point3->sum(); 23 | } 24 | -------------------------------------------------------------------------------- /tests/pybind_wrapper_test.gth: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace anzu { 4 | 5 | virtual class PointBase {}; 6 | 7 | namespace sub { 8 | class Point2 : anzu::PointBase { 9 | Point2(double x); // use the default value. 10 | Point2(double x, double y); 11 | double x() const; 12 | double y() const; 13 | double sum() const; 14 | double func_with_default_args(double a) const; // use the default value. 15 | double func_with_default_args(double a, double b) const; 16 | void print(string s) const; 17 | }; 18 | } // namespace sub 19 | 20 | class Point3 : anzu::PointBase { 21 | Point3(double x, double y, double z); 22 | double x() const; 23 | double x(double to_add) const; 24 | double y() const; 25 | double z() const; 26 | double sum() const; 27 | }; 28 | 29 | template 30 | class Template { 31 | Template(const POINT& point); 32 | Template(const POINT& point, double a); 33 | Template(const This& other); 34 | 35 | POINT point() const; 36 | 37 | double overload() const; 38 | double overload(const POINT& point) const; 39 | double overload(const This& other) const; 40 | 41 | POINT method_on_template_type(const POINT& point) const; 42 | This method_on_this(const POINT& point) const; 43 | 44 | static This static_method(const This& other, double dummy); 45 | 46 | template 47 | double template_method(const OTHER_POINT& other) const; 48 | }; 49 | 50 | template 51 | class Template2 { 52 | Template2(const T1& t1, const T2& t2); 53 | double sum_x() const; 54 | double sum_x(const T1& other1) const; 55 | double sum_x(T2* other2) const; 56 | double sum_x(const T1& other1, T2* other2) const; 57 | T1 property_t1; 58 | }; 59 | 60 | typedef anzu::Template2 61 | Template2Point2Point3Instantiation; 62 | 63 | class Ignore { 64 | Ignore(int x); 65 | }; 66 | 67 | namespace sub2 { 68 | class Point4 { 69 | Point4(const anzu::sub::Point2& p_in, double z_in, double w_in); 70 | double sum(); 71 | const anzu::sub::Point2 p; 72 | double z; 73 | double w; 74 | }; 75 | } // namespace sub2 76 | 77 | double global_func_on_base(anzu::PointBase* point); 78 | 79 | } // namespace anzu 80 | 81 | double global_func_overloads(anzu::sub::Point2* point2); 82 | double global_func_overloads(anzu::Point3* point3); 83 | -------------------------------------------------------------------------------- /tests/pybind_wrapper_test_script.py: -------------------------------------------------------------------------------- 1 | import pybind_wrapper_test as pwt 2 | 3 | p2 = pwt.sub.Point2(10, 20) 4 | print(p2.sum()) 5 | print(p2.func_with_default_args(10)) 6 | print(p2.func_with_default_args(10, 10)) 7 | p2.print_("test print") 8 | 9 | p22 = pwt.sub.Point2(10) 10 | print(p22.y()) 11 | 12 | p3 = pwt.Point3(10, 20, 30) 13 | print(p3.sum()) 14 | print(p3.x(to_add=100)) 15 | 16 | print(pwt.global_func_on_base(p2)) 17 | print(pwt.global_func_on_base(p3)) 18 | 19 | # Test template class. 20 | # Construct with POINT 21 | template_p2 = pwt.TemplatePoint2(p2) 22 | print(template_p2.overload()) 23 | 24 | template_p3 = pwt.TemplatePoint3(p3) 25 | print(template_p3.overload()) 26 | print(template_p3.overload(p3)) 27 | 28 | # Construct with This 29 | template_p3_copy = pwt.TemplatePoint3(template_p3) 30 | print(template_p3_copy.overload()) 31 | print(template_p3.overload(template_p3_copy)) 32 | 33 | # Function of template type. 34 | ret_p3 = template_p3.method_on_template_type(p3) 35 | print(ret_p3.z()) 36 | 37 | # Function of This class type. 38 | this = template_p3.method_on_this(p3) 39 | print(this.method_on_template_type(p3).sum()) 40 | 41 | # Static function. 42 | another_this = pwt.TemplatePoint2.static_method(other=template_p2, dummy=0.0) 43 | 44 | # Template function of other POINT type. 45 | print(another_this.template_methodPoint3(p3)) 46 | print(another_this.template_methodPoint2(p2)) 47 | 48 | # Typedef template instantiation. 49 | inst = pwt.Template2Point2Point3Instantiation(p2, p3) 50 | inst.property_t1 = pwt.sub.Point2(100) 51 | print("inst overload: ", inst.sum_x()) 52 | print(inst.sum_x(p2)) 53 | print(inst.sum_x(p3)) 54 | print(inst.sum_x(p2, p3)) 55 | print(inst.property_t1.sum()) 56 | 57 | # Properties 58 | p4 = pwt.sub2.Point4(p2, 30, 40) 59 | print(p4.p.sum()) 60 | print(p4.sum()) 61 | p4.z = 40 62 | print(p4.sum()) 63 | -------------------------------------------------------------------------------- /tests/testDependencies.h: -------------------------------------------------------------------------------- 1 | //Header file to test dependency checking 2 | // 3 | class Pose3 { 4 | Pose3(const Rot3& r, const Point3& t); //What is Rot3? Throw here 5 | static Rot3 testStaticDep(Rot3& r); //What is Rot3? Throw here 6 | Rot3 testReturnType() const; // Throw here 7 | void testMethodArg(const Rot3& r) const; 8 | }; 9 | -------------------------------------------------------------------------------- /tests/testMemory.m: -------------------------------------------------------------------------------- 1 | %MATLAB testing file for memory allocation and leaks 2 | %Andrew Melim 3 | 4 | addpath([pwd,'/../../../toolbox/gtsam']); 5 | for i=1:100000 6 | p = gtsamPoint2() 7 | end 8 | -------------------------------------------------------------------------------- /utilities/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | REF=${1-master} # branch or tag; defaults to 'master' if parameter 1 not present 3 | REMOTE=pybind11 # just a name to identify the remote 4 | REPO=git@github.com:pybind/pybind11.git # replace this with your repository URL 5 | FOLDER=pybind11 # where to mount the subtree 6 | 7 | git remote add $REMOTE --no-tags $REPO 8 | if [[ -d $FOLDER ]]; then # update the existing subtree 9 | git subtree pull $REMOTE $REF --prefix=$FOLDER --squash -m "Merging '$REF' into '$FOLDER'" 10 | else # add the subtree 11 | git subtree add $REMOTE $REF --prefix=$FOLDER --squash -m "Merging '$REF' into '$FOLDER'" 12 | fi 13 | git remote remove $REMOTE --------------------------------------------------------------------------------