Skip to content

Commit a89c008

Browse files
committed
MapTraits moved from map.hpp to map_traits.hpp.
1 parent 0209b74 commit a89c008

File tree

2 files changed

+54
-45
lines changed

2 files changed

+54
-45
lines changed

src/pyco_tree/pico_tree/_pyco_tree/map.hpp

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,24 @@ namespace py = pybind11;
1111

1212
namespace pyco_tree {
1313

14+
//! \brief The Map class adds the row_major property to the pico_tree::SpaceMap
15+
//! class.
1416
template <typename Scalar_, int Dim_>
15-
class Map {
17+
class Map : public pico_tree::SpaceMap<Scalar_, Dim_> {
1618
public:
17-
using ScalarType = Scalar_;
18-
static int constexpr Dim = Dim_;
19+
using typename pico_tree::SpaceMap<Scalar_, Dim_>::ScalarType;
20+
using pico_tree::SpaceMap<Scalar_, Dim_>::Dim;
1921
// Fixed to be an int.
2022
using IndexType = int;
2123

2224
inline Map(
2325
ScalarType* data, std::size_t npts, std::size_t sdim, bool row_major)
24-
: space_(data, npts, sdim), row_major_(row_major) {}
26+
: pico_tree::SpaceMap<Scalar_, Dim_>(data, npts, sdim),
27+
row_major_(row_major) {}
2528

26-
inline pico_tree::PointMap<ScalarType const, Dim> operator()(
27-
std::size_t i) const {
28-
return space_(i);
29-
}
30-
31-
inline ScalarType const* data() const { return space_.data(); }
32-
inline ScalarType* data() { return space_.data(); }
33-
inline std::size_t npts() const { return space_.npts(); }
34-
inline std::size_t sdim() const { return space_.sdim(); }
3529
inline bool row_major() const { return row_major_; }
3630

3731
private:
38-
pico_tree::SpaceMap<ScalarType, Dim> space_;
3932
bool row_major_;
4033
};
4134

@@ -66,34 +59,8 @@ Map<Scalar_, Dim_> MakeMap(py::array_t<Scalar_, 0> const pts) {
6659
}
6760

6861
template <typename Scalar_, int Dim_, typename Index_>
69-
struct MapTraits {
62+
struct MapTraits : public pico_tree::MapTraits<Scalar_, Dim_, Index_> {
7063
using SpaceType = Map<Scalar_, Dim_>;
71-
using PointType = pico_tree::PointMap<Scalar_ const, Dim_>;
72-
using ScalarType = Scalar_;
73-
static constexpr int Dim = Dim_;
74-
using IndexType = Index_;
75-
76-
inline static int SpaceSdim(SpaceType const& space) {
77-
return static_cast<IndexType>(space.sdim());
78-
}
79-
80-
inline static IndexType SpaceNpts(SpaceType const& space) {
81-
return static_cast<IndexType>(space.npts());
82-
}
83-
84-
inline static PointType PointAt(SpaceType const& space, IndexType const idx) {
85-
return space(idx);
86-
}
87-
88-
template <typename OtherPoint>
89-
inline static int PointSdim(OtherPoint const& point) {
90-
return pico_tree::StdPointTraits<OtherPoint>::Sdim(point);
91-
}
92-
93-
template <typename OtherPoint>
94-
inline static ScalarType const* PointCoords(OtherPoint const& point) {
95-
return pico_tree::StdPointTraits<OtherPoint>::Coords(point);
96-
}
9764
};
9865

9966
} // namespace pyco_tree

src/pyco_tree/pico_tree/_pyco_tree/map_straits.hpp

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ class SpaceMapBase {
5656

5757
} // namespace internal
5858

59+
//! \brief The PointMap class provides an interface for accessing a raw pointer
60+
//! as a Point, allowing easy access to its coordinates.
5961
template <typename Scalar_, int Dim_>
60-
class PointMap final : public internal::PointMapBase<Scalar_, Dim_> {
62+
class PointMap : public internal::PointMapBase<Scalar_, Dim_> {
6163
public:
6264
using typename internal::PointMapBase<Scalar_, Dim_>::ScalarType;
6365
using internal::PointMapBase<Scalar_, Dim_>::Dim;
@@ -73,8 +75,10 @@ class PointMap final : public internal::PointMapBase<Scalar_, Dim_> {
7375
}
7476
};
7577

78+
//! \brief The PointMap class provides an interface for accessing a raw pointer
79+
//! as a Point, allowing easy access to its coordinates.
7680
template <typename Scalar_>
77-
class PointMap<Scalar_, kDynamicDim> final
81+
class PointMap<Scalar_, kDynamicDim>
7882
: public internal::PointMapBase<Scalar_, kDynamicDim> {
7983
public:
8084
using typename internal::PointMapBase<Scalar_, kDynamicDim>::ScalarType;
@@ -89,8 +93,10 @@ class PointMap<Scalar_, kDynamicDim> final
8993
std::size_t sdim_;
9094
};
9195

96+
//! \brief The SpaceMap class provides an interface for accessing a raw pointer
97+
//! as a Space, allowing easy access to its points via a PointMap interface.
9298
template <typename Scalar_, int Dim_>
93-
class SpaceMap final : public internal::SpaceMapBase<Scalar_, Dim_> {
99+
class SpaceMap : public internal::SpaceMapBase<Scalar_, Dim_> {
94100
public:
95101
using typename internal::SpaceMapBase<Scalar_, Dim_>::ScalarType;
96102
using internal::SpaceMapBase<Scalar_, Dim_>::Dim;
@@ -114,8 +120,10 @@ class SpaceMap final : public internal::SpaceMapBase<Scalar_, Dim_> {
114120
}
115121
};
116122

123+
//! \brief The SpaceMap class provides an interface for accessing a raw pointer
124+
//! as a Space, allowing easy access to its points via a PointMap interface.
117125
template <typename Scalar_>
118-
class SpaceMap<Scalar_, kDynamicDim> final
126+
class SpaceMap<Scalar_, kDynamicDim>
119127
: public internal::SpaceMapBase<Scalar_, kDynamicDim> {
120128
public:
121129
using typename internal::SpaceMapBase<Scalar_, kDynamicDim>::ScalarType;
@@ -152,4 +160,38 @@ struct StdPointTraits<PointMap<Scalar_, Dim_>> {
152160
}
153161
};
154162

163+
//! \brief MapTraits provides an interface for SpaceMap and points supported by
164+
//! StdPointTraits.
165+
//! \tparam Index_ Type used for indexing. Defaults to int.
166+
template <typename Scalar_, int Dim_, typename Index_ = int>
167+
struct MapTraits {
168+
using SpaceType = SpaceMap<Scalar_, Dim_>;
169+
using PointType = PointMap<Scalar_ const, Dim_>;
170+
using ScalarType = Scalar_;
171+
static constexpr int Dim = Dim_;
172+
using IndexType = Index_;
173+
174+
inline static int SpaceSdim(SpaceType const& space) {
175+
return static_cast<IndexType>(space.sdim());
176+
}
177+
178+
inline static IndexType SpaceNpts(SpaceType const& space) {
179+
return static_cast<IndexType>(space.npts());
180+
}
181+
182+
inline static PointType PointAt(SpaceType const& space, IndexType const idx) {
183+
return space(idx);
184+
}
185+
186+
template <typename OtherPoint>
187+
inline static int PointSdim(OtherPoint const& point) {
188+
return StdPointTraits<OtherPoint>::Sdim(point);
189+
}
190+
191+
template <typename OtherPoint>
192+
inline static ScalarType const* PointCoords(OtherPoint const& point) {
193+
return StdPointTraits<OtherPoint>::Coords(point);
194+
}
195+
};
196+
155197
} // namespace pico_tree

0 commit comments

Comments
 (0)