def __call__(self, x): # find appropriate linear segments i = find_index(self.lookup, x, hi=self.hi) f = self.segments[i] # approximate linearly from support point # negative overheads make no sense, so avoid them return max(0, f(x))
def inverse(self, y): i = find_index(self.reverse_lookup, y, hi=self.hi) f = self.segments[i] return f.inverse(y)