1#
2# Copyright (C) 2020 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16model = Model()
17input0 = Input("input0", "TENSOR_INT32", "{2, 2, 4, 6}")
18input1 = Input("input1", "TENSOR_INT32", "{2, 2, 4, 6}")
19output = Output("output", "TENSOR_INT32", "{2, 2, 4, 6}")
20model = model.Operation("DIV", input0, input1, 0).To(output)
21Example({
22    input0: [
23        -6, -6, -6, -6, -6, -6,
24        -5, -5, -5, -5, -5, -5,
25        -4, -4, -4, -4, -4, -4,
26        -3, -3, -3, -3, -3, -3,
27        -2, -2, -2, -2, -2, -2,
28        -1, -1, -1, -1, -1, -1,
29        0, 0, 0, 0, 0, 0,
30        1, 1, 1, 1, 1, 1,
31        2, 2, 2, 2, 2, 2,
32        3, 3, 3, 3, 3, 3,
33        4, 4, 4, 4, 4, 4,
34        5, 5, 5, 5, 5, 5,
35        6, 6, 6, 6, 6, 6,
36        7, 7, 7, 7, 7, 7,
37        8, 8, 8, 8, 8, 8,
38        9, 9, 9, 9, 9, 9,
39    ],
40    input1: [
41        -3, -2, -1, 1, 2, 3,
42        -3, -2, -1, 1, 2, 3,
43        -3, -2, -1, 1, 2, 3,
44        -3, -2, -1, 1, 2, 3,
45        -3, -2, -1, 1, 2, 3,
46        -3, -2, -1, 1, 2, 3,
47        -3, -2, -1, 1, 2, 3,
48        -3, -2, -1, 1, 2, 3,
49        -3, -2, -1, 1, 2, 3,
50        -3, -2, -1, 1, 2, 3,
51        -3, -2, -1, 1, 2, 3,
52        -3, -2, -1, 1, 2, 3,
53        -3, -2, -1, 1, 2, 3,
54        -3, -2, -1, 1, 2, 3,
55        -3, -2, -1, 1, 2, 3,
56        -3, -2, -1, 1, 2, 3,
57    ],
58    output: [
59        2, 3, 6, -6, -3, -2,
60        1, 2, 5, -5, -3, -2,
61        1, 2, 4, -4, -2, -2,
62        1, 1, 3, -3, -2, -1,
63        0, 1, 2, -2, -1, -1,
64        0, 0, 1, -1, -1, -1,
65        0, 0, 0, 0, 0, 0,
66        -1, -1, -1, 1, 0, 0,
67        -1, -1, -2, 2, 1, 0,
68        -1, -2, -3, 3, 1, 1,
69        -2, -2, -4, 4, 2, 1,
70        -2, -3, -5, 5, 2, 1,
71        -2, -3, -6, 6, 3, 2,
72        -3, -4, -7, 7, 3, 2,
73        -3, -4, -8, 8, 4, 2,
74        -3, -5, -9, 9, 4, 3,
75    ],
76})
77
78
79# Test DIV by zero.
80# It is undefined behavior. The output is ignored and we only require the drivers to not crash.
81input0 = Input("input0", "TENSOR_INT32", "{1}")
82input1 = Input("input1", "TENSOR_INT32", "{1}")
83output = IgnoredOutput("output", "TENSOR_INT32", "{1}")
84model = Model("by_zero").Operation("DIV", input0, input1, 0).To(output)
85Example({
86    input0: [1],
87    input1: [0],
88    output: [0],
89})
90