-
Notifications
You must be signed in to change notification settings - Fork 661
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
Fix load from file object for small files and shorter bytes #1181
Conversation
823265e
to
07da48d
Compare
4a1640d
to
cbaa492
Compare
a67210d
to
dd92058
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I left only 2 non-blocking comments.
// * This can be changed with `torchaudio.utils.sox_utils.set_buffer_size`. | ||
auto capacity = | ||
(sox_get_globals()->bufsiz > 256) ? sox_get_globals()->bufsiz : 256; | ||
std::string buffer(capacity, '\0'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps there is a better type on std instead of string to define your buffer? Perhaps py::bytes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the implementation of py::bytes
, they do not provide direct access to the underlying memory. The only way to get an access to the memory is converting it to std::string
. So I think it is straightforward to use std::string
97f4b51
to
f858a4b
Compare
* Update index.rst * Delete aws_distributed_training_tutorial.py
In #1158 file-like object support was added to
load
function.The code works an object that implements
read
protocolread(size: int) -> bytes
.The implementation expected that the
read
method will always returns thebytes
with the exact requested length, but that should not be required.This PR relax it with couple of tweaks.
read_fileobj
helper function that callsread
and retry until the requested length is fetched / EOF is reached.