Skip to main content

Small nogil-compatible linear equation system solver

Project description

PyLU

top language supported Python versions supported implementations CI status

version on PyPI PyPI package format dependency status

license open issues PRs welcome

Small nogil-compatible Cython-based solver for linear equation systems A x = b.

We use semantic versioning.

For my stance on AI contributions, see the collaboration guidelines.

Introduction

The algorithm is LU decomposition with partial pivoting (row swaps). The code requires only NumPy and Cython.

The main use case for PyLU (over numpy.linalg.solve) is solving many small systems inside a nogil block in Cython code, without requiring SciPy (for its cython_lapack module).

Python and Cython interfaces are provided. The API is designed to be as simple to use as possible.

The arrays are stored using the C memory layout.

A rudimentary banded solver is also provided, based on detecting the band structure (if any) from the initial full LU decomposition. For cases where L and U have small bandwidth, this makes the O(n**2) solve step run faster. The LU decomposition still costs O(n**3), so this is useful only if the system is small, and the same matrix is needed for a large number of different RHS vectors. (This can be the case e.g. in integration of ODE systems with a constant-in-time mass matrix.)

Examples

Basic usage:

import numpy as np
import pylu

A = np.random.random( (5,5) )
b = np.random.random( 5 )

x = pylu.solve( A, b )

For a complete tour, see the test suite.

The main item of interest, however, is the Cython API in dgesv.pxd. The main differences to the Python API are:

  • Function names end with _c.
  • Explicit sizes must be provided, since the arrays are accessed via raw pointers.
  • The result array x must be allocated by the caller, and passed in as an argument. See dgesv.pyx for examples on how to do this in NumPy.

Installation

From PyPI

pip install pylu

From source

git clone https://github.com/Technologicat/pylu.git
cd pylu
pip install .

For maximum performance on your machine, build with architecture-specific optimizations:

CFLAGS="-march=native" pip install --no-build-isolation .

Pre-built wheels from PyPI use generic -O2 because -march=native bakes in the instruction set of the build machine — a wheel built with AVX-512 would crash on a CPU without it. Building from source avoids this and lets the compiler target your specific hardware.

Development setup

PyLU uses meson-python as its build backend and PDM for dependency management.

git clone https://github.com/Technologicat/pylu.git
cd pylu
pdm install
pip install --no-build-isolation -e .

The --no-build-isolation flag is required for editable installs with meson-python. Normally pip builds in a temporary isolated venv, but meson-python's editable mode needs the build dependencies (Cython, NumPy, meson) to remain available in the environment for on-import rebuilds.

Note on editable installs: meson-python editable installs rebuild the Cython extension on import via a redirect .pth file. After modifying .pyx or .pxd files, re-run pip install --no-build-isolation -e . to rebuild. Alternatively, use a non-editable install (pip install .) and reinstall after changes.

Dependencies

Requires Python ≥ 3.11.

License

BSD. Copyright 2016–2026 Juha Jeronen, University of Jyväskylä, and JAMK University of Applied Sciences.

Acknowledgement

