Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Alias torch.diagonal, torch.diagflat#5622

Merged
soumith merged 2 commits into
pytorch:masterfrom
zou3519:better-diags
Mar 10, 2018
Merged

Alias torch.diagonal, torch.diagflat#5622
soumith merged 2 commits into
pytorch:masterfrom
zou3519:better-diags

Conversation

@zou3519
Copy link
Copy Markdown
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

Comment thread aten/src/ATen/native/TensorShape.cpp Outdated
}

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

This comment was marked as off-topic.

Comment thread torch/_torch_docs.py Outdated
-1.0817
[torch.FloatTensor of size 3]

>>> torch.diag(a, 1)

This comment was marked as off-topic.

@colesbury
Copy link
Copy Markdown
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
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
* Alias torch.diagonal, torch.diagflat

* Address comments; Add sanity tests for torch.diagonal and torch.diagflat
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