Validate empty reduction axes (#32156)
This pull request improves the handling and validation of empty set
reductions in the ONNX Runtime CPU reduction operators. It enforces
stricter checks for the axes input, prevents unnecessary memory
operations, and adds comprehensive tests to verify correct behavior for
various edge cases.
**Validation and Error Handling Improvements:**
- Enforces that the `axes` tensor input must be a 1D vector and only
processes it if it is present, improving robustness and error messages
for invalid input shapes.
- Adds a check to ensure that memory copying only occurs when the input
tensor is non-empty, avoiding redundant operations.
**Logic and Flow Adjustments:**
- Refactors the order of reduction logic to first handle empty axes
cases before checking for empty set input, ensuring correct execution
flow and output.
[[1]](diffhunk://#diff-61c3aeab1bffa9fc6cac3ace83df3a778d14c8f8d02a53ab46e5b776e567cdd4L971-R986)
[[2]](diffhunk://#diff-61c3aeab1bffa9fc6cac3ace83df3a778d14c8f8d02a53ab46e5b776e567cdd4L1016-R1031)
**Testing Enhancements:**
- Adds new tests to verify:
- Reduction when the optional `axes` input is missing (should reduce all
dimensions).
- Validation that the `axes` tensor must be a vector, with expected
error messages for invalid cases.
- Correct behavior for the `noop_with_empty_axes` attribute, both when
axes are omitted and when an empty axes tensor is provided.