-
Notifications
You must be signed in to change notification settings - Fork 87
Emit flat/to_polars directly from the CSR store #968
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
Emit
flatandto_polarsdirectly from the CSR store, without building the dense rectangle first. Child of #756.LinearExpression.flat(linopy/expressions.py:2612) andto_polars(2693) both readself.data, expand to the paddedcoord_dims x _termrectangle, convert to a long frame and then mask the padding straight back out. For a CSR-backed expression that is a round trip through exactly the representation the long format is trying to reach.This matters twice: it is the export boundary, and it is the natural way to inspect a sparse expression, so it currently doubles as a densification trap.
Implementation ideas
csr_to_term_arrays(linopy/csr.py:506-532) already produces the flat term arrays. The work is to assemble the coordinate columns fromGrid(indexer,strides,indexes) and emit the polars frame directly, then haveflatshare that path.CSRConstraint.to_polars(linopy/constraints.py:1271) is the existing precedent on the constraint side and should be the model for the expression side.Note that a CSR-backed result is compact canonical form, so the emitted row count legitimately differs from the dense path where explicit zeros were pruned. See #925.