Class: Chainer::Functions::Array::Transpose
- Inherits:
-
Chainer::FunctionNode
- Object
- Chainer::FunctionNode
- Chainer::Functions::Array::Transpose
- Defined in:
- lib/chainer/functions/array/transpose.rb
Overview
Permute the dimensions of an array.
Instance Attribute Summary
Attributes inherited from Chainer::FunctionNode
Class Method Summary collapse
-
.transpose(x, axes: nil) ⇒ Chainer::Variable
Permute the dimensions of an input variable without copy.
Instance Method Summary collapse
- #backward(indexes, grad_outputs) ⇒ Object
- #forward(inputs) ⇒ Object
-
#initialize(axes: nil) ⇒ Transpose
constructor
A new instance of Transpose.
- #label ⇒ Object
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.
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 |
#label ⇒ Object
20 21 22 |
# File 'lib/chainer/functions/array/transpose.rb', line 20 def label 'Transpose' end |