def compute_G_from_H( H, mdimG = None, mode_inv = "svd" ):
    n_samples = H.shape[0]
    n_dim = H.shape[2]
    if mode_inv is 'svd':
        Huu, Hsvals, Hvv = np.linalg.svd( H )
        if mdimG is None:
            Gsvals = 1./Hsvals
            G = np.zeros((n_samples, n_dim, n_dim))
            for i in np.arange(n_samples):
                G[i,:,:] = np.dot(Huu[i,:,:], np.dot( np.diag(Gsvals[i,:]), Hvv[i,:,:]))
        elif mdimG < n_dim:
            Gsvals[:,:mdimG] = 1./Hsvals[:,:mdimG]
            Gsvals[:,mdimG:] = 0.
            # this can be redone with np.einsum() but it's barbaric
            G = np.zeros((n_samples, mdimG, mdimG))
            for i in np.arange(n_samples):
                G[i,:,:mdimG] = np.dot(Huu[i,:,mdimG], np.dot( np.diag(Gsvals[i,:mdimG]), Hvv[i,:,:mdimG]))
        else:
            raise ValueError('mdimG must be <= H.shape[1]')
        return G, Hvv, Hsvals, Gsvals
    else:
        riemann_metric = np.linalg.inv(h_dual_metric)
        return riemann_metric, None, None, None
Parameters
dataset/ETHPy150Open mmp2/megaman/megaman/geometry/rmetric.py/compute_G_from_H