├── .gitignore ├── CMakeLists.txt ├── README.md ├── collage-pynari.jpg ├── external ├── pybind11 │ ├── 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.txt │ │ └── upgrade.rst │ ├── include │ │ └── pybind11 │ │ │ ├── attr.h │ │ │ ├── buffer_info.h │ │ │ ├── cast.h │ │ │ ├── chrono.h │ │ │ ├── common.h │ │ │ ├── complex.h │ │ │ ├── detail │ │ │ ├── class.h │ │ │ ├── common.h │ │ │ ├── descr.h │ │ │ ├── init.h │ │ │ ├── internals.h │ │ │ ├── type_caster_base.h │ │ │ └── typeid.h │ │ │ ├── eigen.h │ │ │ ├── eigen │ │ │ ├── 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 │ │ ├── extra_python_package │ │ │ ├── pytest.ini │ │ │ └── test_files.py │ │ ├── extra_setuptools │ │ │ ├── pytest.ini │ │ │ └── test_setuphelper.py │ │ ├── local_bindings.h │ │ ├── object.h │ │ ├── pybind11_cross_module_tests.cpp │ │ ├── pybind11_tests.cpp │ │ ├── pybind11_tests.h │ │ ├── pytest.ini │ │ ├── requirements.txt │ │ ├── test_async.cpp │ │ ├── test_async.py │ │ ├── test_buffers.cpp │ │ ├── test_buffers.py │ │ ├── test_builtin_casters.cpp │ │ ├── test_builtin_casters.py │ │ ├── test_call_policies.cpp │ │ ├── test_call_policies.py │ │ ├── test_callbacks.cpp │ │ ├── test_callbacks.py │ │ ├── test_chrono.cpp │ │ ├── test_chrono.py │ │ ├── test_class.cpp │ │ ├── test_class.py │ │ ├── test_cmake_build │ │ │ ├── CMakeLists.txt │ │ │ ├── embed.cpp │ │ │ ├── installed_embed │ │ │ │ └── CMakeLists.txt │ │ │ ├── installed_function │ │ │ │ └── CMakeLists.txt │ │ │ ├── installed_target │ │ │ │ └── CMakeLists.txt │ │ │ ├── main.cpp │ │ │ ├── subdirectory_embed │ │ │ │ └── CMakeLists.txt │ │ │ ├── subdirectory_function │ │ │ │ └── CMakeLists.txt │ │ │ ├── subdirectory_target │ │ │ │ └── CMakeLists.txt │ │ │ └── test.py │ │ ├── test_const_name.cpp │ │ ├── test_const_name.py │ │ ├── test_constants_and_functions.cpp │ │ ├── test_constants_and_functions.py │ │ ├── test_copy_move.cpp │ │ ├── test_copy_move.py │ │ ├── test_custom_type_casters.cpp │ │ ├── test_custom_type_casters.py │ │ ├── test_custom_type_setup.cpp │ │ ├── test_custom_type_setup.py │ │ ├── test_docstring_options.cpp │ │ ├── test_docstring_options.py │ │ ├── test_eigen_matrix.cpp │ │ ├── test_eigen_matrix.py │ │ ├── test_eigen_tensor.cpp │ │ ├── test_eigen_tensor.inl │ │ ├── test_eigen_tensor.py │ │ ├── test_embed │ │ │ ├── CMakeLists.txt │ │ │ ├── catch.cpp │ │ │ ├── external_module.cpp │ │ │ ├── test_interpreter.cpp │ │ │ ├── test_interpreter.py │ │ │ └── test_trampoline.py │ │ ├── test_enum.cpp │ │ ├── test_enum.py │ │ ├── test_eval.cpp │ │ ├── test_eval.py │ │ ├── test_eval_call.py │ │ ├── test_exceptions.cpp │ │ ├── test_exceptions.h │ │ ├── test_exceptions.py │ │ ├── test_factory_constructors.cpp │ │ ├── test_factory_constructors.py │ │ ├── test_gil_scoped.cpp │ │ ├── test_gil_scoped.py │ │ ├── test_iostream.cpp │ │ ├── test_iostream.py │ │ ├── test_kwargs_and_defaults.cpp │ │ ├── test_kwargs_and_defaults.py │ │ ├── test_local_bindings.cpp │ │ ├── test_local_bindings.py │ │ ├── test_methods_and_attributes.cpp │ │ ├── test_methods_and_attributes.py │ │ ├── test_modules.cpp │ │ ├── test_modules.py │ │ ├── test_multiple_inheritance.cpp │ │ ├── test_multiple_inheritance.py │ │ ├── test_numpy_array.cpp │ │ ├── test_numpy_array.py │ │ ├── test_numpy_dtypes.cpp │ │ ├── test_numpy_dtypes.py │ │ ├── test_numpy_vectorize.cpp │ │ ├── test_numpy_vectorize.py │ │ ├── test_opaque_types.cpp │ │ ├── test_opaque_types.py │ │ ├── test_operator_overloading.cpp │ │ ├── test_operator_overloading.py │ │ ├── test_pickling.cpp │ │ ├── test_pickling.py │ │ ├── test_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_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 │ │ ├── pybind11NewTools.cmake │ │ ├── pybind11Tools.cmake │ │ ├── pyproject.toml │ │ ├── setup_global.py.in │ │ └── setup_main.py.in └── stb_image │ ├── CMakeLists.txt │ └── stb │ ├── stb_image.h │ └── stb_image_write.h ├── pynari ├── Array.cpp ├── Array.h ├── CMakeLists.txt ├── Camera.h ├── Context.cpp ├── Context.h ├── Device.cpp ├── Device.h ├── Frame.cpp ├── Frame.h ├── Geometry.h ├── Group.h ├── Light.h ├── Material.h ├── Object.cpp ├── Object.h ├── Renderer.h ├── Sampler.h ├── SpatialField.h ├── Surface.h ├── Volume.h ├── World.h ├── becomes.__init__.py ├── bindings.cpp ├── common.h └── dummy.cu ├── samples ├── camera-depth-of-field.py ├── dlaf-1m.cmap.binary.float3 ├── dlaf-1m.points.binary.float3 ├── dlaf-1m.scalars.binary.float ├── geometry-cones-colorPerPrim.py ├── geometry-cones-colorPerVertex.py ├── geometry-cones.py ├── geometry-cylinders-colorPerPrim.py ├── geometry-cylinders-colorPerVertex.py ├── geometry-cylinders.py ├── geometry-spheres-with-sampler1D.jpg ├── geometry-triangles-testorb-np.py ├── reference-hdri.py ├── sample01.jpg ├── sample01.py ├── sample02.jpg ├── sample02.py ├── sample03-magnetic.jpg ├── sample03.jpg ├── sample03.py ├── sample04.jpg ├── sample04.py ├── sample05.jpg ├── sample05.py ├── sample06.jpg ├── sample06.py ├── sample07.jpg ├── sample07.py ├── testorb-base.npz ├── testorb-equation.npz ├── testorb-floor.npz ├── testorb-inner-sphere.npz ├── testorb-outer-sphere.npz ├── unstructured-cellCentric.py └── unstructured-vertexCentric.py └── viewer ├── anari_viewer.py └── examples ├── anari_scene_base.py ├── anari_tf.py ├── sample01.py ├── sample02.py ├── sample05.py ├── sample07.py ├── sample_volume_sitk.py └── sample_volume_vdb.py /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | textures 3 | *# 4 | .#* 5 | bin 6 | dbg 7 | *.user* 8 | build* 9 | *.sw? 10 | tags 11 | .ycm_extra_conf.pyc 12 | *.autosave 13 | *DS_Store* 14 | *.gz 15 | *.rpm 16 | *.zip 17 | *.bak 18 | *.patch 19 | .vscode 20 | deps 21 | tbb 22 | ispc 23 | *.aux 24 | *.bbl 25 | *.blg 26 | *.brf 27 | *.dvi 28 | *.lbl 29 | *.log 30 | paper/pointQueries/rtxPointQueries.pdf 31 | paper/pointQueries/rtxPointQueries-compressed.pdf 32 | *.swp 33 | *.out 34 | Session.vim 35 | .idea 36 | !*png/*.pdf 37 | .vs/ 38 | __pycache__ 39 | /bunny_cloud.vdb 40 | /Class 3 malocclusion 41 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ======================================================================== # 2 | # Copyright 2024-2024 Ingo Wald # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); # 5 | # you may not use this file except in compliance with the License. # 6 | # You may obtain a copy of the License at # 7 | # # 8 | # http://www.apache.org/licenses/LICENSE-2.0 # 9 | # # 10 | # Unless required by applicable law or agreed to in writing, software # 11 | # distributed under the License is distributed on an "AS IS" BASIS, # 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 13 | # See the License for the specific language governing permissions and # 14 | # limitations under the License. # 15 | # ======================================================================== # 16 | 17 | set(PYNARI_VERSION_MAJOR 1) 18 | set(PYNARI_VERSION_MINOR 2) 19 | set(PYNARI_VERSION_PATCH 9) 20 | 21 | cmake_minimum_required(VERSION 3.12) 22 | 23 | if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18) 24 | cmake_policy(SET CMP0104 NEW) 25 | endif() 26 | 27 | set(CMAKE_BUILD_TYPE_INIT "Release") 28 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 29 | 30 | # project command is required to come after cmake_minimum_required command. 31 | set(PYNARI_VERSION ${PYNARI_VERSION_MAJOR}.${PYNARI_VERSION_MINOR}.${PYNARI_VERSION_PATCH}) 32 | project(pynari VERSION ${PYNARI_VERSION} LANGUAGES C CXX) 33 | 34 | set(PYNARI_HAVE_CUDA OFF) 35 | include(CheckLanguage) 36 | check_language(CUDA) 37 | if (CMAKE_CUDA_COMPILER) 38 | enable_language(CUDA) 39 | set(PYNARI_HAVE_CUDA ON) 40 | message("found CUDA: ${CMAKE_CUDA_COMPILER}") 41 | endif() 42 | 43 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) 44 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) 45 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) 46 | 47 | find_package(anari 0.14.0 COMPONENTS code_gen) 48 | 49 | set(PYBIND11_FINDPYTHON ON) 50 | add_subdirectory(external/pybind11 build_pybin EXCLUDE_FROM_ALL) 51 | if (NOT (TARGET stb_image)) 52 | add_subdirectory(external/stb_image EXCLUDE_FROM_ALL) 53 | endif() 54 | 55 | add_subdirectory(pynari) 56 | 57 | 58 | -------------------------------------------------------------------------------- /collage-pynari.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/collage-pynari.jpg -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/docs/_static/css/custom.css: -------------------------------------------------------------------------------- 1 | .highlight .go { 2 | color: #707070; 3 | } 4 | -------------------------------------------------------------------------------- /external/pybind11/docs/advanced/cast/custom.rst: -------------------------------------------------------------------------------- 1 | Custom type casters 2 | =================== 3 | 4 | In very rare cases, applications may require custom type casters that cannot be 5 | expressed using the abstractions provided by pybind11, thus requiring raw 6 | Python C API calls. This is fairly advanced usage and should only be pursued by 7 | experts who are familiar with the intricacies of Python reference counting. 8 | 9 | The following snippets demonstrate how this works for a very simple ``inty`` 10 | type that that should be convertible from Python types that provide a 11 | ``__int__(self)`` method. 12 | 13 | .. code-block:: cpp 14 | 15 | struct inty { long long_value; }; 16 | 17 | void print(inty s) { 18 | std::cout << s.long_value << std::endl; 19 | } 20 | 21 | The following Python snippet demonstrates the intended usage from the Python side: 22 | 23 | .. code-block:: python 24 | 25 | class A: 26 | def __int__(self): 27 | return 123 28 | 29 | 30 | from example import print 31 | 32 | print(A()) 33 | 34 | To register the necessary conversion routines, it is necessary to add an 35 | instantiation of the ``pybind11::detail::type_caster`` template. 36 | Although this is an implementation detail, adding an instantiation of this 37 | type is explicitly allowed. 38 | 39 | .. code-block:: cpp 40 | 41 | namespace PYBIND11_NAMESPACE { namespace detail { 42 | template <> struct type_caster { 43 | public: 44 | /** 45 | * This macro establishes the name 'inty' in 46 | * function signatures and declares a local variable 47 | * 'value' of type inty 48 | */ 49 | PYBIND11_TYPE_CASTER(inty, const_name("inty")); 50 | 51 | /** 52 | * Conversion part 1 (Python->C++): convert a PyObject into a inty 53 | * instance or return false upon failure. The second argument 54 | * indicates whether implicit conversions should be applied. 55 | */ 56 | bool load(handle src, bool) { 57 | /* Extract PyObject from handle */ 58 | PyObject *source = src.ptr(); 59 | /* Try converting into a Python integer value */ 60 | PyObject *tmp = PyNumber_Long(source); 61 | if (!tmp) 62 | return false; 63 | /* Now try to convert into a C++ int */ 64 | value.long_value = PyLong_AsLong(tmp); 65 | Py_DECREF(tmp); 66 | /* Ensure return code was OK (to avoid out-of-range errors etc) */ 67 | return !(value.long_value == -1 && !PyErr_Occurred()); 68 | } 69 | 70 | /** 71 | * Conversion part 2 (C++ -> Python): convert an inty instance into 72 | * a Python object. The second and third arguments are used to 73 | * indicate the return value policy and parent object (for 74 | * ``return_value_policy::reference_internal``) and are generally 75 | * ignored by implicit casters. 76 | */ 77 | static handle cast(inty src, return_value_policy /* policy */, handle /* parent */) { 78 | return PyLong_FromLong(src.long_value); 79 | } 80 | }; 81 | }} // namespace PYBIND11_NAMESPACE::detail 82 | 83 | .. note:: 84 | 85 | A ``type_caster`` defined with ``PYBIND11_TYPE_CASTER(T, ...)`` requires 86 | that ``T`` is default-constructible (``value`` is first default constructed 87 | and then ``load()`` assigns to it). 88 | 89 | .. warning:: 90 | 91 | When using custom type casters, it's important to declare them consistently 92 | in every compilation unit of the Python extension module. Otherwise, 93 | undefined behavior can ensue. 94 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/docs/benchmark.py: -------------------------------------------------------------------------------- 1 | import datetime as dt 2 | import os 3 | import random 4 | 5 | nfns = 4 # Functions per class 6 | nargs = 4 # Arguments per function 7 | 8 | 9 | def generate_dummy_code_pybind11(nclasses=10): 10 | decl = "" 11 | bindings = "" 12 | 13 | for cl in range(nclasses): 14 | decl += f"class cl{cl:03};\n" 15 | decl += "\n" 16 | 17 | for cl in range(nclasses): 18 | decl += f"class {cl:03} {{\n" 19 | decl += "public:\n" 20 | bindings += f' py::class_(m, "cl{cl:03}")\n' 21 | for fn in range(nfns): 22 | ret = random.randint(0, nclasses - 1) 23 | params = [random.randint(0, nclasses - 1) for i in range(nargs)] 24 | decl += f" cl{ret:03} *fn_{fn:03}(" 25 | decl += ", ".join(f"cl{p:03} *" for p in params) 26 | decl += ");\n" 27 | bindings += f' .def("fn_{fn:03}", &cl{cl:03}::fn_{fn:03})\n' 28 | decl += "};\n\n" 29 | bindings += " ;\n" 30 | 31 | result = "#include \n\n" 32 | result += "namespace py = pybind11;\n\n" 33 | result += decl + "\n" 34 | result += "PYBIND11_MODULE(example, m) {\n" 35 | result += bindings 36 | result += "}" 37 | return result 38 | 39 | 40 | def generate_dummy_code_boost(nclasses=10): 41 | decl = "" 42 | bindings = "" 43 | 44 | for cl in range(nclasses): 45 | decl += f"class cl{cl:03};\n" 46 | decl += "\n" 47 | 48 | for cl in range(nclasses): 49 | decl += "class cl%03i {\n" % cl 50 | decl += "public:\n" 51 | bindings += f' py::class_("cl{cl:03}")\n' 52 | for fn in range(nfns): 53 | ret = random.randint(0, nclasses - 1) 54 | params = [random.randint(0, nclasses - 1) for i in range(nargs)] 55 | decl += f" cl{ret:03} *fn_{fn:03}(" 56 | decl += ", ".join(f"cl{p:03} *" for p in params) 57 | decl += ");\n" 58 | bindings += f' .def("fn_{fn:03}", &cl{cl:03}::fn_{fn:03}, py::return_value_policy())\n' 59 | decl += "};\n\n" 60 | bindings += " ;\n" 61 | 62 | result = "#include \n\n" 63 | result += "namespace py = boost::python;\n\n" 64 | result += decl + "\n" 65 | result += "BOOST_PYTHON_MODULE(example) {\n" 66 | result += bindings 67 | result += "}" 68 | return result 69 | 70 | 71 | for codegen in [generate_dummy_code_pybind11, generate_dummy_code_boost]: 72 | print("{") 73 | for i in range(10): 74 | nclasses = 2**i 75 | with open("test.cpp", "w") as f: 76 | f.write(codegen(nclasses)) 77 | n1 = dt.datetime.now() 78 | os.system( 79 | "g++ -Os -shared -rdynamic -undefined dynamic_lookup " 80 | "-fvisibility=hidden -std=c++14 test.cpp -I include " 81 | "-I /System/Library/Frameworks/Python.framework/Headers -o test.so" 82 | ) 83 | n2 = dt.datetime.now() 84 | elapsed = (n2 - n1).total_seconds() 85 | size = os.stat("test.so").st_size 86 | print(" {%i, %f, %i}," % (nclasses * nfns, elapsed, size)) 87 | print("}") 88 | -------------------------------------------------------------------------------- /external/pybind11/docs/benchmark.rst: -------------------------------------------------------------------------------- 1 | Benchmark 2 | ========= 3 | 4 | The following is the result of a synthetic benchmark comparing both compilation 5 | time and module size of pybind11 against Boost.Python. A detailed report about a 6 | Boost.Python to pybind11 conversion of a real project is available here: [#f1]_. 7 | 8 | .. [#f1] http://graylab.jhu.edu/RosettaCon2016/PyRosetta-4.pdf 9 | 10 | Setup 11 | ----- 12 | 13 | A python script (see the ``docs/benchmark.py`` file) was used to generate a set 14 | of files with dummy classes whose count increases for each successive benchmark 15 | (between 1 and 2048 classes in powers of two). Each class has four methods with 16 | a randomly generated signature with a return value and four arguments. (There 17 | was no particular reason for this setup other than the desire to generate many 18 | unique function signatures whose count could be controlled in a simple way.) 19 | 20 | Here is an example of the binding code for one class: 21 | 22 | .. code-block:: cpp 23 | 24 | ... 25 | class cl034 { 26 | public: 27 | cl279 *fn_000(cl084 *, cl057 *, cl065 *, cl042 *); 28 | cl025 *fn_001(cl098 *, cl262 *, cl414 *, cl121 *); 29 | cl085 *fn_002(cl445 *, cl297 *, cl145 *, cl421 *); 30 | cl470 *fn_003(cl200 *, cl323 *, cl332 *, cl492 *); 31 | }; 32 | ... 33 | 34 | PYBIND11_MODULE(example, m) { 35 | ... 36 | py::class_(m, "cl034") 37 | .def("fn_000", &cl034::fn_000) 38 | .def("fn_001", &cl034::fn_001) 39 | .def("fn_002", &cl034::fn_002) 40 | .def("fn_003", &cl034::fn_003) 41 | ... 42 | } 43 | 44 | The Boost.Python version looks almost identical except that a return value 45 | policy had to be specified as an argument to ``def()``. For both libraries, 46 | compilation was done with 47 | 48 | .. code-block:: bash 49 | 50 | Apple LLVM version 7.0.2 (clang-700.1.81) 51 | 52 | and the following compilation flags 53 | 54 | .. code-block:: bash 55 | 56 | g++ -Os -shared -rdynamic -undefined dynamic_lookup -fvisibility=hidden -std=c++14 57 | 58 | Compilation time 59 | ---------------- 60 | 61 | The following log-log plot shows how the compilation time grows for an 62 | increasing number of class and function declarations. pybind11 includes many 63 | fewer headers, which initially leads to shorter compilation times, but the 64 | performance is ultimately fairly similar (pybind11 is 19.8 seconds faster for 65 | the largest largest file with 2048 classes and a total of 8192 methods -- a 66 | modest **1.2x** speedup relative to Boost.Python, which required 116.35 67 | seconds). 68 | 69 | .. only:: not latex 70 | 71 | .. image:: pybind11_vs_boost_python1.svg 72 | 73 | .. only:: latex 74 | 75 | .. image:: pybind11_vs_boost_python1.png 76 | 77 | Module size 78 | ----------- 79 | 80 | Differences between the two libraries become much more pronounced when 81 | considering the file size of the generated Python plugin: for the largest file, 82 | the binary generated by Boost.Python required 16.8 MiB, which was **2.17 83 | times** / **9.1 megabytes** larger than the output generated by pybind11. For 84 | very small inputs, Boost.Python has an edge in the plot below -- however, note 85 | that it stores many definitions in an external library, whose size was not 86 | included here, hence the comparison is slightly shifted in Boost.Python's 87 | favor. 88 | 89 | .. only:: not latex 90 | 91 | .. image:: pybind11_vs_boost_python2.svg 92 | 93 | .. only:: latex 94 | 95 | .. image:: pybind11_vs_boost_python2.png 96 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/docs/installing.rst: -------------------------------------------------------------------------------- 1 | .. _installing: 2 | 3 | Installing the library 4 | ###################### 5 | 6 | There are several ways to get the pybind11 source, which lives at 7 | `pybind/pybind11 on GitHub `_. The pybind11 8 | developers recommend one of the first three ways listed here, submodule, PyPI, 9 | or conda-forge, for obtaining pybind11. 10 | 11 | .. _include_as_a_submodule: 12 | 13 | Include as a submodule 14 | ====================== 15 | 16 | When you are working on a project in Git, you can use the pybind11 repository 17 | as a submodule. From your git repository, use: 18 | 19 | .. code-block:: bash 20 | 21 | git submodule add -b stable ../../pybind/pybind11 extern/pybind11 22 | git submodule update --init 23 | 24 | This assumes you are placing your dependencies in ``extern/``, and that you are 25 | using GitHub; if you are not using GitHub, use the full https or ssh URL 26 | instead of the relative URL ``../../pybind/pybind11`` above. Some other servers 27 | also require the ``.git`` extension (GitHub does not). 28 | 29 | From here, you can now include ``extern/pybind11/include``, or you can use 30 | the various integration tools (see :ref:`compiling`) pybind11 provides directly 31 | from the local folder. 32 | 33 | Include with PyPI 34 | ================= 35 | 36 | You can download the sources and CMake files as a Python package from PyPI 37 | using Pip. Just use: 38 | 39 | .. code-block:: bash 40 | 41 | pip install pybind11 42 | 43 | This will provide pybind11 in a standard Python package format. If you want 44 | pybind11 available directly in your environment root, you can use: 45 | 46 | .. code-block:: bash 47 | 48 | pip install "pybind11[global]" 49 | 50 | This is not recommended if you are installing with your system Python, as it 51 | will add files to ``/usr/local/include/pybind11`` and 52 | ``/usr/local/share/cmake/pybind11``, so unless that is what you want, it is 53 | recommended only for use in virtual environments or your ``pyproject.toml`` 54 | file (see :ref:`compiling`). 55 | 56 | Include with conda-forge 57 | ======================== 58 | 59 | You can use pybind11 with conda packaging via `conda-forge 60 | `_: 61 | 62 | .. code-block:: bash 63 | 64 | conda install -c conda-forge pybind11 65 | 66 | 67 | Include with vcpkg 68 | ================== 69 | You can download and install pybind11 using the Microsoft `vcpkg 70 | `_ dependency manager: 71 | 72 | .. code-block:: bash 73 | 74 | git clone https://github.com/Microsoft/vcpkg.git 75 | cd vcpkg 76 | ./bootstrap-vcpkg.sh 77 | ./vcpkg integrate install 78 | vcpkg install pybind11 79 | 80 | The pybind11 port in vcpkg is kept up to date by Microsoft team members and 81 | community contributors. If the version is out of date, please `create an issue 82 | or pull request `_ on the vcpkg 83 | repository. 84 | 85 | Global install with brew 86 | ======================== 87 | 88 | The brew package manager (Homebrew on macOS, or Linuxbrew on Linux) has a 89 | `pybind11 package 90 | `_. 91 | To install: 92 | 93 | .. code-block:: bash 94 | 95 | brew install pybind11 96 | 97 | .. We should list Conan, and possibly a few other C++ package managers (hunter, 98 | .. perhaps). Conan has a very clean CMake integration that would be good to show. 99 | 100 | Other options 101 | ============= 102 | 103 | Other locations you can find pybind11 are `listed here 104 | `_; these are maintained 105 | by various packagers and the community. 106 | -------------------------------------------------------------------------------- /external/pybind11/docs/limitations.rst: -------------------------------------------------------------------------------- 1 | Limitations 2 | ########### 3 | 4 | Design choices 5 | ^^^^^^^^^^^^^^ 6 | 7 | pybind11 strives to be a general solution to binding generation, but it also has 8 | certain limitations: 9 | 10 | - pybind11 casts away ``const``-ness in function arguments and return values. 11 | This is in line with the Python language, which has no concept of ``const`` 12 | values. This means that some additional care is needed to avoid bugs that 13 | would be caught by the type checker in a traditional C++ program. 14 | 15 | - The NumPy interface ``pybind11::array`` greatly simplifies accessing 16 | numerical data from C++ (and vice versa), but it's not a full-blown array 17 | class like ``Eigen::Array`` or ``boost.multi_array``. ``Eigen`` objects are 18 | directly supported, however, with ``pybind11/eigen.h``. 19 | 20 | Large but useful features could be implemented in pybind11 but would lead to a 21 | significant increase in complexity. Pybind11 strives to be simple and compact. 22 | Users who require large new features are encouraged to write an extension to 23 | pybind11; see `pybind11_json `_ for an 24 | example. 25 | 26 | 27 | Known bugs 28 | ^^^^^^^^^^ 29 | 30 | These are issues that hopefully will one day be fixed, but currently are 31 | unsolved. If you know how to help with one of these issues, contributions 32 | are welcome! 33 | 34 | - Intel 20.2 is currently having an issue with the test suite. 35 | `#2573 `_ 36 | 37 | - Debug mode Python does not support 1-5 tests in the test suite currently. 38 | `#2422 `_ 39 | 40 | - PyPy3 7.3.1 and 7.3.2 have issues with several tests on 32-bit Windows. 41 | 42 | Known limitations 43 | ^^^^^^^^^^^^^^^^^ 44 | 45 | These are issues that are probably solvable, but have not been fixed yet. A 46 | clean, well written patch would likely be accepted to solve them. 47 | 48 | - Type casters are not kept alive recursively. 49 | `#2527 `_ 50 | One consequence is that containers of ``char *`` are currently not supported. 51 | `#2245 `_ 52 | 53 | - The ``cpptest`` does not run on Windows with Python 3.8 or newer, due to DLL 54 | loader changes. User code that is correctly installed should not be affected. 55 | `#2560 `_ 56 | 57 | Python 3.9.0 warning 58 | ^^^^^^^^^^^^^^^^^^^^ 59 | 60 | Combining older versions of pybind11 (< 2.6.0) with Python on exactly 3.9.0 61 | will trigger undefined behavior that typically manifests as crashes during 62 | interpreter shutdown (but could also destroy your data. **You have been 63 | warned**). 64 | 65 | This issue was `fixed in Python `_. 66 | As a mitigation for this bug, pybind11 2.6.0 or newer includes a workaround 67 | specifically when Python 3.9.0 is detected at runtime, leaking about 50 bytes 68 | of memory when a callback function is garbage collected. For reference, the 69 | pybind11 test suite has about 2,000 such callbacks, but only 49 are garbage 70 | collected before the end-of-process. Wheels (even if built with Python 3.9.0) 71 | will correctly avoid the leak when run in Python 3.9.1, and this does not 72 | affect other 3.X versions. 73 | -------------------------------------------------------------------------------- /external/pybind11/docs/pybind11-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/external/pybind11/docs/pybind11-logo.png -------------------------------------------------------------------------------- /external/pybind11/docs/pybind11_vs_boost_python1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/external/pybind11/docs/pybind11_vs_boost_python1.png -------------------------------------------------------------------------------- /external/pybind11/docs/pybind11_vs_boost_python2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/external/pybind11/docs/pybind11_vs_boost_python2.png -------------------------------------------------------------------------------- /external/pybind11/docs/reference.rst: -------------------------------------------------------------------------------- 1 | .. _reference: 2 | 3 | .. warning:: 4 | 5 | Please be advised that the reference documentation discussing pybind11 6 | internals is currently incomplete. Please refer to the previous sections 7 | and the pybind11 header files for the nitty gritty details. 8 | 9 | Reference 10 | ######### 11 | 12 | .. _macros: 13 | 14 | Macros 15 | ====== 16 | 17 | .. doxygendefine:: PYBIND11_MODULE 18 | 19 | .. _core_types: 20 | 21 | Convenience classes for arbitrary Python types 22 | ============================================== 23 | 24 | Common member functions 25 | ----------------------- 26 | 27 | .. doxygenclass:: object_api 28 | :members: 29 | 30 | Without reference counting 31 | -------------------------- 32 | 33 | .. doxygenclass:: handle 34 | :members: 35 | 36 | With reference counting 37 | ----------------------- 38 | 39 | .. doxygenclass:: object 40 | :members: 41 | 42 | .. doxygenfunction:: reinterpret_borrow 43 | 44 | .. doxygenfunction:: reinterpret_steal 45 | 46 | Convenience classes for specific Python types 47 | ============================================= 48 | 49 | .. doxygenclass:: module_ 50 | :members: 51 | 52 | .. doxygengroup:: pytypes 53 | :members: 54 | 55 | Convenience functions converting to Python types 56 | ================================================ 57 | 58 | .. doxygenfunction:: make_tuple(Args&&...) 59 | 60 | .. doxygenfunction:: make_iterator(Iterator, Sentinel, Extra &&...) 61 | .. doxygenfunction:: make_iterator(Type &, Extra&&...) 62 | 63 | .. doxygenfunction:: make_key_iterator(Iterator, Sentinel, Extra &&...) 64 | .. doxygenfunction:: make_key_iterator(Type &, Extra&&...) 65 | 66 | .. doxygenfunction:: make_value_iterator(Iterator, Sentinel, Extra &&...) 67 | .. doxygenfunction:: make_value_iterator(Type &, Extra&&...) 68 | 69 | .. _extras: 70 | 71 | Passing extra arguments to ``def`` or ``class_`` 72 | ================================================ 73 | 74 | .. doxygengroup:: annotations 75 | :members: 76 | 77 | Embedding the interpreter 78 | ========================= 79 | 80 | .. doxygendefine:: PYBIND11_EMBEDDED_MODULE 81 | 82 | .. doxygenfunction:: initialize_interpreter 83 | 84 | .. doxygenfunction:: finalize_interpreter 85 | 86 | .. doxygenclass:: scoped_interpreter 87 | 88 | Redirecting C++ streams 89 | ======================= 90 | 91 | .. doxygenclass:: scoped_ostream_redirect 92 | 93 | .. doxygenclass:: scoped_estream_redirect 94 | 95 | .. doxygenfunction:: add_ostream_redirect 96 | 97 | Python built-in functions 98 | ========================= 99 | 100 | .. doxygengroup:: python_builtins 101 | :members: 102 | 103 | Inheritance 104 | =========== 105 | 106 | See :doc:`/classes` and :doc:`/advanced/classes` for more detail. 107 | 108 | .. doxygendefine:: PYBIND11_OVERRIDE 109 | 110 | .. doxygendefine:: PYBIND11_OVERRIDE_PURE 111 | 112 | .. doxygendefine:: PYBIND11_OVERRIDE_NAME 113 | 114 | .. doxygendefine:: PYBIND11_OVERRIDE_PURE_NAME 115 | 116 | .. doxygenfunction:: get_override 117 | 118 | Exceptions 119 | ========== 120 | 121 | .. doxygenclass:: error_already_set 122 | :members: 123 | 124 | .. doxygenclass:: builtin_exception 125 | :members: 126 | 127 | Literals 128 | ======== 129 | 130 | .. doxygennamespace:: literals 131 | -------------------------------------------------------------------------------- /external/pybind11/docs/requirements.txt: -------------------------------------------------------------------------------- 1 | breathe==4.34.0 2 | furo==2022.6.21 3 | sphinx==5.0.2 4 | sphinx-copybutton==0.5.0 5 | sphinxcontrib-moderncmakedomain==3.21.4 6 | sphinxcontrib-svg2pdfconverter==1.2.0 7 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/include/pybind11/options.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/options.h: global settings that are configurable at runtime. 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include "detail/common.h" 13 | 14 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 15 | 16 | class options { 17 | public: 18 | // Default RAII constructor, which leaves settings as they currently are. 19 | options() : previous_state(global_state()) {} 20 | 21 | // Class is non-copyable. 22 | options(const options &) = delete; 23 | options &operator=(const options &) = delete; 24 | 25 | // Destructor, which restores settings that were in effect before. 26 | ~options() { global_state() = previous_state; } 27 | 28 | // Setter methods (affect the global state): 29 | 30 | options &disable_user_defined_docstrings() & { 31 | global_state().show_user_defined_docstrings = false; 32 | return *this; 33 | } 34 | 35 | options &enable_user_defined_docstrings() & { 36 | global_state().show_user_defined_docstrings = true; 37 | return *this; 38 | } 39 | 40 | options &disable_function_signatures() & { 41 | global_state().show_function_signatures = false; 42 | return *this; 43 | } 44 | 45 | options &enable_function_signatures() & { 46 | global_state().show_function_signatures = true; 47 | return *this; 48 | } 49 | 50 | options &disable_enum_members_docstring() & { 51 | global_state().show_enum_members_docstring = false; 52 | return *this; 53 | } 54 | 55 | options &enable_enum_members_docstring() & { 56 | global_state().show_enum_members_docstring = true; 57 | return *this; 58 | } 59 | 60 | // Getter methods (return the global state): 61 | 62 | static bool show_user_defined_docstrings() { 63 | return global_state().show_user_defined_docstrings; 64 | } 65 | 66 | static bool show_function_signatures() { return global_state().show_function_signatures; } 67 | 68 | static bool show_enum_members_docstring() { 69 | return global_state().show_enum_members_docstring; 70 | } 71 | 72 | // This type is not meant to be allocated on the heap. 73 | void *operator new(size_t) = delete; 74 | 75 | private: 76 | struct state { 77 | bool show_user_defined_docstrings = true; //< Include user-supplied texts in docstrings. 78 | bool show_function_signatures = true; //< Include auto-generated function signatures 79 | // in docstrings. 80 | bool show_enum_members_docstring = true; //< Include auto-generated member list in enum 81 | // docstrings. 82 | }; 83 | 84 | static state &global_state() { 85 | static state instance; 86 | return instance; 87 | } 88 | 89 | state previous_state; 90 | }; 91 | 92 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 93 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/include/pybind11/typing.h: -------------------------------------------------------------------------------- 1 | /* 2 | pybind11/typing.h: Convenience wrapper classes for basic Python types 3 | with more explicit annotations. 4 | 5 | Copyright (c) 2023 Dustin Spicuzza 6 | 7 | All rights reserved. Use of this source code is governed by a 8 | BSD-style license that can be found in the LICENSE file. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "detail/common.h" 14 | #include "cast.h" 15 | #include "pytypes.h" 16 | 17 | PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) 18 | PYBIND11_NAMESPACE_BEGIN(typing) 19 | 20 | /* 21 | The following types can be used to direct pybind11-generated docstrings 22 | to have have more explicit types (e.g., `list[str]` instead of `list`). 23 | Just use these in place of existing types. 24 | 25 | There is no additional enforcement of types at runtime. 26 | */ 27 | 28 | template 29 | class Tuple : public tuple { 30 | using tuple::tuple; 31 | }; 32 | 33 | template 34 | class Dict : public dict { 35 | using dict::dict; 36 | }; 37 | 38 | template 39 | class List : public list { 40 | using list::list; 41 | }; 42 | 43 | template 44 | class Set : public set { 45 | using set::set; 46 | }; 47 | 48 | template 49 | class Iterable : public iterable { 50 | using iterable::iterable; 51 | }; 52 | 53 | template 54 | class Iterator : public iterator { 55 | using iterator::iterator; 56 | }; 57 | 58 | template 59 | class Callable; 60 | 61 | template 62 | class Callable : public function { 63 | using function::function; 64 | }; 65 | 66 | PYBIND11_NAMESPACE_END(typing) 67 | 68 | PYBIND11_NAMESPACE_BEGIN(detail) 69 | 70 | template 71 | struct handle_type_name> { 72 | static constexpr auto name 73 | = const_name("tuple[") + concat(make_caster::name...) + const_name("]"); 74 | }; 75 | 76 | template <> 77 | struct handle_type_name> { 78 | // PEP 484 specifies this syntax for an empty tuple 79 | static constexpr auto name = const_name("tuple[()]"); 80 | }; 81 | 82 | template 83 | struct handle_type_name> { 84 | static constexpr auto name = const_name("dict[") + make_caster::name + const_name(", ") 85 | + make_caster::name + const_name("]"); 86 | }; 87 | 88 | template 89 | struct handle_type_name> { 90 | static constexpr auto name = const_name("list[") + make_caster::name + const_name("]"); 91 | }; 92 | 93 | template 94 | struct handle_type_name> { 95 | static constexpr auto name = const_name("set[") + make_caster::name + const_name("]"); 96 | }; 97 | 98 | template 99 | struct handle_type_name> { 100 | static constexpr auto name = const_name("Iterable[") + make_caster::name + const_name("]"); 101 | }; 102 | 103 | template 104 | struct handle_type_name> { 105 | static constexpr auto name = const_name("Iterator[") + make_caster::name + const_name("]"); 106 | }; 107 | 108 | template 109 | struct handle_type_name> { 110 | using retval_type = conditional_t::value, void_type, Return>; 111 | static constexpr auto name = const_name("Callable[[") + concat(make_caster::name...) 112 | + const_name("], ") + make_caster::name 113 | + const_name("]"); 114 | }; 115 | 116 | PYBIND11_NAMESPACE_END(detail) 117 | PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) 118 | -------------------------------------------------------------------------------- /external/pybind11/noxfile.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import nox 4 | 5 | nox.needs_version = ">=2022.1.7" 6 | nox.options.sessions = ["lint", "tests", "tests_packaging"] 7 | 8 | PYTHON_VERSIONS = [ 9 | "3.6", 10 | "3.7", 11 | "3.8", 12 | "3.9", 13 | "3.10", 14 | "3.11", 15 | "pypy3.7", 16 | "pypy3.8", 17 | "pypy3.9", 18 | ] 19 | 20 | if os.environ.get("CI", None): 21 | nox.options.error_on_missing_interpreters = True 22 | 23 | 24 | @nox.session(reuse_venv=True) 25 | def lint(session: nox.Session) -> None: 26 | """ 27 | Lint the codebase (except for clang-format/tidy). 28 | """ 29 | session.install("pre-commit") 30 | session.run("pre-commit", "run", "-a", *session.posargs) 31 | 32 | 33 | @nox.session(python=PYTHON_VERSIONS) 34 | def tests(session: nox.Session) -> None: 35 | """ 36 | Run the tests (requires a compiler). 37 | """ 38 | tmpdir = session.create_tmp() 39 | session.install("cmake") 40 | session.install("-r", "tests/requirements.txt") 41 | session.run( 42 | "cmake", 43 | "-S.", 44 | f"-B{tmpdir}", 45 | "-DPYBIND11_WERROR=ON", 46 | "-DDOWNLOAD_CATCH=ON", 47 | "-DDOWNLOAD_EIGEN=ON", 48 | *session.posargs, 49 | ) 50 | session.run("cmake", "--build", tmpdir) 51 | session.run("cmake", "--build", tmpdir, "--config=Release", "--target", "check") 52 | 53 | 54 | @nox.session 55 | def tests_packaging(session: nox.Session) -> None: 56 | """ 57 | Run the packaging tests. 58 | """ 59 | 60 | session.install("-r", "tests/requirements.txt", "--prefer-binary") 61 | session.run("pytest", "tests/extra_python_package", *session.posargs) 62 | 63 | 64 | @nox.session(reuse_venv=True) 65 | def docs(session: nox.Session) -> None: 66 | """ 67 | Build the docs. Pass "serve" to serve. 68 | """ 69 | 70 | session.install("-r", "docs/requirements.txt") 71 | session.chdir("docs") 72 | 73 | if "pdf" in session.posargs: 74 | session.run("sphinx-build", "-M", "latexpdf", ".", "_build") 75 | return 76 | 77 | session.run("sphinx-build", "-M", "html", ".", "_build") 78 | 79 | if "serve" in session.posargs: 80 | session.log("Launching docs at http://localhost:8000/ - use Ctrl-C to quit") 81 | session.run("python", "-m", "http.server", "8000", "-d", "_build/html") 82 | elif session.posargs: 83 | session.error("Unsupported argument to docs") 84 | 85 | 86 | @nox.session(reuse_venv=True) 87 | def make_changelog(session: nox.Session) -> None: 88 | """ 89 | Inspect the closed issues and make entries for a changelog. 90 | """ 91 | session.install("ghapi", "rich") 92 | session.run("python", "tools/make_changelog.py") 93 | 94 | 95 | @nox.session(reuse_venv=True) 96 | def build(session: nox.Session) -> None: 97 | """ 98 | Build SDists and wheels. 99 | """ 100 | 101 | session.install("build") 102 | session.log("Building normal files") 103 | session.run("python", "-m", "build", *session.posargs) 104 | session.log("Building pybind11-global files (PYBIND11_GLOBAL_SDIST=1)") 105 | session.run( 106 | "python", "-m", "build", *session.posargs, env={"PYBIND11_GLOBAL_SDIST": "1"} 107 | ) 108 | -------------------------------------------------------------------------------- /external/pybind11/pybind11/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | if sys.version_info < (3, 6): # noqa: UP036 4 | msg = "pybind11 does not support Python < 3.6. 2.9 was the last release supporting Python 2.7 and 3.5." 5 | raise ImportError(msg) 6 | 7 | 8 | from ._version import __version__, version_info 9 | from .commands import get_cmake_dir, get_include, get_pkgconfig_dir 10 | 11 | __all__ = ( 12 | "version_info", 13 | "__version__", 14 | "get_include", 15 | "get_cmake_dir", 16 | "get_pkgconfig_dir", 17 | ) 18 | -------------------------------------------------------------------------------- /external/pybind11/pybind11/__main__.py: -------------------------------------------------------------------------------- 1 | # pylint: disable=missing-function-docstring 2 | 3 | import argparse 4 | import sys 5 | import sysconfig 6 | 7 | from ._version import __version__ 8 | from .commands import get_cmake_dir, get_include, get_pkgconfig_dir 9 | 10 | 11 | def print_includes() -> None: 12 | dirs = [ 13 | sysconfig.get_path("include"), 14 | sysconfig.get_path("platinclude"), 15 | get_include(), 16 | ] 17 | 18 | # Make unique but preserve order 19 | unique_dirs = [] 20 | for d in dirs: 21 | if d and d not in unique_dirs: 22 | unique_dirs.append(d) 23 | 24 | print(" ".join("-I" + d for d in unique_dirs)) 25 | 26 | 27 | def main() -> None: 28 | parser = argparse.ArgumentParser() 29 | parser.add_argument( 30 | "--version", 31 | action="version", 32 | version=__version__, 33 | help="Print the version and exit.", 34 | ) 35 | parser.add_argument( 36 | "--includes", 37 | action="store_true", 38 | help="Include flags for both pybind11 and Python headers.", 39 | ) 40 | parser.add_argument( 41 | "--cmakedir", 42 | action="store_true", 43 | help="Print the CMake module directory, ideal for setting -Dpybind11_ROOT in CMake.", 44 | ) 45 | parser.add_argument( 46 | "--pkgconfigdir", 47 | action="store_true", 48 | help="Print the pkgconfig directory, ideal for setting $PKG_CONFIG_PATH.", 49 | ) 50 | args = parser.parse_args() 51 | if not sys.argv[1:]: 52 | parser.print_help() 53 | if args.includes: 54 | print_includes() 55 | if args.cmakedir: 56 | print(get_cmake_dir()) 57 | if args.pkgconfigdir: 58 | print(get_pkgconfig_dir()) 59 | 60 | 61 | if __name__ == "__main__": 62 | main() 63 | -------------------------------------------------------------------------------- /external/pybind11/pybind11/_version.py: -------------------------------------------------------------------------------- 1 | from typing import Union 2 | 3 | 4 | def _to_int(s: str) -> Union[int, str]: 5 | try: 6 | return int(s) 7 | except ValueError: 8 | return s 9 | 10 | 11 | __version__ = "2.12.0.dev1" 12 | version_info = tuple(_to_int(s) for s in __version__.split(".")) 13 | -------------------------------------------------------------------------------- /external/pybind11/pybind11/commands.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | DIR = os.path.abspath(os.path.dirname(__file__)) 4 | 5 | 6 | def get_include(user: bool = False) -> str: # noqa: ARG001 7 | """ 8 | Return the path to the pybind11 include directory. The historical "user" 9 | argument is unused, and may be removed. 10 | """ 11 | installed_path = os.path.join(DIR, "include") 12 | source_path = os.path.join(os.path.dirname(DIR), "include") 13 | return installed_path if os.path.exists(installed_path) else source_path 14 | 15 | 16 | def get_cmake_dir() -> str: 17 | """ 18 | Return the path to the pybind11 CMake module directory. 19 | """ 20 | cmake_installed_path = os.path.join(DIR, "share", "cmake", "pybind11") 21 | if os.path.exists(cmake_installed_path): 22 | return cmake_installed_path 23 | 24 | msg = "pybind11 not installed, installation required to access the CMake files" 25 | raise ImportError(msg) 26 | 27 | 28 | def get_pkgconfig_dir() -> str: 29 | """ 30 | Return the path to the pybind11 pkgconfig directory. 31 | """ 32 | pkgconfig_installed_path = os.path.join(DIR, "share", "pkgconfig") 33 | if os.path.exists(pkgconfig_installed_path): 34 | return pkgconfig_installed_path 35 | 36 | msg = "pybind11 not installed, installation required to access the pkgconfig files" 37 | raise ImportError(msg) 38 | -------------------------------------------------------------------------------- /external/pybind11/pybind11/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/external/pybind11/pybind11/py.typed -------------------------------------------------------------------------------- /external/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.7" 23 | strict = true 24 | show_error_codes = true 25 | enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] 26 | warn_unreachable = true 27 | 28 | [[tool.mypy.overrides]] 29 | module = ["ghapi.*"] 30 | ignore_missing_imports = true 31 | 32 | 33 | [tool.pytest.ini_options] 34 | minversion = "6.0" 35 | addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"] 36 | xfail_strict = true 37 | filterwarnings = ["error"] 38 | log_cli_level = "info" 39 | testpaths = [ 40 | "tests", 41 | ] 42 | timeout=300 43 | 44 | 45 | [tool.pylint] 46 | master.py-version = "3.6" 47 | reports.output-format = "colorized" 48 | messages_control.disable = [ 49 | "design", 50 | "fixme", 51 | "imports", 52 | "line-too-long", 53 | "imports", 54 | "invalid-name", 55 | "protected-access", 56 | "missing-module-docstring", 57 | "unused-argument", # covered by Ruff ARG 58 | ] 59 | 60 | [tool.ruff] 61 | target-version = "py37" 62 | src = ["src"] 63 | 64 | [tool.ruff.lint] 65 | extend-select = [ 66 | "B", # flake8-bugbear 67 | "I", # isort 68 | "N", # pep8-naming 69 | "ARG", # flake8-unused-arguments 70 | "C4", # flake8-comprehensions 71 | "EM", # flake8-errmsg 72 | "ICN", # flake8-import-conventions 73 | "PGH", # pygrep-hooks 74 | "PIE", # flake8-pie 75 | "PL", # pylint 76 | "PT", # flake8-pytest-style 77 | "RET", # flake8-return 78 | "RUF100", # Ruff-specific 79 | "SIM", # flake8-simplify 80 | "UP", # pyupgrade 81 | "YTT", # flake8-2020 82 | ] 83 | ignore = [ 84 | "PLR", # Design related pylint 85 | "E501", # Line too long (Black is enough) 86 | "PT011", # Too broad with raises in pytest 87 | "PT004", # Fixture that doesn't return needs underscore (no, it is fine) 88 | "SIM118", # iter(x) is not always the same as iter(x.keys()) 89 | ] 90 | unfixable = ["T20"] 91 | isort.known-first-party = ["env", "pybind11_cross_module_tests", "pybind11_tests"] 92 | 93 | [tool.ruff.lint.per-file-ignores] 94 | "tests/**" = ["EM", "N", "E721"] 95 | "tests/test_call_policies.py" = ["PLC1901"] 96 | -------------------------------------------------------------------------------- /external/pybind11/setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | long_description = file: README.rst 3 | long_description_content_type = text/x-rst 4 | description = Seamless operability between C++11 and Python 5 | author = Wenzel Jakob 6 | author_email = wenzel.jakob@epfl.ch 7 | url = https://github.com/pybind/pybind11 8 | license = BSD 9 | 10 | classifiers = 11 | Development Status :: 5 - Production/Stable 12 | Intended Audience :: Developers 13 | Topic :: Software Development :: Libraries :: Python Modules 14 | Topic :: Utilities 15 | Programming Language :: C++ 16 | Programming Language :: Python :: 3 :: Only 17 | Programming Language :: Python :: 3.6 18 | Programming Language :: Python :: 3.7 19 | Programming Language :: Python :: 3.8 20 | Programming Language :: Python :: 3.9 21 | Programming Language :: Python :: 3.10 22 | Programming Language :: Python :: 3.11 23 | Programming Language :: Python :: 3.12 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.6 43 | zip_safe = False 44 | -------------------------------------------------------------------------------- /external/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 | PyModule_AddObject( 46 | m, 47 | "funcaddr", 48 | PyLong_FromVoidPtr(reinterpret_cast(&interleaved_error_already_set))); 49 | } 50 | return m; 51 | } 52 | -------------------------------------------------------------------------------- /external/pybind11/tests/eigen_tensor_avoid_stl_array.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/eigen_tensor.cpp -- automatic conversion of Eigen Tensor 3 | 4 | All rights reserved. Use of this source code is governed by a 5 | BSD-style license that can be found in the LICENSE file. 6 | */ 7 | 8 | #ifndef EIGEN_AVOID_STL_ARRAY 9 | # define EIGEN_AVOID_STL_ARRAY 10 | #endif 11 | 12 | #include "test_eigen_tensor.inl" 13 | 14 | PYBIND11_MODULE(eigen_tensor_avoid_stl_array, m) { eigen_tensor_test::test_module(m); } 15 | -------------------------------------------------------------------------------- /external/pybind11/tests/env.py: -------------------------------------------------------------------------------- 1 | import platform 2 | import sys 3 | 4 | import pytest 5 | 6 | LINUX = sys.platform.startswith("linux") 7 | MACOS = sys.platform.startswith("darwin") 8 | WIN = sys.platform.startswith("win32") or sys.platform.startswith("cygwin") 9 | 10 | CPYTHON = platform.python_implementation() == "CPython" 11 | PYPY = platform.python_implementation() == "PyPy" 12 | 13 | 14 | def deprecated_call(): 15 | """ 16 | pytest.deprecated_call() seems broken in pytest<3.9.x; concretely, it 17 | doesn't work on CPython 3.8.0 with pytest==3.3.2 on Ubuntu 18.04 (#2922). 18 | 19 | This is a narrowed reimplementation of the following PR :( 20 | https://github.com/pytest-dev/pytest/pull/4104 21 | """ 22 | # TODO: Remove this when testing requires pytest>=3.9. 23 | pieces = pytest.__version__.split(".") 24 | pytest_major_minor = (int(pieces[0]), int(pieces[1])) 25 | if pytest_major_minor < (3, 9): 26 | return pytest.warns((DeprecationWarning, PendingDeprecationWarning)) 27 | return pytest.deprecated_call() 28 | -------------------------------------------------------------------------------- /external/pybind11/tests/extra_python_package/pytest.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/external/pybind11/tests/extra_python_package/pytest.ini -------------------------------------------------------------------------------- /external/pybind11/tests/extra_setuptools/pytest.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/external/pybind11/tests/extra_setuptools/pytest.ini -------------------------------------------------------------------------------- /external/pybind11/tests/local_bindings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "pybind11_tests.h" 3 | 4 | #include 5 | 6 | /// Simple class used to test py::local: 7 | template 8 | class LocalBase { 9 | public: 10 | explicit LocalBase(int i) : i(i) {} 11 | int i = -1; 12 | }; 13 | 14 | /// Registered with py::module_local in both main and secondary modules: 15 | using LocalType = LocalBase<0>; 16 | /// Registered without py::module_local in both modules: 17 | using NonLocalType = LocalBase<1>; 18 | /// A second non-local type (for stl_bind tests): 19 | using NonLocal2 = LocalBase<2>; 20 | /// Tests within-module, different-compilation-unit local definition conflict: 21 | using LocalExternal = LocalBase<3>; 22 | /// Mixed: registered local first, then global 23 | using MixedLocalGlobal = LocalBase<4>; 24 | /// Mixed: global first, then local 25 | using MixedGlobalLocal = LocalBase<5>; 26 | 27 | /// Registered with py::module_local only in the secondary module: 28 | using ExternalType1 = LocalBase<6>; 29 | using ExternalType2 = LocalBase<7>; 30 | 31 | using LocalVec = std::vector; 32 | using LocalVec2 = std::vector; 33 | using LocalMap = std::unordered_map; 34 | using NonLocalVec = std::vector; 35 | using NonLocalVec2 = std::vector; 36 | using NonLocalMap = std::unordered_map; 37 | using NonLocalMap2 = std::unordered_map; 38 | 39 | // Exception that will be caught via the module local translator. 40 | class LocalException : public std::exception { 41 | public: 42 | explicit LocalException(const char *m) : message{m} {} 43 | const char *what() const noexcept override { return message.c_str(); } 44 | 45 | private: 46 | std::string message = ""; 47 | }; 48 | 49 | // Exception that will be registered with register_local_exception_translator 50 | class LocalSimpleException : public std::exception { 51 | public: 52 | explicit LocalSimpleException(const char *m) : message{m} {} 53 | const char *what() const noexcept override { return message.c_str(); } 54 | 55 | private: 56 | std::string message = ""; 57 | }; 58 | 59 | PYBIND11_MAKE_OPAQUE(LocalVec); 60 | PYBIND11_MAKE_OPAQUE(LocalVec2); 61 | PYBIND11_MAKE_OPAQUE(LocalMap); 62 | PYBIND11_MAKE_OPAQUE(NonLocalVec); 63 | // PYBIND11_MAKE_OPAQUE(NonLocalVec2); // same type as LocalVec2 64 | PYBIND11_MAKE_OPAQUE(NonLocalMap); 65 | PYBIND11_MAKE_OPAQUE(NonLocalMap2); 66 | 67 | // Simple bindings (used with the above): 68 | template 69 | py::class_ bind_local(Args &&...args) { 70 | return py::class_(std::forward(args)...).def(py::init()).def("get", [](T &i) { 71 | return i.i + Adjust; 72 | }); 73 | }; 74 | 75 | // Simulate a foreign library base class (to match the example in the docs): 76 | namespace pets { 77 | class Pet { 78 | public: 79 | explicit Pet(std::string name) : name_(std::move(name)) {} 80 | std::string name_; 81 | const std::string &name() const { return name_; } 82 | }; 83 | } // namespace pets 84 | 85 | struct MixGL { 86 | int i; 87 | explicit MixGL(int i) : i{i} {} 88 | }; 89 | struct MixGL2 { 90 | int i; 91 | explicit MixGL2(int i) : i{i} {} 92 | }; 93 | -------------------------------------------------------------------------------- /external/pybind11/tests/pybind11_tests.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace py = pybind11; 7 | using namespace pybind11::literals; 8 | 9 | class test_initializer { 10 | using Initializer = void (*)(py::module_ &); 11 | 12 | public: 13 | explicit test_initializer(Initializer init); 14 | test_initializer(const char *submodule_name, Initializer init); 15 | }; 16 | 17 | #define TEST_SUBMODULE(name, variable) \ 18 | void test_submodule_##name(py::module_ &); \ 19 | test_initializer name(#name, test_submodule_##name); \ 20 | void test_submodule_##name(py::module_ &(variable)) 21 | 22 | /// Dummy type which is not exported anywhere -- something to trigger a conversion error 23 | struct UnregisteredType {}; 24 | 25 | /// A user-defined type which is exported and can be used by any test 26 | class UserType { 27 | public: 28 | UserType() = default; 29 | explicit UserType(int i) : i(i) {} 30 | 31 | int value() const { return i; } 32 | void set(int set) { i = set; } 33 | 34 | private: 35 | int i = -1; 36 | }; 37 | 38 | /// Like UserType, but increments `value` on copy for quick reference vs. copy tests 39 | class IncType : public UserType { 40 | public: 41 | using UserType::UserType; 42 | IncType() = default; 43 | IncType(const IncType &other) : IncType(other.value() + 1) {} 44 | IncType(IncType &&) = delete; 45 | IncType &operator=(const IncType &) = delete; 46 | IncType &operator=(IncType &&) = delete; 47 | }; 48 | 49 | /// A simple union for basic testing 50 | union IntFloat { 51 | int i; 52 | float f; 53 | }; 54 | 55 | /// Custom cast-only type that casts to a string "rvalue" or "lvalue" depending on the cast 56 | /// context. Used to test recursive casters (e.g. std::tuple, stl containers). 57 | struct RValueCaster {}; 58 | PYBIND11_NAMESPACE_BEGIN(pybind11) 59 | PYBIND11_NAMESPACE_BEGIN(detail) 60 | template <> 61 | class type_caster { 62 | public: 63 | PYBIND11_TYPE_CASTER(RValueCaster, const_name("RValueCaster")); 64 | static handle cast(RValueCaster &&, return_value_policy, handle) { 65 | return py::str("rvalue").release(); 66 | } 67 | static handle cast(const RValueCaster &, return_value_policy, handle) { 68 | return py::str("lvalue").release(); 69 | } 70 | }; 71 | PYBIND11_NAMESPACE_END(detail) 72 | PYBIND11_NAMESPACE_END(pybind11) 73 | 74 | template 75 | void ignoreOldStyleInitWarnings(F &&body) { 76 | py::exec(R"( 77 | message = "pybind11-bound class '.+' is using an old-style placement-new '(?:__init__|__setstate__)' which has been deprecated" 78 | 79 | import warnings 80 | with warnings.catch_warnings(): 81 | warnings.filterwarnings("ignore", message=message, category=FutureWarning) 82 | body() 83 | )", 84 | py::dict(py::arg("body") = py::cpp_function(body))); 85 | } 86 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/requirements.txt: -------------------------------------------------------------------------------- 1 | build==0.8.0 2 | numpy==1.21.5; platform_python_implementation=="PyPy" and sys_platform=="linux" and python_version=="3.7" 3 | numpy==1.19.3; platform_python_implementation!="PyPy" and python_version=="3.6" 4 | numpy==1.21.5; platform_python_implementation!="PyPy" and python_version>="3.7" and python_version<"3.10" 5 | numpy==1.22.2; platform_python_implementation!="PyPy" and python_version>="3.10" and python_version<"3.11" 6 | pytest==7.0.0; platform_python_implementation!="PyPy" and python_version=="3.6" 7 | pytest==7.2.0; platform_python_implementation!="PyPy" and python_version>="3.7" 8 | pytest-timeout 9 | scipy==1.5.4; platform_python_implementation!="PyPy" and python_version<"3.10" 10 | scipy==1.10.0; platform_python_implementation!="PyPy" and python_version=="3.10" 11 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_async.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | asyncio = pytest.importorskip("asyncio") 4 | m = pytest.importorskip("pybind11_tests.async_module") 5 | 6 | 7 | @pytest.fixture() 8 | def event_loop(): 9 | loop = asyncio.new_event_loop() 10 | yield loop 11 | loop.close() 12 | 13 | 14 | async def get_await_result(x): 15 | return await x 16 | 17 | 18 | def test_await(event_loop): 19 | assert event_loop.run_until_complete(get_await_result(m.SupportsAsync())) == 5 20 | 21 | 22 | def test_await_missing(event_loop): 23 | with pytest.raises(TypeError): 24 | event_loop.run_until_complete(get_await_result(m.DoesNotSupportAsync())) 25 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_chrono.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_chrono.cpp -- test conversions to/from std::chrono types 3 | 4 | Copyright (c) 2016 Trent Houliston and 5 | Wenzel Jakob 6 | 7 | All rights reserved. Use of this source code is governed by a 8 | BSD-style license that can be found in the LICENSE file. 9 | */ 10 | 11 | #include 12 | 13 | #include "pybind11_tests.h" 14 | 15 | #include 16 | 17 | struct different_resolutions { 18 | using time_point_h = std::chrono::time_point; 19 | using time_point_m = std::chrono::time_point; 20 | using time_point_s = std::chrono::time_point; 21 | using time_point_ms 22 | = std::chrono::time_point; 23 | using time_point_us 24 | = std::chrono::time_point; 25 | time_point_h timestamp_h; 26 | time_point_m timestamp_m; 27 | time_point_s timestamp_s; 28 | time_point_ms timestamp_ms; 29 | time_point_us timestamp_us; 30 | }; 31 | 32 | TEST_SUBMODULE(chrono, m) { 33 | using system_time = std::chrono::system_clock::time_point; 34 | using steady_time = std::chrono::steady_clock::time_point; 35 | 36 | using timespan = std::chrono::duration; 37 | using timestamp = std::chrono::time_point; 38 | 39 | // test_chrono_system_clock 40 | // Return the current time off the wall clock 41 | m.def("test_chrono1", []() { return std::chrono::system_clock::now(); }); 42 | 43 | // test_chrono_system_clock_roundtrip 44 | // Round trip the passed in system clock time 45 | m.def("test_chrono2", [](system_time t) { return t; }); 46 | 47 | // test_chrono_duration_roundtrip 48 | // Round trip the passed in duration 49 | m.def("test_chrono3", [](std::chrono::system_clock::duration d) { return d; }); 50 | 51 | // test_chrono_duration_subtraction_equivalence 52 | // Difference between two passed in time_points 53 | m.def("test_chrono4", [](system_time a, system_time b) { return a - b; }); 54 | 55 | // test_chrono_steady_clock 56 | // Return the current time off the steady_clock 57 | m.def("test_chrono5", []() { return std::chrono::steady_clock::now(); }); 58 | 59 | // test_chrono_steady_clock_roundtrip 60 | // Round trip a steady clock timepoint 61 | m.def("test_chrono6", [](steady_time t) { return t; }); 62 | 63 | // test_floating_point_duration 64 | // Roundtrip a duration in microseconds from a float argument 65 | m.def("test_chrono7", [](std::chrono::microseconds t) { return t; }); 66 | // Float durations (issue #719) 67 | m.def("test_chrono_float_diff", 68 | [](std::chrono::duration a, std::chrono::duration b) { return a - b; }); 69 | 70 | m.def("test_nano_timepoint", 71 | [](timestamp start, timespan delta) -> timestamp { return start + delta; }); 72 | 73 | // Test different resolutions 74 | py::class_(m, "different_resolutions") 75 | .def(py::init<>()) 76 | .def_readwrite("timestamp_h", &different_resolutions::timestamp_h) 77 | .def_readwrite("timestamp_m", &different_resolutions::timestamp_m) 78 | .def_readwrite("timestamp_s", &different_resolutions::timestamp_s) 79 | .def_readwrite("timestamp_ms", &different_resolutions::timestamp_ms) 80 | .def_readwrite("timestamp_us", &different_resolutions::timestamp_us); 81 | } 82 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_cmake_build/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_custom_target(test_cmake_build) 2 | 3 | function(pybind11_add_build_test name) 4 | cmake_parse_arguments(ARG "INSTALL" "" "" ${ARGN}) 5 | 6 | set(build_options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}") 7 | 8 | if(PYBIND11_FINDPYTHON) 9 | list(APPEND build_options "-DPYBIND11_FINDPYTHON=${PYBIND11_FINDPYTHON}") 10 | 11 | if(DEFINED Python_ROOT_DIR) 12 | list(APPEND build_options "-DPython_ROOT_DIR=${Python_ROOT_DIR}") 13 | endif() 14 | 15 | list(APPEND build_options "-DPython_EXECUTABLE=${Python_EXECUTABLE}") 16 | else() 17 | list(APPEND build_options "-DPYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}") 18 | endif() 19 | 20 | if(DEFINED CMAKE_CXX_STANDARD) 21 | list(APPEND build_options "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}") 22 | endif() 23 | 24 | if(NOT ARG_INSTALL) 25 | list(APPEND build_options "-Dpybind11_SOURCE_DIR=${pybind11_SOURCE_DIR}") 26 | else() 27 | list(APPEND build_options "-DCMAKE_PREFIX_PATH=${pybind11_BINARY_DIR}/mock_install") 28 | endif() 29 | 30 | add_custom_target( 31 | test_build_${name} 32 | ${CMAKE_CTEST_COMMAND} 33 | --build-and-test 34 | "${CMAKE_CURRENT_SOURCE_DIR}/${name}" 35 | "${CMAKE_CURRENT_BINARY_DIR}/${name}" 36 | --build-config 37 | Release 38 | --build-noclean 39 | --build-generator 40 | ${CMAKE_GENERATOR} 41 | $<$:--build-generator-platform> 42 | ${CMAKE_GENERATOR_PLATFORM} 43 | --build-makeprogram 44 | ${CMAKE_MAKE_PROGRAM} 45 | --build-target 46 | check_${name} 47 | --build-options 48 | ${build_options}) 49 | if(ARG_INSTALL) 50 | add_dependencies(test_build_${name} mock_install) 51 | endif() 52 | add_dependencies(test_cmake_build test_build_${name}) 53 | endfunction() 54 | 55 | possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID) 56 | 57 | pybind11_add_build_test(subdirectory_function) 58 | pybind11_add_build_test(subdirectory_target) 59 | if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy") 60 | message(STATUS "Skipping embed test on PyPy") 61 | else() 62 | pybind11_add_build_test(subdirectory_embed) 63 | endif() 64 | 65 | if(PYBIND11_INSTALL) 66 | add_custom_target( 67 | mock_install ${CMAKE_COMMAND} "-DCMAKE_INSTALL_PREFIX=${pybind11_BINARY_DIR}/mock_install" -P 68 | "${pybind11_BINARY_DIR}/cmake_install.cmake") 69 | 70 | pybind11_add_build_test(installed_function INSTALL) 71 | pybind11_add_build_test(installed_target INSTALL) 72 | if(NOT ("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy" 73 | )) 74 | pybind11_add_build_test(installed_embed INSTALL) 75 | endif() 76 | endif() 77 | 78 | add_dependencies(check test_cmake_build) 79 | 80 | add_subdirectory(subdirectory_target EXCLUDE_FROM_ALL) 81 | add_subdirectory(subdirectory_embed EXCLUDE_FROM_ALL) 82 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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.26)` 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.26) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.26) 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 | -------------------------------------------------------------------------------- /external/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.26)` 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.26) 8 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 9 | else() 10 | cmake_policy(VERSION 3.26) 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 | -------------------------------------------------------------------------------- /external/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.26)` 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.26) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.26) 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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_cmake_build/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace py = pybind11; 3 | 4 | PYBIND11_MODULE(test_cmake_build, m) { 5 | m.def("add", [](int i, int j) { return i + j; }); 6 | } 7 | -------------------------------------------------------------------------------- /external/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.26)` 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.26) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.26) 10 | endif() 11 | 12 | project(test_subdirectory_embed CXX) 13 | 14 | set(PYBIND11_INSTALL 15 | ON 16 | CACHE BOOL "") 17 | set(PYBIND11_EXPORT_NAME test_export) 18 | 19 | add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) 20 | 21 | # Test basic target functionality 22 | add_executable(test_subdirectory_embed ../embed.cpp) 23 | target_link_libraries(test_subdirectory_embed PRIVATE pybind11::embed) 24 | set_target_properties(test_subdirectory_embed PROPERTIES OUTPUT_NAME test_cmake_build) 25 | 26 | add_custom_target( 27 | check_subdirectory_embed 28 | $ "${PROJECT_SOURCE_DIR}/../test.py" 29 | DEPENDS test_subdirectory_embed) 30 | 31 | # Test custom export group -- PYBIND11_EXPORT_NAME 32 | add_library(test_embed_lib ../embed.cpp) 33 | target_link_libraries(test_embed_lib PRIVATE pybind11::embed) 34 | 35 | install( 36 | TARGETS test_embed_lib 37 | EXPORT test_export 38 | ARCHIVE DESTINATION bin 39 | LIBRARY DESTINATION lib 40 | RUNTIME DESTINATION lib) 41 | install(EXPORT test_export DESTINATION lib/cmake/test_export/test_export-Targets.cmake) 42 | -------------------------------------------------------------------------------- /external/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.26)` 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.26) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.26) 10 | endif() 11 | 12 | project(test_subdirectory_function CXX) 13 | 14 | add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) 15 | pybind11_add_module(test_subdirectory_function ../main.cpp) 16 | set_target_properties(test_subdirectory_function PROPERTIES OUTPUT_NAME test_cmake_build) 17 | 18 | if(DEFINED Python_EXECUTABLE) 19 | set(_Python_EXECUTABLE "${Python_EXECUTABLE}") 20 | elseif(DEFINED PYTHON_EXECUTABLE) 21 | set(_Python_EXECUTABLE "${PYTHON_EXECUTABLE}") 22 | else() 23 | message(FATAL_ERROR "No Python executable defined (should not be possible at this stage)") 24 | endif() 25 | 26 | add_custom_target( 27 | check_subdirectory_function 28 | ${CMAKE_COMMAND} 29 | -E 30 | env 31 | PYTHONPATH=$ 32 | ${_Python_EXECUTABLE} 33 | ${PROJECT_SOURCE_DIR}/../test.py 34 | ${PROJECT_NAME} 35 | DEPENDS test_subdirectory_function) 36 | -------------------------------------------------------------------------------- /external/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.26)` 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.26) 7 | cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 8 | else() 9 | cmake_policy(VERSION 3.26) 10 | endif() 11 | 12 | project(test_subdirectory_target CXX) 13 | 14 | add_subdirectory("${pybind11_SOURCE_DIR}" pybind11) 15 | 16 | add_library(test_subdirectory_target MODULE ../main.cpp) 17 | set_target_properties(test_subdirectory_target PROPERTIES OUTPUT_NAME test_cmake_build) 18 | 19 | target_link_libraries(test_subdirectory_target PRIVATE pybind11::module) 20 | 21 | # Make sure result is, for example, test_installed_target.so, not libtest_installed_target.dylib 22 | pybind11_extension(test_subdirectory_target) 23 | 24 | if(DEFINED Python_EXECUTABLE) 25 | set(_Python_EXECUTABLE "${Python_EXECUTABLE}") 26 | elseif(DEFINED PYTHON_EXECUTABLE) 27 | set(_Python_EXECUTABLE "${PYTHON_EXECUTABLE}") 28 | else() 29 | message(FATAL_ERROR "No Python executable defined (should not be possible at this stage)") 30 | endif() 31 | 32 | add_custom_target( 33 | check_subdirectory_target 34 | ${CMAKE_COMMAND} 35 | -E 36 | env 37 | PYTHONPATH=$ 38 | ${_Python_EXECUTABLE} 39 | ${PROJECT_SOURCE_DIR}/../test.py 40 | ${PROJECT_NAME} 41 | DEPENDS test_subdirectory_target) 42 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_cmake_build/test.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | import test_cmake_build 4 | 5 | assert isinstance(__file__, str) # Test this is properly set 6 | 7 | assert test_cmake_build.add(1, 2) == 3 8 | print(f"{sys.argv[1]} imports, runs, and adds: 1 + 2 = 3") 9 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_const_name.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 The Pybind Development Team. 2 | // All rights reserved. Use of this source code is governed by a 3 | // BSD-style license that can be found in the LICENSE file. 4 | 5 | #include "pybind11_tests.h" 6 | 7 | // IUT = Implementation Under Test 8 | #define CONST_NAME_TESTS(TEST_FUNC, IUT) \ 9 | std::string TEST_FUNC(int selector) { \ 10 | switch (selector) { \ 11 | case 0: \ 12 | return IUT("").text; \ 13 | case 1: \ 14 | return IUT("A").text; \ 15 | case 2: \ 16 | return IUT("Bd").text; \ 17 | case 3: \ 18 | return IUT("Cef").text; \ 19 | case 4: \ 20 | return IUT().text; /*NOLINT(bugprone-macro-parentheses)*/ \ 21 | case 5: \ 22 | return IUT().text; /*NOLINT(bugprone-macro-parentheses)*/ \ 23 | case 6: \ 24 | return IUT("T1", "T2").text; /*NOLINT(bugprone-macro-parentheses)*/ \ 25 | case 7: \ 26 | return IUT("U1", "U2").text; /*NOLINT(bugprone-macro-parentheses)*/ \ 27 | case 8: \ 28 | /*NOLINTNEXTLINE(bugprone-macro-parentheses)*/ \ 29 | return IUT(IUT("D1"), IUT("D2")).text; \ 30 | case 9: \ 31 | /*NOLINTNEXTLINE(bugprone-macro-parentheses)*/ \ 32 | return IUT(IUT("E1"), IUT("E2")).text; \ 33 | case 10: \ 34 | return IUT("KeepAtEnd").text; \ 35 | default: \ 36 | break; \ 37 | } \ 38 | throw std::runtime_error("Invalid selector value."); \ 39 | } 40 | 41 | CONST_NAME_TESTS(const_name_tests, py::detail::const_name) 42 | 43 | #ifdef PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY 44 | CONST_NAME_TESTS(underscore_tests, py::detail::_) 45 | #endif 46 | 47 | TEST_SUBMODULE(const_name, m) { 48 | m.def("const_name_tests", const_name_tests); 49 | 50 | #if defined(PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY) 51 | m.def("underscore_tests", underscore_tests); 52 | #else 53 | m.attr("underscore_tests") = "PYBIND11_DETAIL_UNDERSCORE_BACKWARD_COMPATIBILITY not defined."; 54 | #endif 55 | } 56 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_const_name.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pybind11_tests import const_name as m 4 | 5 | 6 | @pytest.mark.parametrize("func", [m.const_name_tests, m.underscore_tests]) 7 | @pytest.mark.parametrize( 8 | ("selector", "expected"), 9 | enumerate( 10 | ( 11 | "", 12 | "A", 13 | "Bd", 14 | "Cef", 15 | "%", 16 | "%", 17 | "T1", 18 | "U2", 19 | "D1", 20 | "E2", 21 | "KeepAtEnd", 22 | ) 23 | ), 24 | ) 25 | def test_const_name(func, selector, expected): 26 | if isinstance(func, str): 27 | pytest.skip(func) 28 | text = func(selector) 29 | assert text == expected 30 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_constants_and_functions.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | m = pytest.importorskip("pybind11_tests.constants_and_functions") 4 | 5 | 6 | def test_constants(): 7 | assert m.some_constant == 14 8 | 9 | 10 | def test_function_overloading(): 11 | assert m.test_function() == "test_function()" 12 | assert m.test_function(7) == "test_function(7)" 13 | assert m.test_function(m.MyEnum.EFirstEntry) == "test_function(enum=1)" 14 | assert m.test_function(m.MyEnum.ESecondEntry) == "test_function(enum=2)" 15 | 16 | assert m.test_function() == "test_function()" 17 | assert m.test_function("abcd") == "test_function(char *)" 18 | assert m.test_function(1, 1.0) == "test_function(int, float)" 19 | assert m.test_function(1, 1.0) == "test_function(int, float)" 20 | assert m.test_function(2.0, 2) == "test_function(float, int)" 21 | 22 | 23 | def test_bytes(): 24 | assert m.print_bytes(m.return_bytes()) == "bytes[1 0 2 0]" 25 | 26 | 27 | def test_exception_specifiers(): 28 | c = m.C() 29 | assert c.m1(2) == 1 30 | assert c.m2(3) == 1 31 | assert c.m3(5) == 2 32 | assert c.m4(7) == 3 33 | assert c.m5(10) == 5 34 | assert c.m6(14) == 8 35 | assert c.m7(20) == 13 36 | assert c.m8(29) == 21 37 | 38 | assert m.f1(33) == 34 39 | assert m.f2(53) == 55 40 | assert m.f3(86) == 89 41 | assert m.f4(140) == 144 42 | 43 | 44 | def test_function_record_leaks(): 45 | class RaisingRepr: 46 | def __repr__(self): 47 | raise RuntimeError("Surprise!") 48 | 49 | with pytest.raises(RuntimeError): 50 | m.register_large_capture_with_invalid_arguments(m) 51 | with pytest.raises(RuntimeError): 52 | m.register_with_raising_repr(m, RaisingRepr()) 53 | 54 | 55 | def test_noexcept_lambda(): 56 | assert m.l1() == 0 57 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_custom_type_setup.py: -------------------------------------------------------------------------------- 1 | import gc 2 | import weakref 3 | 4 | import pytest 5 | 6 | import env # noqa: F401 7 | from pybind11_tests import custom_type_setup as m 8 | 9 | 10 | @pytest.fixture() 11 | def gc_tester(): 12 | """Tests that an object is garbage collected. 13 | 14 | Assumes that any unreferenced objects are fully collected after calling 15 | `gc.collect()`. That is true on CPython, but does not appear to reliably 16 | hold on PyPy. 17 | """ 18 | 19 | weak_refs = [] 20 | 21 | def add_ref(obj): 22 | # PyPy does not support `gc.is_tracked`. 23 | if hasattr(gc, "is_tracked"): 24 | assert gc.is_tracked(obj) 25 | weak_refs.append(weakref.ref(obj)) 26 | 27 | yield add_ref 28 | 29 | gc.collect() 30 | for ref in weak_refs: 31 | assert ref() is None 32 | 33 | 34 | # PyPy does not seem to reliably garbage collect. 35 | @pytest.mark.skipif("env.PYPY") 36 | def test_self_cycle(gc_tester): 37 | obj = m.OwnsPythonObjects() 38 | obj.value = obj 39 | gc_tester(obj) 40 | 41 | 42 | # PyPy does not seem to reliably garbage collect. 43 | @pytest.mark.skipif("env.PYPY") 44 | def test_indirect_cycle(gc_tester): 45 | obj = m.OwnsPythonObjects() 46 | obj_list = [obj] 47 | obj.value = obj_list 48 | gc_tester(obj) 49 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_docstring_options.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import docstring_options as m 2 | 3 | 4 | def test_docstring_options(): 5 | # options.disable_function_signatures() 6 | assert not m.test_function1.__doc__ 7 | 8 | assert m.test_function2.__doc__ == "A custom docstring" 9 | 10 | # docstring specified on just the first overload definition: 11 | assert m.test_overloaded1.__doc__ == "Overload docstring" 12 | 13 | # docstring on both overloads: 14 | assert m.test_overloaded2.__doc__ == "overload docstring 1\noverload docstring 2" 15 | 16 | # docstring on only second overload: 17 | assert m.test_overloaded3.__doc__ == "Overload docstr" 18 | 19 | # options.enable_function_signatures() 20 | assert m.test_function3.__doc__.startswith("test_function3(a: int, b: int) -> None") 21 | 22 | assert m.test_function4.__doc__.startswith("test_function4(a: int, b: int) -> None") 23 | assert m.test_function4.__doc__.endswith("A custom docstring\n") 24 | 25 | # options.disable_function_signatures() 26 | # options.disable_user_defined_docstrings() 27 | assert not m.test_function5.__doc__ 28 | 29 | # nested options.enable_user_defined_docstrings() 30 | assert m.test_function6.__doc__ == "A custom docstring" 31 | 32 | # RAII destructor 33 | assert m.test_function7.__doc__.startswith("test_function7(a: int, b: int) -> None") 34 | assert m.test_function7.__doc__.endswith("A custom docstring\n") 35 | 36 | # when all options are disabled, no docstring (instead of an empty one) should be generated 37 | assert m.test_function8.__doc__ is None 38 | 39 | # Suppression of user-defined docstrings for non-function objects 40 | assert not m.DocstringTestFoo.__doc__ 41 | assert not m.DocstringTestFoo.value_prop.__doc__ 42 | 43 | # Check existig behaviour of enum docstings 44 | assert ( 45 | m.DocstringTestEnum1.__doc__ 46 | == "Enum docstring\n\nMembers:\n\n Member1\n\n Member2" 47 | ) 48 | 49 | # options.enable_enum_members_docstring() 50 | assert ( 51 | m.DocstringTestEnum2.__doc__ 52 | == "Enum docstring\n\nMembers:\n\n Member1\n\n Member2" 53 | ) 54 | 55 | # options.disable_enum_members_docstring() 56 | assert m.DocstringTestEnum3.__doc__ == "Enum docstring" 57 | 58 | # options.disable_user_defined_docstrings() 59 | assert m.DocstringTestEnum4.__doc__ == "Members:\n\n Member1\n\n Member2" 60 | 61 | # options.disable_user_defined_docstrings() 62 | # options.disable_enum_members_docstring() 63 | # When all options are disabled, no docstring (instead of an empty one) should be generated 64 | assert m.DocstringTestEnum5.__doc__ is None 65 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_embed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID) 2 | 3 | if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy") 4 | message(STATUS "Skipping embed test on PyPy") 5 | add_custom_target(cpptest) # Dummy target on PyPy. Embedding is not supported. 6 | set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}") 7 | return() 8 | endif() 9 | 10 | find_package(Catch 2.13.9) 11 | 12 | if(CATCH_FOUND) 13 | message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}") 14 | else() 15 | message(STATUS "Catch not detected. Interpreter tests will be skipped. Install Catch headers" 16 | " manually or use `cmake -DDOWNLOAD_CATCH=ON` to fetch them automatically.") 17 | return() 18 | endif() 19 | 20 | find_package(Threads REQUIRED) 21 | 22 | add_executable(test_embed catch.cpp test_interpreter.cpp) 23 | pybind11_enable_warnings(test_embed) 24 | 25 | target_link_libraries(test_embed PRIVATE pybind11::embed Catch2::Catch2 Threads::Threads) 26 | 27 | if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) 28 | file(COPY test_interpreter.py test_trampoline.py DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") 29 | endif() 30 | 31 | add_custom_target( 32 | cpptest 33 | COMMAND "$" 34 | DEPENDS test_embed 35 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") 36 | 37 | pybind11_add_module(external_module THIN_LTO external_module.cpp) 38 | set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY 39 | "${CMAKE_CURRENT_BINARY_DIR}") 40 | foreach(config ${CMAKE_CONFIGURATION_TYPES}) 41 | string(TOUPPER ${config} config) 42 | set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config} 43 | "${CMAKE_CURRENT_BINARY_DIR}") 44 | endforeach() 45 | add_dependencies(cpptest external_module) 46 | 47 | add_dependencies(check cpptest) 48 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_embed/external_module.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace py = pybind11; 4 | 5 | /* Simple test module/test class to check that the referenced internals data of external pybind11 6 | * modules aren't preserved over a finalize/initialize. 7 | */ 8 | 9 | PYBIND11_MODULE(external_module, m) { 10 | class A { 11 | public: 12 | explicit A(int value) : v{value} {}; 13 | int v; 14 | }; 15 | 16 | py::class_(m, "A").def(py::init()).def_readwrite("value", &A::v); 17 | 18 | m.def("internals_at", 19 | []() { return reinterpret_cast(&py::detail::get_internals()); }); 20 | } 21 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_embed/test_interpreter.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from widget_module import Widget 4 | 5 | 6 | class DerivedWidget(Widget): 7 | def __init__(self, message): 8 | super().__init__(message) 9 | 10 | def the_answer(self): 11 | return 42 12 | 13 | def argv0(self): 14 | return sys.argv[0] 15 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_embed/test_trampoline.py: -------------------------------------------------------------------------------- 1 | import trampoline_module 2 | 3 | 4 | def func(): 5 | class Test(trampoline_module.test_override_cache_helper): 6 | def func(self): 7 | return 42 8 | 9 | return Test() 10 | 11 | 12 | def func2(): 13 | class Test(trampoline_module.test_override_cache_helper): 14 | pass 15 | 16 | return Test() 17 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_eval.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_eval.cpp -- Usage of eval() and eval_file() 3 | 4 | Copyright (c) 2016 Klemens D. Morgenstern 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | #include "pybind11_tests.h" 13 | 14 | #include 15 | 16 | TEST_SUBMODULE(eval_, m) { 17 | // test_evals 18 | 19 | auto global = py::dict(py::module_::import("__main__").attr("__dict__")); 20 | 21 | m.def("test_eval_statements", [global]() { 22 | auto local = py::dict(); 23 | local["call_test"] = py::cpp_function([&]() -> int { return 42; }); 24 | 25 | // Regular string literal 26 | py::exec("message = 'Hello World!'\n" 27 | "x = call_test()", 28 | global, 29 | local); 30 | 31 | // Multi-line raw string literal 32 | py::exec(R"( 33 | if x == 42: 34 | print(message) 35 | else: 36 | raise RuntimeError 37 | )", 38 | global, 39 | local); 40 | auto x = local["x"].cast(); 41 | 42 | return x == 42; 43 | }); 44 | 45 | m.def("test_eval", [global]() { 46 | auto local = py::dict(); 47 | local["x"] = py::int_(42); 48 | auto x = py::eval("x", global, local); 49 | return x.cast() == 42; 50 | }); 51 | 52 | m.def("test_eval_single_statement", []() { 53 | auto local = py::dict(); 54 | local["call_test"] = py::cpp_function([&]() -> int { return 42; }); 55 | 56 | auto result = py::eval("x = call_test()", py::dict(), local); 57 | auto x = local["x"].cast(); 58 | return result.is_none() && x == 42; 59 | }); 60 | 61 | m.def("test_eval_file", [global](py::str filename) { 62 | auto local = py::dict(); 63 | local["y"] = py::int_(43); 64 | 65 | int val_out = 0; 66 | local["call_test2"] = py::cpp_function([&](int value) { val_out = value; }); 67 | 68 | auto result = py::eval_file(std::move(filename), global, local); 69 | return val_out == 43 && result.is_none(); 70 | }); 71 | 72 | m.def("test_eval_failure", []() { 73 | try { 74 | py::eval("nonsense code ..."); 75 | } catch (py::error_already_set &) { 76 | return true; 77 | } 78 | return false; 79 | }); 80 | 81 | m.def("test_eval_file_failure", []() { 82 | try { 83 | py::eval_file("non-existing file"); 84 | } catch (std::exception &) { 85 | return true; 86 | } 87 | return false; 88 | }); 89 | 90 | // test_eval_empty_globals 91 | m.def("eval_empty_globals", [](py::object global) { 92 | if (global.is_none()) { 93 | global = py::dict(); 94 | } 95 | auto int_class = py::eval("isinstance(42, int)", global); 96 | return global; 97 | }); 98 | 99 | // test_eval_closure 100 | m.def("test_eval_closure", []() { 101 | py::dict global; 102 | global["closure_value"] = 42; 103 | py::dict local; 104 | local["closure_value"] = 0; 105 | py::exec(R"( 106 | local_value = closure_value 107 | 108 | def func_global(): 109 | return closure_value 110 | 111 | def func_local(): 112 | return local_value 113 | )", 114 | global, 115 | local); 116 | return std::make_pair(global, local); 117 | }); 118 | } 119 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_eval.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import pytest 4 | 5 | import env # noqa: F401 6 | from pybind11_tests import eval_ as m 7 | 8 | 9 | def test_evals(capture): 10 | with capture: 11 | assert m.test_eval_statements() 12 | assert capture == "Hello World!" 13 | 14 | assert m.test_eval() 15 | assert m.test_eval_single_statement() 16 | 17 | assert m.test_eval_failure() 18 | 19 | 20 | @pytest.mark.xfail("env.PYPY", raises=RuntimeError) 21 | def test_eval_file(): 22 | filename = os.path.join(os.path.dirname(__file__), "test_eval_call.py") 23 | assert m.test_eval_file(filename) 24 | 25 | assert m.test_eval_file_failure() 26 | 27 | 28 | def test_eval_empty_globals(): 29 | assert "__builtins__" in m.eval_empty_globals(None) 30 | 31 | g = {} 32 | assert "__builtins__" in m.eval_empty_globals(g) 33 | assert "__builtins__" in g 34 | 35 | 36 | def test_eval_closure(): 37 | global_, local = m.test_eval_closure() 38 | 39 | assert global_["closure_value"] == 42 40 | assert local["closure_value"] == 0 41 | 42 | assert "local_value" not in global_ 43 | assert local["local_value"] == 0 44 | 45 | assert "func_global" not in global_ 46 | assert local["func_global"]() == 42 47 | 48 | assert "func_local" not in global_ 49 | with pytest.raises(NameError): 50 | local["func_local"]() 51 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_eval_call.py: -------------------------------------------------------------------------------- 1 | # This file is called from 'test_eval.py' 2 | 3 | if "call_test2" in locals(): 4 | call_test2(y) # noqa: F821 undefined name 5 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_opaque_types.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | tests/test_opaque_types.cpp -- opaque types, passing void pointers 3 | 4 | Copyright (c) 2016 Wenzel Jakob 5 | 6 | All rights reserved. Use of this source code is governed by a 7 | BSD-style license that can be found in the LICENSE file. 8 | */ 9 | 10 | #include 11 | 12 | #include "pybind11_tests.h" 13 | 14 | #include 15 | 16 | // IMPORTANT: Disable internal pybind11 translation mechanisms for STL data structures 17 | // 18 | // This also deliberately doesn't use the below StringList type alias to test 19 | // that MAKE_OPAQUE can handle a type containing a `,`. (The `std::allocator` 20 | // bit is just the default `std::vector` allocator). 21 | PYBIND11_MAKE_OPAQUE(std::vector>); 22 | 23 | using StringList = std::vector>; 24 | 25 | TEST_SUBMODULE(opaque_types, m) { 26 | // test_string_list 27 | py::class_(m, "StringList") 28 | .def(py::init<>()) 29 | .def("pop_back", &StringList::pop_back) 30 | /* There are multiple versions of push_back(), etc. Select the right ones. */ 31 | .def("push_back", (void(StringList::*)(const std::string &)) & StringList::push_back) 32 | .def("back", (std::string & (StringList::*) ()) & StringList::back) 33 | .def("__len__", [](const StringList &v) { return v.size(); }) 34 | .def( 35 | "__iter__", 36 | [](StringList &v) { return py::make_iterator(v.begin(), v.end()); }, 37 | py::keep_alive<0, 1>()); 38 | 39 | class ClassWithSTLVecProperty { 40 | public: 41 | StringList stringList; 42 | }; 43 | py::class_(m, "ClassWithSTLVecProperty") 44 | .def(py::init<>()) 45 | .def_readwrite("stringList", &ClassWithSTLVecProperty::stringList); 46 | 47 | m.def("print_opaque_list", [](const StringList &l) { 48 | std::string ret = "Opaque list: ["; 49 | bool first = true; 50 | for (const auto &entry : l) { 51 | if (!first) { 52 | ret += ", "; 53 | } 54 | ret += entry; 55 | first = false; 56 | } 57 | return ret + "]"; 58 | }); 59 | 60 | // test_pointers 61 | m.def("return_void_ptr", []() { return (void *) 0x1234; }); 62 | m.def("get_void_ptr_value", [](void *ptr) { return reinterpret_cast(ptr); }); 63 | m.def("return_null_str", []() { return (char *) nullptr; }); 64 | m.def("get_null_str_value", [](char *ptr) { return reinterpret_cast(ptr); }); 65 | 66 | m.def("return_unique_ptr", []() -> std::unique_ptr { 67 | auto *result = new StringList(); 68 | result->push_back("some value"); 69 | return std::unique_ptr(result); 70 | }); 71 | 72 | // test unions 73 | py::class_(m, "IntFloat") 74 | .def(py::init<>()) 75 | .def_readwrite("i", &IntFloat::i) 76 | .def_readwrite("f", &IntFloat::f); 77 | } 78 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_opaque_types.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pybind11_tests import ConstructorStats, UserType 4 | from pybind11_tests import opaque_types as m 5 | 6 | 7 | def test_string_list(): 8 | lst = m.StringList() 9 | lst.push_back("Element 1") 10 | lst.push_back("Element 2") 11 | assert m.print_opaque_list(lst) == "Opaque list: [Element 1, Element 2]" 12 | assert lst.back() == "Element 2" 13 | 14 | for i, k in enumerate(lst, start=1): 15 | assert k == f"Element {i}" 16 | lst.pop_back() 17 | assert m.print_opaque_list(lst) == "Opaque list: [Element 1]" 18 | 19 | cvp = m.ClassWithSTLVecProperty() 20 | assert m.print_opaque_list(cvp.stringList) == "Opaque list: []" 21 | 22 | cvp.stringList = lst 23 | cvp.stringList.push_back("Element 3") 24 | assert m.print_opaque_list(cvp.stringList) == "Opaque list: [Element 1, Element 3]" 25 | 26 | 27 | def test_pointers(msg): 28 | living_before = ConstructorStats.get(UserType).alive() 29 | assert m.get_void_ptr_value(m.return_void_ptr()) == 0x1234 30 | assert m.get_void_ptr_value(UserType()) # Should also work for other C++ types 31 | assert ConstructorStats.get(UserType).alive() == living_before 32 | 33 | with pytest.raises(TypeError) as excinfo: 34 | m.get_void_ptr_value([1, 2, 3]) # This should not work 35 | assert ( 36 | msg(excinfo.value) 37 | == """ 38 | get_void_ptr_value(): incompatible function arguments. The following argument types are supported: 39 | 1. (arg0: capsule) -> int 40 | 41 | Invoked with: [1, 2, 3] 42 | """ 43 | ) 44 | 45 | assert m.return_null_str() is None 46 | assert m.get_null_str_value(m.return_null_str()) is not None 47 | 48 | ptr = m.return_unique_ptr() 49 | assert "StringList" in repr(ptr) 50 | assert m.print_opaque_list(ptr) == "Opaque list: [some value]" 51 | 52 | 53 | def test_unions(): 54 | int_float_union = m.IntFloat() 55 | int_float_union.i = 42 56 | assert int_float_union.i == 42 57 | int_float_union.f = 3.0 58 | assert int_float_union.f == 3.0 59 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_pickling.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import re 3 | 4 | import pytest 5 | 6 | import env 7 | from pybind11_tests import pickling as m 8 | 9 | 10 | def test_pickle_simple_callable(): 11 | assert m.simple_callable() == 20220426 12 | if env.PYPY: 13 | serialized = pickle.dumps(m.simple_callable) 14 | deserialized = pickle.loads(serialized) 15 | assert deserialized() == 20220426 16 | else: 17 | # To document broken behavior: currently it fails universally with 18 | # all C Python versions. 19 | with pytest.raises(TypeError) as excinfo: 20 | pickle.dumps(m.simple_callable) 21 | assert re.search("can.*t pickle .*PyCapsule.* object", str(excinfo.value)) 22 | 23 | 24 | @pytest.mark.parametrize("cls_name", ["Pickleable", "PickleableNew"]) 25 | def test_roundtrip(cls_name): 26 | cls = getattr(m, cls_name) 27 | p = cls("test_value") 28 | p.setExtra1(15) 29 | p.setExtra2(48) 30 | 31 | data = pickle.dumps(p, 2) # Must use pickle protocol >= 2 32 | p2 = pickle.loads(data) 33 | assert p2.value() == p.value() 34 | assert p2.extra1() == p.extra1() 35 | assert p2.extra2() == p.extra2() 36 | 37 | 38 | @pytest.mark.xfail("env.PYPY") 39 | @pytest.mark.parametrize("cls_name", ["PickleableWithDict", "PickleableWithDictNew"]) 40 | def test_roundtrip_with_dict(cls_name): 41 | cls = getattr(m, cls_name) 42 | p = cls("test_value") 43 | p.extra = 15 44 | p.dynamic = "Attribute" 45 | 46 | data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL) 47 | p2 = pickle.loads(data) 48 | assert p2.value == p.value 49 | assert p2.extra == p.extra 50 | assert p2.dynamic == p.dynamic 51 | 52 | 53 | def test_enum_pickle(): 54 | from pybind11_tests import enums as e 55 | 56 | data = pickle.dumps(e.EOne, 2) 57 | assert e.EOne == pickle.loads(data) 58 | 59 | 60 | # 61 | # exercise_trampoline 62 | # 63 | class SimplePyDerived(m.SimpleBase): 64 | pass 65 | 66 | 67 | def test_roundtrip_simple_py_derived(): 68 | p = SimplePyDerived() 69 | p.num = 202 70 | p.stored_in_dict = 303 71 | data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL) 72 | p2 = pickle.loads(data) 73 | assert isinstance(p2, SimplePyDerived) 74 | assert p2.num == 202 75 | assert p2.stored_in_dict == 303 76 | 77 | 78 | def test_roundtrip_simple_cpp_derived(): 79 | p = m.make_SimpleCppDerivedAsBase() 80 | assert m.check_dynamic_cast_SimpleCppDerived(p) 81 | p.num = 404 82 | if not env.PYPY: 83 | # To ensure that this unit test is not accidentally invalidated. 84 | with pytest.raises(AttributeError): 85 | # Mimics the `setstate` C++ implementation. 86 | setattr(p, "__dict__", {}) # noqa: B010 87 | data = pickle.dumps(p, pickle.HIGHEST_PROTOCOL) 88 | p2 = pickle.loads(data) 89 | assert isinstance(p2, m.SimpleBase) 90 | assert p2.num == 404 91 | # Issue #3062: pickleable base C++ classes can incur object slicing 92 | # if derived typeid is not registered with pybind11 93 | assert not m.check_dynamic_cast_SimpleCppDerived(p2) 94 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | 4 | from pybind11_tests import python_multiple_inheritance as m 5 | 6 | 7 | class PC(m.CppBase): 8 | pass 9 | 10 | 11 | class PPCC(PC, m.CppDrvd): 12 | pass 13 | 14 | 15 | def test_PC(): 16 | d = PC(11) 17 | assert d.get_base_value() == 11 18 | d.reset_base_value(13) 19 | assert d.get_base_value() == 13 20 | 21 | 22 | def test_PPCC(): 23 | d = PPCC(11) 24 | assert d.get_drvd_value() == 33 25 | d.reset_drvd_value(55) 26 | assert d.get_drvd_value() == 55 27 | 28 | assert d.get_base_value() == 11 29 | assert d.get_base_value_from_drvd() == 11 30 | d.reset_base_value(20) 31 | assert d.get_base_value() == 20 32 | assert d.get_base_value_from_drvd() == 20 33 | d.reset_base_value_from_drvd(30) 34 | assert d.get_base_value() == 30 35 | assert d.get_base_value_from_drvd() == 30 36 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_tagbased_polymorphic.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import tagbased_polymorphic as m 2 | 3 | 4 | def test_downcast(): 5 | zoo = m.create_zoo() 6 | assert [type(animal) for animal in zoo] == [ 7 | m.Labrador, 8 | m.Dog, 9 | m.Chihuahua, 10 | m.Cat, 11 | m.Panther, 12 | ] 13 | assert [animal.name for animal in zoo] == [ 14 | "Fido", 15 | "Ginger", 16 | "Hertzl", 17 | "Tiger", 18 | "Leo", 19 | ] 20 | zoo[1].sound = "woooooo" 21 | assert [dog.bark() for dog in zoo[:3]] == [ 22 | "Labrador Fido goes WOOF!", 23 | "Dog Ginger goes woooooo", 24 | "Chihuahua Hertzl goes iyiyiyiyiyi and runs in circles", 25 | ] 26 | assert [cat.purr() for cat in zoo[3:]] == ["mrowr", "mrrrRRRRRR"] 27 | zoo[0].excitement -= 1000 28 | assert zoo[0].excitement == 14000 29 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_thread.py: -------------------------------------------------------------------------------- 1 | import threading 2 | 3 | from pybind11_tests import thread as m 4 | 5 | 6 | class Thread(threading.Thread): 7 | def __init__(self, fn): 8 | super().__init__() 9 | self.fn = fn 10 | self.e = None 11 | 12 | def run(self): 13 | try: 14 | for i in range(10): 15 | self.fn(i, i) 16 | except Exception as e: 17 | self.e = e 18 | 19 | def join(self): 20 | super().join() 21 | if self.e: 22 | raise self.e 23 | 24 | 25 | def test_implicit_conversion(): 26 | a = Thread(m.test) 27 | b = Thread(m.test) 28 | c = Thread(m.test) 29 | for x in [a, b, c]: 30 | x.start() 31 | for x in [c, b, a]: 32 | x.join() 33 | 34 | 35 | def test_implicit_conversion_no_gil(): 36 | a = Thread(m.test_no_gil) 37 | b = Thread(m.test_no_gil) 38 | c = Thread(m.test_no_gil) 39 | for x in [a, b, c]: 40 | x.start() 41 | for x in [c, b, a]: 42 | x.join() 43 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_type_caster_pyobject_ptr.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pybind11_tests import type_caster_pyobject_ptr as m 4 | 5 | 6 | # For use as a temporary user-defined object, to maximize sensitivity of the tests below. 7 | class ValueHolder: 8 | def __init__(self, value): 9 | self.value = value 10 | 11 | 12 | def test_cast_from_pyobject_ptr(): 13 | assert m.cast_from_pyobject_ptr() == 6758 14 | 15 | 16 | def test_cast_handle_to_pyobject_ptr(): 17 | assert m.cast_handle_to_pyobject_ptr(ValueHolder(24)) == 76 18 | 19 | 20 | def test_cast_object_to_pyobject_ptr(): 21 | assert m.cast_object_to_pyobject_ptr(ValueHolder(43)) == 257 22 | 23 | 24 | def test_cast_list_to_pyobject_ptr(): 25 | assert m.cast_list_to_pyobject_ptr([1, 2, 3, 4, 5]) == 395 26 | 27 | 28 | def test_return_pyobject_ptr(): 29 | assert m.return_pyobject_ptr() == 2314 30 | 31 | 32 | def test_pass_pyobject_ptr(): 33 | assert m.pass_pyobject_ptr(ValueHolder(82)) == 118 34 | 35 | 36 | @pytest.mark.parametrize( 37 | "call_callback", 38 | [ 39 | m.call_callback_with_object_return, 40 | m.call_callback_with_pyobject_ptr_return, 41 | ], 42 | ) 43 | def test_call_callback_with_object_return(call_callback): 44 | def cb(value): 45 | if value < 0: 46 | raise ValueError("Raised from cb") 47 | return ValueHolder(1000 - value) 48 | 49 | assert call_callback(cb, 287).value == 713 50 | 51 | with pytest.raises(ValueError, match="^Raised from cb$"): 52 | call_callback(cb, -1) 53 | 54 | 55 | def test_call_callback_with_pyobject_ptr_arg(): 56 | def cb(obj): 57 | return 300 - obj.value 58 | 59 | assert m.call_callback_with_pyobject_ptr_arg(cb, ValueHolder(39)) == 261 60 | 61 | 62 | @pytest.mark.parametrize("set_error", [True, False]) 63 | def test_cast_to_python_nullptr(set_error): 64 | expected = { 65 | True: r"^Reflective of healthy error handling\.$", 66 | False: ( 67 | r"^Internal error: pybind11::error_already_set called " 68 | r"while Python error indicator not set\.$" 69 | ), 70 | }[set_error] 71 | with pytest.raises(RuntimeError, match=expected): 72 | m.cast_to_pyobject_ptr_nullptr(set_error) 73 | 74 | 75 | def test_cast_to_python_non_nullptr_with_error_set(): 76 | with pytest.raises(SystemError) as excinfo: 77 | m.cast_to_pyobject_ptr_non_nullptr_with_error_set() 78 | assert str(excinfo.value) == "src != nullptr but PyErr_Occurred()" 79 | assert str(excinfo.value.__cause__) == "Reflective of unhealthy error handling." 80 | 81 | 82 | def test_pass_list_pyobject_ptr(): 83 | acc = m.pass_list_pyobject_ptr([ValueHolder(842), ValueHolder(452)]) 84 | assert acc == 842452 85 | 86 | 87 | def test_return_list_pyobject_ptr_take_ownership(): 88 | vec_obj = m.return_list_pyobject_ptr_take_ownership(ValueHolder) 89 | assert [e.value for e in vec_obj] == [93, 186] 90 | 91 | 92 | def test_return_list_pyobject_ptr_reference(): 93 | vec_obj = m.return_list_pyobject_ptr_reference(ValueHolder) 94 | assert [e.value for e in vec_obj] == [93, 186] 95 | # Commenting out the next `assert` will leak the Python references. 96 | # An easy way to see evidence of the leaks: 97 | # Insert `while True:` as the first line of this function and monitor the 98 | # process RES (Resident Memory Size) with the Unix top command. 99 | assert m.dec_ref_each_pyobject_ptr(vec_obj) == 2 100 | 101 | 102 | def test_type_caster_name_via_incompatible_function_arguments_type_error(): 103 | with pytest.raises(TypeError, match=r"1\. \(arg0: object, arg1: int\) -> None"): 104 | m.pass_pyobject_ptr_and_int(ValueHolder(101), ValueHolder(202)) 105 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_union.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import union_ as m 2 | 3 | 4 | def test_union(): 5 | instance = m.TestUnion() 6 | 7 | instance.as_uint = 10 8 | assert instance.as_int == 10 9 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_unnamed_namespace_a.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pybind11_tests import unnamed_namespace_a as m 4 | from pybind11_tests import unnamed_namespace_b as mb 5 | 6 | XFAIL_CONDITION = ( 7 | "(m.PYBIND11_INTERNALS_VERSION <= 4 and (m.defined___clang__ or not m.defined___GLIBCXX__))" 8 | " or " 9 | "(m.PYBIND11_INTERNALS_VERSION >= 5 and not m.defined_WIN32_or__WIN32" 10 | " and " 11 | "(m.defined___clang__ or m.defined__LIBCPP_VERSION))" 12 | ) 13 | XFAIL_REASON = "Known issues: https://github.com/pybind/pybind11/pull/4319" 14 | 15 | 16 | @pytest.mark.xfail(XFAIL_CONDITION, reason=XFAIL_REASON, strict=False) 17 | @pytest.mark.parametrize( 18 | "any_struct", [m.unnamed_namespace_a_any_struct, mb.unnamed_namespace_b_any_struct] 19 | ) 20 | def test_have_class_any_struct(any_struct): 21 | assert any_struct is not None 22 | 23 | 24 | def test_have_at_least_one_class_any_struct(): 25 | assert ( 26 | m.unnamed_namespace_a_any_struct is not None 27 | or mb.unnamed_namespace_b_any_struct is not None 28 | ) 29 | 30 | 31 | @pytest.mark.xfail(XFAIL_CONDITION, reason=XFAIL_REASON, strict=True) 32 | def test_have_both_class_any_struct(): 33 | assert m.unnamed_namespace_a_any_struct is not None 34 | assert mb.unnamed_namespace_b_any_struct is not None 35 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_unnamed_namespace_b.py: -------------------------------------------------------------------------------- 1 | from pybind11_tests import unnamed_namespace_b as m 2 | 3 | 4 | def test_have_attr_any_struct(): 5 | assert hasattr(m, "unnamed_namespace_b_any_struct") 6 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tests/test_vector_unique_ptr_member.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pybind11_tests import vector_unique_ptr_member as m 4 | 5 | 6 | @pytest.mark.parametrize("num_elems", range(3)) 7 | def test_create(num_elems): 8 | vo = m.VectorOwner.Create(num_elems) 9 | assert vo.data_size() == num_elems 10 | 11 | 12 | def test_cast(): 13 | vo = m.VectorOwner.Create(0) 14 | assert m.py_cast_VectorOwner_ptr(vo) is vo 15 | -------------------------------------------------------------------------------- /external/pybind11/tests/valgrind-numpy-scipy.supp: -------------------------------------------------------------------------------- 1 | # Valgrind suppression file for NumPy & SciPy errors and leaks in pybind11 tests 2 | # 3 | # On updating a dependency, to get a list of "default" leaks in e.g. NumPy, run 4 | # `PYTHONMALLOC=malloc valgrind --leak-check=full --show-leak-kinds=definite,indirect python3.9-dbg -c "import numpy"` 5 | # To use these suppression files, add e.g. `--suppressions=valgrind-numpy-scipy.supp` 6 | 7 | { 8 | Leaks when importing NumPy 9 | Memcheck:Leak 10 | fun:malloc 11 | fun:_PyMem_RawMalloc 12 | fun:PyObject_Malloc 13 | fun:_PyObject_GC_Alloc 14 | fun:_PyObject_GC_Malloc 15 | fun:_PyObject_GC_NewVar 16 | fun:tuple_alloc 17 | fun:PyTuple_Pack 18 | ... 19 | fun:__pyx_pymod_exec_* 20 | } 21 | 22 | { 23 | Leaks when importing NumPy (bis) 24 | Memcheck:Leak 25 | fun:malloc 26 | fun:_PyMem_RawMalloc 27 | fun:PyObject_Malloc 28 | fun:_PyObject_New 29 | fun:PyCode_NewWithPosOnlyArgs 30 | fun:PyCode_New 31 | ... 32 | fun:__pyx_pymod_exec_* 33 | } 34 | 35 | { 36 | Leaks when importing NumPy (ter) 37 | Memcheck:Leak 38 | fun:malloc 39 | fun:_PyMem_RawMalloc 40 | fun:PyObject_Malloc 41 | fun:_PyObject_GC_Alloc 42 | fun:_PyObject_GC_Malloc 43 | fun:_PyObject_GC_NewVar 44 | fun:tuple_alloc 45 | fun:_PyTuple_FromArray 46 | fun:_PyObject_MakeTpCall 47 | fun:_PyObject_VectorcallTstate 48 | fun:PyObject_Vectorcall 49 | fun:call_function 50 | fun:_PyEval_EvalFrameDefault 51 | fun:_PyEval_EvalFrame 52 | fun:function_code_fastcall 53 | fun:_PyFunction_Vectorcall 54 | } 55 | 56 | { 57 | Leaks when importing NumPy (quater) 58 | Memcheck:Leak 59 | fun:malloc 60 | fun:_PyMem_RawMalloc 61 | fun:PyObject_Malloc 62 | fun:_PyObject_GC_Alloc 63 | fun:_PyObject_GC_Malloc 64 | fun:_PyObject_GC_NewVar 65 | fun:tuple_alloc 66 | fun:_PyTuple_FromArray 67 | fun:_PyObject_MakeTpCall 68 | fun:_PyObject_VectorcallTstate 69 | fun:_PyObject_CallFunctionVa 70 | fun:PyObject_CallFunction 71 | fun:PyImport_Import 72 | } 73 | 74 | { 75 | Leaks when importing NumPy (quinquies) 76 | Memcheck:Leak 77 | fun:malloc 78 | fun:_PyMem_RawMalloc 79 | fun:PyObject_Malloc 80 | fun:_PyObject_GC_Alloc 81 | fun:_PyObject_GC_Malloc 82 | fun:_PyObject_GC_NewVar 83 | fun:tuple_alloc 84 | fun:PyTuple_New 85 | fun:r_object 86 | fun:r_object 87 | fun:r_object 88 | fun:r_object 89 | } 90 | 91 | { 92 | Leaks when importing NumPy (sexies) 93 | Memcheck:Leak 94 | fun:malloc 95 | fun:_PyMem_RawMalloc 96 | fun:PyObject_Malloc 97 | fun:_PyObject_GC_Alloc 98 | fun:_PyObject_GC_Malloc 99 | fun:_PyObject_GC_NewVar 100 | fun:tuple_alloc 101 | fun:PyTuple_New 102 | fun:dictiter_iternextitem 103 | fun:list_extend 104 | fun:_PyList_Extend 105 | fun:PySequence_List 106 | } 107 | 108 | { 109 | Leak when importing scipy.fft 110 | Memcheck:Leak 111 | fun:_Znwm 112 | fun:PyInit_pypocketfft 113 | fun:_PyImport_LoadDynamicModuleWithSpec 114 | fun:_imp_create_dynamic_impl* 115 | fun:_imp_create_dynamic 116 | fun:cfunction_vectorcall_FASTCALL 117 | fun:PyVectorcall_Call 118 | fun:_PyObject_Call 119 | fun:PyObject_Call 120 | fun:do_call_core 121 | fun:_PyEval_EvalFrameDefault 122 | fun:_PyEval_EvalFrame 123 | fun:_PyEval_EvalCode 124 | } 125 | 126 | { 127 | NumPy leaks when spawning a subprocess 128 | Memcheck:Leak 129 | fun:malloc 130 | ... 131 | fun:_buffer_get_info 132 | fun:array_getbuffer 133 | fun:PyObject_GetBuffer 134 | fun:__Pyx__GetBufferAndValidate* 135 | fun:__pyx_f_5numpy_6random_13bit_generator_12SeedSequence_mix_entropy 136 | fun:__pyx_pw_5numpy_6random_13bit_generator_12SeedSequence_1__init__ 137 | fun:type_call 138 | fun:__Pyx__PyObject_CallOneArg 139 | fun:__pyx_pw_5numpy_6random_13bit_generator_12BitGenerator_1__init__ 140 | } 141 | -------------------------------------------------------------------------------- /external/pybind11/tests/valgrind-python.supp: -------------------------------------------------------------------------------- 1 | # Valgrind suppression file for CPython errors and leaks in pybind11 tests 2 | 3 | # Taken verbatim from https://github.com/python/cpython/blob/3.9/Misc/valgrind-python.supp#L266-L272 4 | { 5 | Uninitialised byte(s) false alarm, see bpo-35561 6 | Memcheck:Param 7 | epoll_ctl(event) 8 | fun:epoll_ctl 9 | fun:pyepoll_internal_ctl 10 | } 11 | 12 | { 13 | Python leaks when spawning a subprocess 14 | Memcheck:Leak 15 | fun:malloc 16 | fun:_PyMem_RawMalloc 17 | fun:PyMem_RawMalloc 18 | fun:PyThread_allocate_lock 19 | fun:_PyEval_InitState 20 | fun:PyInterpreterState_New 21 | ... 22 | fun:pyinit_core* 23 | fun:Py_InitializeFromConfig 24 | fun:pymain_init 25 | fun:pymain_main 26 | } 27 | 28 | { 29 | Python leaks when spawning a subprocess 30 | Memcheck:Leak 31 | fun:malloc 32 | fun:_PyMem_RawMalloc 33 | fun:_PyMem_DebugRawAlloc 34 | fun:_PyMem_DebugRawMalloc 35 | fun:PyMem_RawMalloc 36 | fun:PyThread_allocate_lock 37 | fun:_PyRuntimeState_Init_impl 38 | fun:_PyRuntimeState_Init 39 | fun:_PyRuntime_Initialize 40 | fun:pymain_init 41 | fun:pymain_main 42 | fun:Py_BytesMain 43 | } 44 | 45 | { 46 | Python leaks when spawning a subprocess 47 | Memcheck:Leak 48 | fun:malloc 49 | fun:_PyMem_RawMalloc 50 | fun:PyMem_RawMalloc 51 | fun:PyThread_allocate_lock 52 | fun:_PyImport_AcquireLock 53 | fun:_imp_acquire_lock_impl* 54 | fun:_imp_acquire_lock 55 | fun:cfunction_vectorcall_NOARGS 56 | fun:_PyObject_VectorcallTstate 57 | fun:PyObject_Vectorcall 58 | fun:call_function 59 | fun:_PyEval_EvalFrameDefault 60 | fun:_PyEval_EvalFrame 61 | fun:function_code_fastcall 62 | } 63 | 64 | { 65 | Python leaks when spawning a subprocess 66 | Memcheck:Leak 67 | fun:malloc 68 | fun:_PyMem_RawMalloc 69 | fun:PyMem_RawMalloc 70 | fun:PyThread_allocate_lock 71 | fun:newlockobject 72 | ... 73 | fun:cfunction_vectorcall_NOARGS 74 | fun:_PyObject_VectorcallTstate 75 | fun:PyObject_Vectorcall 76 | fun:call_function 77 | fun:_PyEval_EvalFrameDefault 78 | fun:_PyEval_EvalFrame 79 | fun:function_code_fastcall 80 | fun:_PyFunction_Vectorcall 81 | } 82 | 83 | { 84 | Python leaks when spawning a subprocess 85 | Memcheck:Leak 86 | fun:malloc 87 | fun:_PyMem_RawMalloc 88 | fun:PyMem_RawMalloc 89 | fun:PyThread_allocate_lock 90 | fun:rlock_new 91 | fun:type_call 92 | fun:_PyObject_Call 93 | fun:PyObject_Call 94 | fun:do_call_core 95 | fun:_PyEval_EvalFrameDefault 96 | fun:_PyEval_EvalFrame 97 | fun:_PyEval_EvalCode 98 | fun:_PyFunction_Vectorcall 99 | } 100 | 101 | # Not really CPython-specific, see link 102 | { 103 | dlopen leak (https://stackoverflow.com/questions/1542457/memory-leak-reported-by-valgrind-in-dlopen) 104 | Memcheck:Leak 105 | fun:malloc 106 | ... 107 | fun:dl_open_worker 108 | fun:_dl_catch_exception 109 | fun:_dl_open 110 | fun:dlopen_doit 111 | fun:_dl_catch_exception 112 | fun:_dl_catch_error 113 | fun:_dlerror_run 114 | fun:dlopen@@GLIBC_2.2.5 115 | fun:_PyImport_FindSharedFuncptr 116 | fun:_PyImport_LoadDynamicModuleWithSpec 117 | } 118 | -------------------------------------------------------------------------------- /external/pybind11/tools/FindCatch.cmake: -------------------------------------------------------------------------------- 1 | # - Find the Catch test framework or download it (single header) 2 | # 3 | # This is a quick module for internal use. It assumes that Catch is 4 | # REQUIRED and that a minimum version is provided (not EXACT). If 5 | # a suitable version isn't found locally, the single header file 6 | # will be downloaded and placed in the build dir: PROJECT_BINARY_DIR. 7 | # 8 | # This code sets the following variables: 9 | # CATCH_INCLUDE_DIR - path to catch.hpp 10 | # CATCH_VERSION - version number 11 | 12 | option(DOWNLOAD_CATCH "Download catch2 if not found") 13 | 14 | if(NOT Catch_FIND_VERSION) 15 | message(FATAL_ERROR "A version number must be specified.") 16 | elseif(Catch_FIND_REQUIRED) 17 | message(FATAL_ERROR "This module assumes Catch is not required.") 18 | elseif(Catch_FIND_VERSION_EXACT) 19 | message(FATAL_ERROR "Exact version numbers are not supported, only minimum.") 20 | endif() 21 | 22 | # Extract the version number from catch.hpp 23 | function(_get_catch_version) 24 | file( 25 | STRINGS "${CATCH_INCLUDE_DIR}/catch.hpp" version_line 26 | REGEX "Catch v.*" 27 | LIMIT_COUNT 1) 28 | if(version_line MATCHES "Catch v([0-9]+)\\.([0-9]+)\\.([0-9]+)") 29 | set(CATCH_VERSION 30 | "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}" 31 | PARENT_SCOPE) 32 | endif() 33 | endfunction() 34 | 35 | # Download the single-header version of Catch 36 | function(_download_catch version destination_dir) 37 | message(STATUS "Downloading catch v${version}...") 38 | set(url https://github.com/philsquared/Catch/releases/download/v${version}/catch.hpp) 39 | file( 40 | DOWNLOAD ${url} "${destination_dir}/catch.hpp" 41 | STATUS status 42 | LOG log) 43 | list(GET status 0 error) 44 | if(error) 45 | string(REPLACE "\n" "\n " log " ${log}") 46 | message(FATAL_ERROR "Could not download URL:\n" " ${url}\n" "Log:\n" "${log}") 47 | endif() 48 | set(CATCH_INCLUDE_DIR 49 | "${destination_dir}" 50 | CACHE INTERNAL "") 51 | endfunction() 52 | 53 | # Look for catch locally 54 | find_path( 55 | CATCH_INCLUDE_DIR 56 | NAMES catch.hpp 57 | PATH_SUFFIXES catch2) 58 | if(CATCH_INCLUDE_DIR) 59 | _get_catch_version() 60 | endif() 61 | 62 | # Download the header if it wasn't found or if it's outdated 63 | if(NOT CATCH_VERSION OR CATCH_VERSION VERSION_LESS ${Catch_FIND_VERSION}) 64 | if(DOWNLOAD_CATCH) 65 | _download_catch(${Catch_FIND_VERSION} "${PROJECT_BINARY_DIR}/catch/") 66 | _get_catch_version() 67 | else() 68 | set(CATCH_FOUND FALSE) 69 | return() 70 | endif() 71 | endif() 72 | 73 | add_library(Catch2::Catch2 IMPORTED INTERFACE) 74 | set_property(TARGET Catch2::Catch2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CATCH_INCLUDE_DIR}") 75 | 76 | set(CATCH_FOUND TRUE) 77 | -------------------------------------------------------------------------------- /external/pybind11/tools/FindEigen3.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Eigen3 lib 2 | # 3 | # This module supports requiring a minimum version, e.g. you can do 4 | # find_package(Eigen3 3.1.2) 5 | # to require version 3.1.2 or newer of Eigen3. 6 | # 7 | # Once done this will define 8 | # 9 | # EIGEN3_FOUND - system has eigen lib with correct version 10 | # EIGEN3_INCLUDE_DIR - the eigen include directory 11 | # EIGEN3_VERSION - eigen version 12 | 13 | # Copyright (c) 2006, 2007 Montel Laurent, 14 | # Copyright (c) 2008, 2009 Gael Guennebaud, 15 | # Copyright (c) 2009 Benoit Jacob 16 | # Redistribution and use is allowed according to the terms of the 2-clause BSD license. 17 | 18 | if(NOT Eigen3_FIND_VERSION) 19 | if(NOT Eigen3_FIND_VERSION_MAJOR) 20 | set(Eigen3_FIND_VERSION_MAJOR 2) 21 | endif(NOT Eigen3_FIND_VERSION_MAJOR) 22 | if(NOT Eigen3_FIND_VERSION_MINOR) 23 | set(Eigen3_FIND_VERSION_MINOR 91) 24 | endif(NOT Eigen3_FIND_VERSION_MINOR) 25 | if(NOT Eigen3_FIND_VERSION_PATCH) 26 | set(Eigen3_FIND_VERSION_PATCH 0) 27 | endif(NOT Eigen3_FIND_VERSION_PATCH) 28 | 29 | set(Eigen3_FIND_VERSION 30 | "${Eigen3_FIND_VERSION_MAJOR}.${Eigen3_FIND_VERSION_MINOR}.${Eigen3_FIND_VERSION_PATCH}") 31 | endif(NOT Eigen3_FIND_VERSION) 32 | 33 | macro(_eigen3_check_version) 34 | file(READ "${EIGEN3_INCLUDE_DIR}/Eigen/src/Core/util/Macros.h" _eigen3_version_header) 35 | 36 | string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen3_world_version_match 37 | "${_eigen3_version_header}") 38 | set(EIGEN3_WORLD_VERSION "${CMAKE_MATCH_1}") 39 | string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen3_major_version_match 40 | "${_eigen3_version_header}") 41 | set(EIGEN3_MAJOR_VERSION "${CMAKE_MATCH_1}") 42 | string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen3_minor_version_match 43 | "${_eigen3_version_header}") 44 | set(EIGEN3_MINOR_VERSION "${CMAKE_MATCH_1}") 45 | 46 | set(EIGEN3_VERSION ${EIGEN3_WORLD_VERSION}.${EIGEN3_MAJOR_VERSION}.${EIGEN3_MINOR_VERSION}) 47 | if(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) 48 | set(EIGEN3_VERSION_OK FALSE) 49 | else(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) 50 | set(EIGEN3_VERSION_OK TRUE) 51 | endif(${EIGEN3_VERSION} VERSION_LESS ${Eigen3_FIND_VERSION}) 52 | 53 | if(NOT EIGEN3_VERSION_OK) 54 | 55 | message(STATUS "Eigen3 version ${EIGEN3_VERSION} found in ${EIGEN3_INCLUDE_DIR}, " 56 | "but at least version ${Eigen3_FIND_VERSION} is required") 57 | endif(NOT EIGEN3_VERSION_OK) 58 | endmacro(_eigen3_check_version) 59 | 60 | if(EIGEN3_INCLUDE_DIR) 61 | 62 | # in cache already 63 | _eigen3_check_version() 64 | set(EIGEN3_FOUND ${EIGEN3_VERSION_OK}) 65 | 66 | else(EIGEN3_INCLUDE_DIR) 67 | if(NOT DEFINED KDE4_INCLUDE_DIR) 68 | set(KDE4_INCLUDE_DIR "") 69 | endif() 70 | 71 | find_path( 72 | EIGEN3_INCLUDE_DIR 73 | NAMES signature_of_eigen3_matrix_library 74 | PATHS ${CMAKE_INSTALL_PREFIX}/include ${KDE4_INCLUDE_DIR} 75 | PATH_SUFFIXES eigen3 eigen) 76 | 77 | if(EIGEN3_INCLUDE_DIR) 78 | _eigen3_check_version() 79 | endif(EIGEN3_INCLUDE_DIR) 80 | 81 | include(FindPackageHandleStandardArgs) 82 | find_package_handle_standard_args(Eigen3 DEFAULT_MSG EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK) 83 | 84 | mark_as_advanced(EIGEN3_INCLUDE_DIR) 85 | 86 | endif(EIGEN3_INCLUDE_DIR) 87 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tools/codespell_ignore_lines_from_errors.py: -------------------------------------------------------------------------------- 1 | """Simple script for rebuilding .codespell-ignore-lines 2 | 3 | Usage: 4 | 5 | cat < /dev/null > .codespell-ignore-lines 6 | pre-commit run --all-files codespell >& /tmp/codespell_errors.txt 7 | python3 tools/codespell_ignore_lines_from_errors.py /tmp/codespell_errors.txt > .codespell-ignore-lines 8 | 9 | git diff to review changes, then commit, push. 10 | """ 11 | 12 | import sys 13 | from typing import List 14 | 15 | 16 | def run(args: List[str]) -> None: 17 | assert len(args) == 1, "codespell_errors.txt" 18 | cache = {} 19 | done = set() 20 | with open(args[0]) as f: 21 | lines = f.read().splitlines() 22 | 23 | for line in sorted(lines): 24 | i = line.find(" ==> ") 25 | if i > 0: 26 | flds = line[:i].split(":") 27 | if len(flds) >= 2: 28 | filename, line_num = flds[:2] 29 | if filename not in cache: 30 | with open(filename) as f: 31 | cache[filename] = f.read().splitlines() 32 | supp = cache[filename][int(line_num) - 1] 33 | if supp not in done: 34 | print(supp) 35 | done.add(supp) 36 | 37 | 38 | if __name__ == "__main__": 39 | run(args=sys.argv[1:]) 40 | -------------------------------------------------------------------------------- /external/pybind11/tools/libsize.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | # Internal build script for generating debugging test .so size. 5 | # Usage: 6 | # python libsize.py file.so save.txt -- displays the size of file.so and, if save.txt exists, compares it to the 7 | # size in it, then overwrites save.txt with the new size for future runs. 8 | 9 | if len(sys.argv) != 3: 10 | sys.exit("Invalid arguments: usage: python libsize.py file.so save.txt") 11 | 12 | lib = sys.argv[1] 13 | save = sys.argv[2] 14 | 15 | if not os.path.exists(lib): 16 | sys.exit(f"Error: requested file ({lib}) does not exist") 17 | 18 | libsize = os.path.getsize(lib) 19 | 20 | print("------", os.path.basename(lib), "file size:", libsize, end="") 21 | 22 | if os.path.exists(save): 23 | with open(save) as sf: 24 | oldsize = int(sf.readline()) 25 | 26 | if oldsize > 0: 27 | change = libsize - oldsize 28 | if change == 0: 29 | print(" (no change)") 30 | else: 31 | print(f" (change of {change:+} bytes = {change / oldsize:+.2%})") 32 | else: 33 | print() 34 | 35 | with open(save, "w") as sf: 36 | sf.write(str(libsize)) 37 | -------------------------------------------------------------------------------- /external/pybind11/tools/make_changelog.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | 5 | import ghapi.all 6 | from rich import print 7 | from rich.syntax import Syntax 8 | 9 | ENTRY = re.compile( 10 | r""" 11 | Suggested \s changelog \s entry: 12 | .* 13 | ```rst 14 | \s* 15 | (.*?) 16 | \s* 17 | ``` 18 | """, 19 | re.DOTALL | re.VERBOSE, 20 | ) 21 | 22 | print() 23 | 24 | 25 | api = ghapi.all.GhApi(owner="pybind", repo="pybind11") 26 | 27 | issues_pages = ghapi.page.paged( 28 | api.issues.list_for_repo, labels="needs changelog", state="closed" 29 | ) 30 | issues = (issue for page in issues_pages for issue in page) 31 | missing = [] 32 | 33 | for issue in issues: 34 | changelog = ENTRY.findall(issue.body or "") 35 | if not changelog or not changelog[0]: 36 | missing.append(issue) 37 | else: 38 | (msg,) = changelog 39 | if not msg.startswith("* "): 40 | msg = "* " + msg 41 | if not msg.endswith("."): 42 | msg += "." 43 | 44 | msg += f"\n `#{issue.number} <{issue.html_url}>`_" 45 | 46 | print(Syntax(msg, "rst", theme="ansi_light", word_wrap=True)) 47 | print() 48 | 49 | if missing: 50 | print() 51 | print("[blue]" + "-" * 30) 52 | print() 53 | 54 | for issue in missing: 55 | print(f"[red bold]Missing:[/red bold][red] {issue.title}") 56 | print(f"[red] {issue.html_url}\n") 57 | 58 | print("[bold]Template:\n") 59 | msg = "## Suggested changelog entry:\n\n```rst\n\n```" 60 | print(Syntax(msg, "md", theme="ansi_light")) 61 | 62 | print() 63 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/pybind11/tools/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=42", "wheel"] 3 | build-backend = "setuptools.build_meta" 4 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/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 | -------------------------------------------------------------------------------- /external/stb_image/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ======================================================================== # 2 | # Copyright 2021-2021 Ingo Wald # 3 | # # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); # 5 | # you may not use this file except in compliance with the License. # 6 | # You may obtain a copy of the License at # 7 | # # 8 | # http://www.apache.org/licenses/LICENSE-2.0 # 9 | # # 10 | # Unless required by applicable law or agreed to in writing, software # 11 | # distributed under the License is distributed on an "AS IS" BASIS, # 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 13 | # See the License for the specific language governing permissions and # 14 | # limitations under the License. # 15 | # ======================================================================== # 16 | 17 | add_library(stb_image INTERFACE) 18 | target_include_directories(stb_image INTERFACE ${CMAKE_CURRENT_LIST_DIR}) 19 | -------------------------------------------------------------------------------- /pynari/Array.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | struct Array : public Object { 24 | typedef std::shared_ptr SP; 25 | 26 | Array(Device::SP device, anari::DataType type, 27 | const py::buffer &buffer); 28 | Array(Device::SP device, anari::DataType type, 29 | const std::vector &list); 30 | virtual ~Array() = default; 31 | std::string toString() const override { return "pynari::Array"; } 32 | 33 | ANARIDataType anariType() const override 34 | { 35 | switch (nDims) { 36 | case 1: return ANARI_ARRAY1D; 37 | case 2: return ANARI_ARRAY2D; 38 | case 3: return ANARI_ARRAY3D; 39 | default: throw std::runtime_error("array type not implemented"); 40 | } 41 | }; 42 | 43 | /*! number of DIMENSIONS of this array, NOT the 'size' */ 44 | int nDims = -1; 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /pynari/Camera.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | struct Camera : public Object { 24 | typedef std::shared_ptr SP; 25 | 26 | Camera(Device::SP device, 27 | const std::string &type); 28 | virtual ~Camera() = default; 29 | 30 | std::string toString() const override { return "pynari::Camera<"+type+">"; } 31 | ANARIDataType anariType() const override { return ANARI_CAMERA; } 32 | 33 | const std::string type; 34 | }; 35 | 36 | inline Camera::Camera(Device::SP device, 37 | const std::string &type) 38 | : Object(device), 39 | type(type) 40 | { 41 | handle = anari::newObject(device->handle,type.c_str()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /pynari/Context.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024 Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/common.h" 20 | #include "pynari/Object.h" 21 | 22 | namespace pynari { 23 | 24 | struct Camera; 25 | struct Renderer; 26 | struct Surface; 27 | struct World; 28 | struct Frame; 29 | struct Geometry; 30 | struct Array; 31 | struct Material; 32 | struct Light; 33 | struct SpatialField; 34 | struct Volume; 35 | struct Sampler; 36 | 37 | struct Context { 38 | typedef std::shared_ptr SP; 39 | 40 | Context(const std::string &libName, const std::string &subName); 41 | 42 | virtual ~Context(); 43 | 44 | static SP create(const std::string &libName, const std::string &devName); 45 | 46 | std::shared_ptr newWorld(); 47 | std::shared_ptr newFrame(); 48 | std::shared_ptr newGeometry(const std::string &type); 49 | std::shared_ptr newCamera(const std::string &type); 50 | std::shared_ptr newRenderer(const std::string &type); 51 | std::shared_ptr newSurface(); 52 | std::shared_ptr newSpatialField(const std::string &type); 53 | std::shared_ptr newVolume(const std::string &type); 54 | std::shared_ptr newSampler(const std::string &type); 55 | std::shared_ptr newArray(int type, const py::buffer &buffer); 56 | std::shared_ptr newArray_objects(int type, 57 | const py::list &list); 58 | std::shared_ptr newMaterial(const std::string &type); 59 | std::shared_ptr newLight(const std::string &type); 60 | 61 | /*! allows to query whether the user has already explicitly called 62 | contextDestroy. if so, any releases of handles are no longer 63 | valid because whatever they may have pointed to inside the 64 | (owl-)context is already dead */ 65 | bool alive(); 66 | 67 | void destroy(); 68 | 69 | Device::SP device; 70 | std::mutex mutex; 71 | }; 72 | 73 | std::shared_ptr createContext(const std::string &libName, 74 | const std::string &devName="default"); 75 | } 76 | -------------------------------------------------------------------------------- /pynari/Device.cpp: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024-2024 Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #include "pynari/Device.h" 18 | #include "pynari/Object.h" 19 | 20 | namespace pynari { 21 | 22 | void Device::release() 23 | { 24 | if (!handle) 25 | /* was already force-relased before, it's only the python object 26 | that's till live -> don't do anything */ 27 | return; 28 | 29 | // make sure to release all objects _before_ the device itself 30 | // gets released 31 | std::set copyOfCurrentObjects 32 | = listOfAllObjectsCreatedOnThisDevice; 33 | for (Object *obj : copyOfCurrentObjects) 34 | obj->release(); 35 | 36 | // and finally, release the device itself 37 | anari::release(this->handle,this->handle); 38 | handle = nullptr; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /pynari/Device.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024-2024 Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/common.h" 20 | #include 21 | 22 | namespace pynari { 23 | struct Object; 24 | struct Context; 25 | 26 | /*! python-wrapper object for an ANARIDevice - not that in pynari 27 | all functionality of a device lives in the pynari::Context 28 | object; this only handles the lifetime (so all objects created 29 | from this device can hold a std::shared_ptr to it and thus make 30 | sure the device doesn't die before the obejcts */ 31 | struct Device { 32 | typedef std::shared_ptr SP; 33 | Device(anari::Device handle, Context *context) 34 | : handle(handle), context(context) 35 | {} 36 | virtual ~Device() {} 37 | 38 | /*! force-releases this device, and all objects created from 39 | it. This will force-release all respective objects on the 40 | anari side even if some of the python wrapper objects are 41 | still around. It is of course no longer valid to use any of 42 | these python wrapper objects any more after their owning 43 | device has been deleted, but at least it gives he python user 44 | an easy way of deleting all anari objects (in that gvien 45 | device) without having to track and destroy all the obejcts he 46 | has created */ 47 | void release(); 48 | 49 | std::set listOfAllObjectsCreatedOnThisDevice; 50 | 51 | anari::Device handle = 0; 52 | Context *const context; 53 | }; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /pynari/Frame.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | struct Material; 24 | struct Geometry; 25 | struct Group; 26 | struct Camera; 27 | struct FrameBuffer; 28 | struct Data; 29 | 30 | struct Frame : public Object { 31 | typedef std::shared_ptr SP; 32 | 33 | Frame(Device::SP device); 34 | virtual ~Frame() = default; 35 | 36 | std::string toString() const override { return "pynari::Frame"; } 37 | ANARIDataType anariType() const override { return ANARI_FRAME; } 38 | 39 | /*! trigger rendering a frame; unlike native anari that not only 40 | starts the frame, it also waits for it to finish */ 41 | void render(); 42 | uint64_t map(const std::string &channel); 43 | void unmap(const std::string &channel); 44 | 45 | void readGPU(uint64_t devicePtr, const std::string &channel); 46 | 47 | /*! read a given frame buffer channel, and return it in a 48 | np::array of proper dimensions */ 49 | py::object get(const std::string &channelName); 50 | 51 | }; 52 | 53 | } 54 | -------------------------------------------------------------------------------- /pynari/Geometry.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/common.h" 20 | #include "pynari/Material.h" 21 | 22 | namespace pynari { 23 | 24 | struct Geometry : public Object { 25 | typedef std::shared_ptr SP; 26 | 27 | Geometry(Device::SP device, 28 | const std::string &type); 29 | virtual ~Geometry() = default; 30 | 31 | std::string toString() const override { return "pynari::Geometry<"+type+">"; } 32 | ANARIDataType anariType() const override { return ANARI_GEOMETRY; } 33 | 34 | const std::string type; 35 | }; 36 | 37 | inline Geometry::Geometry(Device::SP device, 38 | const std::string &type) 39 | : Object(device), 40 | type(type) 41 | { 42 | handle = anari::newObject(device->handle,type.c_str()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /pynari/Group.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/common.h" 20 | #include "pynari/Geometry.h" 21 | 22 | namespace pynari { 23 | 24 | struct Geometry; 25 | 26 | struct Group : public Object { 27 | typedef std::shared_ptr SP; 28 | 29 | Group(Device::SP device, 30 | const py::list &list); 31 | virtual ~Group() = default; 32 | 33 | std::string toString() const override { return "py_barn::Group"; } 34 | ANARIDataType anariType() const override { return ANARI_GROUP; } 35 | }; 36 | 37 | inline Group::Group(Device::SP device, 38 | const py::list &list) 39 | : Object(device) 40 | { 41 | handle = anari::newObject(device->handle); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /pynari/Light.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | struct Light : public Object { 24 | typedef std::shared_ptr SP; 25 | 26 | Light(Device::SP device, 27 | const std::string type); 28 | virtual ~Light() = default; 29 | 30 | std::string toString() const override { return "py_barn::Light"; } 31 | ANARIDataType anariType() const override { return ANARI_LIGHT; } 32 | 33 | const std::string type; 34 | }; 35 | 36 | inline Light::Light(Device::SP device, 37 | const std::string type) 38 | : Object(device), 39 | type(type) 40 | { 41 | handle = anari::newObject(device->handle,type.c_str()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /pynari/Material.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | struct Material : public Object { 24 | typedef std::shared_ptr SP; 25 | 26 | Material(Device::SP device, 27 | const std::string &type); 28 | virtual ~Material() = default; 29 | std::string toString() const override { return "pynari::Material"; } 30 | ANARIDataType anariType() const override { return ANARI_MATERIAL; } 31 | 32 | const std::string type; 33 | }; 34 | 35 | inline Material::Material(Device::SP device, 36 | const std::string &type) 37 | : Object(device), 38 | type(type) 39 | { 40 | handle = anari::newObject(device->handle,type.c_str()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pynari/Object.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024-2024 Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Device.h" 20 | #include 21 | #include 22 | 23 | namespace pynari { 24 | 25 | std::string to_string(anari::DataType type); 26 | 27 | /*! base class for any anari object type such as a light, a 28 | material, renderg,e tcpp */ 29 | struct Object : public std::enable_shared_from_this { 30 | typedef std::shared_ptr SP; 31 | 32 | Object(Device::SP device); 33 | 34 | virtual ~Object(); 35 | virtual std::string toString() const = 0; 36 | 37 | virtual ANARIDataType anariType() const = 0; 38 | 39 | void commit(); 40 | 41 | void set_object(const char *name, int type, 42 | const Object::SP &object); 43 | void set_string(const char *name, int type, 44 | const std::string &stringValue); 45 | void set_string_notype(const char *name, //int type, 46 | const std::string &stringValue); 47 | void setArray_list(const char *name, int type, 48 | const py::list &list); 49 | void setArray_np(const char *name, int type, 50 | const py::buffer &buffer); 51 | void set_box1(const char *name, int type, 52 | const helium::box1 b); 53 | void set_float(const char *name, int type, 54 | float v); 55 | void set_float2(const char *name, int type, 56 | const std::tuple &v); 57 | void set_float3(const char *name, int type, 58 | const std::tuple &v); 59 | void set_float4(const char *name, int type, 60 | const std::tuple &v); 61 | void set_float_vec(const char *name, int type, 62 | const std::vector &v); 63 | void set_uint(const char *name, int type, 64 | uint v); 65 | void set_uint2(const char *name, int type, 66 | const std::tuple &v); 67 | void set_uint3(const char *name, int type, 68 | const std::tuple &v); 69 | void set_uint4(const char *name, int type, 70 | const std::tuple &v); 71 | void set_uint_vec(const char *name, int type, 72 | const std::vector &v); 73 | virtual void release(); 74 | 75 | void assertThisObjectIsValid(); 76 | 77 | Device::SP device; 78 | anari::Object handle = {}; 79 | }; 80 | 81 | } 82 | -------------------------------------------------------------------------------- /pynari/Renderer.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | struct Renderer : public Object { 24 | typedef std::shared_ptr SP; 25 | 26 | Renderer(Device::SP device, 27 | const std::string &type); 28 | virtual ~Renderer() = default; 29 | 30 | std::string toString() const override { return "pynari::Renderer<"+type+">"; } 31 | ANARIDataType anariType() const override { return ANARI_RENDERER; } 32 | 33 | const std::string type; 34 | }; 35 | 36 | inline Renderer::Renderer(Device::SP device, 37 | const std::string &type) 38 | : Object(device), 39 | type(type) 40 | { 41 | handle = anari::newObject(device->handle,type.c_str()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /pynari/Sampler.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | /*! abstraction for a pynari 'Sampler' type. Valid subtypes are 24 | 'image1D', 'image2D', 'image3D' */ 25 | struct Sampler : public Object { 26 | typedef std::shared_ptr SP; 27 | 28 | /*! constructor, for given subtype on given device */ 29 | Sampler(Device::SP device, 30 | const std::string &type); 31 | virtual ~Sampler() = default; 32 | 33 | std::string toString() const override { return "pynari::Sampler"; } 34 | ANARIDataType anariType() const override { return ANARI_SAMPLER; } 35 | 36 | const std::string type; 37 | }; 38 | 39 | /*! constructor, for given subtype on given device */ 40 | inline Sampler::Sampler(Device::SP device, 41 | const std::string &type) 42 | : Object(device), 43 | type(type) 44 | { 45 | handle = anari::newObject(device->handle,type.c_str()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /pynari/SpatialField.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | struct SpatialField : public Object { 24 | typedef std::shared_ptr SP; 25 | 26 | SpatialField(Device::SP device, 27 | const std::string &type); 28 | virtual ~SpatialField() = default; 29 | std::string toString() const override 30 | { return "pynari::SpatialField<"+type+">"; } 31 | 32 | ANARIDataType anariType() const override { return ANARI_SPATIAL_FIELD; } 33 | 34 | const std::string type; 35 | }; 36 | 37 | inline SpatialField::SpatialField(Device::SP device, 38 | const std::string &type) 39 | : Object(device), 40 | type(type) 41 | { 42 | handle = anari::newObject(device->handle,type.c_str()); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /pynari/Surface.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | struct Surface : public Object { 24 | typedef std::shared_ptr SP; 25 | 26 | Surface(Device::SP device); 27 | virtual ~Surface() = default; 28 | 29 | std::string toString() const override { return "pynari::Surface"; } 30 | ANARIDataType anariType() const override { return ANARI_SURFACE; } 31 | }; 32 | 33 | inline Surface::Surface(Device::SP device) 34 | : Object(device) 35 | { 36 | handle = anari::newObject(device->handle); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /pynari/Volume.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | struct Volume : public Object { 24 | typedef std::shared_ptr SP; 25 | 26 | Volume(Device::SP device, 27 | const std::string &type); 28 | virtual ~Volume() = default; 29 | std::string toString() const override 30 | { return "pynari::Volume<"+type+">"; } 31 | 32 | ANARIDataType anariType() const override { return ANARI_VOLUME; } 33 | 34 | const std::string type; 35 | }; 36 | 37 | inline Volume::Volume(Device::SP device, 38 | const std::string &type) 39 | : Object(device), 40 | type(type) 41 | { 42 | handle = anari::newObject(device->handle,type.c_str()); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /pynari/World.h: -------------------------------------------------------------------------------- 1 | // ======================================================================== // 2 | // Copyright 2024++ Ingo Wald // 3 | // // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | // you may not use this file except in compliance with the License. // 6 | // You may obtain a copy of the License at // 7 | // // 8 | // http://www.apache.org/licenses/LICENSE-2.0 // 9 | // // 10 | // Unless required by applicable law or agreed to in writing, software // 11 | // distributed under the License is distributed on an "AS IS" BASIS, // 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | // See the License for the specific language governing permissions and // 14 | // limitations under the License. // 15 | // ======================================================================== // 16 | 17 | #pragma once 18 | 19 | #include "pynari/Object.h" 20 | 21 | namespace pynari { 22 | 23 | struct Material; 24 | struct Geometry; 25 | struct Group; 26 | struct Camera; 27 | struct FrameBuffer; 28 | struct Data; 29 | 30 | struct World : public Object { 31 | typedef std::shared_ptr SP; 32 | 33 | World(Device::SP device); 34 | virtual ~World() = default; 35 | 36 | std::string toString() const override { return "pynari::World"; } 37 | ANARIDataType anariType() const override { return ANARI_WORLD; } 38 | }; 39 | 40 | 41 | inline World::World(Device::SP device) 42 | : Object(device) 43 | { 44 | handle = anari::newObject(device->handle); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pynari/becomes.__init__.py: -------------------------------------------------------------------------------- 1 | from .pynari import newDevice 2 | 3 | from .pynari import has_cuda_capable_gpu 4 | 5 | from .pynari import DATA_TYPE 6 | from .pynari import STRING 7 | from .pynari import OBJECT 8 | from .pynari import SURFACE 9 | from .pynari import GEOMETRY 10 | from .pynari import MATERIAL 11 | from .pynari import LIGHT 12 | from .pynari import RENDERER 13 | from .pynari import SPATIAL_FIELD 14 | from .pynari import CAMERA 15 | from .pynari import WORLD 16 | from .pynari import SPATIAL_FIELD 17 | from .pynari import VOLUME 18 | 19 | from .pynari import ARRAY 20 | from .pynari import ARRAY1D 21 | from .pynari import ARRAY2D 22 | from .pynari import ARRAY3D 23 | 24 | from .pynari import FLOAT32 25 | from .pynari import FLOAT32_VEC2 26 | from .pynari import FLOAT32_VEC3 27 | from .pynari import FLOAT32_VEC4 28 | 29 | from .pynari import UINT32 30 | from .pynari import UINT32_VEC2 31 | from .pynari import UINT32_VEC3 32 | from .pynari import UINT32_VEC4 33 | 34 | from .pynari import INT32 35 | from .pynari import INT32_VEC2 36 | from .pynari import INT32_VEC3 37 | from .pynari import INT32_VEC4 38 | 39 | from .pynari import UFIXED8_VEC4 40 | from .pynari import UFIXED8_RGBA_SRGB 41 | 42 | from .pynari import FLOAT 43 | from .pynari import float 44 | from .pynari import float2 45 | from .pynari import float3 46 | from .pynari import float4 47 | 48 | from .pynari import UINT 49 | from .pynari import uint 50 | from .pynari import uint2 51 | from .pynari import uint3 52 | from .pynari import uint4 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /pynari/dummy.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | __global__ void dummyKernel_pynari() 6 | { 7 | printf("dummuy\n"); 8 | } 9 | 10 | extern "C" void dummy_pynari() 11 | { 12 | dummyKernel_pynari<<<32, 32>>>(); 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /samples/dlaf-1m.cmap.binary.float3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/dlaf-1m.cmap.binary.float3 -------------------------------------------------------------------------------- /samples/dlaf-1m.points.binary.float3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/dlaf-1m.points.binary.float3 -------------------------------------------------------------------------------- /samples/dlaf-1m.scalars.binary.float: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/dlaf-1m.scalars.binary.float -------------------------------------------------------------------------------- /samples/geometry-spheres-with-sampler1D.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/geometry-spheres-with-sampler1D.jpg -------------------------------------------------------------------------------- /samples/sample01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/sample01.jpg -------------------------------------------------------------------------------- /samples/sample02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/sample02.jpg -------------------------------------------------------------------------------- /samples/sample03-magnetic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/sample03-magnetic.jpg -------------------------------------------------------------------------------- /samples/sample03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/sample03.jpg -------------------------------------------------------------------------------- /samples/sample04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/sample04.jpg -------------------------------------------------------------------------------- /samples/sample05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/sample05.jpg -------------------------------------------------------------------------------- /samples/sample06.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/sample06.jpg -------------------------------------------------------------------------------- /samples/sample07.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/sample07.jpg -------------------------------------------------------------------------------- /samples/testorb-base.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/testorb-base.npz -------------------------------------------------------------------------------- /samples/testorb-equation.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/testorb-equation.npz -------------------------------------------------------------------------------- /samples/testorb-floor.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/testorb-floor.npz -------------------------------------------------------------------------------- /samples/testorb-inner-sphere.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/testorb-inner-sphere.npz -------------------------------------------------------------------------------- /samples/testorb-outer-sphere.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ingowald/pynari/512398729b837b215641a486662f139888e7f174/samples/testorb-outer-sphere.npz -------------------------------------------------------------------------------- /viewer/examples/sample01.py: -------------------------------------------------------------------------------- 1 | # // ======================================================================== // 2 | # // Copyright 2024++ Ingo Wald // 3 | # // // 4 | # // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | # // you may not use this file except in compliance with the License. // 6 | # // You may obtain a copy of the License at // 7 | # // // 8 | # // http://www.apache.org/licenses/LICENSE-2.0 // 9 | # // // 10 | # // Unless required by applicable law or agreed to in writing, software // 11 | # // distributed under the License is distributed on an "AS IS" BASIS, // 12 | # // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | # // See the License for the specific language governing permissions and // 14 | # // limitations under the License. // 15 | # // ======================================================================== // 16 | 17 | import numpy as np 18 | 19 | import pynari as anari 20 | 21 | from .anari_scene_base import AnariSceneBase 22 | 23 | class AnariScene(AnariSceneBase): 24 | def __init__(self): 25 | super().__init__() 26 | 27 | def create_world(self, device): 28 | """Create and populate the scene with objects.""" 29 | 30 | vertex = np.array([ 31 | -1.0, -1.0, 3.0, 32 | -1.0, 1.0, 3.0, 33 | 1.0, -1.0, 3.0, 34 | 0.1, 0.1, 0.3 35 | ], dtype = np.float32) 36 | 37 | color = np.array([ 38 | 0.9, 0.5, 0.5, 1.0, 39 | 0.8, 0.8, 0.8, 1.0, 40 | 0.8, 0.8, 0.8, 1.0, 41 | 0.5, 0.9, 0.5, 1.0 42 | ], dtype = np.float32) 43 | 44 | index = np.array([ 45 | 0, 1, 2, 46 | 1, 2, 3 47 | ], dtype = np.uint32) 48 | 49 | print('@pynari: -------------------------------------------------------') 50 | print('@pynari: running sample01 - the original ANARI "first light" ') 51 | print('@pynari: sample that just renders a simple pair of triangles') 52 | print('@pynari: -------------------------------------------------------') 53 | 54 | world = device.newWorld() 55 | 56 | mesh = device.newGeometry('triangle') 57 | 58 | array = device.newArray(anari.FLOAT32_VEC3,vertex) 59 | mesh.setParameter('vertex.position', anari.ARRAY, array) 60 | 61 | array = device.newArray(anari.FLOAT32_VEC4, color) 62 | mesh.setParameter('vertex.color', anari.ARRAY, array) 63 | 64 | array = device.newArray(anari.UINT32_VEC3 , index) 65 | mesh.setParameter('primitive.index', anari.ARRAY, array) 66 | mesh.commitParameters() 67 | 68 | material = device.newMaterial('matte') 69 | material.commitParameters() 70 | 71 | surface = device.newSurface() 72 | surface.setParameter('geometry', anari.GEOMETRY, mesh) 73 | surface.setParameter('material', anari.MATERIAL, material) 74 | surface.commitParameters() 75 | 76 | world.setParameterArray('surface', anari.SURFACE, [ surface ]) 77 | 78 | light = device.newLight('directional') 79 | light.setParameter('direction', anari.float3, (0,0,1)) 80 | light.setParameter('irradiance', anari.float, 1) 81 | light.commitParameters() 82 | 83 | array = device.newArray(anari.LIGHT, [light]) 84 | world.setParameter('light', anari.ARRAY1D, array) 85 | 86 | world.commitParameters() 87 | 88 | return world 89 | 90 | 91 | -------------------------------------------------------------------------------- /viewer/examples/sample05.py: -------------------------------------------------------------------------------- 1 | # // ======================================================================== // 2 | # // Copyright 2024++ Ingo Wald // 3 | # // // 4 | # // Licensed under the Apache License, Version 2.0 (the "License"); // 5 | # // you may not use this file except in compliance with the License. // 6 | # // You may obtain a copy of the License at // 7 | # // // 8 | # // http://www.apache.org/licenses/LICENSE-2.0 // 9 | # // // 10 | # // Unless required by applicable law or agreed to in writing, software // 11 | # // distributed under the License is distributed on an "AS IS" BASIS, // 12 | # // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // 13 | # // See the License for the specific language governing permissions and // 14 | # // limitations under the License. // 15 | # // ======================================================================== // 16 | 17 | 18 | import numpy as np 19 | import pynari as anari 20 | import random 21 | 22 | from .anari_scene_base import AnariSceneBase 23 | 24 | class AnariScene(AnariSceneBase): 25 | def __init__(self): 26 | super().__init__() 27 | 28 | def create_world(self, device): 29 | """Create and populate the scene with objects.""" 30 | 31 | random.seed(80577) 32 | 33 | def add_sphere(pos, radius, material): 34 | geom = device.newGeometry('sphere') 35 | array = device.newArray(anari.FLOAT32_VEC3,np.array(pos,dtype=np.float32)) 36 | geom.setParameter('vertex.position',anari.ARRAY,array) 37 | geom.setParameter('radius',anari.FLOAT32,radius) 38 | geom.commitParameters() 39 | 40 | surf = device.newSurface() 41 | surf.setParameter('geometry', anari.GEOMETRY, geom) 42 | surf.setParameter('material', anari.MATERIAL, material) 43 | surf.commitParameters() 44 | 45 | spheres.append(surf) 46 | 47 | def make_pbr(roughness, metallic): 48 | mat = device.newMaterial('physicallyBased') 49 | mat.setParameter('baseColor',anari.float3,(.2,.8,.2)) 50 | mat.setParameter('ior',anari.FLOAT32,1.45) 51 | mat.setParameter('metallic',anari.FLOAT32,metallic) 52 | mat.setParameter('specular',anari.FLOAT32,0.) 53 | mat.setParameter('roughness',anari.float,roughness) 54 | mat.commitParameters() 55 | return mat 56 | 57 | def create_spheres(): 58 | grid_size = 9 59 | radius = .9 / grid_size 60 | for a in range(grid_size): 61 | for b in range(grid_size): 62 | choose_mat = random.random(); 63 | center = ((a + .5 - grid_size/2) / (grid_size/2), 64 | (b + .5 - grid_size/2) / (grid_size/2), 65 | 0.) 66 | metallic = (a+.5)/grid_size 67 | roughness = (b+.5)/grid_size 68 | add_sphere(center,radius,make_pbr(roughness*roughness,metallic)) 69 | 70 | 71 | spheres = [] 72 | 73 | create_spheres() 74 | 75 | world = device.newWorld() 76 | light = device.newLight('directional') 77 | light.setParameter('direction', anari.float3, (-.6,-1,+.5)) 78 | light.setParameter('color', anari.float3, (1,1,1)) 79 | light.setParameter('irradiance', anari.float, 1) 80 | light.commitParameters() 81 | 82 | array = device.newArray(anari.LIGHT, [light]) 83 | world.setParameter('light', anari.ARRAY1D, array) 84 | 85 | 86 | world.setParameterArray('surface', anari.SURFACE, spheres ) 87 | world.commitParameters() 88 | 89 | return world --------------------------------------------------------------------------------