class_docstr: A downsampling layer with an optional convolution.
  
  Arguments
  ---------
  channels: int
      channels in the inputs and outputs.
  use_conv: bool
       a bool determining if a convolution is applied.
  dims: int
      determines if the signal is 1D, 2D, or 3D. If 3D, then
      downsampling occurs in the inner-two dimensions.
  
  Example
  -------
  >>> ups = Downsample(channels=4, use_conv=True, dims=2, out_channels=8)
  >>> x = torch.randn(8, 4, 32, 32)
  >>> x_up = ups(x)
  >>> x_up.shape
  torch.Size([8, 8, 16, 16])
class_docstr_tok: ["A","downsampling","layer","with","an","optional","convolution",".","Arguments","--","--","--","--","-","channels",":","int","channels","in","the","inputs","and","outputs",".","use_conv",":","bool","a","bool","determining","if","a","convolution","is","applied",".","dims",":","int","determines","if","the","signal","is","1D",",","2D",",","or","3D",".","If","3D",",","then","downsampling","occurs","in","the","inner-two","dimensions",".","Example","--","--","--","-",">",">",">","ups","=","Downsample","(","channels=4",",","use_conv=True",",","dims=2",",","out_channels=8",")",">",">",">","x","=","torch.randn","(","8",",","4",",","32",",","32",")",">",">",">","x_up","=","ups","(","x",")",">",">",">","x_up.shape","torch.Size","(","[","8",",","8",",","16",",","16","]",")"]
code: def __init__(self, channels, use_conv, dims=2, out_channels=None):
      super().__init__()
      self.channels = channels
      self.out_channels = out_channels or channels
      self.use_conv = use_conv
      self.dims = dims
      stride = 2 if dims != 3 else (1, 2, 2)
      if use_conv:
          self.op = conv_nd(
              dims,
              self.channels,
              self.out_channels,
              3,
              stride=stride,
              padding=1,
          )
      else:
          assert self.channels == self.out_channels
          self.op = avg_pool_nd(dims, kernel_size=stride, stride=stride)
  
imports: from abc import abstractmethod
  from speechbrain.utils.data_utils import pad_divisible
  from .autoencoders import NormalizingAutoencoder
  import math
  import torch
  import torch.nn
  import torch.nn.functional
label_desc: Use image node_id 1 to create a new Downsample object from inherited base classes: nn with example: obj = Downsample(channels, use_conv, dims, out_channels)