code: def scale_invariant_target(
      estimate: torch.Tensor,
      target: torch.Tensor,
      input_length: Optional[torch.Tensor] = None,
      mask: Optional[torch.Tensor] = None,
      eps: float = 1e-10,
  ) -> torch.Tensor:
      """Calculate optimal scale-invariant target.
      Assumes time dimension is the last dimension in the array.
  
      Calculate scaled target obtained by solving
  
          min_scale || scale * target - estimate ||^2
  
      for each example in batch and each channel (b, c).
  
      Args:
          estimate: tensor, shape (B, C, T)
          target: tensor, shape (B, C, T)
          input_length: optional, length of valid samples, shape (B,)
          mask: optional, mask for input samples, shape (B, T)
          eps: regularization constant
  
      Returns:
          Scaled target, shape (B, C, T)
      """
      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=estimate,
              time_dim=-1,
              valid_ones=True,
          ).squeeze(1)
  
      estimate_dot_target = temporal_mean(
          estimate * target, mask=mask, keepdim=True, eps=eps
      )
      target_pow = temporal_mean(
          torch.abs(target) ** 2, mask=mask, keepdim=True, eps=eps
      )
      scale = estimate_dot_target / (target_pow + eps)
      target_scaled = scale * target
  
      # Mask to keep only the valid samples
      if mask is not None:
          target_scaled = mask.unsqueeze(1) * target_scaled
  
      return target_scaled
  
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 2 for calling a global function with example usage: scale_invariant_target(estimate, target, input_length, mask, eps) and returns: target_scaled