View and select functions

In 0.11, we’ve included a number of different view and select functions – under the hood, these are implemented as pass through functions – i.e. functions that apply the operator to both the mask and the data.

By way of example, consider select; this operation can be applied to both the data and the mask of a MaskedTensor, and the result will then be wrapped into a new MaskedTensor.

A quick example of this:

>>> data = torch.arange(12, dtype=torch.float).reshape((3,4))
>>> mask = torch.tensor([
        [True, False, False, True],
        [False, True, False, False],
        [True, True, True, True]])
>>> mt = masked_tensor(data, mask)
>>> data.select(0, 1)
tensor([4., 5., 6., 7.])
>>> mask.select(0, 1)
tensor([False,  True, False, False])
>>> mt.select(0, 1)
masked_tensor(
[      --,   5.0000,       --,       --]
)

Below is a list of the ops that are currently supported:

atleast_1d

Returns a 1-dimensional view of each input tensor with zero dimensions.

broadcast_tensors

Broadcasts the given tensors according to broadcasting-semantics.

broadcast_to

Broadcasts input to the shape shape.

cat

Concatenates the given sequence of seq tensors in the given dimension.

chunk

Attempts to split a tensor into the specified number of chunks.

column_stack

Creates a new tensor by horizontally stacking the tensors in tensors.

dsplit

Splits input, a tensor with three or more dimensions, into multiple tensors depthwise according to indices_or_sections.

flatten

Flattens input by reshaping it into a one-dimensional tensor.

hsplit

Splits input, a tensor with one or more dimensions, into multiple tensors horizontally according to indices_or_sections.

hstack

Stack tensors in sequence horizontally (column wise).

kron

Computes the Kronecker product, denoted by \(\otimes\), of input and other.

meshgrid

Creates grids of coordinates specified by the 1D inputs in attr:tensors.

narrow

Returns a new tensor that is a narrowed version of input tensor.

ravel

Return a contiguous flattened tensor.

select

Slices the input tensor along the selected dimension at the given index.

split

Splits the tensor into chunks.

t

Expects input to be <= 2-D tensor and transposes dimensions 0 and 1.

transpose

Returns a tensor that is a transposed version of input.

vsplit

Splits input, a tensor with two or more dimensions, into multiple tensors vertically according to indices_or_sections.

vstack

Stack tensors in sequence vertically (row wise).

Tensor.expand

Returns a new view of the self tensor with singleton dimensions expanded to a larger size.

Tensor.expand_as

Expand this tensor to the same size as other.

Tensor.reshape

Returns a tensor with the same data and number of elements as self but with the specified shape.

Tensor.reshape_as

Returns this tensor as the same shape as other.

Tensor.view

Returns a new tensor with the same data as the self tensor but of a different shape.