MatchingBackend#

class MatchingBackend(array_backend, float_dtype, complex_dtype, int_dtype, overflow_safe_dtype)[source]#

Bases: ABC

A strategy class for template matching backends.

This class provides an interface to enable users to swap between different array and fft implementations while preserving the remaining functionalities of the API. The objective is to maintain a numpy like interface that generalizes across various backends.

By delegating attribute access to the provided backend, users can access functions/methods of the backend as if they were directly part of this class.

Parameters:
array_backendobject

The backend object providing array functionalities.

float_dtypetype

Data type of float array instances, e.g. np.float32.

complex_dtypetype

Data type of complex array instances, e.g. np.complex64.

int_dtypetype

Data type of integer array instances, e.g. np.int32.

overflow_safe_dtypetype

Data type than can be used in reduction operations to avoid overflows.

Attributes:
_array_backendobject

The backend object providing array functionalities.

_float_dtypetype

Data type of float array instances, e.g. np.float32.

_complex_dtypetype

Data type of complex array instances, e.g. np.complex64.

_int_dtypetype

Data type of integer array instances, e.g. np.int32.

_overflow_safe_dtypetype

Data type than can be used in reduction operations to avoid overflows.

_fundamental_dtypesDict

Maps int, float and cmoplex python types to backend specific data types.

Notes

Developers should be aware of potential naming conflicts between methods and attributes of this class and those of the provided backend.

Examples

>>> import numpy as np
>>> from tme.backends import NumpyFFTWBackend
>>> backend = NumpyFFTWBackend(
>>>     array_backend=np,
>>>     float_dtype=np.float32,
>>>     complex_dtype=np.complex64,
>>>     int_dtype=np.int32
>>> )
>>> arr = backend.array([1, 2, 3])
>>> print(arr)
[1 2 3]

Methods

MatchingBackend.abs(arr[, out])

Compute the absolute of array elements.

MatchingBackend.add(arr1, arr2[, out])

Element-wise addition of arrays.

MatchingBackend.arange(stop[, start, step])

Arange values in evenly spaced interval.

MatchingBackend.argsort(*args, **kwargs)

Compute the indices to sort a given input array.

MatchingBackend.astype(dtype)

Change the datatype of arr.

MatchingBackend.build_fft(fast_shape, ...)

Build forward and inverse real fourier transform functions.

MatchingBackend.clip(arr, a_min, a_max[, out])

Clip elements of arr.

MatchingBackend.compute_convolution_shapes(...)

Computes regular, optimized and fourier convolution shape.

MatchingBackend.concatenate(*args, **kwargs)

Join a sequence of objects along an existing axis.

MatchingBackend.datatype_bytes(dtype)

Return the number of bytes occupied by a given datatype.

MatchingBackend.device_count()

Return the number of available compute devices considered by the backend.

MatchingBackend.divide(arr1, arr2[, out])

Element-wise division of arrays.

MatchingBackend.einsum(arr1, arr2[, out])

Compute the einstein notation based summation.

MatchingBackend.eps(dtype)

Returns the minimal difference representable by dtype.

MatchingBackend.extract_center(arr, newshape)

Extract the centered portion of an array based on a new shape.

MatchingBackend.fill(arr, value)

Fills arr in-place with a given value.

MatchingBackend.free_cache()

Free cached objects allocated by backend.

MatchingBackend.from_sharedarr(shape, dtype, shm)

Returns an array of given shape and dtype from shared memory location.

MatchingBackend.full(shape, dtype, fill_value)

Returns an array filled with fill_value of specified shape and dtype.

MatchingBackend.get_available_memory()

Returns the available memory available for computations in bytes.

MatchingBackend.get_fundamental_dtype(arr)

Given an array instance, returns the corresponding fundamental python type, i.e., int, float or complex.

MatchingBackend.indices(*args, **kwargs)

Creates an array representing the index grid of an input.

MatchingBackend.max(arr[, axis])

Compute the maximum of array elements.

MatchingBackend.max_filter_coordinates(...)

Identifies local maxima in score_space separated by min_distance.

MatchingBackend.maximum(arr1, arr2[, out])

Compute the element wise maximum of arr1 and arr2.

MatchingBackend.mean(arr[, axis])

Compute the mean of array elements.

MatchingBackend.min(arr[, axis])

Compute the minimum of array elements.

MatchingBackend.minimum(arr1, arr2[, out])

Compute the element wise minimum of arr1 and arr2.

MatchingBackend.mod(arr1, arr2[, out])

Element-wise modulus of arrays.

MatchingBackend.multiply(arr1, arr2[, out])

Element-wise multiplication of arrays.

MatchingBackend.power([arr, power, out])

Compute the n-th power of an array.

MatchingBackend.repeat(*args, **kwargs)

Repeat each array element a specified number of times.

MatchingBackend.reverse()

Reverse the order of elements in an array along all its axes.

MatchingBackend.rigid_transform(arr, ...[, ...])

Performs a rigid transformation.

MatchingBackend.roll(*args, **kwargs)

Roll array elements along a specified axis.

MatchingBackend.set_device()

Context manager that sets active compute device device for operations.

MatchingBackend.size(arr)

Compute the number of elements of arr.

MatchingBackend.sqrt(arr[, out])

Compute the square root of array elements.

MatchingBackend.square(arr[, out])

Compute the square of array elements.

MatchingBackend.stack(*args, **kwargs)

Join a sequence of objects along a new axis.

MatchingBackend.std(arr[, axis])

Compute the standad deviation of array elements.

MatchingBackend.subtract(arr1, arr2[, out])

Element-wise subtraction of arrays.

MatchingBackend.sum(arr[, axis])

Compute the sum of array elements.

MatchingBackend.to_backend_array(arr)

Convert a numpy array instance to backend array type.

MatchingBackend.to_cpu_array(arr)

Convert an array of a given backend to a CPU array of that backend.

MatchingBackend.to_numpy_array(arr)

Convert an array of given backend to a numpy array.

MatchingBackend.to_sharedarr(arr[, ...])

Converts an array to an object shared in memory.

MatchingBackend.tobytes(arr)

Compute the bytestring representation of arr.

MatchingBackend.topk_indices(arr, k)

Determinces the indices of largest elements.

MatchingBackend.topleft_pad(arr, shape[, padval])

Returns an array that has been padded to a specified shape with a padding value at the top-left corner.

MatchingBackend.transpose(arr)

Compute the transpose of arr.

MatchingBackend.tril_indices(*args, **kwargs)

Compute indices of upper triangular matrix

MatchingBackend.unique(arr[, return_index, ...])

Find the unique elements of an array.

MatchingBackend.unravel_index(indices, shape)

Convert flat index to array indices.

MatchingBackend.where(*args)

Return elements from input depending on condition.

MatchingBackend.zeros(shape, dtype)

Returns an aligned array of zeros with specified shape and dtype.