Skip to content

Backport some PRs to release/15.x#7132

Merged
steven-johnson merged 3 commits intorelease/15.xfrom
srj/pybuf-axis-backport
Oct 28, 2022
Merged

Backport some PRs to release/15.x#7132
steven-johnson merged 3 commits intorelease/15.xfrom
srj/pybuf-axis-backport

Conversation

@steven-johnson
Copy link
Copy Markdown
Contributor

No description provided.

* Require Python 3.8+ in CMake build

* Update CMakeLists.txt

* Update CMakeLists.txt
using () to get or set a Buffer element wasn't being checked at runtime for Python, but it clearly should be, because Python. (Note that in C++ we don't always range-check for these operations -- it's limited to `assert()` checks -- but in Python the expectations are clearly different.)
* Fix Python buffer handling

In the category of "how did this ever work"...

TL;DR: in general, Halide Buffers have the opposite axis ordering from Python/NumPy buffers; in Halide, the most-frequently-varying dimension comes first, while in Python, it comes last. This isn't surprising, though, since Halide's indexing scheme is effectively column-major while NumPy's is row-major.

Anyway: what we *should* have done was to reverse the order of dimensions when converting to/from Halide Buffers vs Python buffers; instead, we kept the same order, then jumped thru hoops to rearrange buffers to fit this setup. This PR does the appropriate axis reordering, fixing the apps and tests as needed.

It also adds some helper code for image reading and writing; by default, we use `imageio` for this, but imageio ~always wants RGB/RGBA images to be interleaved (vs the planar that Halide prefers). So, I added the `halide.imageio` package, that has wrapper functions to quietly convert to/from planar as needed.

Needless to say, this change is likely to break existing code that is using 3d buffers in Halide, but I think it's the right long-term thing to do.

Opinions greatly welcomed here.

* Update PyBuffer.cpp

* -"for better vectorization"

* public halide.imageio utilities should copy() buffers

* PEP8

* Update imageio.py

* Update imageio.py

* add 'reverse_axes' options to Buffer conversions (#7127)

* add 'reverse_axes' options to Buffer conversions
@steven-johnson steven-johnson merged commit 23af11d into release/15.x Oct 28, 2022
@steven-johnson steven-johnson deleted the srj/pybuf-axis-backport branch October 28, 2022 16:04
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.

2 participants