deepmodeling / deepmodeling/dftio

[Code scan] Fix Batch.num_graphs for NumPy ptr arrays

Open
#41 0 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.