Loading [MathJax]/extensions/tex2jax.js
LSST Applications 28.0.2,g0fba68d861+5b923b673a,g1fd858c14a+7a7b9dd5ed,g2c84ff76c0+5548bfee71,g30358e5240+f0e04ebe90,g35bb328faa+fcb1d3bbc8,g436fd98eb5+bdc6fcdd04,g4af146b050+742274f7cd,g4d2262a081+3efd3f8190,g4e0f332c67+cb09b8a5b6,g53246c7159+fcb1d3bbc8,g5a012ec0e7+477f9c599b,g5edb6fd927+826dfcb47f,g60b5630c4e+bdc6fcdd04,g67b6fd64d1+2218407a0c,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+f9ac2ab1bd,g8852436030+ebf28f0d95,g89139ef638+2218407a0c,g9125e01d80+fcb1d3bbc8,g989de1cb63+2218407a0c,g9f33ca652e+42fb53f4c8,g9f7030ddb1+11b9b6f027,ga2b97cdc51+bdc6fcdd04,gab72ac2889+bdc6fcdd04,gabe3b4be73+1e0a283bba,gabf8522325+3210f02652,gb1101e3267+9c79701da9,gb58c049af0+f03b321e39,gb89ab40317+2218407a0c,gcf25f946ba+ebf28f0d95,gd6cbbdb0b4+e8f9c9c900,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+a08f294619,ge278dab8ac+3ef3db156b,ge410e46f29+2218407a0c,gf67bdafdda+2218407a0c
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
lsst::sphgeom::python Namespace Reference

Functions

ptrdiff_t convertIndex (ptrdiff_t len, pybind11::int_ i)
 Convert a Python index i over a sequence with length len to a non-negative (C++ style) index, and perform a bounds-check.
 
pybind11::bytes encode (Region const &self)
 Encode a Region as a pybind11 bytes object.
 
template<typename R>
std::unique_ptr< R > decode (pybind11::bytes bytes)
 Decode a Region from a pybind11 bytes object.
 
template<typename S>
std::vector< std::unique_ptr< Region > > convert_region_sequence (S const &seq)
 Create a vector of Region (or Region-subclass) pointers by copying the regions from a sized Python iterable (e.g.
 

Function Documentation

◆ convert_region_sequence()

template<typename S>
std::vector< std::unique_ptr< Region > > lsst::sphgeom::python::convert_region_sequence ( S const & seq)
inline

Create a vector of Region (or Region-subclass) pointers by copying the regions from a sized Python iterable (e.g.

S == py::tuple).

Note that the pybind11 built-in STL conversions don't work, because they use unique_ptr - we can't transfer ownership out of Python, and those converters don't know about our clone methods.

Definition at line 83 of file utils.h.

83 {
85 result.reserve(seq.size());
86 for (pybind11::handle py_region : seq) {
87 result.push_back(py_region.cast<Region const &>().clone());
88 }
89 return result;
90}
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition Region.h:89
virtual std::unique_ptr< Region > clone() const =0
clone returns a deep copy of this region.

◆ convertIndex()

ptrdiff_t lsst::sphgeom::python::convertIndex ( ptrdiff_t len,
pybind11::int_ i )
inline

Convert a Python index i over a sequence with length len to a non-negative (C++ style) index, and perform a bounds-check.

Definition at line 48 of file utils.h.

48 {
49 auto j = static_cast<ptrdiff_t>(i);
50 if ((j == -1 && PyErr_Occurred()) || j < -len || j >= len) {
51 PyErr_Clear();
52 throw pybind11::index_error(
53 pybind11::str("Index {} not in range({}, {})")
54 .format(i, -len, len));
55 }
56 return (j < 0) ? j + len : j;
57}

◆ decode()

template<typename R>
std::unique_ptr< R > lsst::sphgeom::python::decode ( pybind11::bytes bytes)

Decode a Region from a pybind11 bytes object.

Definition at line 69 of file utils.h.

69 {
70 std::uint8_t const *buffer = reinterpret_cast<std::uint8_t const *>(
71 PYBIND11_BYTES_AS_STRING(bytes.ptr()));
72 size_t n = static_cast<size_t>(PYBIND11_BYTES_SIZE(bytes.ptr()));
73 return R::decode(buffer, n);
74}

◆ encode()

pybind11::bytes lsst::sphgeom::python::encode ( Region const & self)
inline

Encode a Region as a pybind11 bytes object.

Definition at line 61 of file utils.h.

61 {
62 std::vector<std::uint8_t> bytes = self.encode();
63 return pybind11::bytes(reinterpret_cast<char const *>(bytes.data()),
64 bytes.size());
65}
T data(T... args)
T size(T... args)