You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tensorflow/tensorflow#127248 reported that keras.ops.rot90 returned incorrect values for k > 1 when rotating a batched, non-square plane — e.g. an input of shape (2, 2, 3) with axes=(1, 2) and k=2 returned -232.0 where -577.0 was expected.
Root cause: the TensorFlow backend flattened the leading (batch) axes into a (-1, h, w) tensor and reshaped back afterwards, which mixes elements across the batch dimension whenever k > 1 and h != w.
This was fixed by #23435 (merged 2026-08-14), which replaced the reshape-based implementation with tf.reverse + swapaxes applied only to the last two axes. I re-ran the original reproducer from tensorflow#127248 against current master and it now returns the expected -577.0, so the bug itself is resolved.
Problem: the fix is not protected by any test
The test added in #23435, test_non_square_rotation, only covers a rank-2 array ((2, 3)). Every existing test that uses a rank-3 or rank-4 input (test_3d_operations, test_image_processing) only exercises the default k=1.
The combination rank > 2 + non-square plane + k > 1 — precisely the case that was broken — is therefore not covered by any test in the suite.
I verified this by reverting the TensorFlow backend rot90 to its pre-#23435 implementation and re-running NumPyTestRot90: every pre-existing test still passed except test_non_square_rotation, i.e. the batched regression would be silently reintroduced without anyone noticing.
Proposal
Add test_batched_non_square_rotation to keras/src/ops/numpy_test.py, parameterised over 3-D and 4-D inputs with non-square rotation planes, checking k in {0, 1, 2, 3, 4, -1, -2, -3} against numpy.rot90.
Verification performed locally (TensorFlow backend):
On current master: 22/22 NumPyTestRot90 tests pass.
Background
tensorflow/tensorflow#127248reported thatkeras.ops.rot90returned incorrect values fork > 1when rotating a batched, non-square plane — e.g. an input of shape(2, 2, 3)withaxes=(1, 2)andk=2returned-232.0where-577.0was expected.Root cause: the TensorFlow backend flattened the leading (batch) axes into a
(-1, h, w)tensor and reshaped back afterwards, which mixes elements across the batch dimension wheneverk > 1andh != w.This was fixed by #23435 (merged 2026-08-14), which replaced the reshape-based implementation with
tf.reverse+swapaxesapplied only to the last two axes. I re-ran the original reproducer from tensorflow#127248 against currentmasterand it now returns the expected-577.0, so the bug itself is resolved.Problem: the fix is not protected by any test
The test added in #23435,
test_non_square_rotation, only covers a rank-2 array ((2, 3)). Every existing test that uses a rank-3 or rank-4 input (test_3d_operations,test_image_processing) only exercises the defaultk=1.The combination rank > 2 + non-square plane +
k > 1— precisely the case that was broken — is therefore not covered by any test in the suite.I verified this by reverting the TensorFlow backend
rot90to its pre-#23435 implementation and re-runningNumPyTestRot90: every pre-existing test still passed excepttest_non_square_rotation, i.e. the batched regression would be silently reintroduced without anyone noticing.Proposal
Add
test_batched_non_square_rotationtokeras/src/ops/numpy_test.py, parameterised over 3-D and 4-D inputs with non-square rotation planes, checkingk in {0, 1, 2, 3, 4, -1, -2, -3}againstnumpy.rot90.Verification performed locally (TensorFlow backend):
master: 22/22NumPyTestRot90tests pass.test_non_square_rotation), confirming the new tests actually catch the regression.axesincluding negative indices, randomkin[-7, 7]) all matchnumpy.rot90onmaster.I have the PR ready to link to this issue.