@@ -85,4 +85,26 @@ INSTANTIATE_TEST_SUITE_P(Transpose, TransposeQU8, rank_params);
8585INSTANTIATE_TEST_SUITE_P (Transpose, TransposeF16, rank_params);
8686INSTANTIATE_TEST_SUITE_P (Transpose, TransposeF32, rank_params);
8787
88+ TEST (Transpose, reshape_rejects_input_rank_mismatch) {
89+ ASSERT_EQ (xnn_status_success, xnn_initialize (nullptr /* allocator */ ));
90+
91+ // The permutation fixes the operator rank at define time. An external input
92+ // may be reshaped to a different rank at runtime; the reshape must reject the
93+ // mismatch instead of transposing with a stale dimension count and reading
94+ // past the input buffer.
95+ const std::vector<size_t > perm = {2 , 0 , 1 };
96+ SubgraphTester subgraph (2 );
97+ subgraph.AddInputTensor (3 , xnn_datatype_fp32, 0 )
98+ .AddOutputTensor (3 , xnn_datatype_fp32, 1 )
99+ .AddTranspose (perm, 0 , 1 );
100+ if (subgraph.CreateRuntime () == xnn_status_unsupported_hardware) {
101+ GTEST_SKIP ();
102+ }
103+
104+ std::vector<float > data (6 , 0 .0f );
105+ subgraph.ReshapeExternalTensor (std::vector<size_t >({2 , 3 }), data.data (), 0 )
106+ .ReshapeRuntime ();
107+ EXPECT_EQ (subgraph.Status (), xnn_status_invalid_parameter);
108+ }
109+
88110} // namespace xnnpack
0 commit comments