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 an S3 class hierarchy for representing tensor data types via DataType:
-
BooleanType()- Boolean (i1/pred/bool) -
IntegerType(bits)- Signed integers (i8,i16,i32,i64) -
UIntegerType(bits)- Unsigned integers (ui8,ui16,ui32,ui64) -
FloatType(bits)- Floating point (f32,f64)
Utility functions:
-
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.
Data types support equality comparison with == and !=.