Number of element in this tensor's buffer. Possibly more elements than represented in the tensor for non-contiguous tensors. A zero dimensional tensor is a scalar, it holds a single element.
| 331 | /// |
| 332 | /// A zero dimensional tensor is a scalar, it holds a single element. |
| 333 | Result<int64_t> ComputeNumElements() const { |
| 334 | const auto strides = this->strides(); |
| 335 | const auto shape = this->shape(); |
| 336 | if (strides.size() > 0) { |
| 337 | // DLPack strides are in number of elements, so is the size we compute from them. |
| 338 | return internal::ComputeTensorSize(shape, strides, 1); |
| 339 | } |
| 340 | // DLPack <1.3 may set strides == nullptr for row major |
| 341 | return std::reduce(shape.begin(), shape.end(), int64_t{1}, std::multiplies{}); |
| 342 | } |
| 343 | |
| 344 | /// Number of bytes needed to store this tensor data. |
| 345 | Result<int64_t> ComputeNumBytes() const { |