Skip to main content

Build Status PyPI

Linear Assignment Problem solver using Jonker-Volgenant algorithm

This project is the rewrite of pyLAPJV which supports Python 3 and updates the core code. The performance is twice as high as the original thanks to the optimization of the augmenting row reduction phase using Intel AVX2 intrinsics. It is a native Python 3 module and does not work with Python 2.x, stick to pyLAPJV otherwise.

Blog post

Linear assignment problem is the bijection between two sets with equal cardinality which optimizes the sum of the individual mapping costs taken from the fixed cost matrix. It naturally arises e.g. when we want to fit t-SNE results into a rectangular regular grid. See this awesome notebook for the details about why LAP matters: CloudToGrid.

Jonker-Volgenant algorithm is described in the paper:

R. Jonker and A. Volgenant, "A Shortest Augmenting Path Algorithm for Dense and Sparse Linear Assignment Problems," Computing, vol. 38, pp. 325-340, 1987.

This paper is not publicly available though a brief description exists on sciencedirect.com. JV is faster in than the Hungarian algorithm in practice, though the complexity is the same - O(n3).

The C++ source of the algorithm comes from http://www.magiclogic.com/assignment.html It has been reworked and partially optimized with OpenMP 4.0 SIMD.

Installing

pip3 install lapjv

Tested on Linux and Windows. macOS is not supported, please do not report macOS build errors in the issues. Feel free to PR macOS support, but I warn that it will be a rough ride.

Usage

Refer to test.py for the complete code.

from lapjv import lapjv
row_ind, col_ind, _ = lapjv(cost_matrix)

The assignment matrix by row is row_ind: the value at n-th place is the assigned column index to the n-th row. col_ind is the reverse of row_ind: mapping from columns to row indexes.

Note: a bijection is only possible for sets with equal cardinality. If you need to map A vectors to B vectors, derive the square symmetric (A+B) x (A+B) matrix: take the first A rows and columns from A and the remaining [A..A+B] rows and columns from B. Set the A->A and B->B costs to some maximum distance value, big enough so that you don't see assignment errors.

Illegal instruction

This error appears if your CPU does not support the AVX2 instruction set. We do not ship builds for different CPUs so you need to build the package yourself:

pip3 install git+https://github.com/src-d/lapjv

NAN-s

NAN-s in the cost matrix lead to completely undefined result. It is the caller's responsibility to check them.

License

MIT Licensed,see LICENSE

Metadata

Release files for lapjv-numpy2 1.3.26

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lapjv-numpy2 1.3.26
File Size Uploaded Provenance Actions
lapjv_numpy2-1.3.26.tar.gz 11.1 kB Without provenance Details for lapjv_numpy2-1.3.26.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for lapjv-numpy2 1.3.26
File Actions
lapjv_numpy2-1.3.26-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for lapjv_numpy2-1.3.26-cp311-cp311-win_amd64.whl
lapjv_numpy2-1.3.26-cp311-cp311-musllinux_1_1_x86_64.whl CPython 3.11 CPython 3.11 Linux musl 1.1+ x86-64 Details for lapjv_numpy2-1.3.26-cp311-cp311-musllinux_1_1_x86_64.whl
lapjv_numpy2-1.3.26-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for lapjv_numpy2-1.3.26-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
lapjv_numpy2-1.3.26-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for lapjv_numpy2-1.3.26-cp310-cp310-win_amd64.whl
lapjv_numpy2-1.3.26-cp310-cp310-musllinux_1_1_x86_64.whl CPython 3.10 CPython 3.10 Linux musl 1.1+ x86-64 Details for lapjv_numpy2-1.3.26-cp310-cp310-musllinux_1_1_x86_64.whl
lapjv_numpy2-1.3.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details for lapjv_numpy2-1.3.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
lapjv_numpy2-1.3.26-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details for lapjv_numpy2-1.3.26-cp39-cp39-win_amd64.whl
lapjv_numpy2-1.3.26-cp39-cp39-musllinux_1_1_x86_64.whl CPython 3.9 CPython 3.9 Linux musl 1.1+ x86-64 Details for lapjv_numpy2-1.3.26-cp39-cp39-musllinux_1_1_x86_64.whl
lapjv_numpy2-1.3.26-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details for lapjv_numpy2-1.3.26-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Total release size: 2.8 MB

Release files / lapjv_numpy2-1.3.26.tar.gz

Download URL lapjv_numpy2-1.3.26.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9a5cc36bbcd365678b660940a169ccb8ee660cffeda49b0de479bb0eda7aa5c6
BLAKE2b-256 checksum
How to use checksums
7aa611c7472936b3d0dda0c53518c5350acfff518a97b1f3e12ac1e5bf04a795
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / lapjv_numpy2-1.3.26-cp311-cp311-win_amd64.whl

