tensorly.context

context(tensor)

Returns the context of a tensor

Creates a dictionary of the parameters characterising the tensor.

Parameters:tensor : tensorly.tensor
Returns:context : dict

Examples

>>> import tensorly as tl
>>> tl.set_backend('numpy')

Imagine you have an existing tensor tensor:

>>> tensor = tl.tensor([0, 1, 2], dtype=tl.float32)

The context, here, will simply be the dtype:

>>> tl.context(tensor)
{'dtype': dtype('float32')}

Note that, if you were using, say, PyTorch, the context would also include the device (i.e. CPU or GPU) and device ID.

If you want to create a new tensor in the same context, use this context:

>>> new_tensor = tl.tensor([1, 2, 3], **tl.context(tensor))