• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2017 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
17lookups = 4
18keys = 3
19rows = 3
20features = 2
21
22table = [x for x in range(rows * features)]
23for i in range(rows):
24  for j in range(features):
25    table[i * features + j] = i * 10 + j
26
27model = Model()
28
29lookup = Input("lookup", "TENSOR_INT32", "{%d}" % (lookups))
30key = Input("key", "TENSOR_INT32", "{%d}" % (keys))
31value = Input("value", "TENSOR_QUANT8_ASYMM", "{%d, %d}, 0.5f, 0" % (rows, features))
32output = Output("output", "TENSOR_QUANT8_ASYMM", "{%d, %d}, 0.5f, 0" % (lookups, features))
33hits = Output("hits", "TENSOR_QUANT8_ASYMM", "{%d}, 1.f, 0" % (lookups))
34model = model.Operation("HASHTABLE_LOOKUP", lookup, key, value).To([output, hits])
35
36input0 = {lookup:  [123, 250, 255, 0],
37          key: [0, 123, 255],
38          value: table}
39
40output0 = {output:
41           [
42               10, 11, # 2nd item
43               0, 0,   # Not found
44               20, 21, # 1st item
45               0, 1,   # 0th item
46           ],
47           hits:
48           [
49               1, 0, 1, 1,
50           ]
51}
52
53# Instantiate an example
54Example((input0, output0))
55