Skip to content

torch.sgn: Vectorized path returns different output from Non-Vectorized path for INF input #53958

@kshitij12345

Description

@kshitij12345

This behavior leads to failure in testing for CPU where nan's are tested for equality with strictness.

import torch

t = torch.tensor([complex(0, float('inf'))] * 4)
out_non_vec = torch.sgn(t)
ref = torch.tensor([complex(float('nan'), float('nan'))] * 4)

print(out_non_vec)
are_equal, msg = torch.testing._compare_tensors_internal(out_non_vec, ref, equal_nan=True, rtol=0, atol=0)
print("EQUAL:", are_equal)

t = torch.tensor([complex(0, float('inf'))] * 9)
out_vec = torch.sgn(t)
ref = torch.tensor([complex(float('nan'), float('nan'))] * 9)

print(out_vec)
are_equal, msg = torch.testing._compare_tensors_internal(out_vec, ref, equal_nan=True, rtol=0, atol=0)
print("EQUAL:", are_equal)

Output:

tensor([nan+nanj, nan+nanj, nan+nanj, nan+nanj])
EQUAL: True
tensor([0.+nanj, 0.+nanj, 0.+nanj, 0.+nanj, 0.+nanj, 0.+nanj, 0.+nanj, 0.+nanj, nan+nanj])
EQUAL: False

cc @ezyang @anjali411 @dylanbespalko @mruberry

Metadata

Metadata

Assignees

Labels

module: NaNs and InfsProblems related to NaN and Inf handling in floating pointmodule: complexRelated to complex number support in PyTorchtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions