Package {xlamisc}


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 ORCID iD [aut, cre], Daniel Falbel ORCID iD [aut]
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:

See Also

Useful links:


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:

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)
Object.

...

(any)
Additional arguments.

Value

(any)


Convert to DataType

Description

Convert to DataType.

Usage

as_dtype(x)

Arguments

x

(any)
A dtype string (e.g. "f32", "i64", "bool"; the aliases "pred" and "i1" map to "bool") or a DataType object.

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)
Object.

...

(any)
Additional arguments.

Value

(any)


Assert DataType

Description

Assert that an object is a DataType.

Usage

assert_dtype(x, arg = rlang::caller_arg(x))

Arguments

x

(any)
Object to check.

arg

(character(1))
Argument name for error messages.

Value

NULL (invisibly). Called for side effects.


Device

Description

Get the device of a tensor.

Usage

device(x, ...)

Arguments

x

(any)
Object.

...

(any)
Additional arguments.

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)
Object.

...

(any)
Additional arguments.

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

(DataType)

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

(DataType)

Value

integer(1)


Is DataType

Description

Check if an object is a DataType.

Usage

is_dtype(x)

Arguments

x

(any)
Object to check.

Value

logical(1)


DataType Category Predicates

Description

Check which category a DataType belongs to:

Usage

is_dtype_float(x)

is_dtype_int(x)

is_dtype_uint(x)

is_dtype_bool(x)

is_dtype_complex(x)

Arguments

x

(DataType)

Value

logical(1)


Number of Axes

Description

Get the number of axes of a tensor.

Usage

naxes(x)

Arguments

x

(any)
Object.

Value

(integer)


Number of Elements

Description

Get the number of elements of a tensor.

Usage

nelts(x)

Arguments

x

(any)
Object.

Value

(integer)


Shape

Description

Get the shape of a tensor.

Usage

shape(x, ...)

Arguments

x

(any)
Object.

...

(any)
Additional arguments.

Value

(integer())
The shape of the tensor.