@cache(level=<NUM_LIT:30>)<EOL>def fmt(y, t_min=<NUM_LIT:0.5>, n_fmt=None, kind='<STR_LIT>', beta=<NUM_LIT:0.5>, over_sample=<NUM_LIT:1>, axis=-<NUM_LIT:1>):
n = y.shape[axis]<EOL>if n < <NUM_LIT:3>:<EOL><INDENT>raise ParameterError('<STR_LIT>'.format(axis, n))<EOL><DEDENT>if t_min <= <NUM_LIT:0>:<EOL><INDENT>raise ParameterError('<STR_LIT>')<EOL><DEDENT>if n_fmt is None:<EOL><INDENT>if over_sample < <NUM_LIT:1>:<EOL><INDENT>raise ParameterError('<STR_LIT>')<EOL><DEDENT>log_base = np.log(n - <NUM_LIT:1>) - np.log(n - <NUM_LIT:2>)<EOL>n_fmt = int(np.ceil(over_sample * (np.log(n - <NUM_LIT:1>) - np.log(t_min)) / log_base))<EOL><DEDENT>elif n_fmt < <NUM_LIT:3>:<EOL><INDENT>raise ParameterError('<STR_LIT>'.format(n_fmt))<EOL><DEDENT>else:<EOL><INDENT>log_base = (np.log(n_fmt - <NUM_LIT:1>) - np.log(n_fmt - <NUM_LIT:2>)) / over_sample<EOL><DEDENT>if not np.all(np.isfinite(y)):<EOL><INDENT>raise ParameterError('<STR_LIT>')<EOL><DEDENT>base = np.exp(log_base)<EOL>x = np.linspace(<NUM_LIT:0>, <NUM_LIT:1>, num=n, endpoint=False)<EOL>f_interp = scipy.interpolate.interp1d(x, y, kind=kind, axis=axis)<EOL>n_over = int(np.ceil(over_sample))<EOL>x_exp = np.logspace((np.log(t_min) - np.log(n)) / log_base,<EOL><NUM_LIT:0>,<EOL>num=n_fmt + n_over,<EOL>endpoint=False,<EOL>base=base)[:-n_over]<EOL>if x_exp[<NUM_LIT:0>] < t_min or x_exp[-<NUM_LIT:1>] > float(n - <NUM_LIT:1.0>) / n:<EOL><INDENT>x_exp = np.clip(x_exp, float(t_min) / n, x[-<NUM_LIT:1>])<EOL><DEDENT>if len(np.unique(x_exp)) != len(x_exp):<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>y_res = f_interp(x_exp)<EOL>shape = [<NUM_LIT:1>] * y_res.ndim<EOL>shape[axis] = -<NUM_LIT:1><EOL>fft = get_fftlib()<EOL>return fft.rfft(y_res * ((x_exp**beta).reshape(shape) * np.sqrt(n) / n_fmt),<EOL>axis=axis)<EOL>
The fast Mellin transform (FMT) [1]_ of a uniformly sampled signal y.

    When the Mellin parameter (beta) is 1/2, it is also known as the scale transform [2]_.
    The scale transform can be useful for audio analysis because its magnitude is invariant
    to scaling of the domain (e.g., time stretching or compression).  This is analogous
    to the magnitude of the Fourier transform being invariant to shifts in the input domain.


    .. [1] De Sena, Antonio, and Davide Rocchesso.
        "A fast Mellin and scale transform."
        EURASIP Journal on Applied Signal Processing 2007.1 (2007): 75-75.

    .. [2] Cohen, L.
        "The scale representation."
        IEEE Transactions on Signal Processing 41, no. 12 (1993): 3275-3292.

    Parameters
    ----------
    y : np.ndarray, real-valued
        The input signal(s).  Can be multidimensional.
        The target axis must contain at least 3 samples.

    t_min : float > 0
        The minimum time spacing (in samples).
        This value should generally be less than 1 to preserve as much information as
        possible.

    n_fmt : int > 2 or None
        The number of scale transform bins to use.
        If None, then `n_bins = over_sample * ceil(n * log((n-1)/t_min))` is taken,
        where `n = y.shape[axis]`

    kind : str
        The type of interpolation to use when re-sampling the input.
        See `scipy.interpolate.interp1d` for possible values.

        Note that the default is to use high-precision (cubic) interpolation.
        This can be slow in practice; if speed is preferred over accuracy,
        then consider using `kind='linear'`.

    beta : float
        The Mellin parameter.  `beta=0.5` provides the scale transform.

    over_sample : float >= 1
        Over-sampling factor for exponential resampling.

    axis : int
        The axis along which to transform `y`

    Returns
    -------
    x_scale : np.ndarray [dtype=complex]
        The scale transform of `y` along the `axis` dimension.

    Raises
    ------
    ParameterError
        if `n_fmt < 2` or `t_min <= 0`
        or if `y` is not finite
        or if `y.shape[axis] < 3`.

    Notes
    -----
    This function caches at level 30.


    Examples
    --------
    >>> # Generate a signal and time-stretch it (with energy normalization)
    >>> scale = 1.25
    >>> freq = 3.0
    >>> x1 = np.linspace(0, 1, num=1024, endpoint=False)
    >>> x2 = np.linspace(0, 1, num=scale * len(x1), endpoint=False)
    >>> y1 = np.sin(2 * np.pi * freq * x1)
    >>> y2 = np.sin(2 * np.pi * freq * x2) / np.sqrt(scale)
    >>> # Verify that the two signals have the same energy
    >>> np.sum(np.abs(y1)**2), np.sum(np.abs(y2)**2)
        (255.99999999999997, 255.99999999999969)
    >>> scale1 = librosa.fmt(y1, n_fmt=512)
    >>> scale2 = librosa.fmt(y2, n_fmt=512)
    >>> # And plot the results
    >>> import matplotlib.pyplot as plt
    >>> plt.figure(figsize=(8, 4))
    >>> plt.subplot(1, 2, 1)
    >>> plt.plot(y1, label='Original')
    >>> plt.plot(y2, linestyle='--', label='Stretched')
    >>> plt.xlabel('time (samples)')
    >>> plt.title('Input signals')
    >>> plt.legend(frameon=True)
    >>> plt.axis('tight')
    >>> plt.subplot(1, 2, 2)
    >>> plt.semilogy(np.abs(scale1), label='Original')
    >>> plt.semilogy(np.abs(scale2), linestyle='--', label='Stretched')
    >>> plt.xlabel('scale coefficients')
    >>> plt.title('Scale transform magnitude')
    >>> plt.legend(frameon=True)
    >>> plt.axis('tight')
    >>> plt.tight_layout()

    >>> # Plot the scale transform of an onset strength autocorrelation
    >>> y, sr = librosa.load(librosa.util.example_audio_file(),
    ...                      offset=10.0, duration=30.0)
    >>> odf = librosa.onset.onset_strength(y=y, sr=sr)
    >>> # Auto-correlate with up to 10 seconds lag
    >>> odf_ac = librosa.autocorrelate(odf, max_size=10 * sr // 512)
    >>> # Normalize
    >>> odf_ac = librosa.util.normalize(odf_ac, norm=np.inf)
    >>> # Compute the scale transform
    >>> odf_ac_scale = librosa.fmt(librosa.util.normalize(odf_ac), n_fmt=512)
    >>> # Plot the results
    >>> plt.figure()
    >>> plt.subplot(3, 1, 1)
    >>> plt.plot(odf, label='Onset strength')
    >>> plt.axis('tight')
    >>> plt.xlabel('Time (frames)')
    >>> plt.xticks([])
    >>> plt.legend(frameon=True)
    >>> plt.subplot(3, 1, 2)
    >>> plt.plot(odf_ac, label='Onset autocorrelation')
    >>> plt.axis('tight')
    >>> plt.xlabel('Lag (frames)')
    >>> plt.xticks([])
    >>> plt.legend(frameon=True)
    >>> plt.subplot(3, 1, 3)
    >>> plt.semilogy(np.abs(odf_ac_scale), label='Scale transform magnitude')
    >>> plt.axis('tight')
    >>> plt.xlabel('scale coefficients')
    >>> plt.legend(frameon=True)
    >>> plt.tight_layout()