| 2429 | } |
| 2430 | |
| 2431 | Status ReadSparseTensorMetadata(const Buffer& metadata, |
| 2432 | std::shared_ptr<DataType>* out_type, |
| 2433 | std::vector<int64_t>* out_shape, |
| 2434 | std::vector<std::string>* out_dim_names, |
| 2435 | int64_t* out_non_zero_length, |
| 2436 | SparseTensorFormat::type* out_format_id, |
| 2437 | const flatbuf::SparseTensor** out_fb_sparse_tensor, |
| 2438 | const flatbuf::Buffer** out_buffer) { |
| 2439 | RETURN_NOT_OK(internal::GetSparseTensorMetadata( |
| 2440 | metadata, out_type, out_shape, out_dim_names, out_non_zero_length, out_format_id)); |
| 2441 | |
| 2442 | const flatbuf::Message* message = nullptr; |
| 2443 | RETURN_NOT_OK(internal::VerifyMessage(metadata.data(), metadata.size(), &message)); |
| 2444 | |
| 2445 | auto sparse_tensor = message->header_as_SparseTensor(); |
| 2446 | if (sparse_tensor == nullptr) { |
| 2447 | return Status::IOError( |
| 2448 | "Header-type of flatbuffer-encoded Message is not SparseTensor."); |
| 2449 | } |
| 2450 | *out_fb_sparse_tensor = sparse_tensor; |
| 2451 | |
| 2452 | auto buffer = sparse_tensor->data(); |
| 2453 | if (!bit_util::IsMultipleOf8(buffer->offset())) { |
| 2454 | return Status::Invalid( |
| 2455 | "Buffer of sparse index data did not start on 8-byte aligned offset: ", |
| 2456 | buffer->offset()); |
| 2457 | } |
| 2458 | *out_buffer = buffer; |
| 2459 | |
| 2460 | return Status::OK(); |
| 2461 | } |
| 2462 | |
| 2463 | } // namespace |
| 2464 |
no test coverage detected