code: def average_features(pitch, durs):
      durs_cums_ends = torch.cumsum(durs, dim=1).long()
      durs_cums_starts = torch.nn.functional.pad(
          durs_cums_ends[:, :-1], (1, 0)
      )
      pitch_nonzero_cums = torch.nn.functional.pad(
          torch.cumsum(pitch != 0.0, dim=2), (1, 0)
      )
      pitch_cums = torch.nn.functional.pad(
          torch.cumsum(pitch, dim=2), (1, 0)
      )
  
      bs, l = durs_cums_ends.size()
      n_formants = pitch.size(1)
      dcs = durs_cums_starts[:, None, :].expand(bs, n_formants, l)
      dce = durs_cums_ends[:, None, :].expand(bs, n_formants, l)
  
      pitch_sums = (
          torch.gather(pitch_cums, 2, dce)
          - torch.gather(pitch_cums, 2, dcs)
      ).float()
      pitch_nelems = (
          torch.gather(pitch_nonzero_cums, 2, dce)
          - torch.gather(pitch_nonzero_cums, 2, dcs)
      ).float()
  
      pitch_avg = torch.where(
          pitch_nelems == 0.0, pitch_nelems, pitch_sums / pitch_nelems
      )
      return pitch_avg
  
imports: import torch
  from nemo.collections.tts.modules.submodules import ConditionalInput, ConditionalLayerNorm
  from nemo.collections.tts.parts.utils.helpers import binarize_attention_parallel, regulate_len
  from nemo.core.classes import NeuralModule, adapter_mixins, typecheck
  from nemo.core.neural_types.elements import EncodedRepresentation, Index, LengthsType, LogprobsType, MelSpectrogramType, ProbsType, RegressionValuesType, TokenDurationType, TokenIndex, TokenLogDurationType
  from nemo.core.neural_types.neural_type import NeuralType
label_desc: Use image node_id 1 for calling a global function with example usage: average_features(pitch, durs) and returns: pitch_avg