| Title: | Tensor Generics |
|---|---|
| Description: | Generic functions and common objects for working with tensors. |
| Authors: | Sebastian Fischer [aut, cre] (ORCID: <https://orcid.org/0000-0002-9609-3197>), Daniel Falbel [aut] (ORCID: <https://orcid.org/0009-0006-0143-2392>) |
| Maintainer: | Sebastian Fischer <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-06-07 06:55:00 UTC |
| Source: | https://github.com/r-xla/tengen |
Convert a value (usually a tensor from some framework) to an R array.
as_array(x, ...)as_array(x, ...)
x |
(any) |
... |
(any) |
(any)
Convert to DataType.
as_dtype(x)as_dtype(x)
x |
(any) |
DataType
Convert a value (usually a tensor from some framework) to a raw() vector.
as_raw(x, ...)as_raw(x, ...)
x |
(any) |
... |
(any) |
(any)
Assert that an object is a DataType.
assert_dtype(x, arg = rlang::caller_arg(x))assert_dtype(x, arg = rlang::caller_arg(x))
x |
(any) |
arg |
( |
NULL (invisibly). Called for side effects.
Represents the boolean type.
BooleanType()BooleanType()
BooleanType
DataType is the parent S3 class for all tensor data types.
All data type classes inherit from DataType, enabling cross-type
comparisons with == and != operators.
The specific data type classes are:
BooleanType() - Boolean (i1)
IntegerType() - Signed integers (i8, i16, i32, i64)
UIntegerType() - Unsigned integers (ui8, ui16, ui32, ui64)
FloatType() - Floating point (f32, f64)
This is a virtual base class - you cannot create instances directly. Use the specific type constructors instead.
BooleanType(), IntegerType(), UIntegerType(), FloatType()
Get the device of a tensor.
device(x, ...)device(x, ...)
x |
(any) |
... |
(any) |
(any)
Get the data type of a tensor. The return type depends on the specific tensor implementation.
dtype(x, ...)dtype(x, ...)
x |
(any) |
... |
(any) |
(any)
Represents a floating point type with a given bit width.
FloatType(value)FloatType(value)
value |
( |
FloatType
Represents a signed integer type with a given bit width.
IntegerType(value)IntegerType(value)
value |
( |
IntegerType
Check if an object is a DataType.
is_dtype(x)is_dtype(x)
x |
(any) |
logical(1)
Get the number of dimensions of a tensor.
ndims(x)ndims(x)
x |
(any) |
(integer)
Get the number of elements of a tensor.
nelts(x)nelts(x)
x |
(any) |
(integer)
Get the shape of a tensor.
shape(x, ...)shape(x, ...)
x |
(any) |
... |
(any) |
(integer())
The shape of the tensor.
Represents an unsigned integer type with a given bit width.
UIntegerType(value)UIntegerType(value)
value |
( |
UIntegerType