Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse causes negative stride error when converting to tensors #284

Open
aaprasad opened this issue Jun 22, 2023 · 1 comment
Open

Reverse causes negative stride error when converting to tensors #284

aaprasad opened this issue Jun 22, 2023 · 1 comment

Comments

@aaprasad
Copy link

When using audiomentations.Reverse() and then converting to a tensor it leads to a ValueError: At least one stride in the given numpy array is negative, and tensors with negative strides are not currently supported. (You can probably work around this by making a copy of your array with array.copy().). This is solved by converting the array using np.ascontiguousarray but might be nice to handle Reverse differently as to not cause the issue in the first place?

@iver56
Copy link
Owner

iver56 commented Jun 22, 2023

Can you show me the code snippet that reproduces this issue?

If I remember correctly, Reverse uses the fast way of reversing the waveform, which does not move the array data around in memory, but just changes the indexing. This often works well, but if you want to convert it to a torch tensor afterwards, you do indeed have to call .copy() on it for it to work, as it says in the error msg.

The alternative would be to always use the slow approach, which moves data around instead of just changing the indexing.

Slow implementation:

  • Makes it slow for everyone
  • Compatible with torch.from_numpy without any extra code

Fast implementation:

  • Fast for most use cases
  • Slow only if you need to .copy() it (e.g. for torch.from_numpy())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants