class_docstr: Applies temporal pooling operations on masked inputs. For each pooling operation
  all masked values are ignored.
class_docstr_tok: ["Applies","temporal","pooling","operations","on","masked","inputs",".","For","each","pooling","operation","all","masked","values","are","ignored","."]
docstr: Args:
      x (torch.Tensor): tensor with shape (batch_size, seq_len, feature_dim)
      mask (torch.Tensor): bool tensor with shape (batch_size, seq_len).
          Sequence elements that are False are invalid.
  
  Returns:
      Tensor with shape (batch_size, feature_dim)
docstr_tok: ["Args",":","x","(","torch.Tensor",")",":","tensor","with","shape","(","batch_size",",","seq_len",",","feature_dim",")","mask","(","torch.Tensor",")",":","bool","tensor","with","shape","(","batch_size",",","seq_len",")",".","Sequence","elements","that","are","False","are","invalid",".","Returns",":","Tensor","with","shape","(","batch_size",",","feature_dim",")"]
code: def forward(
      self, x: torch.Tensor, mask: Optional[torch.Tensor] = None
  ) -> torch.Tensor:
      """
      Args:
          x (torch.Tensor): tensor with shape (batch_size, seq_len, feature_dim)
          mask (torch.Tensor): bool tensor with shape (batch_size, seq_len).
              Sequence elements that are False are invalid.
  
      Returns:
          Tensor with shape (batch_size, feature_dim)
      """
      assert (
          x.dim() == 3
      ), "Requires x shape (batch_size x seq_len x feature_dim)"
      b, t = x.shape[0], x.shape[1]
      if mask is None:
          mask = torch.ones((b, t), dtype=torch.bool)
  
      if self._method == "max":
          x[~mask, :] = float("-inf")
  
          # Invalid batch rows are set to 0.
          invalid_first_dim = ~mask.view(b, -1).any(dim=-1)
          x[invalid_first_dim, :] = 0
  
          x = torch.max(x, dim=1)[0]
      elif self._method == "avg":
          x = x * mask.unsqueeze(-1).float()
          mask = mask.view(b, t, -1).any(dim=-1)
          valid_lengths = mask.float().sum(dim=-1).int()
          x = x.sum(dim=1)
          x = x.div(
              valid_lengths.clamp(min=1)
              .unsqueeze(-1)
              .expand(x.size())
              .float()
          )
      elif self._method == "sum":  # sum
          x = x * mask.unsqueeze(-1).float()
          x = x.sum(dim=1)
      else:
          raise NotImplementedError(
              f"{self._method} not available options are: 'max', 'avg', 'sum'"
          )
  
      return x
  
imports: from typing import List, Optional, Tuple
  import torch
  from pytorchvideo.layers.utils import set_attributes
  from torch import nn
  from torch.nn.utils.rnn import pack_padded_sequence
label_desc: Use image node_id 2 for calling the MaskedTemporalPooling obj's underlying member method code with example usage: obj.forward(x, mask) and returns: x