23 #include "pybind11/pybind11.h" 24 #include "pybind11/stl.h" 26 #include "ndarray/pybind11.h" 50 PyArrayKey<T>
cls(mod, (
"Array" + suffix +
"Key").c_str());
52 cls.def(py::init<>());
54 cls.def(py::init<SubSchema const &>());
59 ArrayKey<T>::addFields,
60 "schema"_a,
"name"_a,
"doc"_a,
"unit"_a,
"docData"_a);
63 ArrayKey<T>::addFields,
64 "schema"_a,
"name"_a,
"doc"_a,
"unit"_a,
"size"_a);
65 cls.def(
"get", &ArrayKey<T>::get);
68 cls.def(
"__eq__", &ArrayKey<T>::operator==, py::is_operator());
69 cls.def(
"__ne__", &ArrayKey<T>::operator!=, py::is_operator());
70 cls.def(
"__getitem__",
72 [](ArrayKey<T>
const &
self, py::object
const &index) -> py::object {
73 if (py::isinstance<py::slice>(index)) {
74 py::slice slice(index);
75 py::size_t start = 0, stop = 0,
step = 0, length = 0;
76 bool valid = slice.compute(
self.
getSize(), &start, &stop, &
step, &length);
77 if (!valid)
throw py::error_already_set();
79 throw py::index_error(
"Step for ArrayKey must be 1.");
81 return py::cast(
self.slice(start, stop));
84 return py::cast(
self[n]);
88 cls.def(
"slice", &ArrayKey<T>::slice);
92 py::module::import(
"lsst.afw.table.base");
94 declareArrayKey<float>(mod,
"F");
95 declareArrayKey<double>(mod,
"D");
std::size_t cppIndex(std::ptrdiff_t size, std::ptrdiff_t i)
Compute a C++ index from a Python index (negative values count from the end) and range-check.
PYBIND11_MODULE(camera, mod)
daf::base::PropertySet * set
A base class for image defects.