def test_argsort(): for n in [2, 4, 8, 16, 32, 64, 128]: matrices = bitonic_matrices(n) for i in range(5): for dtype in [np.float32, np.float64]: for r in [10, 200, 250]: vec = np.random.uniform(-r, r, n).astype(dtype) for sigma in [1e-1, 1, 10]: for max_fn in maxes: argsorted = diff_argsort(matrices, vec, sigma, softmax=max_fn) argsorted = diff_argsort(matrices, vec, sigma, softmax=max_fn, transpose=True) assert np.all(argsorted >= 0)
def test_ranking(): for n in [2, 4, 8, 16, 32, 64, 128, 256, 512]: woven = bitonic_woven_matrices(n) indices = bitonic_indices(n) matrices = bitonic_matrices(n) for i in range(20): # test ranking test = np.random.randint(-200, 200, n) true_rank = rankdata(test) dargsort = diff_argsort(matrices, test, sigma=0.001, softmax=np.maximum) assert np.allclose(true_rank - 1, dargsort)