code: def dkl_wishart(a1, B1, a2, B2):
      """
      returns the KL divergence bteween two Wishart distribution of
      parameters (a1,B1) and (a2,B2),
  
      Parameters
      ----------
      a1: Float,
          degrees of freedom of the first density
      B1: array of shape(n,n),
          scale matrix of the  first density
      a2: Float,
          degrees of freedom of the second density
      B2: array of shape(n,n),
          scale matrix of the second density
  
      Returns
      -------
      dkl: float, the Kullback-Leibler divergence
      """
      from scipy.special import gammaln, psi
  
      tiny = 1.0e-15
      if B1.shape != B2.shape:
          raise ValueError("incompatible dimensions for B1 and B2")
  
      dim = B1.shape[0]
      d1 = max(detsh(B1), tiny)
      d2 = max(detsh(B2), tiny)
      lgc = dim * (dim - 1) * math.log(np.pi) / 4
      lg1 = lgc
      lg2 = lgc
      lw1 = -math.log(d1) + dim * math.log(2)
      lw2 = -math.log(d2) + dim * math.log(2)
      for i in range(dim):
          lg1 += gammaln((a1 - i) / 2)
          lg2 += gammaln((a2 - i) / 2)
          lw1 += psi((a1 - i) / 2)
          lw2 += psi((a2 - i) / 2)
      lz1 = 0.5 * a1 * dim * math.log(2) - 0.5 * a1 * math.log(d1) + lg1
      lz2 = 0.5 * a2 * dim * math.log(2) - 0.5 * a2 * math.log(d2) + lg2
      dkl = (a1 - dim - 1) * lw1 - (a2 - dim - 1) * lw2 - a1 * dim
      dkl += a1 * np.trace(np.dot(B2, inv(B1)))
      dkl /= 2
      dkl += lz2 - lz1
      return dkl
  
imports: import math
  import numpy
  import numpy.random
  from scipy.linalg import cholesky, eigvalsh, inv
  from scipy.special import gammaln
  from .gmm import GMM
  from .utils import kmeans
label_desc: Use image node_id 10 for calling a global function with example usage: dkl_wishart(a1, B1, a2, B2) and returns: dkl