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 Header Only API for Linestring-Polygon Distance #1011

Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7022c1d
initial
isVoid Mar 24, 2023
5686be3
add segment iterator and tests
isVoid Mar 28, 2023
a74af14
WIP
isVoid Mar 28, 2023
1c28faa
making progress towards getting the right index
isVoid Mar 29, 2023
243d2d9
commiting progress
isVoid Mar 29, 2023
0da0afc
able to get the right segment combinations from within the kernel, ne…
isVoid Mar 31, 2023
49e43aa
[skip-ci] initial port from feature/linestring_polygon_distance_header
isVoid Mar 31, 2023
e8e45d0
Apply suggestions from code review
isVoid Mar 31, 2023
fadf5c8
Update cpp/include/cuspatial/experimental/detail/functors.cuh
isVoid Mar 31, 2023
fe31542
address review comments
isVoid Mar 31, 2023
af0c35e
address review comments
isVoid Mar 31, 2023
05bf7ff
[skip-ci] address review coments
isVoid Mar 31, 2023
2435126
Add docstrings for functors
isVoid Mar 31, 2023
98a4a0f
[skip-ci] adds linestring_count test
isVoid Apr 1, 2023
9b72723
[skip-ci] revert removed code
isVoid Apr 1, 2023
6971200
style
isVoid Apr 1, 2023
6f7a226
update unexpected changes
isVoid Apr 1, 2023
641934f
license
isVoid Apr 1, 2023
c580876
Merge branch 'feature/segment_iterators' into feature/linestring_poly…
isVoid Apr 1, 2023
890e95b
Update cpp/include/cuspatial/experimental/detail/ranges/multilinestri…
isVoid Apr 1, 2023
040e432
making a bit of progress
isVoid Apr 2, 2023
7c3603c
fix broken multilinestring->multipoint constructor
isVoid Apr 2, 2023
5966ad0
Merge branch 'feature/segment_iterators' of github.com:isVoid/cuspati…
isVoid Apr 2, 2023
70ca1b6
fix broken multilinestring->multipoint constructor
isVoid Apr 2, 2023
9205533
passing existing tests
isVoid Apr 3, 2023
4bb3ca3
fix wrong test setup and update docs
isVoid Apr 3, 2023
9f34700
Merge branch 'feature/segment_iterators' into feature/linestring_poly…
isVoid Apr 3, 2023
8f20feb
style
isVoid Apr 3, 2023
3ffe5ee
Delete point_in_multipolygon.cuh
isVoid Apr 3, 2023
894f870
Delete linestring_polygon_distance.hpp
isVoid Apr 3, 2023
2b99555
cleanup - first round
isVoid Apr 3, 2023
656d093
Merge branch 'feature/linestring_polygon_distance_header' of github.c…
isVoid Apr 3, 2023
62d821f
merge duplicate code
isVoid Apr 3, 2023
7d22749
add missing header
isVoid Apr 3, 2023
9051944
style
isVoid Apr 3, 2023
e082aa1
fix OB access error
isVoid Apr 4, 2023
d94e060
address reviews
isVoid Apr 4, 2023
5dedc52
address reviews
isVoid Apr 4, 2023
314ad04
address review comments
isVoid Apr 5, 2023
26f272c
Merge branch 'branch-23.04' of https://github.com/rapidsai/cuspatial …
isVoid Apr 5, 2023
75a8fd2
style
isVoid Apr 5, 2023
dd1b09c
fix indirect dependency on thrust includes
isVoid Apr 5, 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
130 changes: 130 additions & 0 deletions cpp/include/cuspatial/experimental/detail/functors.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright (c) 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <cuspatial/cuda_utils.hpp>
#include <cuspatial/experimental/geometry/segment.cuh>
#include <cuspatial/traits.hpp>

#include <thrust/binary_search.h>

