snap-stanford / deepsnap

Python library assists deep learning on graphs
https://snap.stanford.edu/deepsnap/
MIT License
542 stars 57 forks source link

Error in num_nodes #41

Open psanch21 opened 2 years ago

psanch21 commented 2 years ago

Hi,

I'm getting an error in the function num_nodes because sometimes self.G is a list.

https://github.com/snap-stanford/deepsnap/blob/6197dcefc7934c6019fe2f4b0aada562e6c17c7d/deepsnap/graph.py#L220

Would it possible to update such function and just return the length of the attribute G.nodes? Something like this

  @property
  def num_nodes(self) -> int:
      r"""
      Return number of nodes in the graph.

      Returns:
          int: Number of nodes in the graph.
      """
      G = None
      if isinstance(self.G, list):
          G = self.G[0]
      else:
          G = self.G

      return len(G.nodes)

Thanks in advance