You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2021/08/25 15:19:21 UTC

[GitHub] [incubator-mxnet] szha commented on a change in pull request #20505: If variable is not used within the loop body, start the name with an underscore

szha commented on a change in pull request #20505:
URL: https://github.com/apache/incubator-mxnet/pull/20505#discussion_r695844760



##########
File path: python/mxnet/operator.py
##########
@@ -824,7 +824,7 @@ def infer_storage_type_backward_entry(num_tensor, tensor_stypes, tags, _):
                         "entries in returned aux stypes, " \
                         "got %d."%(len(tensors[4]), len(ret[4]))
                     rstype = []
-                    for i, ret_list in enumerate(ret):
+                    for _, ret_list in enumerate(ret):

Review comment:
       ```suggestion
                       for ret_list in ret:
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -382,25 +382,25 @@ def test_dataset_filter():
     a = mx.gluon.data.SimpleDataset([i for i in range(length)])
     a_filtered = a.filter(lambda x: x % 10 == 0)
     assert(len(a_filtered) == 10)
-    for idx, sample in enumerate(a_filtered):
+    for _, sample in enumerate(a_filtered):

Review comment:
       ```suggestion
       for sample in a_filtered:
   ```

##########
File path: python/mxnet/test_utils.py
##########
@@ -1584,7 +1584,7 @@ def smaller_dtype(dt1, dt2):
             else:
                 arg_params[n] = np.random.normal(size=arr.shape,
                                                  scale=scale).astype(rand_type)
-    for n, arr in exe_list[0].aux_dict.items():
+    for n, _ in exe_list[0].aux_dict.items():

Review comment:
       ```suggestion
       for n in exe_list[0].aux_dict:
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -382,25 +382,25 @@ def test_dataset_filter():
     a = mx.gluon.data.SimpleDataset([i for i in range(length)])
     a_filtered = a.filter(lambda x: x % 10 == 0)
     assert(len(a_filtered) == 10)
-    for idx, sample in enumerate(a_filtered):
+    for _, sample in enumerate(a_filtered):
         assert sample % 10 == 0
     a_xform_filtered = a.transform(lambda x: x + 1).filter(lambda x: x % 10 == 0)
     assert(len(a_xform_filtered) == 10)
     # the filtered data is already transformed
-    for idx, sample in enumerate(a_xform_filtered):
+    for _, sample in enumerate(a_xform_filtered):

Review comment:
       ```suggestion
       for sample in a_xform_filtered:
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -325,14 +325,14 @@ def _batchify(data):
 def test_multi_worker_forked_data_loader():
     data = _Dummy(False)
     loader = DataLoader(data, batch_size=40, batchify_fn=_batchify, num_workers=2)
-    for epoch in range(1):
-        for i, data in enumerate(loader):
+    for _ in range(1):
+        for _ in enumerate(loader):

Review comment:
       ```suggestion
           for _ in loader:
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -451,7 +451,7 @@ def test_dataset_take():
     assert len(a_take_10) == count
     expected_total = sum([i for i in range(count)])
     total = 0
-    for idx, sample in enumerate(a_take_10):
+    for _, sample in enumerate(a_take_10):

Review comment:
       ```suggestion
       for sample in a_take_10:
   ```

##########
File path: tests/python/unittest/test_gluon_probability_v2.py
##########
@@ -1842,7 +1842,7 @@ def forward(self, loc, scale, *args):
                             rtol=1e-3, use_broadcast=False)
 
     # Test sampling
-    for shape, hybridize in itertools.product(shapes, [True, False]):
+    for shape, _ in itertools.product(shapes, [True, False]):

Review comment:
       I think hybridize should be kept and on line 1854 insert the following
   ```python
           if hybridize:
               net.hybridize()
   ```

