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

Advanced Indexing Error #2316

Closed
snowyday opened this issue Aug 7, 2017 · 14 comments
Closed

Advanced Indexing Error #2316

snowyday opened this issue Aug 7, 2017 · 14 comments

Comments

@snowyday
Copy link

snowyday commented Aug 7, 2017

Grateful thanks for new various features!

Advanced Indexing does not support vector?:

>>> x = torch.Tensor(5)
>>> x[[0, 3]]

Traceback (most recent call last):
File "", line 1, in
TypeError: indexing a tensor with an object of type list. The only supported types are integers, slices,, numpy scalars and torch.LongTensor or torch.ByteTensor as the only argument.

@chenzhekl
Copy link

chenzhekl commented Aug 7, 2017

Related to #2305. Use x[[0, 3], ] instead.

@snowyday
Copy link
Author

snowyday commented Aug 7, 2017

@chenzhekl Thank you!!
But, I think the expression is non-trivial.
Numpy supports both expressions:

>>> numpy.zeros(5)
array([ 0.,  0.,  0.,  0.,  0.])
>>> x = numpy.zeros(5)
>>> x[[0, 3]]
array([ 0.,  0.])
>>> x[[0, 3], ]
array([ 0.,  0.])

Is there any reason not to support the simple expression such as x[[0, 3]]?

@killeent
Copy link
Contributor

killeent commented Aug 7, 2017

@snowyday by definition, advanced indexing requires a sequence, so the behavior without sequences in PyTorch is unchanged. The currently supported way of doing what you want is:

x = torch.Tensor(5)
x[torch.LongTensor([0, 3])]

@fmassa
Copy link
Member

fmassa commented Aug 7, 2017

@killeent Numpy seems not to use tuples for advanced indexing, but lists or arrays
So

a = np.random.rand(3,3)
a[[1, 2]] == a[np.array([1, 2])] != a[(1, 2)]

Can't we modify the behavior in pytorch to be more in line with numpy's?

@apaszke
Copy link
Contributor

apaszke commented Aug 7, 2017

We should fix that to work as in numpy

@killeent
Copy link
Contributor

killeent commented Aug 7, 2017

@fmassa can you clarify what the difference is in behavior for PyTorch?

@killeent
Copy link
Contributor

killeent commented Aug 7, 2017

Actually, to correct myself, I guess this is considered a form of advanced indexing, so I will address this either way...

@vadimkantorov
Copy link
Contributor

vadimkantorov commented Aug 7, 2017

A few other things that don't work:

a = torch.zeros(2, 2)

a[[0,1], 0]                        # doesn't work
a[torch.LongTensor([0, 1]), 0]     # doesn't work
a[torch.LongTensor([0, 1])][:, 0]  # works

a[[0, 1]][:, 0]                    # doesn't work
a[[0, 1], :1]                      # doesn't work
a[[0, 1], 0:1]                     # doesn't work
a[[0, 1], 0:2]                     # works

@killeent
Copy link
Contributor

killeent commented Aug 7, 2017

@vadimkantorov this is to be expected. We only support a subset of advanced indexing - including no mixing of basic and advanced indexing, or support for non-empty slice objects.

@snowyday
Copy link
Author

snowyday commented Aug 8, 2017

@killeent Thank you so much for #2323!

@snowyday snowyday closed this as completed Aug 8, 2017
zou3519 pushed a commit to zou3519/pytorch that referenced this issue Mar 30, 2018
scope.CurrentDeviceScope() can return a None type, which was not considered.
@micklexqg
Copy link

@chenzhekl , why x[[0,3],] still does not work....
image

@fmassa
Copy link
Member

fmassa commented May 12, 2018

@micklexqg are you using pytorch 0.4?

@micklexqg
Copy link

@fmassa , no, maybe 0.2. so it need to be under pytorch 0.4?

@fmassa
Copy link
Member

fmassa commented May 13, 2018

Preferably. Full support for advanced indexing was added in 0.4
Previous versions had some support for it, but many cases were missing

