Class: Chainer::Functions::Array::Transpose

Inherits:
Chainer::FunctionNode show all
Defined in:
lib/chainer/functions/array/transpose.rb

Overview

Permute the dimensions of an array.

Instance Attribute Summary

Attributes inherited from Chainer::FunctionNode

#inputs, #outputs, #rank

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Chainer::FunctionNode

#apply, #backward_accumulate, #forward_cpu, #get_retained_inputs, #get_retained_outputs, #output_data, #retain_inputs, #retain_outputs, #unchain

Constructor Details

#initialize(axes: nil) ⇒ Transpose

Returns a new instance of Transpose.



16
17
18
# File 'lib/chainer/functions/array/transpose.rb', line 16

def initialize(axes: nil)
  @axes = axes
end

Class Method Details

.transpose(x, axes: nil) ⇒ Chainer::Variable

Permute the dimensions of an input variable without copy.

Parameters:

  • x (Chainer::Variable)

    Input Variable.

  • axes (::Array<Integer>) (defaults to: nil)

    By default, reverse the dimensions, otherwise permute the axes according to the values given.

Returns:



12
13
14
# File 'lib/chainer/functions/array/transpose.rb', line 12

def self.transpose(x, axes: nil)
  Transpose.new(axes: axes).apply([x]).first
end

Instance Method Details

#backward(indexes, grad_outputs) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# 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) ⇒ Object



24
25
26
27
# File 'lib/chainer/functions/array/transpose.rb', line 24

def forward(inputs)
  x = inputs.first
  [x.transpose(*@axes)]
end

#labelObject



20
21
22
# File 'lib/chainer/functions/array/transpose.rb', line 20

def label
  'Transpose'
end