namespace cuspatial {
namespace detail {

/**
* @brief Given iterator a pair of offsets, return the number of elements between the offsets.
isVoid marked this conversation as resolved.
Show resolved Hide resolved
*
* Example:
* pair of offsets: (0, 3), (3, 5), (5, 8)
* number of elements between offsets: 3, 2, 3
*
* @tparam OffsetPairIterator Must be iterator type to thrust::pair of indices.
* @param p Iterator of thrust::pair of indices.
*/
struct offset_pair_to_count_functor {
template <typename OffsetPairIterator>
CUSPATIAL_HOST_DEVICE auto operator()(OffsetPairIterator p)
{
return thrust::get<1>(p) - thrust::get<0>(p);
}
};

/**
* @brief Convert counts of points to counts of segments in a linestring.
*
* A Multilinestring is composed of a series of Linestrings. Each Linestring is composed of a
* segments. The number of segments in a multilinestring is the number of points in the
* multilinestring subtracting the number of linestrings.
*
* Caveats: This has a strong assumption that the Multilinestring does not contain empty linestring.
* While each non-empty linestring in the multilinestring can cause 1 invalid segment, an empty
* multilinestring not introduce and invalid segments since it does not contain any points.
isVoid marked this conversation as resolved.
Show resolved Hide resolved
*
* @tparam IndexPair Must be iterator to a pair of counts
* @param n_point_linestring_pair A pair of counts, the first is the number of points, the second is
* the number of linestrings.
*/
struct point_count_to_segment_count_functor {
template <typename IndexPair>
CUSPATIAL_HOST_DEVICE auto operator()(IndexPair n_point_linestring_pair)
{
auto nPoints = thrust::get<0>(n_point_linestring_pair);
auto nLinestrings = thrust::get<1>(n_point_linestring_pair);
return nPoints - nLinestrings;
}
};

/**
* @brief Given an iterator of offsets, return an iterator of offsets subtracted by the index.
*
* @tparam OffsetIterator Iterator type to the offset
*
* Caveats: This has a strong assumption that the Multilinestring does not contain empty linestring.
* While each non-empty linestring in the multilinestring can cause 1 invalid segment, an empty
* multilinestring not introduce and invalid segments since it does not contain any points.
isVoid marked this conversation as resolved.
Show resolved Hide resolved
*/
template <typename OffsetIterator>
struct to_subtracted_by_index_iterator {
OffsetIterator begin;

template <typename IndexType>
CUSPATIAL_HOST_DEVICE auto operator()(IndexType i)
{
return begin[i] - i;
}
};

/// Deduction guide for to_subtracted_by_index_iterator
template <typename OffsetIterator>
to_subtracted_by_index_iterator(OffsetIterator) -> to_subtracted_by_index_iterator<OffsetIterator>;

/**
* @brief Return a segment from the a partitioned range of points
*
* Used in a counting transform iterator. Given an index of the segment, offset it by the number of
* skipped segments preceding i in the partitioned range of points. Dereference the corresponding
* point and the point following to make a segment.
*
* @tparam OffsetIterator the iterator type indicating partitions of the point range.
* @tparam CoordinateIterator the iterator type to the point range.
*/
template <typename OffsetIterator, typename CoordinateIterator>
struct to_valid_segment_functor {
using element_t = iterator_vec_base_type<CoordinateIterator>;

OffsetIterator begin;
OffsetIterator end;
CoordinateIterator point_begin;

template <typename IndexType>
CUSPATIAL_HOST_DEVICE segment<element_t> operator()(IndexType i)
{
auto kit = thrust::upper_bound(thrust::seq, begin, end, i);
auto k = thrust::distance(begin, kit);
auto pid = i + k - 1;

return segment<element_t>{point_begin[pid], point_begin[pid + 1]};
}
};

/// Deduction guide for to_valid_segment_functor
template <typename OffsetIterator, typename CoordinateIterator>
to_valid_segment_functor(OffsetIterator, OffsetIterator, CoordinateIterator)
-> to_valid_segment_functor<OffsetIterator, CoordinateIterator>;

} // namespace detail
} // namespace cuspatial
Loading