code: def mask_feature(
      x: Tensor,
      p: float = 0.5,
      mode: str = "col",
      fill_value: float = 0.0,
      training: bool = True,
  ) -> Tuple[Tensor, Tensor]:
      r"""Randomly masks feature from the feature matrix
      :obj:`x` with probability :obj:`p` using samples from
      a Bernoulli distribution.
  
      The method returns (1) the retained :obj:`x`, (2) the feature
      mask broadcastable with :obj:`x` (:obj:`mode='row'` and :obj:`mode='col'`)
      or with the same shape as :obj:`x` (:obj:`mode='all'`),
      indicating where features are retained.
  
      Args:
          x (FloatTensor): The feature matrix.
          p (float, optional): The masking ratio. (default: :obj:`0.5`)
          mode (str, optional): The masked scheme to use for feature masking.
              (:obj:`"row"`, :obj:`"col"` or :obj:`"all"`).
              If :obj:`mode='col'`, will mask entire features of all nodes
              from the feature matrix. If :obj:`mode='row'`, will mask entire
              nodes from the feature matrix. If :obj:`mode='all'`, will mask
              individual features across all nodes. (default: :obj:`'col'`)
          fill_value (float, optional): The value for masked features in the
              output tensor. (default: :obj:`0`)
          training (bool, optional): If set to :obj:`False`, this operation is a
              no-op. (default: :obj:`True`)
  
      :rtype: (:class:`FloatTensor`, :class:`BoolTensor`)
  
      Examples:
          >>> # Masked features are column-wise sampled
          >>> x = torch.tensor([[1, 2, 3],
          ...                   [4, 5, 6],
          ...                   [7, 8, 9]], dtype=torch.float)
          >>> x, feat_mask = mask_feature(x)
          >>> x
          tensor([[1., 0., 3.],
                  [4., 0., 6.],
                  [7., 0., 9.]]),
          >>> feat_mask
          tensor([[True, False, True]])
  
          >>> # Masked features are row-wise sampled
          >>> x, feat_mask = mask_feature(x, mode='row')
          >>> x
          tensor([[1., 2., 3.],
                  [0., 0., 0.],
                  [7., 8., 9.]]),
          >>> feat_mask
          tensor([[True], [False], [True]])
  
          >>> # Masked features are uniformly sampled
          >>> x, feat_mask = mask_feature(x, mode='all')
          >>> x
          tensor([[0., 0., 0.],
                  [4., 0., 6.],
                  [0., 0., 9.]])
          >>> feat_mask
          tensor([[False, False, False],
                  [True, False,  True],
                  [False, False,  True]])
      """
      if p < 0.0 or p > 1.0:
          raise ValueError(
              f"Masking ratio has to be between 0 and 1 " f"(got {p}"
          )
      if not training or p == 0.0:
          return x, torch.ones_like(x, dtype=torch.bool)
      assert mode in ["row", "col", "all"]
  
      if mode == "row":
          mask = torch.rand(x.size(0), device=x.device) >= p
          mask = mask.view(-1, 1)
      elif mode == "col":
          mask = torch.rand(x.size(1), device=x.device) >= p
          mask = mask.view(1, -1)
      else:
          mask = torch.rand_like(x) >= p
  
      x = x.masked_fill(~mask, fill_value)
      return x, mask
  
imports: from typing import Optional, Tuple, Union
  import torch
  from torch import Tensor
  from torch_geometric.utils import cumsum, negative_sampling, scatter
label_desc: Use image node_id 2 for calling a global function with example usage: mask_feature(x, p, mode, fill_value, training) and returns: x,  mask, x,  torch