#pragma once #include #include #include #include #include "aare/Frame.hpp" #include "aare/NDArray.hpp" #include "aare/NDView.hpp" namespace py = pybind11; // Pass image data back to python as a numpy array template py::array return_image_data(aare::NDArray *image) { py::capsule free_when_done(image, [](void *f) { aare::NDArray *foo = reinterpret_cast *>(f); delete foo; }); return py::array_t( image->shape(), // shape image->byte_strides(), // C-style contiguous strides for double image->data(), // the data pointer free_when_done); // numpy array references this parent } template py::array return_vector(std::vector *vec) { py::capsule free_when_done(vec, [](void *f) { std::vector *foo = reinterpret_cast *>(f); delete foo; }); return py::array_t({vec->size()}, // shape {sizeof(T)}, // C-style contiguous strides for double vec->data(), // the data pointer free_when_done); // numpy array references this parent } // todo rewrite generic template auto get_shape_3d(const py::array_t& arr) { return aare::Shape<3>{arr.shape(0), arr.shape(1), arr.shape(2)}; } template auto make_view_3d(py::array_t& arr) { return aare::NDView(arr.mutable_data(), get_shape_3d(arr)); } template auto get_shape_2d(const py::array_t& arr) { return aare::Shape<2>{arr.shape(0), arr.shape(1)}; } template auto get_shape_1d(const py::array_t& arr) { return aare::Shape<1>{arr.shape(0)}; } template auto make_view_2d(py::array_t& arr) { return aare::NDView(arr.mutable_data(), get_shape_2d(arr)); } template auto make_view_1d(py::array_t& arr) { return aare::NDView(arr.mutable_data(), get_shape_1d(arr)); }