Download URL lapjv_numpy2-1.3.26-cp311-cp311-win_amd64.whl
Size 27.9 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
acd32fc7ea8285a95e20aa1c250216ac461275f070dcf6ca116da6d7ce69766d
BLAKE2b-256 checksum
How to use checksums
cbd42d1a4cdcd8ae289f4feea98412e1947182d05386711337985aa528e41de1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / lapjv_numpy2-1.3.26-cp311-cp311-musllinux_1_1_x86_64.whl

Download URL lapjv_numpy2-1.3.26-cp311-cp311-musllinux_1_1_x86_64.whl
Size 727.5 kB
Tags CPython 3.11 Linux musl 1.1+ x86-64
SHA-256 checksum
How to use checksums
763fbfd28a19b0de366cbca892aeafcd3febf6d830137191b0a0ffc0a4e1ab98
BLAKE2b-256 checksum
How to use checksums
b45c568040c6b8f30aada53d4e03252842be19c1ab4f6e9a3b65fc246773bc66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / lapjv_numpy2-1.3.26-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL lapjv_numpy2-1.3.26-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 162.8 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
925f1b428d1caf8b94e6cd94a674146783fdea2ef57d7cb53d29d625247cebff
BLAKE2b-256 checksum
How to use checksums
21f5f44c19234e6dd2c3536326d66deba3b61579b3610a34d10748e2e3c883c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / lapjv_numpy2-1.3.26-cp310-cp310-win_amd64.whl

Download URL lapjv_numpy2-1.3.26-cp310-cp310-win_amd64.whl
Size 27.9 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
dbf87a0b62dd6d6ca8a42b0e8dc4ec8a8b65b854de3aa7d9a5caf8af739258b0
BLAKE2b-256 checksum
How to use checksums
1ad9c9ff433da9c14ab3ddccbf482d8dc0016d85e783f7545b6ddd792334bf73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / lapjv_numpy2-1.3.26-cp310-cp310-musllinux_1_1_x86_64.whl

Download URL lapjv_numpy2-1.3.26-cp310-cp310-musllinux_1_1_x86_64.whl
Size 726.7 kB
Tags CPython 3.10 Linux musl 1.1+ x86-64
SHA-256 checksum
How to use checksums
e17893e8f761b836b60f55d25c2573c092d480f39bb4635320e99257e4e7ac9b
BLAKE2b-256 checksum
How to use checksums
62744087ab880bcc434477748c3f5c88c506c90ecdb76e0ec433506fe46effa1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / lapjv_numpy2-1.3.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL lapjv_numpy2-1.3.26-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 161.9 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b7ca651313bfd55b00f5b8274e0d85e2af8c4ccce0563f47d238b240ce6ef2db
BLAKE2b-256 checksum
How to use checksums
c7a4fdf8d8a28c8aacca276acd4f7842f8d175715b97e0c2d44f0e1ce4a8290b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / lapjv_numpy2-1.3.26-cp39-cp39-win_amd64.whl

Download URL lapjv_numpy2-1.3.26-cp39-cp39-win_amd64.whl
Size 27.9 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
849d01e00ead97589e0fa185d4b84e765b081fd7003adc732a5fd49508ac35b6
BLAKE2b-256 checksum
How to use checksums
838b01e8822f10d5b723f1f5cc6fd2f8c7ccee1c752671f48ffc2b3617a12c38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / lapjv_numpy2-1.3.26-cp39-cp39-musllinux_1_1_x86_64.whl

Download URL lapjv_numpy2-1.3.26-cp39-cp39-musllinux_1_1_x86_64.whl
Size 726.6 kB
Tags CPython 3.9 Linux musl 1.1+ x86-64
SHA-256 checksum
How to use checksums
8954c4af1e7d32c3edc76f3f60d55e38667082f0b76735f718c8f9ceb68fd25f
BLAKE2b-256 checksum
How to use checksums
fa95e3fd34f48c0318180b9a4353464ab271cade223733877b7468e92166ecdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / lapjv_numpy2-1.3.26-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL lapjv_numpy2-1.3.26-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 161.8 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
22b37766ef9cad8393bf4fc1228c5253db567d3af4078fa117b33a097282ba9b
BLAKE2b-256 checksum
How to use checksums
7ecfbbdf678478610af75efc3144e432ce123b82ca0da6b07eb4263b067219f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.0 CPython/3.12.4

Security for lapjv-numpy2 1.3.26

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.3.26 This release

10 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page