mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-21 20:55:11 +00:00
abc29cad02
This adds support for controlling the `convert` flag of arguments through the py::arg annotation. This then allows arguments to be flagged as non-converting, which the type_caster is able to use to request different behaviour. Currently, AFAICS `convert` is only used for type converters of regular pybind11-registered types; all of the other core type_casters ignore it. We can, however, repurpose it to control internal conversion of converters like Eigen and `array`: most usefully to give callers a way to disable the conversion that would otherwise occur when a `Eigen::Ref<const Eigen::Matrix>` argument is passed a numpy array that requires conversion (either because it has an incompatible stride or the wrong dtype). Specifying a noconvert looks like one of these: m.def("f1", &f, "a"_a.noconvert() = "default"); // Named, default, noconvert m.def("f2", &f, "a"_a.noconvert()); // Named, no default, no converting m.def("f3", &f, py::arg().noconvert()); // Unnamed, no default, no converting (The last part--being able to declare a py::arg without a name--is new: previous py::arg() only accepted named keyword arguments). Such an non-convert argument is then passed `convert = false` by the type caster when loading the argument. Whether this has an effect is up to the type caster itself, but as mentioned above, this would be extremely helpful for the Eigen support to give a nicer way to specify a "no-copy" mode than the custom wrapper in the current PR, and moreover isn't an Eigen-specific hack. |
||
---|---|---|
.. | ||
_static | ||
advanced | ||
basics.rst | ||
benchmark.py | ||
benchmark.rst | ||
changelog.rst | ||
classes.rst | ||
compiling.rst | ||
conf.py | ||
Doxyfile | ||
environment.yml | ||
faq.rst | ||
index.rst | ||
intro.rst | ||
limitations.rst | ||
Makefile | ||
pybind11_vs_boost_python1.png | ||
pybind11_vs_boost_python1.svg | ||
pybind11_vs_boost_python2.png | ||
pybind11_vs_boost_python2.svg | ||
pybind11-logo.png | ||
reference.rst | ||
release.rst |