tltorch
.FactorizedTensor¶
- class tltorch.FactorizedTensor(*args, **kwargs)[source]¶
Tensor in Factorized form
Important
All tensor factorization must have an order parameter
- Attributes:
decomposition
Returns the factors and parameters composing the tensor in factorized form
name
Factorization name (‘tucker’, ‘tt’, ‘cp’, …)
ndim
Order of the tensor
- tensor_shape
Methods
dim
()Order of the tensor
forward
([indices])To use a tensor factorization within a network, use
tensor.forward
, or, equivalently,tensor()
from_tensor
(tensor, rank[, factorization])Create a factorized tensor by decomposing a dense tensor
new
(shape[, rank, factorization])Main way to create a factorized tensor
normal_
([mean, std])Inialize the factors of the factorization such that the reconstruction follows a Gaussian distribution
size
([index])shape of the tensor
Reconstruct the full tensor from its factorized form
numel
- classmethod new(shape, rank='same', factorization='Tucker', **kwargs)[source]¶
Main way to create a factorized tensor
- Parameters:
- shapetuple[int]
shape of the factorized tensor to create
- rankint, ‘same’ or float, default is ‘same’
rank of the decomposition
- factorization{‘CP’, ‘TT’, ‘Tucker’}, optional
Tensor factorization to use to decompose the tensor, by default ‘Tucker’
- Returns:
- TensorFactorization
Tensor in Factorized form.
- Raises:
- ValueError
If the factorization given does not exist.
Examples
Create a Tucker tensor of shape (3, 4, 2) with half the parameters as a dense tensor would:
>>> tucker_tensor = FactorizedTensor.new((3, 4, 2)), rank=0.5, factorization='tucker')
- classmethod from_tensor(tensor, rank, factorization='CP', **kwargs)[source]¶
Create a factorized tensor by decomposing a dense tensor
- Parameters:
- tensortorch.tensor
tensor to factorize
- rankint, ‘same’ or float
rank of the decomposition
- factorization{‘CP’, ‘TT’, ‘Tucker’}, optional
Tensor factorization to use to decompose the tensor, by default ‘CP’
- Returns:
- TensorFactorization
Tensor in Factorized form.
- Raises:
- ValueError
If the factorization given does not exist.
- forward(indices=None, **kwargs)[source]¶
To use a tensor factorization within a network, use
tensor.forward
, or, equivalently,tensor()
- Parameters:
- indicesint or tuple[int], optional
use to index the tensor during the forward pass, by default None
- Returns:
- TensorFactorization
tensor[indices]
- property decomposition¶
Returns the factors and parameters composing the tensor in factorized form
- size(index=None)[source]¶
shape of the tensor
- Parameters:
- indexint, or tuple, default is None
if not None, returns tensor.shape[index]
See also
shape
- normal_(mean=0, std=1)[source]¶
Inialize the factors of the factorization such that the reconstruction follows a Gaussian distribution
- Parameters:
- meanfloat, currently only 0 is supported
- stdfloat
standard deviation
- Returns:
- self
- property name¶
Factorization name (‘tucker’, ‘tt’, ‘cp’, …)