Backend helpers¶
backend
¶
NumPy/CuPy backend selection and array-module helpers.
A thin wrapper around the array-API differences between NumPy and CuPy so the rest of the package can be written once and run on either CPU or GPU. Also exposes a few low-level helpers (memory probe, FFT-size rounding, dtype pairs) that are shared between the spectrogram and Gabor stages.
get_array_module
¶
Return the active array module (numpy or cupy).
| PARAMETER | DESCRIPTION |
|---|---|
use_gpu
|
If True and CuPy is available, return
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
module
|
Either the |
get_signal_module
¶
Return the active signal-processing module.
| PARAMETER | DESCRIPTION |
|---|---|
use_gpu
|
If True and CuPy is available, return
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
module
|
Either |
next_fast_len
¶
Round n up to an FFT-friendly length.
CPU uses :func:scipy.fft.next_fast_len (product of small primes).
GPU uses the next power of two, which matches cuFFT's optimal path.
| PARAMETER | DESCRIPTION |
|---|---|
n
|
Minimum length required.
TYPE:
|
use_gpu
|
Switches between the CPU and GPU rounding rules.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
The smallest fast length |
get_available_memory
¶
Best-effort estimate of free memory in bytes.
On GPU, reports free VRAM via the current CUDA device. On CPU,
tries /proc/meminfo first, then :mod:psutil, then falls back
to a hard-coded 4 GiB so callers always get a usable number.
| PARAMETER | DESCRIPTION |
|---|---|
use_gpu
|
If True, report device memory rather than host memory.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Available memory in bytes. |
get_dtypes
¶
Return a matching (float, complex) dtype pair.
| PARAMETER | DESCRIPTION |
|---|---|
use_float32
|
If True, return
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of numpy.dtype
|
|
to_numpy
¶
Return array as a host-side NumPy array, copying from GPU if needed.
| PARAMETER | DESCRIPTION |
|---|---|
array
|
Input array. May be a numpy array, cupy array, or any
array-like accepted by :func:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
Host-side numpy array. |