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

Function MakeSparseTensorIndexCSF

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

Source from the content-addressed store, hash-verified

1144}
1145
1146Status MakeSparseTensorIndexCSF(FBB& fbb, const SparseCSFIndex& sparse_index,
1147 const std::vector<BufferMetadata>& buffers,
1148 flatbuf::SparseTensorIndex* fb_sparse_index_type,
1149 Offset* fb_sparse_index, size_t* num_buffers) {
1150 *fb_sparse_index_type =
1151 flatbuf::SparseTensorIndex::SparseTensorIndex_SparseTensorIndexCSF;
1152 const int ndim = static_cast<int>(sparse_index.axis_order().size());
1153
1154 // We assume that the value type of indptr tensor is an integer.
1155 const auto& indptr_value_type =
1156 checked_cast<const IntegerType&>(*sparse_index.indptr()[0]->type());
1157 auto indptr_type_offset = flatbuf::CreateInt(fbb, indptr_value_type.bit_width(),
1158 indptr_value_type.is_signed());
1159
1160 // We assume that the value type of indices tensor is an integer.
1161 const auto& indices_value_type =
1162 checked_cast<const IntegerType&>(*sparse_index.indices()[0]->type());
1163 auto indices_type_offset = flatbuf::CreateInt(fbb, indices_value_type.bit_width(),
1164 indices_value_type.is_signed());
1165
1166 const int64_t indptr_elem_size = indptr_value_type.byte_width();
1167 const int64_t indices_elem_size = indices_value_type.byte_width();
1168
1169 int64_t offset = 0;
1170 std::vector<flatbuf::Buffer> indptr, indices;
1171
1172 for (const std::shared_ptr<arrow::Tensor>& tensor : sparse_index.indptr()) {
1173 const int64_t size = tensor->data()->size() / indptr_elem_size;
1174 const int64_t padded_size = PaddedLength(tensor->data()->size(), kArrowIpcAlignment);
1175
1176 indptr.push_back({offset, size});
1177 offset += padded_size;
1178 }
1179 for (const std::shared_ptr<arrow::Tensor>& tensor : sparse_index.indices()) {
1180 const int64_t size = tensor->data()->size() / indices_elem_size;
1181 const int64_t padded_size = PaddedLength(tensor->data()->size(), kArrowIpcAlignment);
1182
1183 indices.push_back({offset, size});
1184 offset += padded_size;
1185 }
1186
1187 auto fb_indices = fbb.CreateVectorOfStructs(indices);
1188 auto fb_indptr = fbb.CreateVectorOfStructs(indptr);
1189
1190 std::vector<int> axis_order;
1191 for (int i = 0; i < ndim; ++i) {
1192 axis_order.emplace_back(static_cast<int>(sparse_index.axis_order()[i]));
1193 }
1194 auto fb_axis_order =
1195 fbb.CreateVector(arrow::util::MakeNonNull(axis_order.data()), axis_order.size());
1196
1197 *fb_sparse_index =
1198 flatbuf::CreateSparseTensorIndexCSF(fbb, indptr_type_offset, fb_indptr,
1199 indices_type_offset, fb_indices, fb_axis_order)
1200 .Union();
1201 *num_buffers = 2 * ndim - 1;
1202 return Status::OK();
1203}

Callers 1

MakeSparseTensorIndexFunction · 0.85

Calls 15

CreateIntFunction · 0.85
MakeNonNullFunction · 0.85
axis_orderMethod · 0.80
indicesMethod · 0.80
push_backMethod · 0.80
emplace_backMethod · 0.80
PaddedLengthFunction · 0.70
OKFunction · 0.50
sizeMethod · 0.45
typeMethod · 0.45
bit_widthMethod · 0.45

Tested by

no test coverage detected