"...python/git@developer.sourcefind.cn:change/sglang.git" did not exist on "c9bcffd2a53423e6a183e312a58675fb48435d2a"
Unverified Commit c0d1f8e4 authored by Da Zheng's avatar Da Zheng Committed by GitHub
Browse files

small fixes in the immutable graph index. (#271)

* small fix in immutable graph index.

* minor fix.
parent f720ce13
...@@ -8,7 +8,7 @@ import scipy.sparse as sp ...@@ -8,7 +8,7 @@ import scipy.sparse as sp
from ._ffi.function import _init_api from ._ffi.function import _init_api
from . import backend as F from . import backend as F
from . import utils from . import utils
from .base import ALL, is_all, dgl_warning, DGLError from .base import ALL, is_all, DGLError
class ImmutableGraphIndex(object): class ImmutableGraphIndex(object):
"""Graph index object on immutable graphs. """Graph index object on immutable graphs.
...@@ -514,8 +514,6 @@ class ImmutableGraphIndex(object): ...@@ -514,8 +514,6 @@ class ImmutableGraphIndex(object):
def get_adj(ctx): def get_adj(ctx):
new_mat = self._sparse.adjacency_matrix(transpose) new_mat = self._sparse.adjacency_matrix(transpose)
return F.copy_to(new_mat, ctx) return F.copy_to(new_mat, ctx)
# FIXME(minjie): calculate the shuffle index
dgl_warning('Shuffle index is not correctly computed. SPMV with edge feature might fail!!')
return self._sparse.adjacency_matrix(transpose, ctx), None return self._sparse.adjacency_matrix(transpose, ctx), None
def incidence_matrix(self, type, ctx): def incidence_matrix(self, type, ctx):
...@@ -649,9 +647,15 @@ class ImmutableGraphIndex(object): ...@@ -649,9 +647,15 @@ class ImmutableGraphIndex(object):
min_nodes = min(src.min(), dst.min()) min_nodes = min(src.min(), dst.min())
if min_nodes != 0: if min_nodes != 0:
raise DGLError('Invalid edge list. Nodes must start from 0.') raise DGLError('Invalid edge list. Nodes must start from 0.')
data = np.ones((len(src),), dtype=np.int32) edge_ids = mx.nd.arange(0, len(src), step=1, repeat=1, dtype=np.int32)
spmat = sp.coo_matrix((data, (src, dst)), shape=(num_nodes, num_nodes)) src = mx.nd.array(src, dtype=np.int64)
self._sparse.from_coo_matrix(spmat) dst = mx.nd.array(dst, dtype=np.int64)
# TODO we can't generate a csr_matrix with np.int64 directly.
in_csr = mx.nd.sparse.csr_matrix((edge_ids, (dst, src)),
shape=(num_nodes, num_nodes)).astype(np.int64)
out_csr = mx.nd.sparse.csr_matrix((edge_ids, (src, dst)),
shape=(num_nodes, num_nodes)).astype(np.int64)
self.__init__(in_csr, out_csr)
def line_graph(self, backtracking=True): def line_graph(self, backtracking=True):
"""Return the line graph of this graph. """Return the line graph of this graph.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment