24 #ifndef LSST_UTILS_PYTHON_H 25 #define LSST_UTILS_PYTHON_H 27 #include "pybind11/pybind11.h" 57 template<
typename T,
typename PyClass>
61 pybind11::is_operator());
64 pybind11::is_operator());
81 template <
class PyClass>
83 cls.def(method.
c_str(), [](
typename PyClass::type
const &
self) {
98 template <
class PyClass>
100 using Class =
typename PyClass::type;
101 cls.def(
"__hash__", [](Class
const &
self) {
120 auto const i_orig = i;
125 if (i < 0 || i >= size) {
127 os <<
"Index " << i_orig <<
" not in range [" << -size <<
", " << size - 1 <<
"]";
128 throw pybind11::index_error(os.
str());
151 os <<
"Index (" << i <<
", " << j <<
") not in range [" 152 << -size_i <<
", " << size_i - 1 <<
"], [" 153 << -size_j <<
", " << size_j - 1 <<
"]";
154 throw pybind11::index_error(os.
str());
void addOutputOp(PyClass &cls, std::string const &method)
Add __str__ or __repr__ method implemented by operator<<.
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.
Forward declarations for lsst::utils::Cache.
void addHash(PyClass &cls)
Add __hash__ method implemented by std::hash.
void addSharedPtrEquality(PyClass &cls)
Add __eq__ and __ne__ methods based on two std::shared_ptr<T> pointing to the same address...