Project: s41467-025-58854-8 | Function: _euclidean_distances (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Calculates Euclidean distances between query features and class prototypes in prototypical networks. Expands tensors for broadcasting, computes squared differences, sums over feature dimensions, and returns negative distances as logits.

**KEY TERMS:** {
  "distances": "Euclidean distance",
  "query_features": "query set embeddings",
  "class_prototypes": "prototypes"
}

**CONTEXT CODE:**         else:
            examples = examples - torch.mean(examples, dim=1, keepdim=True)
        examples_t = examples.t()
        return factor * examples.matmul(examples_t).squeeze()

    @staticmethod
    def _extract_class_indices(labels: torch.Tensor, which_class: torch.Tensor) -> torch.Tensor:
        class_mask = torch.eq(labels, which_class)  # binary mask of labels equal to which_class
        class_mask_indices = torch.nonzero(class_mask)  # indices of labels equal to which class
        return torch.reshape(class_mask_indices, (-1,))  # reshape to be a 1D vector

    @staticmethod
    def compute_loss(logits: torch.Tensor, labels: torch.Tensor) -> torch.Tensor:
        return nn.functional.cross_entropy(logits, labels.long())

    def _protonets_euclidean_classifier(
        self,
        support_features: torch.Tensor,
        query_features: torch.Tensor,
        support_labels: torch.Tensor,
    ) -> torch.Tensor:
        class_prototypes = self._compute_class_prototypes(support_features, support_labels)
        logits = self._euclidean_distances(query_features, class_prototypes)
        return logits

    def _compute_class_prototypes(
        self, support_features: torch.Tensor, support_labels: torch.Tensor
    ) -> torch.Tensor:
        """
        Computes class prototypes as mean vectors of support set embeddings for each class in prototypical networks meta-learning.

        This function implements the core prototype computation algorithm described in the paper for prototypical
        networks. It takes support features and labels, filters features by class, and returns stacked mean vectors
        that serve as class prototypes for distance-based classification.

        Args:
            support_features: Tensor of support set feature embeddings with shape (num_support, feature_dim)
            support_labels: Tensor of support set labels with shape (num_support,)

        Returns:
            torch.Tensor: Stacked tensor of class prototypes with shape (num_classes, feature_dim)

        Paper reference: "Given these embeddings, a prototype is computed first as the mean vector of the support set embeddings for each class"

        Formula: prototype_c = mean(support_features[support_labels == c])
        Implementation: Class filtering, mean pooling, and tensor stacking for meta-learning classification
        """
        # MASKED: Core prototype computation for prototypical networks meta-learning
        raise NotImplementedError("This function is masked for testing purposes. The function computes class prototypes as mean vectors of support set embeddings for each class in prototypical networks meta-learning, implementing the core algorithm described in the paper.")

    def _euclidean_distances(
        self, query_features: torch.Tensor, class_prototypes: torch.Tensor
    ) -> torch.Tensor:
        """
        Calculates Euclidean distances between query features and class prototypes in prototypical networks.

        This function implements the distance computation component of prototypical networks for meta-learning.
        It expands tensors for broadcasting, computes squared differences, sums over feature dimensions, and
        returns negative distances as logits for classification in few-shot learning scenarios.

        Args:
            query_features: Tensor of query set feature embeddings with shape (num_query, feature_dim)
            class_prototypes: Tensor of class prototypes with shape (num_classes, feature_dim)

        Returns:
            torch.Tensor: Negative Euclidean distances as logits with shape (num_query, num_classes)

        Paper reference: "The query set embeddings are then classified by calculating their distance with each prototype. The Euclidean distance is usually a popular choice for the distance metric."

        Formula: distances = (query_features - class_prototypes)^2, summed over dimensions
        Implementation: Tensor broadcasting, squared differences computation, and distance-based classification
        """
        # MASKED: Euclidean distance computation for prototypical networks classification
        raise NotImplementedError("This function is masked for testing purposes. The function calculates Euclidean distances between query features and class prototypes in prototypical networks, implementing distance-based classification for meta-learning.")

Complete the function implementation replacing "raise NotImplementedError".