Skip to content

Commit

Permalink
Update code to use is_geometry_v (point, box, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed Feb 2, 2024
1 parent 3030e9a commit 31fb1f7
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 69 deletions.
2 changes: 1 addition & 1 deletion benchmarks/dbscan/ArborX_DBSCANVerification.hpp
Expand Up @@ -309,7 +309,7 @@ bool verifyDBSCAN(ExecutionSpace exec_space, Primitives const &primitives,
Points points{primitives}; // NOLINT

using Point = typename Points::value_type;
static_assert(GeometryTraits::is_point<Point>{});
static_assert(GeometryTraits::is_point_v<Point>);

ArborX::BoundingVolumeHierarchy<MemorySpace, ArborX::PairValueIndex<Point>>
bvh(exec_space, ArborX::Experimental::attach_indices(points));
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/point_clouds/point_clouds.hpp
Expand Up @@ -174,7 +174,7 @@ void generatePointCloud(PointCloudType const point_cloud_type,
{
using namespace ArborX::GeometryTraits;
check_valid_geometry_traits(Point{});
static_assert(is_point<Point>{}, "ArborX: View must contain point values");
static_assert(is_point_v<Point>, "ArborX: View must contain point values");

auto random_points_host = Kokkos::create_mirror_view(random_points);
switch (point_cloud_type)
Expand Down
4 changes: 2 additions & 2 deletions src/ArborX_DBSCAN.hpp
Expand Up @@ -66,7 +66,7 @@ struct WithinRadiusGetter
template <typename Point>
KOKKOS_FUNCTION auto operator()(Point const &point) const
{
static_assert(GeometryTraits::is_point<Point>::value);
static_assert(GeometryTraits::is_point_v<Point>);

constexpr int dim = GeometryTraits::dimension_v<Point>;
auto const &hyper_point =
Expand Down Expand Up @@ -263,7 +263,7 @@ dbscan(ExecutionSpace const &exec_space, Primitives const &primitives,
#endif

using Point = typename Points::value_type;
static_assert(GeometryTraits::is_point<Point>{});
static_assert(GeometryTraits::is_point_v<Point>);
constexpr int dim = GeometryTraits::dimension_v<Point>;
using Box = ExperimentalHyperGeometry::Box<dim>;

Expand Down
2 changes: 1 addition & 1 deletion src/details/ArborX_AccessTraits.hpp
Expand Up @@ -183,7 +183,7 @@ void check_valid_access_traits(PrimitivesTag, Primitives const &,
Access, Primitives>>;
if constexpr (CheckGetReturnType())
{
static_assert(GeometryTraits::is_point<T>{} || GeometryTraits::is_box<T>{},
static_assert(GeometryTraits::is_point_v<T> || GeometryTraits::is_box_v<T>,
"AccessTraits<Primitives,PrimitivesTag>::get() return type "
"must decay to a point or a box type");
}
Expand Down
2 changes: 1 addition & 1 deletion src/details/ArborX_DetailsCartesianGrid.hpp
Expand Up @@ -56,7 +56,7 @@ struct CartesianGrid
}

template <typename Point, typename Enable = std::enable_if_t<
GeometryTraits::is_point<Point>{}>>
GeometryTraits::is_point_v<Point>>>
KOKKOS_FUNCTION size_t cellIndex(Point const &point) const
{
static_assert(GeometryTraits::dimension_v<Point> == DIM);
Expand Down
6 changes: 3 additions & 3 deletions src/details/ArborX_DetailsMortonCode.hpp
Expand Up @@ -283,7 +283,7 @@ KOKKOS_INLINE_FUNCTION unsigned long long expandBitsBy<9>(unsigned long long x)
}

template <typename Point,
typename Enable = std::enable_if_t<GeometryTraits::is_point<Point>{}>>
typename Enable = std::enable_if_t<GeometryTraits::is_point_v<Point>>>
KOKKOS_INLINE_FUNCTION unsigned int morton32(Point const &p)
{
constexpr int DIM = GeometryTraits::dimension_v<Point>;
Expand All @@ -303,7 +303,7 @@ KOKKOS_INLINE_FUNCTION unsigned int morton32(Point const &p)
}

template <typename Point,
std::enable_if_t<GeometryTraits::is_point<Point>{} &&
std::enable_if_t<GeometryTraits::is_point_v<Point> &&
GeometryTraits::dimension_v<Point> != 2> * = nullptr>
KOKKOS_INLINE_FUNCTION unsigned long long morton64(Point const &p)
{
Expand All @@ -326,7 +326,7 @@ KOKKOS_INLINE_FUNCTION unsigned long long morton64(Point const &p)
// Calculate a 62-bit Morton code for a 2D point located within [0, 1]^2.
// Special case because it needs double.
template <typename Point,
std::enable_if_t<GeometryTraits::is_point<Point>{} &&
std::enable_if_t<GeometryTraits::is_point_v<Point> &&
GeometryTraits::dimension_v<Point> == 2> * = nullptr>
KOKKOS_INLINE_FUNCTION unsigned long long morton64(Point const &p)
{
Expand Down
4 changes: 2 additions & 2 deletions src/details/ArborX_IndexableGetter.hpp
Expand Up @@ -25,8 +25,8 @@ struct DefaultIndexableGetter
DefaultIndexableGetter() = default;

template <typename Geometry, typename Enable = std::enable_if_t<
GeometryTraits::is_point<Geometry>{} ||
GeometryTraits::is_box<Geometry>{}>>
GeometryTraits::is_point_v<Geometry> ||
GeometryTraits::is_box_v<Geometry>>>
KOKKOS_FUNCTION auto const &operator()(Geometry const &geometry) const
{
return geometry;
Expand Down
2 changes: 1 addition & 1 deletion src/details/ArborX_MinimumSpanningTree.hpp
Expand Up @@ -50,7 +50,7 @@ struct MinimumSpanningTree

using Points = Details::AccessValues<Primitives, PrimitivesTag>;
using Point = typename Points::value_type;
static_assert(GeometryTraits::is_point<Point>{});
static_assert(GeometryTraits::is_point_v<Point>);

Points points{primitives}; // NOLINT

Expand Down
6 changes: 3 additions & 3 deletions src/details/ArborX_NeighborList.hpp
Expand Up @@ -31,7 +31,7 @@ struct NeighborListPredicateGetter
template <typename Point>
KOKKOS_FUNCTION auto operator()(Point point) const
{
static_assert(GeometryTraits::is_point<Point>{});
static_assert(GeometryTraits::is_point_v<Point>);

constexpr int dim = GeometryTraits::dimension_v<Point>;
using Coordinate = typename GeometryTraits::coordinate_type_t<Point>;
Expand Down Expand Up @@ -61,7 +61,7 @@ void findHalfNeighborList(ExecutionSpace const &space,
"Primitives must be accessible from the execution space");

using Point = typename Points::value_type;
static_assert(GeometryTraits::is_point<Point>{});
static_assert(GeometryTraits::is_point_v<Point>);

Points points{primitives}; // NOLINT
int const n = points.size();
Expand Down Expand Up @@ -117,7 +117,7 @@ void findFullNeighborList(ExecutionSpace const &space,
"Primitives must be accessible from the execution space");

using Point = typename Points::value_type;
static_assert(GeometryTraits::is_point<Point>{});
static_assert(GeometryTraits::is_point_v<Point>);

Points points{primitives}; // NOLINT
int const n = points.size();
Expand Down
16 changes: 8 additions & 8 deletions src/details/ArborX_SpaceFillingCurves.hpp
Expand Up @@ -30,16 +30,16 @@ namespace Experimental
struct Morton32
{
template <typename Box, typename Point,
std::enable_if_t<GeometryTraits::is_box<Box>{} &&
GeometryTraits::is_point<Point>{}> * = nullptr>
std::enable_if_t<GeometryTraits::is_box_v<Box> &&
GeometryTraits::is_point_v<Point>> * = nullptr>
KOKKOS_FUNCTION auto operator()(Box const &scene_bounding_box, Point p) const
{
Details::translateAndScale(p, p, scene_bounding_box);
return Details::morton32(p);
}
template <typename Box, typename Geometry,
std::enable_if_t<GeometryTraits::is_box<Box>{} &&
!GeometryTraits::is_point<Geometry>{}> * = nullptr>
std::enable_if_t<GeometryTraits::is_box_v<Box> &&
!GeometryTraits::is_point_v<Geometry>> * = nullptr>
KOKKOS_FUNCTION auto operator()(Box const &scene_bounding_box,
Geometry const &geometry) const
{
Expand All @@ -52,16 +52,16 @@ struct Morton32
struct Morton64
{
template <typename Box, typename Point,
std::enable_if_t<GeometryTraits::is_box<Box>{} &&
GeometryTraits::is_point<Point>{}> * = nullptr>
std::enable_if_t<GeometryTraits::is_box_v<Box> &&
GeometryTraits::is_point_v<Point>> * = nullptr>
KOKKOS_FUNCTION auto operator()(Box const &scene_bounding_box, Point p) const
{
Details::translateAndScale(p, p, scene_bounding_box);
return Details::morton64(p);
}
template <typename Box, class Geometry,
std::enable_if_t<GeometryTraits::is_box<Box>{} &&
!GeometryTraits::is_point<Geometry>{}> * = nullptr>
std::enable_if_t<GeometryTraits::is_box_v<Box> &&
!GeometryTraits::is_point_v<Geometry>> * = nullptr>
KOKKOS_FUNCTION auto operator()(Box const &scene_bounding_box,
Geometry const &geometry) const
{
Expand Down
4 changes: 2 additions & 2 deletions src/geometry/ArborX_DetailsAlgorithms.hpp
Expand Up @@ -512,8 +512,8 @@ struct centroid<TriangleTag, Triangle>
// transformation that maps the unit cube into a new axis-aligned box
// NOTE safe to perform in-place
template <typename Point, typename Box,
std::enable_if_t<GeometryTraits::is_point<Point>{} &&
GeometryTraits::is_box<Box>{}> * = nullptr>
std::enable_if_t<GeometryTraits::is_point_v<Point> &&
GeometryTraits::is_box_v<Box>> * = nullptr>
KOKKOS_FUNCTION void translateAndScale(Point const &in, Point &out,
Box const &ref)
{
Expand Down
60 changes: 23 additions & 37 deletions src/geometry/ArborX_GeometryTraits.hpp
Expand Up @@ -20,27 +20,11 @@ namespace ArborX
namespace GeometryTraits
{

struct PointTag
{};

struct BoxTag
{};

struct SphereTag
{};

struct TriangleTag
{};

struct KDOPTag
{};

template <typename Geometry>
struct dimension
{
using not_specialized = void; // tag to detect existence of a specialization
};

template <typename Geometry>
inline constexpr int dimension_v = dimension<Geometry>::value;

Expand All @@ -63,6 +47,28 @@ struct coordinate_type
template <typename Geometry>
using coordinate_type_t = typename coordinate_type<Geometry>::type;

// clang-format off
#define DEFINE_GEOMETRY(name, name_tag) \
struct name_tag{}; \
template <typename Geometry> \
struct is_##name : std::is_same<tag_t<Geometry>, name_tag>{}; \
template <typename Geometry> \
inline constexpr bool is_##name##_v = is_##name<Geometry>::value
// clang-format on

DEFINE_GEOMETRY(point, PointTag);
DEFINE_GEOMETRY(box, BoxTag);
DEFINE_GEOMETRY(sphere, SphereTag);
DEFINE_GEOMETRY(triangle, TriangleTag);
DEFINE_GEOMETRY(kdop, KDOPTag);
#undef IS_GEOMETRY

template <typename Geometry>
inline constexpr bool
is_valid_geometry = (is_point_v<Geometry> || is_box_v<Geometry> ||
is_sphere_v<Geometry> || is_kdop_v<Geometry> ||
is_triangle_v<Geometry>);

template <typename Geometry>
using DimensionNotSpecializedArchetypeAlias =
typename dimension<Geometry>::not_specialized;
Expand All @@ -77,22 +83,6 @@ using CoordinateNotSpecializedArchetypeAlias =
template <typename Geometry>
using DimensionArchetypeAlias = decltype(dimension_v<Geometry>);

template <typename Geometry>
struct is_point : std::is_same<typename tag<Geometry>::type, PointTag>
{};

template <typename Geometry>
struct is_box : std::is_same<typename tag<Geometry>::type, BoxTag>
{};

template <typename Geometry>
struct is_sphere : std::is_same<typename tag<Geometry>::type, SphereTag>
{};

template <typename Geometry>
struct is_triangle : std::is_same<typename tag<Geometry>::type, TriangleTag>
{};

template <typename Geometry>
void check_valid_geometry_traits(Geometry const &)
{
Expand All @@ -117,11 +107,7 @@ void check_valid_geometry_traits(Geometry const &)

static_assert(!std::is_same_v<tag_t<Geometry>, not_specialized>,
"GeometryTraits::tag<Geometry> must define 'type' member type");
using Tag = typename tag<Geometry>::type;
static_assert(std::is_same<Tag, PointTag>{} || std::is_same<Tag, BoxTag>{} ||
std::is_same<Tag, SphereTag>{} ||
std::is_same<Tag, TriangleTag>{} ||
std::is_same<Tag, KDOPTag>{},
static_assert(is_valid_geometry<Geometry>,
"GeometryTraits::tag<Geometry>::type must be PointTag, BoxTag, "
"SphereTag, TriangleTag or KDOPTag");

Expand Down
2 changes: 1 addition & 1 deletion src/geometry/ArborX_HyperBox.hpp
Expand Up @@ -80,7 +80,7 @@ struct Box
}

template <typename Point,
std::enable_if_t<GeometryTraits::is_point<Point>{}> * = nullptr>
std::enable_if_t<GeometryTraits::is_point_v<Point>> * = nullptr>
KOKKOS_FUNCTION auto &operator+=(Point const &point)
{
using Details::KokkosExt::max;
Expand Down
4 changes: 2 additions & 2 deletions src/interpolation/ArborX_InterpMovingLeastSquares.hpp
Expand Up @@ -121,7 +121,7 @@ class MovingLeastSquares
"Source points must be accessible from the execution space");
using SourcePoint = typename SourceAccess::value_type;
GeometryTraits::check_valid_geometry_traits(SourcePoint{});
static_assert(GeometryTraits::is_point<SourcePoint>::value,
static_assert(GeometryTraits::is_point_v<SourcePoint>,
"Source points elements must be points");
static constexpr int dimension = GeometryTraits::dimension_v<SourcePoint>;

Expand All @@ -135,7 +135,7 @@ class MovingLeastSquares
"Target points must be accessible from the execution space");
using TargetPoint = typename TargetAccess::value_type;
GeometryTraits::check_valid_geometry_traits(TargetPoint{});
static_assert(GeometryTraits::is_point<TargetPoint>::value,
static_assert(GeometryTraits::is_point_v<TargetPoint>,
"Target points elements must be points");
static_assert(dimension == GeometryTraits::dimension_v<TargetPoint>,
"Target and source points must have the same dimension");
Expand Down
Expand Up @@ -100,8 +100,7 @@ KOKKOS_INLINE_FUNCTION constexpr auto
evaluate(Point const &point,
typename GeometryTraits::coordinate_type_t<Point> const radius)
{
static_assert(GeometryTraits::is_point<Point>::value,
"point must be a point");
static_assert(GeometryTraits::is_point_v<Point>, "Point must be a point");
constexpr std::size_t dim = GeometryTraits::dimension_v<Point>;
return CRBFunc::template evaluate<dim>(
ArborX::Details::distance(point, Point{}) / radius);
Expand Down
Expand Up @@ -104,8 +104,7 @@ KOKKOS_FUNCTION constexpr std::size_t polynomialBasisSize()
template <std::size_t Degree, typename Point>
KOKKOS_FUNCTION auto evaluatePolynomialBasis(Point const &p)
{
static_assert(GeometryTraits::is_point<Point>::value,
"point must be a point");
static_assert(GeometryTraits::is_point_v<Point>, "Point must be a point");
static constexpr std::size_t DIM = GeometryTraits::dimension_v<Point>;
using Value = typename GeometryTraits::coordinate_type_t<Point>;
static_assert(DIM > 0, "Polynomial basis with no dimension is invalid");
Expand Down

0 comments on commit 31fb1f7

Please sign in to comment.