mirror of
				https://github.com/pytorch/pytorch.git
				synced 2025-10-31 20:34:54 +08:00 
			
		
		
		
	use irange for loops 10 (#69394)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/69394 Modified loops in files under fbsource/fbcode/caffe2/ from the format ``` for(TYPE var=x0;var<x_max;x++) ``` to the format ``` for(const auto var: irange(xmax)) ``` This was achieved by running r-barnes's loop upgrader script (D28874212) with some modification to exclude all files under /torch/jit and a number of reversions or unused variable suppression warnings added by hand. Test Plan: Sandcastle Reviewed By: malfet Differential Revision: D32837991 fbshipit-source-id: fc7c4f76d2f32a17a0faf329294b3fe7cb81df32
This commit is contained in:
		
				
					committed by
					
						 Facebook GitHub Bot
						Facebook GitHub Bot
					
				
			
			
				
	
			
			
			
						parent
						
							2d5b3101c1
						
					
				
				
					commit
					afb742382a
				
			| @ -1,5 +1,6 @@ | ||||
| #include <gtest/gtest.h> | ||||
|  | ||||
| #include <c10/util/irange.h> | ||||
| #include <torch/torch.h> | ||||
|  | ||||
| #include <algorithm> | ||||
| @ -118,7 +119,7 @@ TEST_F(ModuleListTest, AccessWithAt) { | ||||
|   ASSERT_EQ(list->size(), 3); | ||||
|  | ||||
|   // returns the correct module for a given index | ||||
|   for (size_t i = 0; i < modules.size(); ++i) { | ||||
|   for (const auto i : c10::irange(modules.size())) { | ||||
|     ASSERT_EQ(&list->at<M>(i), modules[i].get()); | ||||
|   } | ||||
|  | ||||
| @ -143,7 +144,7 @@ TEST_F(ModuleListTest, AccessWithPtr) { | ||||
|   ASSERT_EQ(list->size(), 3); | ||||
|  | ||||
|   // returns the correct module for a given index | ||||
|   for (size_t i = 0; i < modules.size(); ++i) { | ||||
|   for (const auto i : c10::irange(modules.size())) { | ||||
|     ASSERT_EQ(list->ptr(i).get(), modules[i].get()); | ||||
|     ASSERT_EQ(list[i].get(), modules[i].get()); | ||||
|     ASSERT_EQ(list->ptr<M>(i).get(), modules[i].get()); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user