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

Alias torch.diagonal, torch.diagflat #5622

Merged
merged 2 commits into from
Mar 10, 2018
Merged

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

@@ -37,6 +37,17 @@ std::vector<Tensor> chunk(const Tensor& self, int64_t chunks, int64_t dim) {
return self.split(split_size, dim);
}

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