code: def _gen_mask(lengths_x, lengths_y, max_len_x, max_len_y):
      """Generate binary mask array for given x and y input pairs.
  
      Parameters
      ----------
      lengths_x : Tensor
          The int tensor indicates the segment information of x.
      lengths_y : Tensor
          The int tensor indicates the segment information of y.
      max_len_x : int
          The maximum element in lengths_x.
      max_len_y : int
          The maximum element in lengths_y.
  
      Returns
      -------
      Tensor
          the mask tensor with shape (batch_size, 1, max_len_x, max_len_y)
      """
      device = lengths_x.device
      # x_mask: (batch_size, max_len_x)
      x_mask = th.arange(max_len_x, device=device).unsqueeze(
          0
      ) < lengths_x.unsqueeze(1)
      # y_mask: (batch_size, max_len_y)
      y_mask = th.arange(max_len_y, device=device).unsqueeze(
          0
      ) < lengths_y.unsqueeze(1)
      # mask: (batch_size, 1, max_len_x, max_len_y)
      mask = (x_mask.unsqueeze(-1) & y_mask.unsqueeze(-2)).unsqueeze(1)
      return mask
  
imports: import numpy
  import torch
  import torch.nn
  from ...backend import pytorch
  from ...base import dgl_warning
  from ...readout import broadcast_nodes, max_nodes, mean_nodes, softmax_nodes, sum_nodes, topk_nodes
label_desc: Use image node_id 1 for calling a global function with example usage: _gen_mask(lengths_x, lengths_y, max_len_x, max_len_y) and returns: mask