-
Notifications
You must be signed in to change notification settings - Fork 157
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
Refactor of pairwise_linestring_distance
to use multilinestring_range
, adds support to multilinestring distance
#755
Merged
rapids-bot
merged 8 commits into
rapidsai:branch-22.12
from
isVoid:feature/multilinestring_distance_header_only
Nov 7, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c1bb5e5
Initial port of header only changes from feature/multilinestring_dist…
isVoid bff953c
Apply suggestions from code review
isVoid 325df98
style
isVoid 251c6e6
simplifies atomicMin statement
isVoid ee36aaf
Merge branch 'branch-22.12' of https://github.com/rapidsai/cuspatial …
isVoid a487ba7
use cuda min instead of std min
isVoid d631629
address review comments
isVoid c1a470b
move vector factory to utility header
isVoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
cpp/include/cuspatial/experimental/detail/geometry/linestring_ref.cuh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2022, 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/detail/iterator.hpp> | ||
#include <cuspatial/traits.hpp> | ||
|
||
#include <thrust/iterator/zip_iterator.h> | ||
#include <thrust/tuple.h> | ||
|
||
namespace cuspatial { | ||
|
||
template <typename VecIterator> | ||
struct to_segment_functor { | ||
using element_t = iterator_vec_base_type<VecIterator>; | ||
using difference_type = typename thrust::iterator_difference<VecIterator>::type; | ||
VecIterator _point_begin; | ||
|
||
CUSPATIAL_HOST_DEVICE | ||
to_segment_functor(VecIterator point_begin) : _point_begin(point_begin) {} | ||
|
||
CUSPATIAL_HOST_DEVICE | ||
thrust::pair<vec_2d<element_t>, vec_2d<element_t>> operator()(difference_type i) | ||
{ | ||
return {_point_begin[i], _point_begin[i + 1]}; | ||
} | ||
}; | ||
|
||
template <typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE linestring_ref<VecIterator>::linestring_ref(VecIterator begin, | ||
VecIterator end) | ||
: _point_begin(begin), _point_end(end) | ||
{ | ||
using T = iterator_vec_base_type<VecIterator>; | ||
static_assert(is_same<vec_2d<T>, iterator_value_type<VecIterator>>(), "must be vec2d type"); | ||
} | ||
|
||
template <typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto linestring_ref<VecIterator>::num_segments() const | ||
{ | ||
// The number of segment equals the number of points minus 1. And the number of points | ||
// is thrust::distance(_point_begin, _point_end) - 1. | ||
return thrust::distance(_point_begin, _point_end) - 1; | ||
} | ||
|
||
template <typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto linestring_ref<VecIterator>::segment_begin() const | ||
{ | ||
return detail::make_counting_transform_iterator(0, to_segment_functor{_point_begin}); | ||
} | ||
|
||
template <typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto linestring_ref<VecIterator>::segment_end() const | ||
{ | ||
return segment_begin() + num_segments(); | ||
} | ||
|
||
} // namespace cuspatial |
70 changes: 70 additions & 0 deletions
70
cpp/include/cuspatial/experimental/detail/geometry_collection/multilinestring_ref.cuh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#pragma once | ||
|
||
#include "cuspatial/cuda_utils.hpp" | ||
#include <cuspatial/detail/iterator.hpp> | ||
#include <cuspatial/experimental/geometry/linestring_ref.cuh> | ||
|
||
#include <thrust/iterator/transform_iterator.h> | ||
|
||
namespace cuspatial { | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
struct to_linestring_functor { | ||
using difference_type = typename thrust::iterator_difference<PartIterator>::type; | ||
PartIterator part_begin; | ||
VecIterator point_begin; | ||
|
||
CUSPATIAL_HOST_DEVICE | ||
to_linestring_functor(PartIterator part_begin, VecIterator point_begin) | ||
: part_begin(part_begin), point_begin(point_begin) | ||
{ | ||
} | ||
|
||
CUSPATIAL_HOST_DEVICE auto operator()(difference_type i) | ||
{ | ||
return linestring_ref{point_begin + part_begin[i], point_begin + part_begin[i + 1]}; | ||
} | ||
}; | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
class multilinestring_ref; | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE multilinestring_ref<PartIterator, VecIterator>::multilinestring_ref( | ||
PartIterator part_begin, PartIterator part_end, VecIterator point_begin, VecIterator point_end) | ||
: _part_begin(part_begin), _part_end(part_end), _point_begin(point_begin), _point_end(point_end) | ||
{ | ||
} | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multilinestring_ref<PartIterator, VecIterator>::num_linestrings() const | ||
{ | ||
return thrust::distance(_part_begin, _part_end) - 1; | ||
} | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multilinestring_ref<PartIterator, VecIterator>::part_begin() const | ||
{ | ||
return detail::make_counting_transform_iterator(0, | ||
to_linestring_functor{_part_begin, _point_begin}); | ||
} | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multilinestring_ref<PartIterator, VecIterator>::part_end() const | ||
{ | ||
return part_begin() + num_linestrings(); | ||
} | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multilinestring_ref<PartIterator, VecIterator>::point_begin() const | ||
{ | ||
return _point_begin; | ||
} | ||
|
||
template <typename PartIterator, typename VecIterator> | ||
CUSPATIAL_HOST_DEVICE auto multilinestring_ref<PartIterator, VecIterator>::point_end() const | ||
{ | ||
return _point_end; | ||
} | ||
|
||
} // namespace cuspatial | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between a
multilinestring_range
and amultilinestring_ref
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conceptually
multilinestring_range
is a non-owning object on an array of multilinestrings.multilinestring_ref
is just a non owning object to a single multilinestring. Iterating onmultilinestring_range
gives amultilinestring_ref
.