@@ -4401,57 +4401,6 @@ def func(x, y):
44014401
44024402 self .assertEqual (compiled (a , b ), func (a , b ))
44034403
4404- @fresh_cache ()
4405- @torch ._dynamo .config .patch ("capture_scalar_outputs" , True )
4406- def test_narrow_unbacked_start (self ):
4407- def func (x , start , length ):
4408- # unbacked start
4409- u0 = start .item ()
4410- return torch .narrow (x , 0 , u0 , length )
4411-
4412- compiled_func = torch .compile (func , fullgraph = True , backend = "inductor" )
4413-
4414- x = torch .tensor ([1 , 2 , 3 , 4 , 5 , 6 ])
4415-
4416- # Test cases: (start, length)
4417- test_cases = [
4418- # Negative starts
4419- (- 2 , 2 ), # Start from second-to-last element
4420- (- 1 , 1 ), # Start from last element
4421- (- 3 , 3 ), # Start from third-to-last element
4422- (- 6 , 2 ), # Start from beginning (negative)
4423- (- 4 , 1 ), # Start from fourth-to-last element
4424- # Positive starts
4425- (0 , 2 ), # Start from beginning
4426- (1 , 3 ), # Start from second element
4427- (2 , 2 ), # Start from third element
4428- (4 , 2 ), # Start near end
4429- # Edge cases
4430- (0 , 6 ), # Full tensor
4431- (0 , 1 ), # Single element from start
4432- (5 , 1 ), # Single element from end
4433- ]
4434-
4435- for start_val , length in test_cases :
4436- with self .subTest (start = start_val , length = length ):
4437- start = torch .tensor ([start_val ])
4438-
4439- # Test with compiled function
4440- result_compiled = compiled_func (x , start , length )
4441-
4442- # Test with eager function (expected behavior)
4443- result_eager = func (x , start , length )
4444-
4445- # Compare results
4446- self .assertEqual (result_compiled , result_eager )
4447-
4448- @fresh_cache ()
4449- @torch ._dynamo .config .patch ("capture_scalar_outputs" , True )
4450- @torch ._inductor .config .patch ("cpp_wrapper" , True )
4451- def test_narrow_unbacked_start_cpp_wrapper (self ):
4452- """Test narrow with unbacked start with cpp_wrapper"""
4453- self .test_narrow_unbacked_start ()
4454-
44554404
44564405instantiate_parametrized_tests (TestUnbacked )
44574406
0 commit comments