-
Notifications
You must be signed in to change notification settings - Fork 154
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
[REVIEW] Python and Cython style cleanup, pre-commit hook #41
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
repos: | ||
- repo: https://github.com/timothycrosley/isort | ||
rev: 4.3.21 | ||
hooks: | ||
- id: isort | ||
- repo: https://github.com/ambv/black | ||
rev: stable | ||
hooks: | ||
- id: black | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.7.7 | ||
hooks: | ||
- id: flake8 | ||
- repo: https://gitlab.com/pycqa/flake8 | ||
rev: 3.7.7 | ||
hooks: | ||
- id: flake8 | ||
alias: flake8-cython | ||
name: flake8-cython | ||
args: ["--config=python/cuspatial/.flake8.cython"] | ||
types: [cython] | ||
default_language_version: | ||
python: python3 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
from .core.trajectory import ( | ||
derive, | ||
distance_and_speed, | ||
spatial_bounds, | ||
subset_trajectory_id | ||
) | ||
from .core.gis import ( | ||
directed_hausdorff_distance, | ||
haversine_distance, | ||
lonlat_to_xy_km_coordinates, | ||
point_in_polygon_bitmap, | ||
window_points, | ||
) | ||
from .core.trajectory import ( | ||
derive, | ||
distance_and_speed, | ||
spatial_bounds, | ||
subset_trajectory_id, | ||
) | ||
from .io.soa import ( | ||
read_uint, | ||
read_its_timestamps, | ||
read_points_lonlat, | ||
read_points_xy_km, | ||
read_polygon | ||
read_polygon, | ||
read_uint, | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,104 @@ | ||
# Copyright (c) 2019, NVIDIA CORPORATION. | ||
|
||
# cython: profile=False | ||
# distutils: language = c++ | ||
# cython: embedsignature = True | ||
# cython: language_level = 3 | ||
|
||
|
||
from cudf.core.column import Column | ||
from cudf._lib.cudf import * | ||
from libc.stdlib cimport calloc, malloc, free | ||
from libcpp.pair cimport pair | ||
|
||
cpdef cpp_read_uint_soa(soa_file_name): | ||
# print("in cpp_read_id_soa, reading ",soa_file_name) | ||
cdef bytes py_bytes = soa_file_name.encode() | ||
cdef char* c_string = py_bytes | ||
cdef gdf_column c_id | ||
|
||
with nogil: | ||
c_id = read_uint32_soa(c_string) | ||
c_id = read_uint32_soa( | ||
c_string | ||
) | ||
|
||
id_data, id_mask = gdf_column_to_column_mem(&c_id) | ||
id=Column.from_mem_views(id_data,id_mask) | ||
id = Column.from_mem_views(id_data, id_mask) | ||
|
||
return id | ||
|
||
cpdef cpp_read_ts_soa(soa_file_name): | ||
# print("in cpp_read_ts_soa, reading ",soa_file_name) | ||
cdef bytes py_bytes = soa_file_name.encode() | ||
cdef char* c_string = py_bytes | ||
cdef gdf_column c_ts | ||
|
||
with nogil: | ||
c_ts = read_timestamp_soa(c_string) | ||
c_ts = read_timestamp_soa( | ||
c_string | ||
) | ||
|
||
ts_data, ts_mask = gdf_column_to_column_mem(&c_ts) | ||
ts=Column.from_mem_views(ts_data,ts_mask) | ||
ts = Column.from_mem_views(ts_data, ts_mask) | ||
|
||
return ts | ||
|
||
cpdef cpp_read_pnt_lonlat_soa(soa_file_name): | ||
# print("in cpp_read_pnt_lonlat_soa, reading ",soa_file_name) | ||
cdef bytes py_bytes = soa_file_name.encode() | ||
cdef char* c_string = py_bytes | ||
cdef pair[gdf_column, gdf_column] columns | ||
|
||
with nogil: | ||
columns = read_lonlat_points_soa(c_string) | ||
columns = read_lonlat_points_soa( | ||
c_string | ||
) | ||
|
||
lon_data, lon_mask = gdf_column_to_column_mem(&columns.first) | ||
lon=Column.from_mem_views(lon_data,lon_mask) | ||
lon = Column.from_mem_views(lon_data, lon_mask) | ||
lat_data, lat_mask = gdf_column_to_column_mem(&columns.second) | ||
lat=Column.from_mem_views(lat_data,lat_mask) | ||
lat = Column.from_mem_views(lat_data, lat_mask) | ||
|
||
return lon,lat | ||
return lon, lat | ||
|
||
cpdef cpp_read_pnt_xy_soa(soa_file_name): | ||
# print("in cpp_read_pnt_xy_soa, reading ",soa_file_name) | ||
cdef bytes py_bytes = soa_file_name.encode() | ||
cdef char* c_string = py_bytes | ||
cdef pair[gdf_column, gdf_column] columns | ||
|
||
with nogil: | ||
columns = read_xy_points_soa(c_string) | ||
columns = read_xy_points_soa( | ||
c_string | ||
) | ||
|
||
x_data, x_mask = gdf_column_to_column_mem(&columns.first) | ||
x=Column.from_mem_views(x_data,x_mask) | ||
x = Column.from_mem_views(x_data, x_mask) | ||
y_data, y_mask = gdf_column_to_column_mem(&columns.second) | ||
y=Column.from_mem_views(y_data,y_mask) | ||
y = Column.from_mem_views(y_data, y_mask) | ||
|
||
return x,y | ||
return x, y | ||
|
||
cpdef cpp_read_polygon_soa(soa_file_name): | ||
# print("in cpp_read_polygon_soa, reading ",soa_file_name) | ||
cdef bytes py_bytes = soa_file_name.encode() | ||
cdef char* c_string = py_bytes | ||
cdef gdf_column* c_ply_fpos=<gdf_column*>malloc(sizeof(gdf_column)) | ||
cdef gdf_column* c_ply_rpos=<gdf_column*>malloc(sizeof(gdf_column)) | ||
cdef gdf_column* c_ply_x=<gdf_column*>malloc(sizeof(gdf_column)) | ||
cdef gdf_column* c_ply_y=<gdf_column*>malloc(sizeof(gdf_column)) | ||
cdef gdf_column* c_ply_fpos = <gdf_column*>malloc(sizeof(gdf_column)) | ||
cdef gdf_column* c_ply_rpos = <gdf_column*>malloc(sizeof(gdf_column)) | ||
cdef gdf_column* c_ply_x = <gdf_column*>malloc(sizeof(gdf_column)) | ||
cdef gdf_column* c_ply_y = <gdf_column*>malloc(sizeof(gdf_column)) | ||
|
||
with nogil: | ||
read_polygon_soa(c_string,c_ply_fpos, c_ply_rpos, c_ply_x, c_ply_y) | ||
read_polygon_soa( | ||
c_string, | ||
c_ply_fpos, | ||
c_ply_rpos, | ||
c_ply_x, | ||
c_ply_y | ||
) | ||
|
||
f_data, f_mask = gdf_column_to_column_mem(c_ply_fpos) | ||
f_pos=Column.from_mem_views(f_data,f_mask) | ||
f_pos = Column.from_mem_views(f_data, f_mask) | ||
r_data, r_mask = gdf_column_to_column_mem(c_ply_rpos) | ||
r_pos=Column.from_mem_views(r_data,r_mask) | ||
r_pos = Column.from_mem_views(r_data, r_mask) | ||
x_data, x_mask = gdf_column_to_column_mem(c_ply_x) | ||
x=Column.from_mem_views(x_data,x_mask) | ||
x = Column.from_mem_views(x_data, x_mask) | ||
y_data, y_mask = gdf_column_to_column_mem(c_ply_y) | ||
y=Column.from_mem_views(y_data,y_mask) | ||
|
||
return f_pos,r_pos,x,y | ||
y = Column.from_mem_views(y_data, y_mask) | ||
|
||
return f_pos, r_pos, x, y |
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 |
---|---|---|
|
@@ -9,33 +9,44 @@ from cudf._lib.cudf cimport * | |
from libcpp.pair cimport pair | ||
|
||
cdef extern from "point_in_polygon.hpp" namespace "cuspatial" nogil: | ||
cdef gdf_column point_in_polygon_bitmap(const gdf_column& pnt_x, | ||
const gdf_column& pnt_y, | ||
const gdf_column& ply_fpos, | ||
const gdf_column& ply_rpos, | ||
const gdf_column& ply_x, | ||
const gdf_column& ply_y) except + | ||
cdef gdf_column point_in_polygon_bitmap( | ||
const gdf_column& pnt_x, | ||
const gdf_column& pnt_y, | ||
const gdf_column& ply_fpos, | ||
const gdf_column& ply_rpos, | ||
const gdf_column& ply_x, | ||
const gdf_column& ply_y | ||
) except + | ||
|
||
cdef extern from "coordinate_transform.hpp" namespace "cuspatial" nogil: | ||
cdef pair[gdf_column, gdf_column] lonlat_to_coord(const gdf_scalar cam_x, | ||
const gdf_scalar cam_y, | ||
const gdf_column & in_x, | ||
const gdf_column & in_y) except + | ||
cdef extern from "coordinate_transform.hpp" namespace "cuspatial" nogil: | ||
cdef pair[gdf_column, gdf_column] lonlat_to_coord( | ||
const gdf_scalar& cam_x, | ||
const gdf_scalar& cam_y, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These weren't pass by reference before, but the |
||
const gdf_column& in_x, | ||
const gdf_column& in_y | ||
) except + | ||
|
||
cdef extern from "haversine.hpp" namespace "cuspatial" nogil: | ||
gdf_column haversine_distance(const gdf_column& x1, const gdf_column& y1, | ||
const gdf_column& x2, const gdf_column& y2) except + | ||
cdef extern from "haversine.hpp" namespace "cuspatial" nogil: | ||
gdf_column haversine_distance( | ||
const gdf_column& x1, | ||
const gdf_column& y1, | ||
const gdf_column& x2, | ||
const gdf_column& y2 | ||
) except + | ||
|
||
cdef extern from "hausdorff.hpp" namespace "cuspatial" nogil: | ||
gdf_column& directed_hausdorff_distance(const gdf_column& coor_x, | ||
const gdf_column& coor_y, | ||
const gdf_column& cnt)except + | ||
cdef extern from "hausdorff.hpp" namespace "cuspatial" nogil: | ||
gdf_column& directed_hausdorff_distance( | ||
const gdf_column& coor_x, | ||
const gdf_column& coor_y, | ||
const gdf_column& cnt | ||
) except + | ||
|
||
cdef extern from "query.hpp" namespace "cuspatial" nogil: | ||
cdef pair[gdf_column, gdf_column] spatial_window_points( | ||
cdef pair[gdf_column, gdf_column] spatial_window_points( | ||
const gdf_scalar& left, | ||
const gdf_scalar& bottom, | ||
const gdf_scalar& right, | ||
const gdf_scalar& top, | ||
const gdf_column& x, | ||
const gdf_column& y) except + | ||
const gdf_column& y | ||
) except + |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're leaking these 4, will file an issue and submit a follow up PR.