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

Expand expect_vector_equivalent to handle std::vector of vec_2d<T> and move traits out of detail #669

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion cpp/doc/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ An example function is helpful.
template <class LonLatItA,
class LonLatItB,
class OutputIt,
class T = typename detail::iterator_vec_base_type<LonLatItA>>
class T = typename cuspatial::iterator_vec_base_type<LonLatItA>>
OutputIt haversine_distance(LonLatItA a_lonlat_first,
LonLatItA a_lonlat_last,
LonLatItB b_lonlat_first,
Expand Down
14 changes: 7 additions & 7 deletions cpp/doc/libcuspatial_refactoring_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ This is the existing API, unchanged by refactoring. Here is the existing
template <class LonLatItA,
class LonLatItB,
class OutputIt,
class T = typename detail::iterator_vec_base_type<LonLatItA>>
class T = typename cuspatial::iterator_vec_base_type<LonLatItA>>
OutputIt haversine_distance(LonLatItA a_lonlat_first,
LonLatItA a_lonlat_last,
LonLatItB b_lonlat_first,
Expand Down Expand Up @@ -196,14 +196,14 @@ OutputIt haversine_distance(LonLatItA a_lonlat_first,
T const radius,
rmm::cuda_stream_view stream)
{
static_assert(detail::is_same<vec_2d<T>,
detail::iterator_value_type<LonLatItA>,
detail::iterator_value_type<LonLatItB>>(),
static_assert(is_same<vec_2d<T>,
cuspatial::iterator_value_type<LonLatItA>,
cuspatial::iterator_value_type<LonLatItB>>(),
"Inputs must be cuspatial::vec_2d");
static_assert(
detail::is_same_floating_point<T,
typename detail::iterator_vec_base_type<LonLatItA>,
typename detail::iterator_value_type<OutputIt>>(),
is_same_floating_point<T,
typename cuspatial::iterator_vec_base_type<LonLatItA>,
typename cuspatial::iterator_value_type<OutputIt>>(),
"All iterator types and radius must have the same floating-point coordinate value type.");

CUSPATIAL_EXPECTS(radius > 0, "radius must be positive.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include <cuspatial/constants.hpp>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand Down Expand Up @@ -74,8 +75,8 @@ OutputIt lonlat_to_cartesian(InputIt lon_lat_first,
vec_2d<T> origin,
rmm::cuda_stream_view stream)
{
static_assert(std::is_floating_point_v<T>,
"lonlat_to_cartesian supports only floating-point coordinates.");
static_assert(is_same_floating_point<T, iterator_vec_base_type<InputIt>>(),
"Origin and input must have the same base floating point type.");

CUSPATIAL_EXPECTS(origin.x >= -180 && origin.x <= 180 && origin.y >= -90 && origin.y <= 90,
"origin must have valid longitude [-180, 180] and latitude [-90, 90]");
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/cuspatial/experimental/detail/hausdorff.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#pragma once

#include <cuspatial/detail/utility/device_atomics.cuh>
#include <cuspatial/detail/utility/traits.hpp>
#include <cuspatial/error.hpp>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand Down Expand Up @@ -150,7 +150,7 @@ OutputIt directed_hausdorff_distance(PointIt points_first,

static_assert(std::is_convertible_v<Point, cuspatial::vec_2d<T>>,
"Input points must be convertible to cuspatial::vec_2d");
static_assert(detail::is_floating_point<T, OutputT>(),
static_assert(is_floating_point<T, OutputT>(),
"Hausdorff supports only floating-point coordinates.");
static_assert(std::is_integral_v<Index>, "Indices must be integral");

Expand Down
15 changes: 7 additions & 8 deletions cpp/include/cuspatial/experimental/detail/haversine.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#pragma once

#include <cuspatial/constants.hpp>
#include <cuspatial/detail/utility/traits.hpp>
#include <cuspatial/error.hpp>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand Down Expand Up @@ -66,14 +66,13 @@ OutputIt haversine_distance(LonLatItA a_lonlat_first,
T const radius,
rmm::cuda_stream_view stream)
{
static_assert(detail::is_same<vec_2d<T>,
detail::iterator_value_type<LonLatItA>,
detail::iterator_value_type<LonLatItB>>(),
"Inputs must be cuspatial::vec_2d");
static_assert(
detail::is_same_floating_point<T,
typename detail::iterator_vec_base_type<LonLatItA>,
typename detail::iterator_value_type<OutputIt>>(),
is_same<vec_2d<T>, iterator_value_type<LonLatItA>, iterator_value_type<LonLatItB>>(),
"Inputs must be cuspatial::vec_2d");
static_assert(
is_same_floating_point<T,
typename cuspatial::iterator_vec_base_type<LonLatItA>,
typename cuspatial::iterator_value_type<OutputIt>>(),
"All iterator types and radius must have the same floating-point coordinate value type.");

CUSPATIAL_EXPECTS(radius > 0, "radius must be positive.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include <cuspatial/detail/utility/device_atomics.cuh>
#include <cuspatial/detail/utility/linestring.cuh>
#include <cuspatial/detail/utility/traits.hpp>
#include <cuspatial/error.hpp>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand Down Expand Up @@ -148,16 +148,16 @@ void pairwise_linestring_distance(OffsetIterator linestring1_offsets_first,
OutputIt distances_first,
rmm::cuda_stream_view stream)
{
using T = typename detail::iterator_vec_base_type<Cart2dItA>;
using T = typename cuspatial::iterator_vec_base_type<Cart2dItA>;

static_assert(detail::is_same_floating_point<T,
typename detail::iterator_vec_base_type<Cart2dItB>,
typename detail::iterator_value_type<OutputIt>>(),
static_assert(is_same_floating_point<T,
typename cuspatial::iterator_vec_base_type<Cart2dItB>,
typename cuspatial::iterator_value_type<OutputIt>>(),
"Inputs and output must have the same floating point value type.");

static_assert(detail::is_same<vec_2d<T>,
typename detail::iterator_value_type<Cart2dItA>,
typename detail::iterator_value_type<Cart2dItB>>(),
static_assert(is_same<vec_2d<T>,
typename cuspatial::iterator_value_type<Cart2dItA>,
typename cuspatial::iterator_value_type<Cart2dItB>>(),
"All input types must be cuspatial::vec_2d with the same value type");

auto const num_linestring_pairs =
Expand Down
16 changes: 8 additions & 8 deletions cpp/include/cuspatial/experimental/detail/point_distance.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#pragma once

#include <cuspatial/detail/utility/traits.hpp>
#include <cuspatial/error.hpp>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand All @@ -36,16 +36,16 @@ OutputIt pairwise_point_distance(Cart2dItA points1_first,
OutputIt distances_first,
rmm::cuda_stream_view stream)
{
using T = typename detail::iterator_vec_base_type<Cart2dItA>;
using T = typename cuspatial::iterator_vec_base_type<Cart2dItA>;

static_assert(detail::is_same_floating_point<T,
typename detail::iterator_vec_base_type<Cart2dItB>,
typename detail::iterator_value_type<OutputIt>>(),
static_assert(is_same_floating_point<T,
typename cuspatial::iterator_vec_base_type<Cart2dItB>,
typename cuspatial::iterator_value_type<OutputIt>>(),
"Inputs and output must have the same floating point value type.");

static_assert(detail::is_same<vec_2d<T>,
typename detail::iterator_value_type<Cart2dItA>,
typename detail::iterator_value_type<Cart2dItB>>(),
static_assert(is_same<vec_2d<T>,
typename cuspatial::iterator_value_type<Cart2dItA>,
typename cuspatial::iterator_value_type<Cart2dItB>>(),
"All Input types must be cuspatial::vec_2d with the same value type");

return thrust::transform(rmm::exec_policy(stream),
Expand Down
19 changes: 9 additions & 10 deletions cpp/include/cuspatial/experimental/detail/point_in_polygon.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#pragma once

#include <cuspatial/detail/utility/traits.hpp>
#include <cuspatial/error.hpp>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand Down Expand Up @@ -161,25 +161,24 @@ OutputIt point_in_polygon(Cart2dItA test_points_first,
OutputIt output,
rmm::cuda_stream_view stream)
{
using T = detail::iterator_vec_base_type<Cart2dItA>;
using T = iterator_vec_base_type<Cart2dItA>;

auto const num_test_points = std::distance(test_points_first, test_points_last);
auto const num_polys = std::distance(polygon_offsets_first, polygon_offsets_last);
auto const num_rings = std::distance(poly_ring_offsets_first, poly_ring_offsets_last);
auto const num_poly_points = std::distance(polygon_points_first, polygon_points_last);

static_assert(detail::is_same_floating_point<T, detail::iterator_vec_base_type<Cart2dItB>>(),
static_assert(is_same_floating_point<T, iterator_vec_base_type<Cart2dItB>>(),
"Underlying type of Cart2dItA and Cart2dItB must be the same floating point type");
static_assert(detail::is_same<vec_2d<T>,
detail::iterator_value_type<Cart2dItA>,
detail::iterator_value_type<Cart2dItB>>(),
"Inputs must be cuspatial::vec_2d");
static_assert(
is_same<vec_2d<T>, iterator_value_type<Cart2dItA>, iterator_value_type<Cart2dItB>>(),
"Inputs must be cuspatial::vec_2d");

static_assert(detail::is_integral<detail::iterator_value_type<OffsetIteratorA>,
detail::iterator_value_type<OffsetIteratorB>>(),
static_assert(cuspatial::is_integral<iterator_value_type<OffsetIteratorA>,
iterator_value_type<OffsetIteratorB>>(),
"OffsetIterators must point to integral type.");

static_assert(std::is_same_v<detail::iterator_value_type<OutputIt>, int32_t>,
static_assert(std::is_same_v<iterator_value_type<OutputIt>, int32_t>,
"OutputIt must point to 32 bit integer type.");

CUSPATIAL_EXPECTS(num_polys <= std::numeric_limits<int32_t>::digits,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#include <cuspatial/detail/utility/device_atomics.cuh>
#include <cuspatial/detail/utility/linestring.cuh>
#include <cuspatial/detail/utility/traits.hpp>
#include <cuspatial/error.hpp>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand Down Expand Up @@ -169,15 +169,14 @@ OutputIt pairwise_point_linestring_distance(OffsetIteratorA point_geometry_offse
OutputIt distances_first,
rmm::cuda_stream_view stream)
{
using T = detail::iterator_vec_base_type<Cart2dItA>;
using T = iterator_vec_base_type<Cart2dItA>;

static_assert(detail::is_same_floating_point<T, detail::iterator_vec_base_type<Cart2dItB>>(),
static_assert(is_same_floating_point<T, iterator_vec_base_type<Cart2dItB>>(),
"Inputs must have same floating point value type.");

static_assert(detail::is_same<vec_2d<T>,
detail::iterator_value_type<Cart2dItA>,
detail::iterator_value_type<Cart2dItB>>(),
"Inputs must be cuspatial::vec_2d");
static_assert(
is_same<vec_2d<T>, iterator_value_type<Cart2dItA>, iterator_value_type<Cart2dItB>>(),
"Inputs must be cuspatial::vec_2d");

auto const num_pairs =
thrust::distance(point_geometry_offset_first, point_geometry_offset_last) - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#pragma once

#include <cuspatial/detail/utility/traits.hpp>
#include <cuspatial/error.hpp>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

#include <rmm/cuda_stream_view.hpp>
Expand Down Expand Up @@ -63,7 +63,7 @@ typename thrust::iterator_traits<InputIt>::difference_type count_points_in_range
{
using Point = typename std::iterator_traits<InputIt>::value_type;

static_assert(detail::is_convertible_to<cuspatial::vec_2d<T>, Point>(),
static_assert(cuspatial::is_convertible_to<cuspatial::vec_2d<T>, Point>(),
"Input points must be convertible to cuspatial::vec_2d");

return thrust::count_if(
Expand All @@ -80,10 +80,10 @@ OutputIt copy_points_in_range(vec_2d<T> vertex_1,
{
using Point = typename std::iterator_traits<InputIt>::value_type;

static_assert(detail::is_convertible_to<cuspatial::vec_2d<T>, Point>(),
static_assert(cuspatial::is_convertible_to<cuspatial::vec_2d<T>, Point>(),
"Input points must be convertible to cuspatial::vec_2d");

static_assert(detail::is_same_floating_point<T, typename Point::value_type>(),
static_assert(is_same_floating_point<T, typename Point::value_type>(),
"Inputs and Range coordinates must have the same value type.");

return thrust::copy_if(rmm::exec_policy(stream),
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/cuspatial/experimental/haversine.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#pragma once

#include <cuspatial/constants.hpp>
#include <cuspatial/detail/utility/traits.hpp>
#include <cuspatial/traits.hpp>

#include <rmm/cuda_stream_view.hpp>

Expand Down Expand Up @@ -66,7 +66,7 @@ namespace cuspatial {
template <class LonLatItA,
class LonLatItB,
class OutputIt,
class T = typename detail::iterator_vec_base_type<LonLatItA>>
class T = typename cuspatial::iterator_vec_base_type<LonLatItA>>
OutputIt haversine_distance(LonLatItA a_lonlat_first,
LonLatItA a_lonlat_last,
LonLatItB b_lonlat_first,
Expand Down
5 changes: 2 additions & 3 deletions cpp/include/cuspatial/experimental/type_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

#include <cuspatial/detail/iterator.hpp>
#include <cuspatial/detail/utility/traits.hpp>
#include <cuspatial/traits.hpp>
#include <cuspatial/vec_2d.hpp>

#include <thrust/iterator/transform_iterator.h>
Expand Down Expand Up @@ -84,8 +84,7 @@ template <typename FirstIter, typename SecondIter>
auto make_vec_2d_iterator(FirstIter first, SecondIter second)
{
using T = typename std::iterator_traits<FirstIter>::value_type;
static_assert(detail::is_same<T, detail::iterator_value_type<SecondIter>>(),
"Iterator value_type mismatch");
static_assert(is_same<T, iterator_value_type<SecondIter>>(), "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<T>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

#pragma once

#include <cuspatial/vec_2d.hpp>

#include <iterator>
#include <type_traits>

namespace cuspatial {
namespace detail {

/**
* @internal
Expand Down Expand Up @@ -62,6 +63,16 @@ constexpr bool is_integral()
return std::conjunction_v<std::is_integral<Ts>...>;
}

/**
* @internal
* @brief returns true if `T` is `vec_2d<float>` or `vec_2d<double>`
*/
template <typename T>
constexpr bool is_vec_2d()
{
return std::is_same_v<T, vec_2d<float>> or std::is_same_v<T, vec_2d<double>>;
}

/**
* @internal
* @brief returns true if T and all types Ts... are the same floating point type.
Expand Down Expand Up @@ -89,7 +100,6 @@ using iterator_value_type = typename std::iterator_traits<Iterator>::value_type;
* @tparam Iterator The value type to get from, must point to a cuspatial::vec_2d
*/
template <typename Iterator>
using iterator_vec_base_type = typename iterator_value_type<Iterator>::value_type;
using iterator_vec_base_type = typename cuspatial::iterator_value_type<Iterator>::value_type;

} // namespace detail
} // namespace cuspatial
11 changes: 11 additions & 0 deletions cpp/include/cuspatial/vec_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <cuspatial/cuda_utils.hpp>

#include <ostream>

namespace cuspatial {

/**
Expand All @@ -41,6 +43,15 @@ struct alignas(2 * sizeof(T)) vec_2d {
value_type y;
};

/**
* @brief Output stream operator for `vec_2d<T>` for human-readable formatting
*/
template <typename T>
std::ostream& operator<<(std::ostream& os, cuspatial::vec_2d<T> const& vec)
{
return os << "(" << vec.x << "," << vec.y << ")";
}

/**
* @brief Compare two 2D vectors for equality.
*/
Expand Down
Loading