| 1242 | } |
| 1243 | |
| 1244 | Status MakeSparseTensor(FBB& fbb, const SparseTensor& sparse_tensor, int64_t body_length, |
| 1245 | const std::vector<BufferMetadata>& buffers, |
| 1246 | SparseTensorOffset* offset) { |
| 1247 | flatbuf::Type fb_type_type; |
| 1248 | Offset fb_type; |
| 1249 | RETURN_NOT_OK( |
| 1250 | TensorTypeToFlatbuffer(fbb, *sparse_tensor.type(), &fb_type_type, &fb_type)); |
| 1251 | |
| 1252 | using TensorDimOffset = flatbuffers::Offset<flatbuf::TensorDim>; |
| 1253 | std::vector<TensorDimOffset> dims; |
| 1254 | for (int i = 0; i < sparse_tensor.ndim(); ++i) { |
| 1255 | FBString name = fbb.CreateString(sparse_tensor.dim_name(i)); |
| 1256 | dims.push_back(flatbuf::CreateTensorDim(fbb, sparse_tensor.shape()[i], name)); |
| 1257 | } |
| 1258 | |
| 1259 | auto fb_shape = fbb.CreateVector(dims); |
| 1260 | |
| 1261 | flatbuf::SparseTensorIndex fb_sparse_index_type; |
| 1262 | Offset fb_sparse_index; |
| 1263 | size_t num_index_buffers = 0; |
| 1264 | RETURN_NOT_OK(MakeSparseTensorIndex(fbb, *sparse_tensor.sparse_index(), buffers, |
| 1265 | &fb_sparse_index_type, &fb_sparse_index, |
| 1266 | &num_index_buffers)); |
| 1267 | |
| 1268 | const BufferMetadata& data_metadata = buffers[num_index_buffers]; |
| 1269 | flatbuf::Buffer data(data_metadata.offset, data_metadata.length); |
| 1270 | |
| 1271 | const int64_t non_zero_length = sparse_tensor.non_zero_length(); |
| 1272 | |
| 1273 | *offset = |
| 1274 | flatbuf::CreateSparseTensor(fbb, fb_type_type, fb_type, fb_shape, non_zero_length, |
| 1275 | fb_sparse_index_type, fb_sparse_index, &data); |
| 1276 | |
| 1277 | return Status::OK(); |
| 1278 | } |
| 1279 | |
| 1280 | } // namespace |
| 1281 |
no test coverage detected