Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add geometry_generator factory for programmatic generation of geometry arrays #998

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
965b80a
initial
isVoid Feb 28, 2023
38af8e6
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 1, 2023
02f61fe
add pragma once for floating_point.cuh
isVoid Mar 7, 2023
7bd797f
add polygon_ref structure
isVoid Mar 7, 2023
0968c15
add multipolygon_ref class
isVoid Mar 7, 2023
a659eab
update multipolygon_range class
isVoid Mar 7, 2023
c274070
update multipoint_range class
isVoid Mar 7, 2023
12ffa53
update is_point_in_polygon usage with polygon_ref
isVoid Mar 7, 2023
7490333
update multilinestring_range
isVoid Mar 7, 2023
f665287
add point to polygon kernel
isVoid Mar 7, 2023
291f6e6
add segment deduction guide
isVoid Mar 7, 2023
efa6883
add owning object type to vector factories
isVoid Mar 7, 2023
23146ef
add tests
isVoid Mar 7, 2023
ead160a
add helper files
isVoid Mar 7, 2023
09bd35f
add more tests
isVoid Mar 8, 2023
92760d1
bug fixes
isVoid Mar 8, 2023
8acb5dc
cleanups
isVoid Mar 8, 2023
a2b94fe
fix tests
isVoid Mar 8, 2023
46a67fe
optimize single point range input
isVoid Mar 8, 2023
b725b52
docs, type checks in range ctor
isVoid Mar 8, 2023
cb5706a
Merge branch 'branch-23.04' into feature/polygon_distances
isVoid Mar 8, 2023
ab59e7d
use range based for loop in is_point_in_polygon
isVoid Mar 8, 2023
b136c0b
Apply suggestions from code review
isVoid Mar 9, 2023
744f32f
add docs
isVoid Mar 9, 2023
bb6c637
style
isVoid Mar 9, 2023
756650b
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 9, 2023
8319e7c
fix bug in PiP tests
isVoid Mar 10, 2023
86d36d9
updates with test docs and API docs, address review
isVoid Mar 14, 2023
7bf8cbf
update offsets_to_keys
isVoid Mar 14, 2023
ff48dc7
update floating_point docs
isVoid Mar 14, 2023
b4420a7
use any_of
isVoid Mar 14, 2023
44e2843
add large (multigrid) tests, address reviews
isVoid Mar 14, 2023
57e6196
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 15, 2023
49972d4
add upper_bound_index.cuh
isVoid Mar 15, 2023
f000e00
remove upper_bound_index
isVoid Mar 15, 2023
57504e6
update geometry id factory
isVoid Mar 15, 2023
4865922
add get gtest scripts in cmake
isVoid Mar 15, 2023
ab52bc2
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 16, 2023
eff0e43
add generators and generator tests
isVoid Mar 17, 2023
6d14d69
add parameterized test fixture
isVoid Mar 17, 2023
5f347fd
adopt single kernel launch device multipolygon generation
isVoid Mar 18, 2023
bd78dfd
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Mar 18, 2023
293ee0f
documentation
isVoid Mar 20, 2023
00a6728
document function
isVoid Mar 20, 2023
d910a7c
enable value parameterized test
isVoid Mar 20, 2023
bd6a4eb
revert distance benchmark
isVoid Mar 20, 2023
9e74468
mixin doc
isVoid Mar 20, 2023
5c67a80
address review comments
isVoid Mar 21, 2023
af4c8a6
remove crtp
isVoid Mar 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

#pragma once

#include <thrust/binary_search.h>
#include <thrust/distance.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/pair.h>

#include <cuspatial/cuda_utils.hpp>
#include <cuspatial/detail/iterator.hpp>
#include <cuspatial/experimental/geometry/segment.cuh>
#include <cuspatial/experimental/geometry_collection/multipolygon_ref.cuh>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

#include <thrust/binary_search.h>
#include <thrust/distance.h>
#include <thrust/iterator/transform_iterator.h>
#include <thrust/pair.h>

#include <iterator>
#include <optional>

Expand Down Expand Up @@ -170,6 +170,26 @@ multipolygon_range<GeometryIterator, PartIterator, RingIterator, VecIterator>::m
return multipolygon_begin() + num_multipolygons();
}

template <typename GeometryIterator,
typename PartIterator,
typename RingIterator,
typename VecIterator>
CUSPATIAL_HOST_DEVICE auto
multipolygon_range<GeometryIterator, PartIterator, RingIterator, VecIterator>::point_begin()
{
return _point_begin;
}

template <typename GeometryIterator,
typename PartIterator,
typename RingIterator,
typename VecIterator>
CUSPATIAL_HOST_DEVICE auto
multipolygon_range<GeometryIterator, PartIterator, RingIterator, VecIterator>::point_end()
{
return _point_end;
}

