Skip to Content

permute_op

View the code on GitHub

Structs

Struct: Permute

Fields

Methods

compute_shape(mut curr: ArrayShape, args: List[ArrayShape])
Permutes the dimensions of an array shape given a list of axes.
Args
  • curr: ArrayShape The ArrayShape to store the result of the computation.

  • args: List[ArrayShape] The ArrayShape to permute, and the list of axes to permute.

Constraints:

  • The number of axes in the list must not exceed the number of dimensions of the ArrayShape.
__call__(mut curr: Array, args: List[Array])
Permutes the input array based on the given axis and stores the result in the current array (curr). The first agument is set as the base of the current array.
Args
  • curr: Array The current array, must be mutable.

  • args: List[Array] The input array and the axis to permute.

jvp(primals: List[Array], tangents: List[Array]) -> Array
more details
Args
  • primals: List[Array]

  • tangents: List[Array]

Returns
  • Array
vjp(primals: List[Array], grad: Array, out: Array) -> List[Array]
Compute vector-Jacobian product for array permutation.
Args
  • primals: List[Array] Primal input arrays.

  • grad: Array Gradient of the output with respect to some scalar function.

  • out: Array The output of the forward pass.

Returns
  • List[Array] - List[Array]: Gradients with respect to each input.

Note: Implements reverse-mode automatic differentiation for permutation. Returns arrays with shape zero for inputs that do not require gradients.

See Also:

permute_jvp: Forward-mode autodiff for permutation.

fwd(arg0: Array, axis: ArrayShape) -> Array
Creates a view of the input array with its dimensions permuted based on the given axis.
Args
  • arg0: Array The input array.

  • axis: ArrayShape The axis to permute.

Returns
  • Array - A view of the input array with its dimensions permuted.

Struct: InvPermute

Fields

Methods

compute_shape(mut curr: ArrayShape, args: List[ArrayShape])
Permutes the dimensions of an array shape given a list of axes, in an inverse manner to the permute_shape function.
Args
  • curr: ArrayShape The ArrayShape to store the result of the computation.

  • args: List[ArrayShape] The ArrayShape to permute, and the list of axes to permute.

Constraints:

  • The number of axes in the list must not exceed the number of dimensions of the ArrayShape.
__call__(mut curr: Array, args: List[Array])
Permutes the input array based on the given axis and stores the result in the current array (curr). The first agument is set as the base of the current array.
Args
  • curr: Array The current array, must be mutable.

  • args: List[Array] The input array and the axis to permute.

jvp(primals: List[Array], tangents: List[Array]) -> Array
more details
Args
  • primals: List[Array]

  • tangents: List[Array]

Returns
  • Array
vjp(primals: List[Array], grad: Array, out: Array) -> List[Array]
Compute vector-Jacobian product for array permutation.
Args
  • primals: List[Array] Primal input arrays.

  • grad: Array Gradient of the output with respect to some scalar function.

  • out: Array The output of the forward pass.

Returns
  • List[Array] - List[Array]: Gradients with respect to each input.

Note: Implements reverse-mode automatic differentiation for permutation. Returns arrays with shape zero for inputs that do not require gradients.

See Also:

permute_inv_jvp: Forward-mode autodiff for permutation.

fwd(arg0: Array, axis: ArrayShape) -> Array
Creates a view of the input array with its dimensions permuted based on the given axis.
Args
  • arg0: Array The input array.

  • axis: ArrayShape The axis to permute.

Returns
  • Array - A view of the input array with its dimensions permuted.

Examples:

a = Array([[1, 2], [3, 4]]) result = permute_inv(a, axis=List(-1,-2)) print(result)

This function supports

  • Automatic differentiation (forward and reverse modes).
  • Complex valued arguments.

Functions

permute

permute(arg0: Array, axis: ArrayShape) -> Array
Creates a view of the input array with its dimensions permuted based on the given axis.
Args
  • arg0: Array The input array.

  • axis: ArrayShape The axis to permute.

Returns
  • Array - A view of the input array with its dimensions permuted.

Examples:

a = Array([[1, 2], [3, 4]]) result = permute(a, axis=List(-1,-2)) print(result)

This function supports

  • Automatic differentiation (forward and reverse modes).
  • Complex valued arguments.

transpose

transpose(arg0: Array, axis1: Int, axis2: Int) -> Array
Transposes the input array based on the given axes.
Args
  • arg0: Array The input array.

  • axis1: Int The first axis to transpose.

  • axis2: Int The second axis to transpose.

Returns
  • Array - The transposed array.

Note: This function is a wrapper around the permute function with the given axes.

swapaxes

swapaxes(arg0: Array, axis1: Int, axis2: Int) -> Array
Swaps the input array’s axes based on the given axes.
Args
  • arg0: Array The input array.

  • axis1: Int The first axis to swap.

  • axis2: Int The second axis to swap.

Returns
  • Array - The array with the axes swapped.

Note: This function is a wrapper around the transpose function with the given axes.

swapdims

swapdims(arg0: Array, axis1: Int, axis2: Int) -> Array
Swaps the input array’s dimensions based on the given axes.
Args
  • arg0: Array The input array.

  • axis1: Int The first axis to swap.

  • axis2: Int The second axis to swap.

Returns
  • Array - The array with the dimensions swapped.

Note: This function is a wrapper around the transpose function with the given axes.

permute_inv

permute_inv(arg0: Array, axis: ArrayShape) -> Array
Creates a view of the input array with its dimensions permuted based on the given axis.
Args
  • arg0: Array The input array.

  • axis: ArrayShape The axis to permute.

Returns
  • Array - A view of the input array with its dimensions permuted.

Examples:

a = Array([[1, 2], [3, 4]]) result = permute_inv(a, axis=List(-1,-2)) print(result)

This function supports

  • Automatic differentiation (forward and reverse modes).
  • Complex valued arguments.
Last updated on