Learn R Programming

einops (version 0.2.1)

parse_shape: Parse a tensor shape to dictionary mapping axes names to their lengths.

Description

Use underscore to skip the dimension in parsing.

Usage

parse_shape(x, expr, ...)

Value

named list, maps axes names to their lengths

Arguments

x

tensor of any supported framework

expr

character of length 1, space separated names for axes, underscore means skip axis

...

additional arguments passed to methods

Examples

Run this code
if (requireNamespace("abind", quietly = TRUE)) {

# Use underscore to skip the dimension in parsing.
x <- array(0, dim = c(2, 3, 5, 7))
parse_shape(x, 'batch _ h w')

# `parse_shape` output can be used to specify axes_lengths for other
# operations:
y <- array(0, dim = 700)
shape_info <- parse_shape(x, 'b _ h w')
# rearrange(y, '(b c h w) -> b c h w', shape_info) would give shape
# (2, 10, 5, 7)

}

Run the code above in your browser using DataLab