18 py::print(
"my_func(x:int={}, y:float={:.0f}, z:float={:.0f})"_s.format(
x,
y,
z));
19 return (
float)
x *
y *
z;
24 py::module_::import(
"numpy");
25 }
catch (
const py::error_already_set &) {
35 m.def(
"vectorized_func2", [](py::array_t<int>
x, py::array_t<float>
y,
float z) {
41 m.def(
"vectorized_func3",
42 py::vectorize([](std::complex<double>
c) {
return c * std::complex<double>(2.
f); }));
48 m.def(
"selective_func",
49 [](
const py::array_t<int, py::array::c_style> &) {
return "Int branch taken."; });
50 m.def(
"selective_func",
51 [](
const py::array_t<float, py::array::c_style> &) {
return "Float branch taken."; });
52 m.def(
"selective_func", [](
const py::array_t<std::complex<float>, py::array::c_style> &) {
53 return "Complex float branch taken.";
60 explicit NonPODClass(
int v) :
value{
v} {}
63 py::class_<NonPODClass>(
m,
"NonPODClass")
66 m.def(
"vec_passthrough",
71 py::array_t<double>
c,
75 const double g) {
return *
a +
b +
c.at(0) +
d +
e +
f.value +
g; }));
78 struct VectorizeTestClass {
79 explicit VectorizeTestClass(
int v) :
value{
v} {};
80 float method(
int x,
float y)
const {
return y + (
float) (
x +
value); }
83 py::class_<VectorizeTestClass> vtc(
m,
"VectorizeTestClass");
87 vtc.def(
"method",
py::vectorize(&VectorizeTestClass::method));
91 py::enum_<py::detail::broadcast_trivial>(
m,
"trivial")
92 .value(
"f_trivial", py::detail::broadcast_trivial::f_trivial)
93 .value(
"c_trivial", py::detail::broadcast_trivial::c_trivial)
94 .value(
"non_trivial", py::detail::broadcast_trivial::non_trivial);
95 m.def(
"vectorized_is_trivial",
96 [](
const py::array_t<int, py::array::forcecast> &arg1,
97 const py::array_t<float, py::array::forcecast> &arg2,
98 const py::array_t<double, py::array::forcecast> &arg3) {
100 std::vector<py::ssize_t> shape;
101 std::array<py::buffer_info, 3> buffers{
102 {arg1.request(), arg2.request(), arg3.request()}};