Empty Node ID array needs to be correct dtype.
- Dominant language
- Python
- Stars
- 14.3k
- Forks
- 3.1k
- PR merge metrics
- No merged PRs in 30d
Description
## 🐛 Bug
When trying to rebuild a heterograph, there were a few ids that were empty. When I created those empty tensors, I got
```
DGLError: [02:10:47] /opt/dgl/dgl-source/src/graph/unit_graph.cc:67: Check failed: aten::IsValidIdArray(src):
Stack trace:
[bt] (0) /opt/conda/lib/python3.8/site-packages/dgl-0.8.0.post2-py3.8-linux-x86_64.egg/dgl/libdgl.so(+0x128c498) [0x7f845982c498]
[bt] (1) /opt/conda/lib/python3.8/site-packages/dgl-0.8.0.post2-py3.8-linux-x86_64.egg/dgl/libdgl.so(dgl::UnitGraph::COO::COO(std::shared_ptr, long, long, dgl::runtime::NDArray, dgl::runtime::NDArray, bool, bool)+0x112) [0x7f8459842902]
[bt] (2) /opt/conda/lib/python3.8/site-packages/dgl-0.8.0.post2-py3.8-linux-x86_64.egg/dgl/libdgl.so(dgl::UnitGraph::CreateFromCOO(long, long, long, dgl::runtime::NDArray, dgl::runtime::NDArray, bool, bool, unsigned char)+0x1bf) [0x7f84598351ef]
[bt] (3) /opt/conda/lib/python3.8/site-packages/dgl-0.8.0.post2-py3.8-linux-x86_64.egg/dgl/libdgl.so(dgl::CreateFromCOO(long, long, long, dgl::runtime::NDArray, dgl::runtime::NDArray, bool, bool, unsigned char)+0x82) [0x7f84596e2912]
[bt] (4) /opt/conda/lib/python3.8/site-packages/dgl-0.8.0.post2-py3.8-linux-x86_64.egg/dgl/libdgl.so(+0x1192273) [0x7f8459732273]
[bt] (5) /opt/conda/lib/python3.8/site-packages/dgl-0.8.0.post2-py3.8-linux-x86_64.egg/dgl/libdgl.so(+0x1192438) [0x7f8459732438]
[bt] (6) /opt/conda/lib/python3.8/site-packages/dgl-0.8.0.post2-py3.8-linux-x86_64.egg/dgl/libdgl.so(DGLFuncCall+0x69) [0x7f84596af2f9]
[bt] (7) /opt/conda/lib/python3.8/site-packages/dgl-0.8.0.post2-py3.8-linux-x86_64.egg/dgl/_ffi/_cy3/core.cpython-38-x86_64-linux-gnu.so(+0x19c09) [0x7f84584d9c09]
[bt] (8) /opt/conda/lib/python3.8/site-packages/dgl-0.8.0.post2-py3.8-linux-x86_64.egg/dgl/_ffi/_cy3/core.cpython-38-x86_64-linux-gnu.so(+0x19da0) [0x7f84584d9da0]
```
In order to fix this, I casted the empty array to int64 and the issue went away.
## To Reproduce
```
import numpy as np
import torch
import dgl
block = {}
block[('a', 'f', 'i')] = (
torch.from_numpy(np.array([])),
torch.from_numpy(np.array([])))
block[('a', 'w', 'p')] = (
torch.from_numpy(np.arange(4)),
torch.from_numpy(np.arange(4, 8)))
dgl.heterograph(block)
```
Can be fixed by replacing code with
```
import numpy as np
import torch
import dgl
block = {}
block[('a', 'f', 'i')] = (
torch.from_numpy(np.array([]).astype(np.int64)),
torch.from_numpy(np.array([]).astype(np.int64)))
block[('a', 'w', 'p')] = (
torch.from_numpy(np.arange(4)),
torch.from_numpy(np.arange(4, 8)))
dgl.heterograph(block)
```
## Expected behavior
If it is an empty array it shouldn't matter what type it is.
## Environment
- DGL Version (e.g., 1.0): 0.8 post 2
- GPU models and configuration (e.g. V100): RTX A6000
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.