Skip to content

Commit 85d1d7d

Browse files
Corrects STACK_DEPTH_OF_BUILD
1 parent faa23eb commit 85d1d7d

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

tripy/tests/frontend/test_tensor.py

+22-5
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def test_tolist(self, tensor, expected):
278278
"tensor",
279279
[
280280
tp.Tensor([1, 2, 3]),
281+
tp.ones((2, 2)),
281282
tp.Tensor([1, 2, 3]) + tp.Tensor([4, 5, 6]),
282283
# This case should trigger datatype conversions.
283284
(4 * tp.Tensor([1, 2, 3])) + (3 * tp.Tensor([4, 5, 6])),
@@ -291,8 +292,24 @@ def test_tolist(self, tensor, expected):
291292
],
292293
)
293294
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

tripy/tripy/frontend/tensor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# We include code for everything above the `BaseTraceOp.build` function, which is called at most
3838
# this many stack frames above the constructor.
39-
STACK_DEPTH_OF_BUILD = 4
39+
STACK_DEPTH_OF_BUILD = 5
4040

4141

4242
class TensorMeta(type):

0 commit comments

Comments
 (0)