You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Makes hl.Buffer <--> Python Buffer Protocol axis convention consistent throughout (#8953)
Halide interacts with Python in three place:
- Python bindings
- PyCallablle (`compile_to_callable()` via Python bindings)
- Python extension
This PR changes our axis ordering conventions to be consistent throughout:
- Constructing a Python buffer object from an `hl.Buffer` reverses axes.
- Constructing an `hl.Buffer` from any Python buffer object reverses axes.
- Note that an `hl.Buffer` is also a Python buffer object. E.g., you can use `my_buffer[idx0, idx1, idx2]` to retrieve an element. Constructing an `hl.Buffer` from another `hl.Buffer` does *not* reverse axes because that would be surprising.
- `hl.Buffer(my_array, "my_buffer_name", reverse_axes=False)` is explicitly supported.
- Calling a PyCallable with:
- A `hl.Buffer` does not reverse axes (it's considered a Halide Buffer, not a Python buffer object)
- A Python buffer object does reverse axes.
- Calling a pipeline function in a Python extension generated by a generator has the same conventions as a PyCallable.
Because of the new consistent conventions, we now permit:
- Non-contiguous views. Previously, Python-side C-contiguous buffers were reversed and F-contiguous buffers were not. Now we support views with arbitrary strides (so long as the Python-side stride in bytes divides the element size, and if the result is in `[INT_MIN, INT_MAX]`).
- This includes negatives strides.
- `hl.Buffer` also gained a `.numpy_view()` method that returns a `np.array` with an explicit `reverse_axes` argument (defaulting to `True`).
0 commit comments