Registry / ai-ml / lapx
library0.9.4pypypi✓ verified 85d ago

lapx is a Python library providing efficient linear assignment problem solvers, including both single and batch solvers, based on the Jonker-Volgenant algorithm. It extends and enhances Tomas Kazmar's original `lap` library, offering improved stability, performance, and broader platform support (Windows, Linux, macOS) for Python 3.7+. The library is actively maintained, with the current version being 0.9.4, and receives frequent minor and patch releases.

pip install lapx
INSTALL
IMPORT
SIG · LAPX
L
lapx
ai-mlpythonv0.9.4
Install
3.8s avg
Import
10ms
Disk
97MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.012s · 98.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.8s · import 0.007s · 92MB
97MB installed
● package 97MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lap
import lap
import lapx
The installed package is `lapx`, but it is imported as `lap` to maintain compatibility with the original `lap` library on which it is based.
lapjv
import lap result = lap.lapjv(...)
Primary function for dense linear assignment problems.
lapjvs
import lap result = lap.lapjvs(...)
Enhanced version of lapjv with specific optimizations.

This example demonstrates how to use the `lapjv` function to solve a basic linear assignment problem given a cost matrix. The function returns the optimal total cost and the assignments for rows and columns.

import lap import numpy as np # Example cost matrix cost_matrix = np.array([[1, 2, 3], [3, 1, 2], [2, 3, 1]]) # Solve the linear assignment problem using lapjv cost, x, y = lap.lapjv(cost_matrix) print(f"Optimal assignment cost: {cost}") print(f"Row assignments (x, maps row index to column index): {x}") print(f"Column assignments (y, maps column index to row index): {y}")
Debug
Known issues
gotchaThe package `lapx` should be imported using `import lap`. Attempting to `import lapx` will result in an `ModuleNotFoundError`.
fix
Always use `import lap` after installing `lapx`.
affects: All versions
breakingInstalling both `lap` (original package) and `lapx` simultaneously will lead to conflicts, as both provide the `lap` import. The package installed last will override the other.
fix
Ensure only one of `lap` or `lapx` is installed in your environment. `lapx` is recommended for extended features and better performance.
affects: All versions
gotchaSince v0.7.1, the `lapjvs()` function defaults `prefer_float32` to `True`. While this generally improves speed without altering return results, users expecting `float64` precision by default for intermediate calculations (as in older versions) should explicitly set `prefer_float32=False`.
fix
If specific float precision is required for `lapjvs()`, explicitly set the `prefer_float32` parameter (e.g., `lap.lapjvs(..., prefer_float32=False)`).
affects: >=0.7.1
gotchaStarting from v0.8.0, dedicated batch processing functions (e.g., `lapjvx_batch`, `lapjvs_batch`) were introduced. While older single-assignment functions might still process batches in some contexts, using the explicit `_batch` functions is recommended for optimal performance and correct handling of batch inputs.
fix
For batch processing, transition to using the `_batch` variants of the assignment functions for clarity and performance.
affects: >=0.8.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'lapx'
The `lapx` library, while installed as 'lapx', is designed to be imported using `import lap` to maintain compatibility with the original `lap` library it extends.
fix
Use `import lap` instead of `import lapx` in your Python code.
ModuleNotFoundError: No module named 'lap'
This error can occur if `lapx` was not successfully installed, or if both `lap` and `lapx` packages are installed and conflicting, or if there's an environment issue preventing the `lap` module from being found even after `lapx` installation.
fix
First, ensure `lapx` is installed: `pip install lapx`. If the error persists, uninstall both `lap` and `lapx` then reinstall only `lapx`: `pip uninstall lap lapx` followed by `pip install lapx`. Ensure you are working in the correct Python environment.
error: Microsoft Visual C++ 14.0 or greater is required. (or similar compilation errors like 'longintrepr.h' file not found or 'subprocess-exited-with-error' during pip install)
These errors typically occur when `pip` attempts to build the `lapx` (or original `lap`) package from source, but a necessary C++ compiler (like Microsoft Visual C++ on Windows or Xcode command line tools on macOS) is not installed or configured, or there are underlying build system incompatibilities (e.g., with `numpy.distutils` in older `lap` versions).
fix
On Windows, install 'Build Tools for Visual Studio' from Microsoft, ensuring C++ build tools are selected. On macOS, install Xcode Command Line Tools: `xcode-select --install`. On Linux, install `build-essential` (e.g., `sudo apt-get install build-essential`). It's also recommended to use a virtual environment and ensure `setuptools` and `wheel` are up-to-date: `pip install --upgrade pip setuptools wheel`.
ImportError: lap requires numpy, please "pip install numpy"
`lapx` depends on `numpy` for its operations, and this error indicates that `numpy` is either not installed in the current Python environment or is not accessible.
fix
Install `numpy` using pip: `pip install numpy`. It is good practice to install `numpy` before `lapx` or ensure it's a part of your environment's dependencies.
Illegal instruction (core dumped)
This runtime error, often observed when using `lap.lapjv()`, can be caused by incompatibilities between the compiled `lapx` binaries and the CPU's instruction set (e.g., AVX instructions not supported on older CPUs), or specific interactions with `numpy` versions.
fix
Try updating `numpy` to its latest stable version: `pip install --upgrade numpy`. If the issue persists, consider installing `lapx` using `pip install lapx --no-binary :all:` to force a source build, which might compile against your specific CPU architecture, assuming you have a C++ compiler set up.
Upgrade
Version history
0.9.4latest on PyPI · released Jan 7, 2026
Audit
Dependencies
numpyrequiredRequired for array manipulation and numerical operations as cost matrices are typically NumPy arrays.
Agent activity
6 hits · last 30 days
node
6
Resources
lapx — pip install lapx · libregistry