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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

kthvalue() cannot be used with complex or bool type of a 1D or more D tensor but kthvalue() can be used with complex or bool type of a 0D tensor #126658

Open
hyperkai opened this issue May 20, 2024 · 1 comment
Labels
module: edge cases Adversarial inputs unlikely to occur in practice triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@hyperkai
Copy link

hyperkai commented May 20, 2024

馃悰 Describe the bug

It seems like kthvalue() cannot be used with complex type of a 1D or more D tensor according to the errors as shown below:

complex type of a 1D tensor:

import torch

my_tensor = torch.tensor([0.+0.j, 1.+0.j, 2.+0.j], device='cpu')

torch.kthvalue(input=my_tensor, k=2) # RuntimeError: "kthvalue_cpu" not implemented for 'ComplexFloat'

my_tensor = torch.tensor([0.+0.j, 1.+0.j, 2.+0.j], device='cuda:0')

torch.kthvalue(input=my_tensor, k=2) # RuntimeError: "kthvalue_cuda" not implemented for 'ComplexFloat'

bool type of a 1D tensor:

import torch

my_tensor = torch.tensor([True, False, True], device='cpu')

torch.kthvalue(input=my_tensor, k=2) # RuntimeError: "kthvalue_cpu" not implemented for 'Bool'

my_tensor = torch.tensor([True, False, True], device='cuda:0')

torch.kthvalue(input=my_tensor, k=2) # RuntimeError: "kthvalue_cuda" not implemented for 'Bool'

complex type of a 2D tensor:

import torch

my_tensor = torch.tensor([[0.+0.j, 1.+0.j], [2.+0.j, 3.+0.j]], device='cpu')

torch.kthvalue(input=my_tensor, k=2) # RuntimeError: "kthvalue_cpu" not implemented for 'ComplexFloat'

my_tensor = torch.tensor([[0.+0.j, 1.+0.j], [2.+0.j, 3.+0.j]], device='cuda:0')

torch.kthvalue(input=my_tensor, k=2) # RuntimeError: "kthvalue_cuda" not implemented for 'ComplexFloat'

bool type of a 2D tensor:

import torch

my_tensor = torch.tensor([[True, False], [False, True]], device='cpu')

torch.kthvalue(input=my_tensor, k=2)  # RuntimeError: "kthvalue_cpu" not implemented for 'Bool'

my_tensor = torch.tensor([[True, False], [False, True]], device='cuda:0')

torch.kthvalue(input=my_tensor, k=2) # RuntimeError: "kthvalue_cuda" not implemented for 'Bool'

But kthvalue() can be used with complex or bool type of a 0D tensor as shown below:

complex type of a 0D tensor:

import torch

my_tensor = torch.tensor(0.+0.j, device='cpu')

torch.kthvalue(input=my_tensor, k=1)
# torch.return_types.kthvalue(
# values=tensor(0.+0.j),
# indices=tensor(0))

my_tensor = torch.tensor(0.+0.j, device='cuda:0')

torch.kthvalue(input=my_tensor, k=1)
# torch.return_types.kthvalue(
# values=tensor(0.+0.j, device='cuda:0'),
# indices=tensor(0, device='cuda:0'))

bool type of a 0D tensor:

import torch

my_tensor = torch.tensor(True, device='cpu')

torch.kthvalue(input=my_tensor, k=1)
# torch.return_types.kthvalue(
# values=tensor(True),
# indices=tensor(0))

my_tensor = torch.tensor(True, device='cuda:0')

torch.kthvalue(input=my_tensor, k=1)
# torch.return_types.kthvalue(
# values=tensor(True),
# indices=tensor(0))

Versions

import torch

torch.__version__ # 2.2.1+cu121
@hyperkai hyperkai changed the title kthvalue() cannot be used with complex type of a 1D or 2D tensor but kthvalue() can be used with complex type of a 0D tensor kthvalue() cannot be used with complex or bool type of a 1D or 2D tensor but kthvalue() can be used with complex or bool type of a 0D tensor May 20, 2024
@hyperkai hyperkai changed the title kthvalue() cannot be used with complex or bool type of a 1D or 2D tensor but kthvalue() can be used with complex or bool type of a 0D tensor kthvalue() cannot be used with complex or bool type of a 1D or more D tensor but kthvalue() can be used with complex or bool type of a 0D tensor May 20, 2024
@drisspg
Copy link
Contributor

drisspg commented May 20, 2024

Do these dtypes have a semantic ordering?

@drisspg drisspg added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: edge cases Adversarial inputs unlikely to occur in practice labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: edge cases Adversarial inputs unlikely to occur in practice triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

2 participants