Skip to content

Commit

Permalink
torch.diag bug fix (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
NC Cullen authored and soumith committed Apr 13, 2017
1 parent c852883 commit cb66e9c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/test_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,8 @@ def prod_single_zero(dim_size):
(Resize, (S * S, S), ((S, S, S),)),
(Diag, (), ((S, S),), '2d'),
(Diag, (), ((S,),), '1d'),
(Diag, (1,), ((S, S),), '2d_1'),
(Diag, (2,), ((S, S),), '2d_2'),
(Tril, (), ((S, S),)),
(Tril, (2,), ((S, S),), 'idx'),
(Triu, (), ((S, S),)),
Expand Down
4 changes: 2 additions & 2 deletions torch/autograd/_functions/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def __init__(self, diagonal_idx=0):
self.diagonal_idx = diagonal_idx

def forward(self, input):
return input.diag()
return input.diag(self.diagonal_idx)

def backward(self, grad_output):
return grad_output.diag()
return grad_output.diag(self.diagonal_idx)


class Tril(Function):
Expand Down

0 comments on commit cb66e9c

Please sign in to comment.