asteroid-team / asteroid

The PyTorch-based audio source separation toolkit for researchers
https://asteroid-team.github.io/
MIT License
2.25k stars 421 forks source link

Fixed a bug caused by a type error #696

Closed Xinyi-Cheng closed 6 months ago

Xinyi-Cheng commented 6 months ago

This commit addresses a specific TypeError encountered in the LibriMix.__getitem__ method when using the random.randint function. The error was triggered by passing a numpy.float64 type argument to random.randint, which expects integer arguments to generate a random integer between two specified integer values. The problematic code snippet was:

start = random.randint(0, row["length"] - self.seg_len)

Here, the operation between row["length"] and self.seg_len could result in a floating-point number, while random.randint requires integer inputs. To resolve this issue, the code has been modified to explicitly convert the result of row["length"] - self.seg_len to an integer using the int() function, as shown below:

start = random.randint(0, int(row["length"] - self.seg_len))

This modification ensures that the input to random.randint is always an integer, irrespective of the original data types involved, thus preventing the TypeError.

mpariente commented 6 months ago

Thank you very much for your contribution and clear explanation, it's perfect. Please remove all the .DS_Store file from the PR, and this is ready to be merged.

Xinyi-Cheng commented 6 months ago

Hi, sorry for .DS_Store files. I have corrected them in the latest commit.