class_docstr: Module for alignment text and mel spectrogram.
  
  Args:
      n_mel_channels: Dimension of mel spectrogram.
      n_text_channels: Dimension of text embeddings.
      n_att_channels: Dimension of model
      temperature: Temperature to scale distance by.
          Suggested to be 0.0005 when using dist_type "l2" and 15.0 when using "cosine".
      condition_types: List of types for nemo.collections.tts.modules.submodules.ConditionalInput.
      dist_type: Distance type to use for similarity measurement. Supports "l2" and "cosine" distance.
class_docstr_tok: ["Module","for","alignment","text","and","mel","spectrogram",".","Args",":","n_mel_channels",":","Dimension","of","mel","spectrogram",".","n_text_channels",":","Dimension","of","text","embeddings",".","n_att_channels",":","Dimension","of","model","temperature",":","Temperature","to","scale","distance","by",".","Suggested","to","be","0.0005","when","using","dist_type","``","l2","''","and","15.0","when","using","``","cosine","''",".","condition_types",":","List","of","types","for","nemo.collections.tts.modules.submodules.ConditionalInput",".","dist_type",":","Distance","type","to","use","for","similarity","measurement",".","Supports","``","l2","''","and","``","cosine","''","distance","."]
docstr: Select elements from the distance matrix for the given durations and mask and return mean distance.
  
  Args:
      dist (torch.tensor): B x T1 x T2 tensor.
      durations (torch.tensor): B x T2 tensor. Dim T2 should sum to T1.
      mask (torch.tensor): B x T2 x 1 binary mask for variable length entries and also can be used
          for ignoring unnecessary elements in dist by T2 dim (True = mask element, False = leave unchanged).
  Output:
      mean_dist (torch.tensor): B x 1 tensor.
docstr_tok: ["Select","elements","from","the","distance","matrix","for","the","given","durations","and","mask","and","return","mean","distance",".","Args",":","dist","(","torch.tensor",")",":","B","x","T1","x","T2","tensor",".","durations","(","torch.tensor",")",":","B","x","T2","tensor",".","Dim","T2","should","sum","to","T1",".","mask","(","torch.tensor",")",":","B","x","T2","x","1","binary","mask","for","variable","length","entries","and","also","can","be","used","for","ignoring","unnecessary","elements","in","dist","by","T2","dim","(","True","=","mask","element",",","False","=","leave","unchanged",")",".","Output",":","mean_dist","(","torch.tensor",")",":","B","x","1","tensor","."]
code: def get_mean_dist_by_durations(dist, durations, mask=None):
      """Select elements from the distance matrix for the given durations and mask and return mean distance.
  
      Args:
          dist (torch.tensor): B x T1 x T2 tensor.
          durations (torch.tensor): B x T2 tensor. Dim T2 should sum to T1.
          mask (torch.tensor): B x T2 x 1 binary mask for variable length entries and also can be used
              for ignoring unnecessary elements in dist by T2 dim (True = mask element, False = leave unchanged).
      Output:
          mean_dist (torch.tensor): B x 1 tensor.
      """
      batch_size, t1_size, t2_size = dist.size()
      assert torch.all(torch.eq(durations.sum(dim=1), t1_size))
  
      AlignmentEncoder._apply_mask(dist, mask, 0)
  
      # TODO(oktai15): make it more efficient
      mean_dist_by_durations = []
      for dist_idx in range(batch_size):
          mean_dist_by_durations.append(
              torch.mean(
                  dist[
                      dist_idx,
                      torch.arange(t1_size),
                      torch.repeat_interleave(
                          torch.arange(t2_size),
                          repeats=durations[dist_idx],
                      ),
                  ]
              )
          )
  
      return torch.tensor(
          mean_dist_by_durations, dtype=dist.dtype, device=dist.device
      )
  
file_path: NeMo/nemo/collections/tts/modules/aligner.py
imports: import torch
  from einops import rearrange
  from torch import nn
  from nemo.collections.tts.modules.submodules import ConditionalInput, ConvNorm
  from nemo.collections.tts.parts.utils.helpers import binarize_attention_parallel
label_desc: Use image node_id 7 for calling the AlignmentEncoder obj's underlying member method code with example usage: obj.get_mean_dist_by_durations(dist, durations, mask) and returns: torch