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

bytearray(tensor) behaves very differently from bytearray(tensor.numpy()) #33041

Open
vadimkantorov opened this issue Feb 6, 2020 · 3 comments
Labels
module: numpy Related to numpy support, and also numpy compatibility of our operators module: printing Issues related to the printing format of tensors triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@vadimkantorov
Copy link
Contributor

vadimkantorov commented Feb 6, 2020

import torch

a = torch.ShortTensor([10000])
print(bytearray(a.numpy()))
# bytearray(b"\x10\'")

print(bytearray(a))
# bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 ............')

I thought this is the Python prescribed interface of getting byte representation of some object, but this fails with PyTorch arrays. My goal is to pass the obtained byte array or byte string to webrtcvad method working with audio byte frames.

Related: https://discuss.pytorch.org/t/getting-tensor-raw-data/18961/2

cc @mruberry @rgommers @heitorschueroff

@fmassa fmassa added module: operators small We think this is a small issue to fix. Consider knocking off high priority small issues triage review labels Feb 10, 2020
@fmassa
Copy link
Member

fmassa commented Feb 10, 2020

I think it would be good to make the behavior consistent (including bytes)

@fmassa fmassa added enhancement Not as big of a feature, but technically not a bug. Should be easy to fix module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module and removed triage review labels Feb 10, 2020
@vadimkantorov
Copy link
Contributor Author

Same problem with bytes(...) method

@vadimkantorov
Copy link
Contributor Author

However, with torch.ByteTensor, it seems to work okay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: numpy Related to numpy support, and also numpy compatibility of our operators module: printing Issues related to the printing format of tensors triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants