code: def downsample(x, stride=1, expand=1, transposed=False):
      if x is None:
          return None
      if stride > 1:
          assert x.ndim == 3, (
              "Downsampling with higher-dimensional inputs is currently not supported."
              "It is recommended to use average or spectral pooling instead."
          )
          if transposed:
              x = x[..., 0::stride]
          else:
              x = x[..., 0::stride, :]
  
      if expand > 1:
          if transposed:
              x = repeat(x, "b d ... -> b (d e) ...", e=expand)
          else:
              x = repeat(x, "b ... d -> b ... (d e)", e=expand)
  
      return x
  
imports: import torch
  import torch.nn.functional
  from einops import rearrange, reduce, repeat
  from torch import nn
  from espnet2.asr.state_spaces.base import SequenceModule
  from espnet2.asr.state_spaces.components import LinearActivation
label_desc: Use image node_id 1 for calling a global function with example usage: downsample(x, stride, expand, transposed) and returns: x, None