Operators and solvers for high-performance computing.
Project description
PyOperators
The PyOperators package defines operators and solvers for high-performance computing. These operators are multi-dimensional functions with optimised and controlled memory management. If linear, they behave like matrices with a sparse storage footprint.
Documentaion
https://pchanial.github.io/pyoperators
Installation
pip install pyoperators[fft,wavelets]
On some platforms, it might be more convenient to install pyfftw through Conda beforehand to use the FFTOperator
:
conda install pyfftw
For MPI communication, an MPI library needs to be installed, for example on Ubuntu:
sudo apt install libopenmpi-dev
pip install pyoperators[fft,wavelets,mpi]
Getting started
To define an operator, one needs to define a direct function which will replace the usual matrix-vector operation:
>>> def f(x, out):
... out[...] = 2 * x
Then, you can instantiate an Operator
:
>>> A = pyoperators.Operator(direct=f, flags='symmetric')
An alternative way to define an operator is to define a subclass:
>>> from pyoperators import flags, Operator
... @flags.symmetric
... class MyOperator(Operator):
... def direct(x, out):
... out[...] = 2 * x
...
... A = MyOperator()
This operator does not have an explicit shape, it can handle inputs of any shape:
>>> A(np.ones(5))
array([ 2., 2., 2., 2., 2.])
>>> A(np.ones((2,3)))
array([[ 2., 2., 2.],
[ 2., 2., 2.]])
By setting the symmetric
flag, we ensure that A's transpose is A:
>>> A.T is A
True
For non-explicit shape operators, we get the corresponding dense matrix by specifying the input shape:
>>> A.todense(shapein=2)
array([[2, 0],
[0, 2]])
Operators do not have to be linear. Many operators are already predefined, such as the DiagonalOperator
, the FFTOperator
or the nonlinear ClipOperator
.
The previous A
matrix could be defined more easily like this:
>>> from pyoperators import I
>>> A = 2 * I
where I
is the identity operator with no explicit shape.
Operators can be combined together by addition, element-wise multiplication or composition. Note that the operator *
stands for matrix multiplication if the two operators are linear, or for element-wise multiplication otherwise:
>>> from pyoperators import I, DiagonalOperator
>>> B = 2 * I + DiagonalOperator(range(3))
>>> B.todense()
array([[2, 0, 0],
[0, 3, 0],
[0, 0, 4]])
Algebraic rules can easily be attached to operators. They are used to simplify expressions to speed up their execution. The B
Operator has been reduced to:
>>> B
DiagonalOperator(array([2, ..., 4], dtype=int64), broadcast='disabled', dtype=int64, shapein=3, shapeout=3)
Many simplifications are available. For instance:
>>> from pyoperators import Operator
>>> C = Operator(flags='idempotent,linear')
>>> C * C is C
True
>>> D = Operator(flags='involutary')
>>> D(D)
IdentityOperator()
Requirements
- python 3.8
Optional requirements:
- PyWavelets: wavelet transforms
- pyfftw: Fast Fourier transforms
- mpi4py: For MPI communication
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pyoperators-0.14.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ef2a42f27c8293708cf649354d7171954eb1e2194b4908949d93b0d85a5c47f |
|
MD5 | 27c2c450067e448ba4d1bf1038a8d5f7 |
|
BLAKE2b-256 | 75d257ed6c6e99e32ccac6bacffa333b75822255c433f4646dd449a3751fbe1c |
Hashes for pyoperators-0.14.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f5e18cf9ac495682e23596906534b228f652b94d6822b33ffbd8c468773282b |
|
MD5 | c17a158c95a16ce00602e5ac3043521a |
|
BLAKE2b-256 | 5172558004efff29d19d88f16e983a1fe8003c41547cafc9c8ba69ed89ce8750 |
Hashes for pyoperators-0.14.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9423eba7c19146b7cb2a1d89790cd29e30395f2cb6f80f0c0c794acdda839e44 |
|
MD5 | 4304fa5b7df0074fafef72c733955373 |
|
BLAKE2b-256 | f7a13b9c57a277b54f0a22c1c6f4508ca119184bdc2d5dedb57d492b3ee9832d |
Hashes for pyoperators-0.14.4-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b99f6c5b4a10be447ddfc0c074bdb8a814c2ba13bb43df6150a646e8f068269f |
|
MD5 | 47c6cf53d8586374fe7fc7f76e0ee070 |
|
BLAKE2b-256 | 233aa7eff8d5a2fb52312a09325141836b769a76bb44621167db8b2e1c16a16e |
Hashes for pyoperators-0.14.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d89bfaa8285cf7e125387cfd01cf7c651d0851d7a626fb7f554b4a7349e13d47 |
|
MD5 | 6a8553ff7b525250e3cc8e5f34e83b6a |
|
BLAKE2b-256 | 790602d4696e9f82e6f279a533cbdb5e0e3de26b9d4a761db88857d1c3b415a1 |
Hashes for pyoperators-0.14.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1d7928b3d3fb70c32109a63348f2a190c88cf00bfd0382e932cef60f1fb5ee0 |
|
MD5 | bb44cde2643f762a462af6282bf31315 |
|
BLAKE2b-256 | ded0525c79068ff2c911c84799e443fe1c11b3f18b1b2cbc9118303e5f9a53f8 |
Hashes for pyoperators-0.14.4-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37ae2f2ea803dd99e4fea1a0c3dd96239b37dd45e2a4387350cc117db7ed2825 |
|
MD5 | 99b72b179757b8b9f782b595dcb2dc40 |
|
BLAKE2b-256 | ef333a0e55ac2ce060c868b0bb3211920accc71d009e222374364af3566c8f31 |
Hashes for pyoperators-0.14.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0d6513f6b3d7df20cc94f7d22920a7b82cc336886d3a65d7ed70e4d1e9aac40 |
|
MD5 | 0abff305c161e64add45b05021ad6d97 |
|
BLAKE2b-256 | 14b1fe25e47a8c7b42209d6d918e8c2e28ac233e25d29f4495292887131b6f6b |
Hashes for pyoperators-0.14.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bddcdc16e1e2999518aa448ae17ce1776294ceea95ac152f6018f9f12c52eff9 |
|
MD5 | 471a119ffd482e3d2bfdec2ac31ef472 |
|
BLAKE2b-256 | 470e967b28b00f9f25779001ca02da4421ae018bcb83c220885bfdbb06262698 |