Skip to content

fix: multiply constant or one-term expression by multi-term expression - #1076

Open
anveshachuri wants to merge 2 commits into
PyPSA:masterfrom
anveshachuri:fix-constant-times-multiterm
Open

anveshachuri wants to merge 2 commits into
PyPSA:masterfrom
anveshachuri:fix-constant-times-multiterm

Conversation

@anveshachuri

Copy link
Copy Markdown

Closes #1055.

I picked up this issue because multiplication behaved asymmetrically depending on the order of the operands: a constant or one-term expression could multiply a multi-term expression in one direction but fail in the other. This change fixes that inconsistency while preserving the existing restriction on multiplying two multi-term expressions.

I added tests covering both multiplication orders for constant and one-term expressions on dense and sparse backends, while verifying that multi-term × multi-term still raises TypeError. The full test suite passes locally, excluding test/remote, which requires the oetc extra.

Checklist

  • AI-generated content is marked (see AGENTS.md).
  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@codspeed

codspeed Bot commented Oct 27, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 181 untouched benchmarks
⏩ 181 skipped benchmarks1


Comparing anveshachuri:fix-constant-times-multiterm (201f26b) with master (9ad435d)

Open in CodSpeed

Footnotes

  1. 181 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@FabianHofmann

Copy link
Copy Markdown
Collaborator

@claude why is there a performance warning for the sparse path?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Constant LinearExpression * multi-term LinearExpression raises TypeError (mirrored product works)

2 participants