KEMBAR78
Replace sox conversion macros with Tensor op by mthrok · Pull Request #1370 · pytorch/audio · GitHub
Skip to content

Conversation

@mthrok
Copy link
Contributor

@mthrok mthrok commented Mar 7, 2021

SOX_SIGNED_16BIT_TO_SAMPLE and SOX_SIGNED_32BIT_TO_SAMPLE uses left shift on signed integers, which is UB.
This PR replaces them (and other sox macros for uint8 and float as well) with Tensor operations.

mthrok added 2 commits March 8, 2021 15:26
Conversion from signed integer with left shift causes UB (negative left shift)
@mthrok mthrok requested a review from cpuhrsch March 8, 2021 16:21
@mthrok mthrok marked this pull request as ready for review March 8, 2021 16:22
chunk = chunk.to(c10::ScalarType::Double);
chunk *= 2147483648.;
chunk.clamp_(INT32_MIN, INT32_MAX);
chunk = chunk.to(c10::ScalarType::Int);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this will guarantee that chunk is contiguous afterwards. I'd call into "contiguous" anyway to be sure. Same applies for the other cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. will update

@mthrok mthrok merged commit 0ea475a into pytorch:master Mar 8, 2021
@mthrok mthrok deleted the fix-ub branch March 8, 2021 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants