-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add python bindings for (multi)point-(multi)point distance (#734)
This PR adds python bindings to Point-point distance. Depend on #731 Reverts change to comment: #731 (comment) Close #578 Authors: - Michael Wang (https://github.com/isVoid) Approvers: - Mark Harris (https://github.com/harrism) - H. Thomson Comer (https://github.com/thomcom) URL: #734
- Loading branch information
Showing
12 changed files
with
314 additions
and
119 deletions.
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
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
20 changes: 20 additions & 0 deletions
20
python/cuspatial/cuspatial/_lib/cpp/distance/point_distance.pxd
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,20 @@ | ||
# Copyright (c) 2022, NVIDIA CORPORATION. | ||
|
||
from libcpp.memory cimport unique_ptr | ||
|
||
from cudf._lib.column cimport Column | ||
from cudf._lib.cpp.column.column cimport column | ||
from cudf._lib.cpp.column.column_view cimport column_view | ||
from cudf._lib.cpp.types cimport size_type | ||
|
||
from cuspatial._lib.cpp.optional cimport optional | ||
|
||
|
||
cdef extern from "cuspatial/distance/point_distance.hpp" \ | ||
namespace "cuspatial" nogil: | ||
cdef unique_ptr[column] pairwise_point_distance( | ||
const optional[column_view] multipoint1_offsets, | ||
const column_view point1_xy, | ||
const optional[column_view] multipoint2_offsets, | ||
const column_view point2_xy | ||
) except + |
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,102 @@ | ||
from typing import Optional | ||
|
||
from libcpp.memory cimport unique_ptr | ||
from libcpp.utility cimport move | ||
|
||
from cudf._lib.column cimport Column | ||
from cudf._lib.cpp.column.column cimport column | ||
from cudf._lib.cpp.column.column_view cimport column_view | ||
|
||
from cuspatial._lib.cpp.distance.linestring_distance cimport ( | ||
pairwise_linestring_distance as c_pairwise_linestring_distance, | ||
) | ||
from cuspatial._lib.cpp.distance.point_distance cimport ( | ||
pairwise_point_distance as c_pairwise_point_distance, | ||
) | ||
from cuspatial._lib.cpp.distance.point_linestring_distance cimport ( | ||
pairwise_point_linestring_distance as c_pairwise_point_linestring_distance, | ||
) | ||
from cuspatial._lib.cpp.optional cimport nullopt, optional | ||
from cuspatial._lib.utils cimport unwrap_pyoptcol | ||
|
||
|
||
def pairwise_point_distance( | ||
Column points1_xy, | ||
Column points2_xy, | ||
multipoint1_offsets=None, | ||
multipoint2_offsets=None, | ||
): | ||
cdef optional[column_view] c_multipoints1_offset = unwrap_pyoptcol( | ||
multipoint1_offsets) | ||
cdef optional[column_view] c_multipoints2_offset = unwrap_pyoptcol( | ||
multipoint2_offsets) | ||
|
||
cdef column_view c_points1_xy = points1_xy.view() | ||
cdef column_view c_points2_xy = points2_xy.view() | ||
cdef unique_ptr[column] c_result | ||
|
||
with nogil: | ||
c_result = move(c_pairwise_point_distance( | ||
c_multipoints1_offset, | ||
c_points1_xy, | ||
c_multipoints2_offset, | ||
c_points2_xy, | ||
)) | ||
return Column.from_unique_ptr(move(c_result)) | ||
|
||
|
||
def pairwise_linestring_distance( | ||
Column linestring1_offsets, | ||
Column linestring1_points_x, | ||
Column linestring1_points_y, | ||
Column linestring2_offsets, | ||
Column linestring2_points_x, | ||
Column linestring2_points_y | ||
): | ||
cdef column_view linestring1_offsets_view = linestring1_offsets.view() | ||
cdef column_view linestring1_points_x_view = linestring1_points_x.view() | ||
cdef column_view linestring1_points_y_view = linestring1_points_y.view() | ||
cdef column_view linestring2_offsets_view = linestring2_offsets.view() | ||
cdef column_view linestring2_points_x_view = linestring2_points_x.view() | ||
cdef column_view linestring2_points_y_view = linestring2_points_y.view() | ||
|
||
cdef unique_ptr[column] c_result | ||
with nogil: | ||
c_result = move(c_pairwise_linestring_distance( | ||
linestring1_offsets_view, | ||
linestring1_points_x_view, | ||
linestring1_points_y_view, | ||
linestring2_offsets_view, | ||
linestring2_points_x_view, | ||
linestring2_points_y_view | ||
)) | ||
|
||
return Column.from_unique_ptr(move(c_result)) | ||
|
||
|
||
def pairwise_point_linestring_distance( | ||
Column points_xy, | ||
Column linestring_part_offsets, | ||
Column linestring_points_xy, | ||
multipoint_geometry_offset=None, | ||
multilinestring_geometry_offset=None, | ||
): | ||
cdef optional[column_view] c_multipoint_parts_offset = unwrap_pyoptcol( | ||
multipoint_geometry_offset) | ||
cdef optional[column_view] c_multilinestring_parts_offset = ( | ||
unwrap_pyoptcol(multilinestring_geometry_offset)) | ||
|
||
cdef column_view c_points_xy = points_xy.view() | ||
cdef column_view c_linestring_offsets = linestring_part_offsets.view() | ||
cdef column_view c_linestring_points_xy = linestring_points_xy.view() | ||
cdef unique_ptr[column] c_result | ||
|
||
with nogil: | ||
c_result = move(c_pairwise_point_linestring_distance( | ||
c_multipoint_parts_offset, | ||
c_points_xy, | ||
c_multilinestring_parts_offset, | ||
c_linestring_offsets, | ||
c_linestring_points_xy, | ||
)) | ||
return Column.from_unique_ptr(move(c_result)) |
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
python/cuspatial/cuspatial/_lib/point_linestring_distance.pyx
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.