Movement Operations

Operations like transpose, reshape and squeeze only move the elements to other locations. The number of elements would not change after these operations. The back propagation of a movement is another movement, and more specifically, its inverse operation.

transpose

The inverse operation of transpose is transpose.

class auto_diff.OpTranspose(x: auto_diff.op.operation.Operation, axes: Optional[Sequence[int]] = None, **kwargs)[source]

Bases: auto_diff.op.operation.Operation

Transpose the tensor.

Basic operation without axes:

Y=XT

Partial derivative of a single element:

Lxij=i,jLyijyijxij=Lyjiyjixij=Lyjixijxij=Lyji

Matrix derivative:

LX=(LY)T

Generally, axes should be a permutation of the dimensions, suppose there is a function f that maps from (0,1,,k) to the new permutation, then this transpose operation would be:

yi1,i2,,ik=xf(i1),f(i2),,f(ik)

The partial derivative of xi1,i2,,ik is 1 only with yf(i1)1,f(i2)1,,f(ik)1. Therefore the derivative should be another transpose operation with inverse mapping function f1.

__init__(x: auto_diff.op.operation.Operation, axes: Optional[Sequence[int]] = None, **kwargs)[source]
Parameters:
  • x – Input operation.
  • axes – A permutation of dimensions. The dimensions will be reversed if it is None.
  • kwargs – Arguments for parent.