24 #include "pybind11/pybind11.h"
25 #include "pybind11/stl.h"
27 #include "ndarray/pybind11.h"
35 using namespace py::literals;
41 using utils::python::WrapperCollection;
45 using PyBaseColumnView = py::class_<BaseColumnView, std::shared_ptr<BaseColumnView>>;
47 using PyBitsColumn = py::class_<BitsColumn, std::shared_ptr<BitsColumn>>;
49 template <
typename T,
typename PyClass>
50 static void declareBaseColumnViewOverloads(
PyClass &cls) {
51 cls.def(
"_basicget", [](BaseColumnView &
self, Key<T>
const &
key) ->
typename ndarray::Array<T, 1>
const {
56 template <
typename U,
typename PyClass>
57 static void declareBaseColumnViewArrayOverloads(
PyClass &cls) {
60 typename ndarray::Array<U, 2, 1>
const {
return self[
key]; });
63 template <
typename PyClass>
64 static void declareBaseColumnViewFlagOverloads(
PyClass &cls) {
66 [](BaseColumnView &
self, Key<Flag>
const &
key) -> ndarray::Array<bool const, 1, 1>
const {
67 return ndarray::copy(
self[
key]);
71 static void declareBaseColumnView(WrapperCollection &wrappers) {
75 wrappers.wrapType(PyBaseColumnView(wrappers.module,
"_BaseColumnViewBase"), [](
auto &mod,
auto &cls) {
76 cls.def(
"getTable", &BaseColumnView::getTable);
77 cls.def_property_readonly(
"table", &BaseColumnView::getTable);
78 cls.def(
"getSchema", &BaseColumnView::getSchema);
79 cls.def_property_readonly(
"schema", &BaseColumnView::getSchema);
81 cls.def(
"_getBits", &BaseColumnView::getBits);
82 cls.def(
"getAllBits", &BaseColumnView::getAllBits);
83 declareBaseColumnViewOverloads<std::uint8_t>(cls);
84 declareBaseColumnViewOverloads<std::uint16_t>(cls);
85 declareBaseColumnViewOverloads<std::int32_t>(cls);
86 declareBaseColumnViewOverloads<std::int64_t>(cls);
87 declareBaseColumnViewOverloads<float>(cls);
88 declareBaseColumnViewOverloads<double>(cls);
89 declareBaseColumnViewFlagOverloads(cls);
92 declareBaseColumnViewArrayOverloads<std::uint8_t>(cls);
93 declareBaseColumnViewArrayOverloads<std::uint16_t>(cls);
94 declareBaseColumnViewArrayOverloads<int>(cls);
95 declareBaseColumnViewArrayOverloads<float>(cls);
96 declareBaseColumnViewArrayOverloads<double>(cls);
100 using AngleArray = ndarray::Array<lsst::geom::Angle, 1>;
101 using DoubleArray = ndarray::Array<double, 1>;
102 cls.def(
"_basicget", [](BaseColumnView &self, Key<lsst::geom::Angle> const &key) -> DoubleArray {
103 ndarray::Array<lsst::geom::Angle, 1, 0> a = self[key];
104 return ndarray::detail::ArrayAccess<DoubleArray>::construct(
105 reinterpret_cast<double *>(a.getData()),
106 ndarray::detail::ArrayAccess<AngleArray>::getCore(a));
111 static void declareBitsColumn(WrapperCollection &wrappers) {
112 wrappers.wrapType(PyBitsColumn(wrappers.module,
"BitsColumn"), [](
auto &mod,
auto &cls) {
113 cls.def(
"getArray", &BitsColumn::getArray);
114 cls.def_property_readonly(
"array", &BitsColumn::getArray);
115 cls.def(
"getBit", (BitsColumn::IntT(BitsColumn::*)(Key<Flag> const &) const) & BitsColumn::getBit,
117 cls.def(
"getBit", (BitsColumn::IntT(BitsColumn::*)(std::string const &) const) & BitsColumn::getBit,
119 cls.def(
"getMask", (BitsColumn::IntT(BitsColumn::*)(Key<Flag> const &) const) & BitsColumn::getMask,
121 cls.def(
"getMask", (BitsColumn::IntT(BitsColumn::*)(std::string const &) const) & BitsColumn::getMask,
129 declareBaseColumnView(wrappers);
130 declareBitsColumn(wrappers);
Tag types used to declare specialized field types.
A helper class for subdividing pybind11 module across multiple translation units (i....
py::class_< PixelAreaBoundedField, std::shared_ptr< PixelAreaBoundedField >, BoundedField > PyClass
void wrapBaseColumnView(WrapperCollection &wrappers)
A base class for image defects.