-
Notifications
You must be signed in to change notification settings - Fork 87
Keep CSR backing through where/mask/sel/isel/loc #966
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or requestperformanceThis improves performance while not (meaningfully) altering behaviour for usersThis improves performance while not (meaningfully) altering behaviour for userssparseSparse / CSR-backed expressions and constraintsSparse / CSR-backed expressions and constraints
Description
Activity
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestperformanceThis improves performance while not (meaningfully) altering behaviour for usersThis improves performance while not (meaningfully) altering behaviour for userssparseSparse / CSR-backed expressions and constraintsSparse / CSR-backed expressions and constraints
Note
The following content was generated by AI.
Describe the feature you'd like to see
Keep the CSR backing through selection and masking:
where,mask,sel,isel,locand__getitem__. Child of #756.All of them densify today:
where(linopy/expressions.py:1892-1942),mask(1666),sel/iseland the rest of theexprwrapbindings (2245-2297),__getitem__(1537-1544). Conditional constraints appear in nearly every real model, so this is on the common path.On a CSR store these are among the cheapest operations available. Masking is a row selection plus a
constwrite, since absence is already carried by a NaNconst. Label selection is areindexedonto a narrower grid, which already exists. Positional selection is a row gather.Implementation ideas
where(cond): evaluatecondover the grid, then write NaN intoconstfor the false cells. The v1 rule that an absent cell has no terms is already implemented foradded(linopy/csr.py:395-398), so the term arrays may be left untouched or pruned, whichever matches that invariant.sel/loc: build the targetGridand route through the existingreindexed.isel/__getitem__: a row gather onindptrplus a newGridfrom the selected indexes.Note the ordering interaction with #925: pruning versus preserving explicit zeros should follow whatever policy that issue settles.