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.15.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cf116d17e072d4ebad1f594cf413bb13c0b6a15ad05232944ba023eb6d60a8c |
|
MD5 | bb11d6d7f37adf39882768611d4a58db |
|
BLAKE2b-256 | 74ee131fc33ca094d886533cfbb90d450372bad9a0613946834c16032f0ee167 |
Hashes for pyoperators-0.15.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ee54f0e4002e72de014631bd3b37d8825f739f3930f6f527514913fd325f6f6 |
|
MD5 | 5cf948d7e0145f671bfef13aa382b21c |
|
BLAKE2b-256 | 6cec4407a85a75c89e2f0abe97e83710b89f8e0a329a268a3eb29e87a04d2862 |
Hashes for pyoperators-0.15.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5222dee2038f8f5de69e63c4fa3ece767dc451db054dd22cc2055e5be4a75303 |
|
MD5 | bee2481e7fdd3e97f5b1e9c407aabd31 |
|
BLAKE2b-256 | f6a47b4083e6b440a6519e21287e0740e034fd0cda37cb917ac05dfd09456971 |
Hashes for pyoperators-0.15.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6416690179a65a162b0641a64dfae4aa302124d226e3bedaa6c976b546cdebaf |
|
MD5 | da5ce39f8922970cdd52cac8e026513d |
|
BLAKE2b-256 | a5fa416f0e5f698ab34630fc8d88cab1122765eee4face4c1657f583a38d40be |
Hashes for pyoperators-0.15.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3973c36072fa74b0ae8d9c9f888b101f87ca18d14b506dd1bb1efdb2c3b1f0c |
|
MD5 | a3141f72584fbcfe0b6bd37e30a929ad |
|
BLAKE2b-256 | af2118b56b3ed385a468237ca982a96daf6f9906a4824be7d7b019fea041b96f |
Hashes for pyoperators-0.15.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 488e7216f79d023128dc9be007d843fe176674a9ddc6c1a7b45d9ba200fb3b42 |
|
MD5 | 14922e45b7e5c4c74bb73b790d33cbaf |
|
BLAKE2b-256 | 9b516264d935f1c21434109feebaa9e079ede336820007b9940d2b822fcc138d |
Hashes for pyoperators-0.15.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 000df2bcfd7bf60cbc68c23c0096af104474e1f2cf80709fbb9f2f0472e1769f |
|
MD5 | 6225f6a1a2d0143e2a30f1bac63c40c6 |
|
BLAKE2b-256 | 34d0e59064c1ab0e8200a1fad822d67fca2d97648262c351e7bef063b3eebb52 |
Hashes for pyoperators-0.15.0-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 811d73c2bd64f206e4480e2db81ccda9820a65fb36a3e1d75c950c223bc0c92c |
|
MD5 | aea5e8ecec30aa6b0d562f82971eb590 |
|
BLAKE2b-256 | 36baded36596ec043b77e6647d0ee11b8179813b3b6e32730955aee8d4cb3a72 |
Hashes for pyoperators-0.15.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41049510751413a3284d8324aa20fa9ee1fe6495adeda0a13ad23af27451a926 |
|
MD5 | 8d62fa0ef7c1f0693bea954aa313eec8 |
|
BLAKE2b-256 | cf6d556f223293be69566b7334d1f5d199a412a00bf05af09ff3871c5ff0884f |