Skip to content

RFC: avoid redundant np.eye and precompute identity matrix in howson_lcp.py M construction#828

Merged
mmcky merged 2 commits intoQuantEcon:mainfrom
mnshkw:refactor/howson-lcp-remove-redundant-eye
Apr 6, 2026
Merged

RFC: avoid redundant np.eye and precompute identity matrix in howson_lcp.py M construction#828
mmcky merged 2 commits intoQuantEcon:mainfrom
mnshkw:refactor/howson-lcp-remove-redundant-eye

Conversation

@mnshkw
Copy link
Copy Markdown
Contributor

@mnshkw mnshkw commented Mar 19, 2026

Summary

This PR makes a small refactor in quantecon.game_theory.howson_lcp.

  • The code previously called np.eye(polymg.N) multiple times during the construction of the LCP matrix M.
  • This PR modifies it, computes the identity matrix once, and reuses it.

Changes

  • add eye_N = np.eye(polymg.N) before the M construction.
  • replace repeated uses of np.eye(polymg.N)[player] with eye_N[player]

The existing logic remains the same (including np.vstack / np.hstack structure unchanged).

Notes for Reviewers

All codes and documentation are written with assistance by LLMs.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 19, 2026

Coverage Status

coverage: 92.706% (+0.001%) from 92.705%
when pulling 4791395 on mnshkw:refactor/howson-lcp-remove-redundant-eye
into 8ba6e49 on QuantEcon:main.

@oyamad oyamad requested a review from Copilot March 19, 2026 04:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 quantecon.game_theory.howson_lcp.polym_lcp_solver to avoid repeated np.eye(polymg.N) allocations during LCP matrix M construction by precomputing and reusing the identity matrix.

Changes:

  • Precompute eye_N = np.eye(polymg.N) once before building M.
  • Replace repeated np.eye(polymg.N)[player] indexing with eye_N[player] inside the M block construction.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mnshkw mnshkw changed the title FIX: avoid redundant np.eye and precompute identity matrix in howson_lcp.py M construction RFC: avoid redundant np.eye and precompute identity matrix in howson_lcp.py M construction Mar 19, 2026
@oyamad oyamad added the ready label Mar 19, 2026
@mmcky
Copy link
Copy Markdown
Contributor

mmcky commented Apr 6, 2026

thanks @oyamad and @mnshkw

@mmcky mmcky merged commit 866de51 into QuantEcon:main Apr 6, 2026
13 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants