From 31fb1f70019b11b0bbad5b0d50d5a1b0c701c96a Mon Sep 17 00:00:00 2001 From: Andrey Prokopenko Date: Fri, 2 Feb 2024 12:57:08 -0500 Subject: [PATCH] Update code to use is_geometry_v (point, box, etc) --- .../dbscan/ArborX_DBSCANVerification.hpp | 2 +- benchmarks/point_clouds/point_clouds.hpp | 2 +- src/ArborX_DBSCAN.hpp | 4 +- src/details/ArborX_AccessTraits.hpp | 2 +- src/details/ArborX_DetailsCartesianGrid.hpp | 2 +- src/details/ArborX_DetailsMortonCode.hpp | 6 +- src/details/ArborX_IndexableGetter.hpp | 4 +- src/details/ArborX_MinimumSpanningTree.hpp | 2 +- src/details/ArborX_NeighborList.hpp | 6 +- src/details/ArborX_SpaceFillingCurves.hpp | 16 ++--- src/geometry/ArborX_DetailsAlgorithms.hpp | 4 +- src/geometry/ArborX_GeometryTraits.hpp | 60 +++++++------------ src/geometry/ArborX_HyperBox.hpp | 2 +- .../ArborX_InterpMovingLeastSquares.hpp | 4 +- ...nterpDetailsCompactRadialBasisFunction.hpp | 3 +- .../ArborX_InterpDetailsPolynomialBasis.hpp | 3 +- 16 files changed, 53 insertions(+), 69 deletions(-) diff --git a/benchmarks/dbscan/ArborX_DBSCANVerification.hpp b/benchmarks/dbscan/ArborX_DBSCANVerification.hpp index b70c2486d..55f90285d 100644 --- a/benchmarks/dbscan/ArborX_DBSCANVerification.hpp +++ b/benchmarks/dbscan/ArborX_DBSCANVerification.hpp @@ -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{}); + static_assert(GeometryTraits::is_point_v); ArborX::BoundingVolumeHierarchy> bvh(exec_space, ArborX::Experimental::attach_indices(points)); diff --git a/benchmarks/point_clouds/point_clouds.hpp b/benchmarks/point_clouds/point_clouds.hpp index f15a4b3a4..35286b742 100644 --- a/benchmarks/point_clouds/point_clouds.hpp +++ b/benchmarks/point_clouds/point_clouds.hpp @@ -174,7 +174,7 @@ void generatePointCloud(PointCloudType const point_cloud_type, { using namespace ArborX::GeometryTraits; check_valid_geometry_traits(Point{}); - static_assert(is_point{}, "ArborX: View must contain point values"); + static_assert(is_point_v, "ArborX: View must contain point values"); auto random_points_host = Kokkos::create_mirror_view(random_points); switch (point_cloud_type) diff --git a/src/ArborX_DBSCAN.hpp b/src/ArborX_DBSCAN.hpp index 7f856628d..093953afc 100644 --- a/src/ArborX_DBSCAN.hpp +++ b/src/ArborX_DBSCAN.hpp @@ -66,7 +66,7 @@ struct WithinRadiusGetter template KOKKOS_FUNCTION auto operator()(Point const &point) const { - static_assert(GeometryTraits::is_point::value); + static_assert(GeometryTraits::is_point_v); constexpr int dim = GeometryTraits::dimension_v; auto const &hyper_point = @@ -263,7 +263,7 @@ dbscan(ExecutionSpace const &exec_space, Primitives const &primitives, #endif using Point = typename Points::value_type; - static_assert(GeometryTraits::is_point{}); + static_assert(GeometryTraits::is_point_v); constexpr int dim = GeometryTraits::dimension_v; using Box = ExperimentalHyperGeometry::Box; diff --git a/src/details/ArborX_AccessTraits.hpp b/src/details/ArborX_AccessTraits.hpp index 4edf5e113..79d66da1a 100644 --- a/src/details/ArborX_AccessTraits.hpp +++ b/src/details/ArborX_AccessTraits.hpp @@ -183,7 +183,7 @@ void check_valid_access_traits(PrimitivesTag, Primitives const &, Access, Primitives>>; if constexpr (CheckGetReturnType()) { - static_assert(GeometryTraits::is_point{} || GeometryTraits::is_box{}, + static_assert(GeometryTraits::is_point_v || GeometryTraits::is_box_v, "AccessTraits::get() return type " "must decay to a point or a box type"); } diff --git a/src/details/ArborX_DetailsCartesianGrid.hpp b/src/details/ArborX_DetailsCartesianGrid.hpp index a54a68638..1bc9beb74 100644 --- a/src/details/ArborX_DetailsCartesianGrid.hpp +++ b/src/details/ArborX_DetailsCartesianGrid.hpp @@ -56,7 +56,7 @@ struct CartesianGrid } template {}>> + GeometryTraits::is_point_v>> KOKKOS_FUNCTION size_t cellIndex(Point const &point) const { static_assert(GeometryTraits::dimension_v == DIM); diff --git a/src/details/ArborX_DetailsMortonCode.hpp b/src/details/ArborX_DetailsMortonCode.hpp index 98d0fcbe4..bd0e7a974 100644 --- a/src/details/ArborX_DetailsMortonCode.hpp +++ b/src/details/ArborX_DetailsMortonCode.hpp @@ -283,7 +283,7 @@ KOKKOS_INLINE_FUNCTION unsigned long long expandBitsBy<9>(unsigned long long x) } template {}>> + typename Enable = std::enable_if_t>> KOKKOS_INLINE_FUNCTION unsigned int morton32(Point const &p) { constexpr int DIM = GeometryTraits::dimension_v; @@ -303,7 +303,7 @@ KOKKOS_INLINE_FUNCTION unsigned int morton32(Point const &p) } template {} && + std::enable_if_t && GeometryTraits::dimension_v != 2> * = nullptr> KOKKOS_INLINE_FUNCTION unsigned long long morton64(Point const &p) { @@ -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 {} && + std::enable_if_t && GeometryTraits::dimension_v == 2> * = nullptr> KOKKOS_INLINE_FUNCTION unsigned long long morton64(Point const &p) { diff --git a/src/details/ArborX_IndexableGetter.hpp b/src/details/ArborX_IndexableGetter.hpp index 9202232be..2b81f62ea 100644 --- a/src/details/ArborX_IndexableGetter.hpp +++ b/src/details/ArborX_IndexableGetter.hpp @@ -25,8 +25,8 @@ struct DefaultIndexableGetter DefaultIndexableGetter() = default; template {} || - GeometryTraits::is_box{}>> + GeometryTraits::is_point_v || + GeometryTraits::is_box_v>> KOKKOS_FUNCTION auto const &operator()(Geometry const &geometry) const { return geometry; diff --git a/src/details/ArborX_MinimumSpanningTree.hpp b/src/details/ArborX_MinimumSpanningTree.hpp index d943b7081..d61731957 100644 --- a/src/details/ArborX_MinimumSpanningTree.hpp +++ b/src/details/ArborX_MinimumSpanningTree.hpp @@ -50,7 +50,7 @@ struct MinimumSpanningTree using Points = Details::AccessValues; using Point = typename Points::value_type; - static_assert(GeometryTraits::is_point{}); + static_assert(GeometryTraits::is_point_v); Points points{primitives}; // NOLINT diff --git a/src/details/ArborX_NeighborList.hpp b/src/details/ArborX_NeighborList.hpp index 1af3b7dca..1b561bcb3 100644 --- a/src/details/ArborX_NeighborList.hpp +++ b/src/details/ArborX_NeighborList.hpp @@ -31,7 +31,7 @@ struct NeighborListPredicateGetter template KOKKOS_FUNCTION auto operator()(Point point) const { - static_assert(GeometryTraits::is_point{}); + static_assert(GeometryTraits::is_point_v); constexpr int dim = GeometryTraits::dimension_v; using Coordinate = typename GeometryTraits::coordinate_type_t; @@ -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{}); + static_assert(GeometryTraits::is_point_v); Points points{primitives}; // NOLINT int const n = points.size(); @@ -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{}); + static_assert(GeometryTraits::is_point_v); Points points{primitives}; // NOLINT int const n = points.size(); diff --git a/src/details/ArborX_SpaceFillingCurves.hpp b/src/details/ArborX_SpaceFillingCurves.hpp index c9d7544b3..009cd461e 100644 --- a/src/details/ArborX_SpaceFillingCurves.hpp +++ b/src/details/ArborX_SpaceFillingCurves.hpp @@ -30,16 +30,16 @@ namespace Experimental struct Morton32 { template {} && - GeometryTraits::is_point{}> * = nullptr> + std::enable_if_t && + GeometryTraits::is_point_v> * = 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 {} && - !GeometryTraits::is_point{}> * = nullptr> + std::enable_if_t && + !GeometryTraits::is_point_v> * = nullptr> KOKKOS_FUNCTION auto operator()(Box const &scene_bounding_box, Geometry const &geometry) const { @@ -52,16 +52,16 @@ struct Morton32 struct Morton64 { template {} && - GeometryTraits::is_point{}> * = nullptr> + std::enable_if_t && + GeometryTraits::is_point_v> * = 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 {} && - !GeometryTraits::is_point{}> * = nullptr> + std::enable_if_t && + !GeometryTraits::is_point_v> * = nullptr> KOKKOS_FUNCTION auto operator()(Box const &scene_bounding_box, Geometry const &geometry) const { diff --git a/src/geometry/ArborX_DetailsAlgorithms.hpp b/src/geometry/ArborX_DetailsAlgorithms.hpp index 94c6e3f94..02c405483 100644 --- a/src/geometry/ArborX_DetailsAlgorithms.hpp +++ b/src/geometry/ArborX_DetailsAlgorithms.hpp @@ -512,8 +512,8 @@ struct centroid // transformation that maps the unit cube into a new axis-aligned box // NOTE safe to perform in-place template {} && - GeometryTraits::is_box{}> * = nullptr> + std::enable_if_t && + GeometryTraits::is_box_v> * = nullptr> KOKKOS_FUNCTION void translateAndScale(Point const &in, Point &out, Box const &ref) { diff --git a/src/geometry/ArborX_GeometryTraits.hpp b/src/geometry/ArborX_GeometryTraits.hpp index a342e74b3..80102b0f3 100644 --- a/src/geometry/ArborX_GeometryTraits.hpp +++ b/src/geometry/ArborX_GeometryTraits.hpp @@ -20,27 +20,11 @@ namespace ArborX namespace GeometryTraits { -struct PointTag -{}; - -struct BoxTag -{}; - -struct SphereTag -{}; - -struct TriangleTag -{}; - -struct KDOPTag -{}; - template struct dimension { using not_specialized = void; // tag to detect existence of a specialization }; - template inline constexpr int dimension_v = dimension::value; @@ -63,6 +47,28 @@ struct coordinate_type template using coordinate_type_t = typename coordinate_type::type; +// clang-format off +#define DEFINE_GEOMETRY(name, name_tag) \ + struct name_tag{}; \ + template \ + struct is_##name : std::is_same, name_tag>{}; \ + template \ + inline constexpr bool is_##name##_v = is_##name::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 +inline constexpr bool + is_valid_geometry = (is_point_v || is_box_v || + is_sphere_v || is_kdop_v || + is_triangle_v); + template using DimensionNotSpecializedArchetypeAlias = typename dimension::not_specialized; @@ -77,22 +83,6 @@ using CoordinateNotSpecializedArchetypeAlias = template using DimensionArchetypeAlias = decltype(dimension_v); -template -struct is_point : std::is_same::type, PointTag> -{}; - -template -struct is_box : std::is_same::type, BoxTag> -{}; - -template -struct is_sphere : std::is_same::type, SphereTag> -{}; - -template -struct is_triangle : std::is_same::type, TriangleTag> -{}; - template void check_valid_geometry_traits(Geometry const &) { @@ -117,11 +107,7 @@ void check_valid_geometry_traits(Geometry const &) static_assert(!std::is_same_v, not_specialized>, "GeometryTraits::tag must define 'type' member type"); - using Tag = typename tag::type; - static_assert(std::is_same{} || std::is_same{} || - std::is_same{} || - std::is_same{} || - std::is_same{}, + static_assert(is_valid_geometry, "GeometryTraits::tag::type must be PointTag, BoxTag, " "SphereTag, TriangleTag or KDOPTag"); diff --git a/src/geometry/ArborX_HyperBox.hpp b/src/geometry/ArborX_HyperBox.hpp index f6272b87b..5c8a800a1 100644 --- a/src/geometry/ArborX_HyperBox.hpp +++ b/src/geometry/ArborX_HyperBox.hpp @@ -80,7 +80,7 @@ struct Box } template {}> * = nullptr> + std::enable_if_t> * = nullptr> KOKKOS_FUNCTION auto &operator+=(Point const &point) { using Details::KokkosExt::max; diff --git a/src/interpolation/ArborX_InterpMovingLeastSquares.hpp b/src/interpolation/ArborX_InterpMovingLeastSquares.hpp index 4e944ae33..c11ffa9d2 100644 --- a/src/interpolation/ArborX_InterpMovingLeastSquares.hpp +++ b/src/interpolation/ArborX_InterpMovingLeastSquares.hpp @@ -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::value, + static_assert(GeometryTraits::is_point_v, "Source points elements must be points"); static constexpr int dimension = GeometryTraits::dimension_v; @@ -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::value, + static_assert(GeometryTraits::is_point_v, "Target points elements must be points"); static_assert(dimension == GeometryTraits::dimension_v, "Target and source points must have the same dimension"); diff --git a/src/interpolation/details/ArborX_InterpDetailsCompactRadialBasisFunction.hpp b/src/interpolation/details/ArborX_InterpDetailsCompactRadialBasisFunction.hpp index f5445b8fe..6e8690246 100644 --- a/src/interpolation/details/ArborX_InterpDetailsCompactRadialBasisFunction.hpp +++ b/src/interpolation/details/ArborX_InterpDetailsCompactRadialBasisFunction.hpp @@ -100,8 +100,7 @@ KOKKOS_INLINE_FUNCTION constexpr auto evaluate(Point const &point, typename GeometryTraits::coordinate_type_t const radius) { - static_assert(GeometryTraits::is_point::value, - "point must be a point"); + static_assert(GeometryTraits::is_point_v, "Point must be a point"); constexpr std::size_t dim = GeometryTraits::dimension_v; return CRBFunc::template evaluate( ArborX::Details::distance(point, Point{}) / radius); diff --git a/src/interpolation/details/ArborX_InterpDetailsPolynomialBasis.hpp b/src/interpolation/details/ArborX_InterpDetailsPolynomialBasis.hpp index 7ac31ee5d..fb1bf4107 100644 --- a/src/interpolation/details/ArborX_InterpDetailsPolynomialBasis.hpp +++ b/src/interpolation/details/ArborX_InterpDetailsPolynomialBasis.hpp @@ -104,8 +104,7 @@ KOKKOS_FUNCTION constexpr std::size_t polynomialBasisSize() template KOKKOS_FUNCTION auto evaluatePolynomialBasis(Point const &p) { - static_assert(GeometryTraits::is_point::value, - "point must be a point"); + static_assert(GeometryTraits::is_point_v, "Point must be a point"); static constexpr std::size_t DIM = GeometryTraits::dimension_v; using Value = typename GeometryTraits::coordinate_type_t; static_assert(DIM > 0, "Polynomial basis with no dimension is invalid");