Skip to content

[feature request] Reinterpret tensor as different dtype #29013

@vadimkantorov

Description

@vadimkantorov

I'd like to read audio file by using a sox utility directly. Currently I can do it as:

signal = torch.from_numpy(np.frombuffer(subprocess.check_output(['sox', '-V0', audio_path, '-b', '16', '-e', 'signed', '--endian', 'little', '-r', str(sample_rate), '-c', '1', '-t', 'raw', '-'], dtype = np.int16))

Is there a way to reinterpret a torch byte tensor (or python's bytearray(...)) as another type without invoking first NumPy? (or a generic numpy.view(dtype) functionality) If not, I think it'd be quite useful (mainly for integral types, but also maybe for some integer bit-tricks on float32 tensors, which can hopefully be fused by jit)

Also reported in https://discuss.pytorch.org/t/reinterpret-pytorch-array-as-a-different-dtype/24256

This probably can also be helpful for conversions between complex <-> pair or real/imag.

cc @mruberry @rgommers

Metadata

Metadata

Assignees

Labels

function requestA request for a new function or the addition of new arguments/modes to an existing function.module: numpyRelated to numpy support, and also numpy compatibility of our operatorstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions