Skip to content

Commit

Permalink
polygon distance: rename from polygon separation
Browse files Browse the repository at this point in the history
  • Loading branch information
cwharris committed Jul 21, 2020
1 parent 0679517 commit 8258698
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 48 deletions.
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ add_library(cuspatial SHARED
src/join/quadtree_poly_filtering.cu
src/spatial/polygon_bounding_box.cu
src/spatial/polyline_bounding_box.cu
src/spatial/polygon_separation.cu
src/spatial/polygon_distance.cu
src/spatial/point_in_polygon.cu
src/spatial_window/spatial_window.cu
src/spatial/haversine.cu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace cuspatial {

std::unique_ptr<cudf::column> directed_polygon_separation(
std::unique_ptr<cudf::column> directed_polygon_distance(
cudf::column_view const& xs,
cudf::column_view const& ys,
cudf::column_view const& space_offsets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct segment_point_distance_calculator {
}
};

struct directed_polygon_separation_functor {
struct directed_polygon_distance_functor {
template <typename T, typename... Args>
std::enable_if_t<not std::is_floating_point<T>::value, std::unique_ptr<cudf::column>> operator()(
Args&&...)
Expand Down Expand Up @@ -141,10 +141,10 @@ struct directed_polygon_separation_functor {
} // namespace
} // namespace detail

std::unique_ptr<cudf::column> directed_polygon_separation(cudf::column_view const& xs,
cudf::column_view const& ys,
cudf::column_view const& points_per_space,
rmm::mr::device_memory_resource* mr)
std::unique_ptr<cudf::column> directed_polygon_distance(cudf::column_view const& xs,
cudf::column_view const& ys,
cudf::column_view const& points_per_space,
rmm::mr::device_memory_resource* mr)
{
CUSPATIAL_EXPECTS(xs.type() == ys.type(), "Inputs `xs` and `ys` must have same type.");
CUSPATIAL_EXPECTS(xs.size() == ys.size(), "Inputs `xs` and `ys` must have same length.");
Expand All @@ -158,7 +158,7 @@ std::unique_ptr<cudf::column> directed_polygon_separation(cudf::column_view cons
cudaStream_t stream = 0;

return cudf::type_dispatcher(
xs.type(), detail::directed_polygon_separation_functor(), xs, ys, points_per_space, mr, stream);
xs.type(), detail::directed_polygon_distance_functor(), xs, ys, points_per_space, mr, stream);
}

} // namespace cuspatial
2 changes: 1 addition & 1 deletion cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ set(HAUSDORFF_TEST_SRC
ConfigureTest(HAUSDORFF_TEST "${HAUSDORFF_TEST_SRC}")

set(POLYGON_SEPARATION_TEST_SRC
"${CMAKE_CURRENT_SOURCE_DIR}/spatial/polygon_separation_test.cpp")
"${CMAKE_CURRENT_SOURCE_DIR}/spatial/polygon_distance_test.cpp")
ConfigureTest(POLYGON_SEPARATION_TEST "${POLYGON_SEPARATION_TEST_SRC}")

set(POINT_IN_POLYGON_TEST_SRC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@
* limitations under the License.
*/

#include <vector>

#include <cuspatial/error.hpp>
#include <cuspatial/hausdorff.hpp>
#include <cuspatial/polygon_separation.hpp>
#include <cuspatial/polygon_distance.hpp>

#include <tests/utilities/base_fixture.hpp>
#include <tests/utilities/column_utilities.hpp>
#include <tests/utilities/column_wrapper.hpp>
#include <tests/utilities/cudf_gtest.hpp>
#include <tests/utilities/type_lists.hpp>
#include "build/cuda-10.2/regex-parallel/release/googletest/install/include/gtest/gtest.h"
#include "gtest/gtest.h"

#include <thrust/iterator/constant_iterator.h>

#include <gtest/gtest.h>

#include <vector>

using namespace cudf;
using namespace test;

Expand All @@ -52,7 +52,7 @@ TYPED_TEST(DirectedPolygonSeparationTest, ZeroShapes)

auto expected = cudf::test::fixed_width_column_wrapper<T>({});

auto actual = cuspatial::directed_polygon_separation(x, y, space_offsets);
auto actual = cuspatial::directed_polygon_distance(x, y, space_offsets);

expect_columns_equivalent(expected, actual->view(), true);
}
Expand All @@ -67,7 +67,7 @@ TYPED_TEST(DirectedPolygonSeparationTest, TwoShapesEdgeToPoint)

auto expected = cudf::test::fixed_width_column_wrapper<T>({0.0, 1.4142135623730951, 1.0, 0.0});

auto actual = cuspatial::directed_polygon_separation(x, y, space_offsets);
auto actual = cuspatial::directed_polygon_distance(x, y, space_offsets);

expect_columns_equivalent(expected, actual->view(), true);
}
Expand All @@ -82,7 +82,7 @@ TYPED_TEST(DirectedPolygonSeparationTest, OneShapeSinglePoint)

auto expected = cudf::test::fixed_width_column_wrapper<T>({0.0});

auto actual = cuspatial::directed_polygon_separation(x, y, space_offsets);
auto actual = cuspatial::directed_polygon_distance(x, y, space_offsets);

expect_columns_equivalent(expected, actual->view(), true);
}
Expand All @@ -98,7 +98,7 @@ TYPED_TEST(DirectedPolygonSeparationTest, TwoShapesPointToPoint)
auto expected =
cudf::test::fixed_width_column_wrapper<T>({0.0, 2.8284271247461903, 2.8284271247461903, 0.0});

auto actual = cuspatial::directed_polygon_separation(x, y, space_offsets);
auto actual = cuspatial::directed_polygon_distance(x, y, space_offsets);

expect_columns_equivalent(expected, actual->view(), true);
}
Expand All @@ -113,7 +113,7 @@ TYPED_TEST(DirectedPolygonSeparationTest, EdgesOnly)

