import torch


def compute_mean_range(x: torch.Tensor, print_values=False):
    """
    Compute mean and range of values over dataset (for inputs / outputs standardization)
    """
    Max, _ = torch.max(x, dim=0)
    Min, _ = torch.min(x, dim=0)

    Mean = (Max + Min) / 2.0
    Range = (Max - Min) / 2.0

    if print_values:
        print("Standardization enabled.")
        print("Mean:", Mean.shape, "-->", Mean)
        print("Range:", Range.shape, "-->", Range)
    if (Range < 1e-6).nonzero().sum() > 0:
        print(
            "[Warning] Normalization: the following features have a range of values < 1e-6:",
            (Range < 1e-6).nonzero(),
        )
        Range[Range < 1e-6] = 1.0

    return Mean, Range