Skip to content

Commit

Permalink
Migrated ArithmeticTraits
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed Dec 26, 2023
1 parent 3ea38fb commit 73a9e90
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/details/ArborX_DetailsMinimumSpanningTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DirectedEdge
{
public:
unsigned long long directed_edge = ULLONG_MAX;
float weight = KokkosBlah::ArithmeticTraits::infinity<float>::value;
float weight = KokkosExt::ArithmeticTraits::infinity<float>::value;

private:
static_assert(sizeof(unsigned long long) == 8);
Expand Down Expand Up @@ -170,7 +170,7 @@ struct FindComponentNearestNeighbors

KOKKOS_FUNCTION void operator()(int i) const
{
constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf = KokkosExt::ArithmeticTraits::infinity<float>::value;

auto const distance = [bounding_volume_i =
HappyTreeFriends::getIndexable(_bvh, i),
Expand Down
4 changes: 2 additions & 2 deletions src/details/ArborX_DetailsTreeConstruction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ class GenerateHierarchy
// number.

constexpr auto max_value =
KokkosBlah::ArithmeticTraits::finite_max<DeltaValueType>::value;
KokkosExt::ArithmeticTraits::finite_max<DeltaValueType>::value;
constexpr auto min_value =
KokkosBlah::ArithmeticTraits::finite_min<DeltaValueType>::value;
KokkosExt::ArithmeticTraits::finite_min<DeltaValueType>::value;

// This check is here simply to avoid code complications in the main
// operator
Expand Down
6 changes: 3 additions & 3 deletions src/details/ArborX_DetailsTreeTraversal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct TreeTraversal<BVH, Predicates, Callback, NearestPredicateTag>
// Nodes with a distance that exceed that radius can safely be
// discarded. Initialize the radius to infinity and tighten it once k
// neighbors have been found.
auto radius = KokkosBlah::ArithmeticTraits::infinity<float>::value;
auto radius = KokkosExt::ArithmeticTraits::infinity<float>::value;

using PairIndexDistance = Kokkos::pair<int, float>;
static_assert(
Expand Down Expand Up @@ -437,7 +437,7 @@ struct TreeTraversal<BVH, Predicates, Callback,
using distance_type =
decltype(distance(getGeometry(predicate), root_bounding_volume));
constexpr auto inf =
KokkosBlah::ArithmeticTraits::infinity<distance_type>::value;
KokkosExt::ArithmeticTraits::infinity<distance_type>::value;
if (distance(getGeometry(predicate), root_bounding_volume) != inf)
{
_callback(predicate, HappyTreeFriends::getValue(_bvh, 0));
Expand Down Expand Up @@ -473,7 +473,7 @@ struct TreeTraversal<BVH, Predicates, Callback,
heap(UnmanagedStaticVector<PairIndexDistance>(buffer, buffer_size));

constexpr auto inf =
KokkosBlah::ArithmeticTraits::infinity<distance_type>::value;
KokkosExt::ArithmeticTraits::infinity<distance_type>::value;

auto &bvh = _bvh;
auto const distance = [&predicate, &bvh](int j) {
Expand Down
4 changes: 3 additions & 1 deletion src/details/ArborX_MinimumSpanningTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ struct MinimumSpanningTree
void doBoruvka(ExecutionSpace const &space, BVH const &bvh,
Metric const &metric)
{
namespace KokkosExt = ArborX::Details::KokkosExt;

auto const n = bvh.size();
Kokkos::View<int *, MemorySpace> tree_parents(
Kokkos::view_alloc(space, Kokkos::WithoutInitializing,
Expand Down Expand Up @@ -186,7 +188,7 @@ struct MinimumSpanningTree
// Propagate leaf node labels to internal nodes
reduceLabels(space, tree_parents, labels);

constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
constexpr DirectedEdge uninitialized_edge;
Kokkos::deep_copy(space, component_out_edges, uninitialized_edge);
Kokkos::deep_copy(space, weights, inf);
Expand Down
12 changes: 6 additions & 6 deletions src/geometry/ArborX_Box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ struct Box
constexpr Point const &maxCorner() const { return _max_corner; }

Point _min_corner = {
{KokkosBlah::ArithmeticTraits::finite_max<float>::value,
KokkosBlah::ArithmeticTraits::finite_max<float>::value,
KokkosBlah::ArithmeticTraits::finite_max<float>::value}};
{Details::KokkosExt::ArithmeticTraits::finite_max<float>::value,
Details::KokkosExt::ArithmeticTraits::finite_max<float>::value,
Details::KokkosExt::ArithmeticTraits::finite_max<float>::value}};
Point _max_corner = {
{KokkosBlah::ArithmeticTraits::finite_min<float>::value,
KokkosBlah::ArithmeticTraits::finite_min<float>::value,
KokkosBlah::ArithmeticTraits::finite_min<float>::value}};
{Details::KokkosExt::ArithmeticTraits::finite_min<float>::value,
Details::KokkosExt::ArithmeticTraits::finite_min<float>::value,
Details::KokkosExt::ArithmeticTraits::finite_min<float>::value}};

KOKKOS_FUNCTION Box &operator+=(Box const &other)
{
Expand Down
4 changes: 2 additions & 2 deletions src/geometry/ArborX_HyperBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ struct Box
for (int d = 0; d < DIM; ++d)
{
_min_corner[d] =
KokkosBlah::ArithmeticTraits::finite_max<Coordinate>::value;
Details::KokkosExt::ArithmeticTraits::finite_max<Coordinate>::value;
_max_corner[d] =
KokkosBlah::ArithmeticTraits::finite_min<Coordinate>::value;
Details::KokkosExt::ArithmeticTraits::finite_min<Coordinate>::value;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/geometry/ArborX_KDOP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ struct KDOP : private Details::KDOP_Directions<k>
{
for (int i = 0; i < n_directions; ++i)
{
_min_values[i] = KokkosBlah::ArithmeticTraits::finite_max<float>::value;
_max_values[i] = KokkosBlah::ArithmeticTraits::finite_min<float>::value;
_min_values[i] =
Details::KokkosExt::ArithmeticTraits::finite_max<float>::value;
_max_values[i] =
Details::KokkosExt::ArithmeticTraits::finite_min<float>::value;
}
}
KOKKOS_FUNCTION KDOP &operator+=(Point const &p)
Expand Down
17 changes: 11 additions & 6 deletions src/geometry/ArborX_Ray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ bool intersection(Ray const &ray, Box const &box, float &tmin, float &tmax)
auto const &orig = ray.origin();
auto const &dir = ray.direction();

constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf =
Details::KokkosExt::ArithmeticTraits::infinity<float>::value;
tmin = -inf;
tmax = inf;

Expand Down Expand Up @@ -362,7 +363,8 @@ bool intersection(Ray const &ray,
w = (double)B[0] * A[1] - (double)B[1] * A[0];
}

constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf =
Details::KokkosExt::ArithmeticTraits::infinity<float>::value;
tmin = inf;
tmax = -inf;

Expand Down Expand Up @@ -471,8 +473,9 @@ float distance(Ray const &ray, Box const &box)
float tmin;
float tmax;
bool intersects = intersection(ray, box, tmin, tmax) && (tmax >= 0.f);
return intersects ? (tmin > 0.f ? tmin : 0.f)
: KokkosBlah::ArithmeticTraits::infinity<float>::value;
return intersects
? (tmin > 0.f ? tmin : 0.f)
: Details::KokkosExt::ArithmeticTraits::infinity<float>::value;
}

// Solves a*x^2 + b*x + c = 0.
Expand Down Expand Up @@ -542,7 +545,8 @@ KOKKOS_INLINE_FUNCTION bool intersection(Ray const &ray, Sphere const &sphere,

return true;
}
constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf =
Details::KokkosExt::ArithmeticTraits::infinity<float>::value;
tmin = inf;
tmax = -inf;
return false;
Expand All @@ -567,7 +571,8 @@ overlapDistance(Ray const &ray, Geometry const &geometry, float &length,
else
{
length = 0;
distance_to_origin = KokkosBlah::ArithmeticTraits::infinity<float>::value;
distance_to_origin =
Details::KokkosExt::ArithmeticTraits::infinity<float>::value;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/kokkos_ext/ArborX_DetailsKokkosExtArithmeticTraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <Kokkos_NumericTraits.hpp>

namespace KokkosBlah::ArithmeticTraits
namespace ArborX::Details::KokkosExt::ArithmeticTraits
{

template <class T>
Expand All @@ -29,6 +29,6 @@ using finite_min = Kokkos::Experimental::finite_min<T>;
template <class T>
using epsilon = Kokkos::Experimental::epsilon<T>;

} // namespace KokkosBlah::ArithmeticTraits
} // namespace ArborX::Details::KokkosExt::ArithmeticTraits

#endif
4 changes: 2 additions & 2 deletions test/tstCompileOnlyWeightedEdges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace

KOKKOS_FUNCTION constexpr bool test_directed_edges()
{
using ArborX::Details::DirectedEdge;
using namespace ArborX::Details;

static_assert(DirectedEdge{0, 1, 2.f}.weight == 2.f);
static_assert(DirectedEdge{0, 1, 2.f}.source() == 0);
Expand All @@ -26,7 +26,7 @@ KOKKOS_FUNCTION constexpr bool test_directed_edges()
static_assert(DirectedEdge{6, 5, 4.f}.source() == 6);
static_assert(DirectedEdge{6, 5, 4.f}.target() == 5);

constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
static_assert(DirectedEdge{}.weight == inf);
static_assert(DirectedEdge{}.source() == INT_MAX);
static_assert(DirectedEdge{}.target() == INT_MAX);
Expand Down
7 changes: 5 additions & 2 deletions test/tstDetailsAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ BOOST_AUTO_TEST_CASE(distance)
BOOST_AUTO_TEST_CASE(distance_box_box)
{
using ArborX::Details::distance;
namespace KokkosExt = ArborX::Details::KokkosExt;

constexpr Box unit_box{{{0.0, 0.0, 0.0}}, {{1.0, 1.0, 1.0}}};

Expand All @@ -81,7 +82,7 @@ BOOST_AUTO_TEST_CASE(distance_box_box)
BOOST_TEST(distance(unit_box, Box{{{.1, .2, .3}}, {{4, 5, 6}}}) == 0);

// distance to empty boxes
auto infinity = KokkosBlah::ArithmeticTraits::infinity<float>::value;
auto infinity = KokkosExt::ArithmeticTraits::infinity<float>::value;
BOOST_TEST(distance(unit_box, Box{}) == infinity);
BOOST_TEST(distance(Box{}, unit_box) == infinity);
BOOST_TEST(distance(Box{}, Box{}) == infinity);
Expand All @@ -90,7 +91,9 @@ BOOST_AUTO_TEST_CASE(distance_box_box)
BOOST_AUTO_TEST_CASE(distance_sphere_box)
{
using ArborX::Details::distance;
auto infinity = KokkosBlah::ArithmeticTraits::infinity<float>::value;
namespace KokkosExt = ArborX::Details::KokkosExt;

auto infinity = KokkosExt::ArithmeticTraits::infinity<float>::value;

// unit sphere
constexpr Sphere sphere{{{0., 0., 0.}}, 1.};
Expand Down
3 changes: 2 additions & 1 deletion test/tstDetailsMutualReachabilityDistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ auto compute_core_distances(ExecutionSpace exec_space,
Kokkos::View<float *, MemorySpace> distances(
Kokkos::view_alloc(Kokkos::WithoutInitializing, "Test::core_distances"),
bvh.size());
constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf =
ArborX::Details::KokkosExt::ArithmeticTraits::infinity<float>::value;
Kokkos::deep_copy(exec_space, distances, -inf);
bvh.query(exec_space, ArborX::Details::NearestK<decltype(points)>{points, k},
ArborX::Details::MaxDistance<decltype(points), decltype(distances)>{
Expand Down
3 changes: 2 additions & 1 deletion test/tstNeighborList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(find_neighbor_list_degenerate, DeviceType,
auto single_point = ArborXTest::toView<ExecutionSpace>(
std::vector<ArborX::Point>{{0.f, 0.f, 0.f}}, "Test::single_point");

constexpr auto radius = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto radius =
ArborX::Details::KokkosExt::ArithmeticTraits::infinity<float>::value;

ARBORX_TEST_NEIGHBOR_LIST(exec_space, no_point, radius, (std::vector<int>{0}),
(std::vector<int>{}));
Expand Down
20 changes: 12 additions & 8 deletions test/tstRay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ BOOST_AUTO_TEST_CASE(ray_box_intersection, *boost::unit_test::tolerance(1e-6f))
using ArborX::Box;
using ArborX::Experimental::Ray;

namespace KokkosExt = ArborX::Details::KokkosExt;
#ifdef _MSC_VER
auto const inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
auto const inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
#else
constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
#endif

constexpr Box unit_box{{0, 0, 0}, {1, 1, 1}};
Expand Down Expand Up @@ -259,10 +260,11 @@ BOOST_AUTO_TEST_CASE(ray_box_distance)
// must have a constant value)
constexpr Box unit_box{{0, 0, 0}, {1, 1, 1}};

namespace KokkosExt = ArborX::Details::KokkosExt;
#ifdef _MSC_VER
auto const inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
auto const inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
#else
constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
#endif

// clang-format off
Expand Down Expand Up @@ -372,10 +374,11 @@ BOOST_AUTO_TEST_CASE(ray_sphere_intersection,
auto const sqrtf_3 = std::sqrt(3.f);
auto const sqrtf_2 = std::sqrt(2.f);

namespace KokkosExt = ArborX::Details::KokkosExt;
#ifdef _MSC_VER
auto const inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
auto const inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
#else
constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
#endif

// clang-format off
Expand Down Expand Up @@ -497,10 +500,11 @@ BOOST_AUTO_TEST_CASE(ray_triangle_intersection,
using ArborX::ExperimentalHyperGeometry::Point;
using ArborX::ExperimentalHyperGeometry::Triangle;

namespace KokkosExt = ArborX::Details::KokkosExt;
#ifdef _MSC_VER
auto const inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
auto const inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
#else
constexpr auto inf = KokkosBlah::ArithmeticTraits::infinity<float>::value;
constexpr auto inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
#endif

constexpr Triangle unit_triangle{Point{0, 0, 0}, Point{1, 0, 0},
Expand Down

0 comments on commit 73a9e90

Please sign in to comment.