class_docstr: A Permutation Matrix
  
  Parameters
  ==========
  
  perm : Permutation
      The permutation the matrix uses.
  
      The size of the permutation determines the matrix size.
  
      See the documentation of
      :class:`sympy.combinatorics.permutations.Permutation` for
      the further information of how to create a permutation object.
  
  Examples
  ========
  
  >>> from sympy import Matrix, PermutationMatrix
  >>> from sympy.combinatorics import Permutation
  
  Creating a permutation matrix:
  
  >>> p = Permutation(1, 2, 0)
  >>> P = PermutationMatrix(p)
  >>> P = P.as_explicit()
  >>> P
  Matrix([
  [0, 1, 0],
  [0, 0, 1],
  [1, 0, 0]])
  
  Permuting a matrix row and column:
  
  >>> M = Matrix([0, 1, 2])
  >>> Matrix(P*M)
  Matrix([
  [1],
  [2],
  [0]])
  
  >>> Matrix(M.T*P)
  Matrix([[2, 0, 1]])
  
  See Also
  ========
  
  sympy.combinatorics.permutations.Permutation
code: def _eval_rewrite_as_BlockDiagMatrix(self, *args, **kwargs):
      from sympy.combinatorics.permutations import Permutation
      from .blockmatrix import BlockDiagMatrix
  
      perm = self.args[0]
      full_cyclic_form = perm.full_cyclic_form
  
      cycles_picks = []
  
      # Stage 1. Decompose the cycles into the blockable form.
      a, b, c = 0, 0, 0
      flag = False
      for cycle in full_cyclic_form:
          l = len(cycle)
          m = max(cycle)
  
          if not flag:
              if m + 1 > a + l:
                  flag = True
                  temp = [cycle]
                  b = m
                  c = l
              else:
                  cycles_picks.append([cycle])
                  a += l
  
          else:
              if m > b:
                  if m + 1 == a + c + l:
                      temp.append(cycle)
                      cycles_picks.append(temp)
                      flag = False
                      a = m + 1
                  else:
                      b = m
                      temp.append(cycle)
                      c += l
              else:
                  if b + 1 == a + c + l:
                      temp.append(cycle)
                      cycles_picks.append(temp)
                      flag = False
                      a = b + 1
                  else:
                      temp.append(cycle)
                      c += l
  
      # Stage 2. Normalize each decomposed cycles and build matrix.
      p = 0
      args = []
      for pick in cycles_picks:
          new_cycles = []
          l = 0
          for cycle in pick:
              new_cycle = [i - p for i in cycle]
              new_cycles.append(new_cycle)
              l += len(cycle)
          p += l
          perm = Permutation(new_cycles)
          mat = PermutationMatrix(perm)
          args.append(mat)
  
      return BlockDiagMatrix(*args)
  
imports: from sympy.core import S
  from sympy.core.sympify import _sympify
  from sympy.functions import KroneckerDelta
  from .matexpr import MatrixExpr
  from .special import ZeroMatrix, Identity, OneMatrix
label_desc: Use image node_id 9 for calling the PermutationMatrix obj's underlying member method code with example usage: obj._eval_rewrite_as_BlockDiagMatrix() and returns: BlockDiagMatrix