Skip to content

Fix argument order in distribution.unflatten()#141

Open
rogerSuperBuilderAlpha wants to merge 2 commits into
wmayner:feature/iit-4.0from
rogerSuperBuilderAlpha:fix/unflatten-arg-order
Open

Fix argument order in distribution.unflatten()#141
rogerSuperBuilderAlpha wants to merge 2 commits into
wmayner:feature/iit-4.0from
rogerSuperBuilderAlpha:fix/unflatten-arg-order

Conversation

@rogerSuperBuilderAlpha

Copy link
Copy Markdown

Problem

distribution.unflatten() is broken for every call:

def unflatten(repertoire, purview, N, big_endian=False):
    ...
    return repertoire.reshape(repertoire_shape(purview, N), order=order)

but the helper's signature is repertoire_shape(all_node_indices, purview). The arguments are swapped, so N (an int) lands where the purview iterable is expected, and the membership test inside repertoire_shape fails:

TypeError: argument of type 'int' is not iterable

This raises on any invocation (since N is always an int), and is currently caught by test/test_distribution.py::test_unflatten, which fails on a clean checkout.

Change

Pass range(N) as the node indices and purview as the purview:

return repertoire.reshape(repertoire_shape(range(N), purview), order=order)

This matches the (all_node_indices, purview) contract used at every other repertoire_shape() call site (e.g. in subsystem.py, repertoire.py, and the function's own docstring example).

Verification

  • test_distribution.py::test_unflatten now passes (all three assertions, including the (0, 2), 3 -> shape (2, 1, 2) reshape case).
  • Full core suite (pytest test pyphi, excluding the optional ray/redis modules) shows no new failures from this change.

rogerSuperBuilderAlpha and others added 2 commits May 30, 2026 11:18
`unflatten(repertoire, purview, N)` called `repertoire_shape(purview, N)`, but
the signature is `repertoire_shape(all_node_indices, purview)`. The swapped
arguments meant `N` (an int) was used where an iterable of purview indices was
expected, so `i in purview` raised `TypeError: argument of type 'int' is not
iterable` on every call — the function was unusable.

Pass `range(N)` as the node indices and `purview` as the purview, matching the
contract used at every other `repertoire_shape()` call site. This makes the
existing `test_unflatten` pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
wmayner added a commit that referenced this pull request Jun 26, 2026
Audit of the 16 open PRs against current main: every fix-type PR
(#141 unflatten arg order, #134 np.log2 out=, #114 strong-connectivity
short-circuit) is already resolved in 2.0, and the rest are moot or
superseded (jsonify tolerance, ray/redis importorskip, 2-3 relation
plot cap, pandas rename, old TPM/substrate PRs, benchmarking notebook).
Nothing left to absorb; only the GitHub closes remain (maintainer step).
Update the "Open PRs to Absorb" section and the P15 status lines.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012dtSzF2YgDjGpFC9mA47ve
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.

1 participant