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

Update black to 22.3.0, update usage of libcudf macros, and remove direct column indexing #511

Merged
merged 5 commits into from
Apr 6, 2022
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
types: [text]
types_or: [python, cython]
- repo: https://github.com/ambv/black
rev: 19.10b0
rev: 22.3.0
hooks:
- id: black
files: python/cuspatial/.*
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/interpolate/cubic_spline.cu
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ std::unique_ptr<cudf::table> cubicspline_coefficients(cudf::column_view const& t
// pBuffer: get size of thisu by gtsv2_bufferSizeExt
cusparseHandle_t handle;

CUDA_TRY(cudaMalloc(&handle, sizeof(cusparseHandle_t)));
CUDF_CUDA_TRY(cudaMalloc(&handle, sizeof(cusparseHandle_t)));
CUSPARSE_TRY(cusparseCreate(&handle));

size_t pBufferSize;
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/join/quadtree_point_to_nearest_polyline.cu
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ struct compute_quadtree_point_to_nearest_polyline {
rmm::device_uvector<T> distances(point_x.size(), stream);

// Fill distances with 0
CUDA_TRY(cudaMemsetAsync(distances.data(), 0, distances.size() * sizeof(T), stream.value()));
CUDF_CUDA_TRY(
cudaMemsetAsync(distances.data(), 0, distances.size() * sizeof(T), stream.value()));

// Reduce the intermediate point/polyline indices to lists of point/polyline index pairs and
// distances, selecting the polyline index closest to each point.
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/spatial/hausdorff.cu
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ struct hausdorff_functor {
space_offsets.begin<cudf::size_type>(),
result_view.begin<T>());

CUDA_TRY(cudaGetLastError());
CUDF_CUDA_TRY(cudaGetLastError());

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/trajectory/trajectory_bounding_boxes.cu
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct dispatch_element {
});

// check for errors
CHECK_CUDA(stream.value());
CUDF_CHECK_CUDA(stream.value());

return std::make_unique<cudf::table>(std::move(cols));
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/trajectory/trajectory_distances_and_speeds.cu
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ struct dispatch_timestamp {
});

// check for errors
CHECK_CUDA(stream.value());
CUDF_CHECK_CUDA(stream.value());

return std::make_unique<cudf::table>(std::move(cols));
}
Expand Down
8 changes: 5 additions & 3 deletions python/cuspatial/cuspatial/core/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ def directed_hausdorff_distance(xs, ys, space_offsets):
return DataFrame()
xs, ys = normalize_point_columns(as_column(xs), as_column(ys))
result = cpp_directed_hausdorff_distance(
xs, ys, as_column(space_offsets, dtype="uint32"),
xs,
ys,
as_column(space_offsets, dtype="uint32"),
)
result = result.data_array_view
result = result.reshape(num_spaces, num_spaces)
return DataFrame(result)


def haversine_distance(p1_lon, p1_lat, p2_lon, p2_lat):
""" Compute the haversine distances between an arbitrary list of lon/lat
"""Compute the haversine distances between an arbitrary list of lon/lat
pairs

Parameters
Expand Down Expand Up @@ -166,7 +168,7 @@ def point_in_polygon(
poly_points_x,
poly_points_y,
):
""" Compute from a set of points and a set of polygons which points fall
"""Compute from a set of points and a set of polygons which points fall
within which polygons. Note that `polygons_(x,y)` must be specified as
closed polygons: the first and last coordinate of each polygon must be
the same.
Expand Down
2 changes: 1 addition & 1 deletion python/cuspatial/cuspatial/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def quadtree_on_points(
xs, ys, x_min, x_max, y_min, y_max, scale, max_depth, min_size
):
""" Construct a quadtree from a set of points for a given area-of-interest
"""Construct a quadtree from a set of points for a given area-of-interest
bounding box.

Parameters
Expand Down
6 changes: 3 additions & 3 deletions python/cuspatial/cuspatial/core/spatial_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def join_quadtree_and_bounding_boxes(
quadtree, poly_bounding_boxes, x_min, x_max, y_min, y_max, scale, max_depth
):
""" Search a quadtree for polygon or polyline bounding box intersections.
"""Search a quadtree for polygon or polyline bounding box intersections.

Parameters
----------
Expand Down Expand Up @@ -87,7 +87,7 @@ def quadtree_point_in_polygon(
poly_points_x,
poly_points_y,
):
""" Test whether the specified points are inside any of the specified
"""Test whether the specified points are inside any of the specified
polygons.

Uses the table of (polygon, quadrant) pairs returned by
Expand Down Expand Up @@ -167,7 +167,7 @@ def quadtree_point_to_nearest_polyline(
poly_points_x,
poly_points_y,
):
""" Finds the nearest polyline to each point in a quadrant, and computes
"""Finds the nearest polyline to each point in a quadrant, and computes
the distances between each point and polyline.

