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

Function ReadSparseCSFIndex

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

Source from the content-addressed store, hash-verified

2422}
2423
2424Result<std::shared_ptr<SparseIndex>> ReadSparseCSFIndex(
2425 const flatbuf::SparseTensor* sparse_tensor, const std::vector<int64_t>& shape,
2426 io::RandomAccessFile* file) {
2427 auto* sparse_index = sparse_tensor->sparseIndex_as_SparseTensorIndexCSF();
2428 const auto ndim = static_cast<int64_t>(shape.size());
2429 RETURN_NOT_OK(ValidateSparseCSFIndexMetadata(sparse_index, ndim));
2430 auto* indptr_buffers = sparse_index->indptrBuffers();
2431 auto* indices_buffers = sparse_index->indicesBuffers();
2432 std::vector<std::shared_ptr<Buffer>> indptr_data(ndim - 1);
2433 std::vector<std::shared_ptr<Buffer>> indices_data(ndim);
2434
2435 std::shared_ptr<DataType> indptr_type, indices_type;
2436 std::vector<int64_t> axis_order, indices_size;
2437
2438 RETURN_NOT_OK(internal::GetSparseCSFIndexMetadata(
2439 sparse_index, &axis_order, &indices_size, &indptr_type, &indices_type));
2440 for (int i = 0; i < static_cast<int>(indptr_buffers->size()); ++i) {
2441 ARROW_ASSIGN_OR_RAISE(indptr_data[i], file->ReadAt(indptr_buffers->Get(i)->offset(),
2442 indptr_buffers->Get(i)->length(),
2443 /*allow_short_read=*/false));
2444 }
2445 for (int i = 0; i < static_cast<int>(indices_buffers->size()); ++i) {
2446 ARROW_ASSIGN_OR_RAISE(indices_data[i], file->ReadAt(indices_buffers->Get(i)->offset(),
2447 indices_buffers->Get(i)->length(),
2448 /*allow_short_read=*/false));
2449 }
2450
2451 return SparseCSFIndex::Make(indptr_type, indices_type, indices_size, axis_order,
2452 indptr_data, indices_data);
2453}
2454
2455Result<std::shared_ptr<SparseTensor>> MakeSparseTensorWithSparseCOOIndex(
2456 const std::shared_ptr<DataType>& type, const std::vector<int64_t>& shape,

Callers 1

ReadSparseTensorFunction · 0.85

Calls 9

ARROW_ASSIGN_OR_RAISEFunction · 0.70
MakeFunction · 0.50
sizeMethod · 0.45
ReadAtMethod · 0.45
offsetMethod · 0.45
GetMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected