From f3518d103582ab672ada25dd525f78358fddb1e2 Mon Sep 17 00:00:00 2001 From: andreii Date: Tue, 9 Jan 2024 13:06:36 -0800 Subject: [PATCH] Fixing problem with imaginary numbers appearing in the lap_pe (laplacian positional encoding) function. --- python/dgl/transforms/functional.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/python/dgl/transforms/functional.py b/python/dgl/transforms/functional.py index 92b554a95ce1..964f665be5c3 100644 --- a/python/dgl/transforms/functional.py +++ b/python/dgl/transforms/functional.py @@ -3688,10 +3688,6 @@ def lap_pe(g, k, padding=False, return_eigval=False): ) max_freqs = k topk_indices = EigVal.argsort()[1:] - # Since scipy may return complex value, to avoid crashing in NN code, - # convert them to real number. - topk_EigVal = EigVal[topk_indices].real - topk_EigVec = EigVec[:, topk_indices].real else: # Fallback to numpy since scipy.sparse do not support this case. EigVal, EigVec = np.linalg.eig(L.toarray()) @@ -3699,8 +3695,11 @@ def lap_pe(g, k, padding=False, return_eigval=False): kpartition_indices = np.argpartition(EigVal, max_freqs)[: max_freqs + 1] topk_eigvals = EigVal[kpartition_indices] topk_indices = kpartition_indices[topk_eigvals.argsort()][1:] - topk_EigVec = EigVec[:, topk_indices] - topk_EigVal = EigVal[topk_indices] + + # Since scipy may return complex value, to avoid crashing in NN code, + # convert them to real number. + topk_EigVal = EigVal[topk_indices].real + topk_EigVec = EigVec[:, topk_indices].real eigvals = F.tensor(topk_EigVal, dtype=F.float32) # get random flip signs