diff --git a/python_bindings/correctness/basics.py b/python_bindings/correctness/basics.py index e4f3327d85c9..0bfa87ca6096 100644 --- a/python_bindings/correctness/basics.py +++ b/python_bindings/correctness/basics.py @@ -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__": @@ -300,3 +316,4 @@ def test_vector_tile(): test_basics3() test_basics4() test_basics5() + test_scalar_funcs() diff --git a/python_bindings/correctness/buffer.py b/python_bindings/correctness/buffer.py index cac68728a114..11ac31e49729 100644 --- a/python_bindings/correctness/buffer.py +++ b/python_bindings/correctness/buffer.py @@ -258,6 +258,19 @@ def test_buffer_to_str(): b = hl.Buffer(hl.Int(32), [128, 256]) assert str(b) == '' +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() @@ -271,3 +284,4 @@ def test_buffer_to_str(): test_reorder() test_overflow() test_buffer_to_str() + test_scalar_buffers() diff --git a/python_bindings/readme.md b/python_bindings/readme.md index 81224ed14bbd..e285a1716cab 100644 --- a/python_bindings/readme.md +++ b/python_bindings/readme.md @@ -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 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