Skip to content

ENH: Plan the scipy.sparse matrix-to-array migration #879

Description

@mmcky

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)

  1. Now: accept both matrix and array inputs everywhere (sp.issparse already covers both); add a test leg that feeds csr_array inputs through MarkovChain / DiscreteDP.
  2. Next minor: convert internals to array semantics (explicit-axis reductions replacing np.matrix-shaped sums — removes the core.py:201 reliance).
  3. Announced release: switch sparse return types to arrays with a changelog notice and, if warranted, a one-release FutureWarning on the affected attributes.

Acceptance criteria

  • Suite green under sparse-array inputs end-to-end
  • No internal reliance on np.matrix semantics
  • Return-type change announced before it ships

From the July 2026 technical-debt audit (AI-assisted; claims verified against 28d4b3b on 2026-07-25).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions