Skip to content

Refactor lcp & bimatrix initialization - #15

Merged
rahulsavani merged 4 commits into
gambitproject:mainfrom
nataliemes:refactor/update-initialization
Jul 29, 2026
Merged

Refactor lcp & bimatrix initialization#15
rahulsavani merged 4 commits into
gambitproject:mainfrom
nataliemes:refactor/update-initialization

Conversation

@nataliemes

@nataliemes nataliemes commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator
  • payoffmatrix and bimatrix classes' redundant __init__() definitions (that were commented out) were removed.

  • Previously, lcp's __init__() method behaved differently based on the type of the argument:

    • for an integer, it created an lcp instance of that dimension with all entries set to 0;
    • for a string, it created an lcp instance after parsing a file with that name.

    Now _init__() accepts 3 arguments: M, q, d. Reading from a file is done by a class method from_file, which accepts a string argument for a filename and returns the parsed lcp object.

  • bimatrix's __init__() was refactored in the same way: it accepts A, B payoff matrices directly and a class method from_file builds a bimatrix object 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.

@rahulsavani
rahulsavani self-requested a review July 24, 2026 04:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 add lcp.from_file(...) for parsing.
  • Refactor bimatrix.__init__ to accept (A, B) directly and add bimatrix.from_file(...) for parsing.
  • Update tests and helpers to use the new constructors / from_file entrypoints.

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.

@rahulsavani rahulsavani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@rahulsavani
rahulsavani merged commit 175c4f5 into gambitproject:main Jul 29, 2026
8 checks passed
@nataliemes
nataliemes deleted the refactor/update-initialization branch July 31, 2026 10:24
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.

3 participants