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

View source: R/parse_shape.R

parse_shapeR Documentation

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, ...)

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

Value

named list, maps axes names to their lengths

Examples

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)

}


einops documentation built on Sept. 9, 2025, 5:29 p.m.