code: def is_reversible(T, mu=None, tol=1e-15):
      r
      if not is_transition_matrix(T, tol):
          raise ValueError("given matrix is not a valid transition matrix.")
  
      T = T.tocsr()
  
      if mu is None:
          from .decomposition import stationary_distribution
          mu = stationary_distribution(T)
  
      Mu = diags(mu, 0)
      prod = Mu * T
  
      return allclose_sparse(prod, prod.transpose(), rtol=tol)
docs: r"""
      checks whether T is reversible in terms of given stationary distribution.
      If no distribution is given, it will be calculated out of T.
  
      performs follwing check:
      :math:`\pi_i P_{ij} = \pi_j P_{ji}
      Parameters
      ----------
      T : scipy.sparse matrix
          Transition matrix
      mu : numpy.ndarray vector
          stationary distribution
      tol : float
          tolerance to check with
  
      Returns
      -------
      Truth value : bool
          True, if T is a stochastic matrix
          False, otherwise