class Chainer::Functions::Array::Transpose
Permute the dimensions of an array.
Public Class Methods
new(axes: nil)
click to toggle source
# File lib/chainer/functions/array/transpose.rb, line 16 def initialize(axes: nil) @axes = axes end
transpose(x, axes: nil)
click to toggle source
Permute the dimensions of an input variable without copy.
@param [Chainer::Variable] x Input Variable
. @param [::Array<Integer>] axes By default, reverse the dimensions,
otherwise permute the axes according to the values given.
@return [Chainer::Variable] Variable
whose axes are permuted.
# File lib/chainer/functions/array/transpose.rb, line 12 def self.transpose(x, axes: nil) Transpose.new(axes: axes).apply([x]).first end
Public Instance Methods
backward(indexes, grad_outputs)
click to toggle source
# File lib/chainer/functions/array/transpose.rb, line 29 def backward(indexes, grad_outputs) inv_axes = @axes if inv_axes axes_len = inv_axes.size axes = inv_axes.map { |ax| ax % axes_len } inv_axes = Numo::NArray[*axes].sort_index.to_a end Transpose.new(axes: inv_axes).apply(grad_outputs) end
forward(inputs)
click to toggle source
# File lib/chainer/functions/array/transpose.rb, line 24 def forward(inputs) x = inputs.first [x.transpose(*@axes)] end
label()
click to toggle source
# File lib/chainer/functions/array/transpose.rb, line 20 def label 'Transpose' end