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

sort bool type has issue #1022

Closed
guizili0 opened this issue Oct 28, 2024 · 0 comments · Fixed by #1037
Closed

sort bool type has issue #1022

guizili0 opened this issue Oct 28, 2024 · 0 comments · Fixed by #1037
Assignees

Comments

@guizili0
Copy link

🐛 Describe the bug

import torch
import random

torch.manual_seed(0)
random.seed(0)

xpu_device = torch.device("xpu")
cpu_device = torch.device("cpu")

#tensor_dtype = torch.int64
tensor_dtype = torch.bool
value_range = 2
a = torch.randint(value_range, (4099,)).to(dtype=tensor_dtype).to(xpu_device)

print(a)
print(a.shape)

for dim in reversed(range(a.dim())):
    #output, output_indices = torch.mode(a, dim)
    #print(output)
    sorted, indices = torch.sort(a)
    print(sorted)
    sorted, indices = a.sort()
    print(sorted)
    sorted, indices = a.sort(stable=True)
    print(sorted)
    sorted_cpu, indices = torch.sort(a.to(cpu_device))
    res = torch.equal(sorted.to(cpu_device), sorted_cpu)
    print(res)

Versions

sort result is wrong:

tensor([False, True, True, ..., False, True, True], device='xpu:0')
torch.Size([4099])
tensor([False, True, True, ..., False, False, False], device='xpu:0')
tensor([False, True, True, ..., False, False, False], device='xpu:0')
tensor([False, True, True, ..., False, False, False], device='xpu:0')
False

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

Successfully merging a pull request may close this issue.

2 participants