Skip to content

torchrelay.jit

Overview

Indexing

ind2sub

Convert linear indices into sub indices (i, j, k).

sub2ind, sub2ind_list

Convert sub indices (i, j, k) into linear indices.

Math

square, square_

x**2

cube, cube_

x**3

pow4, pow4_

x**4

pow5, pow5_

x**5

pow6, pow6_

x**6

pow7, pow7_

x**7

floor_div, floor_div_int

floor(x / y)

trunc_div, trunc_div_int

trunc(x / y)

Meshgrid

meshgrid_list_ij

Meshgrid with indexing="ij"

meshgrid_list_xy

Meshgrid with indexing="xy"

Python objects

pad_list_int pad_list_float pad_list_str

Pad a list

any_list_bool

any(list)

all_list_bool

all(list)

prod_list_int

prod(list)

sum_list_int

sum(list)

reverse_list_int

reversed(list)

cumprod_list_int

Cumulative product

Tensors

prod_list_tensor

prod(list[tensor])

sum_list_tensor

sum(list[tensor])

movedim

movedim(tensor, src, dst)

ind2sub

ind2sub(ind, shape)

Convert linear indices into sub indices (i, j, k).

The rightmost dimension is the most rapidly changing one -> if shape == [D, H, W], the strides are therefore [H*W, W, 1]

Parameters:

Name Type Description Default
ind tensor_like

Linear indices

required
shape (D,) vector_like

Size of each dimension.

required

Returns:

Name Type Description
subs (D, ...) tensor

Sub-indices.

sub2ind

sub2ind(subs, shape)

Convert sub indices (i, j, k) into linear indices.

The rightmost dimension is the most rapidly changing one -> if shape == [D, H, W], the strides are therefore [H*W, W, 1]

Parameters:

Name Type Description Default
subs (D, ...) tensor

List of sub-indices. The first dimension is the number of dimension. Each element should have the same number of elements and shape.

required
shape (D,) list[int]

Size of each dimension. Its length should be the same as the first dimension of subs.

required

Returns:

Name Type Description
ind (...) tensor

Linear indices

sub2ind_list

sub2ind_list(subs, shape)

Convert sub indices (i, j, k) into linear indices.

The rightmost dimension is the most rapidly changing one -> if shape == [D, H, W], the strides are therefore [H*W, W, 1]

Parameters:

Name Type Description Default
subs (D,) list[tensor]

List of sub-indices. The first dimension is the number of dimension. Each element should have the same number of elements and shape.

required
shape (D,) list[int]

Size of each dimension. Its length should be the same as the first dimension of subs.

required

Returns:

Name Type Description
ind (...) tensor

Linear indices

square

square(x)

cube

cube(x)

pow4

pow4(x)

pow5

pow5(x)

pow6

pow6(x)

pow7

pow7(x)

square_

square_(x)

cube_

cube_(x)

pow4_

pow4_(x)

pow5_

pow5_(x)

pow6_

pow6_(x)

pow7_

pow7_(x)

floor_div

floor_div(x, y)

floor_div_int

floor_div_int(x, y)

trunc_div

trunc_div(x, y)

trunc_div_int

trunc_div_int(x, y)

meshgrid_list_ij

meshgrid_list_ij(tensors)

meshgrid_list_xy

meshgrid_list_xy(tensors)

pad_list_int

pad_list_int(x, length)

pad_list_float

pad_list_float(x, dim)

pad_list_str

pad_list_str(x, dim)

any_list_bool

any_list_bool(x)

TorchScript equivalent to any(x)

all_list_bool

all_list_bool(x)

TorchScript equivalent to all(x)

prod_list_int

prod_list_int(x)

Compute the product of elements in the list

sum_list_int

sum_list_int(x)

Compute the sum of elements in the list. Equivalent to sum(x).

reverse_list_int

reverse_list_int(x)

TorchScript equivalent to x[::-1]

cumprod_list_int

cumprod_list_int(x, reverse=False, exclusive=False)

Cumulative product of elements in the list

Parameters:

Name Type Description Default
x list[int]

List of integers

required
reverse bool

Cumulative product from right to left. Else, cumulative product from left to right (default).

False
exclusive bool

Start series from 1. Else start series from first element (default).

False

Returns:

Name Type Description
y list[int]

Cumulative product

prod_list_tensor

prod_list_tensor(x)

Compute the product of tensors in the list.

sum_list_tensor

sum_list_tensor(x)

Compute the sum of tensors in the list. Equivalent to sum(x).

movedim

movedim(x, source, destination)

Backward compatible torch.movedim