我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用torch.fmod()。
def test_frac(self): self._testMath(torch.frac, lambda x: math.fmod(x, 1))
def test_trunc(self): self._testMath(torch.trunc, lambda x: x - math.fmod(x, 1))
def test_fmod(self): m1 = torch.Tensor(10,10).uniform_(-10., 10.) res1 = m1.clone() q = 2.1 res1[:,3].fmod_(q) res2 = m1.clone() for i in range(m1.size(1)): res2[i,3] = math.fmod(res2[i,3], q) self.assertEqual(res1, res2)
def test_cfmod(self): self._test_cop(torch.fmod, math.fmod)
def test_fmod(self): m1 = torch.Tensor(10, 10).uniform_(-10., 10.) res1 = m1.clone() q = 2.1 res1[:, 3].fmod_(q) res2 = m1.clone() for i in range(m1.size(1)): res2[i, 3] = math.fmod(res2[i, 3], q) self.assertEqual(res1, res2)