auto expected = cudf::test::fixed_width_column_wrapper<T>({0.0, 0.0, 0.0, 0.0});

auto actual = cuspatial::directed_polygon_separation(x, y, space_offsets);
auto actual = cuspatial::directed_polygon_distance(x, y, space_offsets);

expect_columns_equivalent(expected, actual->view(), true);
}
Expand All @@ -128,7 +128,7 @@ TYPED_TEST(DirectedPolygonSeparationTest, ZeroLengthEdge)

auto expected = cudf::test::fixed_width_column_wrapper<T>({0});

auto actual = cuspatial::directed_polygon_separation(x, y, space_offsets);
auto actual = cuspatial::directed_polygon_distance(x, y, space_offsets);

expect_columns_equal(expected, actual->view(), true);
}
Expand All @@ -139,7 +139,7 @@ TYPED_TEST(DirectedPolygonSeparationTest, MismatchedTypeTest)
auto y = cudf::test::fixed_width_column_wrapper<float>({0, 0});
auto space_offsets = cudf::test::fixed_width_column_wrapper<cudf::size_type>({0});

EXPECT_THROW(cuspatial::directed_polygon_separation(x, y, space_offsets), cuspatial::logic_error);
EXPECT_THROW(cuspatial::directed_polygon_distance(x, y, space_offsets), cuspatial::logic_error);
}

template <typename T>
Expand All @@ -156,5 +156,5 @@ TYPED_TEST(DirectedPolygonSeparationUnsupportedTypesTest, InvalidTypeTest)
auto y = cudf::test::fixed_width_column_wrapper<T>({0, 0});
auto space_offsets = cudf::test::fixed_width_column_wrapper<cudf::size_type>({0});

