spyrit.core.meas.FreeformLinearSplit.unvectorize

FreeformLinearSplit.unvectorize(x: tensor, fill_value: Any = 0) tensor[source]

Unflatten the last dimension of a tensor to the measurement shape at the measured dimensions based on the mask.

This method expands the last dimension into the measurement shape self.meas_shape, filling the elements not in the mask with the fill_value. The expanded dimensions are then moved to their original positions as defined by self.meas_dims.

Note

This function creates a new tensor filled with the fill_value and then fills the elements in the mask with the corresponding elements. The output tensor is not a view of the input tensor.

Args:

x (torch.tensor): tensor to be expanded. Its last dimension must contain self.N elements.

fill_value (Any, optional): Fill value for all the indices not covered by the mask. Defaults to 0.

Returns:

torch.tensor: A tensor where the dimensions indexed by self.meas_dims match the measurement shape self.meas_shape.

See also:

For the opposite operation use vectorize().

Example:
>>> from spyrit.core.meas import FreeformLinearSplit
>>> import torch
>>> images = torch.rand(17, 3, 40, 40)
>>> mask = torch.tensor([[i, i] for i in range(0,40,2)]).T
>>> H = torch.randn(13, 20)
>>> meas_op = FreeformLinearSplit(H, meas_shape=(40,40), index_mask=mask)
>>> x = torch.randn(17, 3, 20)
>>> print(meas_op.unvectorize(x).shape)
torch.Size([17, 3, 40, 40])