# Generated by tools/algo/legacy.py from the corpus: do not edit. # lib/hf's eigenvalue sort: a selection sort that moves each eigenvector with its value. # Element comparisons are routed through lib/algo/legacy/order.viv; nothing else changes. from algo.legacy.order import lg_lt # from lib/hf/eigen.viv: eig_sort #| Sort the eigenvalues in `d` ascending, moving the columns of `V` with them. #| Selection sort: n is at most a few dozen, and a stable, simple order is #| what makes the members comparable. def eig_sort(d: Arr, V: Arr, n) { for i to n - 1 { k = i p = d[i] for j to n { if j > i and lg_lt(d[j], p) { k = j p = d[j] } } if k != i { d[k] = d[i] d[i] = p t = V[:, i] V[:, i] = V[:, k] V[:, k] = t } } return 0 }