Skip to content

Conversation

@zou3519
Copy link
Contributor

@zou3519 zou3519 commented Mar 7, 2018

Fixes #3213

This adds torch.diagonal and torch.diagflat (like in numpy) to solve the problem that torch.diag is unintuitive to users and performs two functions. The implementations of torch.diagonal and torch.diagflat just call torch.diag.

I'm not sure if this is the best idea to solve the problem of torch.diag being weird to users because this does complicate the API (with this change, there will be 3 diag functions). If we think this is a good idea, I'll add some quick sanity tests to test_torch and test_cuda to check that torch.diagonal and torch.diagflat do what they're supposed to.

cc @gchanan @colesbury

}

Tensor diagflat(const Tensor& self, int64_t offset) {
return self.view(-1).diag(offset);

This comment was marked as off-topic.

-1.0817
[torch.FloatTensor of size 3]
>>> torch.diag(a, 1)

This comment was marked as off-topic.

@colesbury
Copy link
Member

I think this is a good idea. It's worth adding the sanity checks.

@soumith soumith merged commit 74043b6 into pytorch:master Mar 10, 2018
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 this pull request may close these issues.

3 participants