EXPECT_THROW(cuspatial::directed_polygon_separation(x, y, space_offsets), cuspatial::logic_error);
EXPECT_THROW(cuspatial::directed_polygon_distance(x, y, space_offsets), cuspatial::logic_error);
}
2 changes: 1 addition & 1 deletion python/cuspatial/cuspatial/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .core import interpolate
from .core.gis import (
directed_hausdorff_distance,
directed_polygon_separation,
directed_polygon_distance,
haversine_distance,
lonlat_to_cartesian,
point_in_polygon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from cudf._lib.column cimport column, column_view
from cudf._lib.move cimport unique_ptr

cdef extern from "cuspatial/polygon_separation.hpp" namespace "cuspatial" nogil:
cdef unique_ptr[column] directed_polygon_separation(
cdef extern from "cuspatial/polygon_distance.hpp" namespace "cuspatial" \
nogil:
cdef unique_ptr[column] directed_polygon_distance(
const column_view & xs,
const column_view & ys,
const column_view & space_offsets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from cudf._lib.column cimport column, column_view, Column
from cudf._lib.move cimport move, unique_ptr

from cuspatial._lib.cpp.polygon_separation \
cimport directed_polygon_separation as cpp_directed_polygon_separation
from cuspatial._lib.cpp.polygon_distance \
cimport directed_polygon_distance as cpp_directed_polygon_distance


def directed_polygon_separation(
def directed_polygon_distance(
Column xs,
Column ys,
Column space_offsets
Expand All @@ -20,7 +20,7 @@ def directed_polygon_separation(

with nogil:
result = move(
cpp_directed_polygon_separation(
cpp_directed_polygon_distance(
c_xs,
c_ys,
c_space_offsets
Expand Down
14 changes: 7 additions & 7 deletions python/cuspatial/cuspatial/core/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
haversine_distance as cpp_haversine_distance,
lonlat_to_cartesian as cpp_lonlat_to_cartesian,
)
from cuspatial._lib.polygon_separation import (
directed_polygon_separation as cpp_directed_polygon_separation,
from cuspatial._lib.polygon_distance import (
directed_polygon_distance as cpp_directed_polygon_distance,
)
from cuspatial.utils import gis_utils
from cuspatial.utils.column_utils import normalize_point_columns
Expand Down Expand Up @@ -98,7 +98,7 @@ def directed_hausdorff_distance(xs, ys, offsets):
return DataFrame.from_gpu_matrix(result)


def directed_polygon_point_distance(xs, ys, offsets):
def directed_polygon_distance(xs, ys, offsets):
"""Compute the directed polygon-point distances between all pairs of
polygons.
Expand All @@ -114,17 +114,17 @@ def directed_polygon_point_distance(xs, ys, offsets):
Returns
-------
result : cudf.DataFrame
The pairwise directed distance matrix with one row and one column per input
polygon; the value at row `i`, column `j` represents the polygon-point distance
from polygon i to any vertex in polygon j.
The pairwise directed distance matrix with one row and one column per
input polygon; the value at row `i`, column `j` represents the
polygon-point distance from polygon i to any vertex in polygon j.
Examples
--------
... TODO ...
"""
xs, ys = normalize_point_columns(as_column(xs), as_column(ys))
offsets = as_column(offsets, dtype="int32")
result = cpp_directed_polygon_separation(xs, ys, offsets)
result = cpp_directed_polygon_distance(xs, ys, offsets)
if result.size == 0:
return DataFrame()

Expand Down
25 changes: 13 additions & 12 deletions python/cuspatial/cuspatial/tests/test_polygon_separation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
import cuspatial


def _test_polygon_separation_from_list_of_spaces(spaces):
def _test_polygon_distance_from_list_of_spaces(spaces):
lengths = [len(space) for space in spaces]
offsets = np.cumsum([0, *lengths])[:-1]
return cuspatial.directed_polygon_separation(
return cuspatial.directed_polygon_distance(
[x for space in spaces for (x, y) in space],
[y for space in spaces for (x, y) in space],
offsets,
)


def test_empty():
actual = _test_polygon_separation_from_list_of_spaces([])
actual = _test_polygon_distance_from_list_of_spaces([])
expected = cudf.DataFrame([])
assert_eq(expected, actual)

Expand All @@ -40,51 +40,52 @@ def test_empty_y():


def test_solo_point():
actual = _test_polygon_separation_from_list_of_spaces([[(0, 0)]])
actual = _test_polygon_distance_from_list_of_spaces([[(0, 0)]])
expected = cudf.DataFrame([0.0])
assert_eq(expected, actual)


def test_solo_edge():
actual = _test_polygon_separation_from_list_of_spaces([[(1, 2), (2, 1)]])
actual = _test_polygon_distance_from_list_of_spaces([[(1, 2), (2, 1)]])
expected = cudf.DataFrame([0.0])
assert_eq(expected, actual)


def test_solo_edge_zero_length():
actual = _test_polygon_separation_from_list_of_spaces([[(0, 0), (0, 0)]])
actual = _test_polygon_distance_from_list_of_spaces([[(0, 0), (0, 0)]])
expected = cudf.DataFrame([0.0])
assert_eq(expected, actual)


def test_solo_triangle():
actual = _test_polygon_separation_from_list_of_spaces(
actual = _test_polygon_distance_from_list_of_spaces(
[[(-1, 0), (0, 1), (1, 0)]]
)

expected = cudf.DataFrame([0.0])

assert_eq(expected, actual)


def test_two_triangles_edge_to_point():
actual = _test_polygon_separation_from_list_of_spaces(
actual = _test_polygon_distance_from_list_of_spaces(
[[(-1, 0), (0, 1), (1, 0)]]
)

expected = cudf.DataFrame([0.0])
assert_eq(expected, actual)


def test_two_triangles_point_to_point():
actual = _test_polygon_separation_from_list_of_spaces(
actual = _test_polygon_distance_from_list_of_spaces(
[[(-1, 3), (0, 1), (1, 3)], [(-1, -3), (0, -1), (1, -3)]]
)

expected = cudf.DataFrame([0.0, 2.0, 0.0, 2.0])
expected = cudf.DataFrame({0: [0.0, 2.0], 1: [2.0, 0.0]})
assert_eq(expected, actual)


def test_concave():
actual = _test_polygon_separation_from_list_of_spaces(
actual = _test_polygon_distance_from_list_of_spaces(
[
[(-1, 3), (1, 3), (0, 0)],
[(-2, 1), (0, -2), (2, 1), (1, -3), (-1, -3)],
Expand Down

0 comments on commit 8258698

Please sign in to comment.