docarray.math.distance.torch module#
- docarray.math.distance.torch.cosine(x_mat, y_mat, eps=1e-07, device='cpu')[source]#
Cosine distance between each row in x_mat and each row in y_mat.
- Parameters:
x_mat (
tensor
) – torch with ndim=2y_mat (
tensor
) – torch with ndim=2eps (
float
) – a small jitter to avoid divde by zerodevice (
str
) – the computational device for embed_model, can be either cpu or cuda.
- Return type:
ndarray
- Returns:
np.ndarray with ndim=2
- docarray.math.distance.torch.euclidean(x_mat, y_mat, device='cpu')[source]#
Euclidean distance between each row in x_mat and each row in y_mat.
- Parameters:
x_mat (
tensor
) – torch array with ndim=2y_mat (
tensor
) – torch array with ndim=2device (
str
) – the computational device for embed_model, can be either cpu or cuda.
- Return type:
ndarray
- Returns:
np.ndarray with ndim=2
- docarray.math.distance.torch.sqeuclidean(x_mat, y_mat, device='cpu')[source]#
Squared euclidean distance between each row in x_mat and each row in y_mat.
- Parameters:
x_mat (
tensor
) – torch array with ndim=2y_mat (
tensor
) – torch array with ndim=2device (
str
) – the computational device for embed_model, can be either cpu or cuda.
- Return type:
ndarray
- Returns:
np.ndarray with ndim=2