Uses the table of (polyline, quadrant) pairs returned by
Expand Down
2 changes: 1 addition & 1 deletion python/cuspatial/cuspatial/core/spatial_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def points_in_spatial_window(min_x, max_x, min_y, max_y, xs, ys):
""" Return only the subset of coordinates that fall within a
"""Return only the subset of coordinates that fall within a
rectangular window.

A point `(x, y)` is inside the query window if and only if
Expand Down
2 changes: 1 addition & 1 deletion python/cuspatial/cuspatial/core/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def derive_trajectories(object_ids, xs, ys, timestamps):


def trajectory_bounding_boxes(num_trajectories, object_ids, xs, ys):
""" Compute the bounding boxes of sets of trajectories.
"""Compute the bounding boxes of sets of trajectories.

Parameters
----------
Expand Down
5 changes: 4 additions & 1 deletion python/cuspatial/cuspatial/geometry/geoarrowbuffers.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,10 @@ def __repr__(self):
def copy(self, deep=True):
base = super().copy(deep)
result = LineArray(
base.xy, base.offsets, self.mlines.copy(deep), base.z,
base.xy,
base.offsets,
self.mlines.copy(deep),
base.z,
)
return result

Expand Down
6 changes: 5 additions & 1 deletion python/cuspatial/cuspatial/io/geopandas_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ def _load_geometry_offsets(self, geoseries: gpGeoSeries) -> dict:
)
return offsets

