Skip to content

Commit

Permalink
Merge pull request #3154 from okuta/improve-transpose
Browse files Browse the repository at this point in the history
Small improvement for transpose function
  • Loading branch information
rezoo committed Aug 21, 2017
2 parents 89f6e79 + 2fcb74e commit ac9ff1a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions chainer/functions/array/transpose.py
Original file line number Diff line number Diff line change
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 ac9ff1a

Please sign in to comment.