diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1fa616697..730730015 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,46 +1,40 @@ +# Copyright (c) 2019-2022, NVIDIA CORPORATION. + repos: - - repo: https://github.com/pycqa/isort + - repo: https://github.com/PyCQA/isort rev: 5.10.1 hooks: - id: isort - args: ["--settings-path=python/cuspatial/setup.cfg"] - files: python/cuspatial/.* - exclude: __init__.py$ - types: [text] - types_or: [python, cython] - - repo: https://github.com/ambv/black + # Use the config file specific to each subproject so that each + # project can specify its own first/third-party packages. + args: ["--config-root=python/", "--resolve-all-configs"] + files: python/.* + types_or: [python, cython, pyi] + - repo: https://github.com/psf/black rev: 22.3.0 hooks: - id: black files: python/cuspatial/.* # Explicitly specify the pyproject.toml at the repo root, not per-project. args: ["--config", "pyproject.toml"] - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.7.7 + - repo: https://github.com/PyCQA/flake8 + rev: 5.0.4 hooks: - id: flake8 - files: python/cuspatial/.*\.py - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.7.7 + args: ["--config=setup.cfg"] + files: python/.*$ + types: [file] + types_or: [python, cython] + additional_dependencies: ["flake8-force"] + - repo: https://github.com/MarcoGorelli/cython-lint + rev: v0.1.10 hooks: - - id: flake8 - alias: flake8-cython - name: flake8-cython - args: ["--config=python/cuspatial/.flake8.cython"] - types: [cython] - - repo: local + - id: cython-lint + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v11.1.0 hooks: - id: clang-format - # Using the pre-commit stage to simplify invocation of all - # other hooks simultaneously (via any other hook stage). This - # can be removed if we also move to running clang-format - # entirely through pre-commit. - stages: [commit] - name: clang-format - description: Format files with ClangFormat. - entry: clang-format -i - language: system - files: \.(cu|cuh|h|hpp|cpp|inl)$ - args: ['-fallback-style=none'] + types_or: [c, c++, cuda] + args: ["-fallback-style=none", "-style=file", "-i"] default_language_version: python: python3 diff --git a/ci/checks/style.sh b/ci/checks/style.sh index fe382e5af..c28b1f285 100644 --- a/ci/checks/style.sh +++ b/ci/checks/style.sh @@ -1,5 +1,5 @@ #!/bin/bash -# COPYRIGHT (c) 2020, NVIDIA CORPORATION. +# COPYRIGHT (c) 2020-2022, NVIDIA CORPORATION. ##################### # cuSpatial Style Tester # ##################### @@ -14,69 +14,5 @@ LANG=C.UTF-8 . /opt/conda/etc/profile.d/conda.sh conda activate rapids -# Run isort and get results/return code -ISORT=`isort --check-only python/cuspatial --settings-path=python/cuspatial/setup.cfg` -ISORT_RETVAL=$? - -# Run black and get results/return code -BLACK=`black --config pyproject.toml --check --diff python` -BLACK_RETVAL=$? - -# Run flake8 and get results/return code -FLAKE=`flake8 python` -FLAKE_RETVAL=$? - -# Run flake8-cython and get results/return code -FLAKE_CYTHON=`flake8 --config=python/cuspatial/.flake8.cython` -FLAKE_CYTHON_RETVAL=$? - -# Run clang-format and check for a consistent code format -CLANG_FORMAT=`python cpp/scripts/run-clang-format.py 2>&1` -CLANG_FORMAT_RETVAL=$? - -# Output results if failure otherwise show pass -if [ "$ISORT_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: isort style check; begin output\n\n" - echo -e "$ISORT" - echo -e "\n\n>>>> FAILED: isort style check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: isort style check\n\n" -fi - -if [ "$BLACK_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: black style check; begin output\n\n" - echo -e "$BLACK" - echo -e "\n\n>>>> FAILED: black style check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: black style check\n\n" -fi - -if [ "$FLAKE_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: flake8 style check; begin output\n\n" - echo -e "$FLAKE" - echo -e "\n\n>>>> FAILED: flake8 style check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: flake8 style check\n\n" -fi - -if [ "$FLAKE_CYTHON_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: flake8-cython style check; begin output\n\n" - echo -e "$FLAKE_CYTHON" - echo -e "\n\n>>>> FAILED: flake8-cython style check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: flake8-cython style check\n\n" -fi - -if [ "$CLANG_FORMAT_RETVAL" != "0" ]; then - echo -e "\n\n>>>> FAILED: clang format check; begin output\n\n" - echo -e "$CLANG_FORMAT" - echo -e "\n\n>>>> FAILED: clang format check; end output\n\n" -else - echo -e "\n\n>>>> PASSED: clang format check\n\n" -fi - -RETVALS=($ISORT_RETVAL $BLACK_RETVAL $FLAKE_RETVAL $FLAKE_CYTHON_RETVAL $CLANG_FORMAT_RETVAL) -IFS=$'\n' -RETVAL=`echo "${RETVALS[*]}" | sort -nr | head -n1` - -exit $RETVAL +# Run pre-commit checks +pre-commit run --hook-stage manual --all-files --show-diff-on-failure diff --git a/java/src/main/native/src/cuSpatialJni.cpp b/java/src/main/native/src/cuSpatialJni.cpp index 15ab3b9c7..fd28500e7 100644 --- a/java/src/main/native/src/cuSpatialJni.cpp +++ b/java/src/main/native/src/cuSpatialJni.cpp @@ -14,19 +14,20 @@ * limitations under the License. */ -#include "jni_utils.hpp" +#include +#include "cuspatial/coordinate_transform.hpp" +#include "cuspatial/hausdorff.hpp" #include "cuspatial/haversine.hpp" +#include "cuspatial/point_in_polygon.hpp" #include "cuspatial/spatial_window.hpp" #include "cuspatial/trajectory.hpp" -#include "cuspatial/point_in_polygon.hpp" -#include "cuspatial/hausdorff.hpp" -#include "cuspatial/coordinate_transform.hpp" -#include -constexpr char const *CUSPATIAL_ERROR_CLASS = "ai/rapids/cuspatial/CuSpatialException"; //java class package path -#define CATCH_STD_CUSPATIAL(env, ret_val) \ - CATCH_STD_CLASS(env, CUSPATIAL_ERROR_CLASS, ret_val) +#include "jni_utils.hpp" + +constexpr char const *CUSPATIAL_ERROR_CLASS = + "ai/rapids/cuspatial/CuSpatialException"; // java class package path +#define CATCH_STD_CUSPATIAL(env, ret_val) CATCH_STD_CLASS(env, CUSPATIAL_ERROR_CLASS, ret_val) /** * Take a table returned by some operation and turn it into an array of column* so we can track them @@ -57,7 +58,8 @@ jlongArray convert_table_for_return(JNIEnv *env, std::unique_ptr &t return convert_table_for_return(env, table_result, extra); } -jlongArray convert_columns_for_return(JNIEnv *env, std::vector> &columns) { +jlongArray convert_columns_for_return(JNIEnv *env, + std::vector> &columns) { int num_columns = columns.size(); cudf::jni::native_jlongArray outcol_handles(env, num_columns); for (int i = 0; i < num_columns; i++) { @@ -74,12 +76,9 @@ extern "C" { // Native methods for cuspatial/haversine.hpp //////// -JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_haversineDistanceImpl(JNIEnv *env, - jclass clazz, - jlong a_lon_view_handle, - jlong a_lat_view_handle, - jlong b_lon_view_handle, - jlong b_lat_view_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_haversineDistanceImpl( + JNIEnv *env, jclass clazz, jlong a_lon_view_handle, jlong a_lat_view_handle, + jlong b_lon_view_handle, jlong b_lat_view_handle) { JNI_NULL_CHECK(env, a_lon_view_handle, "input column_view a_lon is null", 0); JNI_NULL_CHECK(env, a_lat_view_handle, "input column_view a_lat is null", 0); JNI_NULL_CHECK(env, b_lon_view_handle, "input column_view b_lon is null", 0); @@ -93,8 +92,8 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_haversineDistanceImpl column_view *a_lat_column_view = reinterpret_cast(a_lat_view_handle); column_view *b_lon_column_view = reinterpret_cast(b_lon_view_handle); column_view *b_lat_column_view = reinterpret_cast(b_lat_view_handle); - std::unique_ptr result = - cuspatial::haversine_distance(*a_lon_column_view, *a_lat_column_view, *b_lon_column_view, *b_lat_column_view); + std::unique_ptr result = cuspatial::haversine_distance( + *a_lon_column_view, *a_lat_column_view, *b_lon_column_view, *b_lat_column_view); return reinterpret_cast(result.release()); } @@ -105,14 +104,13 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_haversineDistanceImpl // Native methods for cuspatial/hausdorff.hpp //////// -JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_directedHausdorffDistanceImpl(JNIEnv *env, - jclass clazz, - jlong xs_view_handle, - jlong ys_view_handle, - jlong points_per_space_view_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_directedHausdorffDistanceImpl( + JNIEnv *env, jclass clazz, jlong xs_view_handle, jlong ys_view_handle, + jlong points_per_space_view_handle) { JNI_NULL_CHECK(env, xs_view_handle, "input column_view xs is null", 0); JNI_NULL_CHECK(env, ys_view_handle, "input column_view ys is null", 0); - JNI_NULL_CHECK(env, points_per_space_view_handle, "input column_view points_per_space is null", 0); + JNI_NULL_CHECK(env, points_per_space_view_handle, "input column_view points_per_space is null", + 0); using cudf::column; using cudf::column_view; @@ -120,9 +118,10 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_directedHausdorffDist try { column_view *xs_column_view = reinterpret_cast(xs_view_handle); column_view *ys_column_view = reinterpret_cast(ys_view_handle); - column_view *points_per_space_column_view = reinterpret_cast(points_per_space_view_handle); - std::unique_ptr result = - cuspatial::directed_hausdorff_distance(*xs_column_view, *ys_column_view, *points_per_space_column_view); + column_view *points_per_space_column_view = + reinterpret_cast(points_per_space_view_handle); + std::unique_ptr result = cuspatial::directed_hausdorff_distance( + *xs_column_view, *ys_column_view, *points_per_space_column_view); return reinterpret_cast(result.release()); } @@ -133,14 +132,9 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_directedHausdorffDist // Native methods for cuspatial/spatial_window.hpp //////// -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_pointsInSpatialWindowImpl(JNIEnv *env, - jclass clazz, - jdouble window_min_x, - jdouble window_max_x, - jdouble window_min_y, - jdouble window_max_y, - jlong x_view_handle, - jlong y_view_handle) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_pointsInSpatialWindowImpl( + JNIEnv *env, jclass clazz, jdouble window_min_x, jdouble window_max_x, jdouble window_min_y, + jdouble window_max_y, jlong x_view_handle, jlong y_view_handle) { JNI_NULL_CHECK(env, x_view_handle, "input column_view points_x is null", 0); JNI_NULL_CHECK(env, y_view_handle, "input column_view points_y is null", 0); @@ -149,10 +143,10 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_pointsInSpatialW using cudf::table; try { - column_view *x_column_view = reinterpret_cast(x_view_handle); - column_view *y_column_view = reinterpret_cast(y_view_handle); - std::unique_ptr result = - cuspatial::points_in_spatial_window(window_min_x, window_max_x, window_min_y, window_max_y, *x_column_view, *y_column_view); + column_view *x_column_view = reinterpret_cast(x_view_handle); + column_view *y_column_view = reinterpret_cast(y_view_handle); + std::unique_ptr
result = cuspatial::points_in_spatial_window( + window_min_x, window_max_x, window_min_y, window_max_y, *x_column_view, *y_column_view); return convert_table_for_return(env, result); } CATCH_STD_CUSPATIAL(env, NULL); @@ -162,12 +156,9 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_pointsInSpatialW // Native methods for cuspatial/trajectory.hpp //////// -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_deriveTrajectoriesImpl(JNIEnv *env, - jclass clazz, - jlong object_id_view_handle, - jlong x_view_handle, - jlong y_view_handle, - jlong timestamp_view_handle) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_deriveTrajectoriesImpl( + JNIEnv *env, jclass clazz, jlong object_id_view_handle, jlong x_view_handle, + jlong y_view_handle, jlong timestamp_view_handle) { JNI_NULL_CHECK(env, object_id_view_handle, "input column_view object_id is null", 0); JNI_NULL_CHECK(env, x_view_handle, "input column_view x is null", 0); JNI_NULL_CHECK(env, y_view_handle, "input column_view y is null", 0); @@ -178,11 +169,12 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_deriveTrajectori try { column_view *object_id_column_view = reinterpret_cast(object_id_view_handle); - column_view *x_column_view = reinterpret_cast(x_view_handle); - column_view *y_column_view = reinterpret_cast(y_view_handle); + column_view *x_column_view = reinterpret_cast(x_view_handle); + column_view *y_column_view = reinterpret_cast(y_view_handle); column_view *timestamp_column_view = reinterpret_cast(timestamp_view_handle); - std::pair, std::unique_ptr> result = - cuspatial::derive_trajectories(*object_id_column_view, *x_column_view, *y_column_view, *timestamp_column_view); + std::pair, std::unique_ptr> result = + cuspatial::derive_trajectories(*object_id_column_view, *x_column_view, *y_column_view, + *timestamp_column_view); std::vector> extra; extra.emplace_back(std::move(result.second)); @@ -191,13 +183,9 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_deriveTrajectori CATCH_STD_CUSPATIAL(env, 0); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_trajectoryDistancesAndSpeedsImpl(JNIEnv *env, - jclass clazz, - jint num_trajectories, - jlong object_id_view_handle, - jlong x_view_handle, - jlong y_view_handle, - jlong timestamp_view_handle) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_trajectoryDistancesAndSpeedsImpl( + JNIEnv *env, jclass clazz, jint num_trajectories, jlong object_id_view_handle, + jlong x_view_handle, jlong y_view_handle, jlong timestamp_view_handle) { JNI_NULL_CHECK(env, object_id_view_handle, "input column_view object_id is null", 0); JNI_NULL_CHECK(env, x_view_handle, "input column_view x is null", 0); JNI_NULL_CHECK(env, y_view_handle, "input column_view y is null", 0); @@ -210,22 +198,20 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_trajectoryDistan try { cudf::size_type num_trajectories_int32 = reinterpret_cast(num_trajectories); column_view *object_id_column_view = reinterpret_cast(object_id_view_handle); - column_view *x_column_view = reinterpret_cast(x_view_handle); - column_view *y_column_view = reinterpret_cast(y_view_handle); + column_view *x_column_view = reinterpret_cast(x_view_handle); + column_view *y_column_view = reinterpret_cast(y_view_handle); column_view *timestamp_column_view = reinterpret_cast(timestamp_view_handle); - std::unique_ptr
result = - cuspatial::trajectory_distances_and_speeds(num_trajectories_int32, *object_id_column_view, *x_column_view, *y_column_view, *timestamp_column_view); + std::unique_ptr
result = cuspatial::trajectory_distances_and_speeds( + num_trajectories_int32, *object_id_column_view, *x_column_view, *y_column_view, + *timestamp_column_view); return convert_table_for_return(env, result); } CATCH_STD_CUSPATIAL(env, NULL); } -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_trajectoryBoundingBoxesImpl(JNIEnv *env, - jclass clazz, - jint num_trajectories, - jlong object_id_view_handle, - jlong x_view_handle, - jlong y_view_handle) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_trajectoryBoundingBoxesImpl( + JNIEnv *env, jclass clazz, jint num_trajectories, jlong object_id_view_handle, + jlong x_view_handle, jlong y_view_handle) { JNI_NULL_CHECK(env, object_id_view_handle, "input column_view object_id is null", 0); JNI_NULL_CHECK(env, x_view_handle, "input column_view x is null", 0); JNI_NULL_CHECK(env, y_view_handle, "input column_view y is null", 0); @@ -237,10 +223,10 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_trajectoryBoundi try { cudf::size_type num_trajectories_int32 = reinterpret_cast(num_trajectories); column_view *object_id_column_view = reinterpret_cast(object_id_view_handle); - column_view *x_column_view = reinterpret_cast(x_view_handle); - column_view *y_column_view = reinterpret_cast(y_view_handle); - std::unique_ptr
result = - cuspatial::trajectory_bounding_boxes(num_trajectories_int32, *object_id_column_view, *x_column_view, *y_column_view); + column_view *x_column_view = reinterpret_cast(x_view_handle); + column_view *y_column_view = reinterpret_cast(y_view_handle); + std::unique_ptr
result = cuspatial::trajectory_bounding_boxes( + num_trajectories_int32, *object_id_column_view, *x_column_view, *y_column_view); return convert_table_for_return(env, result); } CATCH_STD_CUSPATIAL(env, NULL); @@ -250,18 +236,15 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_trajectoryBoundi // Native methods for cuspatial/point_in_polygon.hpp //////// -JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_pointInPolygonImpl(JNIEnv *env, - jclass clazz, - jlong test_points_x_view_handle, - jlong test_points_y_view_handle, - jlong poly_offsets_view_handle, - jlong poly_ring_offsets_view_handle, - jlong poly_points_x_view_handle, - jlong poly_points_y_view_handle) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_pointInPolygonImpl( + JNIEnv *env, jclass clazz, jlong test_points_x_view_handle, jlong test_points_y_view_handle, + jlong poly_offsets_view_handle, jlong poly_ring_offsets_view_handle, + jlong poly_points_x_view_handle, jlong poly_points_y_view_handle) { JNI_NULL_CHECK(env, test_points_x_view_handle, "input column_view test_points_x is null", 0); JNI_NULL_CHECK(env, test_points_y_view_handle, "input column_view test_points_y is null", 0); JNI_NULL_CHECK(env, poly_offsets_view_handle, "input column_view poly_offsets is null", 0); - JNI_NULL_CHECK(env, poly_ring_offsets_view_handle, "input column_view poly_ring_offsets is null", 0); + JNI_NULL_CHECK(env, poly_ring_offsets_view_handle, "input column_view poly_ring_offsets is null", + 0); JNI_NULL_CHECK(env, poly_points_x_view_handle, "input column_view poly_points_x is null", 0); JNI_NULL_CHECK(env, poly_points_y_view_handle, "input column_view poly_points_y is null", 0); @@ -269,15 +252,21 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_pointInPolygonImpl(JN using cudf::column_view; try { - column_view *test_points_x_column_view = reinterpret_cast(test_points_x_view_handle); - column_view *test_points_y_column_view = reinterpret_cast(test_points_y_view_handle); - column_view *poly_offsets_column_view = reinterpret_cast(poly_offsets_view_handle); - column_view *poly_ring_offsets_column_view = reinterpret_cast(poly_ring_offsets_view_handle); - column_view *poly_points_x_column_view = reinterpret_cast(poly_points_x_view_handle); - column_view *poly_points_y_column_view = reinterpret_cast(poly_points_y_view_handle); - std::unique_ptr result = - cuspatial::point_in_polygon(*test_points_x_column_view, *test_points_y_column_view, *poly_offsets_column_view, *poly_ring_offsets_column_view, - *poly_points_x_column_view, *poly_points_y_column_view); + column_view *test_points_x_column_view = + reinterpret_cast(test_points_x_view_handle); + column_view *test_points_y_column_view = + reinterpret_cast(test_points_y_view_handle); + column_view *poly_offsets_column_view = + reinterpret_cast(poly_offsets_view_handle); + column_view *poly_ring_offsets_column_view = + reinterpret_cast(poly_ring_offsets_view_handle); + column_view *poly_points_x_column_view = + reinterpret_cast(poly_points_x_view_handle); + column_view *poly_points_y_column_view = + reinterpret_cast(poly_points_y_view_handle); + std::unique_ptr result = cuspatial::point_in_polygon( + *test_points_x_column_view, *test_points_y_column_view, *poly_offsets_column_view, + *poly_ring_offsets_column_view, *poly_points_x_column_view, *poly_points_y_column_view); return reinterpret_cast(result.release()); } @@ -288,12 +277,9 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cuspatial_CuSpatial_pointInPolygonImpl(JN // Native methods for cuspatial/coordinate_transform.hpp //////// -JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_lonlatToCartesianImpl(JNIEnv *env, - jclass clazz, - jdouble origin_lon, - jdouble origin_lat, - jlong input_lon_view_handle, - jlong input_lat_view_handle) { +JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_lonlatToCartesianImpl( + JNIEnv *env, jclass clazz, jdouble origin_lon, jdouble origin_lat, jlong input_lon_view_handle, + jlong input_lat_view_handle) { JNI_NULL_CHECK(env, input_lon_view_handle, "input column_view input_lon is null", 0); JNI_NULL_CHECK(env, input_lat_view_handle, "input column_view input_lat is null", 0); @@ -301,11 +287,12 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cuspatial_CuSpatial_lonlatToCartesia using cudf::column_view; try { - column_view *input_lon_column_view = reinterpret_cast(input_lon_view_handle); - column_view *input_lat_column_view = reinterpret_cast(input_lat_view_handle); + column_view *input_lon_column_view = reinterpret_cast(input_lon_view_handle); + column_view *input_lat_column_view = reinterpret_cast(input_lat_view_handle); std::pair, std::unique_ptr> result = - cuspatial::lonlat_to_cartesian(origin_lon, origin_lat, *input_lon_column_view, *input_lat_column_view); - + cuspatial::lonlat_to_cartesian(origin_lon, origin_lat, *input_lon_column_view, + *input_lat_column_view); + std::vector> columns; columns.emplace_back(std::move(result.first)); columns.emplace_back(std::move(result.second)); diff --git a/python/cuspatial/cuspatial/__init__.py b/python/cuspatial/cuspatial/__init__.py index 6478be32a..66f0eba7e 100644 --- a/python/cuspatial/cuspatial/__init__.py +++ b/python/cuspatial/cuspatial/__init__.py @@ -1,32 +1,32 @@ from ._version import get_versions from .core import interpolate +from .core.geodataframe import GeoDataFrame +from .core.geoseries import GeoSeries +from .core.interpolate import CubicSpline from .core.spatial import ( directed_hausdorff_distance, haversine_distance, join_quadtree_and_bounding_boxes, + linestring_bounding_boxes, lonlat_to_cartesian, - pairwise_point_distance, pairwise_linestring_distance, + pairwise_point_distance, pairwise_point_linestring_distance, pairwise_point_linestring_nearest_points, - polygon_bounding_boxes, - linestring_bounding_boxes, point_in_polygon, points_in_spatial_window, + polygon_bounding_boxes, quadtree_on_points, quadtree_point_in_polygon, quadtree_point_to_nearest_linestring, ) -from .core.interpolate import CubicSpline from .core.trajectory import ( derive_trajectories, trajectory_bounding_boxes, trajectory_distances_and_speeds, ) -from .core.geoseries import GeoSeries -from .core.geodataframe import GeoDataFrame -from .io.shapefile import read_polygon_shapefile from .io.geopandas import from_geopandas +from .io.shapefile import read_polygon_shapefile __version__ = get_versions()["version"] del get_versions diff --git a/python/cuspatial/cuspatial/_lib/distance.pyx b/python/cuspatial/cuspatial/_lib/distance.pyx index 66edcaa7c..64f776f9f 100644 --- a/python/cuspatial/cuspatial/_lib/distance.pyx +++ b/python/cuspatial/cuspatial/_lib/distance.pyx @@ -1,5 +1,3 @@ -from typing import Optional - from libcpp.memory cimport unique_ptr from libcpp.utility cimport move @@ -16,7 +14,7 @@ from cuspatial._lib.cpp.distance.point_distance cimport ( 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.cpp.optional cimport optional from cuspatial._lib.utils cimport unwrap_pyoptcol diff --git a/python/cuspatial/cuspatial/_lib/linestring_bounding_boxes.pyx b/python/cuspatial/cuspatial/_lib/linestring_bounding_boxes.pyx index 50d29d20a..7c19104b8 100644 --- a/python/cuspatial/cuspatial/_lib/linestring_bounding_boxes.pyx +++ b/python/cuspatial/cuspatial/_lib/linestring_bounding_boxes.pyx @@ -1,14 +1,11 @@ # Copyright (c) 2020-2022, NVIDIA CORPORATION. from libcpp.memory cimport unique_ptr -from libcpp.pair cimport pair 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 cudf._lib.cpp.table.table cimport table -from cudf._lib.cpp.types cimport size_type from cudf._lib.utils cimport data_from_unique_ptr from cuspatial._lib.cpp.linestring_bounding_box cimport ( diff --git a/python/cuspatial/cuspatial/_lib/nearest_points.pyx b/python/cuspatial/cuspatial/_lib/nearest_points.pyx index bf118b85c..fd8267419 100644 --- a/python/cuspatial/cuspatial/_lib/nearest_points.pyx +++ b/python/cuspatial/cuspatial/_lib/nearest_points.pyx @@ -1,11 +1,9 @@ -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.optional cimport nullopt, optional +from cuspatial._lib.cpp.optional cimport optional from cuspatial._lib.cpp.point_linestring_nearest_points cimport ( pairwise_point_linestring_nearest_points as c_func, point_linestring_nearest_points_result, diff --git a/python/cuspatial/cuspatial/_lib/polygon_bounding_boxes.pyx b/python/cuspatial/cuspatial/_lib/polygon_bounding_boxes.pyx index 9c7e13f0f..1b8c6799d 100644 --- a/python/cuspatial/cuspatial/_lib/polygon_bounding_boxes.pyx +++ b/python/cuspatial/cuspatial/_lib/polygon_bounding_boxes.pyx @@ -1,14 +1,11 @@ # Copyright (c) 2020, NVIDIA CORPORATION. from libcpp.memory cimport unique_ptr -from libcpp.pair cimport pair 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 cudf._lib.cpp.table.table cimport table -from cudf._lib.cpp.types cimport size_type from cudf._lib.utils cimport data_from_unique_ptr from cuspatial._lib.cpp.polygon_bounding_box cimport ( diff --git a/python/cuspatial/cuspatial/_lib/shapefile_reader.pyx b/python/cuspatial/cuspatial/_lib/shapefile_reader.pyx index 5d0742627..5592eb734 100644 --- a/python/cuspatial/cuspatial/_lib/shapefile_reader.pyx +++ b/python/cuspatial/cuspatial/_lib/shapefile_reader.pyx @@ -2,7 +2,6 @@ from enum import IntEnum -from libcpp cimport bool from libcpp.memory cimport unique_ptr from libcpp.string cimport string from libcpp.utility cimport move diff --git a/python/cuspatial/cuspatial/_lib/spatial.pyx b/python/cuspatial/cuspatial/_lib/spatial.pyx index 06a64014c..bcd5082ce 100644 --- a/python/cuspatial/cuspatial/_lib/spatial.pyx +++ b/python/cuspatial/cuspatial/_lib/spatial.pyx @@ -1,7 +1,5 @@ # Copyright (c) 2019, NVIDIA CORPORATION. -from cudf import Series - from libcpp.memory cimport unique_ptr from libcpp.pair cimport pair from libcpp.utility cimport move diff --git a/python/cuspatial/cuspatial/_lib/spatial_join.pyx b/python/cuspatial/cuspatial/_lib/spatial_join.pyx index 10764e596..aab04c938 100644 --- a/python/cuspatial/cuspatial/_lib/spatial_join.pyx +++ b/python/cuspatial/cuspatial/_lib/spatial_join.pyx @@ -2,12 +2,10 @@ from libc.stdint cimport int8_t from libcpp.memory cimport unique_ptr -from libcpp.pair cimport pair from libcpp.utility cimport move -from cudf._lib.column cimport Column, column, column_view +from cudf._lib.column cimport Column, column_view from cudf._lib.cpp.table.table cimport table, table_view -from cudf._lib.cpp.types cimport size_type from cudf._lib.utils cimport data_from_unique_ptr, table_view_from_table from cuspatial._lib.cpp.spatial_join cimport ( diff --git a/python/cuspatial/cuspatial/_lib/spatial_window.pyx b/python/cuspatial/cuspatial/_lib/spatial_window.pyx index 7c5d8d32d..3e1ced019 100644 --- a/python/cuspatial/cuspatial/_lib/spatial_window.pyx +++ b/python/cuspatial/cuspatial/_lib/spatial_window.pyx @@ -3,7 +3,7 @@ from libcpp.memory cimport unique_ptr from libcpp.utility cimport move -from cudf._lib.column cimport Column, column, column_view +from cudf._lib.column cimport Column, column_view from cudf._lib.cpp.table.table cimport table from cudf._lib.utils cimport data_from_unique_ptr diff --git a/python/cuspatial/cuspatial/core/spatial/__init__.py b/python/cuspatial/cuspatial/core/spatial/__init__.py index 6f20e91f7..5cd92a482 100644 --- a/python/cuspatial/cuspatial/core/spatial/__init__.py +++ b/python/cuspatial/cuspatial/core/spatial/__init__.py @@ -1,33 +1,23 @@ # Copyright (c) 2022, NVIDIA CORPORATION. -from .bounding import ( - polygon_bounding_boxes, - linestring_bounding_boxes, +from .bounding import linestring_bounding_boxes, polygon_bounding_boxes +from .distance import ( + directed_hausdorff_distance, + haversine_distance, + pairwise_linestring_distance, + pairwise_point_distance, + pairwise_point_linestring_distance, ) from .filtering import points_in_spatial_window - from .indexing import quadtree_on_points - from .join import ( - point_in_polygon, join_quadtree_and_bounding_boxes, + point_in_polygon, quadtree_point_in_polygon, quadtree_point_to_nearest_linestring, ) - -from .distance import ( - directed_hausdorff_distance, - haversine_distance, - pairwise_point_distance, - pairwise_linestring_distance, - pairwise_point_linestring_distance, -) - -from .projection import ( - lonlat_to_cartesian, -) - from .nearest_points import pairwise_point_linestring_nearest_points +from .projection import lonlat_to_cartesian __all__ = [ "directed_hausdorff_distance", diff --git a/python/cuspatial/setup.py b/python/cuspatial/setup.py index 4e81705b5..3c271cbad 100644 --- a/python/cuspatial/setup.py +++ b/python/cuspatial/setup.py @@ -1,9 +1,8 @@ # Copyright (c) 2018-2022, NVIDIA CORPORATION. +import versioneer from setuptools import find_packages from skbuild import setup -import versioneer - setup( name="cuspatial", version=versioneer.get_version(), diff --git a/setup.cfg b/setup.cfg index 746a3f6b0..028c88b18 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,24 @@ +# Copyright (c) 2019-2022, NVIDIA CORPORATION. + [flake8] -exclude = img,thirdparty,__init__.py,build +filename = *.py, *.pyx, *.pxd, *.pxi +exclude = __init__.py, *.egg, build, docs, .git +force-check = True ignore = # line break before binary operator - W503 + W503, # whitespace before : E203 +per-file-ignores = + # Rules ignored only in Cython: + # E211: whitespace before '(' (used in multi-line imports) + # E225: Missing whitespace around operators (breaks cython casting syntax like ) + # E226: Missing whitespace around arithmetic operators (breaks cython pointer syntax like int*) + # E227: Missing whitespace around bitwise or shift operator (Can also break casting syntax) + # E275: Missing whitespace after keyword (Doesn't work with Cython except?) + # E402: invalid syntax (works for Python, not Cython) + # E999: invalid syntax (works for Python, not Cython) + # W504: line break after binary operator (breaks lines that end with a pointer) + *.pyx: E211, E225, E226, E227, E275, E402, E999, W504 + *.pxd: E211, E225, E226, E227, E275, E402, E999, W504 + *.pxi: E211, E225, E226, E227, E275, E402, E999, W504