code: def _get_layout_transpose_axes(
      ndim, src_layout, dst_layout, inverse=False
  ):
      # None: no transposition is required.
  
      if src_layout == dst_layout:
          return None
  
      if dst_layout == CUDNN_CHANNEL_LAST_X:
          assert ndim >= 3
          assert src_layout == CUDNN_CHANNEL_FIRST_X
          trans = (0,) + tuple(range(2, ndim)) + (1,)
  
      elif dst_layout == CUDNN_CHANNEL_LAST_W:
          assert ndim >= 3
          assert src_layout == CUDNN_CHANNEL_FIRST_W
          trans = (0,) + tuple(range(2, ndim)) + (1,)
  
      elif src_layout == CUDNN_CHANNEL_LAST_X:
          assert ndim >= 3
          assert dst_layout == CUDNN_CHANNEL_FIRST_X
          trans = (0, ndim - 1) + tuple(range(1, ndim - 1))
  
      elif src_layout == CUDNN_CHANNEL_LAST_W:
          assert ndim >= 3
          assert dst_layout == CUDNN_CHANNEL_FIRST_W
          trans = (0, ndim - 1) + tuple(range(1, ndim - 1))
  
      else:
          raise ValueError(
              "Unknown layout conversion: from '{}' to '{}'".format(
                  src_layout, dst_layout
              )
          )
  
      if inverse:
          t = [None] * ndim
          for i, n in enumerate(trans):
              t[n] = i
          trans = tuple(t)
  
      # Postconditions:
      # - assert isinstance(trans, tuple)
      # - assert len(trans) == ndim
      # - assert all([i in trans for i in range(ndim)])
      return trans
  
file_path: chainer/chainer/memory_layouts.py
imports: import chainer
  from chainer import function_node
  from chainer.utils import type_check
label_desc: Use image node_id 5 for calling a global function with example usage: _get_layout_transpose_axes(ndim, src_layout, dst_layout, inverse) and returns: trans, None