nnrl/utils.py
def convert_to_tensor(arr, device: torch.device) -> Tensor:
    """Convert array-like object to tensor and cast it to appropriate device.

    Arguments:
        arr (array_like): object which can be converted using `np.asarray`
        device: device to cast the resulting tensor to

    Returns:
        The array converted to a `Tensor`.
    """
    if torch.is_tensor(arr):
        return arr.to(device)
    tensor = torch.from_numpy(np.asarray(arr))
    if tensor.dtype == torch.double:
        tensor = tensor.float()
    return tensor.to(device)
Convert array-like object to tensor and cast it to appropriate device.

    Arguments:
        arr (array_like): object which can be converted using `np.asarray`
        device: device to cast the resulting tensor to

    Returns:
        The array converted to a `Tensor`.
    
Convert array-like object to tensor and cast it to appropriate device.
Convert array - like object to tensor and cast it to appropriate device .
def convert_to_tensor(arr, device: torch.device) -> Tensor:
    if torch.is_tensor(arr):
        return arr.to(device)
    tensor = torch.from_numpy(np.asarray(arr))
    if tensor.dtype == torch.double:
        tensor = tensor.float()
    return tensor.to(device)
def convert_to_tensor ( arr , device : torch . device ) -> Tensor : if torch . is_tensor ( arr ) : return arr . to ( device ) tensor = torch . from_numpy ( np . asarray ( arr ) ) if tensor . dtype == torch . double : tensor = tensor . float ( ) return tensor . to ( device )
Convert array-like object to tensor and cast it to appropriate device.
Convert array - like object to tensor and cast it to appropriate device .
"""Convert array-like object to tensor and cast it to appropriate device.

    Arguments:
        arr (array_like): object which can be converted using `np.asarray`
        device: device to cast the resulting tensor to

    Returns:
        The array converted to a `Tensor`.
    """
The array converted to a `Tensor`.
The array converted to a ` Tensor ` .
arr
object which can be converted using `np.asarray`
object which can be converted using ` np . asarray `
device
torch.device
device to cast the resulting tensor to
device to cast the resulting tensor to