from contextlib import suppress
import torch


def reshape_input(input_data, input_size, warning=False):
    """Reshape input data before querying model

    This function will conduct a low-level resize if the size of
    the input data is not compatabile with the model input size.

    Parameters:
        input_data: A Torch tensor or Numpy array of the data
        input_size: A tuple of integers describing the new size
        warning: A Boolean that turns warnings on or off

    Returns:
        Data of new shape
    """
    with suppress(Exception):
        input_data = torch.from_numpy(input_data)

    if input_size is not None:
        try:
            input_data = input_data.reshape(input_size)
        except Exception:
            if warning is True:
                print("Warning: Data loss is possible during resizing.")
            input_data = input_data.resize_(input_size)
    return input_data