| Title: | Helper Functions for 'r-xla' |
| Version: | 0.5.1 |
| 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. |
| License: | MIT + file LICENSE |
| URL: | https://r-xla.github.io/xlamisc/, https://github.com/r-xla/xlamisc |
| BugReports: | https://github.com/r-xla/xlamisc/issues |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.3.0) |
| Imports: | checkmate, cli, rlang, utils |
| Suggests: | testthat (≥ 3.0.0) |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.1.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-09-29 15:42:53 UTC; sebi |
| Author: | Sebastian Fischer |
| Maintainer: | Sebastian Fischer <seb.fischer@tutamail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-08 18:30:02 UTC |
xlamisc: 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.
Author(s)
Maintainer: Sebastian Fischer seb.fischer@tutamail.com (ORCID)
Authors:
Sebastian Fischer seb.fischer@tutamail.com (ORCID)
Daniel Falbel daniel@posit.co (ORCID)
See Also
Useful links:
Report bugs at https://github.com/r-xla/xlamisc/issues
DataType
Description
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:
boolsigned integers:
i8,i16,i32,i64unsigned integers:
ui8,ui16,ui32,ui64floats:
f16,bf16,f32,f64complex:
c64,c128
Construct a DataType with as_dtype(). Inspect it with dtype_width()
and the is_dtype_float() family of predicates.
See Also
as_dtype(), dtype_width(), is_dtype_float()
As Array
Description
Convert a value (usually a tensor from some framework) to an R array.
Usage
as_array(x, ...)
Arguments
x |
(any) |
... |
(any) |
Value
(any)
Convert to DataType
Description
Convert to DataType.
Usage
as_dtype(x)
Arguments
x |
(any) |
Value
DataType
As Raw
Description
Convert a value (usually a tensor from some framework) to a raw() vector.
Usage
as_raw(x, ...)
Arguments
x |
(any) |
... |
(any) |
Value
(any)
Assert DataType
Description
Assert that an object is a DataType.
Usage
assert_dtype(x, arg = rlang::caller_arg(x))
Arguments
x |
(any) |
arg |
( |
Value
NULL (invisibly). Called for side effects.
Device
Description
Get the device of a tensor.
Usage
device(x, ...)
Arguments
x |
(any) |
... |
(any) |
Value
(any)
Data Type
Description
Get the data type of a tensor. The return type depends on the specific tensor implementation.
Usage
dtype(x, ...)
Arguments
x |
(any) |
... |
(any) |
Value
(any)
Category of a DataType
Description
The category of a DataType: one of "bool", "int", "uint",
"float", or "complex".
Usage
dtype_category(x)
Arguments
x |
( |
Value
character(1)
See Also
is_dtype_float() and friends for per-category predicates
Width of a DataType
Description
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).
Usage
dtype_width(x)
Arguments
x |
( |
Value
integer(1)
Is DataType
Description
Check if an object is a DataType.
Usage
is_dtype(x)
Arguments
x |
(any) |
Value
logical(1)
DataType Category Predicates
Description
Check which category a DataType belongs to:
-
is_dtype_float(): floating point, includingbf16. -
is_dtype_int(): signed integers. -
is_dtype_uint(): unsigned integers. -
is_dtype_bool():bool. -
is_dtype_complex():c64,c128.
Usage
is_dtype_float(x)
is_dtype_int(x)
is_dtype_uint(x)
is_dtype_bool(x)
is_dtype_complex(x)
Arguments
x |
( |
Value
logical(1)
Number of Axes
Description
Get the number of axes of a tensor.
Usage
naxes(x)
Arguments
x |
(any) |
Value
(integer)
Number of Elements
Description
Get the number of elements of a tensor.
Usage
nelts(x)
Arguments
x |
(any) |
Value
(integer)
Shape
Description
Get the shape of a tensor.
Usage
shape(x, ...)
Arguments
x |
(any) |
... |
(any) |
Value
(integer())
The shape of the tensor.