##########
File path: python/mxnet/gluon/contrib/estimator/estimator.py
##########
@@ -392,7 +392,7 @@ def fit(self, train_data,
             for handler in epoch_begin:
                 handler.epoch_begin(estimator_ref)
 
-            for i, batch in enumerate(train_data):
+            for _, batch in enumerate(train_data):

Review comment:
       ```suggestion
               for batch in train_data:
   ```

##########
File path: tests/python/unittest/test_numpy_op.py
##########
@@ -8396,7 +8396,7 @@ def dbg(name, data):
                                           dtype=dtype))
                 for optimize in [False, True]:
                     x = []
-                    for (iop, op) in enumerate(operands):
+                    for (iop, _) in enumerate(operands):

Review comment:
       ```suggestion
                       for iop in range(len(operands)):
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -417,7 +417,7 @@ def test_dataset_shard():
     assert len(shard_3) == 2
     total = 0
     for shard in [shard_0, shard_1, shard_2, shard_3]:
-        for idx, sample in enumerate(shard):
+        for _, sample in enumerate(shard):

Review comment:
       ```suggestion
           for sample in shard:
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -382,25 +382,25 @@ def test_dataset_filter():
     a = mx.gluon.data.SimpleDataset([i for i in range(length)])
     a_filtered = a.filter(lambda x: x % 10 == 0)
     assert(len(a_filtered) == 10)
-    for idx, sample in enumerate(a_filtered):
+    for _, sample in enumerate(a_filtered):
         assert sample % 10 == 0
     a_xform_filtered = a.transform(lambda x: x + 1).filter(lambda x: x % 10 == 0)
     assert(len(a_xform_filtered) == 10)
     # the filtered data is already transformed
-    for idx, sample in enumerate(a_xform_filtered):
+    for _, sample in enumerate(a_xform_filtered):
         assert sample % 10 == 0
 
 def test_dataset_filter_handle():
     length = 100
     a = mx.gluon.data.SimpleDataset(np.arange(length))
     a_filtered = a.filter(lambda x: x % 10 == 0).__mx_handle__()
     assert(len(a_filtered) == 10)
-    for idx, sample in enumerate(a_filtered):
+    for _, sample in enumerate(a_filtered):

Review comment:
       ```suggestion
       for sample in a_filtered:
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -325,14 +325,14 @@ def _batchify(data):
 def test_multi_worker_forked_data_loader():
     data = _Dummy(False)
     loader = DataLoader(data, batch_size=40, batchify_fn=_batchify, num_workers=2)
-    for epoch in range(1):
-        for i, data in enumerate(loader):
+    for _ in range(1):
+        for _ in enumerate(loader):
             pass
 
     data = _Dummy(True)
     loader = DataLoader(data, batch_size=40, batchify_fn=_batchify_list, num_workers=2)
-    for epoch in range(1):
-        for i, data in enumerate(loader):
+    for _ in range(1):
+        for _ in enumerate(loader):

Review comment:
       ```suggestion
           for _ in loader:
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -435,7 +435,7 @@ def test_dataset_shard_handle():
     assert len(shard_3) == 2
     total = 0
     for shard in [shard_0, shard_1, shard_2, shard_3]:
-        for idx, sample in enumerate(shard):
+        for _, sample in enumerate(shard):

Review comment:
       ```suggestion
           for sample in shard:
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -382,25 +382,25 @@ def test_dataset_filter():
     a = mx.gluon.data.SimpleDataset([i for i in range(length)])
     a_filtered = a.filter(lambda x: x % 10 == 0)
     assert(len(a_filtered) == 10)
-    for idx, sample in enumerate(a_filtered):
+    for _, sample in enumerate(a_filtered):
         assert sample % 10 == 0
     a_xform_filtered = a.transform(lambda x: x + 1).filter(lambda x: x % 10 == 0)
     assert(len(a_xform_filtered) == 10)
     # the filtered data is already transformed
-    for idx, sample in enumerate(a_xform_filtered):
+    for _, sample in enumerate(a_xform_filtered):
         assert sample % 10 == 0
 
 def test_dataset_filter_handle():
     length = 100
     a = mx.gluon.data.SimpleDataset(np.arange(length))
     a_filtered = a.filter(lambda x: x % 10 == 0).__mx_handle__()
     assert(len(a_filtered) == 10)
-    for idx, sample in enumerate(a_filtered):
+    for _, sample in enumerate(a_filtered):
         assert sample % 10 == 0
     a_xform_filtered = a.transform(lambda x: x + 1).filter(lambda x: x % 10 == 0)
     assert(len(a_xform_filtered) == 10)
     # the filtered data is already transformed
-    for idx, sample in enumerate(a_xform_filtered):
+    for _, sample in enumerate(a_xform_filtered):

Review comment:
       ```suggestion
       for sample in a_xform_filtered:
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -477,7 +477,7 @@ def test_dataset_take_handle():
     assert len(a_take_10) == count
     expected_total = sum([i for i in range(count)])
     total = 0
