Skip to content

Commit

Permalink
Small improvement for transpose function
Browse files Browse the repository at this point in the history
  • Loading branch information
okuta committed Aug 20, 2017
1 parent 2de0c34 commit 2fcb74e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions chainer/functions/array/transpose.py
Expand Up @@ -23,13 +23,11 @@ def forward(self, inputs):
return y,

def backward(self, indexes, grad_outputs):
gy = grad_outputs[0]
inv_axes = self.axes
if self.axes:
axes = tuple(ax % len(self.axes) for ax in self.axes)
inv_axes = tuple(numpy.argsort(axes))
gx = transpose(gy, inv_axes)
return gx,
if inv_axes:
axes_len = len(inv_axes)
inv_axes = tuple(numpy.argsort([ax % axes_len for ax in inv_axes]))
return Transpose(inv_axes).apply(grad_outputs)


def transpose(x, axes=None):
Expand Down

0 comments on commit 2fcb74e

Please sign in to comment.