Skip to content

Commit

Permalink
Merge pull request #44 from lsst/tickets/DM-45486
Browse files Browse the repository at this point in the history
DM-45486: Use cpputils rather than deprecated utils in C++ code
  • Loading branch information
timj authored Jul 30, 2024
2 parents 11f7dcd + 4aaa233 commit 4140384
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 86 deletions.
4 changes: 2 additions & 2 deletions python/lsst/geom/_AffineTransform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
#include "ndarray/pybind11.h"

#include "lsst/geom/AffineTransform.h"
#include "lsst/utils/python.h"
#include "lsst/cpputils/python.h"

namespace py = pybind11;
using namespace pybind11::literals;

namespace lsst {
namespace geom {

void wrapAffineTransform(utils::python::WrapperCollection & wrappers) {
void wrapAffineTransform(cpputils::python::WrapperCollection & wrappers) {
wrappers.wrapType(
py::class_<AffineTransform, std::shared_ptr<AffineTransform>>(wrappers.module, "AffineTransform"),
[](auto & mod, auto & cls) mutable {
Expand Down
6 changes: 3 additions & 3 deletions python/lsst/geom/_Angle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "pybind11/pybind11.h"

#include "lsst/utils/python.h"
#include "lsst/cpputils/python.h"

#include "lsst/geom/Angle.h"

Expand Down Expand Up @@ -51,7 +51,7 @@ void declareAngleComparisonOperators(PyAngle& cls) {

} // anonymous

void wrapAngle(utils::python::WrapperCollection & wrappers) {
void wrapAngle(cpputils::python::WrapperCollection & wrappers) {
wrappers.wrapType(
PyAngleUnit(wrappers.module, "AngleUnit"),
[](auto & mod, auto & cls) mutable {
Expand Down Expand Up @@ -109,7 +109,7 @@ void wrapAngle(utils::python::WrapperCollection & wrappers) {
cls.def("__reduce__", [cls](Angle const& self) {
return py::make_tuple(cls, py::make_tuple(py::cast(self.asRadians())));
});
utils::python::addOutputOp(cls, "__str__");
cpputils::python::addOutputOp(cls, "__str__");
cls.def("__repr__", [](Angle const & self) {
if (std::isfinite(self.asDegrees())) {
return py::str("Angle({:0.17g}, degrees)").format(self.asDegrees());
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/geom/_Box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
#include "pybind11/numpy.h"

#include "lsst/geom/Box.h"
#include "lsst/utils/python.h"
#include "lsst/cpputils/python.h"

namespace py = pybind11;
using namespace py::literals;

namespace lsst {
namespace geom {

void wrapBox(utils::python::WrapperCollection & wrappers) {
void wrapBox(cpputils::python::WrapperCollection & wrappers) {
wrappers.wrapType(
py::class_<Box2I, std::shared_ptr<Box2I>>(wrappers.module, "Box2I"),
[](auto & mod, auto & cls) mutable {
Expand Down
6 changes: 3 additions & 3 deletions python/lsst/geom/_Interval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "ndarray/pybind11.h"

#include "lsst/geom/Interval.h"
#include "lsst/utils/python.h"
#include "lsst/cpputils/python.h"

namespace py = pybind11;
using namespace py::literals;
Expand Down Expand Up @@ -94,15 +94,15 @@ void declareCommonIntervalInterface(PyClass &cls) {
cls.def("expandedTo", py::overload_cast<T const &>(&T::expandedTo, py::const_));
cls.def("clippedTo", &T::clippedTo);
cls.def("__str__", &T::toString);
utils::python::addOutputOp(cls, "__repr__");
cpputils::python::addOutputOp(cls, "__repr__");
cls.def("__reduce__", [cls](IntervalD const &self) {
return py::make_tuple(cls, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
});
}

} // namespace

void wrapInterval(utils::python::WrapperCollection &wrappers) {
void wrapInterval(cpputils::python::WrapperCollection &wrappers) {
wrappers.wrapType(py::class_<IntervalI, std::shared_ptr<IntervalI>>(wrappers.module, "IntervalI"),
[](auto &mod, auto &cls) {
py::enum_<IntervalI::EdgeHandlingEnum>(cls, "EdgeHandlingEnum")
Expand Down
10 changes: 5 additions & 5 deletions python/lsst/geom/_LinearTransform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#include "ndarray/pybind11.h"

#include "lsst/utils/python.h"
#include "lsst/cpputils/python.h"

#include "lsst/geom/Extent.h"
#include "lsst/geom/Point.h"
Expand All @@ -38,7 +38,7 @@ using namespace pybind11::literals;
namespace lsst {
namespace geom {

void wrapLinearTransform(utils::python::WrapperCollection & wrappers) {
void wrapLinearTransform(cpputils::python::WrapperCollection & wrappers) {
wrappers.wrapType(
py::class_<LinearTransform, std::shared_ptr<LinearTransform>>(wrappers.module, "LinearTransform"),
[](auto & mod, auto & cls) {
Expand Down Expand Up @@ -80,10 +80,10 @@ void wrapLinearTransform(utils::python::WrapperCollection & wrappers) {
},
"x"_a, "y"_a);
cls.def("__getitem__",
[](LinearTransform const &self, int i) { return self[utils::python::cppIndex(4, i)]; });
[](LinearTransform const &self, int i) { return self[cpputils::python::cppIndex(4, i)]; });
cls.def("__getitem__", [](LinearTransform const &self, std::pair<int, int> i) {
auto row = utils::python::cppIndex(2, i.first);
auto col = utils::python::cppIndex(2, i.second);
auto row = cpputils::python::cppIndex(2, i.first);
auto col = cpputils::python::cppIndex(2, i.second);
return self.getMatrix()(row, col);
});
cls.def("__mul__", &LinearTransform::operator*, py::is_operator());
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/geom/_SpherePoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <cmath>
#include <memory>

#include "lsst/utils/python.h"
#include "lsst/cpputils/python.h"
#include "lsst/sphgeom/UnitVector3d.h"
#include "lsst/sphgeom/Vector3d.h"
#include "lsst/sphgeom/LonLat.h"
Expand Down Expand Up @@ -59,7 +59,7 @@ double toUnitZ(double longitude, double latitude) {

using PySpherePoint = py::class_<SpherePoint, std::shared_ptr<SpherePoint>>;

void wrapSpherePoint(utils::python::WrapperCollection & wrappers) {
void wrapSpherePoint(cpputils::python::WrapperCollection & wrappers) {
wrappers.addSignatureDependency("lsst.sphgeom");
wrappers.wrapType(
PySpherePoint(wrappers.module, "SpherePoint"),
Expand All @@ -78,7 +78,7 @@ void wrapSpherePoint(utils::python::WrapperCollection & wrappers) {
/* Operators */
cls.def("__getitem__",
[](SpherePoint const &self, std::ptrdiff_t i) {
return self[utils::python::cppIndex(2, i)];
return self[cpputils::python::cppIndex(2, i)];
});
cls.def("__eq__", &SpherePoint::operator==, py::is_operator());
cls.def("__ne__", &SpherePoint::operator!=, py::is_operator());
Expand All @@ -97,7 +97,7 @@ void wrapSpherePoint(utils::python::WrapperCollection & wrappers) {
cls.def("rotated", &SpherePoint::rotated, "axis"_a, "amount"_a);
cls.def("offset", &SpherePoint::offset, "bearing"_a, "amount"_a);
cls.def("getTangentPlaneOffset", &SpherePoint::getTangentPlaneOffset, "other"_a);
utils::python::addOutputOp(cls, "__str__");
cpputils::python::addOutputOp(cls, "__str__");
cls.def("__len__", [](SpherePoint const &) { return 2; });
cls.def("__reduce__", [cls](SpherePoint const &self) {
return py::make_tuple(cls, py::make_tuple(py::cast(self.getLongitude()),
Expand Down
32 changes: 16 additions & 16 deletions python/lsst/geom/_coordinates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "lsst/geom/Extent.h"
#include "lsst/geom/CoordinateBase.h"
#include "lsst/geom/CoordinateExpr.h"
#include "lsst/utils/python.h"
#include "lsst/cpputils/python.h"

namespace py = pybind11;
using namespace pybind11::literals;
Expand Down Expand Up @@ -55,24 +55,24 @@ template <typename T, int N>
using PyPoint = py::class_<Point<T, N>, PointBase<T, N>>;

template <typename Derived, typename T, int N>
void declareCoordinateBase(utils::python::WrapperCollection & wrappers, std::string const &suffix) {
void declareCoordinateBase(cpputils::python::WrapperCollection & wrappers, std::string const &suffix) {
static std::string const name = "CoordinateBase" + suffix;
wrappers.wrapType(
PyCoordinateBase<Derived, T, N>(wrappers.module, name.c_str()),
[](auto & mod, auto & cls) {
cls.def("__getitem__", [](CoordinateBase<Derived, T, N> &self, int i) -> T {
return self[utils::python::cppIndex(N, i)];
return self[cpputils::python::cppIndex(N, i)];
});
cls.def("__setitem__", [](CoordinateBase<Derived, T, N> &self, int i, T value) {
self[utils::python::cppIndex(N, i)] = value;
self[cpputils::python::cppIndex(N, i)] = value;
});
cls.def("__len__", [](CoordinateBase<Derived, T, N> &c) -> int { return N; });
}
);
}

template <int N>
void declareCoordinateExpr(utils::python::WrapperCollection & wrappers, std::string const &suffix) {
void declareCoordinateExpr(cpputils::python::WrapperCollection & wrappers, std::string const &suffix) {
static std::string const name = "CoordinateExpr" + suffix;
declareCoordinateBase<CoordinateExpr<N>, bool, N>(wrappers, name);
wrappers.wrapType(
Expand All @@ -89,7 +89,7 @@ void declareCoordinateExpr(utils::python::WrapperCollection & wrappers, std::str
}

template <typename T, int N>
void declareExtentBase(utils::python::WrapperCollection & wrappers, std::string const &suffix) {
void declareExtentBase(cpputils::python::WrapperCollection & wrappers, std::string const &suffix) {
static std::string const name = "ExtentBase" + suffix;
declareCoordinateBase<Extent<T, N>, T, N>(wrappers, "Extent" + suffix);
wrappers.wrapType(
Expand Down Expand Up @@ -120,7 +120,7 @@ void declareExtentBase(utils::python::WrapperCollection & wrappers, std::string

// Common functionality for all Extents, including declaring base classes.
template <typename T, int N>
PyExtent<T, N> declareExtent(utils::python::WrapperCollection & wrappers, std::string const &suffix) {
PyExtent<T, N> declareExtent(cpputils::python::WrapperCollection & wrappers, std::string const &suffix) {
static std::string const name = "Extent" + suffix;
declareExtentBase<T, N>(wrappers, suffix);
return wrappers.wrapType(
Expand Down Expand Up @@ -177,7 +177,7 @@ PyExtent<T, N> declareExtent(utils::python::WrapperCollection & wrappers, std::s

// Add functionality only found in N=2 Extents (and delgate to declareExtent for the rest)
template <typename T>
PyExtent<T, 2> declareExtent2(utils::python::WrapperCollection & wrappers, std::string const &suffix) {
PyExtent<T, 2> declareExtent2(cpputils::python::WrapperCollection & wrappers, std::string const &suffix) {
return wrappers.wrapType(
declareExtent<T, 2>(wrappers, std::string("2") + suffix),
[](auto & mod, auto & cls) {
Expand All @@ -201,7 +201,7 @@ PyExtent<T, 2> declareExtent2(utils::python::WrapperCollection & wrappers, std::

// Add functionality only found in N=3 Extents (and delgate to declareExtent for the rest)
template <typename T>
PyExtent<T, 3> declareExtent3(utils::python::WrapperCollection & wrappers, const std::string &suffix) {
PyExtent<T, 3> declareExtent3(cpputils::python::WrapperCollection & wrappers, const std::string &suffix) {
return wrappers.wrapType(
declareExtent<T, 3>(wrappers, std::string("3") + suffix),
[](auto & mod, auto & cls) mutable {
Expand Down Expand Up @@ -233,7 +233,7 @@ PyExtent<T, 3> declareExtent3(utils::python::WrapperCollection & wrappers, const
// operators that dispatch on a scalar, and hence they have to be defined here
// instead of declareExtent.
template <int N>
void declareExtentOperators(utils::python::WrapperCollection & wrapper,
void declareExtentOperators(cpputils::python::WrapperCollection & wrapper,
PyExtent<int, N> &clsI, PyExtent<double, N> &clsD) {
wrapper.wrap(
[clsI, clsD](auto & mod) mutable {
Expand Down Expand Up @@ -323,7 +323,7 @@ void declareExtentOperators(utils::python::WrapperCollection & wrapper,
}

template <typename T, int N>
void declarePointBase(utils::python::WrapperCollection & wrappers, std::string const &suffix) {
void declarePointBase(cpputils::python::WrapperCollection & wrappers, std::string const &suffix) {
static std::string const name = "PointBase" + suffix;
declareCoordinateBase<Point<T, N>, T, N>(wrappers, "Point" + suffix);
wrappers.wrapType(
Expand Down Expand Up @@ -356,7 +356,7 @@ void declarePointBase(utils::python::WrapperCollection & wrappers, std::string c

// Common functionality
template <typename T, int N>
PyPoint<T, N> declarePoint(utils::python::WrapperCollection & wrappers, std::string const &suffix) {
PyPoint<T, N> declarePoint(cpputils::python::WrapperCollection & wrappers, std::string const &suffix) {
static std::string const name = "Point" + suffix;
declarePointBase<T, N>(wrappers, suffix);
return wrappers.wrapType(
Expand Down Expand Up @@ -398,7 +398,7 @@ PyPoint<T, N> declarePoint(utils::python::WrapperCollection & wrappers, std::str

// Add functionality only found in N=2 Points
template <typename T>
PyPoint<T, 2> declarePoint2(utils::python::WrapperCollection & wrappers, std::string const &suffix) {
PyPoint<T, 2> declarePoint2(cpputils::python::WrapperCollection & wrappers, std::string const &suffix) {
return wrappers.wrapType(
declarePoint<T, 2>(wrappers, std::string("2") + suffix),
[](auto & mod, auto & cls) {
Expand All @@ -422,7 +422,7 @@ PyPoint<T, 2> declarePoint2(utils::python::WrapperCollection & wrappers, std::st

// Add functionality only found in N=3 Points
template <typename T>
PyPoint<T, 3> declarePoint3(utils::python::WrapperCollection & wrappers, std::string const &suffix) {
PyPoint<T, 3> declarePoint3(cpputils::python::WrapperCollection & wrappers, std::string const &suffix) {
return wrappers.wrapType(
declarePoint<T, 3>(wrappers, std::string("3") + suffix),
[](auto & mod, auto & cls) {
Expand Down Expand Up @@ -454,7 +454,7 @@ PyPoint<T, 3> declarePoint3(utils::python::WrapperCollection & wrappers, std::st
// operators that dispatch on a scalar, and hence they have to be defined here
// instead of declareExtent.
template <int N>
void declarePointOperators(utils::python::WrapperCollection & wrappers,
void declarePointOperators(cpputils::python::WrapperCollection & wrappers,
PyPoint<int, N> &clsI, PyPoint<double, N> &clsD) {
wrappers.wrap(
[clsI, clsD](auto & mod) mutable {
Expand Down Expand Up @@ -488,7 +488,7 @@ void declarePointOperators(utils::python::WrapperCollection & wrappers,

} // anonymous

void wrapCoordinates(utils::python::WrapperCollection & wrappers) {
void wrapCoordinates(cpputils::python::WrapperCollection & wrappers) {
// Only the interface-level classes are defined here, and these functions
// call others to define their base classes, since those are never shared.

Expand Down
4 changes: 2 additions & 2 deletions python/lsst/geom/_geom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include "pybind11/pybind11.h"

#include "lsst/utils/python.h"
#include "lsst/cpputils/python.h"


namespace py = pybind11;
Expand All @@ -30,7 +30,7 @@ using namespace pybind11::literals;
namespace lsst {
namespace geom {

using utils::python::WrapperCollection;
using cpputils::python::WrapperCollection;

void wrapAngle(WrapperCollection & wrappers);
void wrapCoordinates(WrapperCollection & wrappers);
Expand Down
6 changes: 3 additions & 3 deletions src/Box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <cmath>
#include <limits>

#include "lsst/utils/hashCombine.h"
#include "lsst/cpputils/hashCombine.h"
#include "lsst/geom/Box.h"

namespace lsst {
Expand Down Expand Up @@ -255,7 +255,7 @@ bool Box2I::operator!=(Box2I const& other) const noexcept {

std::size_t Box2I::hash_value() const noexcept {
// Completely arbitrary seed
return utils::hashCombine(17, _minimum, _dimensions);
return cpputils::hashCombine(17, _minimum, _dimensions);
}

std::vector<Point2I> Box2I::getCorners() const {
Expand Down Expand Up @@ -489,7 +489,7 @@ std::size_t Box2D::hash_value() const noexcept {
return 179;
} else {
// Completely arbitrary seed
return utils::hashCombine(17, _minimum, _maximum);
return cpputils::hashCombine(17, _minimum, _maximum);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Extent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "lsst/utils/hashCombine.h"
#include "lsst/cpputils/hashCombine.h"
#include "lsst/geom/CoordinateBase.h"
#include "lsst/geom/Point.h"
#include "lsst/geom/Extent.h"
Expand Down Expand Up @@ -126,7 +126,7 @@ Extent<int, N> ceil(Extent<double, N> const &input) noexcept {
template <typename T, int N>
std::size_t hash_value(Extent<T, N> const &extent) noexcept {
std::size_t result = 0; // Completely arbitrary seed
for (int n = 0; n < N; ++n) result = utils::hashCombine(result, extent[n]);
for (int n = 0; n < N; ++n) result = cpputils::hashCombine(result, extent[n]);
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Interval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "boost/format.hpp"

#include "lsst/utils/hashCombine.h"
#include "lsst/cpputils/hashCombine.h"
#include "lsst/geom/Interval.h"

namespace lsst {
Expand Down Expand Up @@ -198,7 +198,7 @@ bool IntervalI::operator!=(IntervalI const& other) const noexcept { return !(oth

std::size_t IntervalI::hash_value() const noexcept {
// Completely arbitrary seed
return utils::hashCombine(17, _min, _size);
return cpputils::hashCombine(17, _min, _size);
}

std::string IntervalI::toString() const {
Expand Down Expand Up @@ -348,7 +348,7 @@ bool IntervalD::operator!=(IntervalD const& other) const noexcept { return !(oth

std::size_t IntervalD::hash_value() const noexcept {
// Completely arbitrary seed
return utils::hashCombine(17, _min, _max);
return cpputils::hashCombine(17, _min, _max);
}

std::string IntervalD::toString() const {
Expand Down
Loading

0 comments on commit 4140384

Please sign in to comment.