Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python buffer handling #7125

Merged
merged 8 commits into from
Oct 28, 2022
Merged

Fix Python buffer handling #7125

merged 8 commits into from
Oct 28, 2022

Commits on Oct 26, 2022

  1. 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.
    steven-johnson committed Oct 26, 2022
    Configuration menu
    Copy the full SHA
    9bb320f View commit details
    Browse the repository at this point in the history
  2. Update PyBuffer.cpp

    steven-johnson committed Oct 26, 2022
    Configuration menu
    Copy the full SHA
    f5785dc View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    040f5e4 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    523c18b View commit details
    Browse the repository at this point in the history
  5. PEP8

    steven-johnson committed Oct 26, 2022
    Configuration menu
    Copy the full SHA
    d2bc100 View commit details
    Browse the repository at this point in the history
  6. Update imageio.py

    steven-johnson committed Oct 26, 2022
    Configuration menu
    Copy the full SHA
    8a4bcaf View commit details
    Browse the repository at this point in the history

Commits on Oct 27, 2022

  1. Update imageio.py

    steven-johnson committed Oct 27, 2022
    Configuration menu
    Copy the full SHA
    946dfea View commit details
    Browse the repository at this point in the history
  2. add 'reverse_axes' options to Buffer conversions (#7127)

    * add 'reverse_axes' options to Buffer conversions
    steven-johnson authored Oct 27, 2022
    Configuration menu
    Copy the full SHA
    25ac02e View commit details
    Browse the repository at this point in the history