File: fft.py

package info (click to toggle)
python-librosa 0.11.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 166,732 kB
  • sloc: python: 21,731; makefile: 141; sh: 2
file content (64 lines) | stat: -rw-r--r-- 1,614 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Fast Fourier Transform (FFT) library container"""
import scipy.fft

from types import ModuleType
from typing import Optional
from ..util.decorators import deprecated


__all__ = ["get_fftlib", "set_fftlib"]

# Object to hold FFT interfaces
__FFTLIB: Optional[ModuleType] = scipy.fft


@deprecated(version="0.11.0", version_removed="1.0")
def set_fftlib(lib: Optional[ModuleType] = None) -> None:
    """Set the FFT library used by librosa.

    .. warning:: This functionality is deprecated in librosa 0.11 and will be
        removed in 1.0.  To achieve the same effect, use either the
        `scipy.fft.set_backend` context manager or
        `scipy.fft.set_global_backend` function.

    Parameters
    ----------
    lib : None or module
        Must implement an interface compatible with `scipy.fft`.
        If ``None``, reverts to `scipy.fft`.

    Examples
    --------
    Use `pyfftw`:

    >>> import pyfftw
    >>> librosa.set_fftlib(pyfftw.interfaces.numpy_fft)

    Reset to default `scipy` implementation

    >>> librosa.set_fftlib()
    """
    global __FFTLIB
    if lib is None:
        lib = scipy.fft

    __FFTLIB = lib


def get_fftlib() -> ModuleType:
    """Get the FFT library currently used by librosa

    Returns
    -------
    fft : module
        The FFT library currently used by librosa.
        Must API-compatible with `numpy.fft`.
    """
    if __FFTLIB is None:
        # This path should never occur because importing
        # this module will call set_fftlib
        assert False  # pragma: no cover

    return __FFTLIB