import torch


def linlogcut_torch(x, a=10, b=100):
    """ Function which is linear until a, logarithmic until b and then constant.
    y = x                  x <= a
    y = a + log(x-a)   a < x < b
    y = a + log(b-a)   b < x
    """
    # cutoff x after b - this should also cutoff infinities
    x = torch.where(x < b, x, b * torch.ones(x.shape).to(x))
    # log after a
    y = a + torch.where(x < a, x - a, torch.log(x - a + 1))
    # make sure everything is finite ?notwendig?
    #y = tf.where(torch.is_finite(y), y, b * torch.ones(tf.shape(y)))
    return y