class_docstr: Residual affine coupling layer.
docstr: Calculate forward propagation.
  
  Args:
      x (Tensor): Input tensor (B, in_channels, T).
      x_lengths (Tensor): Length tensor (B,).
      g (Optional[Tensor]): Global conditioning tensor (B, global_channels, 1).
      inverse (bool): Whether to inverse the flow.
  
  Returns:
      Tensor: Output tensor (B, in_channels, T).
      Tensor: Log-determinant tensor for NLL (B,) if not inverse.
code: def forward(
      self,
      x: torch.Tensor,
      x_mask: torch.Tensor,
      g: Optional[torch.Tensor] = None,
      inverse: bool = False,
  ) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
      """Calculate forward propagation.
  
      Args:
          x (Tensor): Input tensor (B, in_channels, T).
          x_lengths (Tensor): Length tensor (B,).
          g (Optional[Tensor]): Global conditioning tensor (B, global_channels, 1).
          inverse (bool): Whether to inverse the flow.
  
      Returns:
          Tensor: Output tensor (B, in_channels, T).
          Tensor: Log-determinant tensor for NLL (B,) if not inverse.
  
      """
      xa, xb = x.split(x.size(1) // 2, dim=1)
      h = self.input_conv(xa) * x_mask
      h = self.encoder(h, x_mask, g=g)
      stats = self.proj(h) * x_mask
      if not self.use_only_mean:
          m, logs = stats.split(stats.size(1) // 2, dim=1)
      else:
          m = stats
          logs = torch.zeros_like(m)
  
      if not inverse:
          xb = m + xb * torch.exp(logs) * x_mask
          x = torch.cat([xa, xb], 1)
          logdet = torch.sum(logs, [1, 2])
          return x, logdet
      else:
          xb = (xb - m) * torch.exp(-logs) * x_mask
          x = torch.cat([xa, xb], 1)
          return x
  
file_path: espnet/espnet2/gan_tts/vits/residual_coupling.py
imports: from typing import Optional, Tuple, Union
  import torch
  from espnet2.gan_tts.vits.flow import FlipFlow
  from espnet2.gan_tts.wavenet import WaveNet
label_desc: Use image node_id 2 for calling the ResidualAffineCouplingLayer obj's underlying member method code with example usage: obj.forward(x, x_mask, g, inverse) and returns: x,  logdet, x