View#
View and shape manipulation operations.
- nabla.ops.view.permute(input_array, axes)[source]#
Permute (reorder) the dimensions of a tensor.
- Parameters:
- Returns:
Tensor with reordered dimensions
- Return type:
Example
>>> x = nb.ones((2, 3, 4)) # shape (2, 3, 4) >>> y = permute(x, (2, 0, 1)) # shape (4, 2, 3) >>> # Dimension 2 -> position 0, dimension 0 -> position 1, dimension 1 -> position 2
- nabla.ops.view.move_axis_to_front(input_array, axis)[source]#
Move specified axis to the front (position 0), shifting others right.
- Parameters:
- Returns:
Tensor with specified axis moved to front
- Return type:
Example
>>> x = nb.ones((2, 3, 4)) # shape (2, 3, 4) >>> y = move_axis_to_front(x, 2) # shape (4, 2, 3) >>> # axis 2 moved to front, others shifted: [2, 0, 1]
- nabla.ops.view.move_axis_from_front(input_array, target_axis)[source]#
Move front axis (position 0) to specified target position.
- Parameters:
- Returns:
Tensor with front axis moved to target position
- Return type:
Example
>>> x = nb.ones((4, 2, 3)) # front axis has size 4 >>> y = move_axis_from_front(x, 2) # shape (2, 3, 4) >>> # front axis moved to position 2: [1, 2, 0]
- nabla.ops.view.permute_batch_dims(input_array, axes)[source]#
Permute (reorder) the batch dimensions of an array.
This operation reorders the batch_dims of an Array according to the given axes, similar to how regular permute works on shape dimensions. The shape dimensions remain unchanged.
- Parameters:
- Returns:
Array with batch dimensions reordered according to axes
- Return type:
Example
>>> import nabla as nb >>> # Array with batch_dims=(2, 3, 4) and shape=(5, 6) >>> x = nb.ones((5, 6)) >>> x.batch_dims = (2, 3, 4) # Simulated for example >>> y = permute_batch_dims(x, (-1, -3, -2)) # Reorder as (4, 2, 3) >>> # Result has batch_dims=(4, 2, 3) and shape=(5, 6)
- nabla.ops.view.move_axis_to_front_of_batch_dims(input_array, axis)[source]#
Move specified batch dimension to the front (position 0), shifting others right.
- Parameters:
- Returns:
Tensor with specified batch dimension moved to front
- Return type:
Example
>>> x = nb.ones((2, 3, 4)) # shape (2, 3, 4) >>> x.batch_dims = (1, 0) # Simulated for example >>> y = move_axis_to_fron_of_batch_dims(x, -1) # Move last batch dim to front >>> # Result has batch_dims=(0, 1) and shape=(2, 3, 4)
- nabla.ops.view.move_axis_from_front_of_batch_dims(input_array, target_axis)[source]#
Move front batch dimension (position 0) to specified target position.
- Parameters:
- Returns:
Tensor with front batch dimension moved to target position
- Return type:
Example
>>> x = nb.ones((4, 2, 3)) # shape (4, 2, 3) >>> x.batch_dims = (0, 1) # Simulated for example >>> y = move_axis_from_front_of_batch_dims(x, -1) # Move front batch dim to last position >>> # Result has batch_dims=(1, 0) and shape=(4, 2, 3)
- nabla.ops.view.squeeze_batch_dims(arg, axes=None)[source]#
Squeeze array by removing batch dimensions of size 1.
- nabla.ops.view.unsqueeze_batch_dims(arg, axes=None)[source]#
Unsqueeze array by adding batch dimensions of size 1.
- nabla.ops.view.array_slice(arg, slices, squeeze_axes=None)[source]#
Slice an array along specified dimensions.
- nabla.ops.view.pad(arg, slices, target_shape)[source]#
Place a smaller array into a larger zero-filled array at the location specified by slices.
This is the inverse operation of array slicing - given slices, a small array, and target shape, it creates a larger array where the small array is placed at the sliced location and everything else is zero.
- Parameters:
- Returns:
Larger array with input placed at sliced location, zeros elsewhere
- Return type: