Returns the shape of an array as an integer() vector.
Arguments
- x
(
arrayish)
An array-like object.- ...
Additional arguments passed to methods (unused).
Details
An R value has a shape when it is arrayish: a length-1 vector is a scalar
with shape integer(), and an R array has its dim(). Any other R vector is
an error; use nv_array() to make it an array.
This is implemented via the generic xlamisc::shape().
Examples
x <- nv_array(1:4, dtype = "f32")
shape(x)
#> [1] 4
shape(nv_array(1:6, shape = c(2, 3)))
#> [1] 2 3
# a length-1 R vector is a scalar
shape(1)
#> integer(0)
shape(TRUE)
#> integer(0)
# an R array has its `dim()`
shape(array(1:6, dim = c(2, 3)))
#> [1] 2 3
# any other R vector has no shape
try(shape(c(2, 3)))
#> Error in shape(c(2, 3)) :
#> `shape()` is undefined for a length-2 R vector.
#> ℹ Only a length-1 R value and an `array()` are arrayish; use `nv_array()` to
#> make one an array.