Skip to content

Commit

Permalink
Fix JOIN_POINT_IN_POLYGON_LARGE_TEST_EXP test (#1346)
Browse files Browse the repository at this point in the history
The `JOIN_POINT_IN_POLYGON_LARGE_TEST_EXP` test isn't returning any points because they aren't evenly distributed.

The first commit adds a check to ensure the test fails when no results are returned. The second commit fixes the `JOIN_POINT_IN_POLYGON_LARGE_TEST_EXP` test.

Fixes #1380.

Authors:
  - Paul Taylor (https://github.com/trxcllnt)

Approvers:
  - Mark Harris (https://github.com/harrism)

URL: #1346
  • Loading branch information
trxcllnt authored May 6, 2024
1 parent 83e332c commit 0324a33
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions cpp/tests/join/quadtree_point_in_polygon_test_large.cu
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,18 @@ template <typename T>
inline auto generate_points(
std::vector<std::vector<T>> const& quads,
uint32_t points_per_quad,
cuspatial::vec_2d<T> v_min,
cuspatial::vec_2d<T> v_max,
std::size_t seed,
rmm::cuda_stream_view stream,
rmm::device_async_resource_ref mr = rmm::mr::get_current_device_resource())
{
auto engine = cuspatial::test::deterministic_engine(0);
auto uniform = cuspatial::test::make_normal_dist<T>(0.0, 1.0);
auto pgen = cuspatial::test::point_generator(cuspatial::vec_2d<T>{0.0, 0.0},
cuspatial::vec_2d<T>{1.0, 1.0},
engine,
engine,
uniform,
uniform);
auto engine_x = cuspatial::test::deterministic_engine(42);
auto engine_y = cuspatial::test::deterministic_engine(137);
auto uniform_x = cuspatial::test::make_normal_dist<T>(v_min.x, v_max.x);
auto uniform_y = cuspatial::test::make_normal_dist<T>(v_min.y, v_max.y);
auto pgen =
cuspatial::test::point_generator(v_min, v_max, engine_x, engine_y, uniform_x, uniform_y);
auto num_points = quads.size() * points_per_quad;
rmm::device_uvector<cuspatial::vec_2d<T>> points(num_points, stream, mr);

Expand Down Expand Up @@ -97,12 +97,12 @@ TYPED_TEST(PIPRefineTestLarge, TestLarge)
{7, 8, 3, 4},
{0, 4, 4, 8}};

auto points_in = generate_points<T>(quads, min_size, 0, this->stream());
auto points_in = generate_points<T>(quads, min_size, v_min, v_max, 0, this->stream());

auto [point_indices, quadtree] = quadtree_on_points(
auto [point_indices, quadtree] = cuspatial::quadtree_on_points(
points_in.begin(), points_in.end(), v_min, v_max, scale, max_depth, min_size, this->stream());

auto points = rmm::device_uvector<vec_2d<T>>(quads.size() * min_size, this->stream());
auto points = rmm::device_uvector<vec_2d<T>>(point_indices.size(), this->stream());
thrust::gather(rmm::exec_policy(this->stream()),
point_indices.begin(),
point_indices.end(),
Expand Down Expand Up @@ -160,10 +160,13 @@ TYPED_TEST(PIPRefineTestLarge, TestLarge)
quadtree,
point_indices.begin(),
point_indices.end(),
points.begin(),
points_in.begin(),
multipolygons,
this->stream());

EXPECT_GT(actual_point_indices.size(), 0);
EXPECT_GT(actual_poly_indices.size(), 0);

thrust::stable_sort_by_key(rmm::exec_policy(this->stream()),
actual_point_indices.begin(),
actual_point_indices.end(),
Expand All @@ -172,17 +175,17 @@ TYPED_TEST(PIPRefineTestLarge, TestLarge)
{ // verify
rmm::device_uvector<int32_t> hits(points.size(), this->stream());

auto points_range = make_multipoint_range(
auto points_range = cuspatial::make_multipoint_range(
points.size(), thrust::make_counting_iterator(0), points.size(), points.begin());

auto polygons_range = make_multipolygon_range(multipolygons.size(),
thrust::make_counting_iterator(0),
multipolygons.size(),
multipolygons.part_offset_begin(),
multipolygons.num_rings(),
multipolygons.ring_offset_begin(),
multipolygons.num_points(),
multipolygons.point_begin());
auto polygons_range = cuspatial::make_multipolygon_range(multipolygons.size(),
thrust::make_counting_iterator(0),
multipolygons.size(),
multipolygons.part_offset_begin(),
multipolygons.num_rings(),
multipolygons.ring_offset_begin(),
multipolygons.num_points(),
multipolygons.point_begin());

auto hits_end =
cuspatial::point_in_polygon(points_range, polygons_range, hits.begin(), this->stream());
Expand All @@ -209,6 +212,9 @@ TYPED_TEST(PIPRefineTestLarge, TestLarge)
auto d_expected_poly_indices = rmm::device_vector<std::uint32_t>(expected_poly_indices);
auto d_expected_point_indices = rmm::device_vector<std::uint32_t>(expected_point_indices);

EXPECT_GT(d_expected_poly_indices.size(), 0);
EXPECT_GT(d_expected_point_indices.size(), 0);

thrust::stable_sort_by_key(rmm::exec_policy(this->stream()),
d_expected_point_indices.begin(),
d_expected_point_indices.end(),
Expand Down

0 comments on commit 0324a33

Please sign in to comment.