linsen458-spec opened a new pull request, #20316: URL: https://github.com/apache/tvm/pull/20316
Part of #20297 — this is the uncontroversial first slice (negative index normalization); the bounds-checking design for out-of-range indices is still under discussion on the issue. `topi.gather_nd` passed index values through to the data access without any normalization, so an in-range negative index silently read out of bounds instead of counting from the end of the axis. `topi.scatter_elements` already normalizes negative indices (`k + (k < 0) * axis_range`), and the ONNX GatherND importer works around the gap by rewriting indices at import time (#20219) — but indices computed at runtime, or built through the relax API directly, still hit the raw path. This normalizes in-range negative indices in the generated TIR, matching the ONNX GatherND semantics and the existing `scatter_elements` behavior. No changes for non-negative indices. Testing: - New `test_gather_nd_negative_indices_topi` covers `batch_dims=0` and `batch_dims=1` with indices spread over the full negative range of each axis, verified against the numpy reference (and it fails on unpatched main). - The existing ONNX GatherND tests, including `test_gather_nd_negative_indices`, all pass unchanged (importer normalization composes fine with this). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
