chebyshev_distance¶
- chebyshev_distance(points_a, points_b)[source]¶
Compute pairwise Chebyshev (L∞) distances between two point sets.
Overview¶
chebyshev_distance(points_a, points_b) computes the full pairwise Chebyshev (L∞) distance
matrix between two 2D numeric arrays of shapes (N, D) and (M, D), returning an (N, M)
float64 matrix. The Chebyshev distance between vectors x and y is:
It measures the maximum absolute coordinate difference and is useful when the largest deviation across dimensions dominates similarity (e.g., certain quality thresholds or grid-based neighborhood analyses).
Shape Requirements¶
points_a.ndim == 2points_b.ndim == 2Feature dimension matches:
points_a.shape[1] == points_b.shape[1]
Parameters (see signature above)¶
points_a: NumPy array(N, D)(any numeric dtype; coerced to float64)points_b: NumPy array(M, D)(same feature dimension aspoints_a)
Returns¶
numpy.ndarray of shape (N, M) with out[i, j] = max(abs(points_a[i, k] - points_b[j, k])).
Numerical & Dtype Notes¶
All inputs are coerced to
float64internally for uniform arithmetic.No special epsilon handling is required (pure absolute differences).
Extremely large values propagate normally; consider prior clipping if needed.
Performance¶
Implemented in Rust; releases the Python GIL.
Outer loops may parallelize for large
N * Mworkloads.Memory usage is
O(N*M)for the output; for very large matrices consider blockwise strategies (not implemented here).
Examples¶
Basic usage:
import numpy as np
from eo_processor import chebyshev_distance
A = np.array([[0.0, 1.0],
[2.0, 3.5]], dtype=np.float32) # (2, 2)
B = np.array([[1.0, 2.0],
[0.0, -1.0],
[2.0, 3.0]], dtype=np.float64) # (3, 2)
dist = chebyshev_distance(A, B)
# dist[0, 0] = max(|0-1|, |1-2|) = 1
# dist[1, 2] = max(|2-2|, |3.5-3|) = 0.5
print(dist.shape) # (2, 3)
Edge Case (single feature dimension):
A = np.array([[0.0], [5.0]])
B = np.array([[2.5], [10.0]])
d = chebyshev_distance(A, B) # Equivalent to absolute difference
Error Handling¶
Raises ValueError if:
- Inputs are not 2D
- Feature dimensions differ
Raises TypeError if inputs are non-numeric.
Use Cases¶
Fast max-difference screening
Grid / tile similarity where worst-case deviation matters
Alternative to L2/L1 norms for bounding box or threshold checks
See Also¶
euclidean_distance()(L2 norm)manhattan_distance()(L1 norm)minkowski_distance()(general L^p; Chebyshev as p→∞)normalized_difference()(unrelated ratio primitive)
End of chebyshev_distance documentation.