-    for idx, sample in enumerate(a_take_10):
+    for _, sample in enumerate(a_take_10):

Review comment:
       ```suggestion
       for sample in a_take_10:
   ```

##########
File path: tests/python/unittest/test_numpy_interoperability.py
##########
@@ -421,7 +421,7 @@ def _add_workload_swapaxes():
     # assertRaises(np.AxisError, np.swapaxes, -5, 0)
     for i in range(-4, 4):
         for j in range(-4, 4):
-            for k, src in enumerate((a, b)):
+            for _, src in enumerate((a, b)):

Review comment:
       ```suggestion
               for src in (a, b):
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -486,7 +486,7 @@ def test_dataset_take_handle():
     assert len(a_xform_take_10) == count
     expected_total = sum([i for i in range(count)])
     total = 0
-    for idx, sample in enumerate(a_xform_take_10):
+    for _, sample in enumerate(a_xform_take_10):

Review comment:
       ```suggestion
       for sample in a_xform_take_10:
   ```

##########
File path: tests/python/unittest/test_numpy_op.py
##########
@@ -8410,10 +8410,10 @@ def dbg(name, data):
                     assert_almost_equal(out_mx.asnumpy(), expected_np, rtol=rtol, atol=atol)
                     out_mx.backward()
                     cur_grad = []
-                    for (iop, op) in enumerate(x):
+                    for (_, op) in enumerate(x):

Review comment:
       ```suggestion
                       for op in x:
   ```

##########
File path: tests/python/unittest/test_numpy_op.py
##########
@@ -4846,7 +4846,7 @@ def forward(self, param1, param2):
     dtypes = ['float16', 'float32', 'float64']
     op_names = ['uniform_n', 'normal_n']
 
-    for bshape, eshape, dtype, op in itertools.product(batch_shapes, event_shapes, dtypes, op_names):
+    for bshape, eshape, _, op in itertools.product(batch_shapes, event_shapes, dtypes, op_names):

Review comment:
       dtype should be added to line 4834 and 4842 so that different data types are actually tested.

##########
File path: tests/python/unittest/test_numpy_op.py
##########
@@ -8410,10 +8410,10 @@ def dbg(name, data):
                     assert_almost_equal(out_mx.asnumpy(), expected_np, rtol=rtol, atol=atol)
                     out_mx.backward()
                     cur_grad = []
-                    for (iop, op) in enumerate(x):
+                    for (_, op) in enumerate(x):
                         cur_grad.append(op.grad.asnumpy())
                     grad.append(cur_grad)
-                for (iop, op) in enumerate(grad[0]):
+                for (iop, _) in enumerate(grad[0]):

Review comment:
       ```suggestion
                   for iop in range(len(grad[0])):
   ```

##########
File path: tests/python/unittest/test_gluon_data.py
##########
@@ -460,7 +460,7 @@ def test_dataset_take():
     assert len(a_xform_take_10) == count
     expected_total = sum([i * 10 for i in range(count)])
     total = 0
-    for idx, sample in enumerate(a_xform_take_10):
+    for _, sample in enumerate(a_xform_take_10):

Review comment:
       ```suggestion
       for sample in a_xform_take_10:
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mxnet.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org