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

Add diagflat complex support #47564

Closed

Conversation

rjkilpatrick
Copy link
Contributor

Adds complex numbers support for torch.diag

>>> import torch
>>> a = torch.ones(2, dtype=torch.complex128)
>>> torch.diagflat(a)
tensor([[1.+0.j, 0.+0.j],
        [0.+0.j, 1.+0.j]], dtype=torch.complex128)
>>> b = a.cuda()
>>> torch.diagflat(b)
tensor([[1.+0.j, 0.+0.j],
        [0.+0.j, 1.+0.j]], device='cuda:0', dtype=torch.complex128)

Note that automatic differentiation isn't implemented:

>>> d = torch.ones(1, dtype=torch.complex128, requires_grad=True)
>>> torch.diagflat(d)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: diag does not support automatic differentiation for outputs with complex dtype.

Fixes #47499

@dr-ci
Copy link

dr-ci bot commented Nov 7, 2020

💊 CI failures summary and remediations

As of commit 5917c83 (more details on the Dr. CI page):


None of the CI failures appear to be your fault 💚



🚧 1 ongoing upstream failure:

These were probably caused by upstream breakages that are not fixed yet:


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 1 time.

@anjali411
Copy link
Contributor

@rjkilpatrick is this PR ready for review?

@rjkilpatrick
Copy link
Contributor Author

rjkilpatrick commented Nov 9, 2020

@anjali411 this issue is ready to be reviewed.

The complex autograd should be a separate issue.

@heitorschueroff
Copy link
Contributor

@albanD can you please advise whether we can leave autograd support for a later PR?

@heitorschueroff heitorschueroff added module: complex Related to complex number support in PyTorch triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Nov 9, 2020
@anjali411
Copy link
Contributor

torch.diagflat calls torch.diag so it's ok to not add autograd support for torch.diagflat in this PR. let's add that in a follow-up PR

Copy link
Contributor

@anjali411 anjali411 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anjali411 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@anjali411 merged this pull request in 8aca85d.

@albanD
Copy link
Collaborator

albanD commented Nov 10, 2020

@anjali411 the autograd should be disabled anyways as it is not in the whitelist right?

@anjali411
Copy link
Contributor

@albanD diagflat calls diag whose backward uses diagonal which is supported for complex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed Merged module: complex Related to complex number support in PyTorch open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

diagflat not implemented for Complex type
6 participants