code: def transformer_from_metric(metric, tol=None):
    
    if not np.allclose(metric, metric.T):
      raise ValueError("The input metric should be symmetric.")
    # If M is diagonal, we will just return the elementwise square root:
    if np.array_equal(metric, np.diag(np.diag(metric))):
      _check_sdp_from_eigen(np.diag(metric), tol)
      return np.diag(np.sqrt(np.maximum(0, np.diag(metric))))
    else:
      try:
        # if `M` is positive semi-definite, it will admit a Cholesky
        # decomposition: L = cholesky(M).T
        return np.linalg.cholesky(metric).T
      except LinAlgError:
        # However, currently np.linalg.cholesky does not support indefinite
        # matrices. So if the latter does not work we will return L = V.T w^(
        # -1/2), with M = V*w*V.T being the eigenvector decomposition of M with
        # the eigenvalues in the diagonal matrix w and the columns of V being the
        # eigenvectors.
        w, V = np.linalg.eigh(metric)
        _check_sdp_from_eigen(w, tol)
        return V.T * np.sqrt(np.maximum(0, w[:, None]))
docs: Returns the transformation matrix from the Mahalanobis matrix.
  
    Returns the transformation matrix from the Mahalanobis matrix, i.e. the
    matrix L such that metric=L.T.dot(L).
  
    Parameters
    ----------
    metric : symmetric `np.ndarray`, shape=(d x d)
      The input metric, from which we want to extract a transformation matrix.
  
    tol : positive `float`, optional
      Eigenvalues of `metric` between 0 and - tol are considered zero. If tol is
      None, and w_max is `metric`'s largest eigenvalue, and eps is the epsilon
      value for datatype of w, then tol is set to w_max * metric.shape[0] * eps.
  
    Returns
    -------
    L : np.ndarray, shape=(d x d)
      The transformation matrix, such that L.T.dot(L) == metric.