def compute_G_from_H( H, mdimG = None, mode_inv = "<STR_LIT>" ):
n_samples = H.shape[<NUM_LIT:0>]<EOL>n_dim = H.shape[<NUM_LIT:2>]<EOL>if mode_inv is '<STR_LIT>':<EOL><INDENT>Huu, Hsvals, Hvv = np.linalg.svd( H )<EOL>if mdimG is None:<EOL><INDENT>Gsvals = <NUM_LIT:1.>/Hsvals<EOL>G = np.zeros((n_samples, n_dim, n_dim))<EOL>for i in np.arange(n_samples):<EOL><INDENT>G[i,:,:] = np.dot(Huu[i,:,:], np.dot( np.diag(Gsvals[i,:]), Hvv[i,:,:]))<EOL><DEDENT><DEDENT>elif mdimG < n_dim:<EOL><INDENT>Gsvals[:,:mdimG] = <NUM_LIT:1.>/Hsvals[:,:mdimG]<EOL>Gsvals[:,mdimG:] = <NUM_LIT:0.><EOL>G = np.zeros((n_samples, mdimG, mdimG))<EOL>for i in np.arange(n_samples):<EOL><INDENT>G[i,:,:mdimG] = np.dot(Huu[i,:,mdimG], np.dot( np.diag(Gsvals[i,:mdimG]), Hvv[i,:,:mdimG]))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return G, Hvv, Hsvals, Gsvals<EOL><DEDENT>else:<EOL><INDENT>riemann_metric = np.linalg.inv(h_dual_metric)<EOL>return riemann_metric, None, None, None<EOL><DEDENT>
Parameters
----------
H : the inverse R. Metric
if mode_inv == 'svd':
   also returns Hvv, Hsvals, Gsvals the (transposed) eigenvectors of
   H and the singular values of H and G
if mdimG < H.shape[2]:
   G.shape = [ n_samples, mdimG, mdimG ] with n_samples = H.shape[0]

Notes
------
currently Hvv, Hsvals are n_dim = H.shape[2], and Gsvals, G are mdimG
(This contradicts the documentation of riemann_metric which states
that riemann_metric and h_dual_metric have the same dimensions)

See the notes in RiemannMetric