moten.backend package
Submodules
Module contents
- moten.backend.benchmark(backend=None, nimages=100, vdim=96, hdim=128, stimulus_fps=24)[source]
Benchmark motion energy computation across one or more backends.
Runs a small motion energy pyramid projection and reports the wall-clock time for each backend. Useful for comparing CPU vs GPU performance.
- Parameters:
backend (str or None) – Name of a single backend to benchmark, or None to benchmark all available backends.
nimages (int) – Number of video frames in the test stimulus.
vdim (int) – Vertical dimension of the test stimulus (pixels).
hdim (int) – Horizontal dimension of the test stimulus (pixels).
stimulus_fps (int) – Stimulus frame rate.
- Returns:
results – Dictionary mapping backend name to a dict with keys: -
duration_seconds: wall-clock time for per-filter projection -duration_batched_seconds: wall-clock time for batched projection -speedup: ratio of per-filter to batched duration -nimages: number of frames processed -vhsize:(vdim, hdim)-nfilters: number of filters in the pyramid- Return type:
dict
Examples
>>> from moten.backend import benchmark >>> results = benchmark("numpy") >>> print(f"numpy: {results['numpy']['duration_seconds']:.3f}s")
- moten.backend.get_backend()[source]
Get the current backend module.
- Returns:
module – Module of the backend.
- Return type:
python module
- moten.backend.set_backend(backend, on_error='raise')[source]
Set the backend using a global variable, and return the backend module.
- Parameters:
backend (str or module) – Name or module of the backend.
on_error (str in {"raise", "warn"}) – Define what is done if the backend fails to be loaded. If “warn”, this function only warns, and keeps the previous backend. If “raise”, this function raises on errors.
- Returns:
module – Module of the backend.
- Return type:
python module