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

Python Bindings didn't allow for zero-D Funcs, ImageParams, Buffers #6633

Merged
merged 2 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions python_bindings/correctness/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,22 @@ def test_vector_tile():
p = hl.Pipeline([f, g])
p.compile_jit()

def test_scalar_funcs():
input = hl.ImageParam(hl.UInt(16), 0, 'input')

f = hl.Func('f')
g = hl.Func('g')

input[()]

(input[()]+input[()]) / 2
f[()]
g[()]

f[()] = (input[()]+input[()]+input[()])/3
g[()] = (f[()]+f[()]+f[()])/3

g.compile_jit()


if __name__ == "__main__":
Expand All @@ -300,3 +316,4 @@ def test_vector_tile():
test_basics3()
test_basics4()
test_basics5()
test_scalar_funcs()
14 changes: 14 additions & 0 deletions python_bindings/correctness/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,19 @@ def test_buffer_to_str():
b = hl.Buffer(hl.Int(32), [128, 256])
assert str(b) == '<halide.Buffer of type int32 shape:[[0,128,1],[0,256,128]]>'

def test_scalar_buffers():
buf = hl.Buffer.make_scalar(hl.Float(32))

assert buf.dimensions() == 0

buf.fill(0)
buf[()] = 2.5

assert buf[()] == 2.5

buf.fill(32)
assert buf[()] == 32

if __name__ == "__main__":
test_make_interleaved()
test_interleaved_ndarray()
Expand All @@ -271,3 +284,4 @@ def test_buffer_to_str():
test_reorder()
test_overflow()
test_buffer_to_str()
test_scalar_buffers()
4 changes: 3 additions & 1 deletion python_bindings/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ with some differences where the C++ idiom is either inappropriate or impossible:
offers variadic and list versions:
`Buffer<>(Type t, int extent_dim_0, int extent_dim_1, ...., extent_dim_N, string name = "") Buffer<>(Type t, vector<int> extents, string name = "")`
in Python, only the second variant is provided.
- `Func` and `Buffer` access is done using `[]` rather than `()`
- `Func` and `Buffer` access is done using `[]` rather than `()`.
- For zero-dimensional `Func` and `Buffer`, you must explicitly specify `[()]` -- that is, use an empty tuple as the index" --
as `[]` is not syntactically acceptable in Python.
- Some classes in the Halide API aren't provided because they are 'wrapped' with
standard Python idioms:
- `Halide::Tuple` doesn't exist in the Python bindings; an ordinary Python
Expand Down