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

Function GetCOOIndexTensorRow

cpp/src/arrow/sparse_tensor.cc:144–182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144void GetCOOIndexTensorRow(const std::shared_ptr<Tensor>& coords, const int64_t row,
145 std::vector<int64_t>* out_index) {
146 const auto& fw_index_value_type =
147 internal::checked_cast<const FixedWidthType&>(*coords->type());
148 const size_t indices_elsize = fw_index_value_type.bit_width() / CHAR_BIT;
149
150 const auto& shape = coords->shape();
151 const int64_t non_zero_length = shape[0];
152 DCHECK(0 <= row && row < non_zero_length);
153
154 const int64_t ndim = shape[1];
155 out_index->resize(ndim);
156
157 switch (indices_elsize) {
158 case 1: // Int8, UInt8
159 for (int64_t i = 0; i < ndim; ++i) {
160 (*out_index)[i] = static_cast<int64_t>(coords->Value<UInt8Type>({row, i}));
161 }
162 break;
163 case 2: // Int16, UInt16
164 for (int64_t i = 0; i < ndim; ++i) {
165 (*out_index)[i] = static_cast<int64_t>(coords->Value<UInt16Type>({row, i}));
166 }
167 break;
168 case 4: // Int32, UInt32
169 for (int64_t i = 0; i < ndim; ++i) {
170 (*out_index)[i] = static_cast<int64_t>(coords->Value<UInt32Type>({row, i}));
171 }
172 break;
173 case 8: // Int64
174 for (int64_t i = 0; i < ndim; ++i) {
175 (*out_index)[i] = coords->Value<Int64Type>({row, i});
176 }
177 break;
178 default:
179 DCHECK(false) << "Must not reach here";
180 break;
181 }
182}
183
184bool DetectSparseCOOIndexCanonicality(const std::shared_ptr<Tensor>& coords) {
185 DCHECK_EQ(coords->ndim(), 2);

Callers 1

Calls 4

resizeMethod · 0.80
typeMethod · 0.45
bit_widthMethod · 0.45
shapeMethod · 0.45

Tested by

no test coverage detected