(spm, tag_arr=None, tag_pos=None)
| 30 | |
| 31 | |
| 32 | def check_sort(spm, tag_arr=None, tag_pos=None): |
| 33 | if tag_arr is None: |
| 34 | tag_arr = np.arange(spm.shape[0]) |
| 35 | else: |
| 36 | tag_arr = F.asnumpy(tag_arr) |
| 37 | if tag_pos is not None: |
| 38 | tag_pos = F.asnumpy(tag_pos) |
| 39 | for i in range(spm.shape[0]): |
| 40 | row = spm.getrow(i) |
| 41 | dst = row.nonzero()[1] |
| 42 | if tag_pos is not None: |
| 43 | tag_pos_row = tag_pos[i] |
| 44 | tag_pos_ptr = tag_arr[dst[0]] if len(dst) > 0 else 0 |
| 45 | for j in range(len(dst) - 1): |
| 46 | if tag_pos is not None and tag_arr[dst[j]] != tag_pos_ptr: |
| 47 | # `tag_pos_ptr` is the expected tag value. Here we check whether the |
| 48 | # tag value is equal to `tag_pos_ptr` |
| 49 | return False |
| 50 | if tag_arr[dst[j]] > tag_arr[dst[j + 1]]: |
| 51 | # The tag should be in ascending order after sorting |
| 52 | return False |
| 53 | if tag_pos is not None and tag_arr[dst[j]] < tag_arr[dst[j + 1]]: |
| 54 | if j + 1 != int(tag_pos_row[tag_pos_ptr + 1]): |
| 55 | # The boundary of tag should be consistent with `tag_pos` |
| 56 | return False |
| 57 | tag_pos_ptr = tag_arr[dst[j + 1]] |
| 58 | return True |
| 59 | |
| 60 | |
| 61 | @unittest.skipIf( |
no test coverage detected