deepmodeling / deepmodeling/dftio
[Code scan] Fix Batch.num_graphs for NumPy ptr arrays
Open
- Dominant language
- Jupyter Notebook
- Stars
- 16
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
This issue comes from a Codex global repository scan.
## Problem
`Batch.num_graphs` calls `self.ptr.numel()`, but this NumPy batch implementation stores `ptr` as a NumPy array:
https://github.com/deepmodeling/dftio/blob/c9d128f24a74ef2911e1a28f5640357488beb196/dftio/data/batch_np.py#L275-L283
NumPy arrays do not have `.numel()`, so `Batch(ptr=np.array([0, 2, 5])).num_graphs` raises `AttributeError`.
## Suggested fix
Use a NumPy/Python length API, for example:
```python
return len(self.ptr) - 1
```
Contributor guide
Assessment
This issue has not been assessed yet.