Backends#
Backends allows users to effortlessly switch between different array and FFT implementations and to define custom ones. Backends enable the same code to be run on CPU or GPU, and to quickly integrate novel solutions and benefit from their performance gains. Having backends makes pytme flexible and highly adaptive to available compute infrastructure.
Note
Currently flexible backends are only implemented for exhaustive template matching operations. Keep an eye on the documentation or announcements regarding extension to other parts of pytme.
Backend Manager#
Modules that support flexible backends import a global instance of BackendManager
like so: from tme.backends import backend
. The import is quasi-equivalent to import numpy as np
, with the exception being the naming difference. Notably, backend agnostic code is written without instance specific methods such as the ones defined by np.ndarray
. Instance-specific functions are wrapped instead, e.g. NumpyFFTWBackend.fill()
. For additional information please refer to the class documentation below.
Manager for template matching backends. |
Abstract Base Backend#
MatchingBackend
serves as specification for new backends. Generally the aim is to create a structure that is syntactically similar to numpy.
|
A strategy class for template matching backends. |
Schematically, each backend requires an array implementation, such as the ones provided by numpy
, pytorch
or mars
. This backend should provide array data structures and define operations on it. Since the syntax of many backends is already similar to numpy, wrapping them is fairly straightfoward. In addition to array operations, each backend is requried to define a range of template matching specific operations.
With array and template matching specific operations defined, practically any backend can be used to perform template matching with pytme. Below is an overview of methods that are required from each backend.
Array operations#
|
Element-wise addition of arrays. |
|
Element-wise subtraction of arrays. |
|
Element-wise multiplication of arrays. |
|
Element-wise division of arrays. |
|
Element-wise modulus of arrays. |
|
Compute the sum of array elements. |
|
Compute the einstein notation based summation. |
|
Compute the mean of array elements. |
|
Compute the standad deviation of array elements. |
|
Compute the maximum of array elements. |
|
Compute the minimum of array elements. |
|
Compute the element wise maximum of arr1 and arr2. |
|
Compute the element wise minimum of arr1 and arr2. |
|
Compute the square root of array elements. |
|
Compute the square of array elements. |
|
Compute the absolute of array elements. |
Compute the transpose of arr. |
|
Compute the bytestring representation of arr. |
|
|
Compute the number of elements of arr. |
|
Fills |
|
Clip elements of arr. |
|
Roll array elements along a specified axis. |
|
Join a sequence of objects along a new axis. |
|
Creates an array representing the index grid of an input. |
|
Compute the n-th power of an array. |
|
Change the datatype of arr. |
|
Join a sequence of objects along an existing axis. |
|
Repeat each array element a specified number of times. |
|
Find the unique elements of an array. |
|
Determinces the indices of largest elements. |
|
Compute the indices to sort a given input array. |
|
Convert flat index to array indices. |
|
Compute indices of upper triangular matrix |
Array initialization#
|
Returns an array filled with fill_value of specified shape and dtype. |
|
Returns an aligned array of zeros with specified shape and dtype. |
|
Arange values in evenly spaced interval. |
Template matching#
|
Build forward and inverse real fourier transform functions. |
|
Returns an array that has been padded to a specified shape with a padding value at the top-left corner. |
|
Converts an array to an object shared in memory. |
|
Returns an array of given shape and dtype from shared memory location. |
|
Extract the centered portion of an array based on a new shape. |
|
Performs a rigid transformation. |
Identifies local maxima in score_space separated by min_distance. |
|
Computes regular, optimized and fourier convolution shape. |
Conversion#
Convert an array of a given backend to a CPU array of that backend. |
|
Convert an array of given backend to a numpy array. |
|
Convert a numpy array instance to backend array type. |
Auxiliary#
|
Returns the minimal difference representable by dtype. |
Free cached objects allocated by backend. |
|
Return the number of bytes occupied by a given datatype. |
|
Returns the available memory available for computations in bytes. |
Note
Notably, autoray provides a framework that allows for writing backend agnostic python code, similar to the approach taken here. In the future, tme.backends
might be deprecated in favor of autoray
.
Supported Backends#
|
A numpy and pyfftw-based matching backend. |
|
A pytorch-based matching backend. |
|
A cupy-based matching backend. |
|
A mlx-based matching backend. |
|
A jax-based matching backend. |