scipy 1.8.0 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
choose_conv_method(in1, in2, mode='full', measure=False)

This primarily exists to be called during the method='auto' option in convolve and correlate . It can also be used to determine the value of method for many different convolutions of the same dtype/shape. In addition, it supports timing the convolution to adapt the value of method to a particular set of inputs and/or hardware.

Notes

Generally, this method is 99% accurate for 2D signals and 85% accurate for 1D signals for randomly chosen input sizes. For precision, use measure=True to find the fastest method by timing the convolution. This can be used to avoid the minimal overhead of finding the fastest method later, or to adapt the value of method to a particular set of inputs.

Experiments were run on an Amazon EC2 r5a.2xlarge machine to test this function. These experiments measured the ratio between the time required when using method='auto' and the time required for the fastest method (i.e., ratio = time_auto / min(time_fft, time_direct) ). In these experiments, we found:

The 2D results almost certainly generalize to 3D/4D/etc because the implementation is the same (the 1D implementation is different).

All the numbers above are specific to the EC2 machine. However, we did find that this function generalizes fairly decently across hardware. The speed tests were of similar quality (and even slightly better) than the same tests performed on the machine to tune this function's numbers (a mid-2014 15-inch MacBook Pro with 16GB RAM and a 2.5GHz Intel i7 processor).

There are cases when fftconvolve supports the inputs but this function returns :None:None:`direct` (e.g., to protect against floating point integer precision).

versionadded

Parameters

in1 : array_like

The first argument passed into the convolution function.

in2 : array_like

The second argument passed into the convolution function.

mode : str {'full', 'valid', 'same'}, optional

A string indicating the size of the output:

full

The output is the full discrete linear convolution of the inputs. (Default)

valid

The output consists only of those elements that do not rely on the zero-padding.

same

The output is the same size as :None:None:`in1`, centered with respect to the 'full' output.

measure : bool, optional

If True, run and time the convolution of :None:None:`in1` and in2 with both methods and return the fastest. If False (default), predict the fastest method using precomputed values.

Returns

method : str

A string indicating which convolution method is fastest, either 'direct' or 'fft'

times : dict, optional

A dictionary containing the times (in seconds) needed for each method. This value is only returned if measure=True .

Find the fastest convolution/correlation method.

See Also

convolve
correlate

Examples

Estimate the fastest method for a given input:

>>> from scipy import signal
... rng = np.random.default_rng()
... img = rng.random((32, 32))
... filter = rng.random((8, 8))
... method = signal.choose_conv_method(img, filter, mode='same')
... method 'fft'

This can then be applied to other arrays of the same dtype and shape:

>>> img2 = rng.random((32, 32))
... filter2 = rng.random((8, 8))
... corr2 = signal.correlate(img2, filter2, mode='same', method=method)
... conv2 = signal.convolve(img2, filter2, mode='same', method=method)

The output of this function ( method ) works with correlate and convolve .

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.signal._signaltools._fftconv_faster scipy.signal._signaltools.correlate scipy.signal._signaltools.convolve scipy.signal._signaltools.choose_conv_method

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/signal/_signaltools.py#1156
type: <class 'function'>
Commit: