import torch


def create_nonlinearity(name):
    """
    Return nonlinearity function given its name.
    """
    if name == "leaky_relu":
        return torch.nn.functional.leaky_relu
    elif name == "relu":
        return torch.nn.functional.relu
    elif name == "sigmoid":
        return torch.sigmoid
    elif name == "tanh":
        return torch.nn.functional.tanh
    else:
        raise ValueError("Nonlinearity \"{}\" undefined".format(name))