GraphIndex.edge_ids return mismatched shape

I’m been using dgl/examples/pytorch/recommendation code and input my own data, but it raises that

dgl._ffi.base.DGLError: Expect number of features to match number of edges. Got 17211 and 17271 instead.

So I made a detailed probe into the code and find that the problem is located at GraphIndex.edge_ids, the shape of input tensor and output array did not match. I just know about the code little, but I can feel that there is a bug. And I also add a code to MovieLens.refresh_mask to explain it more succinctly:

        tmp = self.g.edges[self.rating_user_vertices, self.rating_movie_vertices].data
        from dgl import utils
        u, v = tmp._edges
        u, v = utils.toindex(u), utils.toindex(v)
        u1, v1, e1 = tmp._graph._graph.edge_ids(u, v)
        raise Exception("u=%s, u1=%s" % (len(u), len(u1)))

and it turned out to be:

Exception: u=17211, u1=17271

Bug confirmed and @minjie is fixing this: https://github.com/dmlc/dgl/issues/1476.

Hi, @Traeyee this happens when the graph is multigraph (there exists multiple edges between two nodes).
For example:

import dgl
import dgl.utils as utils
g = dgl.DGLGraph()
g.add_nodes(4)
g.add_edges([0,1,2,3,0,1,2,3], [1,0,3,2,1,0,3,2])
u = utils.toindex([0,1,2,3])
v = utils.toindex([1,0,3,2])
u1, v1, e1 = g._graph.edge_ids(u, v)
print(len(u), len(u1))

The result is

4 8

Would you mind remove the duplicate edges in your data manually? You can use g.is_multigraph to check whether your graph is a multigraph.