Skip to content

Advanced indexing with uint8 tensor versus int64 tensor is inconsistent #20149

@chenbohua3

Description

@chenbohua3

🐛 Bug

different behavior of slicing tensor with slices in different tensor type

To Reproduce

Steps to reproduce the behavior:

import torch

a = torch.randint(low=1, high=10, size=(2, 3))
print(a)
b = torch.randint(2, (3,), dtype=torch.uint8)
print(b)
a[0, b] = 0
print(a)

Expected behavior

if dtype of b is torch.uint8, it works normally like:

tensor([[9, 5, 3],
        [1, 3, 9]])
tensor([1, 0, 1], dtype=torch.uint8)
tensor([[0, 5, 0],
        [1, 3, 9]])

if I change dtype to torch.int64, it woks differently like:

tensor([[3, 9, 9],
        [8, 7, 7]])
tensor([1, 0, 1])
tensor([[0, 0, 9],
        [8, 7, 7]])

it seems that the value of slices act as slices instead of the position of no-zero elements

Environment

  • PyTorch Version (e.g., 1.0): 1.1.0
  • OS (e.g., Linux): Mac os 10.14.3
  • How you installed PyTorch (conda, pip, source): pip
  • Build command you used (if compiling from source):
  • Python version: 3.6
  • CUDA/cuDNN version: None
  • GPU models and configuration: None
  • Any other relevant information: None

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: advanced indexingRelated to x[i] = y, index functionsmodule: bc-breakingRelated to a BC-breaking changemodule: boolean tensortriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions