kennard_stone.utils package#
Distance computation and helpers.
- kennard_stone.utils.is_installed(package_name: str) bool#
Check if the package is installed.
- Parameters:
package_name (str) – package name like sklearn
- Returns:
if installed, True
- Return type:
bool
- kennard_stone.utils.pairwise_distances(X: ArrayLike, Y: ArrayLike | None = None, metric: kennard_stone.utils._type_alias.MetricLike = 'euclidean', n_jobs: int | None = None, ensure_all_finite: bool = True, force_all_finite: bool | None = None, device: kennard_stone.utils._type_alias.Device = 'cpu', verbose: int = 1, **kwargs) ndarray#
Compute the pairwise distance matrix between two point sets.
Wraps scikit-learn’s
pairwise_distancesand PyTorch’storch.cdistand chooses an implementation depending on the environment and device.- Parameters:
X (array-like of shape (n_samples_1, n_features)) – First set of points.
Y (array-like of shape (n_samples_2, n_features), default=None) – Second set of points. If
None, distances withinXare computed.metric (str or callable, default="euclidean") – Distance metric. If a string, it must be accepted by scikit-learn. With PyTorch, you can use ‘manhattan’, ‘euclidean’, ‘chebyshev’, or ‘minkowski’.
n_jobs (int, default=None) – Number of parallel jobs (effective with scikit-learn only).
ensure_all_finite (bool, default=True) – Whether to raise on inf/NaN.
force_all_finite (bool | None, default=None) – Deprecated alias of
ensure_all_finite. If provided, overrides it.device ({"cpu", "cuda", "mps"} or torch.device or str, default="cpu") – Device to use for computation.
- Returns:
Distance matrix.
- Return type:
ndarray of shape (n_samples_1, n_samples_2)