Internal function to create groups on the values. Parameters ---------- val : Tensor Value tensor. Returns ------- unique_val : Tensor Unique values. bucketor : callable[Tensor -> list[Tensor]] A bucketing function that splits the given tensor da
(val)
| 175 | |
| 176 | |
| 177 | def _bucketing(val): |
| 178 | """Internal function to create groups on the values. |
| 179 | |
| 180 | Parameters |
| 181 | ---------- |
| 182 | val : Tensor |
| 183 | Value tensor. |
| 184 | |
| 185 | Returns |
| 186 | ------- |
| 187 | unique_val : Tensor |
| 188 | Unique values. |
| 189 | bucketor : callable[Tensor -> list[Tensor]] |
| 190 | A bucketing function that splits the given tensor data as the same |
| 191 | way of how the :attr:`val` tensor is grouped. |
| 192 | """ |
| 193 | sorted_val, idx = F.sort_1d(val) |
| 194 | unique_val = F.asnumpy(F.unique(sorted_val)) |
| 195 | bkt_idx = [] |
| 196 | for v in unique_val: |
| 197 | eqidx = F.nonzero_1d(F.equal(sorted_val, v)) |
| 198 | bkt_idx.append(F.gather_row(idx, eqidx)) |
| 199 | |
| 200 | def bucketor(data): |
| 201 | bkts = [F.gather_row(data, idx) for idx in bkt_idx] |
| 202 | return bkts |
| 203 | |
| 204 | return unique_val, bucketor |
| 205 | |
| 206 | |
| 207 | def data_dict_to_list(graph, data_dict, func, target): |
no test coverage detected