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

Python API for pairwise_polygon_distance #1074

Merged
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0792c4e
initial
isVoid Apr 10, 2023
1f7c674
add range cast methods
isVoid Apr 10, 2023
c92656c
passing range cast tests
isVoid Apr 10, 2023
7092c3b
passing one-pair, no-hole simple polygon tests
isVoid Apr 11, 2023
211dca8
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid Apr 11, 2023
b74d180
add polygon test
isVoid Apr 11, 2023
0b77e38
adds single pair test that has holes in polygons
isVoid Apr 11, 2023
002ffa0
fix with_param fixture doc, add multipolygon test
isVoid Apr 11, 2023
137a567
add two pair tests
isVoid Apr 11, 2023
b77285c
style
isVoid Apr 11, 2023
9224c4a
address review comments
isVoid Apr 11, 2023
cc66aeb
add column API and tests, create host-device expect function
isVoid Apr 13, 2023
b77718b
initial addition of python test and API
isVoid Apr 13, 2023
a35ff22
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid Apr 26, 2023
6b89da3
remove experimental headers
isVoid Apr 26, 2023
a349d71
remove data tests
isVoid Apr 26, 2023
2e5a3ac
add docs
isVoid Apr 26, 2023
2c75052
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid May 1, 2023
674b4ea
Merge branch 'feature/polygon_distance_column' into feature/polygon_d…
isVoid May 2, 2023
fd6072e
use new .column() method
isVoid May 2, 2023
de8260f
Merge branch 'branch-23.06' of https://github.com/rapidsai/cuspatial …
isVoid May 2, 2023
e70aa25
address review comments
isVoid May 2, 2023
45cf81c
add missing license header to multiple test files
isVoid May 2, 2023
1932b9f
address review comments
isVoid May 3, 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
Prev Previous commit
Next Next commit
passing range cast tests
isVoid committed Apr 10, 2023
commit c92656c0910b789028a0eb8a7c53dec53029dff4
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@
#include <cuspatial/detail/utility/device_atomics.cuh>
#include <cuspatial/detail/utility/linestring.cuh>

#include <rmm/device_uvector.hpp>

#include <thrust/optional.h>

