我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用torch.rsqrt()。
def test_rsqrt(self): self._testMath(torch.rsqrt, lambda x: 1 / math.sqrt(x) if x > 0 else float('nan'))
def test_sigmoid(self): # TODO: why not simulate math.sigmoid like with rsqrt? inputValues = [-1000,-1,0,0.5,1,2,1000] expectedOutput = [0.0000, 0.2689, 0.5, 0.6225, 0.7311, 0.8808, 1.000] precision_4dps = 0.0002 def checkType(tensor): self.assertEqual(tensor(inputValues).sigmoid(), tensor(expectedOutput), precision_4dps) checkType(torch.FloatTensor) checkType(torch.DoubleTensor)
def test_sigmoid(self): # TODO: why not simulate math.sigmoid like with rsqrt? inputValues = [-1000, -1, 0, 0.5, 1, 2, 1000] expectedOutput = [0.0000, 0.2689, 0.5, 0.6225, 0.7311, 0.8808, 1.000] precision_4dps = 0.0002 def checkType(tensor): self.assertEqual(tensor(inputValues).sigmoid(), tensor(expectedOutput), precision_4dps) checkType(torch.FloatTensor) checkType(torch.DoubleTensor)