SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2002.08871 · ICML · 2020

Fast Differentiable Sorting and Ranking

Mathieu Blondel, Olivier Teboul, Quentin Berthet, Josip Djolonga

arXiv · PDF · Open in the Atlas

Code that ran

9 of 15 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (3 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 5 have no contract verdict; 3 failures of our instrument; 6 no recorded run), measured 2026-11-21; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2002.08871.json · badge: /api/ran/2002.08871.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
google-research/fast-soft-sort canonical (classifier label)
classifier basis: classifier_2025
7 ran · 6 no recorded run
teddykoker/torchsort community (classifier label)
classifier basis not recorded on the link
2 ran · 0 no recorded run
FunctionStatusWhere it lives
Isotonic Ran
ran on a synthesized input · constructed an object; no result was computed
google-research/fast-soft-sort/fast_soft_sort/numpy_ops.py
code served (permissive licence) · get_code("afe332ef67915484")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Isotonic: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# Create small test arrays for isotonic optimization
input_s = np.array([3.0, 1.0, 4.0, 1.0], dtype=np.float64)
input_w = np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float64)

ARGS = {
    'input_s': input_s,
    'input_w': input_w,
    'regularization': 'l2'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Isotonic — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Isotonic output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
SoftSort Ran
ran on a synthesized input · constructed an object; no result was computed
google-research/fast-soft-sort/fast_soft_sort/numpy_ops.py
code served (permissive licence) · get_code("c4e8dcedf8134f96")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, SoftSort: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
from scipy import special

# Set up the arguments for SoftSort.__init__
# The function takes: values, direction, regularization_strength, regularization

# Create a small 1D array of values for isotonic optimization
values = np.array([3.2, 1.5, 4.1, 2.8], dtype=np.float64)

# Direction parameter - must be 'ASCENDING' or 'DESCENDING'
direction = 'ASCENDING'

# Regularization strength - a positive float
regularization_strength = 1.0

# Regularization type - must be 'l2' or 'kl'
regularization = 'l2'

ARGS = {
    'values': values,
    'direction': direction,
    'regularization_strength': regularization_strength,
    'regularization': regularization,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, scipy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type SoftSort — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a SoftSort output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
_Differentiable Ran
ran on a synthesized input · constructed an object; no result was computed
google-research/fast-soft-sort/fast_soft_sort/numpy_ops.py
code served (permissive licence) · get_code("f23527cd314b4641")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, _Differentiable: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

class ConcreteImplementation(object):
    """Concrete implementation of _Differentiable for testing."""
    
    def __init__(self, size_val):
        self._size = size_val
    
    @property
    def size(self):
        return self._size
    
    def compute(self):
        """Returns a simple vector of the appropriate size."""
        return np.ones(self._size)
    
    def jvp(self, vector):
        """Jacobian vector product - simple linear operation."""
        # For a simple linear map, jvp just scales the vector
        return vector * 2.0
    
    def vjp(self, vector):
        """Vector Jacobian product - transpose of jvp."""
        return vector * 2.0


# Create a concrete instance with a specific size
concrete_instance = ConcreteImplementation(size_val=4)

ARGS = {}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type _Differentiable — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a _Differentiable output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
_inv_permutation Ran
ran, honoured the contract we drafted
google-research/fast-soft-sort/fast_soft_sort/numpy_ops.py
code served (permissive licence) · get_code("63fe5c519624e525")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 1, dtype family int, shape (4,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np

# The function _inv_permutation takes a permutation array and returns its inverse.
# It expects:
# - permutation: a 1D numpy array of integers representing a permutation

# Create a valid permutation array
# A permutation is an array where each integer from 0 to n-1 appears exactly once
permutation = np.array([2, 0, 3, 1], dtype=int)

ARGS = {
    "permutation": permutation
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 1, dtype family int, shape (4,) — shape (4,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
_partition Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
google-research/fast-soft-sort/fast_soft_sort/numpy_ops.py
code served (permissive licence) · get_code("9f5283dc2f8b3bd0")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family int; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

# Analyze the function _partition:
# - It takes 'solution' as the main parameter (checked with len())
# - It iterates through solution comparing consecutive elements
# - It uses abs() for comparison and an epsilon threshold
# - Returns a list of partition sizes
# - solution should be a sequence (list or array-like)

# Create a valid solution - a sequence of numbers where some are close together
# and some are far apart to create distinct partitions
solution = [1.0, 1.0, 1.5, 1.6, 5.0, 5.0, 5.1]

eps = 1e-09

ARGS = {
    "solution": solution,
    "eps": eps
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family int — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
map_tensor Ran
ran; our contract draft was wrong, not the code
google-research/fast-soft-sort/fast_soft_sort/pytorch_ops.py
code served (permissive licence) · get_code("c9f5b5643ef43ef6")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 2, dtype family float, shape (2, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Define a simple map function that operates on individual tensors
def simple_map_fn(tensor_i):
    return tensor_i * 2

# Create a small tensor with shape (2, 4) - batch size 2, dimension 4
tensor = torch.randn(2, 4)

# Construct the ARGS dictionary
ARGS = {
    "map_fn": simple_map_fn,
    "tensor": tensor,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
style Ran
ran on a synthesized input
teddykoker/torchsort/extra/benchmark.py
code served (permissive licence) · get_code("1010655db99be008")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned dict. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# The function 'style' takes a single parameter 'name' which is a string
# It checks the string against various patterns and returns a dictionary
# with styling information based on the pattern matches

ARGS = {
    'name': 'torch.sort'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
time Ran
ran on a synthesized input
teddykoker/torchsort/extra/benchmark.py
code served (permissive licence) · get_code("1ec707cfefa8b286")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned float, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from timeit import timeit

torch.manual_seed(0)

SAMPLES = 100
CONVERT = 1e-06

def time(f):
    return timeit(f, number=SAMPLES) / SAMPLES / CONVERT

# Create a simple callable function to time
def simple_function():
    x = torch.randn(2, 4)
    y = x.sum()
    return y

ARGS = {
    'f': simple_function
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
wrap_class Ran
ran; our contract draft was wrong, not the code
google-research/fast-soft-sort/fast_soft_sort/pytorch_ops.py
code served (permissive licence) · get_code("eac501ec140619f8")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned FunctionMeta. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import numpy as np

torch.manual_seed(0)

class NumpyOp:
    """A minimal NumpyOp class that implements compute() and vjp() methods."""
    
    def __init__(self, values, scale=1.0):
        self.values = values
        self.scale = scale
    
    def compute(self):
        """Returns a numpy array result."""
        return self.values * self.scale
    
    def vjp(self, grad_output):
        """Vector-Jacobian product: returns gradient as numpy array."""
        return grad_output * self.scale

ARGS = {
    "cls": NumpyOp,
    "kwargs": {"scale": 2.0}
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type FunctionMeta — a FunctionMeta output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a FunctionMeta output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
_check_direction Not yet run
unverified (harvested, no recorded run)
google-research/fast-soft-sort/fast_soft_sort/numpy_ops.py
code served (permissive licence) · get_code("8428875d00312046")
How it ran

no invocation recorded.

_check_regularization Not yet run
unverified (harvested, no recorded run)
google-research/fast-soft-sort/fast_soft_sort/numpy_ops.py
code served (permissive licence) · get_code("1abdfc51c62a6d27")
How it ran

no invocation recorded.

isotonic_kl Not yet run
unverified (harvested, no recorded run)
google-research/fast-soft-sort/fast_soft_sort/numpy_ops.py
code served (permissive licence) · get_code("4788d9bb11e3b0a3")
How it ran

no invocation recorded.

isotonic_l2 Not yet run
unverified (harvested, no recorded run)
google-research/fast-soft-sort/fast_soft_sort/numpy_ops.py
code served (permissive licence) · get_code("0b9197731988385c")
How it ran

no invocation recorded.

soft_rank Not yet run
unverified (harvested, no recorded run)
google-research/fast-soft-sort/fast_soft_sort/jax_ops.py
code served (permissive licence) · get_code("b554ca732af18086")
How it ran

no invocation recorded.

soft_sort Not yet run
unverified (harvested, no recorded run)
google-research/fast-soft-sort/fast_soft_sort/jax_ops.py
code served (permissive licence) · get_code("36350a3010919e3e")
How it ran

no invocation recorded.

Also present in other papers' code

Of 15 samples lifted from this paper's linked repositories, 15 carry a function identity and 0 do not. Of the 15 distinct functions with an identity, 2 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 2 later) and 13 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
map_tensor 1 other paper
1 later
2306.02738 (2023-06)
A Large-Scale Study of Probabilistic Calibration in Neural Network Regression
wrap_class 1 other paper
1 later
2306.02738 (2023-06)
A Large-Scale Study of Probabilistic Calibration in Neural Network Regression

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-21.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

The sorting operation is one of the most commonly used building blocks in computer programming. In machine learning, it is often used for robust statistics. However, seen as a function, it is piecewise linear and as a result includes many kinks where it is non-differentiable. More problematic is the related ranking operator, often used for order statistics and ranking metrics. It is a piecewise constant function, meaning that its derivatives are null or undefined. While numerous works have proposed differentiable proxies to sorting and ranking, they do not achieve the O(n log n) time complexity one would expect from sorting and ranking operations. In this paper, we propose the first differentiable sorting and ranking operators with O(n log n) time and O(n) space complexity. Our proposal in addition enjoys exact computation and differentiation. We achieve this feat by constructing differentiable operators as projections onto the permutahedron, the convex hull of permutations, and using a reduction to isotonic optimization. Empirically, we confirm that our approach is an order of magnitude faster than existing approaches and showcase two novel applications: differentiable Spearman's rank correlation coefficient and least trimmed squares.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2002.08871")
get_code_for_paper("2002.08871")
have("2002.08871")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2002.08871.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2002.08871.svg)](https://syntology.ai/paper/2002.08871)

Connect an agent — have() is free.