Skip to content

torch.size() diverges from array API specification #58741

@pmeier

Description

@pmeier

The array API specification stipulates that the size attribute of an array should return an integer with the number of elements of the array.

In PyTorch the size attribute is a method that returns the shape when called. The number of elements is accessible through the numel() method:

import torch

t = torch.empty((2, 3, 4))
size = 2 * 3 * 4

assert t.size() == t.shape
assert t.numel() == size

cc @mruberry @rgommers @pmeier @asmeurer @leofang

Metadata

Metadata

Assignees

Labels

module: deprecationmodule: python array apiIssues related to the Python Array APItriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions