// using Taylor approximation with a smooth swift from 10 < scale < 11
// to avoid numerical errors for large scale
b_app = (self.__m - 1) / (4 * self.scale)
s = torch.min(torch.max(torch.Tensor([0.]), self.scale - 10), torch.Tensor([1.]))
b = b_app * s + b_true * (1 - s)
a = (self.__m - 1 + 2 * self.scale + c) / 4
d = (4 * a * b) / (1 + b) - (self.__m - 1) * math.log(self.__m - 1)
After Change
def __sample_w_rej(self, shape):
//c = torch.sqrt((4 * (self.scale ** 2)) + (self.__m - 1) ** 2)
c = self.scale.type(torch.float64) * torch.sqrt(4 + ((self.__m - 1) ** 2) / (self.scale.type(torch.float64) ** 2))
b = (-2 * self.scale.type(torch.float64) + c) / (self.__m - 1)
a = (self.__m - 1 + 2 * self.scale.type(torch.float64) + c) / 4
d = (4 * a * b) / (1 + b) - (self.__m - 1) * math.log(self.__m - 1)