Skip to content

Commit 9eaf93e

Browse files
committed
Python bindings
1 parent 889e61d commit 9eaf93e

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

src/backend/BaseRecordComponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ std::optional<size_t> BaseRecordComponent::joinedDimension() const
7070
auto &rc = get();
7171
if (rc.m_dataset.has_value())
7272
{
73-
return rc.m_dataset.value().joinedDimension;
73+
return rc.m_dataset.value().joinedDimension();
7474
}
7575
else
7676
{

src/binding/python/Dataset.cpp

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,50 @@ using namespace openPMD;
3131

3232
void init_Dataset(py::module &m)
3333
{
34-
py::class_<Dataset>(m, "Dataset")
34+
auto pyDataset =
35+
py::class_<Dataset>(m, "Dataset")
36+
.def(
37+
py::init<Datatype, Extent>(),
38+
py::arg("dtype"),
39+
py::arg("extent"))
40+
.def(py::init<Extent>(), py::arg("extent"))
41+
.def(
42+
py::init([](py::dtype dt, Extent e) {
43+
auto const d = dtype_from_numpy(dt);
44+
return new Dataset{d, e};
45+
}),
46+
py::arg("dtype"),
47+
py::arg("extent"))
48+
.def(
49+
py::init<Datatype, Extent, std::string>(),
50+
py::arg("dtype"),
51+
py::arg("extent"),
52+
py::arg("options"))
53+
.def(
54+
py::init([](py::dtype dt, Extent e, std::string options) {
55+
auto const d = dtype_from_numpy(dt);
56+
return new Dataset{d, e, std::move(options)};
57+
}),
58+
py::arg("dtype"),
59+
py::arg("extent"),
60+
py::arg("options"))
3561

36-
.def(py::init<Datatype, Extent>(), py::arg("dtype"), py::arg("extent"))
37-
.def(py::init<Extent>(), py::arg("extent"))
38-
.def(
39-
py::init([](py::dtype dt, Extent e) {
40-
auto const d = dtype_from_numpy(dt);
41-
return new Dataset{d, e};
42-
}),
43-
py::arg("dtype"),
44-
py::arg("extent"))
45-
.def(
46-
py::init<Datatype, Extent, std::string>(),
47-
py::arg("dtype"),
48-
py::arg("extent"),
49-
py::arg("options"))
50-
.def(
51-
py::init([](py::dtype dt, Extent e, std::string options) {
52-
auto const d = dtype_from_numpy(dt);
53-
return new Dataset{d, e, std::move(options)};
54-
}),
55-
py::arg("dtype"),
56-
py::arg("extent"),
57-
py::arg("options"))
62+
.def(
63+
"__repr__",
64+
[](const Dataset &d) {
65+
return "<openPMD.Dataset of rank '" +
66+
std::to_string(d.rank) + "'>";
67+
})
5868

59-
.def(
60-
"__repr__",
61-
[](const Dataset &d) {
62-
return "<openPMD.Dataset of rank '" + std::to_string(d.rank) +
63-
"'>";
64-
})
65-
66-
.def_readonly("extent", &Dataset::extent)
67-
.def("extend", &Dataset::extend)
68-
.def_readonly("rank", &Dataset::rank)
69-
.def_property_readonly(
70-
"dtype", [](const Dataset &d) { return dtype_to_numpy(d.dtype); })
71-
.def_readwrite("options", &Dataset::options);
69+
.def_property_readonly(
70+
"joined_dimension", &Dataset::joinedDimension)
71+
.def_readonly("extent", &Dataset::extent)
72+
.def("extend", &Dataset::extend)
73+
.def_readonly("rank", &Dataset::rank)
74+
.def_property_readonly(
75+
"dtype",
76+
[](const Dataset &d) { return dtype_to_numpy(d.dtype); })
77+
.def_readwrite("options", &Dataset::options);
78+
pyDataset.attr("JOINED_DIMENSION") =
79+
py::int_(uint64_t(Dataset::JOINED_DIMENSION));
7280
}

0 commit comments

Comments
 (0)