def euclidean_dist(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
        """Compute pairwise Euclidean distances between two sets of vectors.

        Implements an efficient matrix computation of Euclidean distances between
        all pairs of vectors in ``x`` and ``y`` without using ``torch.cdist()``.

        Args:
            x (torch.Tensor): First tensor of shape ``(n, d)``.
            y (torch.Tensor): Second tensor of shape ``(m, d)``.

        Returns:
            torch.Tensor: Distance matrix of shape ``(n, m)`` where element
                ``(i,j)`` is the distance between row ``i`` of ``x`` and row
                ``j`` of ``y``.

        Example:
            >>> x = torch.randn(100, 512)
            >>> y = torch.randn(50, 512)
            >>> distances = PatchcoreModel.euclidean_dist(x, y)
            >>> distances.shape
            torch.Size([100, 50])

        Note:
            This implementation avoids using ``torch.cdist()`` for better
            compatibility with ONNX export and OpenVINO conversion.
        """
        x_norm = x.pow(2).sum(dim=-1, keepdim=True)  # |x|
        y_norm = y.pow(2).sum(dim=-1, keepdim=True)  # |y|
        # row distance can be rewritten as sqrt(|x| - 2 * x @ y.T + |y|.T)
        res = x_norm - 2 * torch.matmul(x, y.transpose(-2, -1)) + y_norm.transpose(-2, -1)
        return res.clamp_min_(0).sqrt_()
Compute pairwise Euclidean distances between two sets of vectors.

        Implements an efficient matrix computation of Euclidean distances between
        all pairs of vectors in ``x`` and ``y`` without using ``torch.cdist()``.

        Args:
            x (torch.Tensor): First tensor of shape ``(n, d)``.
            y (torch.Tensor): Second tensor of shape ``(m, d)``.

        Returns:
            torch.Tensor: Distance matrix of shape ``(n, m)`` where element
                ``(i,j)`` is the distance between row ``i`` of ``x`` and row
                ``j`` of ``y``.

        Example:
            >>> x = torch.randn(100, 512)
            >>> y = torch.randn(50, 512)
            >>> distances = PatchcoreModel.euclidean_dist(x, y)
            >>> distances.shape
            torch.Size([100, 50])

        Note:
            This implementation avoids using ``torch.cdist()`` for better
            compatibility with ONNX export and OpenVINO conversion.
        
src/anomalib/models/image/patchcore/torch_model.py