{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/fast-differentiable-sorting-and-ranking","title":"Fast Differentiable Sorting and Ranking","arxiv_id":"2002.08871","date":"2020-02-20","proceeding":"ICML 2020 1","authors":["Mathieu Blondel","Olivier Teboul","Quentin Berthet","Josip Djolonga"],"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.","url_abs":"https://arxiv.org/abs/2002.08871v2","url_pdf":"https://arxiv.org/pdf/2002.08871v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"fast-differentiable-sorting-and-ranking","repo_url":"https://github.com/google-research/fast-soft-sort","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"fast-differentiable-sorting-and-ranking","repo_url":"https://github.com/teddykoker/torchsort","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2002.08871","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2002.08871"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/google-research/fast-soft-sort","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/teddykoker/torchsort","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran":3,"ran_honours":1,"ran_fixture":1,"ran_draft_wrong":2,"unverified":8},"by_repo_kind":{"official":{"samples":13,"ran":7,"repositories":1},"listed":{"samples":2,"ran":0,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"afe332ef67915484","entry":"Isotonic","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/numpy_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/numpy_ops.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"afe332ef67915484"}},{"code_sha256_prefix":"c4e8dcedf8134f96","entry":"SoftSort","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/numpy_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/numpy_ops.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"c4e8dcedf8134f96"}},{"code_sha256_prefix":"f23527cd314b4641","entry":"_Differentiable","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/numpy_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/numpy_ops.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"f23527cd314b4641"}},{"code_sha256_prefix":"63fe5c519624e525","entry":"_inv_permutation","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/numpy_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/numpy_ops.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"63fe5c519624e525"}},{"code_sha256_prefix":"9f5283dc2f8b3bd0","entry":"_partition","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/numpy_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/numpy_ops.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"9f5283dc2f8b3bd0"}},{"code_sha256_prefix":"c9f5b5643ef43ef6","entry":"map_tensor","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/pytorch_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/pytorch_ops.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"c9f5b5643ef43ef6"}},{"code_sha256_prefix":"eac501ec140619f8","entry":"wrap_class","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/pytorch_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/pytorch_ops.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"eac501ec140619f8"}},{"code_sha256_prefix":"8428875d00312046","entry":"_check_direction","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/numpy_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/numpy_ops.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"8428875d00312046"}},{"code_sha256_prefix":"1abdfc51c62a6d27","entry":"_check_regularization","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/numpy_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/numpy_ops.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"1abdfc51c62a6d27"}},{"code_sha256_prefix":"4788d9bb11e3b0a3","entry":"isotonic_kl","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/numpy_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/numpy_ops.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"4788d9bb11e3b0a3"}},{"code_sha256_prefix":"0b9197731988385c","entry":"isotonic_l2","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/numpy_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/numpy_ops.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"0b9197731988385c"}},{"code_sha256_prefix":"b554ca732af18086","entry":"soft_rank","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/jax_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/jax_ops.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b554ca732af18086"}},{"code_sha256_prefix":"36350a3010919e3e","entry":"soft_sort","repo":"google-research/fast-soft-sort","repo_kind":"official","path":"fast_soft_sort/jax_ops.py","file_url":"https://github.com/google-research/fast-soft-sort/blob/HEAD/fast_soft_sort/jax_ops.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"36350a3010919e3e"}},{"code_sha256_prefix":"1010655db99be008","entry":"style","repo":"teddykoker/torchsort","repo_kind":"listed","path":"extra/benchmark.py","file_url":"https://github.com/teddykoker/torchsort/blob/HEAD/extra/benchmark.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"1010655db99be008"}},{"code_sha256_prefix":"1ec707cfefa8b286","entry":"time","repo":"teddykoker/torchsort","repo_kind":"listed","path":"extra/benchmark.py","file_url":"https://github.com/teddykoker/torchsort/blob/HEAD/extra/benchmark.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"1ec707cfefa8b286"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}