This work was financially supported by the Jenny and Antti Wihuri Foundation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylu-1.0.0.tar.gz (33.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pylu-1.0.0-cp314-cp314-win_amd64.whl (125.5 kB view details)

Uploaded CPython 3.14Windows x86-64

pylu-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (119.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pylu-1.0.0-cp314-cp314-macosx_11_0_arm64.whl (90.1 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pylu-1.0.0-cp313-cp313-win_amd64.whl (122.0 kB view details)

Uploaded CPython 3.13Windows x86-64

pylu-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (119.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pylu-1.0.0-cp313-cp313-macosx_11_0_arm64.whl (89.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pylu-1.0.0-cp312-cp312-win_amd64.whl (122.8 kB view details)

Uploaded CPython 3.12Windows x86-64

pylu-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (119.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pylu-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (90.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pylu-1.0.0-cp311-cp311-win_amd64.whl (126.2 kB view details)

Uploaded CPython 3.11Windows x86-64

pylu-1.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (124.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

pylu-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (89.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file pylu-1.0.0.tar.gz.

File metadata

  • Download URL: pylu-1.0.0.tar.gz
  • Upload date:
  • Size: 33.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pylu-1.0.0.tar.gz
Algorithm Hash digest
SHA256 63b09585ede62ed45c40e3e90198fe42e503d7927edd72f29d023f9aeb1303b9
MD5 76d88e6e43e703df3e24e0bdd60bb699
BLAKE2b-256 0da5dbda492a193b991b7b2996ce7417cb3b323d832b162e3d60ae4772b865d9

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pylu-1.0.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 125.5 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pylu-1.0.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 de16678b89b3a0a670d06df5ec0ad5be3003bee42047423f2887a8be94603326
MD5 b1d2f3c264e8a30f2646decae2313432
BLAKE2b-256 73c467a0fb13c151d3d3d76b22d60fcfb4f28a71927c63e488046675aee3cdb4

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylu-1.0.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8fdc24f3c635f0f8eac6a4cd0f6f64d510618947d259093507dee172ee835ad8
MD5 5437df96af84bb94f8f49a9af122bf46
BLAKE2b-256 cca198f2e50f4ac89553aca84466b5907b73b415d9673231c8ecc65c0815234e

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylu-1.0.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 88328f0d7a714430f2fcc7ec9c09060adb1f8c4acfb6494653d98defab8c2420
MD5 17064b2226f204a47ff8a4409bf72dcd
BLAKE2b-256 4134467bc3f9d41df9f92ec0172e5c312d0b3e914b9be150e7b6a5f21f5ae34b

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pylu-1.0.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 122.0 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pylu-1.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 19d236343b2372ec99e328a70a4eac4581ea1038023f8275512bbec887c3451f
MD5 5c751608ac9b08805d62fa7f2ff8abaa
BLAKE2b-256 1403befffba94ed97cea742e1bd69c431153add701c4bcc7298cf8b071372b68

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylu-1.0.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7686cac41229a21345e9828de74a69a7019b5b7218fa39bb814ad65a913629fc
MD5 38109142185d28fd7f0cf3ad7e7d765a
BLAKE2b-256 6f48d6b1bfe4b82cce52b285cd48969c891319e562aa5fde413b3cfc57874019

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylu-1.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 16b51afd76e30a864db544838a40bd0146516e189ef0dda7fcdbcad049386b1a
MD5 2ab04f53ce77d6e40f8eb5c5b231b212
BLAKE2b-256 1bc3541934515e6efa3abe5d402ce50fec6b9b32d6f056dff2cd5b29408d44ea

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pylu-1.0.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 122.8 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pylu-1.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 082434936bc9a6d04cd8d28fc804aa7dc83b85668e643e8eba7f720eea47049b
MD5 519ed845737dbda183ea7d7ca270b422
BLAKE2b-256 b9e7c90fd000377342621ab63a8d0f95155cd408a6e4a4f5d447dd9cf0782d64

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylu-1.0.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 35fe92e17630db18b67df0934c7630db14c91b21348850116c648d30c0e16413
MD5 f8add7351ed4b4d73a39b18bec815376
BLAKE2b-256 a4fc4a2d53fa28f83cc274b2dd50782c7034242a9ca7464dc75d6d144b2a8af6

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylu-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bd8dd7d210b878eb8cf2ede5b7bac4630b0e23674876204e88bfad9a6bddbebd
MD5 e6f07772484e4d7b403c6ae2f8860f1e
BLAKE2b-256 c5d164c3b851d91e1855f0446037d7f0f2a5a38ba517a60e1434ab30561f970e

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pylu-1.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 126.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pylu-1.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7b38a738475c84cf9ae3e0711264c83f4baa7cf1cfa1d4b911ba8ec38accd1bc
MD5 4dea7cb5cf4f16d90166a9c684e7ac18
BLAKE2b-256 e69bd90d76f4eec6bfab2f4a0d668fd0e9df595b31c7d6516b8fd7afc209dde6

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylu-1.0.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ad3aa0a8d50a27aeb307463b5b768cbec0fb0beef4aaa7776b30a67f36ba9fc4
MD5 c193a58c7c3a9ee6bb7fb29eb8ac8f88
BLAKE2b-256 480119dfe30ec7941273b311a0a0a5408298b1355e3cca3d9a091b269f792ccd

See more details on using hashes here.

File details

Details for the file pylu-1.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylu-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4a57b6b10278de5d6b00965023f461e7d8de87578af011c0618ce4daba0c8cf
MD5 b7ea23c7c687b65fe4c813b685295015
BLAKE2b-256 01b193118ac728bff05c24c143ff095f473fac32a350017b5c9b038dc11a3e91

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page