pythonpytorch

Pytroch clamp for complex values


I am trying to use clamp but it isn't working because I have a mix of complex and real values. Is there something that works the same as clamp but for real and complex values? I've tried looking some up and haven't gotten anything other than clamp.


Solution

  • I ended up using HardTanh with a setup like below

    for key, bounds in self.coefficient_bounds.items():
        min_value, max_value = bounds
        m = torch.nn.Hardtanh(min_value, max_value)
        # the input needs to be a tensor so we have to convert
        # coefficients[key] to a tensor
        input = torch.tensor(coefficients[key])
        coefficients[key] = m(input)