File size: 3,645 Bytes
dc2106c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Copyright (c) ONNX Project Contributors
#
# SPDX-License-Identifier: Apache-2.0

import numpy as np

import onnx
from onnx.backend.test.case.base import Base
from onnx.backend.test.case.node import expect


class BitShift(Base):
    @staticmethod
    def export_right_unit8() -> None:
        node = onnx.helper.make_node(
            "BitShift", inputs=["x", "y"], outputs=["z"], direction="RIGHT"
        )

        x = np.array([16, 4, 1]).astype(np.uint8)
        y = np.array([1, 2, 3]).astype(np.uint8)
        z = x >> y  # expected output [8, 1, 0]
        expect(node, inputs=[x, y], outputs=[z], name="test_bitshift_right_uint8")

    @staticmethod
    def export_right_unit16() -> None:
        node = onnx.helper.make_node(
            "BitShift", inputs=["x", "y"], outputs=["z"], direction="RIGHT"
        )

        x = np.array([16, 4, 1]).astype(np.uint16)
        y = np.array([1, 2, 3]).astype(np.uint16)
        z = x >> y  # expected output [8, 1, 0]
        expect(node, inputs=[x, y], outputs=[z], name="test_bitshift_right_uint16")

    @staticmethod
    def export_right_unit32() -> None:
        node = onnx.helper.make_node(
            "BitShift", inputs=["x", "y"], outputs=["z"], direction="RIGHT"
        )

        x = np.array([16, 4, 1]).astype(np.uint32)
        y = np.array([1, 2, 3]).astype(np.uint32)
        z = x >> y  # expected output [8, 1, 0]
        expect(node, inputs=[x, y], outputs=[z], name="test_bitshift_right_uint32")

    @staticmethod
    def export_right_unit64() -> None:
        node = onnx.helper.make_node(
            "BitShift", inputs=["x", "y"], outputs=["z"], direction="RIGHT"
        )

        x = np.array([16, 4, 1]).astype(np.uint64)
        y = np.array([1, 2, 3]).astype(np.uint64)
        z = x >> y  # expected output [8, 1, 0]
        expect(node, inputs=[x, y], outputs=[z], name="test_bitshift_right_uint64")

    @staticmethod
    def export_left_unit8() -> None:
        node = onnx.helper.make_node(
            "BitShift", inputs=["x", "y"], outputs=["z"], direction="LEFT"
        )

        x = np.array([16, 4, 1]).astype(np.uint8)
        y = np.array([1, 2, 3]).astype(np.uint8)
        z = x << y  # expected output [32, 16, 8]
        expect(node, inputs=[x, y], outputs=[z], name="test_bitshift_left_uint8")

    @staticmethod
    def export_left_unit16() -> None:
        node = onnx.helper.make_node(
            "BitShift", inputs=["x", "y"], outputs=["z"], direction="LEFT"
        )

        x = np.array([16, 4, 1]).astype(np.uint16)
        y = np.array([1, 2, 3]).astype(np.uint16)
        z = x << y  # expected output [32, 16, 8]
        expect(node, inputs=[x, y], outputs=[z], name="test_bitshift_left_uint16")

    @staticmethod
    def export_left_unit32() -> None:
        node = onnx.helper.make_node(
            "BitShift", inputs=["x", "y"], outputs=["z"], direction="LEFT"
        )

        x = np.array([16, 4, 1]).astype(np.uint32)
        y = np.array([1, 2, 3]).astype(np.uint32)
        z = x << y  # expected output [32, 16, 8]
        expect(node, inputs=[x, y], outputs=[z], name="test_bitshift_left_uint32")

    @staticmethod
    def export_left_unit64() -> None:
        node = onnx.helper.make_node(
            "BitShift", inputs=["x", "y"], outputs=["z"], direction="LEFT"
        )

        x = np.array([16, 4, 1]).astype(np.uint64)
        y = np.array([1, 2, 3]).astype(np.uint64)
        z = x << y  # expected output [32, 16, 8]
        expect(node, inputs=[x, y], outputs=[z], name="test_bitshift_left_uint64")