code: def _cholesky(M, hermitian=True):
      """Returns the Cholesky-type decomposition L of a matrix A
      such that L * L.H == A if hermitian flag is True,
      or L * L.T == A if hermitian is False.
  
      A must be a Hermitian positive-definite matrix if hermitian is True,
      or a symmetric matrix if it is False.
  
      Examples
      ========
  
      >>> from sympy import Matrix
      >>> A = Matrix(((25, 15, -5), (15, 18, 0), (-5, 0, 11)))
      >>> A.cholesky()
      Matrix([
      [ 5, 0, 0],
      [ 3, 3, 0],
      [-1, 1, 3]])
      >>> A.cholesky() * A.cholesky().T
      Matrix([
      [25, 15, -5],
      [15, 18,  0],
      [-5,  0, 11]])
  
      The matrix can have complex entries:
  
      >>> from sympy import I
      >>> A = Matrix(((9, 3*I), (-3*I, 5)))
      >>> A.cholesky()
      Matrix([
      [ 3, 0],
      [-I, 2]])
      >>> A.cholesky() * A.cholesky().H
      Matrix([
      [   9, 3*I],
      [-3*I,   5]])
  
      Non-hermitian Cholesky-type decomposition may be useful when the
      matrix is not positive-definite.
  
      >>> A = Matrix([[1, 2], [2, 1]])
      >>> L = A.cholesky(hermitian=False)
      >>> L
      Matrix([
      [1,         0],
      [2, sqrt(3)*I]])
      >>> L*L.T == A
      True
  
      See Also
      ========
  
      sympy.matrices.dense.DenseMatrix.LDLdecomposition
      sympy.matrices.matrixbase.MatrixBase.LUdecomposition
      QRdecomposition
      """
  
      from .dense import MutableDenseMatrix
  
      if not M.is_square:
          raise NonSquareMatrixError("Matrix must be square.")
      if hermitian and not M.is_hermitian:
          raise ValueError("Matrix must be Hermitian.")
      if not hermitian and not M.is_symmetric():
          raise ValueError("Matrix must be symmetric.")
  
      L = MutableDenseMatrix.zeros(M.rows, M.rows)
  
      if hermitian:
          for i in range(M.rows):
              for j in range(i):
                  L[i, j] = (1 / L[j, j]) * (
                      M[i, j]
                      - sum(
                          L[i, k] * L[j, k].conjugate()
                          for k in range(j)
                      )
                  )
  
              Lii2 = M[i, i] - sum(
                  L[i, k] * L[i, k].conjugate() for k in range(i)
              )
  
              if Lii2.is_positive is False:
                  raise NonPositiveDefiniteMatrixError(
                      "Matrix must be positive-definite"
                  )
  
              L[i, i] = sqrt(Lii2)
  
      else:
          for i in range(M.rows):
              for j in range(i):
                  L[i, j] = (1 / L[j, j]) * (
                      M[i, j] - sum(L[i, k] * L[j, k] for k in range(j))
                  )
  
              L[i, i] = sqrt(
                  M[i, i] - sum(L[i, k] ** 2 for k in range(i))
              )
  
      return M._new(L)
  
imports: import copy
  from sympy.core import S
  from sympy.core.function import expand_mul
  from sympy.functions.elementary.miscellaneous import Min, sqrt
  from sympy.functions.elementary.complexes import sign
  from .exceptions import NonSquareMatrixError, NonPositiveDefiniteMatrixError
  from .utilities import _get_intermediate_simp, _iszero
  from .determinant import _find_reasonable_pivot_naive
label_desc: Use image node_id 4 for calling a global function with example usage: _cholesky(M, hermitian) and returns: M