| Title: | Helper Functions for 'r-xla' |
|---|---|
| Description: | Frequently used generics and helper functions used in 'anvl' and its companion packages 'stablehlo' and 'pjrt'. Comes with S3 generics to query arrays (shape, data type, device) and to convert them to R arrays and raw vectors, as well as a class for data types. |
| Authors: | Sebastian Fischer [aut, cre] (ORCID: <https://orcid.org/0000-0002-9609-3197>), Daniel Falbel [aut] (ORCID: <https://orcid.org/0009-0006-0143-2392>) |
| Maintainer: | Sebastian Fischer <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.5.1 |
| Built: | 2026-10-08 22:26:25 UTC |
| Source: | https://github.com/cran/xlamisc |
Convert a value (usually a tensor from some framework) to an R array.
as_array(x, ...)as_array(x, ...)
x |
(any) |
... |
(any) |
(any)
Convert to DataType.
as_dtype(x)as_dtype(x)
x |
(any) |
DataType
Convert a value (usually a tensor from some framework) to a raw() vector.
as_raw(x, ...)as_raw(x, ...)
x |
(any) |
... |
(any) |
(any)
Assert that an object is a DataType.
assert_dtype(x, arg = rlang::caller_arg(x))assert_dtype(x, arg = rlang::caller_arg(x))
x |
(any) |
arg |
( |
NULL (invisibly). Called for side effects.
DataType is the S3 class representing a tensor element type.
It is an enum: one singleton object per supported dtype, wrapping the
canonical dtype string. The members are the element types supported by
the r-xla stack:
boolean: bool
signed integers: i8, i16, i32, i64
unsigned integers: ui8, ui16, ui32, ui64
floats: f16, bf16, f32, f64
complex: c64, c128
Construct a DataType with as_dtype(). Inspect it with dtype_width()
and the is_dtype_float() family of predicates.
as_dtype(), dtype_width(), is_dtype_float()
Get the device of a tensor.
device(x, ...)device(x, ...)
x |
(any) |
... |
(any) |
(any)
Get the data type of a tensor. The return type depends on the specific tensor implementation.
dtype(x, ...)dtype(x, ...)
x |
(any) |
... |
(any) |
(any)
The category of a DataType: one of "bool", "int", "uint",
"float", or "complex".
dtype_category(x)dtype_category(x)
x |
( |
character(1)
is_dtype_float() and friends for per-category predicates
The width in bits of one element of the given DataType.
For bool this is 1; for complex types it is the total width of the
element (c64 -> 64).
dtype_width(x)dtype_width(x)
x |
( |
integer(1)
Check if an object is a DataType.
is_dtype(x)is_dtype(x)
x |
(any) |
logical(1)
Check which category a DataType belongs to:
is_dtype_float(): floating point, including bf16.
is_dtype_int(): signed integers.
is_dtype_uint(): unsigned integers.
is_dtype_bool(): bool.
is_dtype_complex(): c64, c128.
is_dtype_float(x) is_dtype_int(x) is_dtype_uint(x) is_dtype_bool(x) is_dtype_complex(x)is_dtype_float(x) is_dtype_int(x) is_dtype_uint(x) is_dtype_bool(x) is_dtype_complex(x)
x |
( |
logical(1)
Get the number of axes of a tensor.
naxes(x)naxes(x)
x |
(any) |
(integer)
Get the number of elements of a tensor.
nelts(x)nelts(x)
x |
(any) |
(integer)
Get the shape of a tensor.
shape(x, ...)shape(x, ...)
x |
(any) |
... |
(any) |
(integer())
The shape of the tensor.