houseroad added a commit to houseroad/pytorch that referenced this issue Sep 17, 2019
…bcc3b0 (pytorch#26309)

Summary:
Pull Request resolved: pytorch#26309

Previous import was 95252c2adec185e305e34486c6756ece9aa8f57f

Included changes:
- **[1316afc9](onnx/onnx@1316afc9)**: Update IR doc to clarify initializers are permitted as node inputs (pytorch#2320) <G. Ramalingam>
- **[5e920d0c](onnx/onnx@5e920d0c)**: Avoid uses of special chars (pytorch#2315) <Wei-Sheng Chin>
- **[2fa08b0f](onnx/onnx@2fa08b0f)**: Regenerate ONNX proto and add release date to ver 6 IR (pytorch#2316) <Wei-Sheng Chin>
- **[adf9c7a3](onnx/onnx@adf9c7a3)**: Add description of default type about y_zero_point (pytorch#2110) <Takeshi Watanabe>
- **[ee7072c7](onnx/onnx@ee7072c7)**: Support make_attribute empty string (pytorch#2129) <shjwudp>
- **[f913b6e7](onnx/onnx@f913b6e7)**: More unsqueeze tests (pytorch#2200) <James Allingham>
- **[57b51937](onnx/onnx@57b51937)**: Fix resize shape inference issue in opset10 (pytorch#2294) <Bowen Bao>
- **[d7595f34](onnx/onnx@d7595f34)**: Sequence related ops (pytorch#2249) <Bowen Bao>
- **[599f3da9](onnx/onnx@599f3da9)**: Add helper function update_inputs_outputs_dims to tools (pytorch#2148) <Bowen Bao>
- **[3e6382bc](onnx/onnx@3e6382bc)**: Update documentation about required input output types (pytorch#2310) <G. Ramalingam>
- **[0c765d9b](onnx/onnx@0c765d9b)**: Shape inference for NMS (pytorch#2269) <Hariharan Seshadri>
- **[89266710](onnx/onnx@89266710)**: Fix extra collect_snippets warning (pytorch#2277) (pytorch#2307) <Lutz Roeder>

Test Plan: ci

Reviewed By: hl475

Differential Revision: D17403954

fbshipit-source-id: 8f7cbf77b7e09b73db2015f3e0f436772482b322
facebook-github-bot pushed a commit that referenced this issue Sep 17, 2019
…bcc3b0 (#26309)

Summary:
Pull Request resolved: #26309

Previous import was 95252c2adec185e305e34486c6756ece9aa8f57f

Included changes:
- **[1316afc9](onnx/onnx@1316afc9)**: Update IR doc to clarify initializers are permitted as node inputs (#2320) <G. Ramalingam>
- **[5e920d0c](onnx/onnx@5e920d0c)**: Avoid uses of special chars (#2315) <Wei-Sheng Chin>
- **[2fa08b0f](onnx/onnx@2fa08b0f)**: Regenerate ONNX proto and add release date to ver 6 IR (#2316) <Wei-Sheng Chin>
- **[adf9c7a3](onnx/onnx@adf9c7a3)**: Add description of default type about y_zero_point (#2110) <Takeshi Watanabe>
- **[ee7072c7](onnx/onnx@ee7072c7)**: Support make_attribute empty string (#2129) <shjwudp>
- **[f913b6e7](onnx/onnx@f913b6e7)**: More unsqueeze tests (#2200) <James Allingham>
- **[57b51937](onnx/onnx@57b51937)**: Fix resize shape inference issue in opset10 (#2294) <Bowen Bao>
- **[d7595f34](onnx/onnx@d7595f34)**: Sequence related ops (#2249) <Bowen Bao>
- **[599f3da9](onnx/onnx@599f3da9)**: Add helper function update_inputs_outputs_dims to tools (#2148) <Bowen Bao>
- **[3e6382bc](onnx/onnx@3e6382bc)**: Update documentation about required input output types (#2310) <G. Ramalingam>
- **[0c765d9b](onnx/onnx@0c765d9b)**: Shape inference for NMS (#2269) <Hariharan Seshadri>
- **[89266710](onnx/onnx@89266710)**: Fix extra collect_snippets warning (#2277) (#2307) <Lutz Roeder>

Test Plan: ci

Reviewed By: hl475

Differential Revision: D17403954

fbshipit-source-id: 78a9c3ecf5aa7f7a0ba8ea30286eab61ee903772
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants