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

Function MakeCSFSparseTensorMessage

cpp/src/arrow/ipc/tensor_test.cc:531–573  ·  view source on GitHub ↗

Build a SparseTensor IPC message carrying a CSF index with caller-controlled buffer counts. This lets us exercise the reader's validation directly, since such inconsistent indices can only be produced by hand-crafted flatbuffers.

Source from the content-addressed store, hash-verified

529// buffer counts. This lets us exercise the reader's validation directly, since
530// such inconsistent indices can only be produced by hand-crafted flatbuffers.
531Result<std::shared_ptr<Message>> MakeCSFSparseTensorMessage(
532 const std::vector<int64_t>& shape, int num_indptr_buffers, int num_indices_buffers,
533 int axis_order_size, int64_t non_zero_length = 0) {
534 flatbuffers::FlatBufferBuilder fbb;
535
536 auto value_type = flatbuf::CreateInt(fbb, 64, /*is_signed=*/true);
537
538 std::vector<flatbuffers::Offset<flatbuf::TensorDim>> dims;
539 for (int64_t dim_size : shape) {
540 dims.push_back(flatbuf::CreateTensorDim(fbb, dim_size, /*name=*/0));
541 }
542 auto fb_shape = fbb.CreateVector(dims);
543
544 auto indptr_type = flatbuf::CreateInt(fbb, 64, /*is_signed=*/false);
545 auto indices_type = flatbuf::CreateInt(fbb, 64, /*is_signed=*/false);
546
547 std::vector<flatbuf::Buffer> indptr(num_indptr_buffers, flatbuf::Buffer(0, 0));
548 std::vector<flatbuf::Buffer> indices(num_indices_buffers, flatbuf::Buffer(0, 0));
549 auto fb_indptr = fbb.CreateVectorOfStructs(indptr);
550 auto fb_indices = fbb.CreateVectorOfStructs(indices);
551
552 std::vector<int32_t> axis_order(axis_order_size, 0);
553 auto fb_axis_order = fbb.CreateVector(axis_order);
554
555 auto csf = flatbuf::CreateSparseTensorIndexCSF(fbb, indptr_type, fb_indptr,
556 indices_type, fb_indices, fb_axis_order);
557
558 flatbuf::Buffer data(0, 0);
559 auto sparse_tensor = flatbuf::CreateSparseTensor(
560 fbb, flatbuf::Type_Int, value_type.Union(), fb_shape, non_zero_length,
561 flatbuf::SparseTensorIndex::SparseTensorIndex_SparseTensorIndexCSF, csf.Union(),
562 &data);
563
564 fbb.Finish(flatbuf::CreateMessage(fbb, internal::kCurrentMetadataVersion,
565 flatbuf::MessageHeader::MessageHeader_SparseTensor,
566 sparse_tensor.Union(),
567 /*bodyLength=*/0));
568
569 ARROW_ASSIGN_OR_RAISE(auto metadata, internal::WriteFlatbufferBuilder(fbb));
570 auto body = Buffer::FromString(std::string(8, '\0'));
571 ARROW_ASSIGN_OR_RAISE(auto message, Message::Open(metadata, body));
572 return std::shared_ptr<Message>(std::move(message));
573}
574
575IpcPayload MakeSparseTensorPayload(const std::shared_ptr<Message>& message,
576 int num_body_buffers) {

Callers 1

TESTFunction · 0.85

Calls 9

CreateIntFunction · 0.85
CreateTensorDimFunction · 0.85
CreateSparseTensorFunction · 0.85
CreateMessageFunction · 0.85
FromStringFunction · 0.85
push_backMethod · 0.80
BufferClass · 0.50
FinishMethod · 0.45

Tested by

no test coverage detected