From 4746ed8e5b9316c63fbae64cf6b42de22b217738 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Wed, 24 May 2023 15:39:09 -0500 Subject: [PATCH 1/9] Add cython-lint configuration. --- .pre-commit-config.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2c334e69cc..abd70a8eec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,6 +18,10 @@ repos: types_or: [python, cython] exclude: thirdparty additional_dependencies: [flake8-force] + - repo: https://github.com/MarcoGorelli/cython-lint + rev: v0.15.0 + hooks: + - id: cython-lint - repo: https://github.com/pre-commit/mirrors-clang-format rev: v16.0.1 hooks: From 29d2568a2a3e24f135a51939663ee54010106c39 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Wed, 24 May 2023 16:54:28 -0500 Subject: [PATCH 2/9] Add config to exclude line length errors. --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index c68ea7ba4d..3094eee3ad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,3 +9,7 @@ ignore-words-list = "inout,numer,startd,couldn,referr" builtin = "clear" # disable warnings about binary files and wrong encoding quiet-level = 3 + +[tool.cython-lint] +max-line-length = 999 +ignore = ['E501'] From cffee7b3e33610ef88f37d3d8f55d1b33370581a Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Wed, 24 May 2023 16:57:01 -0500 Subject: [PATCH 3/9] Apply cython-lint changes. --- python/cuml/cluster/cpp/kmeans.pxd | 4 +-- python/cuml/cluster/dbscan.pyx | 6 +--- python/cuml/cluster/hdbscan/hdbscan.pyx | 7 ++--- python/cuml/cluster/hdbscan/prediction.pyx | 17 ++++------- python/cuml/cluster/kmeans.pyx | 15 ++++------ python/cuml/cluster/kmeans_mg.pyx | 24 +++++----------- python/cuml/common/opg_data_utils_mg.pyx | 6 ++-- python/cuml/datasets/arima.pyx | 4 +-- python/cuml/decomposition/base_mg.pyx | 13 ++------- python/cuml/decomposition/pca.pyx | 3 -- python/cuml/decomposition/pca_mg.pyx | 11 ++------ python/cuml/decomposition/tsvd.pyx | 4 +-- python/cuml/decomposition/tsvd_mg.pyx | 9 ++---- python/cuml/ensemble/randomforest_common.pyx | 6 ++-- python/cuml/ensemble/randomforest_shared.pyx | 5 ++-- .../cuml/ensemble/randomforestclassifier.pyx | 28 +++++-------------- .../cuml/ensemble/randomforestregressor.pyx | 23 ++++----------- .../fil/detail/raft_proto/optional.pxd | 2 +- python/cuml/experimental/fil/fil.pyx | 5 ++-- .../cuml/experimental/linear_model/lars.pyx | 9 ++---- python/cuml/explainer/base.pyx | 4 +-- python/cuml/explainer/kernel_shap.pyx | 7 ++--- python/cuml/explainer/permutation_shap.pyx | 5 ---- python/cuml/fil/fil.pyx | 9 ++---- python/cuml/internals/base.pyx | 4 --- python/cuml/internals/logger.pyx | 16 +++++------ python/cuml/linear_model/base.pyx | 10 +------ python/cuml/linear_model/base_mg.pyx | 6 +--- .../cuml/linear_model/linear_regression.pyx | 3 -- .../linear_model/linear_regression_mg.pyx | 11 ++------ python/cuml/linear_model/ridge.pyx | 5 +--- python/cuml/linear_model/ridge_mg.pyx | 10 ++----- python/cuml/manifold/simpl_set.pyx | 23 +++++++++------ python/cuml/manifold/t_sne.pyx | 5 +--- python/cuml/manifold/umap.pyx | 20 ++----------- python/cuml/manifold/umap_utils.pyx | 4 +-- python/cuml/metrics/accuracy.pyx | 2 +- .../metrics/cluster/adjusted_rand_index.pyx | 3 +- python/cuml/metrics/kl_divergence.pyx | 4 +-- python/cuml/metrics/pairwise_distances.pyx | 21 ++++++-------- python/cuml/metrics/regression.pyx | 5 ++-- python/cuml/metrics/trustworthiness.pyx | 7 ++--- .../cuml/neighbors/kneighbors_classifier.pyx | 9 ++---- .../neighbors/kneighbors_classifier_mg.pyx | 22 +++++++-------- .../cuml/neighbors/kneighbors_regressor.pyx | 9 ++---- .../neighbors/kneighbors_regressor_mg.pyx | 8 +++--- python/cuml/neighbors/nearest_neighbors.pyx | 12 ++------ .../cuml/neighbors/nearest_neighbors_mg.pyx | 10 +++---- .../random_projection/random_projection.pyx | 28 +++++++++---------- python/cuml/solvers/cd.pyx | 6 ++-- python/cuml/solvers/cd_mg.pyx | 8 ++---- python/cuml/solvers/qn.pyx | 2 +- python/cuml/solvers/sgd.pyx | 5 +--- python/cuml/svm/linear.pyx | 13 ++++----- python/cuml/svm/svc.pyx | 11 ++------ python/cuml/svm/svm_base.pyx | 4 +-- python/cuml/svm/svr.pyx | 4 --- python/cuml/tsa/arima.pyx | 11 ++------ python/cuml/tsa/auto_arima.pyx | 5 +--- python/cuml/tsa/seasonality.pyx | 8 +++--- python/cuml/tsa/stationarity.pyx | 3 +- 61 files changed, 174 insertions(+), 389 deletions(-) diff --git a/python/cuml/cluster/cpp/kmeans.pxd b/python/cuml/cluster/cpp/kmeans.pxd index 468d7cb62c..53b4c44d1d 100644 --- a/python/cuml/cluster/cpp/kmeans.pxd +++ b/python/cuml/cluster/cpp/kmeans.pxd @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -167,4 +167,4 @@ cdef extern from "cuml/cluster/kmeans.hpp" namespace "ML::kmeans": const double *X, int64_t n_samples, int64_t n_features, - double *X_new) except + \ No newline at end of file + double *X_new) except + diff --git a/python/cuml/cluster/dbscan.pyx b/python/cuml/cluster/dbscan.pyx index 0871f5b1b0..c916872ca3 100644 --- a/python/cuml/cluster/dbscan.pyx +++ b/python/cuml/cluster/dbscan.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import @@ -24,7 +23,6 @@ cp = gpu_only_import('cupy') from libcpp cimport bool from libc.stdint cimport uintptr_t, int64_t -from libc.stdlib cimport calloc, malloc, free from cuml.internals.array import CumlArray from cuml.internals.base import Base @@ -37,8 +35,6 @@ from cuml.internals.mixins import ClusterMixin from cuml.internals.mixins import CMajorInputTagMixin from cuml.metrics.distance_type cimport DistanceType -from collections import defaultdict - cdef extern from "cuml/cluster/dbscan.hpp" \ namespace "ML::Dbscan": diff --git a/python/cuml/cluster/hdbscan/hdbscan.pyx b/python/cuml/cluster/hdbscan/hdbscan.pyx index 8c4ebb854d..aecfc0ff96 100644 --- a/python/cuml/cluster/hdbscan/hdbscan.pyx +++ b/python/cuml/cluster/hdbscan/hdbscan.pyx @@ -40,7 +40,6 @@ from cuml.internals.api_decorators import device_interop_preparation from cuml.internals.api_decorators import enable_device_interop from cuml.internals.mixins import ClusterMixin from cuml.internals.mixins import CMajorInputTagMixin -from cuml.internals import logger from cuml.internals.import_utils import has_hdbscan import cuml @@ -257,7 +256,7 @@ def condense_hierarchy(dendrogram, new CondensedHierarchy[int, float]( handle_[0], n_leaves) - children, n_rows, _, _ = \ + children, _, _, _ = \ input_to_cuml_array(dendrogram[:, 0:2].astype('int32'), order='C', check_dtype=[np.int32], convert_to_dtype=(np.int32)) @@ -457,7 +456,7 @@ class HDBSCAN(UniversalBase, ClusterMixin, CMajorInputTagMixin): A score of how persistent each cluster is. A score of 1.0 represents a perfectly stable cluster that persists over all distance scales, while a score of 0.0 represents a perfectly ephemeral cluster. These - scores can be used to gauge the relative coherence of the + scores can be used to gauge the relative coherence of the clusters output by the algorithm. condensed_tree_ : CondensedTree object @@ -1026,7 +1025,7 @@ class HDBSCAN(UniversalBase, ClusterMixin, CMajorInputTagMixin): cdef handle_t* handle_ = self.handle.getHandle() - self.X_m, self.n_rows, self.n_cols, dtype = \ + self.X_m, self.n_rows, self.n_cols, _ = \ input_to_cuml_array(self._cpu_model._raw_data, order='C', check_dtype=[np.float32], convert_to_dtype=(np.float32 diff --git a/python/cuml/cluster/hdbscan/prediction.pyx b/python/cuml/cluster/hdbscan/prediction.pyx index 6a6803b186..6aa83c7b7a 100644 --- a/python/cuml/cluster/hdbscan/prediction.pyx +++ b/python/cuml/cluster/hdbscan/prediction.pyx @@ -25,20 +25,13 @@ from cuml.internals.safe_imports import gpu_only_import cp = gpu_only_import('cupy') from cuml.internals.array import CumlArray -from cuml.internals.base import Base -from cuml.common.doc_utils import generate_docstring from pylibraft.common.handle cimport handle_t -from pylibraft.common.handle import Handle from cuml.common import ( input_to_cuml_array, input_to_host_array ) -from cuml.common.array_descriptor import CumlArrayDescriptor -from cuml.internals.available_devices import is_cuda_available from cuml.internals.device_type import DeviceType -from cuml.internals.mixins import ClusterMixin -from cuml.internals.mixins import CMajorInputTagMixin from cuml.internals import logger from cuml.internals.import_utils import has_hdbscan @@ -96,7 +89,7 @@ cdef extern from "cuml/cluster/hdbscan.hpp" namespace "ML": DistanceType metric, float* membership_vec, size_t batch_size) - + void compute_membership_vector( const handle_t& handle, CondensedHierarchy[int, float] &condensed_tree, @@ -107,7 +100,7 @@ cdef extern from "cuml/cluster/hdbscan.hpp" namespace "ML": int min_samples, DistanceType metric, float* membership_vec, - size_t batch_size); + size_t batch_size) void out_of_sample_predict(const handle_t &handle, CondensedHierarchy[int, float] &condensed_tree, @@ -249,7 +242,7 @@ def membership_vector(clusterer, points_to_predict, batch_size=4096, convert_dty The new data points to predict cluster labels for. They should have the same dimensionality as the original dataset over which clusterer was fit. - + batch_size : int, optional, default=min(4096, n_points_to_predict) Lowers memory requirement by computing distance-based membership in smaller batches of points in the prediction data. A batch size @@ -306,7 +299,7 @@ def membership_vector(clusterer, points_to_predict, batch_size=4096, convert_dty convert_to_dtype=(np.float32 if convert_dtype else None)) - + if clusterer.n_clusters_ == 0: return np.zeros(n_prediction_points, dtype=np.float32) @@ -318,7 +311,7 @@ def membership_vector(clusterer, points_to_predict, batch_size=4096, convert_dty cdef uintptr_t prediction_ptr = points_to_predict_m.ptr cdef uintptr_t input_ptr = clusterer.X_m.ptr - + membership_vec = CumlArray.empty( (n_prediction_points * clusterer.n_clusters_,), dtype="float32") diff --git a/python/cuml/cluster/kmeans.pyx b/python/cuml/cluster/kmeans.pyx index a49a09a8c9..6b12deeaa1 100644 --- a/python/cuml/cluster/kmeans.pyx +++ b/python/cuml/cluster/kmeans.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,24 +16,21 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') -import warnings import typing from cython.operator cimport dereference as deref from libcpp cimport bool from libc.stdint cimport uintptr_t, int64_t -from libc.stdlib cimport calloc, malloc, free +from libc.stdlib cimport calloc, free from cuml.cluster.cpp.kmeans cimport fit_predict as cpp_fit_predict from cuml.cluster.cpp.kmeans cimport predict as cpp_predict from cuml.cluster.cpp.kmeans cimport transform as cpp_transform from cuml.cluster.cpp.kmeans cimport KMeansParams -from cuml.cluster.cpp.kmeans cimport InitMethod from cuml.internals.array import CumlArray from cuml.common.array_descriptor import CumlArrayDescriptor @@ -246,7 +243,7 @@ class KMeans(Base, else: self.init = 'preset' self._params_init = Array - self.cluster_centers_, n_rows, self.n_cols, self.dtype = \ + self.cluster_centers_, _n_rows, self.n_cols, self.dtype = \ input_to_cuml_array(init, order='C', check_dtype=[np.float32, np.float64]) @@ -417,7 +414,7 @@ class KMeans(Base, Sum of squared distances of samples to their closest cluster center. """ - X_m, n_rows, n_cols, dtype = \ + X_m, n_rows, n_cols, _ = \ input_to_cuml_array(X, order='C', check_dtype=self.dtype, convert_to_dtype=(self.dtype if convert_dtype else None), @@ -452,8 +449,6 @@ class KMeans(Base, cdef KMeansParams* params = \ self._get_kmeans_params() - cur_int_dtype = labels_.dtype - if self.dtype == np.float32: if int_dtype == np.int32: cpp_predict( @@ -548,7 +543,7 @@ class KMeans(Base, """ - X_m, n_rows, n_cols, dtype = \ + X_m, n_rows, _n_cols, _dtype = \ input_to_cuml_array(X, order='C', check_dtype=self.dtype, convert_to_dtype=(self.dtype if convert_dtype else None), diff --git a/python/cuml/cluster/kmeans_mg.pyx b/python/cuml/cluster/kmeans_mg.pyx index 34df18eb89..27ceb1f4b6 100644 --- a/python/cuml/cluster/kmeans_mg.pyx +++ b/python/cuml/cluster/kmeans_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,21 +16,17 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') -import warnings from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') from cython.operator cimport dereference as deref -from libcpp cimport bool from libc.stdint cimport uintptr_t, int64_t -from libc.stdlib cimport calloc, malloc, free +from libc.stdlib cimport free from cuml.internals.array import CumlArray -from cuml.internals.base import Base from pylibraft.common.handle cimport handle_t from cuml.common import input_to_cuml_array @@ -79,10 +75,10 @@ cdef extern from "cuml/cluster/kmeans_mg.hpp" \ const double *sample_weight, double *centroids, double &inertia, - int64_t &n_iter) except + + int64_t &n_iter) except + -class KMeansMG(KMeans): +class KMeansMG(KMeans): """ A Multi-Node Multi-GPU implementation of KMeans @@ -141,16 +137,10 @@ class KMeansMG(KMeans): cdef uintptr_t cluster_centers_ptr = self.cluster_centers_.ptr - int_dtype = np.int32 if np.int64(n_rows) * np.int64(n_cols) < 2**31-1 else np.int64 print(str(n_rows * n_cols)) - labels_ = CumlArray.zeros(shape=n_rows, dtype=int_dtype, - index=X_m.index) - - cdef uintptr_t labels_ptr = labels_.ptr - cdef float inertiaf = 0 cdef double inertiad = 0 @@ -224,9 +214,9 @@ class KMeansMG(KMeans): self.handle.sync() - self.labels_, _, _, _ = input_to_cuml_array(self.predict(X, - sample_weight=sample_weight), order='C', - convert_to_dtype=self.dtype) + self.labels_, _, _, _ = input_to_cuml_array(self.predict(X, + sample_weight=sample_weight), order='C', + convert_to_dtype=self.dtype) del(X_m) free(params) diff --git a/python/cuml/common/opg_data_utils_mg.pyx b/python/cuml/common/opg_data_utils_mg.pyx index 0a600a3dc2..f1e6107385 100644 --- a/python/cuml/common/opg_data_utils_mg.pyx +++ b/python/cuml/common/opg_data_utils_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ np = cpu_only_import('numpy') from cuml.common.opg_data_utils_mg cimport * from libc.stdlib cimport malloc, free -from libc.stdint cimport uintptr_t, uint32_t, uint64_t +from libc.stdint cimport uintptr_t from cuml.common import input_to_cuml_array from cython.operator cimport dereference as deref from cuml.internals.array import CumlArray @@ -213,7 +213,7 @@ def _build_part_inputs(cuda_arr_ifaces, cuml_arr_ifaces = [] for arr in cuda_arr_ifaces: - X_m, n_rows, n_cols, dtype = \ + X_m, _, _, _ = \ input_to_cuml_array(arr, order="F", convert_to_dtype=(np.float32 if convert_dtype diff --git a/python/cuml/datasets/arima.pyx b/python/cuml/datasets/arima.pyx index 099e66153f..d40c2072bd 100644 --- a/python/cuml/datasets/arima.pyx +++ b/python/cuml/datasets/arima.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ # distutils: language = c++ -import warnings - from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') diff --git a/python/cuml/decomposition/base_mg.pyx b/python/cuml/decomposition/base_mg.pyx index 309dc892b4..aa1d32e17d 100644 --- a/python/cuml/decomposition/base_mg.pyx +++ b/python/cuml/decomposition/base_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,24 +16,16 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') -from libc.stdlib cimport malloc, free +from libc.stdint cimport uintptr_t -from libcpp cimport bool -from libc.stdint cimport uintptr_t, uint32_t, uint64_t -from cython.operator cimport dereference as deref - -from cuml.internals.array import CumlArray import cuml.common.opg_data_utils_mg as opg import cuml.internals -from cuml.internals.base import Base -from pylibraft.common.handle cimport handle_t from cuml.decomposition.utils cimport * from cuml.decomposition.utils_mg cimport * from cuml.common import input_to_cuml_array @@ -97,7 +89,6 @@ class BaseDecompositionMG(object): rank_to_sizes, rank) - cdef uintptr_t trans_data cdef uintptr_t trans_part_desc if _transform: trans_arys = opg.build_pred_or_trans_arys(X_arys, "F", self.dtype) diff --git a/python/cuml/decomposition/pca.pyx b/python/cuml/decomposition/pca.pyx index e65afd2f56..9f5674224f 100644 --- a/python/cuml/decomposition/pca.pyx +++ b/python/cuml/decomposition/pca.pyx @@ -16,7 +16,6 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import @@ -28,7 +27,6 @@ from enum import IntEnum rmm = gpu_only_import('rmm') -from libcpp cimport bool from libc.stdint cimport uintptr_t from cython.operator cimport dereference as deref @@ -38,7 +36,6 @@ from cuml.internals.array import CumlArray from cuml.internals.base import UniversalBase from cuml.common.doc_utils import generate_docstring from pylibraft.common.handle cimport handle_t -from pylibraft.common.handle import Handle import cuml.internals.logger as logger from cuml.decomposition.utils cimport * from cuml.internals.input_utils import input_to_cuml_array diff --git a/python/cuml/decomposition/pca_mg.pyx b/python/cuml/decomposition/pca_mg.pyx index e76f6473a4..d4244b9966 100644 --- a/python/cuml/decomposition/pca_mg.pyx +++ b/python/cuml/decomposition/pca_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,27 +16,20 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') -from enum import IntEnum from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') -from libc.stdlib cimport malloc, free - from libcpp cimport bool -from libc.stdint cimport uintptr_t, uint32_t, uint64_t +from libc.stdint cimport uintptr_t from cython.operator cimport dereference as deref -from cuml.internals.array import CumlArray -import cuml.common.opg_data_utils_mg as opg import cuml.internals from pylibraft.common.handle cimport handle_t -from cuml.internals.base import Base from cuml.common.opg_data_utils_mg cimport * from cuml.decomposition import PCA from cuml.decomposition.base_mg import BaseDecompositionMG, MGSolver diff --git a/python/cuml/decomposition/tsvd.pyx b/python/cuml/decomposition/tsvd.pyx index c388a30e48..3241a527e4 100644 --- a/python/cuml/decomposition/tsvd.pyx +++ b/python/cuml/decomposition/tsvd.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') @@ -24,7 +23,6 @@ from enum import IntEnum from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') -from libcpp cimport bool from libc.stdint cimport uintptr_t diff --git a/python/cuml/decomposition/tsvd_mg.pyx b/python/cuml/decomposition/tsvd_mg.pyx index 12c338d507..f33c49ae26 100644 --- a/python/cuml/decomposition/tsvd_mg.pyx +++ b/python/cuml/decomposition/tsvd_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,25 +15,20 @@ # # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') -from libc.stdlib cimport malloc, free - from libcpp cimport bool -from libc.stdint cimport uintptr_t, uint32_t, uint64_t +from libc.stdint cimport uintptr_t from cython.operator cimport dereference as deref from pylibraft.common.handle cimport handle_t import cuml.internals -import cuml.common.opg_data_utils_mg as opg -from cuml.internals.base import Base from cuml.common.opg_data_utils_mg cimport * from cuml.decomposition.utils cimport * from cuml.decomposition.utils_mg cimport * diff --git a/python/cuml/ensemble/randomforest_common.pyx b/python/cuml/ensemble/randomforest_common.pyx index 77fe304d92..3a189fa2cd 100644 --- a/python/cuml/ensemble/randomforest_common.pyx +++ b/python/cuml/ensemble/randomforest_common.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import ctypes from cuml.internals.safe_imports import gpu_only_import cp = gpu_only_import('cupy') import math import warnings import typing -from inspect import signature from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') @@ -347,7 +345,7 @@ class BaseRandomForestModel(Base): fil_sparse_format, threshold=0.5, output_class=False, predict_proba=False) -> CumlArray: - _, n_rows, n_cols, dtype = \ + _, _, _, _ = \ input_to_cuml_array(X, order='F', check_cols=self.n_cols) treelite_handle = self._obtain_treelite_handle() diff --git a/python/cuml/ensemble/randomforest_shared.pyx b/python/cuml/ensemble/randomforest_shared.pyx index 5e4fe49649..dcaae34da6 100644 --- a/python/cuml/ensemble/randomforest_shared.pyx +++ b/python/cuml/ensemble/randomforest_shared.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,11 +17,10 @@ # distutils: language = c++ from libcpp.vector cimport vector -from cython.operator cimport dereference as deref, preincrement as inc from cpython.object cimport PyObject from libc.stdint cimport uintptr_t from libcpp.memory cimport unique_ptr -from typing import Tuple, Dict, List, Union +from typing import Dict, List, Union from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') diff --git a/python/cuml/ensemble/randomforestclassifier.pyx b/python/cuml/ensemble/randomforestclassifier.pyx index 1a08489c0e..af6810bbee 100644 --- a/python/cuml/ensemble/randomforestclassifier.pyx +++ b/python/cuml/ensemble/randomforestclassifier.pyx @@ -21,17 +21,12 @@ np = cpu_only_import('numpy') import nvtx from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') -import warnings -import cuml.internals.logger as logger - -from cuml import ForestInference from cuml.internals.array import CumlArray from cuml.internals.mixins import ClassifierMixin import cuml.internals from cuml.common.doc_utils import generate_docstring from cuml.common.doc_utils import insert_into_docstring -from pylibraft.common.handle import Handle from cuml.common import input_to_cuml_array from cuml.ensemble.randomforest_common import BaseRandomForestModel @@ -40,12 +35,8 @@ from cuml.ensemble.randomforest_shared cimport * from cuml.fil.fil import TreeliteModel -from cython.operator cimport dereference as deref - from libcpp cimport bool -from libcpp.vector cimport vector from libc.stdint cimport uintptr_t, uint64_t -from libc.stdlib cimport calloc, malloc, free from cuml.internals.safe_imports import gpu_only_import_from cuda = gpu_only_import_from('numba', 'cuda') @@ -54,8 +45,6 @@ from cuml.prims.label.classlabels import check_labels, invert_labels from pylibraft.common.handle cimport handle_t cimport cuml.common.cuda -cimport cython - cdef extern from "cuml/ensemble/randomforest.hpp" namespace "ML": @@ -262,13 +251,10 @@ class RandomForestClassifier(BaseRandomForestModel, output_type=output_type, **kwargs) - """ - TODO: - Add the preprocess and postprocess functions - in the cython code to normalize the labels - Link to the above issue on github : - https://github.com/rapidsai/cuml/issues/691 - """ + # TODO: Add the preprocess and postprocess functions in the cython code to + # normalize the labels + # Link to the above issue on github: + # https://github.com/rapidsai/cuml/issues/691 def __getstate__(self): state = self.__dict__.copy() cdef size_t params_t @@ -510,7 +496,7 @@ class RandomForestClassifier(BaseRandomForestModel, @cuml.internals.api_base_return_array(get_output_dtype=True) def _predict_model_on_cpu(self, X, convert_dtype) -> CumlArray: cdef uintptr_t X_ptr - X_m, n_rows, n_cols, dtype = \ + X_m, n_rows, n_cols, _dtype = \ input_to_cuml_array(X, order='C', convert_to_dtype=(self.dtype if convert_dtype else None), @@ -733,13 +719,13 @@ class RandomForestClassifier(BaseRandomForestModel, Accuracy of the model [0.0 - 1.0] """ - cdef uintptr_t X_ptr, y_ptr + cdef uintptr_t y_ptr _, n_rows, _, _ = \ input_to_cuml_array(X, check_dtype=self.dtype, convert_to_dtype=(self.dtype if convert_dtype else None), check_cols=self.n_cols) - y_m, n_rows, _, y_dtype = \ + y_m, n_rows, _, _ = \ input_to_cuml_array(y, check_dtype=np.int32, convert_to_dtype=(np.int32 if convert_dtype else False)) diff --git a/python/cuml/ensemble/randomforestregressor.pyx b/python/cuml/ensemble/randomforestregressor.pyx index fc34099b7e..5d9a55c866 100644 --- a/python/cuml/ensemble/randomforestregressor.pyx +++ b/python/cuml/ensemble/randomforestregressor.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,18 +21,13 @@ np = cpu_only_import('numpy') import nvtx from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') -import warnings -import cuml.internals.logger as logger - -from cuml import ForestInference from cuml.internals.array import CumlArray import cuml.internals from cuml.internals.mixins import RegressorMixin from cuml.common.doc_utils import generate_docstring from cuml.common.doc_utils import insert_into_docstring -from pylibraft.common.handle import Handle from cuml.common import input_to_cuml_array from cuml.ensemble.randomforest_common import BaseRandomForestModel @@ -41,12 +36,8 @@ from cuml.ensemble.randomforest_shared cimport * from cuml.fil.fil import TreeliteModel -from cython.operator cimport dereference as deref - from libcpp cimport bool -from libcpp.vector cimport vector from libc.stdint cimport uintptr_t, uint64_t -from libc.stdlib cimport calloc, malloc, free from cuml.internals.safe_imports import gpu_only_import_from cuda = gpu_only_import_from('numba', 'cuda') @@ -54,8 +45,6 @@ cuda = gpu_only_import_from('numba', 'cuda') from pylibraft.common.handle cimport handle_t cimport cuml.common.cuda -cimport cython - cdef extern from "cuml/ensemble/randomforest.hpp" namespace "ML": @@ -267,11 +256,9 @@ class RandomForestRegressor(BaseRandomForestModel, verbose=verbose, output_type=output_type, **kwargs) - """ - TODO: - Add the preprocess and postprocess functions - in the cython code to normalize the labels - """ + + # TODO: Add the preprocess and postprocess functions in the cython code to + # normalize the labels def __getstate__(self): state = self.__dict__.copy() cdef size_t params_t @@ -652,7 +639,7 @@ class RandomForestRegressor(BaseRandomForestModel, input_to_cuml_array(X, convert_to_dtype=(self.dtype if convert_dtype else None)) - y_m, n_rows, _, y_dtype = \ + y_m, n_rows, _, _ = \ input_to_cuml_array(y, convert_to_dtype=(dtype if convert_dtype else False)) diff --git a/python/cuml/experimental/fil/detail/raft_proto/optional.pxd b/python/cuml/experimental/fil/detail/raft_proto/optional.pxd index 1132aef18c..bbdea8ba28 100644 --- a/python/cuml/experimental/fil/detail/raft_proto/optional.pxd +++ b/python/cuml/experimental/fil/detail/raft_proto/optional.pxd @@ -38,7 +38,7 @@ cdef extern from "" namespace "std" nogil: void reset() T& emplace(...) T& operator*() - #T* operator->() # Not Supported + # T* operator->() # Not Supported optional& operator=(optional&) optional& operator=[U](U&) bool operator bool() diff --git a/python/cuml/experimental/fil/fil.pyx b/python/cuml/experimental/fil/fil.pyx index 1309e5b2e0..885be3dcc6 100644 --- a/python/cuml/experimental/fil/fil.pyx +++ b/python/cuml/experimental/fil/fil.pyx @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import cupy as cp import functools import numpy as np import nvtx @@ -201,7 +200,7 @@ cdef class ForestInference_impl(): model_dtype = self.get_dtype() cdef uintptr_t in_ptr - in_arr, n_rows, n_cols, dtype = input_to_cuml_array( + in_arr, n_rows, _, _ = input_to_cuml_array( X, order='C', convert_to_dtype=model_dtype, @@ -289,6 +288,7 @@ cdef class ForestInference_impl(): output_dtype=output_dtype ) + def _handle_legacy_fil_args(func): @functools.wraps(func) def wrapper(*args, **kwargs): @@ -602,7 +602,6 @@ class ForestInference(UniversalBase, CMajorInputTagMixin): if old_value != value: self._reload_model() - def __init__( self, *, diff --git a/python/cuml/experimental/linear_model/lars.pyx b/python/cuml/experimental/linear_model/lars.pyx index a4dd301ec2..25a2ead0ac 100644 --- a/python/cuml/experimental/linear_model/lars.pyx +++ b/python/cuml/experimental/linear_model/lars.pyx @@ -19,18 +19,14 @@ # cython: embedsignature = True # cython: language_level = 3 -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import cp = gpu_only_import('cupy') -import warnings import cuml.internals.logger as logger import cuml.internals -from collections import defaultdict - -from libcpp cimport bool, nullptr +from libcpp cimport nullptr from libc.stdint cimport uintptr_t from cuml.common import input_to_cuml_array @@ -39,7 +35,6 @@ from cuml.common.array_descriptor import CumlArrayDescriptor from cuml.internals.base import Base from cuml.internals.mixins import RegressorMixin from cuml.common.doc_utils import generate_docstring -from cuml.common.exceptions import NotFittedError from pylibraft.common.handle cimport handle_t cdef extern from "cuml/solvers/lars.hpp" namespace "ML::Solver::Lars": @@ -360,7 +355,7 @@ class Lars(Base, RegressorMixin): """ conv_dtype=(self.dtype if convert_dtype else None) - X_m, n_rows, n_cols, dtype = input_to_cuml_array( + X_m, n_rows, _n_cols, _dtype = input_to_cuml_array( X, check_dtype=self.dtype, convert_to_dtype=conv_dtype, check_cols=self.n_cols, order='F') diff --git a/python/cuml/explainer/base.pyx b/python/cuml/explainer/base.pyx index 7ad1b54afa..4d0bf77ab3 100644 --- a/python/cuml/explainer/base.pyx +++ b/python/cuml/explainer/base.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ from cuml.internals.safe_imports import gpu_only_import cudf = gpu_only_import('cudf') -import cuml.internals from cuml.internals.safe_imports import gpu_only_import cp = gpu_only_import('cupy') from cuml.internals.safe_imports import cpu_only_import @@ -27,7 +26,6 @@ import cuml.internals.logger as logger from cuml.internals.import_utils import has_shap from cuml.internals.input_utils import input_to_cupy_array from cuml.internals.input_utils import input_to_host_array -from cuml.internals.logger import debug from cuml.internals.logger import warn from cuml.explainer.common import get_dtype_from_model_func from cuml.explainer.common import get_handle_from_cuml_model_func diff --git a/python/cuml/explainer/kernel_shap.pyx b/python/cuml/explainer/kernel_shap.pyx index b11cb1cbc8..f1fc4cec71 100644 --- a/python/cuml/explainer/kernel_shap.pyx +++ b/python/cuml/explainer/kernel_shap.pyx @@ -14,7 +14,6 @@ # limitations under the License. # -import cuml.internals.logger as logger from cuml.internals.safe_imports import gpu_only_import cp = gpu_only_import('cupy') from cuml.internals.safe_imports import cpu_only_import @@ -26,10 +25,8 @@ from cuml.internals.input_utils import input_to_cupy_array from cuml.explainer.base import SHAPBase from cuml.explainer.common import get_cai_ptr from cuml.explainer.common import model_func_call -from cuml.explainer.common import output_list_shap_values from cuml.linear_model import Lasso from cuml.linear_model import LinearRegression -from pylibraft.common.handle import Handle from functools import lru_cache from itertools import combinations from numbers import Number @@ -324,12 +321,12 @@ class KernelExplainer(SHAPBase): self.randind, self.dtype) - row, n_rows, n_cols, dtype = \ + row, _, _, _ = \ input_to_cupy_array(row, order=self.order) cdef handle_t* handle_ = \ self.handle.getHandle() - cdef uintptr_t row_ptr, bg_ptr, ds_ptr, masked_ptr, x_ptr, smp_ptr + cdef uintptr_t row_ptr, bg_ptr, ds_ptr, x_ptr, smp_ptr row_ptr = get_cai_ptr(row) bg_ptr = get_cai_ptr(self.background) diff --git a/python/cuml/explainer/permutation_shap.pyx b/python/cuml/explainer/permutation_shap.pyx index 4bb3f6ae27..b0270b5873 100644 --- a/python/cuml/explainer/permutation_shap.pyx +++ b/python/cuml/explainer/permutation_shap.pyx @@ -14,7 +14,6 @@ # limitations under the License. # -import cuml from cuml.internals.safe_imports import gpu_only_import cp = gpu_only_import('cupy') from cuml.internals.safe_imports import cpu_only_import @@ -23,12 +22,8 @@ import time from cuml.internals.safe_imports import gpu_only_import_from cu_df = gpu_only_import_from('cudf', 'DataFrame') -from cuml.internals.array import CumlArray -from cuml.internals.input_utils import input_to_cupy_array from cuml.explainer.base import SHAPBase from cuml.explainer.common import get_cai_ptr -from cuml.explainer.common import get_dtype_from_model_func -from cuml.explainer.common import get_tag_from_model_func from cuml.explainer.common import model_func_call cuda = gpu_only_import_from('numba', 'cuda') from cuml.internals.safe_imports import cpu_only_import_from diff --git a/python/cuml/fil/fil.pyx b/python/cuml/fil/fil.pyx index b8b6f72913..078bdc6fcc 100644 --- a/python/cuml/fil/fil.pyx +++ b/python/cuml/fil/fil.pyx @@ -16,12 +16,8 @@ # distutils: language = c++ -import copy -import ctypes -import math from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') -import warnings pd = cpu_only_import('pandas') from inspect import getdoc @@ -30,7 +26,7 @@ rmm = gpu_only_import('rmm') from libcpp cimport bool from libc.stdint cimport uintptr_t -from libc.stdlib cimport calloc, malloc, free +from libc.stdlib cimport free import cuml.internals from cuml.internals.array import CumlArray @@ -43,7 +39,6 @@ from cuml.common.doc_utils import _parameters_docstrings from rmm._lib.memory_resource cimport DeviceMemoryResource from rmm._lib.memory_resource cimport get_current_device_resource -import treelite import treelite.sklearn as tl_skl cimport cuml.common.cuda @@ -382,7 +377,7 @@ cdef class ForestInference_impl(): " the FIL model.") fil_dtype = self.get_dtype() cdef uintptr_t X_ptr - X_m, n_rows, n_cols, dtype = \ + X_m, n_rows, _n_cols, _dtype = \ input_to_cuml_array(X, order='C', convert_to_dtype=fil_dtype, safe_dtype_conversion=safe_dtype_conversion, diff --git a/python/cuml/internals/base.pyx b/python/cuml/internals/base.pyx index 7209a80b61..cebe10c9e2 100644 --- a/python/cuml/internals/base.pyx +++ b/python/cuml/internals/base.pyx @@ -23,7 +23,6 @@ from importlib import import_module from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') import nvtx -import typing import cuml import cuml.common @@ -48,12 +47,10 @@ from cuml.internals.output_type import ( VALID_OUTPUT_TYPES ) from cuml.internals.array import CumlArray -from cuml.internals.array_sparse import SparseCumlArray from cuml.internals.safe_imports import ( gpu_only_import, gpu_only_import_from ) -from cuml.common.doc_utils import generate_docstring from cuml.internals.mixins import TagsMixin cp_ndarray = gpu_only_import_from('cupy', 'ndarray') @@ -437,7 +434,6 @@ class Base(TagsMixin, for func_name in ['fit', 'transform', 'predict', 'fit_transform', 'fit_predict']: if hasattr(self, func_name): - message = self.__class__.__module__ + '.' + func_name msg = '{class_name}.{func_name} [{addr}]' msg = msg.format(class_name=self.__class__.__module__, func_name=func_name, diff --git a/python/cuml/internals/logger.pyx b/python/cuml/internals/logger.pyx index bcdca6ca49..dc3dee98b0 100644 --- a/python/cuml/internals/logger.pyx +++ b/python/cuml/internals/logger.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -54,25 +54,25 @@ cdef extern from "cuml/common/logger.hpp" nogil: cdef int CUML_LEVEL_OFF -"""Enables all log messages upto and including `trace()`""" +# Enables all log messages up to and including `trace()` level_trace = CUML_LEVEL_TRACE -"""Enables all log messages upto and including `debug()`""" +# Enables all log messages up to and including `debug()` level_debug = CUML_LEVEL_DEBUG -"""Enables all log messages upto and including `info()`""" +# Enables all log messages up to and including `info()` level_info = CUML_LEVEL_INFO -"""Enables all log messages upto and including `warn()`""" +# Enables all log messages up to and including `warn()` level_warn = CUML_LEVEL_WARN -"""Enables all log messages upto and include `error()`""" +# Enables all log messages up to and include `error()` level_error = CUML_LEVEL_ERROR -"""Enables only `critical()` messages""" +# Enables only `critical()` messages level_critical = CUML_LEVEL_CRITICAL -"""Disables all log messages""" +# Disables all log messages level_off = CUML_LEVEL_OFF cdef void _log_callback(int lvl, const char * msg) with gil: diff --git a/python/cuml/linear_model/base.pyx b/python/cuml/linear_model/base.pyx index 99aef27977..7c9745cf6a 100644 --- a/python/cuml/linear_model/base.pyx +++ b/python/cuml/linear_model/base.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,27 +16,19 @@ # distutils: language = c++ -import ctypes import cuml.internals from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import cp = gpu_only_import('cupy') -import warnings from cuml.internals.safe_imports import gpu_only_import_from cuda = gpu_only_import_from('numba', 'cuda') -from collections import defaultdict -from libcpp cimport bool from libc.stdint cimport uintptr_t -from libc.stdlib cimport calloc, malloc, free from cuml.internals.array import CumlArray -from cuml.common.array_descriptor import CumlArrayDescriptor -from cuml.internals.base import Base from cuml.internals.input_utils import input_to_cuml_array -from cuml.internals.mixins import RegressorMixin from cuml.common.doc_utils import generate_docstring from pylibraft.common.handle cimport handle_t from cuml.internals.api_decorators import enable_device_interop diff --git a/python/cuml/linear_model/base_mg.pyx b/python/cuml/linear_model/base_mg.pyx index 172fd18081..660a6f2551 100644 --- a/python/cuml/linear_model/base_mg.pyx +++ b/python/cuml/linear_model/base_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ # distutils: language = c++ -import ctypes import cuml.common.opg_data_utils_mg as opg from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') @@ -24,12 +23,9 @@ from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') from libc.stdint cimport uintptr_t -from cython.operator cimport dereference as deref import cuml.internals -from cuml.internals.base import Base from cuml.internals.array import CumlArray -from pylibraft.common.handle cimport handle_t from cuml.common.opg_data_utils_mg cimport * from cuml.internals.input_utils import input_to_cuml_array from cuml.decomposition.utils cimport * diff --git a/python/cuml/linear_model/linear_regression.pyx b/python/cuml/linear_model/linear_regression.pyx index 9e04e40b57..5960ad35d0 100644 --- a/python/cuml/linear_model/linear_regression.pyx +++ b/python/cuml/linear_model/linear_regression.pyx @@ -16,7 +16,6 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import @@ -25,11 +24,9 @@ import warnings from cuml.internals.safe_imports import gpu_only_import_from cuda = gpu_only_import_from('numba', 'cuda') -from collections import defaultdict from libcpp cimport bool from libc.stdint cimport uintptr_t -from libc.stdlib cimport calloc, malloc, free from cuml import Handle from cuml.internals.array import CumlArray diff --git a/python/cuml/linear_model/linear_regression_mg.pyx b/python/cuml/linear_model/linear_regression_mg.pyx index 40a23229f2..1f5f31d3dc 100644 --- a/python/cuml/linear_model/linear_regression_mg.pyx +++ b/python/cuml/linear_model/linear_regression_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,25 +15,18 @@ # # distutils: language = c++ -import ctypes -import cuml.common.opg_data_utils_mg as opg from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') -from libc.stdlib cimport malloc, free - from libcpp cimport bool -from libc.stdint cimport uintptr_t, uint32_t, uint64_t +from libc.stdint cimport uintptr_t from cython.operator cimport dereference as deref import cuml.internals -from cuml.internals.base import Base -from cuml.internals.array import CumlArray from pylibraft.common.handle cimport handle_t from cuml.common.opg_data_utils_mg cimport * -from cuml.common import input_to_cuml_array from cuml.decomposition.utils cimport * from cuml.linear_model import LinearRegression diff --git a/python/cuml/linear_model/ridge.pyx b/python/cuml/linear_model/ridge.pyx index c0217b0fa7..a7bcaecfe5 100644 --- a/python/cuml/linear_model/ridge.pyx +++ b/python/cuml/linear_model/ridge.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,14 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') -from collections import defaultdict from cuml.internals.safe_imports import gpu_only_import_from cuda = gpu_only_import_from('numba', 'cuda') import warnings from libcpp cimport bool from libc.stdint cimport uintptr_t -from libc.stdlib cimport calloc, malloc, free from cuml.common.array_descriptor import CumlArrayDescriptor from cuml.internals.base import UniversalBase diff --git a/python/cuml/linear_model/ridge_mg.pyx b/python/cuml/linear_model/ridge_mg.pyx index 91df1639ca..e5c3273088 100644 --- a/python/cuml/linear_model/ridge_mg.pyx +++ b/python/cuml/linear_model/ridge_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,25 +15,19 @@ # # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') -from libc.stdlib cimport malloc, free - from libcpp cimport bool -from libc.stdint cimport uintptr_t, uint32_t, uint64_t +from libc.stdint cimport uintptr_t from cython.operator cimport dereference as deref import cuml.internals -from cuml.internals.base import Base -from cuml.internals.array import CumlArray from pylibraft.common.handle cimport handle_t from cuml.common.opg_data_utils_mg cimport * -from cuml.common import input_to_cuml_array from cuml.decomposition.utils cimport * from cuml.linear_model import Ridge diff --git a/python/cuml/manifold/simpl_set.pyx b/python/cuml/manifold/simpl_set.pyx index 729da3792b..a22f4da38a 100644 --- a/python/cuml/manifold/simpl_set.pyx +++ b/python/cuml/manifold/simpl_set.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ cp = gpu_only_import('cupy') from cuml.manifold.umap_utils cimport * from cuml.manifold.umap_utils import GraphHolder, find_ab_params -import cuml.internals -from cuml.internals.base import Base from cuml.internals.input_utils import input_to_cuml_array from cuml.internals.array import CumlArray @@ -61,7 +59,7 @@ def fuzzy_simplicial_set(X, n_neighbors, random_state=None, metric="euclidean", - metric_kwds={}, + metric_kwds=None, knn_indices=None, knn_dists=None, set_op_mix_ratio=1.0, @@ -121,6 +119,9 @@ def fuzzy_simplicial_set(X, 1-simplex between the ith and jth sample points. """ + if metric_kwds is None: + metric_kwds = {} + deterministic = random_state is not None if not isinstance(random_state, int): if isinstance(random_state, np.random.RandomState): @@ -139,7 +140,7 @@ def fuzzy_simplicial_set(X, umap_params.local_connectivity = local_connectivity umap_params.verbosity = verbose - X_m, n_rows, n_cols, _ = \ + X_m, _, _, _ = \ input_to_cuml_array(X, order='C', check_dtype=np.float32, @@ -200,9 +201,9 @@ def simplicial_set_embedding( init="spectral", random_state=None, metric="euclidean", - metric_kwds={}, + metric_kwds=None, output_metric="euclidean", - output_metric_kwds={}, + output_metric_kwds=None, verbose=False, ): """Perform a fuzzy simplicial set embedding, using a specified @@ -262,6 +263,12 @@ def simplicial_set_embedding( euclidean space. """ + if metric_kwds is None: + metric_kwds = {} + + if output_metric_kwds is None: + output_metric_kwds = {} + if init not in ['spectral', 'random']: raise Exception("Initialization strategy not supported: %d" % init) @@ -307,7 +314,7 @@ def simplicial_set_embedding( if 'p' in output_metric_kwds else 0 umap_params.verbosity = verbose - X_m, n_rows, n_cols, dtype = \ + X_m, _, _, _ = \ input_to_cuml_array(data, order='C', check_dtype=np.float32) graph = graph.tocoo() diff --git a/python/cuml/manifold/t_sne.pyx b/python/cuml/manifold/t_sne.pyx index 62316010c4..3680b9f8b9 100644 --- a/python/cuml/manifold/t_sne.pyx +++ b/python/cuml/manifold/t_sne.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,10 +18,8 @@ # cython: boundscheck = False # cython: wraparound = False -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') -import inspect pd = cpu_only_import('pandas') import warnings from cuml.internals.safe_imports import gpu_only_import @@ -47,7 +45,6 @@ from libcpp cimport bool from libc.stdint cimport uintptr_t from libc.stdint cimport int64_t from libc.stdlib cimport free -from libcpp.memory cimport shared_ptr from cython.operator cimport dereference as deref cimport cuml.common.cuda diff --git a/python/cuml/manifold/umap.pyx b/python/cuml/manifold/umap.pyx index 4fc69acfc2..7f5e35446e 100644 --- a/python/cuml/manifold/umap.pyx +++ b/python/cuml/manifold/umap.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,9 @@ # distutils: language = c++ -import typing -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') pd = cpu_only_import('pandas') -import warnings import joblib @@ -41,26 +38,17 @@ cp_coo_matrix = gpu_only_import_from('cupyx.scipy.sparse', 'coo_matrix') cp_csc_matrix = gpu_only_import_from('cupyx.scipy.sparse', 'csc_matrix') import cuml.internals -from cuml.common import using_output_type from cuml.internals.base import UniversalBase from pylibraft.common.handle cimport handle_t from cuml.common.doc_utils import generate_docstring from cuml.internals import logger from cuml.internals.input_utils import input_to_cuml_array -from cuml.internals.memory_utils import using_output_type -from cuml.internals.import_utils import has_scipy from cuml.internals.array import CumlArray from cuml.internals.array_sparse import SparseCumlArray from cuml.internals.mixins import CMajorInputTagMixin from cuml.common.sparse_utils import is_sparse from cuml.metrics.distance_type cimport DistanceType -from cuml.manifold.simpl_set import fuzzy_simplicial_set, \ - simplicial_set_embedding - -if has_scipy(True): - import scipy.sparse - from cuml.common.array_descriptor import CumlArrayDescriptor from cuml.internals.api_decorators import device_interop_preparation from cuml.internals.api_decorators import enable_device_interop @@ -70,8 +58,6 @@ rmm = gpu_only_import('rmm') from libc.stdint cimport uintptr_t from libc.stdlib cimport free -from libcpp.memory cimport shared_ptr - cimport cuml.common.cuda @@ -541,7 +527,7 @@ class UMAP(UniversalBase, # Handle dense inputs else: - self._raw_data, self.n_rows, self.n_dims, dtype = \ + self._raw_data, self.n_rows, self.n_dims, _ = \ input_to_cuml_array(X, order='C', check_dtype=np.float32, convert_to_dtype=(np.float32 if convert_dtype @@ -720,7 +706,7 @@ class UMAP(UniversalBase, convert_format=False) index = None else: - X_m, n_rows, n_cols, dtype = \ + X_m, n_rows, n_cols, _ = \ input_to_cuml_array(X, order='C', check_dtype=np.float32, convert_to_dtype=(np.float32 if convert_dtype diff --git a/python/cuml/manifold/umap_utils.pyx b/python/cuml/manifold/umap_utils.pyx index bf9b725754..d788d36b49 100644 --- a/python/cuml/manifold/umap_utils.pyx +++ b/python/cuml/manifold/umap_utils.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2022, NVIDIA CORPORATION. +# Copyright (c) 2022-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -128,5 +128,5 @@ def find_ab_params(spread, min_dist): yv = np.zeros(xv.shape) yv[xv < min_dist] = 1.0 yv[xv >= min_dist] = np.exp(-(xv[xv >= min_dist] - min_dist) / spread) - params, covar = curve_fit(curve, xv, yv) + params, _covar = curve_fit(curve, xv, yv) return params[0], params[1] diff --git a/python/cuml/metrics/accuracy.pyx b/python/cuml/metrics/accuracy.pyx index c09f9f7820..940aaa843a 100644 --- a/python/cuml/metrics/accuracy.pyx +++ b/python/cuml/metrics/accuracy.pyx @@ -68,7 +68,7 @@ def accuracy_score(ground_truth, predictions, handle=None, convert_dtype=True): preds_ptr = preds_m.ptr - ground_truth_m, _, _, ground_truth_dtype=\ + ground_truth_m, _, _, _ =\ input_to_cuml_array(ground_truth, convert_to_dtype=np.int32 if convert_dtype else None) diff --git a/python/cuml/metrics/cluster/adjusted_rand_index.pyx b/python/cuml/metrics/cluster/adjusted_rand_index.pyx index 9858710bad..97047eae4f 100644 --- a/python/cuml/metrics/cluster/adjusted_rand_index.pyx +++ b/python/cuml/metrics/cluster/adjusted_rand_index.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ from cuml.internals.safe_imports import gpu_only_import cp = gpu_only_import('cupy') -import warnings from libc.stdint cimport uintptr_t diff --git a/python/cuml/metrics/kl_divergence.pyx b/python/cuml/metrics/kl_divergence.pyx index 3dbaed3d6a..c7fdfc367a 100644 --- a/python/cuml/metrics/kl_divergence.pyx +++ b/python/cuml/metrics/kl_divergence.pyx @@ -19,9 +19,7 @@ cp = gpu_only_import('cupy') from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') import cuml.internals -from cuml.internals.input_utils import determine_array_type -from cuml.common import (input_to_cuml_array, CumlArray) -from cuml.internals import logger +from cuml.common import input_to_cuml_array from libc.stdint cimport uintptr_t from pylibraft.common.handle cimport handle_t from pylibraft.common.handle import Handle diff --git a/python/cuml/metrics/pairwise_distances.pyx b/python/cuml/metrics/pairwise_distances.pyx index 8b35b1b7a8..c7d9952a8c 100644 --- a/python/cuml/metrics/pairwise_distances.pyx +++ b/python/cuml/metrics/pairwise_distances.pyx @@ -31,13 +31,10 @@ cudf = gpu_only_import('cudf') scipy = cpu_only_import('scipy') cupyx = gpu_only_import('cupyx') import cuml.internals -from cuml.internals.base import _determine_stateless_output_type from cuml.common import (input_to_cuml_array, CumlArray) -from cuml.internals import logger from cuml.internals.input_utils import sparse_scipy_to_cp from cuml.common.sparse_utils import is_sparse from cuml.internals.array_sparse import SparseCumlArray -from cuml.metrics.cluster.utils import prepare_cluster_metric_inputs from cuml.metrics.distance_type cimport DistanceType from cuml.thirdparty_adapters import _get_mask @@ -65,9 +62,7 @@ cdef extern from "cuml/metrics/metrics.hpp" namespace "ML::Metrics": DistanceType metric, float metric_arg) except + -""" -List of available distance metrics in `pairwise_distances` -""" +# List of available distance metrics in `pairwise_distances` PAIRWISE_DISTANCE_METRICS = { "cityblock": DistanceType.L1, "cosine": DistanceType.CosineExpanded, @@ -106,7 +101,7 @@ PAIRWISE_DISTANCE_SPARSE_METRICS = { } -def _determine_metric(metric_str, is_sparse=False): +def _determine_metric(metric_str, is_sparse_=False): # Available options in scikit-learn and their pairs. See # sklearn.metrics.pairwise.PAIRWISE_DISTANCE_FUNCTIONS: # 'cityblock': L1 @@ -125,16 +120,16 @@ def _determine_metric(metric_str, is_sparse=False): raise ValueError(" The metric: '{}', is not supported at this time." .format(metric_str)) - if not(is_sparse) and (metric_str not in PAIRWISE_DISTANCE_METRICS): + if not is_sparse_ and (metric_str not in PAIRWISE_DISTANCE_METRICS): if metric_str in PAIRWISE_DISTANCE_SPARSE_METRICS: raise ValueError(" The metric: '{}', is only available on " "sparse data.".format(metric_str)) else: raise ValueError("Unknown metric: {}".format(metric_str)) - elif is_sparse and (metric_str not in PAIRWISE_DISTANCE_SPARSE_METRICS): + elif is_sparse_ and (metric_str not in PAIRWISE_DISTANCE_SPARSE_METRICS): raise ValueError("Unknown metric: {}".format(metric_str)) - if is_sparse: + if is_sparse_: return PAIRWISE_DISTANCE_SPARSE_METRICS[metric_str] else: return PAIRWISE_DISTANCE_METRICS[metric_str] @@ -195,13 +190,13 @@ def nan_euclidean_distances( if (Y.isnull().any()).any(): Y.fillna(0, inplace=True) - X_m, n_samples_x, n_features_x, dtype_x = \ + X_m, _n_samples_x, _n_features_x, dtype_x = \ input_to_cuml_array(X, order="K", check_dtype=[np.float32, np.float64]) if Y is None: Y = X_m - Y_m, n_samples_y, n_features_y, dtype_y = \ + Y_m, _n_samples_y, _n_features_y, _dtype_y = \ input_to_cuml_array( Y, order=X_m.order, convert_to_dtype=dtype_x, check_dtype=[dtype_x]) @@ -578,7 +573,7 @@ def sparse_pairwise_distances(X, Y=None, metric="euclidean", handle=None, .format(n_features_x, n_features_y)) # Get the metric string to a distance enum - metric_val = _determine_metric(metric, is_sparse=True) + metric_val = _determine_metric(metric, is_sparse_=True) x_nrows, y_nrows = X_m.indptr.shape[0] - 1, Y_m.indptr.shape[0] - 1 dest_m = CumlArray.zeros((x_nrows, y_nrows), dtype=dtype_x) diff --git a/python/cuml/metrics/regression.pyx b/python/cuml/metrics/regression.pyx index 2a6d27564a..e9a090fb37 100644 --- a/python/cuml/metrics/regression.pyx +++ b/python/cuml/metrics/regression.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ cp = gpu_only_import('cupy') from libc.stdint cimport uintptr_t import cuml.internals -from cuml.internals.array import CumlArray from pylibraft.common.handle import Handle from pylibraft.common.handle cimport handle_t from cuml.metrics cimport regression @@ -108,7 +107,7 @@ def _prepare_input_reg(y_true, y_pred, sample_weight, multioutput): """ allowed_d_types = [np.float32, np.float64, np.int32, np.int64] y_true = y_true.squeeze() if len(y_true.shape) > 1 else y_true - y_true, n_rows, n_cols, ytype = \ + y_true, n_rows, n_cols, _ = \ input_to_cuml_array(y_true, check_dtype=allowed_d_types) y_pred = y_pred.squeeze() if len(y_pred.shape) > 1 else y_pred diff --git a/python/cuml/metrics/trustworthiness.pyx b/python/cuml/metrics/trustworthiness.pyx index 7185c33a19..9d77238921 100644 --- a/python/cuml/metrics/trustworthiness.pyx +++ b/python/cuml/metrics/trustworthiness.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') -import warnings from cuml.internals.safe_imports import gpu_only_import_from cuda = gpu_only_import_from('numba', 'cuda') @@ -102,13 +101,13 @@ def trustworthiness(X, X_embedded, handle=None, n_neighbors=5, cdef uintptr_t d_X_ptr cdef uintptr_t d_X_embedded_ptr - X_m, n_samples, n_features, dtype1 = \ + X_m, n_samples, n_features, _ = \ input_to_cuml_array(X, order='C', check_dtype=np.float32, convert_to_dtype=(np.float32 if convert_dtype else None)) d_X_ptr = X_m.ptr - X_m2, n_rows, n_components, dtype2 = \ + X_m2, _, n_components, _ = \ input_to_cuml_array(X_embedded, order='C', check_dtype=np.float32, convert_to_dtype=(np.float32 if convert_dtype diff --git a/python/cuml/neighbors/kneighbors_classifier.pyx b/python/cuml/neighbors/kneighbors_classifier.pyx index 37a70620eb..989d4747aa 100644 --- a/python/cuml/neighbors/kneighbors_classifier.pyx +++ b/python/cuml/neighbors/kneighbors_classifier.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -39,14 +39,9 @@ from cython.operator cimport dereference as deref from pylibraft.common.handle cimport handle_t from libcpp.vector cimport vector -from libcpp cimport bool -from libcpp.memory cimport shared_ptr - rmm = gpu_only_import('rmm') -from libc.stdlib cimport malloc, free from libc.stdint cimport uintptr_t, int64_t -from libc.stdlib cimport calloc, malloc, free from cuml.internals.safe_imports import gpu_only_import_from cuda = gpu_only_import_from('numba', 'cuda') @@ -252,7 +247,7 @@ class KNeighborsClassifier(ClassifierMixin, knn_indices = self.kneighbors(X, return_distance=False, convert_dtype=convert_dtype) - inds, n_rows, n_cols, dtype = \ + inds, n_rows, _, _ = \ input_to_cuml_array(knn_indices, order='C', check_dtype=np.int64, convert_to_dtype=(np.int64 diff --git a/python/cuml/neighbors/kneighbors_classifier_mg.pyx b/python/cuml/neighbors/kneighbors_classifier_mg.pyx index 063137ce70..f319a6adac 100644 --- a/python/cuml/neighbors/kneighbors_classifier_mg.pyx +++ b/python/cuml/neighbors/kneighbors_classifier_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -112,9 +112,9 @@ class KNeighborsClassifierMG(NearestNeighborsMG): self.get_out_type(index, query) # Build input arrays and descriptors for native code interfacing - input = type(self).gen_local_input(index, index_parts_to_ranks, index_nrows, - query, query_parts_to_ranks, query_nrows, - ncols, rank, convert_dtype) + input = type(self).gen_local_input( + index, index_parts_to_ranks, index_nrows, query, + query_parts_to_ranks, query_nrows, ncols, rank, convert_dtype) # Build input labels arrays and descriptors for native code interfacing labels = type(self).gen_local_labels(index, convert_dtype, 'int32') @@ -180,8 +180,8 @@ class KNeighborsClassifierMG(NearestNeighborsMG): # Release memory type(self).free_mem(input) free(labels['labels']) - type(self)._free_unique(uniq_labels_vec, - n_unique_vec) + type(self)._free_unique( + uniq_labels_vec, n_unique_vec) for i in range(out_result_local_parts.size()): free(out_result_local_parts.at(i)) free(out_result_local_parts) @@ -221,9 +221,9 @@ class KNeighborsClassifierMG(NearestNeighborsMG): self.get_out_type(index, query) # Build input arrays and descriptors for native code interfacing - input = type(self).gen_local_input(index, index_parts_to_ranks, index_nrows, - query, query_parts_to_ranks, query_nrows, - ncols, rank, convert_dtype) + input = type(self).gen_local_input( + index, index_parts_to_ranks, index_nrows, query, + query_parts_to_ranks, query_nrows, ncols, rank, convert_dtype) # Build input labels arrays and descriptors for native code interfacing labels = type(self).gen_local_labels(index, convert_dtype, dtype='int32') @@ -293,8 +293,8 @@ class KNeighborsClassifierMG(NearestNeighborsMG): # Release memory type(self).free_mem(input) free(labels['labels']) - type(self)._free_unique(uniq_labels_vec, - n_unique_vec) + type(self)._free_unique( + uniq_labels_vec, n_unique_vec) free(probas_local_parts) return tuple(proba_cais) diff --git a/python/cuml/neighbors/kneighbors_regressor.pyx b/python/cuml/neighbors/kneighbors_regressor.pyx index 57cdb8f896..011c6b6d25 100644 --- a/python/cuml/neighbors/kneighbors_regressor.pyx +++ b/python/cuml/neighbors/kneighbors_regressor.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -36,15 +36,10 @@ from libcpp.vector cimport vector from pylibraft.common.handle cimport handle_t -from libcpp cimport bool -from libcpp.memory cimport shared_ptr - from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') -from libc.stdlib cimport malloc, free from libc.stdint cimport uintptr_t, int64_t -from libc.stdlib cimport calloc, malloc, free from cuml.internals.safe_imports import gpu_only_import_from cuda = gpu_only_import_from('numba', 'cuda') @@ -201,7 +196,7 @@ class KNeighborsRegressor(RegressorMixin, knn_indices = self.kneighbors(X, return_distance=False, convert_dtype=convert_dtype) - inds, n_rows, n_cols, dtype = \ + inds, n_rows, _n_cols, _dtype = \ input_to_cuml_array(knn_indices, order='C', check_dtype=np.int64, convert_to_dtype=(np.int64 if convert_dtype diff --git a/python/cuml/neighbors/kneighbors_regressor_mg.pyx b/python/cuml/neighbors/kneighbors_regressor_mg.pyx index 524bf4c3c1..48accf5730 100644 --- a/python/cuml/neighbors/kneighbors_regressor_mg.pyx +++ b/python/cuml/neighbors/kneighbors_regressor_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -105,9 +105,9 @@ class KNeighborsRegressorMG(NearestNeighborsMG): self.get_out_type(index, query) # Build input arrays and descriptors for native code interfacing - input = type(self).gen_local_input(index, index_parts_to_ranks, index_nrows, - query, query_parts_to_ranks, query_nrows, - ncols, rank, convert_dtype) + input = type(self).gen_local_input( + index, index_parts_to_ranks, index_nrows, query, + query_parts_to_ranks, query_nrows, ncols, rank, convert_dtype) # Build input labels arrays and descriptors for native code interfacing labels = type(self).gen_local_labels(index, convert_dtype, dtype='float32') diff --git a/python/cuml/neighbors/nearest_neighbors.pyx b/python/cuml/neighbors/nearest_neighbors.pyx index 4369b5d475..61f9887b23 100644 --- a/python/cuml/neighbors/nearest_neighbors.pyx +++ b/python/cuml/neighbors/nearest_neighbors.pyx @@ -23,7 +23,6 @@ np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import cp = gpu_only_import('cupy') cupyx = gpu_only_import('cupyx') -import ctypes import warnings import math @@ -34,7 +33,6 @@ from cuml.internals.array import CumlArray from cuml.internals.array_sparse import SparseCumlArray from cuml.common.doc_utils import generate_docstring from cuml.common.doc_utils import insert_into_docstring -from cuml.internals.import_utils import has_scipy from cuml.internals.mixins import CMajorInputTagMixin from cuml.internals.input_utils import input_to_cupy_array from cuml.common import input_to_cuml_array @@ -50,10 +48,8 @@ from pylibraft.common.handle cimport handle_t from cython.operator cimport dereference as deref from libcpp cimport bool -from libcpp.memory cimport shared_ptr from libc.stdint cimport uintptr_t, int64_t, uint32_t -from libc.stdlib cimport calloc, malloc, free from libcpp.vector cimport vector @@ -64,10 +60,6 @@ rmm = gpu_only_import('rmm') cimport cuml.common.cuda -if has_scipy(): - import scipy.sparse - - cdef extern from "raft/spatial/knn/ball_cover_types.hpp" \ namespace "raft::spatial::knn": cdef cppclass BallCoverIndex[int64_t, float, uint32_t]: @@ -368,7 +360,7 @@ class NearestNeighbors(UniversalBase, else: valid_metrics = cuml.neighbors.VALID_METRICS valid_metric_str = "" - self._fit_X, _, _, dtype = \ + self._fit_X, _, _, _ = \ input_to_cuml_array(X, order='C', check_dtype=np.float32, convert_to_dtype=(np.float32 if convert_dtype @@ -691,7 +683,7 @@ class NearestNeighbors(UniversalBase, metric = self._build_metric_type(self.effective_metric_) - X_m, N, _, dtype = \ + X_m, N, _, _ = \ input_to_cuml_array(X, order='C', check_dtype=np.float32, convert_to_dtype=(np.float32 if convert_dtype else False)) diff --git a/python/cuml/neighbors/nearest_neighbors_mg.pyx b/python/cuml/neighbors/nearest_neighbors_mg.pyx index f690187662..5596c1e2f6 100644 --- a/python/cuml/neighbors/nearest_neighbors_mg.pyx +++ b/python/cuml/neighbors/nearest_neighbors_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ from libcpp cimport bool from libcpp.vector cimport vector from libc.stdint cimport uintptr_t from cython.operator cimport dereference as deref -from libc.stdlib cimport calloc, malloc, free +from libc.stdlib cimport free cdef extern from "cuml/neighbors/knn_mg.hpp" namespace \ @@ -114,9 +114,9 @@ class NearestNeighborsMG(NearestNeighbors): else n_neighbors # Build input arrays and descriptors for native code interfacing - input = type(self).gen_local_input(index, index_parts_to_ranks, index_nrows, - query, query_parts_to_ranks, query_nrows, - ncols, rank, convert_dtype) + input = type(self).gen_local_input( + index, index_parts_to_ranks, index_nrows, query, + query_parts_to_ranks, query_nrows, ncols, rank, convert_dtype) query_cais = input['cais']['query'] local_query_rows = list(map(lambda x: x.shape[0], query_cais)) diff --git a/python/cuml/random_projection/random_projection.pyx b/python/cuml/random_projection/random_projection.pyx index 7a67e22b1c..210a45d7c5 100644 --- a/python/cuml/random_projection/random_projection.pyx +++ b/python/cuml/random_projection/random_projection.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -35,23 +35,23 @@ cdef extern from "cuml/random_projection/rproj_c.h" namespace "ML": # Structure holding random projection hyperparameters cdef struct paramsRPROJ: - int n_samples # number of samples - int n_features # number of features (original dimension) - int n_components # number of components (target dimension) - double eps # error tolerance according to Johnson-Lindenstrauss lemma # noqa E501 - bool gaussian_method # toggle Gaussian or Sparse random projection methods # noqa E501 - double density # ratio of non-zero component in the random projection matrix (used for sparse random projection) # noqa E501 - bool dense_output # toggle random projection's transformation as a dense or sparse matrix # noqa E501 - int random_state # seed used by random generator + int n_samples # number of samples + int n_features # number of features (original dimension) + int n_components # number of components (target dimension) + double eps # error tolerance according to Johnson-Lindenstrauss lemma # noqa E501 + bool gaussian_method # toggle Gaussian or Sparse random projection methods # noqa E501 + double density # ratio of non-zero component in the random projection matrix (used for sparse random projection) # noqa E501 + bool dense_output # toggle random projection's transformation as a dense or sparse matrix # noqa E501 + int random_state # seed used by random generator # Structure describing random matrix cdef cppclass rand_mat[T]: rand_mat(cuda_stream_view stream) except + # random matrix structure constructor (set all to nullptr) # noqa E501 - T *dense_data # dense random matrix data - int *indices # sparse CSC random matrix indices - int *indptr # sparse CSC random matrix indptr - T *sparse_data # sparse CSC random matrix data - size_t sparse_data_size # sparse CSC random matrix number of non-zero elements # noqa E501 + T *dense_data # dense random matrix data + int *indices # sparse CSC random matrix indices + int *indptr # sparse CSC random matrix indptr + T *sparse_data # sparse CSC random matrix data + size_t sparse_data_size # sparse CSC random matrix number of non-zero elements # noqa E501 # Function used to fit the model cdef void RPROJfit[T](const handle_t& handle, rand_mat[T] *random_matrix, diff --git a/python/cuml/solvers/cd.pyx b/python/cuml/solvers/cd.pyx index 1567a61c82..c6b5040124 100644 --- a/python/cuml/solvers/cd.pyx +++ b/python/cuml/solvers/cd.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') @@ -24,7 +23,6 @@ cuda = gpu_only_import_from('numba', 'cuda') from libcpp cimport bool from libc.stdint cimport uintptr_t -from libc.stdlib cimport calloc, malloc, free from cuml.common import CumlArray from cuml.common.array_descriptor import CumlArrayDescriptor @@ -314,7 +312,7 @@ class CD(Base, Predicts the y for X. """ - X_m, n_rows, n_cols, dtype = \ + X_m, n_rows, n_cols, _ = \ input_to_cuml_array(X, check_dtype=self.dtype, convert_to_dtype=(self.dtype if convert_dtype else None), diff --git a/python/cuml/solvers/cd_mg.pyx b/python/cuml/solvers/cd_mg.pyx index e8c20f94cd..d0bffa27c2 100644 --- a/python/cuml/solvers/cd_mg.pyx +++ b/python/cuml/solvers/cd_mg.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,22 +15,18 @@ # # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import rmm = gpu_only_import('rmm') from libcpp cimport bool -from libc.stdint cimport uintptr_t, uint32_t, uint64_t +from libc.stdint cimport uintptr_t from cython.operator cimport dereference as deref import cuml.internals -from cuml.internals.base import Base -from cuml.internals.array import CumlArray from pylibraft.common.handle cimport handle_t from cuml.common.opg_data_utils_mg cimport * -from cuml.internals.input_utils import input_to_cuml_array from cuml.decomposition.utils cimport * from cuml.linear_model.base_mg import MGFitMixin from cuml.solvers import CD diff --git a/python/cuml/solvers/qn.pyx b/python/cuml/solvers/qn.pyx index 6585719f9d..4069b032ad 100644 --- a/python/cuml/solvers/qn.pyx +++ b/python/cuml/solvers/qn.pyx @@ -472,7 +472,7 @@ class QN(Base, X, check_dtype=[np.float32, np.float64], order='K' ) - y_m, lab_rows, _, _ = input_to_cuml_array( + y_m, _, _, _ = input_to_cuml_array( y, check_dtype=self.dtype, convert_to_dtype=(self.dtype if convert_dtype else None), check_rows=n_rows, check_cols=1 diff --git a/python/cuml/solvers/sgd.pyx b/python/cuml/solvers/sgd.pyx index d50ac3c212..df0c7f9c92 100644 --- a/python/cuml/solvers/sgd.pyx +++ b/python/cuml/solvers/sgd.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,9 +15,7 @@ # distutils: language = c++ -import typing -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import @@ -28,7 +26,6 @@ cuda = gpu_only_import_from('numba', 'cuda') from libcpp cimport bool from libc.stdint cimport uintptr_t -from libc.stdlib cimport calloc, malloc, free import cuml.internals from cuml.internals.base import Base diff --git a/python/cuml/svm/linear.pyx b/python/cuml/svm/linear.pyx index dd2e3bf8dd..a0bcf5d3a5 100644 --- a/python/cuml/svm/linear.pyx +++ b/python/cuml/svm/linear.pyx @@ -38,7 +38,6 @@ from libcpp cimport bool as cppbool from cuda.ccudart cimport( cudaMemcpyAsync, cudaMemcpyKind, - cudaMemcpyDeviceToDevice ) @@ -219,7 +218,7 @@ for prop_name in LSVMPWrapper().get_param_names(): del __add_prop LinearSVM_defaults = LSVMPWrapper() -'''Default parameter values for LinearSVM, re-exported from C++.''' +# Default parameter values for LinearSVM, re-exported from C++. cdef union SomeLinearSVMModel: LinearSVMModel[float] float32 @@ -296,7 +295,6 @@ cdef class LinearSVMWrapper: " estimator with fit_intercept enabled") self.dtype = X.dtype if do_training else coefs.dtype - cdef cuda_stream_view stream = self.handle.get_stream() nClasses = 0 if self.dtype != np.float32 and self.dtype != np.float64: @@ -311,7 +309,6 @@ cdef class LinearSVMWrapper: if do_training: nCols = X.shape[1] nRows = X.shape[0] - sw_ptr = sampleWeight.ptr if sampleWeight is not None else 0 if self.dtype == np.float32: with cuda_interruptible(): with nogil: @@ -638,7 +635,7 @@ class LinearSVM(Base, metaclass=WithReexportedParams): def fit(self, X, y, sample_weight=None, convert_dtype=True) -> 'LinearSVM': - X_m, n_rows, n_cols, self.dtype = input_to_cuml_array(X, order='F') + X_m, n_rows, _n_cols, self.dtype = input_to_cuml_array(X, order='F') convert_to_dtype = self.dtype if convert_dtype else None y_m = input_to_cuml_array( y, check_dtype=self.dtype, @@ -690,7 +687,7 @@ class LinearSVM(Base, metaclass=WithReexportedParams): def predict(self, X, convert_dtype=True) -> CumlArray: convert_to_dtype = self.dtype if convert_dtype else None - X_m, n_rows, n_cols, _ = input_to_cuml_array( + X_m, _, _, _ = input_to_cuml_array( X, check_dtype=self.dtype, convert_to_dtype=convert_to_dtype) self.__sync_model() @@ -698,7 +695,7 @@ class LinearSVM(Base, metaclass=WithReexportedParams): def decision_function(self, X, convert_dtype=True) -> CumlArray: convert_to_dtype = self.dtype if convert_dtype else None - X_m, n_rows, n_cols, _ = input_to_cuml_array( + X_m, _, _, _ = input_to_cuml_array( X, check_dtype=self.dtype, convert_to_dtype=convert_to_dtype) self.__sync_model() @@ -706,7 +703,7 @@ class LinearSVM(Base, metaclass=WithReexportedParams): def predict_proba(self, X, log=False, convert_dtype=True) -> CumlArray: convert_to_dtype = self.dtype if convert_dtype else None - X_m, n_rows, n_cols, _ = input_to_cuml_array( + X_m, _, _, _ = input_to_cuml_array( X, check_dtype=self.dtype, convert_to_dtype=convert_to_dtype) self.__sync_model() diff --git a/python/cuml/svm/svc.pyx b/python/cuml/svm/svc.pyx index c4774a4df3..bca184784b 100644 --- a/python/cuml/svm/svc.pyx +++ b/python/cuml/svm/svc.pyx @@ -15,9 +15,6 @@ # distutils: language = c++ -import typing - -import ctypes from cuml.internals.safe_imports import gpu_only_import cudf = gpu_only_import('cudf') from cuml.internals.safe_imports import gpu_only_import @@ -33,20 +30,17 @@ from libc.stdint cimport uintptr_t import cuml.internals from cuml.internals.array import CumlArray -from cuml.internals.base import Base from cuml.internals.mixins import ClassifierMixin from cuml.common.doc_utils import generate_docstring -from cuml.common.array_descriptor import CumlArrayDescriptor from cuml.internals.logger import warn from pylibraft.common.handle cimport handle_t from pylibraft.common.interruptible import cuda_interruptible -from cuml.common import input_to_cuml_array, input_to_host_array, with_cupy_rmm +from cuml.common import input_to_cuml_array, input_to_host_array from cuml.internals.input_utils import input_to_cupy_array from cuml.preprocessing import LabelEncoder from libcpp cimport bool, nullptr from cuml.svm.svm_base import SVMBase from cuml.internals.import_utils import has_sklearn -from cuml.internals.mixins import FMajorInputTagMixin if has_sklearn(): from cuml.multiclass import MulticlassClassifier @@ -125,7 +119,7 @@ def apply_class_weight(handle, sample_weight, class_weight, y, verbose, output_t ----------- handle : cuml.Handle Specifies the cuml.handle that holds internal CUDA state for - computations in this model. + computations in this model. sample_weight: array-like (device or host), shape = (n_samples, 1) sample weights or None if not given class_weight : dict or string (default=None) @@ -171,7 +165,6 @@ def apply_class_weight(handle, sample_weight, class_weight, y, verbose, output_t class_weight = {i: weights[i] for i in range(n_classes)} else: keys = class_weight.keys() - keys_series = cudf.Series(keys) encoded_keys = le.transform(cudf.Series(keys)).values_host class_weight = {enc_key: class_weight[key] for enc_key, key in zip(encoded_keys, keys)} diff --git a/python/cuml/svm/svm_base.pyx b/python/cuml/svm/svm_base.pyx index 2a34554217..c69fd2fde5 100644 --- a/python/cuml/svm/svm_base.pyx +++ b/python/cuml/svm/svm_base.pyx @@ -15,7 +15,6 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import gpu_only_import cupy = gpu_only_import('cupy') from cuml.internals.safe_imports import cpu_only_import @@ -24,7 +23,6 @@ np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import_from cuda = gpu_only_import_from('numba', 'cuda') -from cython.operator cimport dereference as deref from libc.stdint cimport uintptr_t import cuml.internals @@ -553,7 +551,7 @@ class SVMBase(Base, self._check_is_fitted('_model') - X_m, n_rows, n_cols, pred_dtype = \ + X_m, n_rows, n_cols, _ = \ input_to_cuml_array( X, check_dtype=self.dtype, diff --git a/python/cuml/svm/svr.pyx b/python/cuml/svm/svr.pyx index 4d89d95755..cc31ef2da6 100644 --- a/python/cuml/svm/svr.pyx +++ b/python/cuml/svm/svr.pyx @@ -15,7 +15,6 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import gpu_only_import cupy = gpu_only_import('cupy') from cuml.internals.safe_imports import cpu_only_import @@ -24,14 +23,11 @@ np = cpu_only_import('numpy') from cuml.internals.safe_imports import gpu_only_import_from cuda = gpu_only_import_from('numba', 'cuda') -from cython.operator cimport dereference as deref from libc.stdint cimport uintptr_t from cuml.internals.array import CumlArray -from cuml.internals.base import Base from cuml.internals.mixins import RegressorMixin from cuml.common.doc_utils import generate_docstring -from cuml.metrics import r2_score from pylibraft.common.handle cimport handle_t from cuml.common import input_to_cuml_array from libcpp cimport bool, nullptr diff --git a/python/cuml/tsa/arima.pyx b/python/cuml/tsa/arima.pyx index e450251f83..379fd5e6a7 100644 --- a/python/cuml/tsa/arima.pyx +++ b/python/cuml/tsa/arima.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,14 +18,12 @@ from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') -import sys import nvtx -import ctypes from libc.stdint cimport uintptr_t from libcpp cimport bool from libcpp.vector cimport vector -from typing import List, Tuple, Dict, Mapping, Optional, Union +from typing import Tuple, Dict, Mapping, Optional, Union import cuml.internals from cuml.internals.array import CumlArray @@ -35,11 +33,8 @@ from pylibraft.common.handle cimport handle_t from cuml.tsa.batched_lbfgs import batched_fmin_lbfgs_b import cuml.internals.logger as logger from cuml.common import has_scipy -from cuml.internals.input_utils import determine_array_dtype from cuml.internals.input_utils import input_to_cuml_array -from cuml.internals.input_utils import input_to_host_array from cuml.internals import _deprecate_pos_args -import warnings cdef extern from "cuml/tsa/arima_common.h" namespace "ML": @@ -882,7 +877,6 @@ class ARIMA(Base): observations """ # noqa def fit_helper(x_in, fit_method): - cdef uintptr_t d_y_ptr = self.d_y.ptr def f(x: np.ndarray) -> np.ndarray: """The (batched) energy functional returning the negative @@ -1102,7 +1096,6 @@ class ARIMA(Base): else self.n_obs) cdef LoglikeMethod ll_method = MLE - diff = self.simple_differencing cdef uintptr_t d_temp_mem = self._temp_mem.ptr arima_mem_ptr = new ARIMAMemory[double]( diff --git a/python/cuml/tsa/auto_arima.pyx b/python/cuml/tsa/auto_arima.pyx index 43ccc1a413..6f94e086bd 100644 --- a/python/cuml/tsa/auto_arima.pyx +++ b/python/cuml/tsa/auto_arima.pyx @@ -1,5 +1,5 @@ # -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ import typing -import ctypes import itertools from libc.stdint cimport uintptr_t from libcpp cimport bool @@ -39,11 +38,9 @@ from pylibraft.common.handle cimport handle_t from pylibraft.common.handle import Handle from cuml.common import input_to_cuml_array from cuml.common import using_output_type -from cuml.internals.input_utils import determine_array_dtype from cuml.tsa.arima import ARIMA from cuml.tsa.seasonality import seas_test from cuml.tsa.stationarity import kpss_test -import warnings # TODO: diff --git a/python/cuml/tsa/seasonality.pyx b/python/cuml/tsa/seasonality.pyx index 37f94f716d..6d26d5a018 100644 --- a/python/cuml/tsa/seasonality.pyx +++ b/python/cuml/tsa/seasonality.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,13 +16,13 @@ # distutils: language = c++ from cuml.internals.safe_imports import cpu_only_import -np = cpu_only_import('numpy') import cuml.internals from cuml.internals.array import CumlArray -from pylibraft.common.handle cimport handle_t from cuml.internals.input_utils import input_to_host_array, input_to_cuml_array +np = cpu_only_import('numpy') + # TODO: #2234 and #2235 @@ -77,7 +77,7 @@ def seas_test(y, s, handle=None) -> CumlArray: .format(s)) # At the moment we use a host array - h_y, n_obs, batch_size, dtype = \ + h_y, n_obs, batch_size, _ = \ input_to_host_array(y, check_dtype=[np.float32, np.float64]) # Temporary: Python implementation diff --git a/python/cuml/tsa/stationarity.pyx b/python/cuml/tsa/stationarity.pyx index d5ea6a589b..396b82eb4c 100644 --- a/python/cuml/tsa/stationarity.pyx +++ b/python/cuml/tsa/stationarity.pyx @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ # distutils: language = c++ -import ctypes from cuml.internals.safe_imports import cpu_only_import np = cpu_only_import('numpy') from libc.stdint cimport uintptr_t From 5cb7975cc7b227f7eebc9d1be88992d40cd3f62c Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Wed, 24 May 2023 17:12:04 -0500 Subject: [PATCH 4/9] Update docs. --- CONTRIBUTING.md | 1 + pyproject.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b3818444f9..0baec5a219 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -107,6 +107,7 @@ please see the `.pre-commit-config.yaml` file. - `clang-format`: Formats C++ and CUDA code for consistency and readability. - `black`: Auto-formats Python code to conform to the PEP 8 style guide. - `flake8`: Lints Python code for syntax errors and common code style issues. +- `cython-lint`: Lints Cython code for syntax errors and common code style issues. - _`DeprecationWarning` checker_: Checks for new `DeprecationWarning` being introduced in Python code, and instead `FutureWarning` should be used. - _`#include` syntax checker_: Ensures consistent syntax for C++ `#include` statements. diff --git a/pyproject.toml b/pyproject.toml index 3094eee3ad..a6e20329b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,5 +11,6 @@ builtin = "clear" quiet-level = 3 [tool.cython-lint] +# TODO: Re-enable E501 with a reasonable line length max-line-length = 999 ignore = ['E501'] From afb9b0d251cbd63a83b09cde0f7e138e3076180b Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Fri, 2 Jun 2023 14:37:54 -0500 Subject: [PATCH 5/9] Apply fixes from rapids-dependency-file-generator. --- python/pyproject.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/pyproject.toml b/python/pyproject.toml index 92137a0c25..d87ce282b7 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -18,8 +18,8 @@ requires = [ "cuda-python>=11.7.1,<12.0", "cython>=0.29,<0.30", "ninja", - "pylibraft==23.6.*", - "rmm==23.6.*", + "pylibraft==23.8.*", + "rmm==23.8.*", "scikit-build>=0.13.1,<0.17.2", "setuptools", "treelite==3.2.0", @@ -57,7 +57,7 @@ authors = [ license = { text = "Apache 2.0" } requires-python = ">=3.9" dependencies = [ - "cudf==23.6.*", + "cudf==23.8.*", "cupy-cuda11x>=12.0.0", "dask-cuda==23.8.*", "dask-cudf==23.8.*", @@ -65,7 +65,7 @@ dependencies = [ "distributed==2023.3.2.1", "joblib>=0.11", "numba>=0.57", - "raft-dask==23.6.*", + "raft-dask==23.8.*", "scipy", "treelite==3.2.0", "treelite_runtime==3.2.0", From d77330577d6e8b5f0b0cbfee224b6f3079993384 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Fri, 30 Jun 2023 13:00:33 -0500 Subject: [PATCH 6/9] Add back public APIs with no-cython-lint. --- python/cuml/manifold/umap.pyx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/cuml/manifold/umap.pyx b/python/cuml/manifold/umap.pyx index 7f5e35446e..686152a6f0 100644 --- a/python/cuml/manifold/umap.pyx +++ b/python/cuml/manifold/umap.pyx @@ -49,6 +49,9 @@ from cuml.internals.mixins import CMajorInputTagMixin from cuml.common.sparse_utils import is_sparse from cuml.metrics.distance_type cimport DistanceType +from cuml.manifold.simpl_set import fuzzy_simplicial_set # no-cython-lint +from cuml.manifold.simpl_set import simplicial_set_embedding # no-cython-lint + from cuml.common.array_descriptor import CumlArrayDescriptor from cuml.internals.api_decorators import device_interop_preparation from cuml.internals.api_decorators import enable_device_interop From 92e8a8f7bc72b648b438571c872901206821a7db Mon Sep 17 00:00:00 2001 From: Simon Adorf Date: Fri, 30 Jun 2023 23:51:17 +0200 Subject: [PATCH 7/9] Remove obsolete input_to_cuml_array conversion in BaseRandomForestModel. --- python/cuml/ensemble/randomforest_common.pyx | 3 --- 1 file changed, 3 deletions(-) diff --git a/python/cuml/ensemble/randomforest_common.pyx b/python/cuml/ensemble/randomforest_common.pyx index 3a189fa2cd..a3f23c6093 100644 --- a/python/cuml/ensemble/randomforest_common.pyx +++ b/python/cuml/ensemble/randomforest_common.pyx @@ -345,9 +345,6 @@ class BaseRandomForestModel(Base): fil_sparse_format, threshold=0.5, output_class=False, predict_proba=False) -> CumlArray: - _, _, _, _ = \ - input_to_cuml_array(X, order='F', - check_cols=self.n_cols) treelite_handle = self._obtain_treelite_handle() storage_type = \ _check_fil_parameter_validity(depth=self.max_depth, From e324d3802436cfb6a805433afc3bf145b83be975 Mon Sep 17 00:00:00 2001 From: Simon Adorf Date: Fri, 30 Jun 2023 23:55:08 +0200 Subject: [PATCH 8/9] Drop unneeded variable name. --- python/cuml/manifold/umap_utils.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/cuml/manifold/umap_utils.pyx b/python/cuml/manifold/umap_utils.pyx index d788d36b49..5d69ead34c 100644 --- a/python/cuml/manifold/umap_utils.pyx +++ b/python/cuml/manifold/umap_utils.pyx @@ -128,5 +128,5 @@ def find_ab_params(spread, min_dist): yv = np.zeros(xv.shape) yv[xv < min_dist] = 1.0 yv[xv >= min_dist] = np.exp(-(xv[xv >= min_dist] - min_dist) / spread) - params, _covar = curve_fit(curve, xv, yv) + params, _ = curve_fit(curve, xv, yv) return params[0], params[1] From 1cfe86c0b89be16bada56014508e49a8271ea9d7 Mon Sep 17 00:00:00 2001 From: Simon Adorf Date: Sat, 1 Jul 2023 00:01:00 +0200 Subject: [PATCH 9/9] Add comment that explains need for no-cython-lint markers. --- python/cuml/manifold/umap.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/cuml/manifold/umap.pyx b/python/cuml/manifold/umap.pyx index 686152a6f0..eb02258e2c 100644 --- a/python/cuml/manifold/umap.pyx +++ b/python/cuml/manifold/umap.pyx @@ -51,6 +51,10 @@ from cuml.metrics.distance_type cimport DistanceType from cuml.manifold.simpl_set import fuzzy_simplicial_set # no-cython-lint from cuml.manifold.simpl_set import simplicial_set_embedding # no-cython-lint +# TODO: These two symbols are considered part of the public API of this module +# which is why imports should not be removed. The no-cython-lint markers can be +# replaced with an explicit __all__ specifications once +# https://github.com/MarcoGorelli/cython-lint/issues/80 is resolved. from cuml.common.array_descriptor import CumlArrayDescriptor from cuml.internals.api_decorators import device_interop_preparation