TensorOperator | R Documentation |
Tensor backend configuration and methods for all the tensor operations in BKTR
R6P::Singleton
-> TensorOperator
fp_type
The floating point type to use for the tensor operations
fp_device
The device to use for the tensor operations
new()
Initialize the tensor operator with the given floating point type and device
TensorOperator$new(fp_type = "float64", fp_device = "cpu")
fp_type
The floating point type to use for the tensor operations (either "float64" or "float32")
fp_device
The device to use for the tensor operations (either "cpu" or "cuda")
A new tensor operator instance
set_params()
Set the tensor operator parameters
TensorOperator$set_params(fp_type = NULL, fp_device = NULL, seed = NULL)
fp_type
The floating point type to use for the tensor operations (either "float64" or "float32")
fp_device
The device to use for the tensor operations (either "cpu" or "cuda")
seed
The seed to use for the random number generator
get_default_jitter()
Get the default jitter value for the floating point type used by the tensor operator
TensorOperator$get_default_jitter()
The default jitter value for the floating point type used by the tensor operator
tensor()
Create a tensor from a vector or matrix of data with the tensor operator dtype and device
TensorOperator$tensor(tensor_data)
tensor_data
The vector or matrix of data to create the tensor from
A new tensor with the tensor operator dtype and device
is_tensor()
Check if a provided object is a tensor
TensorOperator$is_tensor(tensor)
tensor
The object to check
A boolean indicating if the object is a tensor
eye()
Create a tensor with a diagonal of ones and zeros with the tensor operator dtype and device for a given dimension
TensorOperator$eye(eye_dim)
eye_dim
The dimension of the tensor to create
A new tensor with a diagonal of ones and zeros with the tensor operator dtype and device
ones()
Create a tensor of ones with the tensor operator dtype and device for a given dimension
TensorOperator$ones(tsr_dim)
tsr_dim
The dimension of the tensor to create
A new tensor of ones with the tensor operator dtype and device
zeros()
Create a tensor of zeros with the tensor operator dtype and device for a given dimension
TensorOperator$zeros(tsr_dim)
tsr_dim
The dimension of the tensor to create
A new tensor of zeros with the tensor operator dtype and device
rand()
Create a tensor of random uniform values with the tensor operator dtype and device for a given dimension
TensorOperator$rand(tsr_dim)
tsr_dim
The dimension of the tensor to create
A new tensor of random values with the tensor operator dtype and device
randn()
Create a tensor of random normal values with the tensor operator dtype and device for a given dimension
TensorOperator$randn(tsr_dim)
tsr_dim
The dimension of the tensor to create
A new tensor of random normal values with the tensor operator dtype and device
randn_like()
Create a tensor of random uniform values with the same shape as a given tensor with the tensor operator dtype and device
TensorOperator$randn_like(input_tensor)
input_tensor
The tensor to use as a shape reference
A new tensor of random uniform values with the same shape as a given tensor
arange()
Create a tensor of a range of values with the tensor operator dtype and device for a given start and end
TensorOperator$arange(start, end)
start
The start of the range
end
The end of the range
A new tensor of a range of values with the tensor operator dtype and device
rand_choice()
Choose random values from a tensor for a given number of samples
TensorOperator$rand_choice( choices_tsr, nb_sample, use_replace = FALSE, weights_tsr = NULL )
choices_tsr
The tensor to choose values from
nb_sample
The number of samples to choose
use_replace
A boolean indicating if the sampling should be done with replacement. Defaults to FALSE
weights_tsr
The weights to use for the sampling. If NULL, the sampling is uniform. Defaults to NULL
A new tensor of randomly chosen values from a tensor
kronecker_prod()
Efficiently compute the kronecker product of two matrices in tensor format
TensorOperator$kronecker_prod(a, b)
a
The first tensor
b
The second tensor
The kronecker product of the two matrices
khatri_rao_prod()
Efficiently compute the khatri rao product of two matrices in tensor format having the same number of columns
TensorOperator$khatri_rao_prod(a, b)
a
The first tensor
b
The second tensor
The khatri rao product of the two matrices
clone()
The objects of this class are cloneable with this method.
TensorOperator$clone(deep = FALSE)
deep
Whether to make a deep clone.
# Set the seed, setup the tensor floating point type and device
TSR$set_params(fp_type='float64', fp_device='cpu', seed=42)
# Create a tensor from a vector
TSR$tensor(c(1, 2, 3))
# Create a tensor from a matrix
TSR$tensor(matrix(c(1, 2, 3, 4), nrow=2))
# Create a 3x3 tensor with a diagonal of ones and zeros elsewhere
TSR$eye(3)
# Create a tensor of ones (with 6 elements, 2 rows and 3 columns)
TSR$ones(c(2, 3))
# Create a tensor of zeros (with 12 elements, 3 rows and 4 columns)
TSR$zeros(c(3, 4))
# Create a tensor of random uniform values (with 6 elements)
TSR$rand(c(2, 3))
# Create a tensor of random normal values (with 6 elements)
TSR$randn(c(2, 3))
# Create a tensor of random normal values with the same shape as a given tensor
tsr_a <- TSR$randn(c(2, 3))
TSR$randn_like(tsr_a)
# Create a tensor of a range of values (1, 2, 3, 4)
TSR$arange(1, 4)
# Choose two random values from a given tensor without replacement
tsr_b <- TSR$rand(6)
TSR$rand_choice(tsr_b, 2)
# Use the tensor operator to compute the kronecker product of two 2x2 matrices
tsr_c <- TSR$tensor(matrix(c(1, 2, 3, 4), nrow=2))
tsr_d <- TSR$tensor(matrix(c(5, 6, 7, 8), nrow=2))
TSR$kronecker_prod(tsr_c, tsr_d) # Returns a 4x4 tensor
# Use the tensor operator to compute the khatri rao product of two 2x2 matrices
TSR$khatri_rao_prod(tsr_c, tsr_d) # Returns a 4x2 tensor
# Check if a given object is a tensor
TSR$is_tensor(tsr_d) # Returns TRUE
TSR$is_tensor(TSR$eye(2)) # Returns TRUE
TSR$is_tensor(1) # Returns FALSE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.