File: identity_app.py

package info (click to toggle)
halide 21.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,752 kB
  • sloc: cpp: 289,334; ansic: 22,751; python: 7,486; makefile: 4,299; sh: 2,508; java: 1,549; javascript: 282; pascal: 207; xml: 127; asm: 9
file content (38 lines) | stat: -rw-r--r-- 718 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sys

import halide as hl
import numpy as np
from identity import identity


def main():
    size = 100

    ##
    # First test using Numpy buffers

    expected = np.arange(size, dtype=np.int32)
    array = np.empty_like(expected)

    identity(array)

    if not np.array_equal(array, expected):
        sys.exit("np.array failure!")

    ##
    # Second test using hl.Buffer as a wrapper

    expected = np.arange(-size, 0, dtype=np.int32)
    array = np.empty_like(expected)
    array_hl = hl.Buffer(array)
    array_hl.set_min([-size])
    identity(array_hl)

    if not np.array_equal(array, expected):
        sys.exit("hl.Buffer failure!")

    print("Success!")


if __name__ == "__main__":
    main()