Originally derived from https://github.com/scikit-hep/boost-histogram/blob/460ef90905d6a8a9e6dd3beddfe7b4b49b364579/include/bh_python/transform.hpp#L68-L85
| 23 | // Originally derived from |
| 24 | // https://github.com/scikit-hep/boost-histogram/blob/460ef90905d6a8a9e6dd3beddfe7b4b49b364579/include/bh_python/transform.hpp#L68-L85 |
| 25 | double 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 |