Refactor lcp & bimatrix initialization - #15
Merged
rahulsavani merged 4 commits intoJul 29, 2026
Conversation
rahulsavani
self-requested a review
July 24, 2026 04:52
nataliemes
force-pushed
the
refactor/update-initialization
branch
from
July 24, 2026 05:55
e01a50d to
bdfbb10
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors object construction for the core LCP (lcp) and bimatrix game (bimatrix) data structures by separating “parse from file” behavior into explicit from_file(...) class methods, while making __init__ accept the underlying data directly. This clarifies the APIs and removes type-dependent constructor behavior.
Changes:
- Refactor
lcp.__init__to accept(M, q, d)directly and addlcp.from_file(...)for parsing. - Refactor
bimatrix.__init__to accept(A, B)directly and addbimatrix.from_file(...)for parsing. - Update tests and helpers to use the new constructors /
from_fileentrypoints.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_lemke.py | Updates LCP parsing tests to use lcp.from_file and introduces a helper for constructing empty LCPs under the new API. |
| tests/test_lcp.py | Migrates fixture-based LCP construction from lcp(path) to lcp.from_file(path). |
| tests/test_bimatrix.py | Migrates fixture-based bimatrix construction from bimatrix(path) to bimatrix.from_file(path). |
| tests/sequence_form_helper.py | Updates helper to construct lcp(M, q, d) directly rather than creating then mutating an empty instance. |
| src/lemke/lemke.py | Implements new lcp(M, q, d) + lcp.from_file(...) API and updates CLI entry to use from_file. |
| src/lemke/bimatrix.py | Implements new bimatrix(A, B) + bimatrix.from_file(...) API and updates LCP creation to build (M, q, d) directly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
payoffmatrixandbimatrixclasses' redundant__init__()definitions (that were commented out) were removed.Previously,
lcp's__init__()method behaved differently based on the type of the argument:lcpinstance of that dimension with all entries set to 0;lcpinstance after parsing a file with that name.Now
_init__()accepts 3 arguments:M,q,d. Reading from a file is done by a class methodfrom_file, which accepts a string argument for a filename and returns the parsedlcpobject.bimatrix's__init__()was refactored in the same way: it acceptsA,Bpayoff matrices directly and a class methodfrom_filebuilds abimatrixobject after parsing a file.Note
These
__init__()methods should have error checking (for example, to verify that given vectors/matrices have the right dimensions) – this will be done later in a separate PR that updates error handling.