netgen-mesher 6.2.2504.post11.dev0__cp313-cp313-win_amd64.whl → 6.2.2506.post48.dev0__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netgen/__init__.pyi +3 -3
- netgen/cmake/NetgenConfig.cmake +10 -9
- netgen/config/__init__.pyi +8 -8
- netgen/config/config.py +7 -7
- netgen/config/config.pyi +8 -8
- netgen/include/core/archive.hpp +18 -3
- netgen/include/core/array.hpp +20 -4
- netgen/include/core/autodiff.hpp +9 -11
- netgen/include/core/autodiffdiff.hpp +0 -2
- netgen/include/core/bitarray.hpp +1 -1
- netgen/include/core/flags.hpp +1 -1
- netgen/include/core/hashtable.hpp +1 -1
- netgen/include/core/memtracer.hpp +7 -7
- netgen/include/core/ngcore.hpp +5 -0
- netgen/include/core/ngcore_api.hpp +11 -0
- netgen/include/core/paje_trace.hpp +9 -8
- netgen/include/core/profiler.hpp +5 -5
- netgen/include/core/register_archive.hpp +8 -0
- netgen/include/core/simd.hpp +69 -1
- netgen/include/core/simd_arm64.hpp +205 -1
- netgen/include/core/simd_avx.hpp +72 -4
- netgen/include/core/simd_avx512.hpp +9 -0
- netgen/include/core/simd_generic.hpp +274 -8
- netgen/include/core/simd_math.hpp +178 -0
- netgen/include/core/simd_sse.hpp +11 -1
- netgen/include/core/statushandler.hpp +37 -0
- netgen/include/core/table.hpp +3 -2
- netgen/include/core/taskmanager.hpp +34 -1
- netgen/include/core/utils.hpp +3 -8
- netgen/include/include/netgen_version.hpp +4 -4
- netgen/include/meshing/basegeom.hpp +1 -4
- netgen/include/meshing/global.hpp +0 -17
- netgen/include/meshing/hpref_tet.hpp +41 -0
- netgen/include/meshing/hprefinement.hpp +2 -0
- netgen/include/meshing/meshtype.hpp +2 -1
- netgen/include/meshing/msghandler.hpp +9 -6
- netgen/include/meshing/topology.hpp +2 -2
- netgen/include/nginterface.h +3 -2
- netgen/include/occ/occ_utils.hpp +26 -0
- netgen/include/occ/occgeom.hpp +8 -0
- netgen/include/pybind11/attr.h +40 -8
- netgen/include/pybind11/buffer_info.h +14 -14
- netgen/include/pybind11/cast.h +553 -29
- netgen/include/pybind11/chrono.h +4 -1
- netgen/include/pybind11/conduit/README.txt +15 -0
- netgen/include/pybind11/conduit/pybind11_conduit_v1.h +116 -0
- netgen/include/pybind11/conduit/pybind11_platform_abi_id.h +87 -0
- netgen/include/pybind11/conduit/wrap_include_python_h.h +72 -0
- netgen/include/pybind11/critical_section.h +56 -0
- netgen/include/pybind11/detail/class.h +172 -97
- netgen/include/pybind11/detail/common.h +270 -189
- netgen/include/pybind11/detail/cpp_conduit.h +75 -0
- netgen/include/pybind11/detail/descr.h +55 -0
- netgen/include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h +39 -0
- netgen/include/pybind11/detail/exception_translation.h +71 -0
- netgen/include/pybind11/detail/function_record_pyobject.h +191 -0
- netgen/include/pybind11/detail/init.h +113 -9
- netgen/include/pybind11/detail/internals.h +479 -344
- netgen/include/pybind11/detail/native_enum_data.h +209 -0
- netgen/include/pybind11/detail/pybind11_namespace_macros.h +82 -0
- netgen/include/pybind11/detail/struct_smart_holder.h +378 -0
- netgen/include/pybind11/detail/type_caster_base.h +506 -133
- netgen/include/pybind11/detail/using_smart_holder.h +22 -0
- netgen/include/pybind11/detail/value_and_holder.h +90 -0
- netgen/include/pybind11/eigen/matrix.h +19 -10
- netgen/include/pybind11/eigen/tensor.h +15 -11
- netgen/include/pybind11/embed.h +50 -46
- netgen/include/pybind11/eval.h +11 -6
- netgen/include/pybind11/functional.h +58 -49
- netgen/include/pybind11/gil.h +34 -82
- netgen/include/pybind11/gil_safe_call_once.h +12 -1
- netgen/include/pybind11/gil_simple.h +37 -0
- netgen/include/pybind11/native_enum.h +67 -0
- netgen/include/pybind11/numpy.h +272 -93
- netgen/include/pybind11/pybind11.h +947 -265
- netgen/include/pybind11/pytypes.h +127 -21
- netgen/include/pybind11/stl/filesystem.h +23 -25
- netgen/include/pybind11/stl.h +277 -59
- netgen/include/pybind11/stl_bind.h +42 -7
- netgen/include/pybind11/subinterpreter.h +299 -0
- netgen/include/pybind11/trampoline_self_life_support.h +65 -0
- netgen/include/pybind11/typing.h +177 -4
- netgen/include/pybind11/warnings.h +75 -0
- netgen/include/visualization/mvdraw.hpp +48 -12
- netgen/include/visualization/vssolution.hpp +3 -1
- netgen/lib/libnggui.lib +0 -0
- netgen/lib/ngcore.lib +0 -0
- netgen/lib/nglib.lib +0 -0
- netgen/libnggui.dll +0 -0
- netgen/libngguipy.pyd +0 -0
- netgen/libngpy/_NgOCC.pyi +224 -139
- netgen/libngpy/_csg.pyi +26 -26
- netgen/libngpy/_geom2d.pyi +34 -25
- netgen/libngpy/_meshing.pyi +262 -111
- netgen/libngpy/_stl.pyi +3 -4
- netgen/libngpy.pyd +0 -0
- netgen/ngcore.dll +0 -0
- netgen/nglib.dll +0 -0
- netgen/read_gmsh.py +41 -0
- netgen/togl.dll +0 -0
- netgen/version.py +1 -1
- netgen/webgui.py +38 -2
- {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/METADATA +2 -1
- {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/RECORD +153 -132
- pyngcore/pyngcore.cp313-win_amd64.pyd +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/boundarycondition.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/boxcyl.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/circle_on_cube.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cone.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cube.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubeandring.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubeandspheres.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubemcyl.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cubemsphere.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cylinder.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/cylsphere.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/doc/ng4.pdf +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ellipsoid.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ellipticcyl.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/extrusion.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/fichera.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/frame.step +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/hinge.stl +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/lshape3d.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/manyholes.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/manyholes2.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/matrix.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/ortho.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/part1.stl +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/period.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/exportNeutral.py +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/mesh.py +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/py_tutorials/shaft.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/revolution.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/screw.step +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sculpture.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/shaft.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/shell.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sphere.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/sphereincube.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/square.in2d +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/squarecircle.in2d +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/squarehole.in2d +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/torus.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/trafo.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twobricks.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twocubes.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.data → netgen_mesher-6.2.2506.post48.dev0.data}/data/share/netgen/twocyl.geo +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/AUTHORS +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/LICENSE +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/WHEEL +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/entry_points.txt +0 -0
- {netgen_mesher-6.2.2504.post11.dev0.dist-info → netgen_mesher-6.2.2506.post48.dev0.dist-info}/top_level.txt +0 -0
netgen/include/pybind11/stl.h
CHANGED
|
@@ -11,10 +11,14 @@
|
|
|
11
11
|
|
|
12
12
|
#include "pybind11.h"
|
|
13
13
|
#include "detail/common.h"
|
|
14
|
+
#include "detail/descr.h"
|
|
15
|
+
#include "detail/type_caster_base.h"
|
|
14
16
|
|
|
15
17
|
#include <deque>
|
|
18
|
+
#include <initializer_list>
|
|
16
19
|
#include <list>
|
|
17
20
|
#include <map>
|
|
21
|
+
#include <memory>
|
|
18
22
|
#include <ostream>
|
|
19
23
|
#include <set>
|
|
20
24
|
#include <unordered_map>
|
|
@@ -35,6 +39,103 @@
|
|
|
35
39
|
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
|
36
40
|
PYBIND11_NAMESPACE_BEGIN(detail)
|
|
37
41
|
|
|
42
|
+
//
|
|
43
|
+
// Begin: Equivalent of
|
|
44
|
+
// https://github.com/google/clif/blob/ae4eee1de07cdf115c0c9bf9fec9ff28efce6f6c/clif/python/runtime.cc#L388-L438
|
|
45
|
+
/*
|
|
46
|
+
The three `object_is_convertible_to_*()` functions below are
|
|
47
|
+
the result of converging the behaviors of pybind11 and PyCLIF
|
|
48
|
+
(http://github.com/google/clif).
|
|
49
|
+
|
|
50
|
+
Originally PyCLIF was extremely far on the permissive side of the spectrum,
|
|
51
|
+
while pybind11 was very far on the strict side. Originally PyCLIF accepted any
|
|
52
|
+
Python iterable as input for a C++ `vector`/`set`/`map` argument, as long as
|
|
53
|
+
the elements were convertible. The obvious (in hindsight) problem was that
|
|
54
|
+
any empty Python iterable could be passed to any of these C++ types, e.g. `{}`
|
|
55
|
+
was accepted for C++ `vector`/`set` arguments, or `[]` for C++ `map` arguments.
|
|
56
|
+
|
|
57
|
+
The functions below strike a practical permissive-vs-strict compromise,
|
|
58
|
+
informed by tens of thousands of use cases in the wild. A main objective is
|
|
59
|
+
to prevent accidents and improve readability:
|
|
60
|
+
|
|
61
|
+
- Python literals must match the C++ types.
|
|
62
|
+
|
|
63
|
+
- For C++ `set`: The potentially reducing conversion from a Python sequence
|
|
64
|
+
(e.g. Python `list` or `tuple`) to a C++ `set` must be explicit, by going
|
|
65
|
+
through a Python `set`.
|
|
66
|
+
|
|
67
|
+
- However, a Python `set` can still be passed to a C++ `vector`. The rationale
|
|
68
|
+
is that this conversion is not reducing. Implicit conversions of this kind
|
|
69
|
+
are also fairly commonly used, therefore enforcing explicit conversions
|
|
70
|
+
would have an unfavorable cost : benefit ratio; more sloppily speaking,
|
|
71
|
+
such an enforcement would be more annoying than helpful.
|
|
72
|
+
|
|
73
|
+
Additional checks have been added to allow types derived from `collections.abc.Set` and
|
|
74
|
+
`collections.abc.Mapping` (`collections.abc.Sequence` is already allowed by `PySequence_Check`).
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
inline bool object_is_instance_with_one_of_tp_names(PyObject *obj,
|
|
78
|
+
std::initializer_list<const char *> tp_names) {
|
|
79
|
+
if (PyType_Check(obj)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const char *obj_tp_name = Py_TYPE(obj)->tp_name;
|
|
83
|
+
for (const auto *tp_name : tp_names) {
|
|
84
|
+
if (std::strcmp(obj_tp_name, tp_name) == 0) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
inline bool object_is_convertible_to_std_vector(const handle &src) {
|
|
92
|
+
// Allow sequence-like objects, but not (byte-)string-like objects.
|
|
93
|
+
if (PySequence_Check(src.ptr()) != 0) {
|
|
94
|
+
return !PyUnicode_Check(src.ptr()) && !PyBytes_Check(src.ptr());
|
|
95
|
+
}
|
|
96
|
+
// Allow generators, set/frozenset and several common iterable types.
|
|
97
|
+
return (PyGen_Check(src.ptr()) != 0) || (PyAnySet_Check(src.ptr()) != 0)
|
|
98
|
+
|| object_is_instance_with_one_of_tp_names(
|
|
99
|
+
src.ptr(), {"dict_keys", "dict_values", "dict_items", "map", "zip"});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
inline bool object_is_convertible_to_std_set(const handle &src, bool convert) {
|
|
103
|
+
// Allow set/frozenset and dict keys.
|
|
104
|
+
// In convert mode: also allow types derived from collections.abc.Set.
|
|
105
|
+
return ((PyAnySet_Check(src.ptr()) != 0)
|
|
106
|
+
|| object_is_instance_with_one_of_tp_names(src.ptr(), {"dict_keys"}))
|
|
107
|
+
|| (convert && isinstance(src, module_::import("collections.abc").attr("Set")));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
inline bool object_is_convertible_to_std_map(const handle &src, bool convert) {
|
|
111
|
+
// Allow dict.
|
|
112
|
+
if (PyDict_Check(src.ptr())) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
// Allow types conforming to Mapping Protocol.
|
|
116
|
+
// According to https://docs.python.org/3/c-api/mapping.html, `PyMappingCheck()` checks for
|
|
117
|
+
// `__getitem__()` without checking the type of keys. In order to restrict the allowed types
|
|
118
|
+
// closer to actual Mapping-like types, we also check for the `items()` method.
|
|
119
|
+
if (PyMapping_Check(src.ptr()) != 0) {
|
|
120
|
+
PyObject *items = PyObject_GetAttrString(src.ptr(), "items");
|
|
121
|
+
if (items != nullptr) {
|
|
122
|
+
bool is_convertible = (PyCallable_Check(items) != 0);
|
|
123
|
+
Py_DECREF(items);
|
|
124
|
+
if (is_convertible) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
PyErr_Clear();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// In convert mode: Allow types derived from collections.abc.Mapping
|
|
132
|
+
return convert && isinstance(src, module_::import("collections.abc").attr("Mapping"));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//
|
|
136
|
+
// End: Equivalent of clif/python/runtime.cc
|
|
137
|
+
//
|
|
138
|
+
|
|
38
139
|
/// Extracts an const lvalue reference or rvalue reference for U based on the type of T (e.g. for
|
|
39
140
|
/// forwarding a container element). Typically used indirect via forwarded_type(), below.
|
|
40
141
|
template <typename T, typename U>
|
|
@@ -66,17 +167,10 @@ private:
|
|
|
66
167
|
}
|
|
67
168
|
void reserve_maybe(const anyset &, void *) {}
|
|
68
169
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!isinstance<anyset>(src)) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
auto s = reinterpret_borrow<anyset>(src);
|
|
75
|
-
value.clear();
|
|
76
|
-
reserve_maybe(s, &value);
|
|
77
|
-
for (auto entry : s) {
|
|
170
|
+
bool convert_iterable(const iterable &itbl, bool convert) {
|
|
171
|
+
for (const auto &it : itbl) {
|
|
78
172
|
key_conv conv;
|
|
79
|
-
if (!conv.load(
|
|
173
|
+
if (!conv.load(it, convert)) {
|
|
80
174
|
return false;
|
|
81
175
|
}
|
|
82
176
|
value.insert(cast_op<Key &&>(std::move(conv)));
|
|
@@ -84,6 +178,29 @@ public:
|
|
|
84
178
|
return true;
|
|
85
179
|
}
|
|
86
180
|
|
|
181
|
+
bool convert_anyset(const anyset &s, bool convert) {
|
|
182
|
+
value.clear();
|
|
183
|
+
reserve_maybe(s, &value);
|
|
184
|
+
return convert_iterable(s, convert);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public:
|
|
188
|
+
bool load(handle src, bool convert) {
|
|
189
|
+
if (!object_is_convertible_to_std_set(src, convert)) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
if (isinstance<anyset>(src)) {
|
|
193
|
+
value.clear();
|
|
194
|
+
return convert_anyset(reinterpret_borrow<anyset>(src), convert);
|
|
195
|
+
}
|
|
196
|
+
if (!convert) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
assert(isinstance<iterable>(src));
|
|
200
|
+
value.clear();
|
|
201
|
+
return convert_iterable(reinterpret_borrow<iterable>(src), convert);
|
|
202
|
+
}
|
|
203
|
+
|
|
87
204
|
template <typename T>
|
|
88
205
|
static handle cast(T &&src, return_value_policy policy, handle parent) {
|
|
89
206
|
if (!std::is_lvalue_reference<T>::value) {
|
|
@@ -100,7 +217,9 @@ public:
|
|
|
100
217
|
return s.release();
|
|
101
218
|
}
|
|
102
219
|
|
|
103
|
-
PYBIND11_TYPE_CASTER(type,
|
|
220
|
+
PYBIND11_TYPE_CASTER(type,
|
|
221
|
+
io_name("collections.abc.Set", "set") + const_name("[") + key_conv::name
|
|
222
|
+
+ const_name("]"));
|
|
104
223
|
};
|
|
105
224
|
|
|
106
225
|
template <typename Type, typename Key, typename Value>
|
|
@@ -115,15 +234,10 @@ private:
|
|
|
115
234
|
}
|
|
116
235
|
void reserve_maybe(const dict &, void *) {}
|
|
117
236
|
|
|
118
|
-
|
|
119
|
-
bool load(handle src, bool convert) {
|
|
120
|
-
if (!isinstance<dict>(src)) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
auto d = reinterpret_borrow<dict>(src);
|
|
237
|
+
bool convert_elements(const dict &d, bool convert) {
|
|
124
238
|
value.clear();
|
|
125
239
|
reserve_maybe(d, &value);
|
|
126
|
-
for (auto it : d) {
|
|
240
|
+
for (const auto &it : d) {
|
|
127
241
|
key_conv kconv;
|
|
128
242
|
value_conv vconv;
|
|
129
243
|
if (!kconv.load(it.first.ptr(), convert) || !vconv.load(it.second.ptr(), convert)) {
|
|
@@ -134,6 +248,25 @@ public:
|
|
|
134
248
|
return true;
|
|
135
249
|
}
|
|
136
250
|
|
|
251
|
+
public:
|
|
252
|
+
bool load(handle src, bool convert) {
|
|
253
|
+
if (!object_is_convertible_to_std_map(src, convert)) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
if (isinstance<dict>(src)) {
|
|
257
|
+
return convert_elements(reinterpret_borrow<dict>(src), convert);
|
|
258
|
+
}
|
|
259
|
+
if (!convert) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
auto items = reinterpret_steal<object>(PyMapping_Items(src.ptr()));
|
|
263
|
+
if (!items) {
|
|
264
|
+
throw error_already_set();
|
|
265
|
+
}
|
|
266
|
+
assert(isinstance<iterable>(items));
|
|
267
|
+
return convert_elements(dict(reinterpret_borrow<iterable>(items)), convert);
|
|
268
|
+
}
|
|
269
|
+
|
|
137
270
|
template <typename T>
|
|
138
271
|
static handle cast(T &&src, return_value_policy policy, handle parent) {
|
|
139
272
|
dict d;
|
|
@@ -157,7 +290,8 @@ public:
|
|
|
157
290
|
}
|
|
158
291
|
|
|
159
292
|
PYBIND11_TYPE_CASTER(Type,
|
|
160
|
-
|
|
293
|
+
io_name("collections.abc.Mapping", "dict") + const_name("[")
|
|
294
|
+
+ key_conv::name + const_name(", ") + value_conv::name
|
|
161
295
|
+ const_name("]"));
|
|
162
296
|
};
|
|
163
297
|
|
|
@@ -166,13 +300,35 @@ struct list_caster {
|
|
|
166
300
|
using value_conv = make_caster<Value>;
|
|
167
301
|
|
|
168
302
|
bool load(handle src, bool convert) {
|
|
169
|
-
if (!
|
|
303
|
+
if (!object_is_convertible_to_std_vector(src)) {
|
|
170
304
|
return false;
|
|
171
305
|
}
|
|
172
|
-
|
|
306
|
+
if (isinstance<sequence>(src)) {
|
|
307
|
+
return convert_elements(src, convert);
|
|
308
|
+
}
|
|
309
|
+
if (!convert) {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
// Designed to be behavior-equivalent to passing tuple(src) from Python:
|
|
313
|
+
// The conversion to a tuple will first exhaust the generator object, to ensure that
|
|
314
|
+
// the generator is not left in an unpredictable (to the caller) partially-consumed
|
|
315
|
+
// state.
|
|
316
|
+
assert(isinstance<iterable>(src));
|
|
317
|
+
return convert_elements(tuple(reinterpret_borrow<iterable>(src)), convert);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
private:
|
|
321
|
+
template <typename T = Type, enable_if_t<has_reserve_method<T>::value, int> = 0>
|
|
322
|
+
void reserve_maybe(const sequence &s, Type *) {
|
|
323
|
+
value.reserve(s.size());
|
|
324
|
+
}
|
|
325
|
+
void reserve_maybe(const sequence &, void *) {}
|
|
326
|
+
|
|
327
|
+
bool convert_elements(handle seq, bool convert) {
|
|
328
|
+
auto s = reinterpret_borrow<sequence>(seq);
|
|
173
329
|
value.clear();
|
|
174
330
|
reserve_maybe(s, &value);
|
|
175
|
-
for (const auto &it :
|
|
331
|
+
for (const auto &it : seq) {
|
|
176
332
|
value_conv conv;
|
|
177
333
|
if (!conv.load(it, convert)) {
|
|
178
334
|
return false;
|
|
@@ -182,13 +338,6 @@ struct list_caster {
|
|
|
182
338
|
return true;
|
|
183
339
|
}
|
|
184
340
|
|
|
185
|
-
private:
|
|
186
|
-
template <typename T = Type, enable_if_t<has_reserve_method<T>::value, int> = 0>
|
|
187
|
-
void reserve_maybe(const sequence &s, Type *) {
|
|
188
|
-
value.reserve(s.size());
|
|
189
|
-
}
|
|
190
|
-
void reserve_maybe(const sequence &, void *) {}
|
|
191
|
-
|
|
192
341
|
public:
|
|
193
342
|
template <typename T>
|
|
194
343
|
static handle cast(T &&src, return_value_policy policy, handle parent) {
|
|
@@ -208,7 +357,9 @@ public:
|
|
|
208
357
|
return l.release();
|
|
209
358
|
}
|
|
210
359
|
|
|
211
|
-
PYBIND11_TYPE_CASTER(Type,
|
|
360
|
+
PYBIND11_TYPE_CASTER(Type,
|
|
361
|
+
io_name("collections.abc.Sequence", "list") + const_name("[")
|
|
362
|
+
+ value_conv::name + const_name("]"));
|
|
212
363
|
};
|
|
213
364
|
|
|
214
365
|
template <typename Type, typename Alloc>
|
|
@@ -220,43 +371,87 @@ struct type_caster<std::deque<Type, Alloc>> : list_caster<std::deque<Type, Alloc
|
|
|
220
371
|
template <typename Type, typename Alloc>
|
|
221
372
|
struct type_caster<std::list<Type, Alloc>> : list_caster<std::list<Type, Alloc>, Type> {};
|
|
222
373
|
|
|
374
|
+
template <typename ArrayType, typename V, size_t... I>
|
|
375
|
+
ArrayType vector_to_array_impl(V &&v, index_sequence<I...>) {
|
|
376
|
+
return {{std::move(v[I])...}};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Based on https://en.cppreference.com/w/cpp/container/array/to_array
|
|
380
|
+
template <typename ArrayType, size_t N, typename V>
|
|
381
|
+
ArrayType vector_to_array(V &&v) {
|
|
382
|
+
return vector_to_array_impl<ArrayType, V>(std::forward<V>(v), make_index_sequence<N>{});
|
|
383
|
+
}
|
|
384
|
+
|
|
223
385
|
template <typename ArrayType, typename Value, bool Resizable, size_t Size = 0>
|
|
224
386
|
struct array_caster {
|
|
225
387
|
using value_conv = make_caster<Value>;
|
|
226
388
|
|
|
227
389
|
private:
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
390
|
+
std::unique_ptr<ArrayType> value;
|
|
391
|
+
|
|
392
|
+
template <bool R = Resizable, enable_if_t<R, int> = 0>
|
|
393
|
+
bool convert_elements(handle seq, bool convert) {
|
|
394
|
+
auto l = reinterpret_borrow<sequence>(seq);
|
|
395
|
+
value.reset(new ArrayType{});
|
|
396
|
+
// Using `resize` to preserve the behavior exactly as it was before PR #5305
|
|
397
|
+
// For the `resize` to work, `Value` must be default constructible.
|
|
398
|
+
// For `std::valarray`, this is a requirement:
|
|
399
|
+
// https://en.cppreference.com/w/cpp/named_req/NumericType
|
|
400
|
+
value->resize(l.size());
|
|
401
|
+
size_t ctr = 0;
|
|
402
|
+
for (const auto &it : l) {
|
|
403
|
+
value_conv conv;
|
|
404
|
+
if (!conv.load(it, convert)) {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
(*value)[ctr++] = cast_op<Value &&>(std::move(conv));
|
|
232
408
|
}
|
|
233
409
|
return true;
|
|
234
410
|
}
|
|
235
|
-
template <bool R = Resizable>
|
|
236
|
-
bool require_size(enable_if_t<!R, size_t> size) {
|
|
237
|
-
return size == Size;
|
|
238
|
-
}
|
|
239
411
|
|
|
240
|
-
|
|
241
|
-
bool
|
|
242
|
-
|
|
412
|
+
template <bool R = Resizable, enable_if_t<!R, int> = 0>
|
|
413
|
+
bool convert_elements(handle seq, bool convert) {
|
|
414
|
+
auto l = reinterpret_borrow<sequence>(seq);
|
|
415
|
+
if (l.size() != Size) {
|
|
243
416
|
return false;
|
|
244
417
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
418
|
+
// The `temp` storage is needed to support `Value` types that are not
|
|
419
|
+
// default-constructible.
|
|
420
|
+
// Deliberate choice: no template specializations, for simplicity, and
|
|
421
|
+
// because the compile time overhead for the specializations is deemed
|
|
422
|
+
// more significant than the runtime overhead for the `temp` storage.
|
|
423
|
+
std::vector<Value> temp;
|
|
424
|
+
temp.reserve(l.size());
|
|
425
|
+
for (auto it : l) {
|
|
251
426
|
value_conv conv;
|
|
252
427
|
if (!conv.load(it, convert)) {
|
|
253
428
|
return false;
|
|
254
429
|
}
|
|
255
|
-
|
|
430
|
+
temp.emplace_back(cast_op<Value &&>(std::move(conv)));
|
|
256
431
|
}
|
|
432
|
+
value.reset(new ArrayType(vector_to_array<ArrayType, Size>(std::move(temp))));
|
|
257
433
|
return true;
|
|
258
434
|
}
|
|
259
435
|
|
|
436
|
+
public:
|
|
437
|
+
bool load(handle src, bool convert) {
|
|
438
|
+
if (!object_is_convertible_to_std_vector(src)) {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
if (isinstance<sequence>(src)) {
|
|
442
|
+
return convert_elements(src, convert);
|
|
443
|
+
}
|
|
444
|
+
if (!convert) {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
// Designed to be behavior-equivalent to passing tuple(src) from Python:
|
|
448
|
+
// The conversion to a tuple will first exhaust the generator object, to ensure that
|
|
449
|
+
// the generator is not left in an unpredictable (to the caller) partially-consumed
|
|
450
|
+
// state.
|
|
451
|
+
assert(isinstance<iterable>(src));
|
|
452
|
+
return convert_elements(tuple(reinterpret_borrow<iterable>(src)), convert);
|
|
453
|
+
}
|
|
454
|
+
|
|
260
455
|
template <typename T>
|
|
261
456
|
static handle cast(T &&src, return_value_policy policy, handle parent) {
|
|
262
457
|
list l(src.size());
|
|
@@ -272,12 +467,38 @@ public:
|
|
|
272
467
|
return l.release();
|
|
273
468
|
}
|
|
274
469
|
|
|
275
|
-
PYBIND11_TYPE_CASTER
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
470
|
+
// Code copied from PYBIND11_TYPE_CASTER macro.
|
|
471
|
+
// Intentionally preserving the behavior exactly as it was before PR #5305
|
|
472
|
+
template <typename T_, enable_if_t<std::is_same<ArrayType, remove_cv_t<T_>>::value, int> = 0>
|
|
473
|
+
static handle cast(T_ *src, return_value_policy policy, handle parent) {
|
|
474
|
+
if (!src) {
|
|
475
|
+
return none().release();
|
|
476
|
+
}
|
|
477
|
+
if (policy == return_value_policy::take_ownership) {
|
|
478
|
+
auto h = cast(std::move(*src), policy, parent);
|
|
479
|
+
delete src; // WARNING: Assumes `src` was allocated with `new`.
|
|
480
|
+
return h;
|
|
481
|
+
}
|
|
482
|
+
return cast(*src, policy, parent);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
486
|
+
operator ArrayType *() { return &(*value); }
|
|
487
|
+
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
488
|
+
operator ArrayType &() { return *value; }
|
|
489
|
+
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
490
|
+
operator ArrayType &&() && { return std::move(*value); }
|
|
491
|
+
|
|
492
|
+
template <typename T_>
|
|
493
|
+
using cast_op_type = movable_cast_op_type<T_>;
|
|
494
|
+
|
|
495
|
+
static constexpr auto name
|
|
496
|
+
= const_name<Resizable>(const_name(""), const_name("typing.Annotated["))
|
|
497
|
+
+ io_name("collections.abc.Sequence", "list") + const_name("[") + value_conv::name
|
|
498
|
+
+ const_name("]")
|
|
499
|
+
+ const_name<Resizable>(const_name(""),
|
|
500
|
+
const_name(", \"FixedSize(") + const_name<Size>()
|
|
501
|
+
+ const_name(")\"]"));
|
|
281
502
|
};
|
|
282
503
|
|
|
283
504
|
template <typename Type, size_t Size>
|
|
@@ -336,7 +557,7 @@ struct optional_caster {
|
|
|
336
557
|
return true;
|
|
337
558
|
}
|
|
338
559
|
|
|
339
|
-
PYBIND11_TYPE_CASTER(Type,
|
|
560
|
+
PYBIND11_TYPE_CASTER(Type, value_conv::name | make_caster<none>::name);
|
|
340
561
|
};
|
|
341
562
|
|
|
342
563
|
#if defined(PYBIND11_HAS_OPTIONAL)
|
|
@@ -420,10 +641,7 @@ struct variant_caster<V<Ts...>> {
|
|
|
420
641
|
}
|
|
421
642
|
|
|
422
643
|
using Type = V<Ts...>;
|
|
423
|
-
PYBIND11_TYPE_CASTER(Type,
|
|
424
|
-
const_name("Union[")
|
|
425
|
-
+ ::pybind11::detail::concat(make_caster<Ts>::name...)
|
|
426
|
-
+ const_name("]"));
|
|
644
|
+
PYBIND11_TYPE_CASTER(Type, ::pybind11::detail::union_concat(make_caster<Ts>::name...));
|
|
427
645
|
};
|
|
428
646
|
|
|
429
647
|
#if defined(PYBIND11_HAS_VARIANT)
|
|
@@ -158,8 +158,7 @@ void vector_modifiers(
|
|
|
158
158
|
return v.release();
|
|
159
159
|
}));
|
|
160
160
|
|
|
161
|
-
cl.def(
|
|
162
|
-
"clear", [](Vector &v) { v.clear(); }, "Clear the contents");
|
|
161
|
+
cl.def("clear", [](Vector &v) { v.clear(); }, "Clear the contents");
|
|
163
162
|
|
|
164
163
|
cl.def(
|
|
165
164
|
"extend",
|
|
@@ -181,7 +180,7 @@ void vector_modifiers(
|
|
|
181
180
|
v.end());
|
|
182
181
|
try {
|
|
183
182
|
v.shrink_to_fit();
|
|
184
|
-
} catch (const std::exception &) {
|
|
183
|
+
} catch (const std::exception &) { // NOLINT(bugprone-empty-catch)
|
|
185
184
|
// Do nothing
|
|
186
185
|
}
|
|
187
186
|
throw;
|
|
@@ -488,7 +487,7 @@ PYBIND11_NAMESPACE_END(detail)
|
|
|
488
487
|
//
|
|
489
488
|
// std::vector
|
|
490
489
|
//
|
|
491
|
-
template <typename Vector, typename holder_type =
|
|
490
|
+
template <typename Vector, typename holder_type = default_holder_type<Vector>, typename... Args>
|
|
492
491
|
class_<Vector, holder_type> bind_vector(handle scope, std::string const &name, Args &&...args) {
|
|
493
492
|
using Class_ = class_<Vector, holder_type>;
|
|
494
493
|
|
|
@@ -695,9 +694,43 @@ struct ItemsViewImpl : public detail::items_view {
|
|
|
695
694
|
Map ↦
|
|
696
695
|
};
|
|
697
696
|
|
|
697
|
+
inline str format_message_key_error_key_object(handle py_key) {
|
|
698
|
+
str message = "pybind11::bind_map key";
|
|
699
|
+
if (!py_key) {
|
|
700
|
+
return message;
|
|
701
|
+
}
|
|
702
|
+
try {
|
|
703
|
+
message = str(py_key);
|
|
704
|
+
} catch (const std::exception &) {
|
|
705
|
+
try {
|
|
706
|
+
message = repr(py_key);
|
|
707
|
+
} catch (const std::exception &) {
|
|
708
|
+
return message;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
const ssize_t cut_length = 100;
|
|
712
|
+
if (len(message) > 2 * cut_length + 3) {
|
|
713
|
+
return str(message[slice(0, cut_length, 1)]) + str("✄✄✄")
|
|
714
|
+
+ str(message[slice(-cut_length, static_cast<ssize_t>(len(message)), 1)]);
|
|
715
|
+
}
|
|
716
|
+
return message;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
template <typename KeyType>
|
|
720
|
+
str format_message_key_error(const KeyType &key) {
|
|
721
|
+
object py_key;
|
|
722
|
+
try {
|
|
723
|
+
py_key = cast(key);
|
|
724
|
+
} catch (const std::exception &) {
|
|
725
|
+
do { // Trick to avoid "empty catch" warning/error.
|
|
726
|
+
} while (false);
|
|
727
|
+
}
|
|
728
|
+
return format_message_key_error_key_object(py_key);
|
|
729
|
+
}
|
|
730
|
+
|
|
698
731
|
PYBIND11_NAMESPACE_END(detail)
|
|
699
732
|
|
|
700
|
-
template <typename Map, typename holder_type =
|
|
733
|
+
template <typename Map, typename holder_type = default_holder_type<Map>, typename... Args>
|
|
701
734
|
class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args &&...args) {
|
|
702
735
|
using KeyType = typename Map::key_type;
|
|
703
736
|
using MappedType = typename Map::mapped_type;
|
|
@@ -786,7 +819,8 @@ class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args &&
|
|
|
786
819
|
[](Map &m, const KeyType &k) -> MappedType & {
|
|
787
820
|
auto it = m.find(k);
|
|
788
821
|
if (it == m.end()) {
|
|
789
|
-
|
|
822
|
+
set_error(PyExc_KeyError, detail::format_message_key_error(k));
|
|
823
|
+
throw error_already_set();
|
|
790
824
|
}
|
|
791
825
|
return it->second;
|
|
792
826
|
},
|
|
@@ -809,7 +843,8 @@ class_<Map, holder_type> bind_map(handle scope, const std::string &name, Args &&
|
|
|
809
843
|
cl.def("__delitem__", [](Map &m, const KeyType &k) {
|
|
810
844
|
auto it = m.find(k);
|
|
811
845
|
if (it == m.end()) {
|
|
812
|
-
|
|
846
|
+
set_error(PyExc_KeyError, detail::format_message_key_error(k));
|
|
847
|
+
throw error_already_set();
|
|
813
848
|
}
|
|
814
849
|
m.erase(it);
|
|
815
850
|
});
|