Rejects a shape with the wrong number of dimensions. Give either ndim, the number(s) of
dimensions the operator accepts, or the bounds min and max (either on its own), which is what
an operator that accepts a range of them uses, as batch normalization does.
Arguments
- shape
(
integer())
The input shape, withNAfor the dimensions whose size is unknown.- ndim
(
integer())
The number(s) of dimensions the operator accepts, the batch dimension included. Alternatively giveminand/ormax.- id
(
character(1))
The id of thePipeOp, which the error message names.- min
(
integer(1))
The smallest number of dimensions the operator accepts,NULLfor no lower bound.- max
(
integer(1))
The largest number of dimensions the operator accepts,NULLfor no upper bound.
Examples
assert_ndim(c(NA, 3, 32, 32), 4L, id = "nn_conv2d")
try(assert_ndim(c(NA, 3), 4L, id = "nn_conv2d"))
#> Error : PipeOp 'nn_conv2d' requires an input with 4 dimensions (the first one being the batch dimension), but got the shape (NA,3), which has 2.
# batch normalization accepts a range
try(assert_ndim(c(NA, 3, 4, 5), id = "nn_batch_norm1d", min = 2L, max = 3L))
#> Error : PipeOp 'nn_batch_norm1d' requires an input with 2 or 3 dimensions (the first one being the batch dimension), but got the shape (NA,3,4,5), which has 4.