mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[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:
committed by
PyTorch MergeBot
parent
2d2016fdf8
commit
6de28e92d2
@ -22,6 +22,7 @@ from torch.testing._internal.common_dtype import (
|
||||
all_types_and_complex, floating_and_complex_types_and)
|
||||
from torch.testing._internal.opinfo.definitions.sparse import validate_sample_input_sparse
|
||||
from test_sparse import CUSPARSE_SPMM_COMPLEX128_SUPPORTED
|
||||
import operator
|
||||
|
||||
if TEST_SCIPY:
|
||||
import scipy.sparse as sp
|
||||
@ -3310,7 +3311,7 @@ class TestSparseCSR(TestCase):
|
||||
|
||||
# random bool vector w/ length equal to max possible nnz for the sparse_shape
|
||||
mask_source = make_tensor(batch_mask_shape, dtype=torch.bool, device=device).flatten()
|
||||
n_batch = functools.reduce(lambda x, y: x * y, batch_shape, 1)
|
||||
n_batch = functools.reduce(operator.mul, batch_shape, 1)
|
||||
|
||||
# stack random permutations of the source for each batch
|
||||
mask = torch.stack([mask_source[torch.randperm(mask_source.numel())]
|
||||
|
||||
Reference in New Issue
Block a user