template <typename GeometryIterator,
typename PartIterator,
typename RingIterator,
Expand Down
34 changes: 19 additions & 15 deletions cpp/include/cuspatial/experimental/ranges/multipolygon_range.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,32 @@ class multipolygon_range {
/// Return the iterator to the one past the last multipolygon in the range.
CUSPATIAL_HOST_DEVICE auto end() { return multipolygon_end(); }

/// Return the iterator to the first point in the range.
CUSPATIAL_HOST_DEVICE auto point_begin();

/// Return the iterator to the one past the last point in the range.
CUSPATIAL_HOST_DEVICE auto point_end();

/// Given the index of a segment, return the index of the geometry (multipolygon) that contains
/// the segment. Segment index is the index to the starting point of the segment. If the index is
/// the last point of the ring, then it is not a valid index. This function returns
/// multipolygon_range::INVALID_INDEX if the index is invalid.
template <typename IndexType>
CUSPATIAL_HOST_DEVICE auto geometry_idx_from_segment_idx(IndexType segment_idx);

/// Given the index of a point, return the index of the ring that contains the point.
template <typename IndexType>
CUSPATIAL_HOST_DEVICE auto ring_idx_from_point_idx(IndexType point_idx);

/// Given the index of a ring, return the index of the part (polygon) that contains the point.
template <typename IndexType>
CUSPATIAL_HOST_DEVICE auto part_idx_from_ring_idx(IndexType ring_idx);

/// Given the index of a part (polygon), return the index of the geometry (multipolygon) that
/// contains the part.
template <typename IndexType>
CUSPATIAL_HOST_DEVICE auto geometry_idx_from_part_idx(IndexType part_idx);

/// Returns the `multipolygon_idx`th multipolygon in the range.
template <typename IndexType>
CUSPATIAL_HOST_DEVICE auto operator[](IndexType multipolygon_idx);
Expand All @@ -133,21 +152,6 @@ class multipolygon_range {
VecIterator _point_end;

private:
/// Given the index of a point, return the ring index
/// where the point locates.
template <typename IndexType>
CUSPATIAL_HOST_DEVICE auto ring_idx_from_point_idx(IndexType point_idx);

/// Given the index of a ring, return the part (polygon) index
/// where the ring locates.
template <typename IndexType>
CUSPATIAL_HOST_DEVICE auto part_idx_from_ring_idx(IndexType ring_idx);

/// Given the index of a part (polygon), return the geometry (multipolygon) index
/// where the polygon locates.
template <typename IndexType>
CUSPATIAL_HOST_DEVICE auto geometry_idx_from_part_idx(IndexType part_idx);

template <typename IndexType1, typename IndexType2>
CUSPATIAL_HOST_DEVICE bool is_valid_segment_id(IndexType1 segment_idx, IndexType2 ring_idx);
};
Expand Down
57 changes: 49 additions & 8 deletions cpp/include/cuspatial_test/base_fixture.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, NVIDIA CORPORATION.
* Copyright (c) 2022-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include <rmm/cuda_stream_view.hpp>
#include <rmm/mr/device/per_device_resource.hpp>

#include <gtest/gtest.h>
Expand All @@ -22,15 +23,11 @@ namespace cuspatial {
namespace test {

/**
* @brief Base test fixture class from which all libcuspatial tests should inherit.
*
* Example:
* ```
* class MyTestFixture : public cuspatial::test::BaseFixture {};
* ```
* @brief Mixin to supply rmm resources for fixtures
*/
class BaseFixture : public ::testing::Test {
class RMMResourceMixin {
rmm::mr::device_memory_resource* _mr{rmm::mr::get_current_device_resource()};
rmm::cuda_stream_view _stream{rmm::cuda_stream_default};

public:
/**
Expand All @@ -39,6 +36,50 @@ class BaseFixture : public ::testing::Test {
* @return pointer to memory resource
*/
rmm::mr::device_memory_resource* mr() { return _mr; }

/**
* @brief Returns `cuda_stream_view` that should be used for computation in
* tests inheriting from this fixture.
* @return view to cuda stream
*/
rmm::cuda_stream_view stream() { return _stream; }
};

/**
* @brief Base test fixture class from which libcuspatial test with no parameterization or only with
* type parameterization should inherit.
*
* Example:
* ```
* class MyTestFixture : public cuspatial::test::BaseFixture {};
* ```
*/
class BaseFixture : public RMMResourceMixin, public ::testing::Test {
};

/**
* @brief Base test fixture class from which libcuspatial test with only value parameterization
* should inherit.
*
* Example:
* ```
* template<int, int, int>
* class MyTest : public cuspatial::test::BaseFixtureWithParam {};
*
* TEST_P(MyTest, TestParamterGet) {
* auto [a, b, c] = GetParam();
* ...
* }
*
* INSTANTIATE_TEST_SUITE_P(MyTests, MyTest, ::testing::Values(
* std::make_tuple(1, 2, 3),
* std::make_tuple(4, 5, 6, 9),
* std::make_tuple(7, 8)))
* ```
*/
template <typename... Ts>
class BaseFixtureWithParam : public RMMResourceMixin,
public ::testing::TestWithParam<std::tuple<Ts...>> {
};

} // namespace test
Expand Down
Loading