| 159 | #ifdef HAVE_NUMPY |
| 160 | template <typename Axis> |
| 161 | bp::object axis_array_interface(const Axis& axis) { |
| 162 | using T = typename std::decay<typename Axis::value_type>::type; |
| 163 | bp::dict d; |
| 164 | auto shape = bp::make_tuple(axis.size() + 1); |
| 165 | d["shape"] = shape; |
| 166 | d["typestr"] = bp::dtype_typestr<T>(); |
| 167 | // make new array, and pass it to Python |
| 168 | auto a = np::empty(shape, np::dtype::get_builtin<T>()); |
| 169 | auto buf = reinterpret_cast<T*>(a.get_data()); |
| 170 | for (auto i = 0; i < axis.size() + 1; ++i) buf[i] = axis.lower(i); |
| 171 | d["data"] = a; |
| 172 | d["version"] = 3; |
| 173 | return d; |
| 174 | } |
| 175 | |
| 176 | template <> |
| 177 | bp::object axis_array_interface<bha::category<>>(const bha::category<>& axis) { |