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

torch_frontend.Tensor.is_conj #28789

Open
Sam-Armstrong opened this issue Jul 11, 2024 · 1 comment
Open

torch_frontend.Tensor.is_conj #28789

Sam-Armstrong opened this issue Jul 11, 2024 · 1 comment
Labels
PyTorch Frontend Developing the PyTorch Frontend, checklist triggered by commenting add_frontend_checklist

Comments

@Sam-Armstrong
Copy link
Contributor

Sam-Armstrong commented Jul 11, 2024

torch.Tensor.is_conj() needs to be implemented in the torch frontend in order to write a frontend for torch.resolve_conj.

cc #26935

@Sam-Armstrong Sam-Armstrong added the PyTorch Frontend Developing the PyTorch Frontend, checklist triggered by commenting add_frontend_checklist label Jul 11, 2024
@yugborana
Copy link

Hey @Sam-Armstrong I would like to work on this issue.
This is the code I would like to propose for the above issue...

def is_conj(input):
"""
Returns a single boolean indicating whether the entire input tensor represents conjugate values.

If the input tensor has an explicit `is_conj` attribute, this function will simply return it.
Otherwise, it will try to infer the conjugacy by checking the imaginary component of complex tensors.
"""
if hasattr(input, 'is_conj'):
    # If the tensor has an explicit `is_conj` attribute, use it
    return input.is_conj
else:
    # If no explicit conjugacy state, infer it from the tensor data
    if torch.is_complex(input):
        # For complex tensors, check if the imaginary component is zero for all elements
        return torch.all(torch.abs(input.imag) < 1e-8)
    else:
        # For real tensors, all elements are conjugate
        return True

If the proposed solution is correct, should I raise the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PyTorch Frontend Developing the PyTorch Frontend, checklist triggered by commenting add_frontend_checklist
Projects
None yet
Development

No branches or pull requests

2 participants