Skip to content

Add Tensor.nbytes() / Tensor.itemsize() #12728

Closed
@ezyang

Description

@ezyang

🚀 Feature

Add nbytes and itemsize methods to Tensor. It has the same semantics as https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.ndarray.nbytes.html and https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.ndarray.itemsize.html (though, in keeping with PyTorch style, it is a function call, not a property).

Motivation

The primary motivation is that caffe2::Tensor has these two methods, it's used somewhat frequently in the Caffe2 codebase, and it seems like a generally useful thing to have around.

Alternatives

  • Don't add them, and make users do the computation themselves. This might be a little annoying to do, because if we don't have itemsize() the user has to compute it themselves from the dtype.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issuelow priorityWe're unlikely to get around to doing this in the near futuremodule: numpyRelated to numpy support, and also numpy compatibility of our operatorstriagedThis 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