<commit_before>""" Module for calculating DCT type 4 using FFT and pre/post-twiddling

"""

from __future__ import division
import numpy
import scipy

__all__ = [
    'mdct', 'imdct',
    'mdst', 'imdst',
    'cmdct', 'icmdct',
]


def mdct(x):
    """ Calculate modified discrete cosine transform of input signal

    Parameters
    ----------
    X : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    return numpy.real(cmdct(x))


def imdct(X):
    """ Calculate inverse modified discrete cosine transform of input signal

    Parameters
    ----------
    X : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    return numpy.real(icmdct(X))


def mdst(x):
    """ Calculate modified discrete sine transform of input signal

    Parameters
    ----------
    X : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    return numpy.imag(cmdct(x))


def imdst(X):
    """ Calculate inverse modified discrete sine transform of input signal

    Parameters
    ----------
    X : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    return numpy.imag(icmdct(X))


def cmdct(x):
    """ Calculate complex MDCT of input signal

    Parameters
    ----------
    x : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    N = len(x)
    n0 = (N / 2 + 1) / 2

    X = scipy.fftpack.fft(
        x * numpy.exp(-1j * 2 * numpy.pi * numpy.arange(N) / 2 / N)
    )

    return X[:N/2] * numpy.exp(
        -1j * 2 * numpy.pi * n0 * (numpy.arange(N / 2) + 0.5) / N
    )


def icmdct(X):
    """ Calculate inverse complex MDCT of input signal

    Parameters
    ----------
    X : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    N = 2 * len(X)
    n0 = (N / 2 + 1) / 2

    Y = numpy.zeros(N, dtype=X.dtype)

    Y[:N/2] = X
    Y[N/2:] = -1 * X[::-1]

    y = scipy.fftpack.ifft(
        Y * numpy.exp(1j * 2 * numpy.pi * numpy.arange(N) * n0 / N)
    )

    return 2 * y * numpy.exp(
        1j * 2 * numpy.pi * (numpy.arange(N) + n0) / 2 / N
    )<commit_msg>Fixed inverse functions a bit, still failing<commit_after>""" Module for calculating DCT type 4 using FFT and pre/post-twiddling

"""

from __future__ import division
import numpy
import scipy

__all__ = [
    'mdct', 'imdct',
    'mdst', 'imdst',
    'cmdct', 'icmdct',
]


def mdct(x):
    """ Calculate modified discrete cosine transform of input signal

    Parameters
    ----------
    X : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    return numpy.real(cmdct(x))


def imdct(X):
    """ Calculate inverse modified discrete cosine transform of input signal

    Parameters
    ----------
    X : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    return icmdct(X)


def mdst(x):
    """ Calculate modified discrete sine transform of input signal

    Parameters
    ----------
    X : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    return -numpy.imag(cmdct(x))


def imdst(X):
    """ Calculate inverse modified discrete sine transform of input signal

    Parameters
    ----------
    X : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    return icmdct(X)


def cmdct(x):
    """ Calculate complex MDCT of input signal

    Parameters
    ----------
    x : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    N = len(x)
    n0 = (N / 2 + 1) / 2

    X = scipy.fftpack.fft(
        x * numpy.exp(-1j * 2 * numpy.pi * numpy.arange(N) / 2 / N)
    )

    return X[:N/2] * numpy.exp(
        -1j * 2 * numpy.pi * n0 * (numpy.arange(N / 2) + 0.5) / N
    )


def icmdct(X):
    """ Calculate inverse complex MDCT of input signal

    Parameters
    ----------
    X : array_like
        The input signal

    Returns
    -------
    out : array_like
        The output signal

    """
    N = 2 * len(X)
    n0 = (N / 2 + 1) / 2

    Y = numpy.zeros(N, dtype=X.dtype)

    Y[:N/2] = X
    Y[N/2:] = -1 * X[::-1]

    y = scipy.fftpack.ifft(
        Y * numpy.exp(1j * 2 * numpy.pi * n0 * numpy.arange(N) / N)
    )

    return 2 * numpy.real(
        y * numpy.exp(
            1j * 2 * numpy.pi * (numpy.arange(N) + n0) / 2 / N
        )
    )
{'fraction_non_alphanumeric': 0.1422883487007544, 'fraction_numerical': 0.013411567476948869, 'mean_word_length': 1.5869918699186991, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6156369', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1545, 'n_words': 463}