Skip to contents

Rejects a dim parameter that does not address a dimension of shape. Resolve negative indices with resolve_dim() first and pass both, so that the error message can report the value the user actually specified.

Usage

assert_dim_in_range(dim, true_dim, shape, id)

Arguments

dim

(integer(1))
The dimension as the user specified it: it may count back from the last dimension. Only used for the error message.

true_dim

(integer(1))
The same dimension resolved to a positive index, see resolve_dim().

shape

(integer())
The shape that true_dim addresses.

id

(character(1))
The id of the PipeOp, which the error message names.

Value

The resolved dimension, invisibly.

Examples

shape = c(NA, 3, 8, 8)
assert_dim_in_range(-1L, resolve_dim(-1L, shape), shape, id = "nn_squeeze")
try(assert_dim_in_range(-5L, resolve_dim(-5L, shape), shape, id = "nn_squeeze"))
#> Error : PipeOp 'nn_squeeze' cannot use 'dim' -5 for the input shape (NA,3,8,8), which has 4 dimension(s).