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.
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, seeresolve_dim().- shape
(
integer())
The shape thattrue_dimaddresses.- id
(
character(1))
The id of thePipeOp, which the error message names.
See also
Other Shape Assertions:
assert_known_dims(),
assert_ndim(),
assert_not_batch_dim(),
assert_positive_extent(),
assert_same_batch_size(),
assert_same_ndim(),
assert_shape(),
assert_shapes()
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).