-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Add torch.take and Tensor.put_ #3263
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
Conversation
|
Two differences from the NumPy implementations: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.take.html
|
apaszke
left a comment
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.
Looks good in general. A few minor comments. BTW putScalar might be useful as well
torch/lib/TH/generic/THTensorMath.c
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/lib/TH/generic/THTensorMath.c
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/lib/TH/generic/THTensorMath.c
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/lib/THC/THCTensorIndex.cu
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/lib/THC/THCTensorIndex.cu
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/lib/TH/generic/THTensorMath.c
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/lib/TH/generic/THTensorMath.c
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
087ff0f to
05ff99e
Compare
6a5036a to
a5caa6a
Compare
|
I've added an accumulate option to (The accumulate=True option is substantially slower, so accumulate is False by default). |
These are similar to numpy.take and numpy.put. The take function allows you to linearly index into a tensor without viewing it as a 1D tensor first. The output has the same shape as the indices. The put function copies value into a tensor also using linear indices.
I have no idea how it worked on cuda 8, but apparently this fixes failures on cuda 9. cc @colesbury
I have no idea how it worked on cuda 8, but apparently this fixes failures on cuda 9. cc @colesbury
I have no idea how it worked on cuda 8, but apparently this fixes failures on cuda 9. cc @colesbury
|
@colesbury thanks for this work and especially the accumulate option. Are there any plans to add an axis argument to put_ as well? Specifying the index for each individual element of a tensor can take quite a lot of place in memory. |
|
It'd be nice to have an |
|
From what I see, numpy doesn't have an |
I have no idea how it worked on cuda 8, but apparently this fixes failures on cuda 9. cc @colesbury
These are similar to numpy.take and numpy.put. The take function allows
you to linearly index into a tensor without viewing it as a 1D tensor
first. The output has the same shape as the indices. The put function
copies value into a tensor also using linear indices.
I'll add these to ATen+Variable in a subsequent PR