Skip to content

[Utilities] skip map_indices when the variable map of IndexMap is the identity - #3118

Open
blegat wants to merge 1 commit into
bl/clever_dict_identityfrom
bl/map_indices_identity
Open

blegat wants to merge 1 commit into
bl/clever_dict_identityfrom
bl/map_indices_identity

Conversation

@blegat

@blegat blegat commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

We spend time doing map_indices even though this mapping is often trivial! As side benefit, it prevents the copy from destroying aliasing information and, if we go for #2802, that dictionary won't get filled if the variable mapping is trivial.

Does MOI assume map_indices copies?

No. The docstring never promised a copy, and index-free values (ObjectOrTupleOrArrayWithoutIndex, ScalarConstantChange) are already returned without copying. We have the convention in MOI that when a models receive a something, it needs to copy it. But we do not also need to give copies otherwise we're just copying on both sides. So just returning the object without copying is fine if the mapping is trivial.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants