[BE]: Apply FURB118 (prev): replaces unnecessary lambdas with operator. (#116027)

This replaces a bunch of unnecessary lambdas with the operator package. This is semantically equivalent, but the operator package is faster, and arguably more readable. When the FURB rules are taken out of preview, I will enable it as a ruff check.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/116027
Approved by: https://github.com/malfet
This commit is contained in:
Aaron Gokaslan
2023-12-20 19:35:04 +00:00
committed by PyTorch MergeBot
parent 2d2016fdf8
commit 6de28e92d2
29 changed files with 115 additions and 107 deletions

View File

@ -2980,17 +2980,17 @@ class TestBinaryUfuncs(TestCase):
@onlyCPU
@dtypes(torch.float)
def test_cdiv(self, device, dtype):
self._test_cop(torch.div, lambda x, y: x / y, dtype, device)
self._test_cop(torch.div, operator.truediv, dtype, device)
@onlyCPU
@dtypes(torch.float)
def test_cremainder(self, device, dtype):
self._test_cop(torch.remainder, lambda x, y: x % y, dtype, device)
self._test_cop(torch.remainder, operator.mod, dtype, device)
@onlyCPU
@dtypes(torch.float)
def test_cmul(self, device, dtype):
self._test_cop(torch.mul, lambda x, y: x * y, dtype, device)
self._test_cop(torch.mul, operator.mul, dtype, device)
@onlyCPU
@dtypes(torch.float)