# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/Manifold Distances.ipynb.

# %% auto 0
__all__ = ['phate_distances']

# %% ../nbs/Manifold Distances.ipynb 3
from sklearn.metrics import pairwise_distances
import numpy as np
import scipy
import graphtools
def phate_distances(G:graphtools.api.Graph):
    assert G.Pt is not None
    if type(G.Pt) == np.ndarray:
        log_Pts = -np.log(G.Pt + 1e-6)
        D = pairwise_distances(log_Pts)
    elif type(G.Pt) == scipy.sparse.csr_matrix:
        # TODO: There's likely a more efficient way of doing this. 
        # But I mustn't tempt the devil of premature optimization
        Pt_np = G.Pt.toarray()
        log_Pts = -np.log(Pt_np + 1e-6)
        D = pairwise_distances(log_Pts)
    G.D = D
    return G
