From 8f606c5d721bfc5b32609a9c5557f2bcafdd4936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Tue, 25 Apr 2023 13:38:05 +0200 Subject: [PATCH] Python bindings --- src/binding/python/Dataset.cpp | 108 ++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 50 deletions(-) diff --git a/src/binding/python/Dataset.cpp b/src/binding/python/Dataset.cpp index 656cd59ea8..70d85721f2 100644 --- a/src/binding/python/Dataset.cpp +++ b/src/binding/python/Dataset.cpp @@ -27,58 +27,66 @@ void init_Dataset(py::module &m) { - py::class_(m, "Dataset") + auto pyDataset = + py::class_(m, "Dataset") + .def( + py::init(), + py::arg("dtype"), + py::arg("extent")) + .def(py::init(), py::arg("extent")) + .def( + py::init([](py::dtype dt, Extent const &e) { + auto const d = dtype_from_numpy(std::move(dt)); + return new Dataset{d, e}; + }), + py::arg("dtype"), + py::arg("extent")) + .def( + py::init(), + py::arg("dtype"), + py::arg("extent"), + py::arg("options")) + .def( + py::init([](py::dtype dt, Extent e, std::string options) { + auto const d = dtype_from_numpy(std::move(dt)); + return new Dataset{d, std::move(e), std::move(options)}; + }), + py::arg("dtype"), + py::arg("extent"), + py::arg("options")) - .def(py::init(), py::arg("dtype"), py::arg("extent")) - .def(py::init(), py::arg("extent")) - .def( - py::init([](py::dtype dt, Extent const &e) { - auto const d = dtype_from_numpy(std::move(dt)); - return new Dataset{d, e}; - }), - py::arg("dtype"), - py::arg("extent")) - .def( - py::init(), - py::arg("dtype"), - py::arg("extent"), - py::arg("options")) - .def( - py::init([](py::dtype dt, Extent const &e, std::string options) { - auto const d = dtype_from_numpy(std::move(dt)); - return new Dataset{d, e, std::move(options)}; - }), - py::arg("dtype"), - py::arg("extent"), - py::arg("options")) - - .def( - "__repr__", - [](const Dataset &d) { - std::stringstream stream; - stream << ""; - } - else - { - auto begin = d.extent.begin(); - stream << '[' << *begin++; - for (; begin != d.extent.end(); ++begin) + .def( + "__repr__", + [](const Dataset &d) { + std::stringstream stream; + stream << ""; + } + else { - stream << ", " << *begin; + auto begin = d.extent.begin(); + stream << '[' << *begin++; + for (; begin != d.extent.end(); ++begin) + { + stream << ", " << *begin; + } + stream << "]>"; } - stream << "]>"; - } - return stream.str(); - }) + return stream.str(); + }) - .def_readonly("extent", &Dataset::extent) - .def("extend", &Dataset::extend) - .def_readonly("rank", &Dataset::rank) - .def_property_readonly( - "dtype", [](const Dataset &d) { return dtype_to_numpy(d.dtype); }) - .def_readwrite("options", &Dataset::options); + .def_property_readonly( + "joined_dimension", &Dataset::joinedDimension) + .def_readonly("extent", &Dataset::extent) + .def("extend", &Dataset::extend) + .def_readonly("rank", &Dataset::rank) + .def_property_readonly( + "dtype", + [](const Dataset &d) { return dtype_to_numpy(d.dtype); }) + .def_readwrite("options", &Dataset::options); + pyDataset.attr("JOINED_DIMENSION") = + py::int_(uint64_t(Dataset::JOINED_DIMENSION)); }