Project: s41467-025-58854-8 | Function: _compute_class_prototypes (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:** Computes class prototypes as mean vectors of support set embeddings for each class in prototypical networks meta-learning. Takes support features and labels, filters features by class, and returns stacked mean vectors.

**KEY TERMS:** {
  "class_features": "support set embeddings",
  "means": "class prototypes",
  "torch.mean": "mean pooling examples"
}

**CONTEXT CODE:**         If we examine N-dimensional samples, `X = [x_1, x_2, ... x_N]^T`,
        then the covariance matrix element `C_{ij}` is the covariance of
        `x_i` and `x_j`. The element `C_{ii}` is the variance of `x_i`.

        Args:
            examples: A 1-D or 2-D array containing multiple variables and observations.
                Each row of `m` represents a variable, and each column a single
                observation of all those variables.
            rowvar: If `rowvar` is True, then each row represents a
                variable, with observations in the columns. Otherwise, the
                relationship is transposed: each column represents a variable,
                while the rows contain observations.

        Returns:
            The covariance matrix of the variables.
        """
        if examples.dim() > 2:
            raise ValueError("m has more than 2 dimensions")
        if examples.dim() < 2:
            examples = examples.view(1, -1)
        if not rowvar and examples.size(0) != 1:
            examples = examples.t()
        factor = 1.0 / (examples.size(1) - 1)
        if inplace:
            examples -= torch.mean(examples, dim=1, keepdim=True)
        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".