Skip to main content

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


Download files

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

Source Distribution

pyoperators-0.16.2.tar.gz (210.8 kB view hashes)

Uploaded Source

Built Distributions

pyoperators-0.16.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (257.8 kB view hashes)

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

pyoperators-0.16.2-cp311-cp311-macosx_11_0_arm64.whl (154.5 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pyoperators-0.16.2-cp311-cp311-macosx_10_9_x86_64.whl (159.3 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pyoperators-0.16.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (253.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pyoperators-0.16.2-cp310-cp310-macosx_11_0_arm64.whl (154.0 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pyoperators-0.16.2-cp310-cp310-macosx_10_9_x86_64.whl (158.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pyoperators-0.16.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (252.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pyoperators-0.16.2-cp39-cp39-macosx_11_0_arm64.whl (153.6 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pyoperators-0.16.2-cp39-cp39-macosx_10_9_x86_64.whl (157.8 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyoperators-0.16.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (255.9 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

pyoperators-0.16.2-cp38-cp38-macosx_11_0_arm64.whl (154.1 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pyoperators-0.16.2-cp38-cp38-macosx_10_9_x86_64.whl (158.5 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

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