Skip to content

Index integer_array_t in NumPy like in VUnit - #26

Merged
ru551n merged 1 commit into
VUnit:mainfrom
ru551n:integer-array-xyz
Oct 14, 2026
Merged

ru551n merged 1 commit into
VUnit:mainfrom
ru551n:integer-array-xyz

Conversation

@ru551n

@ru551n ru551n commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

An integer_array_t is now indexed in Python like in VUnit: get(a, x, y, z) is a[x, y, z], with shape (width, height, depth). Before, the indices of the first two axes were swapped, a[y, x, z] with shape (height, width, depth).

This is a breaking change, with a release note entry.

Array VHDL Python before Python now
1D get(a, i) a[i] a[i] (unchanged)
2D get(a, x, y) a[y, x], shape (height, width) a[x, y], shape (width, height)
3D get(a, x, y, z) a[y, x, z] a[x, y, z], shape (width, height, depth)

How

  • Arguments: VUnit stores an array by y, then x, then z. An argument is still a view of the transferred storage, with no copy, and that view has its first two axes swapped.
  • Returned arrays: they get the reverse swap before they're copied out, so width and height now come from shape[0] and shape[1].
  • Word size: a function returning its own argument still keeps that argument's word size.

Things users will notice

  • Indexing: code that indexes a 2D or 3D array in Python must swap its first two indices.
  • Flattening: NumPy now flattens a 2D argument x first. a.reshape(-1) of a 3×2 array gives 0, 10, 1, 11, 2, 12 rather than VUnit's storage order. The test of a returned array with a new shape checks this.
  • Image libraries: Pillow, OpenCV and numpy.loadtxt of a CSV file written by VUnit's save_csv index rows first. Such an array needs a.swapaxes(0, 1) (or a.T in 2D), which the user guide now says.

Changes

  • runtime.py: make_array swaps the axes of the view, and _array_result swaps them back.
  • tests/tb_python_pkg_bridge.vhd: the 2D/3D argument and result tests are indexed like VUnit now, and the flatten test has the new order.
  • examples/embedded_python: the image_model.pixel docs and code, and the comment in tb_example.vhd.
  • docs/types.rst: the indexing table, plus a paragraph on row-first image libraries.
  • release_notes/unreleased.md: a breaking change entry.

Tests

Locally:

  • pytest: 111 passed.
  • NVC and GHDL: 109/109, plus file_base 7/7.
  • The embedded_python example on NVC and GHDL: 18/18, with the CI filters.
  • Sphinx -W: builds cleanly.

🤖 Generated with Claude Code

get(a, x, y, z) is now a[x, y, z] in Python, with shape (width, height, depth),
for arguments and returned arrays alike, instead of a[y, x, z]. Arguments are
views of the transferred storage with the first two axes swapped, and returned
arrays are swapped back to VUnit's storage order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ru551n
ru551n force-pushed the integer-array-xyz branch from d0e5274 to 0e9f349 Compare October 14, 2026 09:21
@ru551n
ru551n merged commit 54f5194 into VUnit:main Oct 14, 2026
52 checks passed
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