• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2019 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#
16def test(name, input0, output0, input0_data, output0_data):
17  model = Model().Operation("RANK", input0).To(output0)
18  quant8 = DataTypeConverter().Identify({
19      input0: ("TENSOR_QUANT8_ASYMM", 0.1, 128),
20  })
21  quant8_signed = DataTypeConverter().Identify({
22      input0: ("TENSOR_QUANT8_ASYMM_SIGNED", 0.1, 0),
23  })
24  example = Example({
25      input0: input0_data,
26      output0: output0_data,
27  }, model=model, name=name).AddVariations("int32", "float16", quant8, quant8_signed)
28
29test(
30    name="1d",
31    input0=Input("input0", "TENSOR_FLOAT32", "{3}"),
32    output0=Output("output0", "INT32", "{}"),
33    input0_data=[5, 7, 10],
34    output0_data=[1],
35)
36
37test(
38    name="1d",
39    input0=Input("input0", "TENSOR_FLOAT32", "{2, 3}"),
40    output0=Output("output0", "INT32", "{}"),
41    input0_data=[1, 2, 3, 4, 5, 6],
42    output0_data=[2],
43)
44
45# b/150728111 regression test.
46# Rank is a first operation that produces a scalar output.
47# This test verifies that RANK works with a scalar output
48# that's internal graph variable (not input or output of a graph).
49def test_internal_output(name, rank_input, fill_dims, fill_output, rank_input_data,
50                  fill_dims_data, fill_output_data):
51  internal_result = Internal("rank_internal_result", "INT32", "{}")
52  model = Model()
53  model = model.Operation("RANK", rank_input).To(internal_result)
54  model = model.Operation("FILL", fill_dims, internal_result).To(fill_output)
55
56  example = Example({
57      rank_input: rank_input_data,
58      fill_dims: fill_dims_data,
59      fill_output: fill_output_data,
60  }, model=model, name=name)
61
62test_internal_output(
63    name="internal_output",
64    rank_input=Input("input0", "TENSOR_FLOAT32", "{2, 3}"),
65    fill_dims=Input("input0", "TENSOR_INT32", "{3}"),
66    fill_output=Output("output", "TENSOR_INT32", "{2, 3, 4}"),
67    rank_input_data=[1, 2, 3, 4, 5, 6],
68    fill_dims_data=[2, 3, 4],
69    fill_output_data=[2] * (2 * 3 * 4),
70)
71