MCPcopy Create free account
hub / github.com/apache/arrow / MakeSparseTensor

Function MakeSparseTensor

cpp/src/arrow/ipc/metadata_internal.cc:1245–1279  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

WriteSparseTensorMessageFunction · 0.85

Calls 10

TensorTypeToFlatbufferFunction · 0.85
CreateTensorDimFunction · 0.85
MakeSparseTensorIndexFunction · 0.85
CreateSparseTensorFunction · 0.85
push_backMethod · 0.80
sparse_indexMethod · 0.80
OKFunction · 0.50
typeMethod · 0.45
shapeMethod · 0.45
non_zero_lengthMethod · 0.45

Tested by

no test coverage detected