我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用torch.lerp()。
def test_lerp(self): def TH_lerp(a, b, weight): return a + weight * (b-a); size = (100, 100) a = torch.rand(*size) b = torch.rand(*size) w = random.random() result = torch.lerp(a, b, w) expected = a.clone() expected.map2_(a, b, lambda _, a, b: TH_lerp(a, b, w)) self.assertEqual(result, expected)
def test_lerp(self): def TH_lerp(a, b, weight): return a + weight * (b - a) size = (100, 100) a = torch.rand(*size) b = torch.rand(*size) w = random.random() result = torch.lerp(a, b, w) expected = a.clone() expected.map2_(a, b, lambda _, a, b: TH_lerp(a, b, w)) self.assertEqual(result, expected)