in src/mlio-py/mlio/core/schema.cc [42:96]
void register_schema(py::module &m)
{
py::class_<Attribute>(m,
"Attribute",
"Describes an attribute which defines a measurable "
"property of a dataset.")
.def(py::init(&make_attribute),
"name"_a,
"data_type"_a,
"shape"_a,
"strides"_a = std::nullopt,
"sparse"_a = false)
.def("__eq__",
[](const Attribute &self, const Attribute &other) {
return self == other;
})
.def("__hash__",
[](const Attribute &self) {
return std::hash<Attribute>{}(self);
})
.def("__repr__", &Attribute::repr)
.def_property_readonly("name", &Attribute::name)
.def_property_readonly("data_type", &Attribute::data_type)
.def_property_readonly("shape",
[](Attribute &self) -> py::tuple {
return py::cast(self.shape());
})
.def_property_readonly("strides",
[](Attribute &self) -> py::tuple {
return py::cast(self.strides());
})
.def_property_readonly("sparse", &Attribute::sparse);
py::bind_vector<std::vector<Attribute>>(m, "AttributeList");
py::implicitly_convertible<py::list, std::vector<Attribute>>();
py::class_<Schema, Intrusive_ptr<Schema>>(
m, "Schema", "Represents a Schema that contains the attributes of a dataset.")
.def(py::init<std::vector<Attribute>>(), "attrs"_a)
.def("get_index",
&Schema::get_index,
"name"_a,
"Returns the index of the Attribute with the specified name.")
.def("__eq__",
[](const Schema &self, const Schema &other) {
return self == other;
})
.def("__hash__",
[](const Schema &self) {
return std::hash<Schema>{}(self);
})
.def("__repr__", &Schema::repr)
.def_property_readonly("attributes", &Schema::attributes);
}