MCPcopy Create free account
hub / github.com/apache/arrow / ComputeNumElements

Method ComputeNumElements

cpp/src/arrow/c/dlpack.cc:333–342  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 6

stridesMethod · 0.95
shapeMethod · 0.95
ComputeTensorSizeFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected