Skip to content

Commit 6e84a34

Browse files
Changes intermediate
1 parent 5312cb5 commit 6e84a34

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

pytensor/tensor/rewriting/subtensor.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,26 +406,24 @@ def local_replace_slice(fgraph, node):
406406
if not isinstance(s, slice):
407407
continue
408408

409-
idx_change = False
410409
start = s.start
411410
stop = s.stop
412411
step = s.step
413412
if extract_constant(start, only_process_constants=True) == 0:
414-
idx_change = True
413+
idx_flag = True
415414
start = None
416415

417416
if extract_constant(stop, only_process_constants=True) == x.type.shape[dim]:
418-
idx_change = True
417+
idx_flag = True
419418
stop = None
420419

421420
if extract_constant(step, only_process_constants=True) == 1:
422-
idx_change = True
421+
idx_flag = True
423422
step = None
424423

425-
if idx_change:
426-
idx_flag = True
427-
new_idxs[dim] = slice(start, stop, step)
424+
new_idxs[dim] = slice(start, stop, step)
428425

426+
assert node.outputs[0].type == x[tuple(new_idxs)].type
429427
if idx_flag is True:
430428
return [x[tuple(new_idxs)]]
431429
else:

tests/tensor/rewriting/test_subtensor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,6 +2411,7 @@ def test_slice_canonicalize(fstop, lstop, lstep):
24112411
f = pytensor.function([x], y)
24122412

24132413
test_y = f(np.random.normal(size=(3, 5, 6, 9)))
2414+
# test_y = f.maker.fgraph.toposort()
24142415

24152416
y1 = x[None:None:None, None:None:None, None:7:None, None:None:-1]
24162417

@@ -2420,6 +2421,7 @@ def test_slice_canonicalize(fstop, lstop, lstep):
24202421
f1 = pytensor.function([x], y1)
24212422

24222423
expected_y = f1(np.random.normal(size=(3, 5, 6, 9)))
2424+
# expected_y = f1.maker.fgraph.toposort()
24232425

24242426
# TODO: test using equal_computations
24252427
assert test_y.all() == expected_y.all()

0 commit comments

Comments
 (0)