diff --git a/cpp/benchmarks/pairwise_linestring_distance.cu b/cpp/benchmarks/pairwise_linestring_distance.cu index 2d98e79e8..f0cb548fd 100644 --- a/cpp/benchmarks/pairwise_linestring_distance.cu +++ b/cpp/benchmarks/pairwise_linestring_distance.cu @@ -64,24 +64,23 @@ using namespace cuspatial; * */ template -std::tuple>, rmm::device_vector> generate_linestring( - int32_t num_strings, int32_t num_segments_per_string, T segment_length, cartesian_2d init_xy) +std::tuple>, rmm::device_vector> generate_linestring( + int32_t num_strings, int32_t num_segments_per_string, T segment_length, vec_2d init_xy) { int32_t num_points = num_strings * (num_segments_per_string + 1); auto offset_iter = detail::make_counting_transform_iterator( 0, [num_segments_per_string](auto i) { return i * num_segments_per_string; }); auto rads_iter = detail::make_counting_transform_iterator(0, [](auto i) { - return cartesian_2d{cos(static_cast(i)), sin(static_cast(i))}; + return vec_2d{cos(static_cast(i)), sin(static_cast(i))}; }); std::vector offsets(offset_iter, offset_iter + num_strings); - std::vector> rads(rads_iter, rads_iter + num_points); - std::vector> points(num_points); + std::vector> rads(rads_iter, rads_iter + num_points); + std::vector> points(num_points); - auto random_walk_func = [segment_length](cartesian_2d const& prev, - cartesian_2d const& rad) { - return cartesian_2d{prev.x + segment_length * rad.x, prev.y + segment_length * rad.y}; + auto random_walk_func = [segment_length](vec_2d const& prev, vec_2d const& rad) { + return prev + segment_length * rad; }; thrust::exclusive_scan( diff --git a/cpp/benchmarks/point_in_polygon.cu b/cpp/benchmarks/point_in_polygon.cu index dcdfc01c4..6567bd47c 100644 --- a/cpp/benchmarks/point_in_polygon.cu +++ b/cpp/benchmarks/point_in_polygon.cu @@ -39,11 +39,11 @@ auto constexpr num_rings_per_polygon = 1; // only 1 ring for now * @brief Generate a random point within a window of [minXY, maxXY] */ template -cartesian_2d random_point(cartesian_2d minXY, cartesian_2d maxXY) +vec_2d random_point(vec_2d minXY, vec_2d maxXY) { auto x = minXY.x + (maxXY.x - minXY.x) * rand() / static_cast(RAND_MAX); auto y = minXY.y + (maxXY.y - minXY.y) * rand() / static_cast(RAND_MAX); - return cartesian_2d{x, y}; + return vec_2d{x, y}; } /** @@ -63,14 +63,12 @@ cartesian_2d random_point(cartesian_2d minXY, cartesian_2d maxXY) * */ template -std::tuple, - rmm::device_vector, - rmm::device_vector>> -generate_polygon(int32_t num_sides, T radius, cartesian_2d minXY, cartesian_2d maxXY) +std::tuple, rmm::device_vector, rmm::device_vector>> +generate_polygon(int32_t num_sides, T radius, vec_2d minXY, vec_2d maxXY) { std::vector polygon_offsets(num_polygons); std::vector ring_offsets(num_polygons * num_rings_per_polygon); - std::vector> polygon_points(31 * (num_sides + 1)); + std::vector> polygon_points(31 * (num_sides + 1)); std::iota(polygon_offsets.begin(), polygon_offsets.end(), 0); std::iota(ring_offsets.begin(), ring_offsets.end(), 0); @@ -84,11 +82,11 @@ generate_polygon(int32_t num_sides, T radius, cartesian_2d minXY, cartesian_2 auto begin = i * num_sides + polygon_points.begin(); auto center = random_point(minXY, maxXY); std::transform(it, it + num_sides + 1, begin, [num_sides, radius, center](int32_t j) { - return cartesian_2d{ - static_cast(radius * std::cos(2 * PI * (j % num_sides) / static_cast(num_sides)) + - center.x), - static_cast(radius * std::sin(2 * PI * (j % num_sides) / static_cast(num_sides)) + - center.y)}; + return center + + radius * + vec_2d{ + static_cast(std::cos(2 * PI * (j % num_sides) / static_cast(num_sides))), + static_cast(std::sin(2 * PI * (j % num_sides) / static_cast(num_sides)))}; }); } @@ -102,11 +100,11 @@ generate_polygon(int32_t num_sides, T radius, cartesian_2d minXY, cartesian_2 * @tparam T The floating point type for the coordinates */ template -rmm::device_vector> generate_points(int32_t num_test_points, - cartesian_2d minXY, - cartesian_2d maxXY) +rmm::device_vector> generate_points(int32_t num_test_points, + vec_2d minXY, + vec_2d maxXY) { - std::vector> points(num_test_points); + std::vector> points(num_test_points); std::generate( points.begin(), points.end(), [minXY, maxXY]() { return random_point(minXY, maxXY); }); // Implicitly convert to device_vector @@ -120,8 +118,8 @@ void point_in_polygon_benchmark(nvbench::state& state, nvbench::type_list) cuspatial::rmm_pool_raii rmm_pool; std::srand(0); // For reproducibility - auto const minXY = cartesian_2d{-radius * 2, -radius * 2}; - auto const maxXY = cartesian_2d{radius * 2, radius * 2}; + auto const minXY = vec_2d{-radius * 2, -radius * 2}; + auto const maxXY = vec_2d{radius * 2, radius * 2}; auto const num_test_points{state.get_int64("NumTestPoints")}, num_sides_per_ring{state.get_int64("NumSidesPerRing")}; diff --git a/cpp/doc/libcuspatial_refactoring_guide.md b/cpp/doc/libcuspatial_refactoring_guide.md index c7f3e06b0..e8daa1245 100644 --- a/cpp/doc/libcuspatial_refactoring_guide.md +++ b/cpp/doc/libcuspatial_refactoring_guide.md @@ -48,8 +48,8 @@ There are a few key points to notice. 1. The API is very similar to STL algorithms such as `std::transform`. 2. All array inputs and outputs are iterator type templates. - 3. Longitude/Latitude data is passed as array of structures, using the `cuspatial::lonlat_2d` - type (include/cuspatial/types.hpp). This is enforced using a `static_assert` in the function + 3. Longitude/Latitude data is passed as array of structures, using the `cuspatial::vec_2d` + type (include/cuspatial/vec_2d.hpp). This is enforced using a `static_assert` in the function body (discussed later). 4. The `Location` type is a template that is by default equal to the `value_type` of the input iterators. @@ -96,8 +96,7 @@ Following is the (Doxygen) documentation for the above `cuspatial::haversine_dis * [LegacyRandomAccessIterator][LinkLRAI] and be device-accessible. * @tparam OutputIt Output iterator. Must meet the requirements of * [LegacyRandomAccessIterator][LinkLRAI] and be device-accessible. - * @tparam Location The `value_type` of `LonLatItA` and `LonLatItB`. Must be - * `cuspatial::lonlat_2d`. + * @tparam Location The `value_type` of `LonLatItA` and `LonLatItB`. Must be `cuspatial::vec_2d`. * @tparam T The underlying coordinate type. Must be a floating-point type. * * @pre `a_lonlat_first` may equal `distance_first`, but the range `[a_lonlat_first, a_lonlat_last)` @@ -107,7 +106,7 @@ Following is the (Doxygen) documentation for the above `cuspatial::haversine_dis * shall not overlap the range `[distance_first, distance_first + (b_lonlat_last - b_lonlat_last)) * otherwise. * @pre All iterators must have the same `Location` type, with the same underlying floating-point - * coordinate type (e.g. `cuspatial::lonlat_2d`). + * coordinate type (e.g. `cuspatial::vec_2d`). * * @return Output iterator to the element past the last distance computed. * @@ -132,13 +131,16 @@ This is the existing API, unchanged by refactoring. Here is the existing `cuspatial::haversine_distance`: ```C++ -std::unique_ptr haversine_distance( - cudf::column_view const& a_lon, - cudf::column_view const& a_lat, - cudf::column_view const& b_lon, - cudf::column_view const& b_lat, - double const radius = EARTH_RADIUS_KM, - rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); +template > +OutputIt haversine_distance(LonLatItA a_lonlat_first, + LonLatItA a_lonlat_last, + LonLatItB b_lonlat_first, + OutputIt distance_first, + T const radius = EARTH_RADIUS_KM, + rmm::cuda_stream_view stream = rmm::cuda_stream_default); ``` key points: @@ -186,11 +188,7 @@ a simple matter of a few static asserts and dynamic expectation checks, followed `thrust::transform` with a custom transform functor. ```C++ -template ::value_type, - class T = typename Location::value_type> +template OutputIt haversine_distance(LonLatItA a_lonlat_first, LonLatItA a_lonlat_last, LonLatItB b_lonlat_first, @@ -198,15 +196,15 @@ OutputIt haversine_distance(LonLatItA a_lonlat_first, T const radius, rmm::cuda_stream_view stream) { - using LocationB = typename std::iterator_traits::value_type; - static_assert(std::conjunction_v, Location>, - std::is_same, LocationB>>, - "Inputs must be cuspatial::lonlat_2d"); + static_assert(detail::is_same, + detail::iterator_value_type, + detail::iterator_value_type>(), + "Inputs must be cuspatial::vec_2d"); static_assert( - std::conjunction_v, - std::is_floating_point, - std::is_floating_point::value_type>>, - "Haversine distance supports only floating-point coordinates."); + detail::is_same_floating_point, + typename detail::iterator_value_type>(), + "All iterator types and radius must have the same floating-point coordinate value type."); CUSPATIAL_EXPECTS(radius > 0, "radius must be positive."); @@ -221,7 +219,7 @@ OutputIt haversine_distance(LonLatItA a_lonlat_first, Note that we `static_assert` that the types of the iterator inputs match documented expectations. We also do a runtime check that the radius is positive. Finally we just call `thrust::transform`, -passing it an instance of `haversine_distance_functor`, which is a function of two `lonlat_2d` +passing it an instance of `haversine_distance_functor`, which is a function of two `vec_2d` inputs that implements the Haversine distance formula. ### libcudf-based API Implementation @@ -229,7 +227,7 @@ inputs that implements the Haversine distance formula. The substance of the refactoring is making the libcudf-based API a wrapper around the header-only API. This mostly involves replacing business logic implementation in the type-dispatched functor with a call to the header-only API. We also need to convert disjoint latitude and longitude inputs -into `lonlat_2d` structs. This is easily done using the `cuspatial::make_lonlat_iterator` utility +into `vec_2d` structs. This is easily done using the `cuspatial::make_vec_2d_iterator` utility provided in `type_utils.hpp`. So, to refactor the libcudf-based API, we remove the following code. @@ -259,8 +257,8 @@ thrust::transform(rmm::exec_policy(stream), And replace it with the following code. ```C++ -auto lonlat_a = cuspatial::make_lonlat_iterator(a_lon.begin(), a_lat.begin()); -auto lonlat_b = cuspatial::make_lonlat_iterator(b_lon.begin(), b_lat.begin()); +auto lonlat_a = cuspatial::make_vec_2d_iterator(a_lon.begin(), a_lat.begin()); +auto lonlat_b = cuspatial::make_vec_2d_iterator(b_lon.begin(), b_lat.begin()); cuspatial::haversine_distance(lonlat_a, lonlat_a + a_lon.size(), diff --git a/cpp/include/cuspatial/detail/utility/traits.hpp b/cpp/include/cuspatial/detail/utility/traits.hpp index 301d74a3e..68578b208 100644 --- a/cpp/include/cuspatial/detail/utility/traits.hpp +++ b/cpp/include/cuspatial/detail/utility/traits.hpp @@ -16,6 +16,7 @@ #pragma once +#include #include namespace cuspatial { diff --git a/cpp/include/cuspatial/experimental/coordinate_transform.cuh b/cpp/include/cuspatial/experimental/coordinate_transform.cuh index fd64d8157..60c252f7a 100644 --- a/cpp/include/cuspatial/experimental/coordinate_transform.cuh +++ b/cpp/include/cuspatial/experimental/coordinate_transform.cuh @@ -33,9 +33,9 @@ namespace cuspatial { * @param[out] xy_first: beginning of range of output x/y coordinates. * @param[in] stream: The CUDA stream on which to perform computations and allocate memory. * - * All input iterators must have a `value_type` of `cuspatial::lonlat_2d` (Lat/Lon coordinates), - * and the output iterator must be able to accept for storage values of type - * `cuspatial::cartesian_2d` (Cartesian coordinates). + * All input iterators must have a `value_type` of `cuspatial::vec_2d` (Lat/Lon coordinates), + * and the output iterator must be able to accept for storage values of type `cuspatial::vec_2d` + * (Cartesian coordinates). * * @tparam InputIt Iterator over longitude/latitude locations. Must meet the requirements of * [LegacyRandomAccessIterator][LinkLRAI] and be device-accessible. @@ -56,7 +56,7 @@ template OutputIt lonlat_to_cartesian(InputIt lon_lat_first, InputIt lon_lat_last, OutputIt xy_first, - lonlat_2d origin, + vec_2d origin, rmm::cuda_stream_view stream = rmm::cuda_stream_default); } // namespace cuspatial diff --git a/cpp/include/cuspatial/experimental/detail/coordinate_transform.cuh b/cpp/include/cuspatial/experimental/detail/coordinate_transform.cuh index ae139db1e..f99e955c4 100644 --- a/cpp/include/cuspatial/experimental/detail/coordinate_transform.cuh +++ b/cpp/include/cuspatial/experimental/detail/coordinate_transform.cuh @@ -53,16 +53,16 @@ __device__ inline T lat_to_y(T lat) template struct to_cartesian_functor { - to_cartesian_functor(lonlat_2d origin) : _origin(origin) {} + to_cartesian_functor(vec_2d origin) : _origin(origin) {} - cartesian_2d __device__ operator()(lonlat_2d loc) + vec_2d __device__ operator()(vec_2d loc) { - return cartesian_2d{lon_to_x(_origin.x - loc.x, midpoint(loc.y, _origin.y)), - lat_to_y(_origin.y - loc.y)}; + return vec_2d{lon_to_x(_origin.x - loc.x, midpoint(loc.y, _origin.y)), + lat_to_y(_origin.y - loc.y)}; } private: - lonlat_2d _origin{}; + vec_2d _origin{}; }; } // namespace detail @@ -71,7 +71,7 @@ template OutputIt lonlat_to_cartesian(InputIt lon_lat_first, InputIt lon_lat_last, OutputIt xy_first, - lonlat_2d origin, + vec_2d origin, rmm::cuda_stream_view stream) { static_assert(std::is_floating_point_v, diff --git a/cpp/include/cuspatial/experimental/detail/haversine.cuh b/cpp/include/cuspatial/experimental/detail/haversine.cuh index 70b64d3a3..3ecbe3aa7 100644 --- a/cpp/include/cuspatial/experimental/detail/haversine.cuh +++ b/cpp/include/cuspatial/experimental/detail/haversine.cuh @@ -17,6 +17,7 @@ #pragma once #include +#include #include #include @@ -24,7 +25,6 @@ #include #include -#include #include @@ -36,12 +36,12 @@ template struct haversine_distance_functor { haversine_distance_functor(T radius) : radius_(radius) {} - __device__ T operator()(lonlat_2d point_a, lonlat_2d point_b) + __device__ T operator()(vec_2d lonlat_a, vec_2d lonlat_b) { - auto ax = point_a.x * DEGREE_TO_RADIAN; - auto ay = point_a.y * DEGREE_TO_RADIAN; - auto bx = point_b.x * DEGREE_TO_RADIAN; - auto by = point_b.y * DEGREE_TO_RADIAN; + auto ax = lonlat_a.x * DEGREE_TO_RADIAN; + auto ay = lonlat_a.y * DEGREE_TO_RADIAN; + auto bx = lonlat_b.x * DEGREE_TO_RADIAN; + auto by = lonlat_b.y * DEGREE_TO_RADIAN; // haversine formula auto x = (bx - ax) / 2; @@ -58,7 +58,7 @@ struct haversine_distance_functor { } // namespace detail -template +template OutputIt haversine_distance(LonLatItA a_lonlat_first, LonLatItA a_lonlat_last, LonLatItB b_lonlat_first, @@ -66,15 +66,15 @@ OutputIt haversine_distance(LonLatItA a_lonlat_first, T const radius, rmm::cuda_stream_view stream) { - using LocationB = typename std::iterator_traits::value_type; + static_assert(detail::is_same, + detail::iterator_value_type, + detail::iterator_value_type>(), + "Inputs must be cuspatial::vec_2d"); static_assert( - std::conjunction_v, Location>, std::is_same, LocationB>>, - "Inputs must be cuspatial::lonlat_2d"); - static_assert( - std::conjunction_v, - std::is_floating_point, - std::is_floating_point::value_type>>, - "Haversine distance supports only floating-point coordinates."); + detail::is_same_floating_point, + typename detail::iterator_value_type>(), + "All iterator types and radius must have the same floating-point coordinate value type."); CUSPATIAL_EXPECTS(radius > 0, "radius must be positive."); diff --git a/cpp/include/cuspatial/experimental/detail/linestring_distance.cuh b/cpp/include/cuspatial/experimental/detail/linestring_distance.cuh index ef055aaef..289ec014c 100644 --- a/cpp/include/cuspatial/experimental/detail/linestring_distance.cuh +++ b/cpp/include/cuspatial/experimental/detail/linestring_distance.cuh @@ -148,21 +148,17 @@ void pairwise_linestring_distance(OffsetIterator linestring1_offsets_first, OutputIt distances_first, rmm::cuda_stream_view stream) { - using T = typename std::iterator_traits::value_type::value_type; - - static_assert( - detail::is_floating_point::value_type::value_type, - typename std::iterator_traits::value_type>(), - "Inputs and output must have floating point value type."); + using T = typename detail::iterator_vec_base_type; - static_assert(detail::is_same::value_type>(), - "Inputs and output must have the same value type."); + static_assert(detail::is_same_floating_point, + typename detail::iterator_value_type>(), + "Inputs and output must have the same floating point value type."); - static_assert(detail::is_same, - typename std::iterator_traits::value_type, - typename std::iterator_traits::value_type>(), - "All input types must be cuspatial::cartesian_2d with the same value type"); + static_assert(detail::is_same, + typename detail::iterator_value_type, + typename detail::iterator_value_type>(), + "All input types must be cuspatial::vec_2d with the same value type"); auto const num_linestring_pairs = thrust::distance(linestring1_offsets_first, linestring1_offsets_last); diff --git a/cpp/include/cuspatial/experimental/detail/point_distance.cuh b/cpp/include/cuspatial/experimental/detail/point_distance.cuh index 7d9853713..7e52db02d 100644 --- a/cpp/include/cuspatial/experimental/detail/point_distance.cuh +++ b/cpp/include/cuspatial/experimental/detail/point_distance.cuh @@ -36,21 +36,17 @@ OutputIt pairwise_point_distance(Cart2dItA points1_first, OutputIt distances_first, rmm::cuda_stream_view stream) { - using T = typename std::iterator_traits::value_type::value_type; + using T = typename detail::iterator_vec_base_type; - static_assert( - detail::is_floating_point::value_type::value_type, - typename std::iterator_traits::value_type>(), - "Inputs and output must be floating point types."); + static_assert(detail::is_same_floating_point, + typename detail::iterator_value_type>(), + "Inputs and output must have the same floating point value type."); - static_assert(detail::is_same::value_type>(), - "Inputs and output must be the same types."); - - static_assert(detail::is_same, - typename std::iterator_traits::value_type, - typename std::iterator_traits::value_type>(), - "All Input types must be cuspatial::cartesian_2d with the same value type"); + static_assert(detail::is_same, + typename detail::iterator_value_type, + typename detail::iterator_value_type>(), + "All Input types must be cuspatial::vec_2d with the same value type"); return thrust::transform(rmm::exec_policy(stream), points1_first, diff --git a/cpp/include/cuspatial/experimental/detail/point_in_polygon.cuh b/cpp/include/cuspatial/experimental/detail/point_in_polygon.cuh index d2e11740e..64016be48 100644 --- a/cpp/include/cuspatial/experimental/detail/point_in_polygon.cuh +++ b/cpp/include/cuspatial/experimental/detail/point_in_polygon.cuh @@ -170,10 +170,10 @@ OutputIt point_in_polygon(Cart2dItA test_points_first, static_assert(detail::is_same_floating_point>(), "Underlying type of Cart2dItA and Cart2dItB must be the same floating point type"); - static_assert(detail::is_same, + static_assert(detail::is_same, detail::iterator_value_type, detail::iterator_value_type>(), - "Inputs must be cuspatial::cartesian_2d"); + "Inputs must be cuspatial::vec_2d"); static_assert(detail::is_integral, detail::iterator_value_type>(), diff --git a/cpp/include/cuspatial/experimental/detail/point_linestring_distance.cuh b/cpp/include/cuspatial/experimental/detail/point_linestring_distance.cuh index 85efdf3ad..24ed18e46 100644 --- a/cpp/include/cuspatial/experimental/detail/point_linestring_distance.cuh +++ b/cpp/include/cuspatial/experimental/detail/point_linestring_distance.cuh @@ -89,10 +89,10 @@ void __global__ pairwise_point_linestring_distance(Cart2dItA points_first, // Note that the last point for the last linestring is guarded by the grid-stride loop. if (offsets_iter != linestring_offsets_last and *offsets_iter - 1 == idx) { continue; } - auto point_idx = thrust::distance(linestring_offsets_first, thrust::prev(offsets_iter)); - cartesian_2d const a = linestring_points_first[idx]; - cartesian_2d const b = linestring_points_first[idx + 1]; - cartesian_2d const c = points_first[point_idx]; + auto point_idx = thrust::distance(linestring_offsets_first, thrust::prev(offsets_iter)); + vec_2d const a = linestring_points_first[idx]; + vec_2d const b = linestring_points_first[idx + 1]; + vec_2d const c = points_first[point_idx]; auto const distance_squared = point_to_segment_distance_squared(c, a, b); @@ -117,10 +117,10 @@ void pairwise_point_linestring_distance(Cart2dItA points_first, static_assert(detail::is_same_floating_point>(), "Inputs must have same floating point value type."); - static_assert(detail::is_same, + static_assert(detail::is_same, detail::iterator_value_type, detail::iterator_value_type>(), - "Inputs must be cuspatial::cartesian_2d"); + "Inputs must be cuspatial::vec_2d"); auto const num_pairs = thrust::distance(points_first, points_last); diff --git a/cpp/include/cuspatial/experimental/haversine.cuh b/cpp/include/cuspatial/experimental/haversine.cuh index 4b743f690..cb408653e 100644 --- a/cpp/include/cuspatial/experimental/haversine.cuh +++ b/cpp/include/cuspatial/experimental/haversine.cuh @@ -17,6 +17,7 @@ #pragma once #include +#include #include @@ -52,12 +53,10 @@ namespace cuspatial { * [LegacyRandomAccessIterator][LinkLRAI] and be device-accessible. * @tparam OutputIt Output iterator. Must meet the requirements of * [LegacyRandomAccessIterator][LinkLRAI] and be device-accessible and mutable. - * @tparam Location The `value_type` of `LonLatItA` and `LonLatItB`. Must be - * `cuspatial::lonlat_2d`. * @tparam T The underlying coordinate type. Must be a floating-point type. * * @pre All iterators must have the same `Location` type, with the same underlying floating-point - * coordinate type (e.g. `cuspatial::lonlat_2d`). + * coordinate type (e.g. `cuspatial::vec_2d`). * * @return Output iterator to the element past the last distance computed. * @@ -67,8 +66,7 @@ namespace cuspatial { template ::value_type, - class T = typename Location::value_type> + class T = typename detail::iterator_vec_base_type> OutputIt haversine_distance(LonLatItA a_lonlat_first, LonLatItA a_lonlat_last, LonLatItB b_lonlat_first, diff --git a/cpp/include/cuspatial/experimental/linestring_distance.cuh b/cpp/include/cuspatial/experimental/linestring_distance.cuh index 563a0a771..ac95fd803 100644 --- a/cpp/include/cuspatial/experimental/linestring_distance.cuh +++ b/cpp/include/cuspatial/experimental/linestring_distance.cuh @@ -51,7 +51,7 @@ namespace cuspatial { * @param distances_first beginning iterator to output * @param stream The CUDA stream to use for device memory operations and kernel launches. * - * @pre all input iterators for coordinates must have `cuspatial::cartesian_2d` type. + * @pre all input iterators for coordinates must have `cuspatial::vec_2d` type. * @pre all scalar types must be floating point types, and must be the same type for all input * iterators and output iterators. * diff --git a/cpp/include/cuspatial/experimental/point_distance.cuh b/cpp/include/cuspatial/experimental/point_distance.cuh index 51260df8c..b3cdaf5fe 100644 --- a/cpp/include/cuspatial/experimental/point_distance.cuh +++ b/cpp/include/cuspatial/experimental/point_distance.cuh @@ -38,7 +38,7 @@ namespace cuspatial { * @param stream The CUDA stream to use for device memory operations and kernel launches * @return Output iterator to one past the last element in the output range * - * @pre all input iterators for coordinates must have a `value_type` of `cuspatial::cartesian_2d`. + * @pre all input iterators for coordinates must have a `value_type` of `cuspatial::vec_2d`. * @pre all scalar types must be floating point types, and must be the same type for all input * iterators and output iterators. * diff --git a/cpp/include/cuspatial/experimental/point_in_polygon.cuh b/cpp/include/cuspatial/experimental/point_in_polygon.cuh index 756ec57a2..1d9c86c19 100644 --- a/cpp/include/cuspatial/experimental/point_in_polygon.cuh +++ b/cpp/include/cuspatial/experimental/point_in_polygon.cuh @@ -82,10 +82,9 @@ namespace cuspatial { * +-----------+ +------------------------+ * ``` * - * @pre All point iterators must have the same `cartesian_2d` type, with the same underlying - * floating-point coordinate type (e.g. `cuspatial::cartesian_2d`). - * @pre All offset iterators must have the same `cartesian_2d` type, with the same underlying - * integeral type. + * @pre All point iterators must have the same `vec_2d` value type, with the same underlying + * floating-point coordinate type (e.g. `cuspatial::vec_2d`). + * @pre All offset iterators must have the same integral value type. * @pre Output iterator must be mutable and iterate on int32_t type. * * @throw cuspatial::logic_error if the number of polygons or rings exceeds 31. diff --git a/cpp/include/cuspatial/experimental/point_linestring_distance.cuh b/cpp/include/cuspatial/experimental/point_linestring_distance.cuh index b95c6700a..b326c7172 100644 --- a/cpp/include/cuspatial/experimental/point_linestring_distance.cuh +++ b/cpp/include/cuspatial/experimental/point_linestring_distance.cuh @@ -46,7 +46,7 @@ namespace cuspatial { * @param distances_first beginning the output range of distances * @param stream The CUDA stream to use for device memory operations and kernel launches. * - * @pre all input iterators for coordinates must have `cuspatial::cartesian_2d` type. + * @pre all input iterators for coordinates must have `cuspatial::vec_2d` type. * @pre all scalar types must be floating point types, and must be the same type for all input * iterators and output iterators. * diff --git a/cpp/include/cuspatial/experimental/type_utils.hpp b/cpp/include/cuspatial/experimental/type_utils.hpp index 2b3f1e1d8..e6acbe035 100644 --- a/cpp/include/cuspatial/experimental/type_utils.hpp +++ b/cpp/include/cuspatial/experimental/type_utils.hpp @@ -15,6 +15,7 @@ */ #include +#include #include #include @@ -32,7 +33,7 @@ namespace detail { * @internal * @brief Helper to convert a tuple of elements into a `vec_2d` */ -template +template > struct tuple_to_vec_2d { __device__ VectorType operator()(thrust::tuple const& pos) { @@ -44,7 +45,7 @@ struct tuple_to_vec_2d { * @internal * @brief Helper to convert a `vec_2d` into a tuple of elements */ -template +template > struct vec_2d_to_tuple { __device__ thrust::tuple operator()(VectorType const& xy) { @@ -65,7 +66,7 @@ struct vec_2d_to_tuple { * Interleaves x and y coordinates from separate iterators into a single iterator to x-y * coordinates. * - * @tparam VectorType cuSpatial vector type, must be `vec_2d`, `lonlat_2d` or `cartesian_2d` + * @tparam VectorType cuSpatial vector type, must be `vec_2d` * @tparam FirstIter Iterator type to the first component of `vec_2d`. Must meet the requirements of * [LegacyRandomAccessIterator][LinkLRAI] and be device-accessible. * @tparam SecondIter Iterator type to the second component of `vec_2d`. Must meet the requirements @@ -79,72 +80,15 @@ struct vec_2d_to_tuple { * [LinkLRAI]: https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator * "LegacyRandomAccessIterator" */ -template +template auto make_vec_2d_iterator(FirstIter first, SecondIter second) { using T = typename std::iterator_traits::value_type; - static_assert(std::is_same_v::value_type>, + static_assert(detail::is_same>(), "Iterator value_type mismatch"); auto zipped = thrust::make_zip_iterator(thrust::make_tuple(first, second)); - return thrust::make_transform_iterator(zipped, detail::tuple_to_vec_2d()); -} - -/** - * @brief Create an iterator to `lonlat_2d` data from two input iterators. - * - * Interleaves longitude and latitude from separate iterators into a single iterator to lon/lat - * coordinates. - * @tparam FirstIter Iterator type to the first component (the longitude) of `lonlat_2d`. Must meet - * the requirements of [LegacyRandomAccessIterator][LinkLRAI] and be device-accessible. - * @tparam SecondIter Iterator type to the second component (the latitude) of `lonlat_2d`. Must meet - * the requirements of [LegacyRandomAccessIterator][LinkLRAI] and be device-accessible. - * @param first Iterator to beginning of `lonlat_2d::x` - * @param second Iterator to beginning of `lonlat_2d::y` - * @return Iterator to `lonlat_2d` - * - * @pre `first` and `second` must iterate on same data type. - * - * [LinkLRAI]: https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator - * "LegacyRandomAccessIterator" - */ -template -auto make_vec_2d_iterator(FirstIter first, SecondIter second) -{ - using T = typename std::iterator_traits::value_type; - return make_vec_2d_iterator>(first, second); -} - -template -auto make_lonlat_iterator(FirstIter first, SecondIter second) -{ - using T = typename std::iterator_traits::value_type; - return make_vec_2d_iterator>(first, second); -} - -/** - * @brief Create an iterator to `cartesian_2d` data from two input iterators. - * - * Interleaves x and y coordinates from separate iterators into a single iterator to x-y - * coordinates. - * @tparam FirstIter Iterator type to the first component of `cartesian_2d`. Must meet the - * requirements of [LegacyRandomAccessIterator][LinkLRAI] and be device-accessible. - * @tparam SecondIter Iterator type to the second component of `cartesian_2d`. Must meet the - * requirements of [LegacyRandomAccessIterator][LinkLRAI] and be device-accessible. - * @param first Iterator to beginning of `cartesian_2d::x` - * @param second Iterator to beginning of `cartesian_2d::y` - * @return Iterator to `cartesian_2d` - * - * @pre `first` and `second` must iterate on same data type. - * - * [LinkLRAI]: https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator - * "LegacyRandomAccessIterator" - */ -template -auto make_cartesian_2d_iterator(FirstIter first, SecondIter second) -{ - using T = typename std::iterator_traits::value_type; - return make_vec_2d_iterator>(first, second); + return thrust::make_transform_iterator(zipped, detail::tuple_to_vec_2d()); } /** @@ -154,7 +98,7 @@ auto make_cartesian_2d_iterator(FirstIter first, SecondIter second) * can be written interleaved x/y data. This allows using two separate arrays of * output data with APIs that expect an iterator to structured data. * - * @tparam VectorType cuSpatial vector type, must be `vec_2d`, `lonlat_2d` or `cartesian_2d` + * @tparam VectorType cuSpatial vector type, must be `vec_2d` * @tparam FirstIter Iterator type to the first component of `vec_2d`. Must meet the * requirements of [LegacyRandomAccessIterator][LinkLRAI], be mutable and be device-accessible. * @tparam SecondIter Iterator type to the second component of `vec_2d`. Must meet the @@ -168,67 +112,12 @@ auto make_cartesian_2d_iterator(FirstIter first, SecondIter second) * [LinkLRAI]: https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator * "LegacyRandomAccessIterator" */ -template +template auto make_zipped_vec_2d_output_iterator(FirstIter first, SecondIter second) { using T = typename std::iterator_traits::value_type; auto zipped_out = thrust::make_zip_iterator(thrust::make_tuple(first, second)); - return thrust::make_transform_output_iterator(zipped_out, - detail::vec_2d_to_tuple()); -} - -/** - * @brief Create an output iterator to `lonlat_2d` from two output iterators. - * - * Creates an output iterator from separate iterators to longitude and latitude data - * to which can be written interleaved longitude/latitude data. This allows using two - * separate arrays of output data with APIs that expect an iterator to interleaved - * data. - * - * @tparam FirstIter Iterator type to the first component of `lonlat_2d`. Must meet the - * requirements of [LegacyRandomAccessIterator][LinkLRAI], be mutable and be device-accessible. - * @tparam SecondIter Iterator type to the second component of `lonlat_2d`. Must meet the - * requirements of [LegacyRandomAccessIterator][LinkLRAI], be mutable and be device-accessible. - * @param first Iterator to beginning of longitude data. - * @param second Iterator of beginning of latitude data. - * @return Iterator to `lonlat_2d` - * - * @pre `first` and `second` must iterate on same data type. - * - * [LinkLRAI]: https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator - * "LegacyRandomAccessIterator" - */ -template -auto make_zipped_lonlat_output_iterator(FirstIter first, SecondIter second) -{ - using T = typename std::iterator_traits::value_type; - return make_zipped_vec_2d_output_iterator>(first, second); -} - -/** - * @brief Create an output iterator to `cartesian_2d` from two output iterators. - * - * Creates an output iterator from separate iterators to x and y data to which - * can be written interleaved x/y data. This allows using two separate arrays of - * output data with APIs that expect an iterator to structured data. - * @tparam FirstIter Iterator type to the first component of `cartesian_2d`. Must meet the - * requirements of [LegacyRandomAccessIterator][LinkLRAI], be mutable and be device-accessible. - * @tparam SecondIter Iterator type to the second component of `cartesian_2d`. Must meet the - * requirements of [LegacyRandomAccessIterator][LinkLRAI], be mutable and be device-accessible. - * @param first Iterator to beginning of `x` data. - * @param second Iterator to beginning of `y` data. - * @return Iterator to `cartesian_2d` - * - * @pre `first` and `second` must iterate on same data type. - * - * [LinkLRAI]: https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator - * "LegacyRandomAccessIterator" - */ -template -auto make_zipped_cartesian_2d_output_iterator(FirstIter first, SecondIter second) -{ - using T = typename std::iterator_traits::value_type; - return make_zipped_vec_2d_output_iterator>(first, second); + return thrust::make_transform_output_iterator(zipped_out, detail::vec_2d_to_tuple()); } template > @@ -244,22 +133,6 @@ auto interleaved_iterator_to_vec_2d_iterator(Iter d_points_begin) return detail::make_counting_transform_iterator(0, interleaved_to_vec_2d{d_points_begin}); } -template -auto interleaved_iterator_to_cartesian_2d_iterator(Iter d_points_begin) -{ - using T = typename std::iterator_traits::value_type; - return detail::make_counting_transform_iterator( - 0, interleaved_to_vec_2d>{d_points_begin}); -} - -template -auto interleaved_iterator_to_lonlat_2d_iterator(Iter d_points_begin) -{ - using T = typename std::iterator_traits::value_type; - return detail::make_counting_transform_iterator( - 0, interleaved_to_vec_2d>{d_points_begin}); -} - /** * @} // end of doxygen group */ diff --git a/cpp/include/cuspatial/vec_2d.hpp b/cpp/include/cuspatial/vec_2d.hpp index 9fafc355b..46798f988 100644 --- a/cpp/include/cuspatial/vec_2d.hpp +++ b/cpp/include/cuspatial/vec_2d.hpp @@ -41,26 +41,6 @@ struct alignas(2 * sizeof(T)) vec_2d { value_type y; }; -/** - * @brief A geographical Longitude/Latitude (LonLat) coordinate pair - * - * `x` is the longitude coordinate, `y` is the latitude coordinate. - * - * @tparam T the base type for the coordinates - */ -template -struct alignas(2 * sizeof(T)) lonlat_2d : vec_2d { -}; - -/** - * @brief A Cartesian (x/y) coordinate pair. - * - * @tparam T the base type for the coordinates. - */ -template -struct alignas(2 * sizeof(T)) cartesian_2d : vec_2d { -}; - /** * @brief Compare two 2D vectors for equality. */ diff --git a/cpp/src/spatial/haversine.cu b/cpp/src/spatial/haversine.cu index 502337ef5..25ff800bd 100644 --- a/cpp/src/spatial/haversine.cu +++ b/cpp/src/spatial/haversine.cu @@ -56,8 +56,8 @@ struct haversine_functor { auto mask_policy = cudf::mask_allocation_policy::NEVER; auto result = cudf::allocate_like(a_lon, a_lon.size(), mask_policy, mr); - auto lonlat_a = cuspatial::make_lonlat_iterator(a_lon.begin(), a_lat.begin()); - auto lonlat_b = cuspatial::make_lonlat_iterator(b_lon.begin(), b_lat.begin()); + auto lonlat_a = cuspatial::make_vec_2d_iterator(a_lon.begin(), a_lat.begin()); + auto lonlat_b = cuspatial::make_vec_2d_iterator(b_lon.begin(), b_lat.begin()); cuspatial::haversine_distance(lonlat_a, lonlat_a + a_lon.size(), diff --git a/cpp/src/spatial/linestring_distance.cu b/cpp/src/spatial/linestring_distance.cu index 2497327cb..d34f60b48 100644 --- a/cpp/src/spatial/linestring_distance.cu +++ b/cpp/src/spatial/linestring_distance.cu @@ -63,9 +63,9 @@ struct pairwise_linestring_distance_functor { mr); auto linestring1_coords_it = - make_cartesian_2d_iterator(linestring1_points_x.begin(), linestring1_points_y.begin()); + make_vec_2d_iterator(linestring1_points_x.begin(), linestring1_points_y.begin()); auto linestring2_coords_it = - make_cartesian_2d_iterator(linestring2_points_x.begin(), linestring2_points_y.begin()); + make_vec_2d_iterator(linestring2_points_x.begin(), linestring2_points_y.begin()); pairwise_linestring_distance(linestring1_offsets.begin(), linestring1_offsets.end(), diff --git a/cpp/src/spatial/lonlat_to_cartesian.cu b/cpp/src/spatial/lonlat_to_cartesian.cu index a6e498eb5..4432abf35 100644 --- a/cpp/src/spatial/lonlat_to_cartesian.cu +++ b/cpp/src/spatial/lonlat_to_cartesian.cu @@ -63,12 +63,12 @@ struct lonlat_to_cartesian_functor { auto output_y = cudf::make_fixed_width_column(type, size, cudf::mask_state::UNALLOCATED, stream, mr); - auto lonlat_begin = cuspatial::make_lonlat_iterator(input_lon.begin(), input_lat.begin()); + auto lonlat_begin = cuspatial::make_vec_2d_iterator(input_lon.begin(), input_lat.begin()); - auto output_zip = cuspatial::make_zipped_cartesian_2d_output_iterator( + auto output_zip = cuspatial::make_zipped_vec_2d_output_iterator( output_x->mutable_view().begin(), output_y->mutable_view().begin()); - auto origin = cuspatial::lonlat_2d{origin_lon, origin_lat}; + auto origin = cuspatial::vec_2d{origin_lon, origin_lat}; cuspatial::lonlat_to_cartesian( lonlat_begin, lonlat_begin + input_lon.size(), output_zip, origin, stream); diff --git a/cpp/src/spatial/point_distance.cu b/cpp/src/spatial/point_distance.cu index b42d22ae5..a4127a05d 100644 --- a/cpp/src/spatial/point_distance.cu +++ b/cpp/src/spatial/point_distance.cu @@ -48,8 +48,8 @@ struct pairwise_point_distance_functor { stream, mr); - auto points1_it = make_cartesian_2d_iterator(points1_x.begin(), points1_y.begin()); - auto points2_it = make_cartesian_2d_iterator(points2_x.begin(), points2_y.begin()); + auto points1_it = make_vec_2d_iterator(points1_x.begin(), points1_y.begin()); + auto points2_it = make_vec_2d_iterator(points2_x.begin(), points2_y.begin()); pairwise_point_distance(points1_it, points1_it + points1_x.size(), diff --git a/cpp/src/spatial/point_in_polygon.cu b/cpp/src/spatial/point_in_polygon.cu index a64f7394b..cfda5c0ec 100644 --- a/cpp/src/spatial/point_in_polygon.cu +++ b/cpp/src/spatial/point_in_polygon.cu @@ -65,11 +65,11 @@ struct point_in_polygon_functor { if (results->size() == 0) { return results; } auto points_begin = - cuspatial::make_cartesian_2d_iterator(test_points_x.begin(), test_points_y.begin()); + cuspatial::make_vec_2d_iterator(test_points_x.begin(), test_points_y.begin()); auto polygon_offsets_begin = poly_offsets.begin(); auto ring_offsets_begin = poly_ring_offsets.begin(); auto polygon_points_begin = - cuspatial::make_cartesian_2d_iterator(poly_points_x.begin(), poly_points_y.begin()); + cuspatial::make_vec_2d_iterator(poly_points_x.begin(), poly_points_y.begin()); auto results_begin = results->mutable_view().begin(); cuspatial::point_in_polygon(points_begin, diff --git a/cpp/src/spatial/point_linestring_distance.cu b/cpp/src/spatial/point_linestring_distance.cu index 9ebaa4130..5341d5c96 100644 --- a/cpp/src/spatial/point_linestring_distance.cu +++ b/cpp/src/spatial/point_linestring_distance.cu @@ -53,9 +53,9 @@ struct pairwise_point_linestring_distance_functor { auto output = cudf::make_numeric_column( points_xy.type(), num_pairs, cudf::mask_state::UNALLOCATED, stream, mr); - auto points_it = interleaved_iterator_to_cartesian_2d_iterator(points_xy.begin()); + auto points_it = interleaved_iterator_to_vec_2d_iterator(points_xy.begin()); auto linestring_points_it = - interleaved_iterator_to_cartesian_2d_iterator(linestring_points_xy.begin()); + interleaved_iterator_to_vec_2d_iterator(linestring_points_xy.begin()); auto output_begin = output->mutable_view().begin(); pairwise_point_linestring_distance(points_it, diff --git a/cpp/src/spatial_window/spatial_window.cu b/cpp/src/spatial_window/spatial_window.cu index 3de5b0c59..7e29d0783 100644 --- a/cpp/src/spatial_window/spatial_window.cu +++ b/cpp/src/spatial_window/spatial_window.cu @@ -44,7 +44,7 @@ struct spatial_window_dispatch { rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - auto points_begin = cuspatial::make_cartesian_2d_iterator(x.begin(), y.begin()); + auto points_begin = cuspatial::make_vec_2d_iterator(x.begin(), y.begin()); auto window_min = cuspatial::vec_2d{static_cast(window_min_x), static_cast(window_min_y)}; @@ -63,7 +63,7 @@ struct spatial_window_dispatch { auto& output_x = cols[0]; auto& output_y = cols[1]; - auto output_zip = cuspatial::make_zipped_cartesian_2d_output_iterator( + auto output_zip = cuspatial::make_zipped_vec_2d_output_iterator( output_x->mutable_view().begin(), output_y->mutable_view().begin()); cuspatial::copy_points_in_range( diff --git a/cpp/tests/experimental/spatial/coordinate_transform_test.cu b/cpp/tests/experimental/spatial/coordinate_transform_test.cu index 8f78c9a6d..9fca83e71 100644 --- a/cpp/tests/experimental/spatial/coordinate_transform_test.cu +++ b/cpp/tests/experimental/spatial/coordinate_transform_test.cu @@ -34,8 +34,8 @@ TYPED_TEST_CASE(LonLatToCartesianTest, TestTypes); TYPED_TEST(LonLatToCartesianTest, Empty) { using T = TypeParam; - using Loc = cuspatial::lonlat_2d; - using Cart = cuspatial::cartesian_2d; + using Loc = cuspatial::vec_2d; + using Cart = cuspatial::vec_2d; auto origin = Loc{-90.66511046, 42.49197018}; @@ -57,8 +57,8 @@ TYPED_TEST(LonLatToCartesianTest, Empty) TYPED_TEST(LonLatToCartesianTest, Single) { using T = TypeParam; - using Loc = cuspatial::lonlat_2d; - using Cart = cuspatial::cartesian_2d; + using Loc = cuspatial::vec_2d; + using Cart = cuspatial::vec_2d; auto origin = Loc{-90.66511046, 42.49197018}; @@ -80,8 +80,8 @@ TYPED_TEST(LonLatToCartesianTest, Single) TYPED_TEST(LonLatToCartesianTest, Extremes) { using T = TypeParam; - using Loc = cuspatial::lonlat_2d; - using Cart = cuspatial::cartesian_2d; + using Loc = cuspatial::vec_2d; + using Cart = cuspatial::vec_2d; auto origin = Loc{0, 0}; @@ -109,8 +109,8 @@ TYPED_TEST(LonLatToCartesianTest, Extremes) TYPED_TEST(LonLatToCartesianTest, Multiple) { using T = TypeParam; - using Loc = cuspatial::lonlat_2d; - using Cart = cuspatial::cartesian_2d; + using Loc = cuspatial::vec_2d; + using Cart = cuspatial::vec_2d; auto origin = Loc{-90.66511046, 42.49197018}; @@ -140,8 +140,8 @@ TYPED_TEST(LonLatToCartesianTest, Multiple) TYPED_TEST(LonLatToCartesianTest, OriginOutOfBounds) { using T = TypeParam; - using Loc = cuspatial::lonlat_2d; - using Cart = cuspatial::cartesian_2d; + using Loc = cuspatial::vec_2d; + using Cart = cuspatial::vec_2d; auto origin = Loc{-181, -91}; @@ -160,7 +160,7 @@ TYPED_TEST(LonLatToCartesianTest, OriginOutOfBounds) template struct identity_xform { - using Location = cuspatial::lonlat_2d; + using Location = cuspatial::vec_2d; __device__ Location operator()(Location const& loc) { return loc; }; }; @@ -168,8 +168,8 @@ struct identity_xform { TYPED_TEST(LonLatToCartesianTest, TransformIterator) { using T = TypeParam; - using Loc = cuspatial::lonlat_2d; - using Cart = cuspatial::cartesian_2d; + using Loc = cuspatial::vec_2d; + using Cart = cuspatial::vec_2d; auto origin = Loc{-90.66511046, 42.49197018}; diff --git a/cpp/tests/experimental/spatial/haversine_test.cu b/cpp/tests/experimental/spatial/haversine_test.cu index 77b9223c9..b9cbe5b07 100644 --- a/cpp/tests/experimental/spatial/haversine_test.cu +++ b/cpp/tests/experimental/spatial/haversine_test.cu @@ -34,7 +34,7 @@ TYPED_TEST_CASE(HaversineTest, TestTypes); TYPED_TEST(HaversineTest, Empty) { using T = TypeParam; - using Location = cuspatial::lonlat_2d; + using Location = cuspatial::vec_2d; auto a_lonlat = rmm::device_vector{}; auto b_lonlat = rmm::device_vector{}; @@ -52,7 +52,7 @@ TYPED_TEST(HaversineTest, Empty) TYPED_TEST(HaversineTest, Zero) { using T = TypeParam; - using Location = cuspatial::lonlat_2d; + using Location = cuspatial::vec_2d; using LocVec = std::vector; auto a_lonlat = rmm::device_vector(1, Location{0, 0}); @@ -71,7 +71,7 @@ TYPED_TEST(HaversineTest, Zero) TYPED_TEST(HaversineTest, NegativeRadius) { using T = TypeParam; - using Location = cuspatial::lonlat_2d; + using Location = cuspatial::vec_2d; using LocVec = std::vector; auto a_lonlat = rmm::device_vector(LocVec({Location{1, 1}, Location{0, 0}})); @@ -88,7 +88,7 @@ TYPED_TEST(HaversineTest, NegativeRadius) TYPED_TEST(HaversineTest, EquivalentPoints) { using T = TypeParam; - using Location = cuspatial::lonlat_2d; + using Location = cuspatial::vec_2d; auto h_a_lonlat = std::vector({{-180, 0}, {180, 30}}); auto h_b_lonlat = std::vector({{180, 0}, {-180, 30}}); @@ -110,7 +110,7 @@ TYPED_TEST(HaversineTest, EquivalentPoints) template struct identity_xform { - using Location = cuspatial::lonlat_2d; + using Location = cuspatial::vec_2d; __device__ Location operator()(Location const& loc) { return loc; }; }; @@ -118,7 +118,7 @@ struct identity_xform { TYPED_TEST(HaversineTest, TransformIterator) { using T = TypeParam; - using Location = cuspatial::lonlat_2d; + using Location = cuspatial::vec_2d; auto h_a_lonlat = std::vector({{-180, 0}, {180, 30}}); auto h_b_lonlat = std::vector({{180, 0}, {-180, 30}}); diff --git a/cpp/tests/experimental/spatial/linestring_distance_test.cu b/cpp/tests/experimental/spatial/linestring_distance_test.cu index 2dbdfcd36..de523f005 100644 --- a/cpp/tests/experimental/spatial/linestring_distance_test.cu +++ b/cpp/tests/experimental/spatial/linestring_distance_test.cu @@ -47,11 +47,11 @@ TYPED_TEST_CASE(PairwiseLinestringDistanceTest, TestTypes); TYPED_TEST(PairwiseLinestringDistanceTest, FromSeparateArrayInputs) { using T = TypeParam; - using CartVec = std::vector>; + using CartVec = std::vector>; - auto a_cart2d = rmm::device_vector>{ + auto a_cart2d = rmm::device_vector>{ CartVec({{0.0f, 0.0f}, {1.0f, 0.0f}, {2.0f, 0.0f}, {3.0f, 0.0f}, {4.0f, 0.0f}})}; - auto b_cart2d = rmm::device_vector>{ + auto b_cart2d = rmm::device_vector>{ CartVec({{0.0f, 1.0f}, {1.0f, 1.0f}, {2.0f, 1.0f}, {3.0f, 1.0f}, {4.0f, 1.0f}})}; auto offset = rmm::device_vector{std::vector{0}}; @@ -73,9 +73,9 @@ TYPED_TEST(PairwiseLinestringDistanceTest, FromSeparateArrayInputs) TYPED_TEST(PairwiseLinestringDistanceTest, FromSamePointArrayInput) { using T = TypeParam; - using CartVec = std::vector>; + using CartVec = std::vector>; - auto cart2ds = rmm::device_vector>{ + auto cart2ds = rmm::device_vector>{ CartVec({{0.0f, 0.0f}, {1.0f, 0.0f}, {2.0f, 0.0f}, {3.0f, 0.0f}, {4.0f, 0.0f}})}; auto offset = rmm::device_vector{std::vector{0}}; @@ -96,18 +96,18 @@ TYPED_TEST(PairwiseLinestringDistanceTest, FromSamePointArrayInput) TYPED_TEST(PairwiseLinestringDistanceTest, FromTransformIterator) { using T = TypeParam; - using CartVec = std::vector>; + using CartVec = std::vector>; auto a_cart2d_x = rmm::device_vector{std::vector{0.0, 1.0, 2.0, 3.0, 4.0}}; auto a_cart2d_y = rmm::device_vector(5, 0.0); - auto a_begin = make_cartesian_2d_iterator(a_cart2d_x.begin(), a_cart2d_y.begin()); + auto a_begin = make_vec_2d_iterator(a_cart2d_x.begin(), a_cart2d_y.begin()); auto a_end = a_begin + a_cart2d_x.size(); auto b_cart2d_x = rmm::device_vector{std::vector{0.0, 1.0, 2.0, 3.0, 4.0}}; auto b_cart2d_y = rmm::device_vector(5, 1.0); - auto b_begin = make_cartesian_2d_iterator(b_cart2d_x.begin(), b_cart2d_y.begin()); + auto b_begin = make_vec_2d_iterator(b_cart2d_x.begin(), b_cart2d_y.begin()); auto b_end = b_begin + b_cart2d_x.size(); auto offset = rmm::device_vector{std::vector{0}}; @@ -124,15 +124,15 @@ TYPED_TEST(PairwiseLinestringDistanceTest, FromTransformIterator) TYPED_TEST(PairwiseLinestringDistanceTest, FromMixedIterator) { using T = TypeParam; - using CartVec = std::vector>; + using CartVec = std::vector>; - auto a_cart2d = rmm::device_vector>{ + auto a_cart2d = rmm::device_vector>{ CartVec({{0.0f, 0.0f}, {1.0f, 0.0f}, {2.0f, 0.0f}, {3.0f, 0.0f}, {4.0f, 0.0f}})}; auto b_cart2d_x = rmm::device_vector{std::vector{0.0, 1.0, 2.0, 3.0, 4.0}}; auto b_cart2d_y = rmm::device_vector(5, 1.0); - auto b_begin = make_cartesian_2d_iterator(b_cart2d_x.begin(), b_cart2d_y.begin()); + auto b_begin = make_vec_2d_iterator(b_cart2d_x.begin(), b_cart2d_y.begin()); auto b_end = b_begin + b_cart2d_x.size(); auto offset = rmm::device_vector{std::vector{0}}; @@ -155,18 +155,18 @@ TYPED_TEST(PairwiseLinestringDistanceTest, FromMixedIterator) TYPED_TEST(PairwiseLinestringDistanceTest, FromLongInputs) { using T = TypeParam; - using CartVec = std::vector>; + using CartVec = std::vector>; auto num_points = 1000; auto a_cart2d_x_begin = thrust::make_constant_iterator(T{0.0}); auto a_cart2d_y_begin = thrust::make_counting_iterator(T{0.0}); - auto a_cart2d_begin = make_cartesian_2d_iterator(a_cart2d_x_begin, a_cart2d_y_begin); + auto a_cart2d_begin = make_vec_2d_iterator(a_cart2d_x_begin, a_cart2d_y_begin); auto a_cart2d_end = a_cart2d_begin + num_points; auto b_cart2d_x_begin = thrust::make_constant_iterator(T{42.0}); auto b_cart2d_y_begin = thrust::make_counting_iterator(T{0.0}); - auto b_cart2d_begin = make_cartesian_2d_iterator(b_cart2d_x_begin, b_cart2d_y_begin); + auto b_cart2d_begin = make_vec_2d_iterator(b_cart2d_x_begin, b_cart2d_y_begin); auto b_cart2d_end = b_cart2d_begin + num_points; auto offset = rmm::device_vector{std::vector{0, 100, 200, 300, 400}}; diff --git a/cpp/tests/experimental/spatial/point_distance_test.cu b/cpp/tests/experimental/spatial/point_distance_test.cu index 8776c9eb1..12fd3d022 100644 --- a/cpp/tests/experimental/spatial/point_distance_test.cu +++ b/cpp/tests/experimental/spatial/point_distance_test.cu @@ -66,7 +66,7 @@ TYPED_TEST_CASE(PairwisePointDistanceTest, TestTypes); TYPED_TEST(PairwisePointDistanceTest, Empty) { using T = TypeParam; - using Cart2D = cartesian_2d; + using Cart2D = vec_2d; using Cart2DVec = std::vector; rmm::device_vector points1{}; @@ -85,7 +85,7 @@ TYPED_TEST(PairwisePointDistanceTest, Empty) TYPED_TEST(PairwisePointDistanceTest, OnePair) { using T = TypeParam; - using Cart2D = cartesian_2d; + using Cart2D = vec_2d; using Cart2DVec = std::vector; rmm::device_vector points1{Cart2DVec{{1.0, 1.0}}}; @@ -103,7 +103,7 @@ TYPED_TEST(PairwisePointDistanceTest, OnePair) template struct RandomPointGenerator { - using Cart2D = cartesian_2d; + using Cart2D = vec_2d; thrust::minstd_rand rng{}; thrust::random::normal_distribution norm_dist{}; @@ -117,7 +117,7 @@ struct RandomPointGenerator { TYPED_TEST(PairwisePointDistanceTest, ManyRandom) { using T = TypeParam; - using Cart2D = cartesian_2d; + using Cart2D = vec_2d; using Cart2DVec = std::vector; std::size_t constexpr num_points = 1000; @@ -151,7 +151,7 @@ TYPED_TEST(PairwisePointDistanceTest, ManyRandom) TYPED_TEST(PairwisePointDistanceTest, CompareWithShapely) { using T = TypeParam; - using Cart2D = cartesian_2d; + using Cart2D = vec_2d; using Cart2DVec = std::vector; std::vector x1{ @@ -291,8 +291,8 @@ TYPED_TEST(PairwisePointDistanceTest, CompareWithShapely) rmm::device_vector dx1(x1), dy1(y1), dx2(x2), dy2(y2); rmm::device_vector got(dx1.size()); - auto p1_begin = make_cartesian_2d_iterator(dx1.begin(), dy1.begin()); - auto p2_begin = make_cartesian_2d_iterator(dx2.begin(), dy2.begin()); + auto p1_begin = make_vec_2d_iterator(dx1.begin(), dy1.begin()); + auto p2_begin = make_vec_2d_iterator(dx2.begin(), dy2.begin()); auto ret_it = pairwise_point_distance(p1_begin, p1_begin + dx1.size(), p2_begin, got.begin()); diff --git a/cpp/tests/experimental/spatial/point_in_polygon_test.cu b/cpp/tests/experimental/spatial/point_in_polygon_test.cu index dd00114e4..279c982ae 100644 --- a/cpp/tests/experimental/spatial/point_in_polygon_test.cu +++ b/cpp/tests/experimental/spatial/point_in_polygon_test.cu @@ -32,9 +32,9 @@ using namespace cuspatial; template struct PointInPolygonTest : public ::testing::Test { public: - rmm::device_vector> make_device_points(std::initializer_list> pts) + rmm::device_vector> make_device_points(std::initializer_list> pts) { - return rmm::device_vector>(pts.begin(), pts.end()); + return rmm::device_vector>(pts.begin(), pts.end()); } rmm::device_vector make_device_offsets(std::initializer_list pts) @@ -271,7 +271,7 @@ TYPED_TEST(PointInPolygonTest, 31PolygonSupport) thrust::make_transform_iterator(offsets_iter, PolyPointIteratorFunctorA{}); auto poly_point_ys_iter = thrust::make_transform_iterator(offsets_iter, PolyPointIteratorFunctorB{}); - auto poly_point_iter = make_cartesian_2d_iterator(poly_point_xs_iter, poly_point_ys_iter); + auto poly_point_iter = make_vec_2d_iterator(poly_point_xs_iter, poly_point_ys_iter); auto expected = std::vector({0b1111111111111111111111111111111, 0b0000000000000000000000000000000}); diff --git a/cpp/tests/experimental/spatial/point_linestring_distance_test.cu b/cpp/tests/experimental/spatial/point_linestring_distance_test.cu index e0d44fc0f..81de3f1c8 100644 --- a/cpp/tests/experimental/spatial/point_linestring_distance_test.cu +++ b/cpp/tests/experimental/spatial/point_linestring_distance_test.cu @@ -44,15 +44,15 @@ TYPED_TEST_CASE(PairwisePointLinestringDistanceTest, TestTypes); TYPED_TEST(PairwisePointLinestringDistanceTest, Empty) { using T = TypeParam; - using CartVec = std::vector>; + using CartVec = std::vector>; CartVec points{}; std::vector linestring_offsets{0}; CartVec linestring_points{}; - rmm::device_vector> d_points(points); + rmm::device_vector> d_points(points); rmm::device_vector d_offsets(linestring_offsets); - rmm::device_vector> d_linestring_points(linestring_points); + rmm::device_vector> d_linestring_points(linestring_points); rmm::device_vector got{}; @@ -72,16 +72,16 @@ TYPED_TEST(PairwisePointLinestringDistanceTest, Empty) TYPED_TEST(PairwisePointLinestringDistanceTest, OnePairFromVector) { using T = TypeParam; - using CartVec = std::vector>; + using CartVec = std::vector>; CartVec points{{0, 0}}; std::vector linestring_offsets{0, 3}; CartVec linestring_points{{1, 1}, {2, 2}, {3, 3}}; thrust::host_vector expect(std::vector{std::sqrt(T{2.0})}); - rmm::device_vector> d_points(points); + rmm::device_vector> d_points(points); rmm::device_vector d_offsets(linestring_offsets); - rmm::device_vector> d_linestring_points(linestring_points); + rmm::device_vector> d_linestring_points(linestring_points); rmm::device_vector got(points.size()); @@ -99,16 +99,16 @@ TYPED_TEST(PairwisePointLinestringDistanceTest, OnePairFromVector) TYPED_TEST(PairwisePointLinestringDistanceTest, TwoPairFromVector) { using T = TypeParam; - using CartVec = std::vector>; + using CartVec = std::vector>; CartVec points{{0, 0}, {0, 0}}; std::vector linestring_offsets{0, 3, 6}; CartVec linestring_points{{1, 1}, {2, 2}, {3, 3}, {-1, -1}, {-2, -2}, {-3, -3}}; thrust::host_vector expect(std::vector{std::sqrt(T{2.0}), std::sqrt(T{2.0})}); - rmm::device_vector> d_points(points); + rmm::device_vector> d_points(points); rmm::device_vector d_offsets(linestring_offsets); - rmm::device_vector> d_linestring_points(linestring_points); + rmm::device_vector> d_linestring_points(linestring_points); rmm::device_vector got(points.size()); @@ -137,12 +137,12 @@ TYPED_TEST(PairwisePointLinestringDistanceTest, ManyPairsFromIterators) auto linestring_points_x = thrust::make_counting_iterator(T{0.0}); auto linestring_points_y = thrust::make_constant_iterator(T{1.0}); - auto linestring_points = make_cartesian_2d_iterator(linestring_points_x, linestring_points_y); + auto linestring_points = make_vec_2d_iterator(linestring_points_x, linestring_points_y); auto offsets = detail::make_counting_transform_iterator(0, times_three_functor{}); auto points_x = detail::make_counting_transform_iterator(T{0.0}, times_three_functor{}); auto points_y = thrust::make_constant_iterator(T{0.0}); - auto points = make_cartesian_2d_iterator(points_x, points_y); + auto points = make_vec_2d_iterator(points_x, points_y); std::vector expect(num_pairs, T{1.0}); rmm::device_vector got(num_pairs); @@ -161,7 +161,7 @@ TYPED_TEST(PairwisePointLinestringDistanceTest, ManyPairsFromIterators) TYPED_TEST(PairwisePointLinestringDistanceTest, FiftyPairsCompareWithShapely) { using T = TypeParam; - using CartVec = std::vector>; + using CartVec = std::vector>; // All point coordinates are confined in [-1e9, 0] inverval auto d_points_x = rmm::device_vector(std::vector{ @@ -292,9 +292,9 @@ TYPED_TEST(PairwisePointLinestringDistanceTest, FiftyPairsCompareWithShapely) auto offsets = detail::make_counting_transform_iterator(0, times_three_functor{}); - auto points = make_cartesian_2d_iterator(d_points_x.begin(), d_points_y.begin()); + auto points = make_vec_2d_iterator(d_points_x.begin(), d_points_y.begin()); auto linestring_points = - make_cartesian_2d_iterator(d_linestring_points_x.begin(), d_linestring_points_y.begin()); + make_vec_2d_iterator(d_linestring_points_x.begin(), d_linestring_points_y.begin()); rmm::device_vector got(d_points_x.size());