sparse-dot-topn is a Python package designed to accelerate sparse matrix multiplication followed by the selection of the top-N results. It significantly reduces memory footprint and improves performance for operations common in tasks like large-scale string comparison and entity matching. Developed by ING Wholesale Banking Advanced Analytics, it is currently at version 1.2.0 and receives regular updates with a focus on performance and Python version compatibility.
pip install sparse-dot-topnVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to perform a sparse matrix multiplication with top-N result selection using `sp_matmul_topn`. It creates two random CSR sparse matrices and computes their product, keeping only the top 10 values for each row in the result matrix. Ensure `scipy` and `numpy` are installed.
Upgrade your Python environment to 3.9 or newer.
Migrate your code to use the new `sp_matmul_topn` function and updated parameter names. Refer to the migration guide in the GitHub README.
If experiencing OpenMP errors, try installing from source with `pip install sparse_dot_topn --no-binary sparse_dot_topn` to ensure architecture-specific optimizations, or run functions without explicitly specifying the `n_threads` argument. Check the `INSTALLATION.md` for platform-specific troubleshooting.
Profile your application with `threshold=None` versus a specific `threshold` value to determine the optimal setting for your use case.
Update your import statement and function calls to use `sp_matmul_topn` instead. For example: `from sparse_dot_topn import sp_matmul_topn` and `C = sp_matmul_topn(A, B, top_n=N)`.
Ensure you have a C++17 compatible compiler installed (e.g., `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on MacOS, Visual Studio Build Tools on Windows). Also, explicitly install `cython` and `numpy` before `sparse-dot-topn`: `pip install cython numpy scipy sparse-dot-topn`. If issues persist, try specifying a known working NumPy version or installing with `--no-binary sparse_dot_topn`.
For very large matrices (e.g., O(10M+) rows), consider breaking them into smaller chunks and using the `zip_sp_matmul_topn` function to process them distributedly. Adjusting `top_n` and `threshold` can also help reduce memory footprint.