Representation of an abstract array type.
The base class represents an unknown value, but child classes exist for:
closed-over constants:
ConcreteArrayscalar arrays arising from R literals:
LiteralArraysequence patterns:
IotaArrayR values
RData. They are special because they do not have a data type.
To convert an arrayish value to an abstract array, use to_abstract().
Arguments
- dtype
(
xlamisc::DataType|character(1))
The data type of the array. Fornv_aval()only,"double","integer"or"logical"create anRDatainstead.- shape
(
stablehlo::Shape|integer())
The shape of the array. Can be provided as an integer vector.
Value
AbstractArray(): (AbstractArray)
nv_aval(): (AbstractArray | RData)
An RData when dtype names an R storage type.
Examples
# -- Creating abstract arrays --
a <- AbstractArray("f32", c(2L, 3L))
a
#> AbstractArray(dtype=f32, shape=2x3)
dtype(a)
#> <f32>
shape(a)
#> [1] 2 3
# shorthand
nv_aval("f32", c(2L, 3L))
#> AbstractArray(dtype=f32, shape=2x3)
# an R value, which has no dtype until it is used
nv_aval("double", c(2L, 3L))
#> RData(double, (2,3))
# how AbstractArrays appear in an AnvlGraph
graph <- trace_fn(function(x) x + 1L, list(x = nv_aval("i32", 4L)))
graph
#> <AnvlGraph> (%x1: i32[4]) {
#> %1: i32[4] = broadcast_in_axes [
#> shape = 4, broadcast_axes = integer(0)
#> ] (1:i32)
#> %2: i32[4] = add(%x1, %1)
#> return %2
#> }
graph$inputs[[1]]$aval
#> AbstractArray(dtype=i32, shape=4)