Helper Functions for 'r-xla'

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.


xlamisc

CRANstatus R-CMD-check r-universe

Provides S3 generics and data types for tensors, shared across the r-xla packages.

Installation

pak::pak("r-xla/xlamisc")

Available Generics

  • shape(): Different from dim() by also supporting 0-dimensional tensors.
  • dtype(): Returns the data type of the tensor.
  • as_array(): Converts the tensor to an R array.
  • as_raw(): Converts the tensor to a raw() vector.
  • device(): Returns the device of the tensor.

Other functions:

  • naxes(): Returns the number of axes of the tensor. Is implemented as length(shape(x)).
  • nelts(): Returns the number of elements of the tensor. Is implemented as prod(shape(x)).

Tensor Data Types

xlamisc provides DataType, an enum-style S3 class representing a tensor element type. There is one singleton object per supported dtype, wrapping its canonical string. The members are:

  • boolean: bool (aliases i1, pred)
  • signed integers: i8, i16, i32, i64
  • unsigned integers: ui8, ui16, ui32, ui64
  • floats: f16, bf16, f32, f64
  • complex: c64, c128

Construct and inspect data types with:

  • as_dtype(x): Convert a string (e.g. "f32") or DataType to a DataType object.
  • is_dtype(x): Check whether an object is a DataType.
  • assert_dtype(x): Assert that an object is a DataType.
  • dtype_width(x): The width of one element in bits.
  • dtype_category(x): The category, one of "bool", "int", "uint", "float", or "complex".
  • is_dtype_float(x), is_dtype_int(x), is_dtype_uint(x), is_dtype_bool(x), is_dtype_complex(x): Per-category predicates.

Data types support equality comparison with == and !=.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("xlamisc")

0.5.1 by Sebastian Fischer, 7 hours ago


https://r-xla.github.io/xlamisc/, https://github.com/r-xla/xlamisc


Report a bug at https://github.com/r-xla/xlamisc/issues


Browse source code at https://github.com/cran/xlamisc


Authors: Sebastian Fischer [aut, cre] (ORCID: , Daniel Falbel [aut]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports checkmate, cli, rlang, utils

Suggests testthat


See at CRAN