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

Function DetectSparseCOOIndexCanonicality

cpp/src/arrow/sparse_tensor.cc:184–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

182}
183
184bool DetectSparseCOOIndexCanonicality(const std::shared_ptr<Tensor>& coords) {
185 DCHECK_EQ(coords->ndim(), 2);
186
187 const auto& shape = coords->shape();
188 const int64_t non_zero_length = shape[0];
189 if (non_zero_length <= 1) return true;
190
191 const int64_t ndim = shape[1];
192 std::vector<int64_t> last_index, index;
193 GetCOOIndexTensorRow(coords, 0, &last_index);
194 for (int64_t i = 1; i < non_zero_length; ++i) {
195 GetCOOIndexTensorRow(coords, i, &index);
196 int64_t j = 0;
197 while (j < ndim) {
198 if (last_index[j] > index[j]) {
199 // last_index > index, so we can detect non-canonical here
200 return false;
201 }
202 if (last_index[j] < index[j]) {
203 // last_index < index, so we can skip the remaining dimensions
204 break;
205 }
206 ++j;
207 }
208 if (j == ndim) {
209 // last_index == index, so we can detect non-canonical here
210 return false;
211 }
212 swap(last_index, index);
213 }
214
215 return true;
216}
217
218} // namespace
219

Callers 1

MakeMethod · 0.85

Calls 3

GetCOOIndexTensorRowFunction · 0.85
swapFunction · 0.85
shapeMethod · 0.45

Tested by

no test coverage detected