quantnn/models/pytorch/common.py
def handle_input(data, device=None):
    """
    Handle input data.

    This function handles data supplied

      - as tuple of :code:`np.ndarray`
      - a single :code:`np.ndarray`
      - torch :code:`dataloader`

    If a numpy array is provided it is converted to a torch tensor
    so that it can be fed into a pytorch model.
    """
    if type(data) == tuple:
        x, y = data

        dtype_y = torch.float
        if "int" in str(y.dtype):
            dtype_y = torch.long

        x = torch.tensor(x, dtype=torch.float)
        y = torch.tensor(y, dtype=dtype_y)
        if device is not None:
            x = x.to(device)
            y = y.to(device)
        return x, y

    if type(data) == np.ndarray:
        x = torch.tensor(data, dtype=torch.float)
        if device is not None:
            x = x.to(device)
        return x

    return data

    Handle input data.

    This function handles data supplied

      - as tuple of :code:`np.ndarray`
      - a single :code:`np.ndarray`
      - torch :code:`dataloader`

    If a numpy array is provided it is converted to a torch tensor
    so that it can be fed into a pytorch model.
    
Handle input data.
This function handles data supplied



If a numpy array is provided it is converted to a torch tensor
so that it can be fed into a pytorch model.
Handle input data . This function handles data supplied If a numpy array is provided it is converted to a torch tensor so that it can be fed into a pytorch model .
def handle_input(data, device=None):
    if type(data) == tuple:
        x, y = data
        dtype_y = torch.float
        if "int" in str(y.dtype):
            dtype_y = torch.long
        x = torch.tensor(x, dtype=torch.float)
        y = torch.tensor(y, dtype=dtype_y)
        if device is not None:
            x = x.to(device)
            y = y.to(device)
        return x, y
    if type(data) == np.ndarray:
        x = torch.tensor(data, dtype=torch.float)
        if device is not None:
            x = x.to(device)
        return x
    return data
def handle_input ( data , device = None ) : if type ( data ) == tuple : x , y = data dtype_y = torch . float if "int" in str ( y . dtype ) : dtype_y = torch . long x = torch . tensor ( x , dtype = torch . float ) y = torch . tensor ( y , dtype = dtype_y ) if device is not None : x = x . to ( device ) y = y . to ( device ) return x , y if type ( data ) == np . ndarray : x = torch . tensor ( data , dtype = torch . float ) if device is not None : x = x . to ( device ) return x return data
Handle input data.
Handle input data .
"""
    Handle input data.

    This function handles data supplied

      - as tuple of :code:`np.ndarray`
      - a single :code:`np.ndarray`
      - torch :code:`dataloader`

    If a numpy array is provided it is converted to a torch tensor
    so that it can be fed into a pytorch model.
    """
data
device