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

Function ReadSparseCOOIndex

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

Source from the content-addressed store, hash-verified

2282namespace {
2283
2284Result<std::shared_ptr<SparseIndex>> ReadSparseCOOIndex(
2285 const flatbuf::SparseTensor* sparse_tensor, const std::vector<int64_t>& shape,
2286 int64_t non_zero_length, io::RandomAccessFile* file) {
2287 auto* sparse_index = sparse_tensor->sparseIndex_as_SparseTensorIndexCOO();
2288 const auto ndim = static_cast<int64_t>(shape.size());
2289
2290 std::shared_ptr<DataType> indices_type;
2291 RETURN_NOT_OK(internal::GetSparseCOOIndexMetadata(sparse_index, &indices_type));
2292 const int64_t indices_elsize = indices_type->byte_width();
2293
2294 auto* indices_buffer = sparse_index->indicesBuffer();
2295 ARROW_ASSIGN_OR_RAISE(auto indices_data,
2296 file->ReadAt(indices_buffer->offset(), indices_buffer->length()));
2297 std::vector<int64_t> indices_shape({non_zero_length, ndim});
2298 auto* indices_strides = sparse_index->indicesStrides();
2299 std::vector<int64_t> strides(2);
2300 if (indices_strides && indices_strides->size() > 0) {
2301 if (indices_strides->size() != 2) {
2302 return Status::Invalid("Wrong size for indicesStrides in SparseCOOIndex");
2303 }
2304 strides[0] = indices_strides->Get(0);
2305 strides[1] = indices_strides->Get(1);
2306 } else {
2307 // Row-major by default
2308 strides[0] = indices_elsize * ndim;
2309 strides[1] = indices_elsize;
2310 }
2311 return SparseCOOIndex::Make(
2312 std::make_shared<Tensor>(indices_type, indices_data, indices_shape, strides),
2313 sparse_index->isCanonical());
2314}
2315
2316Result<std::shared_ptr<SparseIndex>> ReadSparseCSXIndex(
2317 const flatbuf::SparseTensor* sparse_tensor, const std::vector<int64_t>& shape,

Callers 1

ReadSparseTensorFunction · 0.85

Calls 6

InvalidFunction · 0.50
MakeFunction · 0.50
sizeMethod · 0.45
byte_widthMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected