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

Function GetCOOIndexTensorRow

cpp/src/arrow/sparse_tensor.cc:143–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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