Commit 6663fdf4 authored by nd-02110114's avatar nd-02110114
Browse files

remove int64

parent 2b79862f
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -60,8 +60,8 @@ class GraphData:

    if isinstance(edge_index, np.ndarray) is False:
      raise ValueError('edge_index must be np.ndarray.')
    elif edge_index.dtype != np.int64:
      raise ValueError('edge_index.dtype must be np.int64')
    elif edge_index.dtype != np.int:
      raise ValueError('edge_index.dtype must be np.int.')
    elif edge_index.shape[0] != 2:
      raise ValueError('The shape of edge_index is [2, num_edges].')
    elif np.max(edge_index) >= len(node_features):
@@ -108,7 +108,7 @@ class GraphData:

    return Data(
      x=torch.from_numpy(self.node_features),
      edge_index=torch.from_numpy(self.edge_index),
      edge_index=torch.from_numpy(self.edge_index).long(),
      edge_attr=None if self.edge_features is None \
        else torch.from_numpy(self.edge_features),
    )
@@ -196,13 +196,13 @@ class BatchGraphData(GraphData):
    batch_edge_index = np.hstack(
      [graph.edge_index + prev_num_node for prev_num_node, graph \
        in zip([0] + num_nodes_list[:-1], graph_list)]
    ).astype(np.int64)
    )

    # graph_index indicates which nodes belong to which graph
    graph_index = []
    for i, num_nodes in enumerate(num_nodes_list):
      graph_index.extend([i] * num_nodes)
    self.graph_index = np.array(graph_index, dtype=np.int64)
    self.graph_index = np.array(graph_index)

    super().__init__(
        node_features=batch_node_features,
+20 −25
Original line number Diff line number Diff line
@@ -11,11 +11,10 @@ class TestGraph(unittest.TestCase):
    num_edges, num_edge_features = 6, 32
    node_features = np.random.random_sample((num_nodes, num_node_features))
    edge_features = np.random.random_sample((num_edges, num_edge_features))
    edge_index = np.array(
        [
    edge_index = np.array([
        [0, 1, 2, 2, 3, 4],
        [1, 2, 0, 3, 4, 0],
        ], dtype=np.int64)
    ])
    graph_features = None

    graph = GraphData(
@@ -41,11 +40,10 @@ class TestGraph(unittest.TestCase):
  def test_invalid_graph_data(self):
    with pytest.raises(ValueError):
      invalid_node_features_type = list(np.random.random_sample((5, 32)))
      edge_index = np.array(
          [
      edge_index = np.array([
          [0, 1, 2, 2, 3, 4],
          [1, 2, 0, 3, 4, 0],
          ], dtype=np.int64)
      ])
      _ = GraphData(
          node_features=invalid_node_features_type,
          edge_index=edge_index,
@@ -53,11 +51,10 @@ class TestGraph(unittest.TestCase):

    with pytest.raises(ValueError):
      node_features = np.random.random_sample((5, 32))
      invalid_edge_index_shape = np.array(
          [
      invalid_edge_index_shape = np.array([
          [0, 1, 2, 2, 3, 4],
          [1, 2, 0, 3, 4, 5],
          ], dtype=np.int64)
      ])
      _ = GraphData(
          node_features=node_features,
          edge_index=invalid_edge_index_shape,
@@ -65,13 +62,11 @@ class TestGraph(unittest.TestCase):

    with pytest.raises(ValueError):
      node_features = np.random.random_sample((5, 5))
      invalid_edge_index_shape = np.array(
          [
      invalid_edge_index_shape = np.array([
          [0, 1, 2, 2, 3, 4],
          [1, 2, 0, 3, 4, 0],
          [2, 2, 1, 4, 0, 3],
          ],
          dtype=np.int64)
      ],)
      _ = GraphData(
          node_features=node_features,
          edge_index=invalid_edge_index_shape,
@@ -85,9 +80,9 @@ class TestGraph(unittest.TestCase):
    num_nodes_list, num_edge_list = [3, 4, 5], [2, 4, 5]
    num_node_features, num_edge_features = 32, 32
    edge_index_list = [
        np.array([[0, 1], [1, 2]], dtype=np.int64),
        np.array([[0, 1, 2, 3], [1, 2, 0, 2]], dtype=np.int64),
        np.array([[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]], dtype=np.int64),
        np.array([[0, 1], [1, 2]]),
        np.array([[0, 1, 2, 3], [1, 2, 0, 2]]),
        np.array([[0, 1, 2, 3, 4], [1, 2, 3, 4, 0]]),
    ]

    graph_list = [