15 py::print(
"my_func(x:int={}, y:float={:.0f}, z:float={:.0f})"_s.format(x, y, z));
20 try { py::module::import(
"numpy"); }
21 catch (...) {
return; }
28 m.def(
"vectorized_func2",
29 [](py::array_t<int>
x, py::array_t<float>
y,
float z) {
36 [](std::complex<double>
c) {
return c * std::complex<double>(2.f); }
41 m.def(
"selective_func", [](py::array_t<int, py::array::c_style>) {
return "Int branch taken."; });
42 m.def(
"selective_func", [](py::array_t<float, py::array::c_style>) {
return "Float branch taken."; });
43 m.def(
"selective_func", [](py::array_t<std::complex<float>, py::array::c_style>) {
return "Complex float branch taken."; });
50 NonPODClass(
int v) :
value{v} {}
53 py::class_<NonPODClass>(
m,
"NonPODClass").def(py::init<int>());
55 [](
double *
a,
double b, py::array_t<double> c,
const int &
d,
int &
e, NonPODClass
f,
const double g) {
56 return *a + b + c.at(0) + d + e + f.value +
g;
61 struct VectorizeTestClass {
62 VectorizeTestClass(
int v) :
value{v} {};
63 float method(
int x,
float y) {
return y + (
float) (x +
value); }
66 py::class_<VectorizeTestClass> vtc(m,
"VectorizeTestClass");
67 vtc .def(py::init<int>())
71 vtc.def(
"method",
py::vectorize(&VectorizeTestClass::method));
75 py::enum_<py::detail::broadcast_trivial>(
m,
"trivial")
76 .
value(
"f_trivial", py::detail::broadcast_trivial::f_trivial)
77 .value(
"c_trivial", py::detail::broadcast_trivial::c_trivial)
78 .value(
"non_trivial", py::detail::broadcast_trivial::non_trivial);
79 m.def(
"vectorized_is_trivial", [](
80 py::array_t<int, py::array::forcecast> arg1,
81 py::array_t<float, py::array::forcecast> arg2,
82 py::array_t<double, py::array::forcecast> arg3
85 std::vector<ssize_t> shape;
86 std::array<py::buffer_info, 3> buffers {{ arg1.request(), arg2.request(), arg3.request() }};
void print(const Matrix &A, const string &s, ostream &stream)
double my_func(int x, float y, double z)
void g(const string &key, int i)
detail::vectorize_helper< Return(*)(Args...), Return, Args... > vectorize(Return(*f)(Args...))
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
TEST_SUBMODULE(numpy_vectorize, m)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
broadcast_trivial broadcast(const std::array< buffer_info, N > &buffers, ssize_t &ndim, std::vector< ssize_t > &shape)