2 # Copyright (C) 2018 The Android Open Source Project
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 Operand = collections.namedtuple(
21 "Operand", ["name", "as_input", "as_output", "data", "supports_relaxation"])
26 as_input=Input("input0", "TENSOR_FLOAT16", "{2, 3}"),
27 as_output=Output("output0", "TENSOR_FLOAT16", "{2, 3}"),
28 data=[1, 2, 3, 4, 5, 6],
29 supports_relaxation=False),
32 as_input=Input("input0", "TENSOR_FLOAT32", "{2, 3}"),
33 as_output=Output("output0", "TENSOR_FLOAT32", "{2, 3}"),
34 data=[1, 2, 3, 4, 5, 6],
35 supports_relaxation=True),
38 as_input=Input("input0", "TENSOR_INT32", "{2, 3}"),
39 as_output=Output("output0", "TENSOR_INT32", "{2, 3}"),
40 data=[1, 2, 3, 4, 5, 6],
41 supports_relaxation=False),
44 as_input=Input("input0", "TENSOR_QUANT8_ASYMM", "{2, 3}, 4.0, 100"),
45 as_output=Output("output0", "TENSOR_QUANT8_ASYMM", "{2, 3}, 4.0, 100"),
46 data=[1, 2, 3, 4, 5, 6],
47 supports_relaxation=False),
50 for operand1, operand2 in itertools.product(operands, operands):
51 input0 = operand1.as_input
52 output0 = operand2.as_output
54 model = Model().Operation("CAST", input0).To(output0)
57 input0: operand1.data,
58 output0: operand2.data,
59 }, model=model, name='{}_to_{}'.format(operand1.name, operand2.name))
61 if operand1.supports_relaxation or operand2.supports_relaxation:
65 # Test overflow and underflow.
69 as_input=Input("input0", "TENSOR_FLOAT16", "{2}"),
72 supports_relaxation=False),
75 as_input=Input("input0", "TENSOR_FLOAT32", "{2}"),
78 supports_relaxation=True),
81 as_input=Input("input0", "TENSOR_INT32", "{2}"),
84 supports_relaxation=False),
87 for operand1 in operands:
88 input0 = operand1.as_input
89 output0 = Output("output0", "TENSOR_QUANT8_ASYMM", "{2}, 4.0, 100")
91 model = Model().Operation("CAST", input0).To(output0)
94 input0: operand1.data,
96 }, model=model, name='{}_to_quant8_overflow'.format(operand1.name))
98 if operand1.supports_relaxation: