| 1472 | } |
| 1473 | |
| 1474 | Status 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 | |
| 1508 | Status GetSparseCOOIndexMetadata(const flatbuf::SparseTensorIndexCOO* sparse_index, |
| 1509 | std::shared_ptr<DataType>* indices_type) { |
no test coverage detected