def _maybe_guard_negative_indices_for_coreml_scatter(x: Var, index: Var) -> Var:
        """
        Core ML `scatter_nd` op used to support negative indices,
        but starting from iOS 17 negative indices behaviour becomes undefined
        """
        if not is_current_opset_version_compatible_with(target.iOS17):
            return index

        cond = mb.greater_equal(x=index, y=0)
        x_shape = mb.shape(x=x)
        indices_shape = mb.shape(x=index)
        indices_last_dim = _utils.pymil_value_at(indices_shape, index.rank - 1)
        indices_last_dim_expand = mb.expand_dims(x=indices_last_dim, axes=[0])
        slice_shape = mb.slice_by_size(x=x_shape, begin=[0], size=indices_last_dim_expand)
        nonnegative_indices = mb.select(
            cond=cond,
            a=index,
            b=mb.add(x=index, y=slice_shape),
        )
        return nonnegative_indices

        Core ML `scatter_nd` op used to support negative indices,
        but starting from iOS 17 negative indices behaviour becomes undefined
        
coremltools/converters/mil/frontend/torch/ops.py