Computes the pairwise distance matrix between rows of X and Y.
The dominant cost (row inner-products via am_tcrossprod) is dispatched to the
active GPU backend (ArrayFire or MLX); norm computation and final transforms
run on CPU where they are O(mp + np) — negligible versus the O(mnp) GEMM.
Usage
dist_matrix(
X,
Y = NULL,
method = c("euclidean", "sqeuclidean", "cosine"),
tile_size = NULL
)Arguments
- X
Numeric matrix or
adgeMatrix, shape [m, p].- Y
Numeric matrix or
adgeMatrix, shape [n, p], orNULLto compute pairwise distances withinX(returns [m, m] matrix).- method
One of
"euclidean"(default),"sqeuclidean", or"cosine".- tile_size
Integer row-block size for tiled computation, or
NULL(default) to auto-tile whennrow(X) > 50000(self-distance only). Set explicitly to process any size in row-blocks; useful when GPU memory is limited. Not supported formethod = "cosine".