namespace cuspatial {
@@ -33,14 +35,14 @@ namespace detail {
* which is then combined with other segment results via an atomic operation to form the global
* minimum distance between the linestrings.
*
* `intersects` is an optional pointer to a boolean range where the `i`th element indicates the `i`th
* output should be set to 0 and bypass distance computation. This argument is optional, if set to nullopt,
* no distance computation will be bypassed.
* `intersects` is an optional pointer to a boolean range where the `i`th element indicates the
* `i`th output should be set to 0 and bypass distance computation. This argument is optional, if
* set to nullopt, no distance computation will be bypassed.
*/
template <class MultiLinestringRange1, class MultiLinestringRange2, class IntersectRange, class OutputIt>
template <class MultiLinestringRange1, class MultiLinestringRange2, class OutputIt>
__global__ void linestring_distance(MultiLinestringRange1 multilinestrings1,
MultiLinestringRange2 multilinestrings2,
thrust::optional<IntersectRange> intersects,
thrust::optional<uint8_t*> intersects,
OutputIt distances_first)
{
using T = typename MultiLinestringRange1::element_t;
@@ -51,14 +53,13 @@ __global__ void linestring_distance(MultiLinestringRange1 multilinestrings1,
if (!multilinestrings1.is_valid_segment_id(idx, part_idx)) continue;
auto const geometry_idx = multilinestrings1.geometry_idx_from_part_idx(part_idx);

if (intersects.has_value() && intersects.value()[geometry_idx])
{
distances_first[geometry_idx] = 0;
continue;
if (intersects.has_value() && intersects.value()[geometry_idx]) {
distances_first[geometry_idx] = 0;
continue;
}

auto [a, b] = multilinestrings1.segment(idx);
T min_distance_squared = std::numeric_limits<T>::max();
auto [a, b] = multilinestrings1.segment(idx);
T min_distance_squared = std::numeric_limits<T>::max();

for (auto const& linestring2 : multilinestrings2[geometry_idx]) {
for (auto [c, d] : linestring2) {
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
#include <cuspatial/experimental/detail/functors.cuh>
#include <cuspatial/experimental/geometry/segment.cuh>
#include <cuspatial/experimental/geometry_collection/multipolygon_ref.cuh>
#include <cuspatial/experimental/ranges/multilinestring_range.cuh>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

23 changes: 19 additions & 4 deletions cpp/include/cuspatial_test/vector_equality.hpp
Original file line number Diff line number Diff line change
@@ -197,7 +197,6 @@ inline void expect_vector_equivalent(Vector1 const& lhs, Vector2 const& rhs, U a
}
}


#define CUSPATIAL_EXPECT_VECTORS_EQUIVALENT(lhs, rhs, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
@@ -240,7 +239,7 @@ void expect_vec_2d_pair_equivalent(PairVector1 const& expected, PairVector2 cons
} while (0)

template <typename Array1, typename Array2>
void expect_multilinestring_array_equivalent(Array1 &lhs, Array2 &rhs)
void expect_multilinestring_array_equivalent(Array1& lhs, Array2& rhs)
{
auto [lhs_geometry_offset, lhs_part_offset, lhs_coordinates] = lhs.release();
auto [rhs_geometry_offset, rhs_part_offset, rhs_coordinates] = rhs.release();
@@ -251,11 +250,27 @@ void expect_multilinestring_array_equivalent(Array1 &lhs, Array2 &rhs)
}

#define CUSPATIAL_EXPECT_MULTILINESTRING_ARRAY_EQUIVALENT(lhs, rhs) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cuspatial::test::expect_multilinestring_array_equivalent(lhs, rhs); \
} while (0)

template <typename Array1, typename Array2>
void expect_multipoint_array_equivalent(Array1& lhs, Array2& rhs)
{
auto [lhs_geometry_offset, lhs_coordinates] = lhs.release();
auto [rhs_geometry_offset, rhs_coordinates] = rhs.release();

CUSPATIAL_EXPECT_VECTORS_EQUIVALENT(lhs_geometry_offset, rhs_geometry_offset);
CUSPATIAL_EXPECT_VECTORS_EQUIVALENT(lhs_coordinates, rhs_coordinates);
}

#define CUSPATIAL_EXPECT_MULTIPOINT_ARRAY_EQUIVALENT(lhs, rhs) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
cuspatial::test::expect_multipoint_array_equivalent(lhs, rhs); \
} while (0)

#define CUSPATIAL_RUN_TEST(FUNC, ...) \
do { \
SCOPED_TRACE(" <-- line of failure\n"); \
17 changes: 9 additions & 8 deletions cpp/include/cuspatial_test/vector_factories.cuh
Original file line number Diff line number Diff line change
@@ -250,16 +250,18 @@ class multilinestring_array {
/**
* @brief Construct an owning object of a multilinestring array from ranges
*
* @tparam T Type of coordinate
* @param geometry_inl Range of geometry offsets
* @param part_inl Range of part offsets
* @param coord_inl Ramge of coordinate
* @return multilinestring array object
*/
template <typename IndexRange,
template <typename IndexRangeA,
typename IndexRangeB,
typename CoordRange,
typename IndexType = typename IndexRange::value_type>
auto make_multilinestring_array(IndexRange geometry_inl, IndexRange part_inl, CoordRange coord_inl)
typename IndexType = typename IndexRangeB::value_type>
auto make_multilinestring_array(IndexRangeA geometry_inl,
IndexRangeB part_inl,
CoordRange coord_inl)
{
using CoordType = typename CoordRange::value_type;
using DeviceIndexVector = thrust::device_vector<IndexType>;
@@ -323,16 +325,15 @@ class multipoint_array {
};

/**
* @brief Factory method to construct multipoint array from ranges of geometry offsets and coordintes
*
* @brief Factory method to construct multipoint array from ranges of geometry offsets and
* coordinates
*/
template<typename GeometryRange, typename CoordRange>
template <typename GeometryRange, typename CoordRange>
auto make_multipoints_array(GeometryRange geometry_inl, CoordRange coordinates_inl)
{
return multipoint_array{make_device_vector(geometry_inl), make_device_vector(coordinates_inl)};
}


/**
* @brief Factory method to construct multipoint array from initializer list of multipoints.
*
121 changes: 104 additions & 17 deletions cpp/tests/experimental/range/multipolygon_range_test.cu
Original file line number Diff line number Diff line change
@@ -115,9 +115,10 @@ struct MultipolygonRangeTest : public BaseFixture {
multipolygon_coordinates);
auto rng = multipolygon_array.range().as_multilinestring_range();

auto got = make_multilinestring_array(range(rng.geometry_begin(), rng.geometry_end()),
range(rng.parts_begin(), rng.parts_end()),
range(rng.coordinates_begin(), rng.coordinates_end()));
auto got =
make_multilinestring_array(range(rng.geometry_offsets_begin(), rng.geometry_offsets_end()),
range(rng.part_offsets_begin(), rng.part_offsets_end()),
range(rng.point_begin(), rng.point_end()));

auto expected = make_multilinestring_array(
multilinestring_geometry_offset, multilinestring_part_offset, multilinestring_coordinates);
@@ -139,14 +140,14 @@ struct MultipolygonRangeTest : public BaseFixture {
multipolygon_coordinates);
auto rng = multipolygon_array.range().as_multipoint_range();

auto got = make_multipoint_range(range(rng.geometry_begin(), rng.geometry_end()),
range(rng.coordinates_begin(), rng.coordinates_end()));
auto got = make_multipoints_array(range(rng.offsets_begin(), rng.offsets_end()),
range(rng.point_begin(), rng.point_end()));

auto expected = make_multipoint_range(
auto expected = make_multipoints_array(
range(multipoint_geometry_offset.begin(), multipoint_geometry_offset.end()),
range(multipoint_coordinates.begin(), multipoint_coordinates.end()));

CUSPATIAL_EXPECT_MULTILINESTRING_ARRAY_EQUIVALENT(expected, got);
CUSPATIAL_EXPECT_MULTIPOINT_ARRAY_EQUIVALENT(expected, got);
}
};

@@ -388,7 +389,6 @@ TYPED_TEST(MultipolygonRangeTest, DISABLED_MultipolygonSegmentCount_ConatainsEmp
{6, 3});
}


TYPED_TEST(MultipolygonRangeTest, MultipolygonAsMultilinestring1)
{
CUSPATIAL_RUN_TEST(this->test_multipolygon_as_multilinestring,
@@ -407,10 +407,32 @@ TYPED_TEST(MultipolygonRangeTest, MultipolygonAsMultilinestring2)
{0, 1, 2},
{0, 1, 3},
{0, 4, 8, 12},
{{0, 0}, {1, 0}, {1, 1}, {0, 0}, {10, 10}, {11, 10}, {11, 11}, {10, 10}, {20, 20}, {21, 20}, {21, 21}, {20, 20}},
{{0, 0},
{1, 0},
{1, 1},
{0, 0},
{10, 10},
{11, 10},
{11, 11},
{10, 10},
{20, 20},
{21, 20},
{21, 21},
{20, 20}},
{0, 1, 3},
{0, 4, 8, 12},
{{0, 0}, {1, 0}, {1, 1}, {0, 0}, {10, 10}, {11, 10}, {11, 11}, {10, 10}, {20, 20}, {21, 20}, {21, 21}, {20, 20}});
{{0, 0},
{1, 0},
{1, 1},
{0, 0},
{10, 10},
{11, 10},
{11, 11},
{10, 10},
{20, 20},
{21, 20},
{21, 21},
{20, 20}});
}

TYPED_TEST(MultipolygonRangeTest, MultipolygonAsMultilinestring3)
@@ -419,10 +441,32 @@ TYPED_TEST(MultipolygonRangeTest, MultipolygonAsMultilinestring3)
{0, 1, 2},
{0, 2, 3},
{0, 4, 8, 12},
{{0, 0}, {1, 0}, {1, 1}, {0, 0}, {10, 10}, {11, 10}, {11, 11}, {10, 10}, {20, 20}, {21, 20}, {21, 21}, {20, 20}},
{{0, 0},
{1, 0},
{1, 1},
{0, 0},
{10, 10},
{11, 10},
{11, 11},
{10, 10},
{20, 20},
{21, 20},
{21, 21},
{20, 20}},
{0, 2, 3},
{0, 4, 8, 12},
{{0, 0}, {1, 0}, {1, 1}, {0, 0}, {10, 10}, {11, 10}, {11, 11}, {10, 10}, {20, 20}, {21, 20}, {21, 21}, {20, 20}});
{{0, 0},
{1, 0},
{1, 1},
{0, 0},
{10, 10},
{11, 10},
{11, 11},
{10, 10},
{20, 20},
{21, 20},
{21, 21},
{20, 20}});
}

TYPED_TEST(MultipolygonRangeTest, MultipolygonAsMultiPoint1)
@@ -442,19 +486,62 @@ TYPED_TEST(MultipolygonRangeTest, MultipolygonAsMultiPoint2)
{0, 1, 2},
{0, 1, 3},
{0, 4, 8, 12},
{{0, 0}, {1, 0}, {1, 1}, {0, 0}, {10, 10}, {11, 10}, {11, 11}, {10, 10}, {20, 20}, {21, 20}, {21, 21}, {20, 20}},
{{0, 0},
{1, 0},
{1, 1},
{0, 0},
{10, 10},
{11, 10},
{11, 11},
{10, 10},
{20, 20},
{21, 20},
{21, 21},
{20, 20}},
{0, 4, 12},
{{0, 0}, {1, 0}, {1, 1}, {0, 0}, {10, 10}, {11, 10}, {11, 11}, {10, 10}, {20, 20}, {21, 20}, {21, 21}, {20, 20}});
{{0, 0},
{1, 0},
{1, 1},
{0, 0},
{10, 10},
{11, 10},
{11, 11},
{10, 10},
{20, 20},
{21, 20},
{21, 21},
{20, 20}});
}


TYPED_TEST(MultipolygonRangeTest, MultipolygonAsMultiPoint3)
{
CUSPATIAL_RUN_TEST(this->test_multipolygon_as_multipoint,
{0, 1, 2},
{0, 2, 3},
{0, 4, 8, 12},
{{0, 0}, {1, 0}, {1, 1}, {0, 0}, {10, 10}, {11, 10}, {11, 11}, {10, 10}, {20, 20}, {21, 20}, {21, 21}, {20, 20}},
{{0, 0},
{1, 0},
{1, 1},
{0, 0},
{10, 10},
{11, 10},
{11, 11},
{10, 10},
{20, 20},
{21, 20},
{21, 21},
{20, 20}},
{0, 8, 12},
{{0, 0}, {1, 0}, {1, 1}, {0, 0}, {10, 10}, {11, 10}, {11, 11}, {10, 10}, {20, 20}, {21, 20}, {21, 21}, {20, 20}});
{{0, 0},
{1, 0},
{1, 1},
{0, 0},
{10, 10},
{11, 10},
{11, 11},
{10, 10},
{20, 20},
{21, 20},
{21, 21},
{20, 20}});
}