Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ def fit(self, X, y=None) -> "ColumnTransformer":
self.fit_transform(X, y=y)
return self

@cuml.internals.reflect(reset="type")
@cuml.internals.reflect(reset=True)
def fit_transform(self, X, y=None) -> SparseCumlArray:
"""Fit all transformers, transform the data and concatenate results.

Expand Down
28 changes: 14 additions & 14 deletions python/cuml/cuml/_thirdparty/sklearn/preprocessing/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def _get_param_names(cls):
"copy"
]

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "MinMaxScaler":
"""Compute the minimum and maximum to be used for later scaling.

Expand All @@ -347,7 +347,7 @@ def fit(self, X, y=None) -> "MinMaxScaler":
self._reset()
return self.partial_fit(X, y)

@reflect(reset="type")
@reflect(reset=True)
def partial_fit(self, X, y=None) -> "MinMaxScaler":
"""Online computation of min and max on X for later scaling.

Expand Down Expand Up @@ -709,7 +709,7 @@ def _attrs_to_cpu(self, model):
}
return {**attrs, **super()._attrs_to_cpu(model)}

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "StandardScaler":
"""Compute the mean and std to be used for later scaling.

Expand All @@ -727,7 +727,7 @@ def fit(self, X, y=None) -> "StandardScaler":
self._reset()
return self.partial_fit(X, y)

@reflect(reset="type")
@reflect(reset=True)
def partial_fit(self, X, y=None) -> "StandardScaler":
"""
Online computation of mean and std on X for later scaling.
Expand Down Expand Up @@ -1024,7 +1024,7 @@ def _get_param_names(cls):
"copy"
]

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "MaxAbsScaler":
"""Compute the maximum absolute value to be used for later scaling.

Expand All @@ -1039,7 +1039,7 @@ def fit(self, X, y=None) -> "MaxAbsScaler":
self._reset()
return self.partial_fit(X, y)

@reflect(reset="type")
@reflect(reset=True)
def partial_fit(self, X, y=None) -> "MaxAbsScaler":
"""
Online computation of max absolute value of X for later scaling.
Expand Down Expand Up @@ -1287,7 +1287,7 @@ def _get_param_names(cls):
"copy"
]

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "RobustScaler":
"""Compute the median and quantiles to be used for scaling.

Expand Down Expand Up @@ -1618,7 +1618,7 @@ def get_feature_names(self, input_features=None):
feature_names.append(name)
return feature_names

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "PolynomialFeatures":
"""
Compute number of output features.
Expand Down Expand Up @@ -1924,7 +1924,7 @@ def __sklearn_tags__(self):
tags.requires_fit = False
return tags

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "Normalizer":
"""Do nothing and return the estimator unchanged

Expand Down Expand Up @@ -2059,7 +2059,7 @@ def __sklearn_tags__(self):
tags.requires_fit = False
return tags

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "Binarizer":
"""Do nothing and return the estimator unchanged

Expand Down Expand Up @@ -2200,7 +2200,7 @@ def __init__(self):
# Needed for backported inspect.signature compatibility with PyPy
pass

@reflect(reset="type")
@reflect(reset=True)
def fit(self, K, y=None) -> 'KernelCenterer':
"""Fit KernelCenterer

Expand Down Expand Up @@ -2458,7 +2458,7 @@ def _sparse_fit(self, X, random_state):
# https://github.com/numpy/numpy/issues/14685
self.quantiles_ = np.array(cpu_np.maximum.accumulate(self.quantiles_))

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> 'QuantileTransformer':
"""Compute the quantiles used for transforming.

Expand Down Expand Up @@ -2887,7 +2887,7 @@ def _get_param_names(cls):
"copy"
]

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> 'PowerTransformer':
"""Estimate the optimal parameter lambda for each feature.

Expand All @@ -2908,7 +2908,7 @@ def fit(self, X, y=None) -> 'PowerTransformer':
self._fit(X, y=y, force_transform=False)
return self

