Skip to content

Commit

Permalink
small fixes in the immutable graph index. (dmlc#271)
Browse files Browse the repository at this point in the history
* small fix in immutable graph index.

* minor fix.
  • Loading branch information
zheng-da authored Dec 7, 2018
1 parent f720ce1 commit c0d1f8e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions python/dgl/immutable_graph_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ._ffi.function import _init_api
from . import backend as F
from . import utils
from .base import ALL, is_all, dgl_warning, DGLError
from .base import ALL, is_all, DGLError

class ImmutableGraphIndex(object):
"""Graph index object on immutable graphs.
Expand Down Expand Up @@ -514,8 +514,6 @@ def adjacency_matrix(self, transpose=False, ctx=F.cpu()):
def get_adj(ctx):
new_mat = self._sparse.adjacency_matrix(transpose)
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

def incidence_matrix(self, type, ctx):
Expand Down Expand Up @@ -649,9 +647,15 @@ def from_edge_list(self, elist):
min_nodes = min(src.min(), dst.min())
if min_nodes != 0:
raise DGLError('Invalid edge list. Nodes must start from 0.')
data = np.ones((len(src),), dtype=np.int32)
spmat = sp.coo_matrix((data, (src, dst)), shape=(num_nodes, num_nodes))
self._sparse.from_coo_matrix(spmat)
edge_ids = mx.nd.arange(0, len(src), step=1, repeat=1, dtype=np.int32)
src = mx.nd.array(src, dtype=np.int64)
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):
"""Return the line graph of this graph.
Expand Down

0 comments on commit c0d1f8e

Please sign in to comment.