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

Function GetTensorMetadata

cpp/src/arrow/ipc/metadata_internal.cc:1470–1502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1468}
1469
1470Status GetTensorMetadata(const Buffer& metadata, std::shared_ptr<DataType>* type,
1471 std::vector<int64_t>* shape, std::vector<int64_t>* strides,
1472 std::vector<std::string>* dim_names) {
1473 const flatbuf::Message* message = nullptr;
1474 RETURN_NOT_OK(internal::VerifyMessage(metadata.data(), metadata.size(), &message));
1475 auto tensor = message->header_as_Tensor();
1476 if (tensor == nullptr) {
1477 return Status::IOError("Header-type of flatbuffer-encoded Message is not Tensor.");
1478 }
1479
1480 flatbuffers::uoffset_t ndim = tensor->shape()->size();
1481
1482 for (flatbuffers::uoffset_t i = 0; i < ndim; ++i) {
1483 auto dim = tensor->shape()->Get(i);
1484
1485 shape->push_back(dim->size());
1486 dim_names->push_back(StringFromFlatbuffers(dim->name()));
1487 }
1488
1489 if (tensor->strides() && tensor->strides()->size() > 0) {
1490 if (tensor->strides()->size() != ndim) {
1491 return Status::IOError(
1492 "The sizes of shape and strides in a tensor are mismatched.");
1493 }
1494
1495 for (decltype(ndim) i = 0; i < ndim; ++i) {
1496 strides->push_back(tensor->strides()->Get(i));
1497 }
1498 }
1499
1500 auto type_data = tensor->type(); // Required
1501 return ConcreteTypeFromFlatbuffer(tensor->type_type(), type_data, {}, type);
1502}
1503
1504Status GetSparseCOOIndexMetadata(const flatbuf::SparseTensorIndexCOO* sparse_index,
1505 std::shared_ptr<DataType>* indices_type) {

Callers 1

ReadTensorFunction · 0.85

Calls 13

VerifyMessageFunction · 0.85
IOErrorFunction · 0.85
StringFromFlatbuffersFunction · 0.85
push_backMethod · 0.80
stridesMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
shapeMethod · 0.45
GetMethod · 0.45
nameMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected