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