File size: 550 Bytes
452723c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | """Dataset utility functions."""
from typing import Tuple
import torch
from src.utils.logging_util import LoggingUtils
logger = LoggingUtils.configure_logger(log_name=__name__)
def map_tensor_range(
tensor: torch.Tensor,
in_range: Tuple[float, float],
out_range: Tuple[float, float]
) -> torch.Tensor:
"""
Linearly map a tensor from in_range [a, b] to out_range [c, d].
"""
a, b = in_range
c, d = out_range
a, b, c, d = float(a), float(b), float(c), float(d)
return ((tensor - a) / (b - a)) * (d - c) + c |