Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17810
Partially addresses #12728. Also, switch the element_size bindings
to use the new function, rather than the method on Type.
We don't add Python bindings yet, as they need to be special
(they will be properties.)
Differential Revision:
D14388790
fbshipit-source-id:
294183d0c8a59b0c13f2bf21d6f1cd557333e83b
bool is_contiguous() const {
return impl_->is_contiguous();
}
+
+ // Total bytes consumed by the "view" of elements of the array. Does not
+ // include size of metadata. The number reported here does not necessarily
+ // correspond to the true physical memory consumed by a tensor; instead,
+ // it reports the memory the tensor would take *if* it were contiguous.
+ // Defined to be numel() * itemsize()
+ size_t nbytes() const {
+ return impl_->numel() * impl_->itemsize();
+ }
+
+ // Length of one array element in bytes. This is the traditional
+ // Numpy naming.
+ size_t itemsize() const {
+ return impl_->itemsize();
+ }
+
+ // Same as itemsize(). This is the PyTorch naming.
+ size_t element_size() const {
+ return impl_->itemsize();
+ }
+
Type & type() const {
return legacyTensorType(*impl_);
}
bool is_contiguous() const {
return impl_->is_contiguous();
}
+
+ // Total bytes consumed by the "view" of elements of the array. Does not
+ // include size of metadata. The number reported here does not necessarily
+ // correspond to the true physical memory consumed by a tensor; instead,
+ // it reports the memory the tensor would take *if* it were contiguous.
+ // Defined to be numel() * itemsize()
+ size_t nbytes() const {
+ return impl_->numel() * impl_->itemsize();
+ }
+
+ // Length of one array element in bytes. This is the traditional
+ // Numpy naming.
+ size_t itemsize() const {
+ return impl_->itemsize();
+ }
+
+ // Same as itemsize(). This is the PyTorch naming.
+ size_t element_size() const {
+ return impl_->itemsize();
+ }
+
Type & type() const {
return legacyTensorType(*impl_);
}
{
HANDLE_TH_ERRORS
auto& self_ = reinterpret_cast<THPVariable*>(self)->cdata;
- size_t element_size = self_.type().elementSizeInBytes();
- return THPUtils_packInt64(element_size);
+ return THPUtils_packInt64(self_.element_size());
END_HANDLE_TH_ERRORS
}