class_docstr: Swin Transformer block based on: "Liu et al.,
  Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
  <https://arxiv.org/abs/2103.14030>"
  https://github.com/microsoft/Swin-Transformer
code: def forward_part1(self, x, mask_matrix):
      x_shape = x.size()
      x = self.norm1(x)
      if len(x_shape) == 5:
          b, d, h, w, c = x.shape
          window_size, shift_size = get_window_size(
              (d, h, w), self.window_size, self.shift_size
          )
          pad_l = pad_t = pad_d0 = 0
          pad_d1 = (window_size[0] - d % window_size[0]) % window_size[
              0
          ]
          pad_b = (window_size[1] - h % window_size[1]) % window_size[1]
          pad_r = (window_size[2] - w % window_size[2]) % window_size[2]
          x = F.pad(
              x, (0, 0, pad_l, pad_r, pad_t, pad_b, pad_d0, pad_d1)
          )
          _, dp, hp, wp, _ = x.shape
          dims = [b, dp, hp, wp]
  
      elif len(x_shape) == 4:
          b, h, w, c = x.shape
          window_size, shift_size = get_window_size(
              (h, w), self.window_size, self.shift_size
          )
          pad_l = pad_t = 0
          pad_b = (window_size[0] - h % window_size[0]) % window_size[0]
          pad_r = (window_size[1] - w % window_size[1]) % window_size[1]
          x = F.pad(x, (0, 0, pad_l, pad_r, pad_t, pad_b))
          _, hp, wp, _ = x.shape
          dims = [b, hp, wp]
  
      if any(i > 0 for i in shift_size):
          if len(x_shape) == 5:
              shifted_x = torch.roll(
                  x,
                  shifts=(
                      -shift_size[0],
                      -shift_size[1],
                      -shift_size[2],
                  ),
                  dims=(1, 2, 3),
              )
          elif len(x_shape) == 4:
              shifted_x = torch.roll(
                  x,
                  shifts=(-shift_size[0], -shift_size[1]),
                  dims=(1, 2),
              )
          attn_mask = mask_matrix
      else:
          shifted_x = x
          attn_mask = None
      x_windows = window_partition(shifted_x, window_size)
      attn_windows = self.attn(x_windows, mask=attn_mask)
      attn_windows = attn_windows.view(-1, *(window_size + (c,)))
      shifted_x = window_reverse(attn_windows, window_size, dims)
      if any(i > 0 for i in shift_size):
          if len(x_shape) == 5:
              x = torch.roll(
                  shifted_x,
                  shifts=(shift_size[0], shift_size[1], shift_size[2]),
                  dims=(1, 2, 3),
              )
          elif len(x_shape) == 4:
              x = torch.roll(
                  shifted_x,
                  shifts=(shift_size[0], shift_size[1]),
                  dims=(1, 2),
              )
      else:
          x = shifted_x
  
      if len(x_shape) == 5:
          if pad_d1 > 0 or pad_r > 0 or pad_b > 0:
              x = x[:, :d, :h, :w, :].contiguous()
      elif len(x_shape) == 4:
          if pad_r > 0 or pad_b > 0:
              x = x[:, :h, :w, :].contiguous()
  
      return x
  
imports: from __future__ import annotations
  import itertools
  from collections.abc import Sequence
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from torch.nn import LayerNorm
  from typing_extensions import Final
  from monai.networks.blocks import MLPBlock
  from monai.networks.blocks import PatchEmbed, UnetOutBlock, UnetrBasicBlock, UnetrUpBlock
  from monai.networks.layers import DropPath, trunc_normal_
  from monai.utils import ensure_tuple_rep, look_up_option, optional_import
  from monai.utils.deprecate_utils import deprecated_arg
label_desc: Use image node_id 2 for calling the SwinTransformerBlock obj's underlying member method code with example usage: obj.forward_part1(x, mask_matrix) and returns: x