Skip to contents

The AbstractArray of a non-static R value that was passed to a jit-compiled function. It is special, because it does not have a data type, i.e., calling dtype() on it results in an error.

Usage

RData(shape, r_type)

Arguments

shape

(stablehlo::Shape | integer())
The shape of the value: () for a length-1 vector, its dim() for an R array.

r_type

(character(1))
The R storage type: "double", "integer" or "logical".

Value

(RData)

Details

It only exists during tracing, never in a finalized graph.

Extractors

Just like AbstractArray, with the exception that dtype() errs.

Examples

RData(c(2, 3), "double")
#> RData(double, (2,3)) 
# is equivalent to
nv_aval("double", c(2, 3))
#> RData(double, (2,3)) 
# below, the `RData` input is materialized in 32 and 64-bit precisions, so the input
# dtype becomes f64.
# by NOT converting RData to their default data type we prevent loss of precision
# (avoiding a double -> default data type -> f64 round trip)
graph <- trace_fn(function(x) {
    print(x)
    list(x + nv_scalar(1, "f64"), x + nv_scalar(1, "f32"))
  }, list(x = nv_aval("double", c()))
)
#> GraphBox(GraphValue(RData(double, ()))) 
print(graph)
#> <AnvlGraph> [%c1: f64[], %c2: f32[]] (%x1: f64[] <- double) {
#>   %1: f32[] = convert [dtype = f32] (%x1)
#>   %2: f64[] = add(%x1, %c1)
#>   %3: f32[] = add(%1, %c2)
#>   return (%2, %3)
#> }
# the actual inputs to the compiled program
graph$inputs
#> [[1]]
#> GraphValue(AbstractArray(dtype=f64, shape=)) 
#> 
# the data types of the R values; AnvlArrays get NA here
graph$rdata_types
#> [1] "double"