@@ -278,6 +278,7 @@ def test_tolist(self, tensor, expected):
278
278
"tensor" ,
279
279
[
280
280
tp .Tensor ([1 , 2 , 3 ]),
281
+ tp .ones ((2 , 2 )),
281
282
tp .Tensor ([1 , 2 , 3 ]) + tp .Tensor ([4 , 5 , 6 ]),
282
283
# This case should trigger datatype conversions.
283
284
(4 * tp .Tensor ([1 , 2 , 3 ])) + (3 * tp .Tensor ([4 , 5 , 6 ])),
@@ -291,8 +292,24 @@ def test_tolist(self, tensor, expected):
291
292
],
292
293
)
293
294
def test_stack_depth_of_build (self , tensor ):
294
- if any (info .function == "build" for info in tensor .stack_info ):
295
- # + 1 for inclusive bound
296
- assert any (
297
- info .function == "build" for info in tensor .stack_info [: tp .frontend .tensor .STACK_DEPTH_OF_BUILD + 1 ]
298
- )
295
+ tensor .stack_info .fetch_source_code ()
296
+
297
+ # Ensure that we do not include code for any frame until after the caller of `Tensor.build`
298
+ build_caller = len (tensor .stack_info )
299
+ for index , source_info in enumerate (tensor .stack_info ):
300
+ if source_info .function == "build" :
301
+ build_caller = index + 1
302
+ break
303
+
304
+ for index , source_info in enumerate (tensor .stack_info ):
305
+ # Once we reach user code we can stop checking
306
+ if source_info .file == __file__ :
307
+ assert source_info .code is not None
308
+ break
309
+
310
+ # We should include code starting one frame past the *caller* of `build`, i.e. we
311
+ # should not see a call to `build` in the code stack trace we display.
312
+ if index > build_caller :
313
+ assert source_info .code is not None
314
+ else :
315
+ assert source_info .code is None
0 commit comments