Skip to content

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

Description

@njzjz

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:

@property
def num_graphs(self) -> int:
"""Returns the number of graphs in the batch."""
if self.__num_graphs__ is not None:
return self.__num_graphs__
elif self.ptr is not None:
return self.ptr.numel() - 1
elif self.batch is not None:
return int(self.batch.max()) + 1

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:

return len(self.ptr) - 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions