• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2021 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#
16
17# value = (8_bit_encoding - zeroPoint) * scale
18
19# If square roots are 0.5, 1, 2, 4
20# Then reciprocal square roots (outputs) are 2, 1, 0.5, 0.25
21# And squares (inputs) are 0.25, 1, 4, 16
22
23for inScale, inOffset, inToken in [(0.25, 0, "25h_0"),
24                                   (0.125, 10, "125t_10")]:
25    for outScale, outOffset, outToken  in [(0.25, 0, "25h_0"),
26                                            (0.01, 75, "1h_75")]:
27
28        input0_values = []
29        output0_values = []
30        for in0, out0 in [(0.25, 2),
31                          (1, 1),
32                          (4, 0.5),
33                          (16, 0.25)]:
34            input0_value = in0 / inScale + inOffset
35            output0_value = out0 / outScale + outOffset
36            if 0 <= input0_value < 128 and 0 <= output0_value < 128:
37                # We use [0, 128) as the range because the same values are used for
38                # both TENSOR_QUANT8_ASYMM and TENSOR_QUANT8_ASYMM_SIGNED  testing
39                input0_values.append(input0_value)
40                output0_values.append(output0_value)
41
42        input0 = Input("input0", "TENSOR_QUANT8_ASYMM", "{%d}, %f, %d" % (len(input0_values), inScale, inOffset))
43        output0 = Output("output0", "TENSOR_QUANT8_ASYMM", "{%d}, %f, %d" % (len(output0_values), outScale, outOffset))
44        model = Model().Operation("RSQRT", input0).To(output0)
45
46        example_name = "%s_%s" % (inToken, outToken)
47        Example({
48            input0: input0_values,
49            output0: output0_values,
50        }, name=example_name)
51
52# We rely on QuantizationCouplingTest to replicate this test case for TENSOR_QUANT8_ASYMM_SIGNED.
53