code: def _average_by_duration(
      self, x: torch.Tensor, d: torch.Tensor
  ) -> torch.Tensor:
      assert 0 <= len(x) - d.sum() < self.reduction_factor
      d_cumsum = F.pad(d.cumsum(dim=0), (1, 0))
      x_avg = [
          x[start:end].masked_select(x[start:end].gt(0.0)).mean(dim=0)
          if len(x[start:end].masked_select(x[start:end].gt(0.0))) != 0
          else x.new_tensor(0.0)
          for start, end in zip(d_cumsum[:-1], d_cumsum[1:])
      ]
      return torch.stack(x_avg)
  
file_path: espnet/espnet2/tts/feats_extract/ying.py
imports: import math
  from typing import Any, Dict, Tuple, Union
  import torch
  from espnet2.tts.feats_extract.abs_feats_extract import AbsFeatsExtract
  from espnet2.tts.feats_extract.yin import *
  from espnet.nets.pytorch_backend.nets_utils import pad_list
label_desc: Use image node_id 7 for calling the Ying obj's underlying member method code with example usage: obj._average_by_duration(x, d) and returns: torch