| 1468 | } |
| 1469 | |
| 1470 | Status 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 | |
| 1504 | Status GetSparseCOOIndexMetadata(const flatbuf::SparseTensorIndexCOO* sparse_index, |
| 1505 | std::shared_ptr<DataType>* indices_type) { |
no test coverage detected