spyrit.core.meas.FreeformLinear.mask_unvectorize

FreeformLinear.mask_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.