tltorch.TensorizedMatrix

class tltorch.TensorizedMatrix(*args, **kwargs)[source]

Tensor representing one or a batch of tensorized vectors/matrices/tensors

Important

All tensor factorization must have an order parameter

Attributes
name

Factorization name (‘tucker’, ‘tt’, ‘cp’, …)

ndim

Order of the tensor

Methods

dim()

Order of the tensor

forward([indices])

To use a tensor factorization within a network, use tensor.forward, or, equivalently, tensor()

from_matrix(matrix, tensorized_row_shape, …)

Create a Tensorized Matrix by tensorizing and decomposing an existing matrix

new(tensorized_row_shape, …[, n_matrices, …])

Main way to create a Tensorized Matrix

normal_(mean, std)

Inialize the factors of the factorization such that the reconstruction follows a Gaussian distribution

size([index])

shape of the tensor

to_matrix()

Reconstruct the full matrix from the factorized tensorization

to_tensor()

Reconstruct the full tensor from its factorized form

classmethod new(tensorized_row_shape, tensorized_column_shape, rank, n_matrices=(), factorization='CP', **kwargs)[source]

Main way to create a Tensorized Matrix

Parameters
tensorized_row_shapetuple[int]

The first dimension (rows) of the matrix will be tensorized to that shape

tensorized_column_shapetuple[int]

The second dimension (columns) of the matrix will be tensorized to that shape

rankint, ‘same’ or float

rank of the decomposition

n_matricestuple or int, default is ()

if not (), indicates how many matrices have to be jointly factorized

factorization{‘CP’, ‘TT’, ‘Tucker’}, optional

Tensor factorization to use to decompose the tensor, by default ‘CP’

Returns
TensorizedMatrix

Matrix in Tensorized and Factorized form.

Raises
ValueError

If the factorization given does not exist.

classmethod from_matrix(matrix, tensorized_row_shape, tensorized_column_shape, rank, factorization='CP', **kwargs)[source]

Create a Tensorized Matrix by tensorizing and decomposing an existing matrix

Parameters
matrixtorch.tensor of order 2

matrix to decompose

tensorized_row_shapetuple[int]

The first dimension (rows) of the matrix will be tensorized to that shape

tensorized_column_shapetuple[int]

The second dimension (columns) of the matrix will be tensorized to that shape

rankint, ‘same’ or float

rank of the decomposition

n_matricestuple or int, default is ()

if not (), indicates how many matrices have to be jointly factorized

factorization{‘CP’, ‘TT’, ‘Tucker’}, optional

Tensor factorization to use to decompose the tensor, by default ‘CP’

Returns
TensorizedMatrix

Matrix in Tensorized and 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
TensorizedMatrix

tensor[indices]

to_tensor()[source]

Reconstruct the full tensor from its factorized form

to_matrix()[source]

Reconstruct the full matrix from the factorized tensorization

If several matrices are parametrized, a batch of matrices is returned

dim()[source]

Order of the tensor

See also

ndim

Notes

fact_tensor.dim() == fact_tensor.ndim

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
property ndim

Order of the tensor

See also

dim

Notes

fact_tensor.dim() == fact_tensor.ndim

normal_(mean, std)[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’, …)