test_numpy_vectorize.cpp (11986:c12e4625ab56) | test_numpy_vectorize.cpp (12037:d28054ac6ec9) |
---|---|
1/* 2 tests/test_numpy_vectorize.cpp -- auto-vectorize functions over NumPy array 3 arguments 4 5 Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> 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. --- 24 unchanged lines hidden (view full) --- 33 34 // Vectorize a complex-valued function 35 m.def("vectorized_func3", py::vectorize(my_func3)); 36 37 /// Numpy function which only accepts specific data types 38 m.def("selective_func", [](py::array_t<int, py::array::c_style>) { return "Int branch taken."; }); 39 m.def("selective_func", [](py::array_t<float, py::array::c_style>) { return "Float branch taken."; }); 40 m.def("selective_func", [](py::array_t<std::complex<float>, py::array::c_style>) { return "Complex float branch taken."; }); | 1/* 2 tests/test_numpy_vectorize.cpp -- auto-vectorize functions over NumPy array 3 arguments 4 5 Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch> 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. --- 24 unchanged lines hidden (view full) --- 33 34 // Vectorize a complex-valued function 35 m.def("vectorized_func3", py::vectorize(my_func3)); 36 37 /// Numpy function which only accepts specific data types 38 m.def("selective_func", [](py::array_t<int, py::array::c_style>) { return "Int branch taken."; }); 39 m.def("selective_func", [](py::array_t<float, py::array::c_style>) { return "Float branch taken."; }); 40 m.def("selective_func", [](py::array_t<std::complex<float>, py::array::c_style>) { return "Complex float branch taken."; }); |
41 42 43 // Internal optimization test for whether the input is trivially broadcastable: 44 py::enum_<py::detail::broadcast_trivial>(m, "trivial") 45 .value("f_trivial", py::detail::broadcast_trivial::f_trivial) 46 .value("c_trivial", py::detail::broadcast_trivial::c_trivial) 47 .value("non_trivial", py::detail::broadcast_trivial::non_trivial); 48 m.def("vectorized_is_trivial", []( 49 py::array_t<int, py::array::forcecast> arg1, 50 py::array_t<float, py::array::forcecast> arg2, 51 py::array_t<double, py::array::forcecast> arg3 52 ) { 53 size_t ndim; 54 std::vector<size_t> shape; 55 std::array<py::buffer_info, 3> buffers {{ arg1.request(), arg2.request(), arg3.request() }}; 56 return py::detail::broadcast(buffers, ndim, shape); 57 }); |
|
41}); | 58}); |