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=2
y_mat (tensor) – torch with ndim=2
eps (
float
) – a small jitter to avoid divde by zerodevice (
str
) – the computational device for embed_model, can be either cpu or cuda.
- Return type
numpy.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=2
y_mat (tensor) – torch array with ndim=2
device (
str
) – the computational device for embed_model, can be either cpu or cuda.
- Return type
numpy.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=2
y_mat (tensor) – torch array with ndim=2
device (
str
) – the computational device for embed_model, can be either cpu or cuda.
- Return type
numpy.ndarray
- Returns
np.ndarray with ndim=2