@reflect(reset="type")
@reflect(reset=True)
def fit_transform(self, X, y=None) -> CumlArray:
return self._fit(X, y, force_transform=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _get_param_names(cls):
"strategy"
]

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "KBinsDiscretizer":
"""
Fit the estimator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _check_inverse_transform(self, X):
" want to proceed regardless, set"
" 'check_inverse=False'.", UserWarning)

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "FunctionTransformer":
"""Fit transformer by checking X.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def _validate_input(self, X, in_fit):

return X

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "SimpleImputer":
"""Fit the imputer on X.

Expand Down Expand Up @@ -701,7 +701,7 @@ def _fit(self, X, y=None):

return missing_features_info[0]

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None) -> "MissingIndicator":
"""Fit the transformer on X.

Expand Down Expand Up @@ -760,7 +760,7 @@ def transform(self, X) -> SparseCumlArray:

return imputer_mask

@reflect(reset="type")
@reflect(reset=True)
def fit_transform(self, X, y=None) -> SparseCumlArray:
"""Generate missing values indicator for X.

Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/cluster/agglomerative.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class AgglomerativeClustering(ClusterMixin, CMajorInputTagMixin, Base):
self.c = c

@generate_docstring()
@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None, *, convert_dtype=True) -> "AgglomerativeClustering":
"""
Fit the hierarchical clustering from features.
Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/cluster/dbscan.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class DBSCAN(InteropMixin,
self.algorithm = algorithm

@generate_docstring(skip_parameters_heading=True)
@reflect(reset="type")
@reflect(reset=True)
def fit(
self,
X,
Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/cluster/hdbscan/hdbscan.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ class HDBSCAN(InteropMixin, ClusterMixin, CMajorInputTagMixin, Base):
self.prediction_data = True

@generate_docstring()
@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None, *, convert_dtype=True) -> "HDBSCAN":
"""
Fit HDBSCAN model from features.
Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/cluster/kmeans.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ class KMeans(InteropMixin,
return self.n_clusters

@generate_docstring()
@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None, sample_weight=None, *, convert_dtype=True) -> "KMeans":
"""
Compute k-means clustering with X.
Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/cluster/spectral_clustering.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class SpectralClustering(InteropMixin,
self.fit(X, y=y)
return self.labels_

@cuml.internals.reflect(reset="type")
@cuml.internals.reflect(reset=True)
def fit(self, X, y=None) -> "SpectralClustering":
"""Perform spectral clustering on ``X``.

Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/covariance/empirical_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __init__(
self.store_precision = store_precision
self.assume_centered = assume_centered

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None, *, convert_dtype=True) -> "EmpiricalCovariance":
"""Fit the maximum likelihood covariance estimator to X.

Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/covariance/ledoit_wolf.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def __init__(
self.assume_centered = assume_centered
self.block_size = block_size

@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y=None, *, convert_dtype=True) -> "LedoitWolf":
"""Fit the Ledoit-Wolf shrunk covariance model to X.

Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/decomposition/incremental_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __init__(
)
self.batch_size = batch_size

@cuml.internals.reflect(reset="type")
@cuml.internals.reflect(reset=True)
def fit(self, X, y=None, *, convert_dtype=True) -> "IncrementalPCA":
"""
Fit the model with X, using minibatches of size batch_size.
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/decomposition/pca.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class PCA(InteropMixin,
self.noise_variance_ = noise_variance

@generate_docstring(X='dense_sparse')
@cuml.internals.reflect(reset="type")
@cuml.internals.reflect(reset=True)
def fit(self, X, y=None, *, convert_dtype=True) -> "PCA":
"""
Fit the model with X. y is currently ignored.
Expand Down Expand Up @@ -507,7 +507,7 @@ class PCA(InteropMixin,
'type': 'dense_sparse',
'description': 'Transformed values',
'shape': '(n_samples, n_components)'})
@cuml.internals.reflect(reset="type")
@cuml.internals.reflect(reset=True)
def fit_transform(self, X, y=None) -> CumlArray:
"""
Fit the model with X and apply the dimensionality reduction on X.
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/decomposition/tsvd.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class TruncatedSVD(InteropMixin,
return self.components_.shape[0]

@generate_docstring()
@cuml.internals.reflect(reset="type")
@cuml.internals.reflect(reset=True)
def fit(self, X, y=None) -> "TruncatedSVD":
"""
Fit model on training cudf DataFrame X. y is currently ignored.
Expand All @@ -300,7 +300,7 @@ class TruncatedSVD(InteropMixin,
'type': 'dense',
'description': 'Reduced version of X',
'shape': '(n_samples, n_components)'})
@cuml.internals.reflect(reset="type")
@cuml.internals.reflect(reset=True)
def fit_transform(self, X, y=None, *, convert_dtype=True) -> CumlArray:
"""
Fit model to X and perform dimensionality reduction on X.
Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/experimental/linear_model/lars.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Lars(RegressorMixin, Base):
return gram

@generate_docstring(y="dense_anydtype")
@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y, convert_dtype=True) -> "Lars":
"""
Fit the model with X and y.
Expand Down
26 changes: 5 additions & 21 deletions python/cuml/cuml/internals/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from cuml.internals.array import CumlArray
from cuml.internals.array_sparse import SparseCumlArray
from cuml.internals.global_settings import GlobalSettings
from cuml.internals.validation import check_features

__all__ = (
"check_output_type",
Expand Down Expand Up @@ -427,15 +426,11 @@ def reflect(
provide ``None`` to disable this inference entirely; in this case the
output type is expected to be specified manually either internal or
external to the method.
reset : bool or "type", default=False
If True, both the features and reflected type are reset on the estimator.
If ``"type"``, only the reflected type is reset on the estimator.
reset : bool, default=False
If True, the input type for reflection is reset on the estimator.
Defaults to False, to not reset anything. Most estimators should set
``reset=True`` on any fit-like methods.
"""
# Local to avoid circular imports
import cuml.accel

if func is None:
return lambda func: reflect(
func,
Expand Down Expand Up @@ -463,33 +458,22 @@ def reflect(
if array is not None:
array = _get_param(sig, array)

if reset not in (True, False, "type"):
raise ValueError(f"reset={reset!r} is not supported")

if (reset is not False) and (model is None or array is None):
if reset and (model is None or array is None):
raise ValueError(
f"`reset={reset}` is not valid with `array=None` or `model=None`"
"`reset=True` is not valid with `array=None` or `model=None`"
)

@functools.wraps(func)
def inner(*args, **kwargs):
# Accept list/tuple inputs when accelerator is active
accept_lists = cuml.accel.enabled()

# Bind arguments
bound = sig.bind(*args, **kwargs)
bound.apply_defaults()

model_arg = None if model is None else bound.arguments[model]
array_arg = None if array is None else bound.arguments[array]
if accept_lists and isinstance(array_arg, (list, tuple)):
array_arg = np.asarray(array_arg)

with enter_internal_context() as was_external:
if reset is not False:
if reset:
model_arg._set_output_type(array_arg)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if reset is True:
check_features(model_arg, array_arg, reset=True)

res = func(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/kernel_ridge/kernel_ridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def _get_kernel(self, X, Y=None):
).to_output("cupy")

@generate_docstring()
@reflect(reset="type")
@reflect(reset=True)
def fit(
self, X, y, sample_weight=None, *, convert_dtype=True
) -> "KernelRidge":
Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/linear_model/elastic_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def sparse_coef_(self):
return cupyx.scipy.sparse.csr_matrix(self.coef_.to_output("cupy"))

@generate_docstring()
@reflect(reset="type")
@reflect(reset=True)
def fit(
self, X, y, sample_weight=None, *, convert_dtype=True
) -> "ElasticNet":
Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/linear_model/linear_regression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class LinearRegression(InteropMixin,
return coef, intercept

@generate_docstring()
@reflect(reset="type")
@reflect(reset=True)
def fit(self, X, y, sample_weight=None, *, convert_dtype=True) -> "LinearRegression":
"""
Fit the model with X and y.
Expand Down
2 changes: 1 addition & 1 deletion python/cuml/cuml/linear_model/logistic_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _get_l1_l2_strength(self):
return l1_strength, l2_strength

@generate_docstring(X="dense_sparse")
@cuml.internals.reflect(reset="type")
@cuml.internals.reflect(reset=True)
def fit(
self, X, y, sample_weight=None, *, convert_dtype=True
) -> "LogisticRegression":
Expand Down
Loading
Loading