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

Function GetTensorMetadata

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

Source from the content-addressed store, hash-verified

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