Skip to content

Keep CSR backing through where/mask/sel/isel/loc #966

Description

@FabianHofmann

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, loc and __getitem__. Child of #756.

All of them densify today: where (linopy/expressions.py:1892-1942), mask (1666), sel/isel and the rest of the exprwrap bindings (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 const write, since absence is already carried by a NaN const. Label selection is a reindexed onto a narrower grid, which already exists. Positional selection is a row gather.

Implementation ideas

  • where(cond): evaluate cond over the grid, then write NaN into const for the false cells. The v1 rule that an absent cell has no terms is already implemented for added (linopy/csr.py:395-398), so the term arrays may be left untouched or pruned, whichever matches that invariant.
  • sel/loc: build the target Grid and route through the existing reindexed.
  • isel/__getitem__: a row gather on indptr plus a new Grid from the selected indexes.

Note the ordering interaction with #925: pruning versus preserving explicit zeros should follow whatever policy that issue settles.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestperformanceThis improves performance while not (meaningfully) altering behaviour for userssparseSparse / CSR-backed expressions and constraints

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions