Skip to main content

Lazylinop

License Downloads Downloads PyPI version Anaconda version

Lazylinop is a python toolbox to ease and accelerate computations with ("matrix-free") linear operators. It provides glue to combine linear operators as easily as NumPy arrays, PyTorch/CuPy compatibility, standard signal/image processing linear operators, as well as advanced tools to approximate large matrices by efficient butterfly operators.

A LazyLinOp is a high-level linear operator based on an arbitrary underlying implementation, such as:

Thanks to the Lazylinop API, this operator can be easily manipulated, transformed or aggregated with other linear operators to form more complex LazyLinOp objects. Thus, many operations are available such as the addition, concatenation, adjoint etc. These operations are all ruled by the lazy paradigm: their evaluation is delayed until the resulting LazyLinOp is actually applied to a vector (or to a collection of vectors, seen as a matrix).

Install

Please refer to the documentation to install Lazylinop.

Get started

You can read our documentation and our quick tour.

Please refer to tutorials for advanced examples.

2D Magnetic-Resonance-Imaging (MRI)

from skimage.data import shepp_logan_phantom
from lazylinop.signal2d import dft2d, colvec, uncolvec
from lazylinop.basicops import diag, eye, kron, roll
import matplotlib.pyplot as plt
import numpy as np

img = shepp_logan_phantom()
M, N = img.shape

The following code shows how to create a MRI operator and apply to Shepp-Logan phantom image.

# Pre-built 2D FFT.
F2 = dft2d(img.shape)
# Construct a 2D FFT-shift.
shift = kron(roll(N, shift=N // 2), roll(M, shift=M // 2))
# Apply random mask to the columns.
v = np.zeros(N, dtype=img.dtype)
v[np.random.randint(0, high=N, size=int(0.9 * N))] = 1
mask = kron(diag(v), eye(M))
# MRI operator.
op = mask @ shift.T @ F2 @ shift

y = op @ colvec(img)
x_hat = op.H @ y

From left to right we plot the original image, the undersampling in the Fourier space and the reconstruction using the adjoint of the MRI operator.

fig, axs = plt.subplots(1, 3, figsize=(12, 4))
axs[0].imshow(img, cmap="gray", vmin=0, vmax=1)
axs[0].set_title("original")
axs[1].imshow(uncolvec(np.sqrt(y * np.conj(y)).real, (M, N)), cmap="rainbow", vmin=0, vmax=1)
axs[1].set_title("undersampling")
axs[2].imshow(uncolvec(np.real(x_hat), (M, N)), cmap="gray", vmin=0, vmax=1)
axs[2].set_title("adjoint reconstruction")
fig.tight_layout()

Authors

  • Pascal Carrivain
  • Simon Delamare
  • Hakim Hadj-Djilani
  • Remi Gribonval

Contributing

You can contribute to Lazylinop with bug report, feature request and merge request.

Running unit tests

cd tests
python3 -m unittest TestLazyLinOp.py
python3 -m unittest TestBasicops.py
python3 -m unittest TestSignal.py
python3 -m unittest TestButterfly.py
python3 -m unittest TestQuantization.py
python3 -m unittest TestLinalg.py

Metadata

Release files for lazylinop 1.24.32

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

Built distribution (wheel)

Table of built distributions (wheels) for lazylinop 1.24.32
File Interpreter ABI Platform Actions
lazylinop-1.24.32-py3-none-any.whl Python 3 none any Details for lazylinop-1.24.32-py3-none-any.whl

Release files / lazylinop-1.24.32-py3-none-any.whl

Download URL lazylinop-1.24.32-py3-none-any.whl
Size 346.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ab57faa519e6590744e6637feb9fd1e58e465897d7664e5422030f5630838e4
BLAKE2b-256 checksum
How to use checksums
eb748603320e1d7e8932ed783012a060e4f1efdab56e369132491df0ef9124fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for lazylinop 1.24.32

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.24.32 This release

1 release file 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