MCPcopy Create free account
hub / github.com/pybind/pybind11 / apply_custom_transform

Function apply_custom_transform

tests/test_callbacks.cpp:25–38  ·  view source on GitHub ↗

Originally derived from https://github.com/scikit-hep/boost-histogram/blob/460ef90905d6a8a9e6dd3beddfe7b4b49b364579/include/bh_python/transform.hpp#L68-L85

Source from the content-addressed store, hash-verified

23// Originally derived from
24// https://github.com/scikit-hep/boost-histogram/blob/460ef90905d6a8a9e6dd3beddfe7b4b49b364579/include/bh_python/transform.hpp#L68-L85
25double apply_custom_transform(const py::object &src, double value) {
26 using raw_t = double(double);
27
28 py::detail::make_caster<std::function<raw_t>> func_caster;
29 if (!func_caster.load(src, /*convert*/ false)) {
30 return -100;
31 }
32 auto func = static_cast<std::function<raw_t> &>(func_caster);
33 auto *cfunc = func.target<raw_t *>();
34 if (cfunc == nullptr) {
35 return -200;
36 }
37 return (*cfunc)(value);
38}
39
40} // namespace boost_histogram
41} // namespace test_callbacks

Callers

nothing calls this directly

Calls 1

loadMethod · 0.45

Tested by

no test coverage detected