code: def temporal_mean(
      input: torch.Tensor,
      input_length: Optional[torch.Tensor] = None,
      mask: Optional[torch.Tensor] = None,
      keepdim: bool = False,
      eps: float = 1e-10,
  ) -> torch.Tensor:
      """Calculate mean along temporal dimension with optionally
      averaging only over valid samples (based on the input length).
  
      Args:
          input: Batch of signals, shape (B, C, T)
          input_length: Optional, length of each example in the batch, shape (B,)
          mask: Optional, temporal mask for each example in the batch, shape (B, T)
          keepdim: Whether to keep the temporal dimension
          eps: Regularization to avoid division by zero
  
      Returns:
          (B, C, 1) if keepdim=True, otherwise (B, C)
      """
      if input_length is not None:
          if mask is not None:
              raise RuntimeError(
                  "Argument `input_length` is mutually exclusive with `mask`. Both cannot be used at the same time."
              )
          # Construct a binary mask
          mask = make_seq_mask_like(
              lengths=input_length,
              like=input,
              time_dim=-1,
              valid_ones=True,
          ).squeeze(1)
  
      if mask is None:
          # No length information, assume all samples are valid
          mean = torch.mean(input, dim=-1, keepdim=keepdim)
      else:
          # Average using temporal mask
          mean = mask.unsqueeze(1) * input
          mean = torch.sum(mean, axis=-1, keepdim=keepdim)
          normalization = torch.sum(mask, axis=-1, keepdim=keepdim)
          mean = mean / (normalization.unsqueeze(1) + eps)
  
      return mean
  
file_path: NeMo/nemo/collections/asr/losses/audio_losses.py
imports: import math
  from typing import List, Optional
  import numpy
  import torch
  from nemo.collections.asr.parts.preprocessing.features import make_seq_mask_like
  from nemo.collections.asr.parts.utils.audio_utils import toeplitz
  from nemo.core.classes import Loss, Typing, typecheck
  from nemo.core.neural_types import AudioSignal, LengthsType, LossType, MaskType, NeuralType
  from nemo.utils import logging
label_desc: Use image node_id 1 for calling a global function with example usage: temporal_mean(input, input_length, mask, keepdim, eps) and returns: mean