class_docstr: F0 estimation with dio + stonemask algorithm.
  
  This is f0 extractor based on dio + stonmask algorithm introduced in `WORLD:
  a vocoder-based high-quality speech synthesis system for real-time applications`_.
  
  .. _`WORLD: a vocoder-based high-quality speech synthesis system for real-time
      applications`: https://doi.org/10.1587/transinf.2015EDP7457
  
  Note:
      This module is based on NumPy implementation. Therefore, the computational graph
      is not connected.
  
  Todo:
      Replace this module with PyTorch-based implementation.
class_docstr_tok: ["F0","estimation","with","dio","+","stonemask","algorithm",".","This","is","f0","extractor","based","on","dio","+","stonmask","algorithm","introduced","in","`","WORLD",":","a","vocoder-based","high-quality","speech","synthesis","system","for","real-time","applications","`","_",".","..","_","`","WORLD",":","a","vocoder-based","high-quality","speech","synthesis","system","for","real-time","applications","`",":","https",":","\/\/doi.org\/10.1587\/transinf.2015EDP7457","Note",":","This","module","is","based","on","NumPy","implementation",".","Therefore",",","the","computational","graph","is","not","connected",".","Todo",":","Replace","this","module","with","PyTorch-based","implementation","."]
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)
  
imports: import logging
  from typing import Any, Dict, Tuple, Union
  import humanfriendly
  import numpy
  import pyworld
  import torch
  import torch.nn.functional
  from scipy.interpolate import interp1d
  from typeguard import check_argument_types
  from espnet2.tts.feats_extract.abs_feats_extract import AbsFeatsExtract
  from espnet.nets.pytorch_backend.nets_utils import pad_list
label_desc: Use image node_id 8 for calling the Dio obj's underlying member method code with example usage: obj._average_by_duration(x, d) and returns: torch