Unverified Commit 0038a29b authored by Xin Yao's avatar Xin Yao Committed by GitHub
Browse files

[Fix core lib warning] Fix numpy dtype (#5027)

parent 354a2110
...@@ -31,7 +31,7 @@ def data_type_dict(): ...@@ -31,7 +31,7 @@ def data_type_dict():
"int16": np.int16, "int16": np.int16,
"int32": np.int32, "int32": np.int32,
"int64": np.int64, "int64": np.int64,
"bool": np.bool, "bool": np.bool_,
} # mxnet does not support bool } # mxnet does not support bool
...@@ -40,7 +40,7 @@ def cpu(): ...@@ -40,7 +40,7 @@ def cpu():
def tensor(data, dtype=None): def tensor(data, dtype=None):
if dtype == np.bool: if dtype == np.bool_:
# mxnet doesn't support bool # mxnet doesn't support bool
dtype = np.int32 dtype = np.int32
if isinstance(data, nd.NDArray): if isinstance(data, nd.NDArray):
...@@ -53,7 +53,7 @@ def tensor(data, dtype=None): ...@@ -53,7 +53,7 @@ def tensor(data, dtype=None):
data = [data] data = [data]
if dtype is None: if dtype is None:
if isinstance(data, np.ndarray): if isinstance(data, np.ndarray):
dtype = np.int32 if data.dtype == np.bool else data.dtype dtype = np.int32 if data.dtype == np.bool_ else data.dtype
elif len(data) == 0: elif len(data) == 0:
dtype = np.int64 dtype = np.int64
else: else:
...@@ -165,7 +165,7 @@ def to_backend_ctx(dglctx): ...@@ -165,7 +165,7 @@ def to_backend_ctx(dglctx):
def astype(input, ty): def astype(input, ty):
if ty == np.bool: if ty == np.bool_:
ty = np.int32 ty = np.int32
return input.astype(ty) return input.astype(ty)
......
...@@ -162,9 +162,9 @@ class FakeNewsDataset(DGLBuiltinDataset): ...@@ -162,9 +162,9 @@ class FakeNewsDataset(DGLBuiltinDataset):
train_idx = np.load(os.path.join(self.raw_path, "train_idx.npy")) train_idx = np.load(os.path.join(self.raw_path, "train_idx.npy"))
val_idx = np.load(os.path.join(self.raw_path, "val_idx.npy")) val_idx = np.load(os.path.join(self.raw_path, "val_idx.npy"))
test_idx = np.load(os.path.join(self.raw_path, "test_idx.npy")) test_idx = np.load(os.path.join(self.raw_path, "test_idx.npy"))
train_mask = np.zeros(num_graphs, dtype=np.bool) train_mask = np.zeros(num_graphs, dtype=np.bool_)
val_mask = np.zeros(num_graphs, dtype=np.bool) val_mask = np.zeros(num_graphs, dtype=np.bool_)
test_mask = np.zeros(num_graphs, dtype=np.bool) test_mask = np.zeros(num_graphs, dtype=np.bool_)
train_mask[train_idx] = True train_mask[train_idx] = True
val_mask[val_idx] = True val_mask[val_idx] = True
test_mask[test_idx] = True test_mask[test_idx] = True
......
...@@ -227,9 +227,9 @@ class FraudDataset(DGLBuiltinDataset): ...@@ -227,9 +227,9 @@ class FraudDataset(DGLBuiltinDataset):
int(train_size * len(index)) : len(index) int(train_size * len(index)) : len(index)
- int(val_size * len(index)) - int(val_size * len(index))
] ]
train_mask = np.zeros(N, dtype=np.bool) train_mask = np.zeros(N, dtype=np.bool_)
val_mask = np.zeros(N, dtype=np.bool) val_mask = np.zeros(N, dtype=np.bool_)
test_mask = np.zeros(N, dtype=np.bool) test_mask = np.zeros(N, dtype=np.bool_)
train_mask[train_idx] = True train_mask[train_idx] = True
val_mask[val_idx] = True val_mask[val_idx] = True
test_mask[test_idx] = True test_mask[test_idx] = True
......
...@@ -178,7 +178,7 @@ class MiniGCDataset(DGLDataset): ...@@ -178,7 +178,7 @@ class MiniGCDataset(DGLDataset):
for i in range(self.num_graphs): for i in range(self.num_graphs):
# convert to DGLGraph, and add self loops # convert to DGLGraph, and add self loops
self.graphs[i] = add_self_loop(from_networkx(self.graphs[i])) self.graphs[i] = add_self_loop(from_networkx(self.graphs[i]))
self.labels = F.tensor(np.array(self.labels).astype(np.int)) self.labels = F.tensor(np.array(self.labels).astype(np.int64))
def _gen_cycle(self, n): def _gen_cycle(self, n):
for _ in range(n): for _ in range(n):
......
...@@ -182,7 +182,7 @@ class QM9Dataset(DGLDataset): ...@@ -182,7 +182,7 @@ class QM9Dataset(DGLDataset):
n_atoms = self.N[idx] n_atoms = self.N[idx]
R = self.R[self.N_cumsum[idx]:self.N_cumsum[idx + 1]] R = self.R[self.N_cumsum[idx]:self.N_cumsum[idx + 1]]
dist = np.linalg.norm(R[:, None, :] - R[None, :, :], axis=-1) dist = np.linalg.norm(R[:, None, :] - R[None, :, :], axis=-1)
adj = sp.csr_matrix(dist <= self.cutoff) - sp.eye(n_atoms, dtype=np.bool) adj = sp.csr_matrix(dist <= self.cutoff) - sp.eye(n_atoms, dtype=np.bool_)
adj = adj.tocoo() adj = adj.tocoo()
u, v = F.tensor(adj.row), F.tensor(adj.col) u, v = F.tensor(adj.row), F.tensor(adj.col)
g = dgl_graph((u, v)) g = dgl_graph((u, v))
......
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