QuantEcon / QuantEcon/QuantEcon.py
ENH: Plan the scipy.sparse matrix-to-array migration
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.4k
- Forks
- 2.3k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 3
Description
Problem
markov/core.py, markov/ddp.py, markov/random.py, _graph_tools.py, and game_theory/localint.py are written against scipy.sparse matrix classes (csr_matrix, coo_matrix). SciPy's announced direction is sparse arrays; the matrix classes — whose semantics rest on np.matrix, itself slated for removal — are on the way out. Our dependence is behavioral, not just nominal: markov/core.py:201 comments that row_sums is np.matrix (ndim=2) and the surrounding reduction code relies on that quirk. And it is user-visible: public APIs accept and return these types (MarkovChain docstrings advertise scipy.sparse.csr_matrix).
Proposed change (staged)
- Now: accept both matrix and array inputs everywhere (
sp.issparsealready covers both); add a test leg that feedscsr_arrayinputs throughMarkovChain/DiscreteDP. - Next minor: convert internals to array semantics (explicit-axis reductions replacing
np.matrix-shaped sums — removes thecore.py:201reliance). - Announced release: switch sparse return types to arrays with a changelog notice and, if warranted, a one-release
FutureWarningon the affected attributes.
Acceptance criteria
- Suite green under sparse-array inputs end-to-end
- No internal reliance on
np.matrixsemantics - Return-type change announced before it ships
From the July 2026 technical-debt audit (AI-assisted; claims verified against 28d4b3b on 2026-07-25).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading markov/core.py, especially line 201, then review markov/ddp.py, markov/random.py, _graph_tools.py, and game_theory/localint.py for sparse matrix assumptions. Exercise MarkovChain and DiscreteDP with csr_array inputs, then use the acceptance criteria to assess array compatibility, removal of np.matrix reliance, and release-notice requirements.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100