kaira.utils.to_tensor
- kaira.utils.to_tensor(x: Any, device: str | device | None = None) Tensor[source]
Convert an input data into a torch.Tensor, with an option to move it to a specific device.
- Parameters:
x (Any) – The data to be converted. Acceptable types are: - torch.Tensor: Returned as is (optionally moved to the specified device). - int or float: Converted to a scalar tensor. - list or numpy.ndarray: Converted to a tensor.
device (Union[str, torch.device, None]) – The target device for the tensor (for example, ‘cpu’ or ‘cuda’). Default is None.
- Returns:
The input data converted to a tensor on the specified device if provided.
- Return type:
- Raises:
TypeError – If the input type is not supported for conversion.