| 2485 | } |
| 2486 | |
| 2487 | Status ReadSparseTensorMetadata(const Buffer& metadata, |
| 2488 | std::shared_ptr<DataType>* out_type, |
| 2489 | std::vector<int64_t>* out_shape, |
| 2490 | std::vector<std::string>* out_dim_names, |
| 2491 | int64_t* out_non_zero_length, |
| 2492 | SparseTensorFormat::type* out_format_id, |
| 2493 | const flatbuf::SparseTensor** out_fb_sparse_tensor, |
| 2494 | const flatbuf::Buffer** out_buffer) { |
| 2495 | RETURN_NOT_OK(internal::GetSparseTensorMetadata( |
| 2496 | metadata, out_type, out_shape, out_dim_names, out_non_zero_length, out_format_id)); |
| 2497 | |
| 2498 | const flatbuf::Message* message = nullptr; |
| 2499 | RETURN_NOT_OK(internal::VerifyMessage(metadata.data(), metadata.size(), &message)); |
| 2500 | |
| 2501 | auto sparse_tensor = message->header_as_SparseTensor(); |
| 2502 | if (sparse_tensor == nullptr) { |
| 2503 | return Status::IOError( |
| 2504 | "Header-type of flatbuffer-encoded Message is not SparseTensor."); |
| 2505 | } |
| 2506 | *out_fb_sparse_tensor = sparse_tensor; |
| 2507 | |
| 2508 | auto buffer = sparse_tensor->data(); |
| 2509 | if (!bit_util::IsMultipleOf8(buffer->offset())) { |
| 2510 | return Status::Invalid( |
| 2511 | "Buffer of sparse index data did not start on 8-byte aligned offset: ", |
| 2512 | buffer->offset()); |
| 2513 | } |
| 2514 | *out_buffer = buffer; |
| 2515 | |
| 2516 | return Status::OK(); |
| 2517 | } |
| 2518 | |
| 2519 | } // namespace |
| 2520 |
no test coverage detected