• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2018 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#
16import collections
17
18TestCase = collections.namedtuple("TestCase", [
19    "inp", "inp_data", "k", "out_values", "out_values_data", "out_indices",
20    "out_indices_data"
21])
22
23test_cases = [
24    TestCase(
25        inp=Input("input", "TENSOR_FLOAT32", "{2, 2}"),
26        inp_data=[-2.0, 0.2, 0.8, 0.1],
27        k=Int32Scalar("k", 2),
28        out_values=Output("out_values", "TENSOR_FLOAT32", "{2, 2}"),
29        out_values_data=[0.2, -2.0, 0.8, 0.1],
30        out_indices=Output("out_indices", "TENSOR_INT32", "{2, 2}"),
31        out_indices_data=[1, 0, 0, 1]),
32    TestCase(
33        inp=Input("input", "TENSOR_FLOAT32", "{2, 3}"),
34        inp_data=[-2.0, -3.0, 0.2, 0.8, 0.1, -0.1],
35        k=Int32Scalar("k", 2),
36        out_values=Output("out_values", "TENSOR_FLOAT32", "{2, 2}"),
37        out_values_data=[0.2, -2.0, 0.8, 0.1],
38        out_indices=Output("out_indices", "TENSOR_INT32", "{2, 2}"),
39        out_indices_data=[2, 0, 0, 1]),
40    TestCase(
41        inp=Input("input", "TENSOR_FLOAT32", "{2, 4}"),
42        inp_data=[-2.0, -3.0, -4.0, 0.2, 0.8, 0.1, -0.1, -0.8],
43        k=Int32Scalar("k", 2),
44        out_values=Output("out_values", "TENSOR_FLOAT32", "{2, 2}"),
45        out_values_data=[0.2, -2.0, 0.8, 0.1],
46        out_indices=Output("out_indices", "TENSOR_INT32", "{2, 2}"),
47        out_indices_data=[3, 0, 0, 1]),
48    TestCase(
49        inp=Input("input", "TENSOR_FLOAT32", "{8}"),
50        inp_data=[-2.0, -3.0, -4.0, 0.2, 0.8, 0.1, -0.1, -0.8],
51        k=Int32Scalar("k", 2),
52        out_values=Output("out_values", "TENSOR_FLOAT32", "{2}"),
53        out_values_data=[0.8, 0.2],
54        out_indices=Output("out_indices", "TENSOR_INT32", "{2}"),
55        out_indices_data=[4, 3]),
56    TestCase(
57        inp=Input("input", "TENSOR_QUANT8_ASYMM", "{2, 3}, 2.0, 128"),
58        inp_data=[1, 2, 3, 251, 250, 249],
59        k=Int32Scalar("k", 2),
60        out_values=Output("out_values", "TENSOR_QUANT8_ASYMM", "{2, 2}, 2.0, 128"),
61        out_values_data=[3, 2, 251, 250],
62        out_indices=Output("out_indices", "TENSOR_INT32", "{2, 2}"),
63        out_indices_data=[2, 1, 0, 1]),
64    TestCase(
65        inp=Input("input", "TENSOR_INT32", "{2, 3}"),
66        inp_data=[1, 2, 3, 10251, 10250, 10249],
67        k=Int32Scalar("k", 2),
68        out_values=Output("out_values", "TENSOR_INT32", "{2, 2}"),
69        out_values_data=[3, 2, 10251, 10250],
70        out_indices=Output("out_indices", "TENSOR_INT32", "{2, 2}"),
71        out_indices_data=[2, 1, 0, 1]),
72]
73
74for test_case in test_cases:
75  model = Model().Operation("TOPK_V2", test_case.inp, test_case.k).To(
76      test_case.out_values, test_case.out_indices)
77  Example({
78      test_case.inp: test_case.inp_data,
79      test_case.out_values: test_case.out_values_data,
80      test_case.out_indices: test_case.out_indices_data
81  }, model=model).AddVariations("relaxed", "float16")
82