Provides S3 generics for common tensor operations.
Installation
pak::pak("r-xla/tengen")Available Generics
-
shape(): Different fromdim()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 araw()vector. -
device(): Returns the device of the tensor.
Other functions:
Tensor Data Types
tengen 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(aliasesi1,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") orDataTypeto aDataTypeobject. -
is_dtype(x): Check whether an object is aDataType. -
assert_dtype(x): Assert that an object is aDataType. -
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 !=.