<commit_before># Lint as: python3
"""Tests for spectral."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import os

import spectral


class SpectralTest(tf.test.TestCase):

    def test_give_me_a_name(self):
        pass


if __name__ == '__main__':
    os.environ["CUDA_VISIBLE_DEVICES"] = ''
    tf.test.main()<commit_msg>Work on utils/spectral Tests<commit_after># Lint as: python3
"""Tests for spectral."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf
import numpy as np
import os

import spectral


class SpectralTest(tf.test.TestCase):

    def test_waveform_to_spectogram_shape(self):
        waveform = np.random.normal(size=(2**14,))
        spectogram = spectral.waveform_2_spectogram(waveform, frame_length=512, frame_step=128)
        
        self.assertEqual((128, 256, 2), spectogram.shape)
        
    def test_waveform_to_magnitude_shape(self):
        waveform = np.random.normal(size=(2**14,))
        magnitude = spectral.waveform_2_magnitude(waveform, frame_length=512, frame_step=128)
        
        self.assertEqual((128, 256), magnitude.shape)
        
    def test_waveform_to_spectogram_return(self):
        waveform = np.random.normal(size=(2**14,))
        spectogram = spectral.waveform_2_spectogram(waveform, frame_length=512, frame_step=128)
        waveform_hat = spectral.spectogram_2_waveform(spectogram, frame_length=512, frame_step=128)
        
        # Account for extra samples from reverse transform
        waveform_hat = waveform[0:len(waveform)]
        
        self.assertAllClose(waveform, waveform_hat)
        
    def test_waveform_to_magnitude_return(self):
        waveform = np.random.normal(size=(2**14,))
        spectogram = spectral.waveform_2_magnitude(waveform, frame_length=512, frame_step=128)
        waveform_hat = spectral.magnitude_2_waveform(spectogram, frame_length=512, frame_step=128)
        
        # Account for extra samples from reverse transform
        waveform_hat = waveform[0:len(waveform)]
        
        self.assertAllClose(waveform, waveform_hat)
        


if __name__ == '__main__':
    os.environ["CUDA_VISIBLE_DEVICES"] = ''
    tf.test.main()
{'fraction_non_alphanumeric': 0.09283246977547496, 'fraction_numerical': 0.03065630397236615, 'mean_word_length': 3.6997971602434077, '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': '1168138', 'n_tokens_mistral': 765, 'n_tokens_neox': 711, 'n_words': 146}