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

Function ReadSparseTensor

cpp/src/arrow/ipc/reader.cc:2686–2735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2684namespace {
2685
2686Result<std::shared_ptr<SparseTensor>> ReadSparseTensor(const Buffer& metadata,
2687 io::RandomAccessFile* file) {
2688 std::shared_ptr<DataType> type;
2689 std::vector<int64_t> shape;
2690 std::vector<std::string> dim_names;
2691 int64_t non_zero_length;
2692 SparseTensorFormat::type sparse_tensor_format_id;
2693 const flatbuf::SparseTensor* sparse_tensor;
2694 const flatbuf::Buffer* buffer;
2695
2696 RETURN_NOT_OK(ReadSparseTensorMetadata(metadata, &type, &shape, &dim_names,
2697 &non_zero_length, &sparse_tensor_format_id,
2698 &sparse_tensor, &buffer));
2699
2700 ARROW_ASSIGN_OR_RAISE(auto data, file->ReadAt(buffer->offset(), buffer->length(),
2701 /*allow_short_read=*/false));
2702
2703 std::shared_ptr<SparseIndex> sparse_index;
2704 switch (sparse_tensor_format_id) {
2705 case SparseTensorFormat::COO: {
2706 ARROW_ASSIGN_OR_RAISE(
2707 sparse_index, ReadSparseCOOIndex(sparse_tensor, shape, non_zero_length, file));
2708 return MakeSparseTensorWithSparseCOOIndex(
2709 type, shape, dim_names, checked_pointer_cast<SparseCOOIndex>(sparse_index),
2710 non_zero_length, data);
2711 }
2712 case SparseTensorFormat::CSR: {
2713 ARROW_ASSIGN_OR_RAISE(
2714 sparse_index, ReadSparseCSXIndex(sparse_tensor, shape, non_zero_length, file));
2715 return MakeSparseTensorWithSparseCSRIndex(
2716 type, shape, dim_names, checked_pointer_cast<SparseCSRIndex>(sparse_index),
2717 non_zero_length, data);
2718 }
2719 case SparseTensorFormat::CSC: {
2720 ARROW_ASSIGN_OR_RAISE(
2721 sparse_index, ReadSparseCSXIndex(sparse_tensor, shape, non_zero_length, file));
2722 return MakeSparseTensorWithSparseCSCIndex(
2723 type, shape, dim_names, checked_pointer_cast<SparseCSCIndex>(sparse_index),
2724 non_zero_length, data);
2725 }
2726 case SparseTensorFormat::CSF: {
2727 ARROW_ASSIGN_OR_RAISE(sparse_index, ReadSparseCSFIndex(sparse_tensor, shape, file));
2728 return MakeSparseTensorWithSparseCSFIndex(
2729 type, shape, dim_names, checked_pointer_cast<SparseCSFIndex>(sparse_index),
2730 data);
2731 }
2732 default:
2733 return Status::Invalid("Unsupported sparse index format");
2734 }
2735}
2736
2737} // namespace
2738

Callers 4

TESTFunction · 0.85

Calls 14

ReadSparseTensorMetadataFunction · 0.85
ReadSparseCOOIndexFunction · 0.85
ReadSparseCSXIndexFunction · 0.85
ReadSparseCSFIndexFunction · 0.85
ReadContiguousPayloadFunction · 0.85
ARROW_ASSIGN_OR_RAISEFunction · 0.70
InvalidFunction · 0.50
metadataMethod · 0.45

Tested by 4

TESTFunction · 0.68