code: def match_batch_shape(X: Tensor, Y: Tensor) -> Tensor:
      r"""Matches the batch dimension of a tensor to that of another tensor.
  
      Args:
          X: A `batch_shape_X x q x d` tensor, whose batch dimensions that
              correspond to batch dimensions of `Y` are to be matched to those
              (if compatible).
          Y: A `batch_shape_Y x q' x d` tensor.
  
      Returns:
          A `batch_shape_Y x q x d` tensor containing the data of `X` expanded to
          the batch dimensions of `Y` (if compatible). For instance, if `X` is
          `b'' x b' x q x d` and `Y` is `b x q x d`, then the returned tensor is
          `b'' x b x q x d`.
  
      Example:
          >>> X = torch.rand(2, 1, 5, 3)
          >>> Y = torch.rand(2, 6, 4, 3)
          >>> X_matched = match_batch_shape(X, Y)
          >>> X_matched.shape
          torch.Size([2, 6, 5, 3])
  
      """
      return X.expand(
          X.shape[: -(Y.dim())] + Y.shape[:-2] + X.shape[-2:]
      )
  
file_path: botorch/botorch/utils/transforms.py
imports: from __future__ import annotations
  import warnings
  from functools import wraps
  from typing import Any, Callable, List, Optional, TYPE_CHECKING
  import torch
  from botorch.utils.safe_math import logmeanexp
  from torch import Tensor
label_desc: Use image node_id 10 for calling a global function with example usage: match_batch_shape(X, Y) and returns: X