Skip to contents

Representation of an abstract array type. During tracing, it is wrapped in a GraphNode held by a GraphBox. In the lowered AnvlGraph it is also part of GraphNodes representing the values in the program.

The base class represents an unknown value, but child classes exist for:

To convert a arrayish value to an abstract array, use to_abstract().

Usage

nv_aval(dtype, shape)

AbstractArray(dtype, shape)

Arguments

dtype

(tengen::DataType | character(1))
The data type of the array. To create an RData object, specify "double", "integer", or "logical".

shape

(stablehlo::Shape | integer())
The shape of the array. Can be provided as an integer vector.

Extractors

The following extractors are available on AbstractArray objects:

  • dtype(): Get the data type of the array.

  • shape(): Get the shape (axis sizes) of the array.

  • naxes(): Get the number of axes.

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 + 1, list(x = nv_aval("i32", 4L)))
graph
#> <AnvlGraph> (%x1: i32[4]) {
#>   %1: f32[4] = convert [dtype = f32] (%x1)
#>   %2: f32[4] = broadcast_in_axes [
#>     shape = 4, broadcast_axes = integer(0)
#>   ] (1:f32)
#>   %3: f32[4] = add(%1, %2)
#>   return %3
#> }
graph$inputs[[1]]$aval
#> AbstractArray(dtype=i32, shape=4)