def _read_geometries(self, geoseries: gpGeoSeries, offsets: dict,) -> dict:
def _read_geometries(
self,
geoseries: gpGeoSeries,
offsets: dict,
) -> dict:
"""
Creates a set of buffers sized to fit all of the geometries and
iteratively populates them with geometry coordinate values.
Expand Down
4 changes: 3 additions & 1 deletion python/cuspatial/cuspatial/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def gs():
g5 = MultiLineString((((15, 16), (17, 18)), ((19, 20), (21, 22))))
g6 = MultiLineString((((23, 24), (25, 26)), ((27, 28), (29, 30))))
g7 = LineString(((31, 32), (33, 34)))
g8 = Polygon(((35, 36), (37, 38), (39, 40), (41, 42)),)
g8 = Polygon(
((35, 36), (37, 38), (39, 40), (41, 42)),
)
g9 = MultiPolygon(
[
(
Expand Down
14 changes: 11 additions & 3 deletions python/cuspatial/cuspatial/tests/test_from_geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,17 @@ def test_from_geopandas_linestring():

def test_from_geopandas_multilinestring():
gs = gpd.GeoSeries(
MultiLineString((((1.0, 2.0), (3.0, 4.0)), ((5.0, 6.0), (7.0, 8.0)),))
MultiLineString(
(
((1.0, 2.0), (3.0, 4.0)),
((5.0, 6.0), (7.0, 8.0)),
)
)
)
cugs = cuspatial.from_geopandas(gs)
cudf.testing.assert_series_equal(
cugs.lines.xy, cudf.Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]),
cugs.lines.xy,
cudf.Series([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]),
)
cudf.testing.assert_series_equal(
cugs.lines.offsets, cudf.Series([0, 4, 8])
Expand All @@ -85,7 +91,9 @@ def test_from_geopandas_multilinestring():

def test_from_geopandas_polygon():
gs = gpd.GeoSeries(
Polygon(((0.0, 0.0), (1.0, 0.0), (0.0, 1.0), (0.0, 0.0)),)
Polygon(
((0.0, 0.0), (1.0, 0.0), (0.0, 1.0), (0.0, 0.0)),
)
)
cugs = cuspatial.from_geopandas(gs)
cudf.testing.assert_series_equal(
Expand Down
10 changes: 8 additions & 2 deletions python/cuspatial/cuspatial/tests/test_geodataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,17 @@ def test_interleaved_point(gpdf, polys):
)
cudf.testing.assert_series_equal(
cugs.lines.x,
cudf.Series(np.array([range(11, 34, 2)]).flatten(), dtype="float64",),
cudf.Series(
np.array([range(11, 34, 2)]).flatten(),
dtype="float64",
),
)
cudf.testing.assert_series_equal(
cugs.lines.y,
cudf.Series(np.array([range(12, 35, 2)]).flatten(), dtype="float64",),
cudf.Series(
np.array([range(12, 35, 2)]).flatten(),
dtype="float64",
),
)
cudf.testing.assert_series_equal(
cugs.polygons.x, cudf.Series(polys[:, 0], dtype="float64")
Expand Down
10 changes: 8 additions & 2 deletions python/cuspatial/cuspatial/tests/test_geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,17 @@ def test_interleaved_point(gs, polys):
)
cudf.testing.assert_series_equal(
cugs.lines.x,
cudf.Series(np.array([range(11, 34, 2)]).flatten(), dtype="float64",),
cudf.Series(
np.array([range(11, 34, 2)]).flatten(),
dtype="float64",
),
)
cudf.testing.assert_series_equal(
cugs.lines.y,
cudf.Series(np.array([range(12, 35, 2)]).flatten(), dtype="float64",),
cudf.Series(
np.array([range(12, 35, 2)]).flatten(),
dtype="float64",
),
)
cudf.testing.assert_series_equal(
cugs.polygons.x, cudf.Series(polys[:, 0], dtype="float64")
Expand Down
8 changes: 6 additions & 2 deletions python/cuspatial/cuspatial/tests/test_hausdorff_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ def test_zeros():
def test_empty_x():
with pytest.raises(RuntimeError):
cuspatial.directed_hausdorff_distance(
[], [0.0], [0],
[],
[0.0],
[0],
)


def test_empty_y():
with pytest.raises(RuntimeError):
cuspatial.directed_hausdorff_distance(
[0.0], [], [0],
[0.0],
[],
[0],
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_zeros():
cudf.Series([0.0]),
cudf.Series([0.0]),
)
assert distance[0] == 0
assert distance.element_indexing(0) == 0


def test_empty_x1():
Expand Down
62 changes: 53 additions & 9 deletions python/cuspatial/cuspatial/tests/test_spatial_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ def test_empty(dtype):
)
# empty should not throw
intersections = cuspatial.join_quadtree_and_bounding_boxes(
quadtree, poly_bboxes, *bbox_1, 1, 1, # bbox # scale # max_depth
quadtree,
poly_bboxes,
*bbox_1,
1,
1, # bbox # scale # max_depth
)
cudf.testing.assert_frame_equal(
intersections,
Expand Down Expand Up @@ -264,10 +268,20 @@ def test_polygon_join_small(dtype):
min_size,
)
poly_bboxes = cuspatial.polygon_bounding_boxes(
small_poly_offsets, small_ring_offsets, poly_points_x, poly_points_y,
small_poly_offsets,
small_ring_offsets,
poly_points_x,
poly_points_y,
)
intersections = cuspatial.join_quadtree_and_bounding_boxes(
quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth,
quadtree,
poly_bboxes,
x_min,
x_max,
y_min,
y_max,
scale,
max_depth,
)
cudf.testing.assert_frame_equal(
intersections,
Expand Down Expand Up @@ -310,10 +324,20 @@ def test_polyline_join_small(dtype):
min_size,
)
poly_bboxes = cuspatial.polyline_bounding_boxes(
small_ring_offsets, poly_points_x, poly_points_y, expansion_radius,
small_ring_offsets,
poly_points_x,
poly_points_y,
expansion_radius,
)
intersections = cuspatial.join_quadtree_and_bounding_boxes(
quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth,
quadtree,
poly_bboxes,
x_min,
x_max,
y_min,
y_max,
scale,
max_depth,
)
cudf.testing.assert_frame_equal(
intersections,
Expand Down Expand Up @@ -401,10 +425,20 @@ def test_quadtree_point_in_polygon_small(dtype):
min_size,
)
poly_bboxes = cuspatial.polygon_bounding_boxes(
small_poly_offsets, small_ring_offsets, poly_points_x, poly_points_y,
small_poly_offsets,
small_ring_offsets,
poly_points_x,
poly_points_y,
)
intersections = cuspatial.join_quadtree_and_bounding_boxes(
quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth,
quadtree,
poly_bboxes,
x_min,
x_max,
y_min,
y_max,
scale,
max_depth,
)
polygons_and_points = cuspatial.quadtree_point_in_polygon(
intersections,
Expand Down Expand Up @@ -481,10 +515,20 @@ def run_test_quadtree_point_to_nearest_polyline_small(
min_size,
)
poly_bboxes = cuspatial.polyline_bounding_boxes(
small_ring_offsets, poly_points_x, poly_points_y, expansion_radius,
small_ring_offsets,
poly_points_x,
poly_points_y,
expansion_radius,
)
intersections = cuspatial.join_quadtree_and_bounding_boxes(
quadtree, poly_bboxes, x_min, x_max, y_min, y_max, scale, max_depth,
quadtree,
poly_bboxes,
x_min,
x_max,
y_min,
y_max,
scale,
max_depth,
)
p2np_result = cuspatial.quadtree_point_to_nearest_polyline(
intersections,
Expand Down
Loading