iver56 / audiomentations

A Python library for audio data augmentation. Inspired by albumentations. Useful for machine learning.
https://iver56.github.io/audiomentations/
MIT License
1.76k stars 183 forks source link

test_simulate_apply_parity failure #317

Closed atamazian closed 4 months ago

atamazian commented 4 months ago

When running pytest on the current version, I'm getting this error:

__________________________________________________ TestRoomSimulatorTransform.test_simulate_apply_parity __________________________________________________

self = <tests.test_room_simulator.TestRoomSimulatorTransform object at 0x0000025D1384DC30>

    def test_simulate_apply_parity(self):
        """
        Tests whether RoomSimulator.apply gives the same result as Roomsimulator.room.simulate() in the 1D case.

        This mainly tests that we took into consideration and compensated about the delays introduced when pyroomacoustics
        computes the room impulse response.

        See:[Create the Room Impulse Response](https://pyroomacoustics.readthedocs.io/en/pypi-release/pyroomacoustics.room.html?highlight=simulate#)
        """

        random.seed(1)
        sample_rate = 16000
        samples = get_sinc_impulse(sample_rate, 10)

        augment = RoomSimulator()
        augmented_samples_apply = augment(samples=samples, sample_rate=sample_rate)
        augment.room.simulate()
        augmented_samples_simulate = augment.room.mic_array.signals.astype(
            np.float32
        ).flatten()

>       assert np.all(augmented_samples_apply == augmented_samples_simulate)
E       assert False
E        +  where False = <function all at 0x0000025D0F41F530>(array([-2.212...dtype=float32) == array([-2.212...dtype=float32)
E        +    where <function all at 0x0000025D0F41F530> = np.all
E
E           Use -v to get more diff)

tests\test_room_simulator.py:43: AssertionError

Can you check this out?

iver56 commented 4 months ago

I tried to run the test suite with the following versions of pyroomacoustics, and the tests were green in all cases on my end:

@atamazian Could you provide some more info about your environment? Like python version, operating system and the output of pip freeze?

@mmxgn Do you think it could be a numerical inaccuracy in this case? Maybe we should switch from np.all to pytest.approx with a very small error tolerance?

atamazian commented 4 months ago

Python 3.10.13, miniforge3 Windows 10 Home x64 [Version 10.0.19045.4046]

As for the list of Python packages, it's too long to post it here. Just tell me, in what packages are you interested in.

UPD. I have pyroomacoustics 0.7.3

iver56 commented 4 months ago

Hmm, My hunch is that there is merely a numerical inaccuracy somewhere. To check this hyphothesis, I would like some help from you: Could you comment out the failing assert, and add two lines for dumping the two arrays to disk? Like:

joblib.dump(augmented_samples_apply, "augmented_samples_apply.pkl")
joblib.dump(augmented_samples_simulate, "augmented_samples_simulate.pkl")

Then please zip the two files and attach it in a comment here

atamazian commented 4 months ago

dumps.zip

iver56 commented 4 months ago

Thanks! Fixed