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>
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